|
14 | 14 | package frc.robot; |
15 | 15 |
|
16 | 16 | import com.pathplanner.lib.auto.AutoBuilder; |
17 | | -import edu.wpi.first.math.geometry.Pose2d; |
18 | | -import edu.wpi.first.math.geometry.Rotation2d; |
19 | 17 | import edu.wpi.first.wpilibj.GenericHID; |
20 | 18 | import edu.wpi.first.wpilibj.XboxController; |
21 | 19 | import edu.wpi.first.wpilibj2.command.Command; |
22 | | -import edu.wpi.first.wpilibj2.command.Commands; |
23 | 20 | import edu.wpi.first.wpilibj2.command.button.CommandPS5Controller; |
24 | 21 | import edu.wpi.first.wpilibj2.command.button.CommandXboxController; |
25 | | -import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine; |
26 | | -import frc.robot.commands.DriveCommands; |
27 | | -import frc.robot.generated.TunerConstants; |
28 | | -import frc.robot.subsystems.drive.Drive; |
29 | | -import frc.robot.subsystems.drive.GyroIO; |
30 | | -import frc.robot.subsystems.drive.GyroIOPigeon2; |
31 | | -import frc.robot.subsystems.drive.ModuleIO; |
32 | | -import frc.robot.subsystems.drive.ModuleIOSim; |
33 | | -import frc.robot.subsystems.drive.ModuleIOTalonFX; |
| 22 | +import frc.robot.subsystems.elevator.Elevator; |
| 23 | +import frc.robot.subsystems.elevator.ElevatorIOSim; |
| 24 | +import frc.robot.subsystems.elevator.ElevatorIOTalonFX; |
34 | 25 | import frc.robot.subsystems.rollers.Rollers; |
35 | 26 | import frc.robot.subsystems.rollers.RollersIOSim; |
36 | 27 | import frc.robot.subsystems.rollers.RollersIOSparkMax; |
|
43 | 34 | * subsystems, commands, and button mappings) should be declared here. |
44 | 35 | */ |
45 | 36 | public class RobotContainer { |
46 | | - // Subsystems |
47 | | - private final Drive drive; |
48 | | - public final Rollers rollers; |
| 37 | + // Subsystems |
| 38 | + public final Rollers rollers; |
| 39 | + public final Elevator elevator; |
49 | 40 |
|
50 | | - // Controller |
51 | | - public CommandXboxController controller = new CommandXboxController(0); |
52 | | - public static CommandPS5Controller operatorController = new CommandPS5Controller(1); |
| 41 | + // Controller |
| 42 | + public CommandXboxController controller = new CommandXboxController(0); |
| 43 | + public static CommandPS5Controller operatorController = new CommandPS5Controller(1); |
53 | 44 |
|
54 | | - // Dashboard inputs |
55 | | - private final LoggedDashboardChooser<Command> autoChooser; |
| 45 | + // Dashboard inputs |
| 46 | + private final LoggedDashboardChooser<Command> autoChooser; |
56 | 47 |
|
57 | | - /** The container for the robot. Contains subsystems, OI devices, and commands. */ |
58 | | - public RobotContainer() { |
59 | | - switch (Constants.currentMode) { |
60 | | - case REAL: |
61 | | - // Real robot, instantiate hardware IO implementations |
62 | | - drive = |
63 | | - new Drive( |
64 | | - new GyroIOPigeon2(), |
65 | | - new ModuleIOTalonFX(TunerConstants.FrontLeft), |
66 | | - new ModuleIOTalonFX(TunerConstants.FrontRight), |
67 | | - new ModuleIOTalonFX(TunerConstants.BackLeft), |
68 | | - new ModuleIOTalonFX(TunerConstants.BackRight)); |
| 48 | + /** The container for the robot. Contains subsystems, OI devices, and commands. */ |
| 49 | + public RobotContainer() { |
| 50 | + switch (Constants.currentMode) { |
| 51 | + case REAL: |
| 52 | + // Real robot, instantiate hardware IO implementations |
| 53 | + rollers = new Rollers(new RollersIOSparkMax()); |
| 54 | + elevator = new Elevator(new ElevatorIOTalonFX()); |
69 | 55 |
|
70 | | - rollers = new Rollers(new RollersIOSparkMax()); |
| 56 | + break; |
71 | 57 |
|
72 | | - break; |
| 58 | + case SIM: |
| 59 | + // Sim robot, instantiate physics sim IO implementations |
| 60 | + rollers = new Rollers(new RollersIOSim()); |
| 61 | + elevator = new Elevator(new ElevatorIOSim()); |
73 | 62 |
|
74 | | - case SIM: |
75 | | - // Sim robot, instantiate physics sim IO implementations |
76 | | - drive = |
77 | | - new Drive( |
78 | | - new GyroIO() {}, |
79 | | - new ModuleIOSim(TunerConstants.FrontLeft), |
80 | | - new ModuleIOSim(TunerConstants.FrontRight), |
81 | | - new ModuleIOSim(TunerConstants.BackLeft), |
82 | | - new ModuleIOSim(TunerConstants.BackRight)); |
| 63 | + break; |
83 | 64 |
|
84 | | - rollers = new Rollers(new RollersIOSim()); |
| 65 | + default: |
| 66 | + // Replayed robot, disable IO implementations |
| 67 | + rollers = new Rollers(null); |
| 68 | + elevator = new Elevator(null); |
85 | 69 |
|
86 | | - break; |
87 | | - |
88 | | - default: |
89 | | - // Replayed robot, disable IO implementations |
90 | | - drive = |
91 | | - new Drive( |
92 | | - new GyroIO() {}, |
93 | | - new ModuleIO() {}, |
94 | | - new ModuleIO() {}, |
95 | | - new ModuleIO() {}, |
96 | | - new ModuleIO() {}); |
97 | | - |
98 | | - rollers = new Rollers(null); |
99 | | - |
100 | | - break; |
101 | | - } |
102 | | - |
103 | | - // Set up auto routines |
104 | | - autoChooser = new LoggedDashboardChooser<>("Auto Choices", AutoBuilder.buildAutoChooser()); |
105 | | - |
106 | | - // Set up SysId routines |
107 | | - autoChooser.addOption( |
108 | | - "Drive Wheel Radius Characterization", DriveCommands.wheelRadiusCharacterization(drive)); |
109 | | - autoChooser.addOption( |
110 | | - "Drive Simple FF Characterization", DriveCommands.feedforwardCharacterization(drive)); |
111 | | - autoChooser.addOption( |
112 | | - "Drive SysId (Quasistatic Forward)", |
113 | | - drive.sysIdQuasistatic(SysIdRoutine.Direction.kForward)); |
114 | | - autoChooser.addOption( |
115 | | - "Drive SysId (Quasistatic Reverse)", |
116 | | - drive.sysIdQuasistatic(SysIdRoutine.Direction.kReverse)); |
117 | | - autoChooser.addOption( |
118 | | - "Drive SysId (Dynamic Forward)", drive.sysIdDynamic(SysIdRoutine.Direction.kForward)); |
119 | | - autoChooser.addOption( |
120 | | - "Drive SysId (Dynamic Reverse)", drive.sysIdDynamic(SysIdRoutine.Direction.kReverse)); |
121 | | - |
122 | | - // Configure the button bindings |
123 | | - configureButtonBindings(); |
| 70 | + break; |
124 | 71 | } |
125 | 72 |
|
126 | | - /** |
127 | | - * Use this method to define your button->command mappings. Buttons can be created by |
128 | | - * instantiating a {@link GenericHID} or one of its subclasses ({@link |
129 | | - * edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link |
130 | | - * edu.wpi.first.wpilibj2.command.button.JoystickButton}. |
131 | | - */ |
132 | | - private void configureButtonBindings() { |
133 | | - // Default command, normal field-relative drive |
134 | | - drive.setDefaultCommand( |
135 | | - DriveCommands.joystickDrive( |
136 | | - drive, |
137 | | - () -> -controller.getLeftY(), |
138 | | - () -> -controller.getLeftX(), |
139 | | - () -> -controller.getRightX())); |
140 | | - |
141 | | - // Lock to 0° when A button is held |
142 | | - controller |
143 | | - .a() |
144 | | - .whileTrue( |
145 | | - DriveCommands.joystickDriveAtAngle( |
146 | | - drive, |
147 | | - () -> -controller.getLeftY(), |
148 | | - () -> -controller.getLeftX(), |
149 | | - () -> new Rotation2d())); |
150 | | - |
151 | | - // Switch to X pattern when X button is pressed |
152 | | - controller.x().onTrue(Commands.runOnce(drive::stopWithX, drive)); |
153 | | - |
154 | | - // Reset gyro to 0° when B button is pressed |
155 | | - controller |
156 | | - .b() |
157 | | - .onTrue( |
158 | | - Commands.runOnce( |
159 | | - () -> |
160 | | - drive.setPose( |
161 | | - new Pose2d(drive.getPose().getTranslation(), new Rotation2d())), |
162 | | - drive) |
163 | | - .ignoringDisable(true)); |
164 | | - } |
165 | | - |
166 | | - /** |
167 | | - * Use this to pass the autonomous command to the main {@link Robot} class. |
168 | | - * |
169 | | - * @return the command to run in autonomous |
170 | | - */ |
171 | | - public Command getAutonomousCommand() { |
172 | | - return autoChooser.get(); |
173 | | - } |
| 73 | + // Set up auto routines |
| 74 | + autoChooser = new LoggedDashboardChooser<>("Auto Choices", AutoBuilder.buildAutoChooser()); |
| 75 | + |
| 76 | + configureButtonBindings(); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Use this method to define your button->command mappings. Buttons can be created by |
| 81 | + * instantiating a {@link GenericHID} or one of its subclasses ({@link |
| 82 | + * edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link |
| 83 | + * edu.wpi.first.wpilibj2.command.button.JoystickButton}. |
| 84 | + */ |
| 85 | + private void configureButtonBindings() {} |
| 86 | + |
| 87 | + /** |
| 88 | + * Use this to pass the autonomous command to the main {@link Robot} class. |
| 89 | + * |
| 90 | + * @return the command to run in autonomous |
| 91 | + */ |
| 92 | + public Command getAutonomousCommand() { |
| 93 | + return autoChooser.get(); |
| 94 | + } |
174 | 95 | } |
0 commit comments