-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRobotContainer.java
More file actions
404 lines (370 loc) · 17.2 KB
/
RobotContainer.java
File metadata and controls
404 lines (370 loc) · 17.2 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot;
import com.studica.frc.AHRS;
import com.studica.frc.AHRS.NavXComType;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import frc.robot.apriltags.ApriltagInputs;
import frc.robot.apriltags.MockApriltag;
import frc.robot.apriltags.TCPApriltag;
import frc.robot.commands.CancelAll;
import frc.robot.commands.RollAlgae;
import frc.robot.commands.byebye.ByeByeToFwrLimit;
import frc.robot.commands.byebye.ByeByeToRevLimit;
import frc.robot.commands.coral.IntakeCoral;
import frc.robot.commands.coral.ShootCoral;
import frc.robot.commands.drivetrain.Drive;
import frc.robot.commands.drivetrain.DriveVoltage;
import frc.robot.commands.drivetrain.RobotSlide;
import frc.robot.commands.elevator.*;
import frc.robot.commands.hihi.*;
import frc.robot.commands.lightStrip.SetLedFromElevatorPosition;
import frc.robot.commands.lightStrip.SetLedPattern;
import frc.robot.commands.sequences.ByeByeAllDone;
import frc.robot.commands.sequences.IntakeAlgae;
import frc.robot.commands.sequences.PickUpCoral;
import frc.robot.commands.sequences.RemoveAlgaeFromReef;
import frc.robot.commands.sequences.ShootAlgae;
import frc.robot.constants.Constants;
import frc.robot.constants.ElevatorPosition;
import frc.robot.subsystems.algaebyebyeroller.AlgaeByeByeRollerSubsystem;
import frc.robot.subsystems.algaebyebyeroller.MockAlgaeByeByeRollerIO;
import frc.robot.subsystems.algaebyebyeroller.RealAlgaeByeByeRollerIO;
import frc.robot.subsystems.algaebyebyeroller.SimAlgaeByeByeRollerIO;
import frc.robot.subsystems.algaebyebyetilt.AlgaeByeByeTiltSubsystem;
import frc.robot.subsystems.algaebyebyetilt.MockAlgaeByeByeTiltIO;
import frc.robot.subsystems.algaebyebyetilt.RealAlgaeByeByeTiltIO;
import frc.robot.subsystems.coral.CoralSubsystem;
import frc.robot.subsystems.coral.MockCoralIOFollower;
import frc.robot.subsystems.coral.MockCoralIOLeader;
import frc.robot.subsystems.coral.RealCoralIOFollower;
import frc.robot.subsystems.coral.RealCoralIOLeader;
import frc.robot.subsystems.coral.SimCoralIOFollower;
import frc.robot.subsystems.coral.SimCoralIOLeader;
import frc.robot.subsystems.elevator.ElevatorSubsystem;
import frc.robot.subsystems.elevator.MockElevatorIO;
import frc.robot.subsystems.elevator.RealElevatorIO;
import frc.robot.subsystems.elevator.SimElevatorIO;
import frc.robot.subsystems.gyro.GyroIO;
import frc.robot.subsystems.gyro.MockGyroIO;
import frc.robot.subsystems.gyro.RealGyroIO;
import frc.robot.subsystems.gyro.ThreadedGyro;
import frc.robot.subsystems.hihiextender.HihiExtenderSubsystem;
import frc.robot.subsystems.hihiextender.MockHihiExtenderIO;
import frc.robot.subsystems.hihiextender.RealHihiExtenderIO;
import frc.robot.subsystems.hihiextender.SimHihiExtenderIO;
import frc.robot.subsystems.hihiroller.HihiRollerSubsystem;
import frc.robot.subsystems.hihiroller.MockHihiRollerIO;
import frc.robot.subsystems.hihiroller.RealHihiRollerIO;
import frc.robot.subsystems.hihiroller.SimHihiRollerIO;
import frc.robot.subsystems.lightStrip.LightStrip;
import frc.robot.subsystems.lightStrip.MockLightStripIO;
import frc.robot.subsystems.lightStrip.RealLightStripIO;
import frc.robot.subsystems.swervev3.KinematicsConversionConfig;
import frc.robot.subsystems.swervev3.SwerveDrivetrain;
import frc.robot.subsystems.swervev3.SwerveIdConfig;
import frc.robot.subsystems.swervev3.SwervePidConfig;
import frc.robot.subsystems.swervev3.io.SwerveModule;
import frc.robot.subsystems.swervev3.io.abs.MockAbsIO;
import frc.robot.subsystems.swervev3.io.drive.MockDriveMotorIO;
import frc.robot.subsystems.swervev3.io.steer.MockSteerMotorIO;
import frc.robot.utils.BlinkinPattern;
import frc.robot.utils.ModulePosition;
import frc.robot.utils.logging.LoggableIO;
import frc.robot.utils.motor.Gain;
import frc.robot.utils.motor.PID;
import frc.robot.utils.shuffleboard.SmartShuffleboard;
import java.util.Optional;
public class RobotContainer {
private SwerveDrivetrain drivetrain;
private final AlgaeByeByeRollerSubsystem byebyeRoller;
private final AlgaeByeByeTiltSubsystem byebyeTilt;
private final HihiRollerSubsystem hihiRoller;
private final HihiExtenderSubsystem hihiExtender;
private final ElevatorSubsystem elevatorSubsystem;
private final CoralSubsystem coralSubsystem;
// private final ClimberSubsystem climber;
private final LightStrip lightStrip;
private final CommandXboxController controller =
new CommandXboxController(Constants.XBOX_CONTROLLER_ID);
private final Joystick joyleft = new Joystick(Constants.LEFT_JOYSTICK_ID);
private final Joystick joyright = new Joystick(Constants.RIGHT_JOYSTICK_ID);
public RobotContainer() {
switch (Constants.currentMode) {
case REAL -> {
hihiRoller = new HihiRollerSubsystem(new RealHihiRollerIO());
hihiExtender = new HihiExtenderSubsystem(new RealHihiExtenderIO());
elevatorSubsystem = new ElevatorSubsystem(new RealElevatorIO());
coralSubsystem = new CoralSubsystem(new RealCoralIOFollower(), new RealCoralIOLeader());
// climber = new ClimberSubsystem(new RealClimberIO());
byebyeRoller = new AlgaeByeByeRollerSubsystem(new RealAlgaeByeByeRollerIO());
byebyeTilt = new AlgaeByeByeTiltSubsystem(new RealAlgaeByeByeTiltIO());
lightStrip = new LightStrip(new RealLightStripIO());
}
case REPLAY -> {
hihiRoller = new HihiRollerSubsystem(new MockHihiRollerIO());
hihiExtender = new HihiExtenderSubsystem(new MockHihiExtenderIO());
elevatorSubsystem = new ElevatorSubsystem(new MockElevatorIO());
coralSubsystem = new CoralSubsystem(new MockCoralIOFollower(), new MockCoralIOLeader());
// climber = new ClimberSubsystem(new MockClimberIO());
byebyeRoller = new AlgaeByeByeRollerSubsystem(new MockAlgaeByeByeRollerIO());
byebyeTilt = new AlgaeByeByeTiltSubsystem(new MockAlgaeByeByeTiltIO());
lightStrip = new LightStrip(new MockLightStripIO());
}
case SIM -> {
hihiRoller = new HihiRollerSubsystem(new SimHihiRollerIO()); // TODO
hihiExtender = new HihiExtenderSubsystem(new SimHihiExtenderIO()); // TODO
elevatorSubsystem = new ElevatorSubsystem(new SimElevatorIO());
coralSubsystem = new CoralSubsystem(new SimCoralIOFollower(), new SimCoralIOLeader());
// climber = new ClimberSubsystem(new SimClimberIO());
byebyeTilt = new AlgaeByeByeTiltSubsystem(new MockAlgaeByeByeTiltIO()); // TODO
byebyeRoller = new AlgaeByeByeRollerSubsystem(new SimAlgaeByeByeRollerIO());
lightStrip = new LightStrip(new MockLightStripIO());
}
default -> {
throw new RuntimeException("Did not specify Robot Mode");
}
}
setupDriveTrain();
configureBindings();
putShuffleboardCommands();
}
private void configureBindings() {
lightStrip.setDefaultCommand(
new SetLedFromElevatorPosition(elevatorSubsystem::getStoredReefPosition, lightStrip));
drivetrain.setDefaultCommand(
new Drive(
drivetrain, joyleft::getY, joyleft::getX, joyright::getX, drivetrain::getDriveMode));
JoystickButton joyLeft2 = new JoystickButton(joyleft, 2);
RobotSlide robotSlide = new RobotSlide(drivetrain, joyleft::getX);
joyLeft2.whileTrue(robotSlide);
controller.leftTrigger().onTrue(new PickUpCoral(elevatorSubsystem, coralSubsystem, lightStrip));
controller
.povUp()
.onTrue(
new SetElevatorStoredPosition(ElevatorPosition.LEVEL4, elevatorSubsystem, lightStrip));
controller
.povDown()
.onTrue(
new SetElevatorStoredPosition(ElevatorPosition.LEVEL1, elevatorSubsystem, lightStrip));
controller
.povLeft()
.onTrue(
new SetElevatorStoredPosition(ElevatorPosition.LEVEL2, elevatorSubsystem, lightStrip));
controller
.povRight()
.onTrue(
new SetElevatorStoredPosition(ElevatorPosition.LEVEL3, elevatorSubsystem, lightStrip));
controller.rightBumper().onTrue(new ElevatorToStoredPosition(elevatorSubsystem));
controller.leftBumper().onTrue(new ResetElevator(elevatorSubsystem));
controller.rightTrigger().onTrue(new ShootCoral(coralSubsystem, Constants.CORAL_SHOOTER_SPEED));
SetElevatorTargetPosition setElevatorTargetPosition =
new SetElevatorTargetPosition(controller::getLeftY, elevatorSubsystem);
elevatorSubsystem.setDefaultCommand(setElevatorTargetPosition);
controller.x().onTrue(new IntakeAlgae(hihiExtender, hihiRoller));
controller.y().onTrue(new ShootAlgae(hihiExtender, hihiRoller));
controller.a().onTrue(new RemoveAlgaeFromReef(byebyeTilt, byebyeRoller));
controller.b().onTrue(new ByeByeAllDone(byebyeTilt, byebyeRoller));
controller.back().onTrue(new CancelAll(elevatorSubsystem, hihiExtender));
// climber on Right Trigger
if (Constants.COMMAND_DEBUG) {
SmartShuffleboard.putCommand("DEBUG", "Roll Algae", new RollAlgae(hihiRoller, 0.5));
// SmartShuffleboard.putCommand("DEBUG", "Climber reset", new ResetClimber(climber));
// SmartShuffleboard.putCommand("DEBUG", "Climber stop", new CloseClimber(climber));
SmartShuffleboard.put("DEBUG", "CID", Constants.ALGAE_ROLLER_CAN_ID);
}
}
public Command getAutonomousCommand() {
return Commands.print("No autonomous command configured");
}
public static boolean isRedAlliance() {
Optional<DriverStation.Alliance> alliance = DriverStation.getAlliance();
return alliance.filter(value -> value == DriverStation.Alliance.Red).isPresent();
}
private void setupDriveTrain() {
SwerveIdConfig frontLeftIdConf =
new SwerveIdConfig(
Constants.DRIVE_FRONT_LEFT_D,
Constants.DRIVE_FRONT_LEFT_S,
Constants.DRIVE_CANCODER_FRONT_LEFT);
SwerveIdConfig frontRightIdConf =
new SwerveIdConfig(
Constants.DRIVE_FRONT_RIGHT_D,
Constants.DRIVE_FRONT_RIGHT_S,
Constants.DRIVE_CANCODER_FRONT_RIGHT);
SwerveIdConfig backLeftIdConf =
new SwerveIdConfig(
Constants.DRIVE_BACK_LEFT_D,
Constants.DRIVE_BACK_LEFT_S,
Constants.DRIVE_CANCODER_BACK_LEFT);
SwerveIdConfig backRightIdConf =
new SwerveIdConfig(
Constants.DRIVE_BACK_RIGHT_D,
Constants.DRIVE_BACK_RIGHT_S,
Constants.DRIVE_CANCODER_BACK_RIGHT);
TrapezoidProfile.Constraints constraints =
new TrapezoidProfile.Constraints(Constants.MAX_ANGULAR_SPEED * 150, 2 * Math.PI * 150);
PID drivePid = PID.of(Constants.DRIVE_PID_P, Constants.DRIVE_PID_I, Constants.DRIVE_PID_D);
PID steerPid = PID.of(Constants.STEER_PID_P, Constants.STEER_PID_I, Constants.STEER_PID_D);
Gain driveGain = Gain.of(Constants.DRIVE_PID_FF_V, Constants.DRIVE_PID_FF_S);
Gain steerGain = Gain.of(Constants.STEER_PID_FF_V, Constants.STEER_PID_FF_S);
KinematicsConversionConfig kConfig =
new KinematicsConversionConfig(Constants.WHEEL_RADIUS, Constants.SWERVE_MODULE_PROFILE);
SwervePidConfig pidConfig =
new SwervePidConfig(drivePid, steerPid, driveGain, steerGain, constraints);
SwerveModule frontLeft;
SwerveModule frontRight;
SwerveModule backLeft;
SwerveModule backRight;
GyroIO gyroIO;
LoggableIO<ApriltagInputs> apriltagIO;
if (Robot.isReal()) {
frontLeft =
SwerveModule.createModule(
frontLeftIdConf, kConfig, pidConfig, ModulePosition.FRONT_LEFT, false);
frontRight =
SwerveModule.createModule(
frontRightIdConf, kConfig, pidConfig, ModulePosition.FRONT_RIGHT, true);
backLeft =
SwerveModule.createModule(
backLeftIdConf, kConfig, pidConfig, ModulePosition.BACK_LEFT, false);
backRight =
SwerveModule.createModule(
backRightIdConf,
kConfig,
pidConfig,
ModulePosition.BACK_RIGHT,
true); // TODO: put these in the right SwerveModuleProfiles later
ThreadedGyro threadedGyro =
new ThreadedGyro(new AHRS(NavXComType.kMXP_SPI)); // TODO: change comtype later
threadedGyro.start();
gyroIO = new RealGyroIO(threadedGyro);
apriltagIO = new TCPApriltag();
} else {
frontLeft =
new SwerveModule(
new MockDriveMotorIO(),
new MockSteerMotorIO(),
new MockAbsIO(),
pidConfig,
"frontLeft");
frontRight =
new SwerveModule(
new MockDriveMotorIO(),
new MockSteerMotorIO(),
new MockAbsIO(),
pidConfig,
"frontRight");
backLeft =
new SwerveModule(
new MockDriveMotorIO(),
new MockSteerMotorIO(),
new MockAbsIO(),
pidConfig,
"backLeft");
backRight =
new SwerveModule(
new MockDriveMotorIO(),
new MockSteerMotorIO(),
new MockAbsIO(),
pidConfig,
"backRight");
gyroIO = new MockGyroIO();
apriltagIO = new MockApriltag();
}
drivetrain =
new SwerveDrivetrain(frontLeft, frontRight, backLeft, backRight, gyroIO, apriltagIO);
}
public SwerveDrivetrain getDrivetrain() {
return drivetrain;
}
public void putShuffleboardCommands() {
if (Constants.SWERVE_DEBUG) {
SmartShuffleboard.put("Drive", "VoltsToRunWith", 0);
SmartShuffleboard.putCommand(
"Drive",
"RunWithVolts",
new DriveVoltage(
drivetrain, () -> SmartShuffleboard.getDouble("Drive", "VoltsToRunWith", 0), 5));
}
if (Constants.CORAL_DEBUG) {
SmartShuffleboard.putCommand(
"Commands", "Shoot Coral", new ShootCoral(coralSubsystem, Constants.CORAL_SHOOTER_SPEED));
SmartShuffleboard.putCommand("Commands", "Intake Coral", new IntakeCoral(coralSubsystem));
SmartShuffleboard.putCommand(
"Coral", "Pick Up Coral", new PickUpCoral(elevatorSubsystem, coralSubsystem, lightStrip));
}
if (Constants.HIHI_DEBUG) {
// HiHi Commads
SmartShuffleboard.putCommand("HiHi", "Extend HiHi", new ExtendHiHi(hihiExtender));
SmartShuffleboard.putCommand("HiHi", "Retract HiHi", new RetractHiHi(hihiExtender));
SmartShuffleboard.putCommand("HiHi", "Roll HiHi Roller In", new RollHiHiRollerIn(hihiRoller));
SmartShuffleboard.putCommand(
"HiHi", "Roll HiHi Roller Out", new ShootHiHiRollerOut(hihiRoller));
SmartShuffleboard.putCommand(
"HiHi", "Intake Algae", new IntakeAlgae(hihiExtender, hihiRoller));
}
if (Constants.BYEBYE_DEBUG) {
// ByeBye Commands
SmartShuffleboard.putCommand(
"ByeBye", "ByeBye To FWD Limit", new ByeByeToFwrLimit(byebyeTilt));
SmartShuffleboard.putCommand(
"ByeBye", "ByeBye To REV Limit", new ByeByeToRevLimit(byebyeTilt));
}
if (Constants.ELEVATOR_DEBUG) {
// Elevator Commands
SmartShuffleboard.putCommand(
"Elevator",
"SetElevatorSetpointTo0",
new SetElevatorTargetPosition(() -> 0, elevatorSubsystem));
SmartShuffleboard.putCommand(
"Elevator", "RestElevatorEncoder", new ResetElevatorEncoder(elevatorSubsystem));
SmartShuffleboard.putCommand(
"Elevator", "Reset Elevator", new ResetElevator(elevatorSubsystem));
SmartShuffleboard.putCommand(
"Elevator", "Elevator To Position", new ElevatorToStoredPosition(elevatorSubsystem));
SmartShuffleboard.putCommand(
"Elevator",
"Store L0",
new SetElevatorStoredPosition(
ElevatorPosition.CORAL_INTAKE, elevatorSubsystem, lightStrip));
SmartShuffleboard.putCommand(
"Elevator",
"Store L1",
new SetElevatorStoredPosition(ElevatorPosition.LEVEL1, elevatorSubsystem, lightStrip));
SmartShuffleboard.putCommand(
"Elevator",
"Store L2",
new SetElevatorStoredPosition(ElevatorPosition.LEVEL2, elevatorSubsystem, lightStrip));
SmartShuffleboard.putCommand(
"Elevator",
"Store L3",
new SetElevatorStoredPosition(ElevatorPosition.LEVEL3, elevatorSubsystem, lightStrip));
SmartShuffleboard.putCommand(
"Elevator",
"Store L4",
new SetElevatorStoredPosition(ElevatorPosition.LEVEL4, elevatorSubsystem, lightStrip));
}
if (Constants.CLIMBER_DEBUG) {
// Climber Commands
// SmartShuffleboard.putCommand("Climber", "Reset Climber", new ResetClimber(climber));
//
// SmartShuffleboard.putCommand("Climber", "Close Climber", new CloseClimber(climber));
}
SmartShuffleboard.putCommand(
"DEBUG",
"LightStripPatternGreen",
new SetLedPattern(lightStrip, BlinkinPattern.BLUE_GREEN));
SmartShuffleboard.putCommand(
"DEBUG",
"LightStripPatternViolet",
new SetLedPattern(lightStrip, BlinkinPattern.BLUE_VIOLET));
}
}