This repository was archived by the owner on Mar 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOI.java
More file actions
210 lines (178 loc) · 10.8 KB
/
OI.java
File metadata and controls
210 lines (178 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package org.usfirst.frc.team4915.stronghold;
import java.io.IOException;
import java.io.InputStream;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import org.usfirst.frc.team4915.stronghold.commands.DriveTrain.GearShiftCommand;
import org.usfirst.frc.team4915.stronghold.commands.IntakeLauncher.ActivateLauncherPneumaticCommand;
import org.usfirst.frc.team4915.stronghold.commands.IntakeLauncher.AimerGoToAngleCommand;
import org.usfirst.frc.team4915.stronghold.commands.IntakeLauncher.IntakeBallCommandGroup;
import org.usfirst.frc.team4915.stronghold.commands.IntakeLauncher.LaunchBallCommandGroup;
import org.usfirst.frc.team4915.stronghold.commands.IntakeLauncher.RetractLauncherPneumaticCommand;
import org.usfirst.frc.team4915.stronghold.commands.IntakeLauncher.StopWheelsCommand;
import org.usfirst.frc.team4915.stronghold.commands.Scaler.ScalerCommand;
import org.usfirst.frc.team4915.stronghold.commands.vision.AutoAimControlCommand;
import org.usfirst.frc.team4915.stronghold.subsystems.Autonomous;
import org.usfirst.frc.team4915.stronghold.subsystems.Scaler.State;
import org.usfirst.frc.team4915.stronghold.vision.robot.VisionState;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
* This class handles the "operator interface", or the interactions between the
* driver station and the robot code.
*/
public class OI {
// Ports for joysticks
public static final int DRIVE_STICK_PORT = 0;
public static final int LAUNCHER_STICK_PORT = 1;
// Button numbers for driveStick buttons
public static final int HIGH_SPEED_DRIVE_BUTTON = 6;
public static final int LOW_SPEED_DRIVE_BUTTON = 4;
public static final int INTAKE_BALL_BUTTON_NUMBER = 3;
// Button numbers for launching related buttons on the mechanism stick
public static final int LAUNCH_BALL_BUTTON_NUMBER = 2;
public static final int STOP_WHEELS_BUTTON_NUMBER = 5;
public static final int LAUNCHER_JUMP_TO_POSITION_BUTTON_NUMBER = 4; //Test
public static final int AUTO_AIM_BUTTON_NUMBER = 7;
public static final int HIGH_LOW_BUTTON_NUMBER = 8;
public static final int ACTIVATE_PNEUMATIC_TEST_BUTTON_NUMBER = 6; //Test Button
public static final int RETRACT_PNEUMATIC_TEST_BUTTON_NUMBER = 7; //Test Button
// Button numbers for scaling related buttons on the mechanism joystick
public static final int SCALER_REACH_UP_BUTTON_NUMBER = 2;
public static final int SCALER_REACH_DOWN_BUTTON_NUMBER = 10;
public static final int SCALER_LIFT_BUTTON_NUMBER = 9;
// Create joysticks for driving and aiming the launcher
public Joystick driveStick;
public Joystick aimStick;
// Create buttons for the driveStick
public JoystickButton speedUpButton;
public JoystickButton slowDownButton;
public JoystickButton grabBallButton;
// Create buttons for the launcher on the mechanism stick
public JoystickButton launchBallButton;
public JoystickButton stopWheelsButton;
public JoystickButton launcherZeroEncoderButton;
public JoystickButton launcherSetSetpointForDashboardButton;
public JoystickButton launcherJumpToPositionButton;
public JoystickButton autoAimButton;
public JoystickButton highLowButton;
public JoystickButton activatePneumaticTestButton;
public JoystickButton retractPneumaticTestButton;
// Create buttons for the scaler on the mechanism stick
public JoystickButton scalerExtendButton;
public JoystickButton scalerRetractButton;
public JoystickButton scalerReachUpButton;
public JoystickButton scalerReachDownButton;
public JoystickButton scalerLiftButton;
//variables for the sendable chooser
public SendableChooser startingFieldPosition;
public SendableChooser barrierType;
public SendableChooser strategy;
public OI() {
// *****autonomous*****
//***Three Sendable Choosers***
//SendableChooser for the starting field position
startingFieldPosition = new SendableChooser();
SmartDashboard.putData("Starting Field Position for autonomous", startingFieldPosition);
startingFieldPosition.addDefault("Field Position 1: Low Bar", Autonomous.Position.ONE);
startingFieldPosition.addObject("Field Position 2", Autonomous.Position.TWO);
startingFieldPosition.addObject("Field Position 3:", Autonomous.Position.THREE);
startingFieldPosition.addObject("Field Position 4:", Autonomous.Position.FOUR);
startingFieldPosition.addObject("Field Position 5", Autonomous.Position.FIVE);
//SendableChooser for the barrier type
//assigning each barrier to a number
barrierType = new SendableChooser();
SmartDashboard.putData("Barrier Type for autonomous", barrierType);
barrierType.addDefault("Low Bar", Autonomous.Type.LOWBAR);
barrierType.addObject("Cheval De Frise", Autonomous.Type.CHEVAL_DE_FRISE);
barrierType.addObject("Moat", Autonomous.Type.MOAT);
barrierType.addObject("Ramparts", Autonomous.Type.RAMPARTS);
barrierType.addObject("Rough Terrain", Autonomous.Type.ROUGH_TERRAIN);
barrierType.addObject("Rock Wall", Autonomous.Type.ROCK_WALL);
//SendableChooser for the strategy
strategy = new SendableChooser();
SmartDashboard.putData("Strategy for autonomous", strategy);
strategy.addDefault("None", Autonomous.Strat.NONE);
strategy.addObject("Drive across barrier", Autonomous.Strat.DRIVE_ACROSS);
strategy.addObject("Drive and shoot high goal with vision", Autonomous.Strat.DRIVE_SHOOT_VISION);
strategy.addObject("Drive and shoot high goal without vision", Autonomous.Strat.DRIVE_SHOOT_NO_VISION);
this.driveStick = new Joystick(DRIVE_STICK_PORT);
this.aimStick = new Joystick(LAUNCHER_STICK_PORT);
// Bind module commands to buttons
if (ModuleManager.DRIVE_MODULE_ON) {
System.out.println("ModuleManager OI initialized: TODO DriveTrain"); // TODO:
// OI
// init
// DriveTrain
}
if (ModuleManager.GEARSHIFT_MODULE_ON) {
initializeButton(this.speedUpButton, driveStick, HIGH_SPEED_DRIVE_BUTTON, new GearShiftCommand(true));
initializeButton(this.speedUpButton, driveStick, LOW_SPEED_DRIVE_BUTTON, new GearShiftCommand(false));
System.out.println("ModuleManager OI initialized: TODO DriveTrain"); // TODO:
// OI
// init
// DriveTrain
}
if (ModuleManager.INTAKELAUNCHER_MODULE_ON) {
initializeButton(this.launchBallButton, aimStick, LAUNCH_BALL_BUTTON_NUMBER, new LaunchBallCommandGroup());
initializeButton(this.stopWheelsButton, aimStick, STOP_WHEELS_BUTTON_NUMBER, new StopWheelsCommand());
initializeButton(this.grabBallButton, aimStick, INTAKE_BALL_BUTTON_NUMBER, new IntakeBallCommandGroup());
initializeButton(this.launcherJumpToPositionButton, aimStick, LAUNCHER_JUMP_TO_POSITION_BUTTON_NUMBER, new AimerGoToAngleCommand(2000));
initializeButton(this.activatePneumaticTestButton, aimStick, ACTIVATE_PNEUMATIC_TEST_BUTTON_NUMBER, new ActivateLauncherPneumaticCommand());
initializeButton(this.retractPneumaticTestButton, aimStick, RETRACT_PNEUMATIC_TEST_BUTTON_NUMBER, new RetractLauncherPneumaticCommand());
System.out.println("ModuleManager initialized: IntakeLauncher");
}
if (ModuleManager.GYRO_MODULE_ON) {
System.out.println("ModuleManager OI TODO: Initialize Gyro!"); // TODO:
// OI
// init
// Gyro
SmartDashboard.putData("Gyro", RobotMap.gyro);
}
if (ModuleManager.VISION_MODULE_ON) {
SmartDashboard.putData(VisionState.getInstance());
initializeButton(this.autoAimButton, aimStick, AUTO_AIM_BUTTON_NUMBER, new AutoAimControlCommand(true, false));
initializeButton(this.highLowButton, aimStick, HIGH_LOW_BUTTON_NUMBER, new AutoAimControlCommand(false, true));
System.out.println("ModuleManager OI: Initialize Vision!");
}
if (ModuleManager.SCALING_MODULE_ON) {
SmartDashboard.putData("Scaler Winch", RobotMap.scalingWinch);
SmartDashboard.putData("Scaler Tape Measure Motor", RobotMap.scalingMotor);
initializeButton(this.scalerReachUpButton, aimStick, SCALER_REACH_UP_BUTTON_NUMBER, new ScalerCommand(State.REACHING_UP));
initializeButton(this.scalerLiftButton, aimStick, SCALER_LIFT_BUTTON_NUMBER, new ScalerCommand(State.LIFTING));
initializeButton(this.scalerReachDownButton, aimStick, SCALER_REACH_DOWN_BUTTON_NUMBER, new ScalerCommand(State.REACHING_DOWN));
}
if (ModuleManager.IMU_MODULE_ON) {
System.out.println("ModuleManager initialized: imu");
}
/*
* VERSION STRING!!
*/
try (InputStream manifest = getClass().getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF")) {
Attributes attributes = new Manifest(manifest).getMainAttributes();
/* Print the attributes into form fields on the dashboard */
SmartDashboard.putString("Code Version", attributes.getValue("Code-Version"));
SmartDashboard.putString("Built At", attributes.getValue("Built-At"));
SmartDashboard.putString("Built By", attributes.getValue("Built-By"));
/* And print the attributes into the log. */
System.out.println("Code Version: " + attributes.getValue("Code-Version"));
System.out.println("Built At: " + attributes.getValue("Built-At"));
System.out.println("Built By: " + attributes.getValue("Built-By"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void initializeButton(JoystickButton Button, Joystick Joystick, int buttonNumber, Command Command) {
Button = new JoystickButton(Joystick, buttonNumber);
Button.whenPressed(Command);
}
public Joystick getJoystickDrive() {
return this.driveStick;
}
public Joystick getJoystickAimStick() {
return this.aimStick;
}
}