-
Notifications
You must be signed in to change notification settings - Fork 1
/
robotcontainer.py
321 lines (276 loc) · 13 KB
/
robotcontainer.py
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
from commands2 import WaitCommand
import wpilib
from wpimath.geometry import Pose2d
import commands2
import commands2.button
import constants
from commands.resetdrive import ResetDrive
from commands.complexauto import ComplexAuto
from commands.indexer.feedforward import FeedForward
from commands.indexer.holdball import HoldBall
from commands.drivedistance import DriveDistance
from commands.drivetotarget import DriveToTarget
from commands.targetrelativedrive import TargetRelativeDrive
from commands.robotrelativedrive import RobotRelativeDrive
from commands.absoluterelativedrive import AbsoluteRelativeDrive
from commands.climber.pivotclimbersformid import PivotBothClimbersToVertical
from commands.climber.moveclimberstomiddlerungcaptureposition import (
MoveBothClimbersToMiddleRungCapturePositionMovements,
)
from commands.climber.moveclimberstomiddlerunghangposition import (
MoveBothClimbersToMiddleRungHangPosition,
)
from commands.climber.holdcimbersposition import (
HoldBothClimbersPosition,
HoldLeftClimberPosition,
)
from commands.climber.moveclimberstofullhangingposition import (
MoveLeftClimberToFullHangingPosition,
MoveRightClimberToFullHangingPosition,
)
from commands.climber.moveclimberstonextrungcaptureposition import (
MoveLeftClimberToNextRungCapturePosition,
MoveRightClimberToNextRungCapturePosition,
)
from commands.climber.holdcimbersposition import HoldRightClimberPosition
from commands.reverseballpath import ReverseBallPath
from commands.normalballpath import NormalBallPath
from commands.shootball import ShootBall
from commands.defensestate import DefenseState
from commands.intake.autoballintake import AutoBallIntake
from commands.intake.deployintake import DeployIntake
from commands.intake.retractintake import RetractIntake
from commands.shooter.aimshootertotarget import AimShooterToTarget
from commands.shooter.aimshootermanual import AimShooterManually
from commands.shooter.stopaimsystem import StopMovingParts
from commands.shooter.decreaseshooterspeed import DecreaseShooterSpeed
from commands.shooter.increaseshooterspeed import IncreaseShooterSpeed
from commands.shooter.resetshooteroffset import ResetShooterOffset
from commands.auto.fivebrstandard import FiveBRStandard
from commands.auto.fourblnoninvasive import FourBLNoninvasive
from commands.auto.twoblhangerouttake import TwoBLHangerOuttake
from commands.auto.threebrstandard import ThreeBRStandard
from subsystems.drivesubsystem import DriveSubsystem
from subsystems.visionsubsystem import VisionSubsystem
from subsystems.climbers.leftclimbersubsystem import LeftClimber
from subsystems.climbers.rightclimbersubsystem import RightClimber
from subsystems.intakesubsystem import IntakeSubsystem
from subsystems.indexersubsystem import IndexerSubsystem
from subsystems.shootersubsystem import ShooterSubsystem
from subsystems.lightsubsystem import LightSubsystem
from operatorinterface import OperatorInterface
from util.helpfultriggerwrappers import SmartDashboardButton
class RobotContainer:
"""
This class is where the bulk of the robot should be declared. Since Command-based is a
"declarative" paradigm, very little robot logic should actually be handled in the :class:`.Robot`
periodic methods (other than the scheduler calls). Instead, the structure of the robot (including
subsystems, commands, and button mappings) should be declared here.
"""
def __init__(self) -> None:
# The operator interface (driver controls)
self.operatorInterface = OperatorInterface()
# The robot's subsystems
self.drive = DriveSubsystem()
self.vision = VisionSubsystem()
self.leftClimber = LeftClimber()
self.rightClimber = RightClimber()
self.shooter = ShooterSubsystem()
self.intake = IntakeSubsystem()
self.indexer = IndexerSubsystem()
self.lights = LightSubsystem()
# Autonomous routines
# A simple auto routine that drives forward a specified distance, and then stops.
self.simpleAuto = commands2.ParallelCommandGroup(
commands2.SequentialCommandGroup(
ResetDrive(self.drive),
HoldBall(self.indexer),
DeployIntake(self.intake),
DriveDistance(
4 * constants.kWheelCircumference,
constants.kAutoDriveSpeedFactor,
DriveDistance.Axis.X,
self.drive,
),
RetractIntake(self.intake),
commands2.WaitCommand(2),
FeedForward(self.indexer),
commands2.WaitCommand(2),
HoldBall(self.indexer),
),
AimShooterToTarget(self.shooter),
)
# A complex auto routine that drives to the target, drives forward, waits, drives back
self.complexAuto = ComplexAuto(self.drive)
# A routine that drives to the target with a given offset
self.driveToTarget = DriveToTarget(self.drive, constants.kAutoTargetOffset)
# A routine that follows a set trajectory
self.fiveBRStandard = FiveBRStandard(
self.shooter, self.drive, self.intake, self.indexer
)
self.twoBLHangerOuttake = TwoBLHangerOuttake(
self.shooter, self.drive, self.intake, self.indexer
)
self.fourBLNoninvasive = FourBLNoninvasive(
self.shooter, self.drive, self.intake, self.indexer
)
self.threeBRStandard = ThreeBRStandard(
self.shooter, self.drive, self.intake, self.indexer
)
# Chooser
self.chooser = wpilib.SendableChooser()
# Add commands to the autonomous command chooser
self.chooser.addOption("Complex Auto", self.complexAuto)
self.chooser.addOption("Target Auto", self.driveToTarget)
self.chooser.addOption(
"2 Ball Left Hanger Outtake Auto", self.twoBLHangerOuttake
)
self.chooser.addOption("4 Ball Left Noninvasive Auto", self.fourBLNoninvasive)
self.chooser.addOption("5 Ball Right Standard Auto", self.fiveBRStandard)
self.chooser.addOption("3 Ball Right Standard Auto", self.threeBRStandard)
self.chooser.setDefaultOption("Simple Auto", self.simpleAuto)
# Put the chooser on the dashboard
wpilib.SmartDashboard.putData("Autonomous", self.chooser)
self.configureButtonBindings()
self.drive.setDefaultCommand(
AbsoluteRelativeDrive(
self.drive,
lambda: self.operatorInterface.chassisControls.forwardsBackwards()
* constants.kNormalSpeedMultiplier,
lambda: self.operatorInterface.chassisControls.sideToSide()
* constants.kNormalSpeedMultiplier,
self.operatorInterface.chassisControls.rotationX,
self.operatorInterface.chassisControls.rotationY,
)
)
self.rightClimber.setDefaultCommand(HoldRightClimberPosition(self.rightClimber))
self.leftClimber.setDefaultCommand(HoldLeftClimberPosition(self.leftClimber))
self.shooter.setDefaultCommand(AimShooterToTarget(self.shooter))
def configureButtonBindings(self):
"""
Use this method to define your button->command mappings. Buttons can be created by
instantiating a :GenericHID or one of its subclasses (Joystick or XboxController),
and then passing it to a JoystickButton.
"""
commands2.button.JoystickButton(
*self.operatorInterface.deployIntakeControl,
).whenHeld(DeployIntake(self.intake)).whenReleased(RetractIntake(self.intake))
(
commands2.button.JoystickButton(
*self.operatorInterface.deployIntakeControl,
).and_(
commands2.button.JoystickButton(
*self.operatorInterface.reverseBallPath,
)
)
).whenActive(ReverseBallPath(self.intake, self.indexer))
(
commands2.button.JoystickButton(
*self.operatorInterface.deployIntakeControl,
).and_(
commands2.button.JoystickButton(
*self.operatorInterface.reverseBallPath,
).not_()
)
).whenActive(
NormalBallPath(self.intake, self.indexer)
) # when let go of just the reverse button, go back to normal ball path
commands2.button.JoystickButton(*self.operatorInterface.turboSpeed).whileHeld(
AbsoluteRelativeDrive(
self.drive,
lambda: self.operatorInterface.chassisControls.forwardsBackwards()
* constants.kTurboSpeedMultiplier,
lambda: self.operatorInterface.chassisControls.sideToSide()
* constants.kTurboSpeedMultiplier,
self.operatorInterface.chassisControls.rotationX,
self.operatorInterface.chassisControls.rotationY,
)
)
commands2.button.JoystickButton(
*self.operatorInterface.fieldRelativeCoordinateModeControl
).toggleWhenPressed(
RobotRelativeDrive(
self.drive,
self.operatorInterface.chassisControls.forwardsBackwards,
self.operatorInterface.chassisControls.sideToSide,
self.operatorInterface.chassisControls.rotationX,
)
)
commands2.button.JoystickButton(
*self.operatorInterface.targetRelativeCoordinateModeControl
).whileHeld(
TargetRelativeDrive(
self.drive,
self.operatorInterface.chassisControls.forwardsBackwards,
self.operatorInterface.chassisControls.sideToSide,
self.operatorInterface.chassisControls.rotationX,
)
)
commands2.button.JoystickButton(*self.operatorInterface.resetGyro).whenPressed(
ResetDrive(self.drive, Pose2d(0, 0, 0))
)
commands2.button.JoystickButton(
*self.operatorInterface.defenseStateControl
).whileHeld(DefenseState(self.drive))
commands2.button.JoystickButton(
*self.operatorInterface.driveToTargetControl
).whenHeld(DriveToTarget(self.drive, constants.kAutoTargetOffset))
commands2.button.JoystickButton(
*self.operatorInterface.pivotBothClimbers
).whenPressed(
commands2.SequentialCommandGroup(
WaitCommand(constants.kClimberPauseBeforeMovement),
PivotBothClimbersToVertical(self.leftClimber, self.rightClimber),
),
).whenPressed(
StopMovingParts(self.indexer, self.shooter)
)
commands2.button.JoystickButton(
*self.operatorInterface.moveBothClimbersToMiddleRungCapturePosition
).whenPressed(
MoveBothClimbersToMiddleRungCapturePositionMovements(
self.leftClimber, self.rightClimber
)
)
commands2.button.JoystickButton(
*self.operatorInterface.moveBothClimbersToMiddleRungHangPosition
).whenPressed(
MoveBothClimbersToMiddleRungHangPosition(
self.leftClimber, self.rightClimber
)
)
commands2.button.JoystickButton(
*self.operatorInterface.holdBothClimbersPosition
).whenPressed(HoldBothClimbersPosition(self.leftClimber, self.rightClimber))
commands2.button.JoystickButton(
*self.operatorInterface.leftClimberToNextRungCapturePosition
).whenPressed(MoveLeftClimberToNextRungCapturePosition(self.leftClimber))
commands2.button.JoystickButton(
*self.operatorInterface.rightClimberToNextRungCapturePosition
).whenPressed(MoveRightClimberToNextRungCapturePosition(self.rightClimber))
commands2.button.JoystickButton(
*self.operatorInterface.leftClimberToHangingPosition
).whenPressed(MoveLeftClimberToFullHangingPosition(self.leftClimber))
commands2.button.JoystickButton(
*self.operatorInterface.rightClimberToHangingPosition
).whenPressed(MoveRightClimberToFullHangingPosition(self.rightClimber))
commands2.button.JoystickButton(
*self.operatorInterface.autoBallIntakeControl
).whenHeld(AutoBallIntake(self.drive, self.intake))
commands2.button.JoystickButton(*self.operatorInterface.shootBall).whenHeld(
ShootBall(self.indexer)
).whenReleased(HoldBall(self.indexer))
SmartDashboardButton(constants.kShootingManualModeKey).whileHeld(
AimShooterManually(self.shooter)
)
commands2.button.JoystickButton(
*self.operatorInterface.increaseSpeed
).whenPressed(IncreaseShooterSpeed())
commands2.button.JoystickButton(
*self.operatorInterface.decreaseSpeed
).whenPressed(DecreaseShooterSpeed())
commands2.button.JoystickButton(*self.operatorInterface.resetSpeed).whenPressed(
ResetShooterOffset()
)
def getAutonomousCommand(self) -> commands2.Command:
return self.chooser.getSelected()