-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrobotcontainer.py
91 lines (70 loc) · 3.09 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
import wpilib
import commands2
import commands2.button
import constants
from commands.complexauto import ComplexAuto
from commands.drivedistance import DriveDistance
from commands.defaultdrive import DefaultDrive
from commands.fieldrelativedrive import FieldRelativeDrive
from commands.resetdrive import ResetDrive
from subsystems.drivesubsystem import DriveSubsystem
from operatorinterface import OperatorInterface
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()
# Autonomous routines
# A simple auto routine that drives forward a specified distance, and then stops.
self.simpleAuto = DriveDistance(
constants.kAutoDriveDistance,
constants.kAutoDriveSpeedFactor,
DriveDistance.Axis.X,
self.drive,
)
# A complex auto routine that drives forward, right, back, left
self.complexAuto = ComplexAuto(self.drive)
# Chooser
self.chooser = wpilib.SendableChooser()
# Add commands to the autonomous command chooser
self.chooser.setDefaultOption("Simple Auto", self.simpleAuto)
self.chooser.addOption("Complex Auto", self.complexAuto)
# Put the chooser on the dashboard
wpilib.SmartDashboard.putData("Autonomous", self.chooser)
self.configureButtonBindings()
self.drive.setDefaultCommand(
DefaultDrive(
self.drive,
self.operatorInterface.chassisControls.forwardsBackwards,
self.operatorInterface.chassisControls.sideToSide,
self.operatorInterface.chassisControls.rotation,
)
)
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.coordinateModeControl
).whileHeld(
FieldRelativeDrive(
self.drive,
self.operatorInterface.chassisControls.forwardsBackwards,
self.operatorInterface.chassisControls.sideToSide,
self.operatorInterface.chassisControls.rotation,
)
)
commands2.button.JoystickButton(
*self.operatorInterface.resetSwerveControl
).whenPressed(ResetDrive(self.drive))
def getAutonomousCommand(self) -> commands2.Command:
return self.chooser.getSelected()