-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobotcontainer.py
143 lines (115 loc) · 5.05 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
import commands2
import commands2.button
import commands2.cmd
import wpilib
import photonvision
from subsystems.drivesubsystem import DriveSubsystem
from subsystems.camsubsytem import CamSubsystem
from subsystems.armsubsystem import ArmSubsystem
from hud.autonchooser import AutonChooser
from hud.inrange import InRange
from qlib.POVBindings import POVBindings
from commands.ramsete import PathCommand
from commands.balancechargestation import BalanceChargeStation
from autos.toprowandbalance import TopRowAndBalance
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, MyRobot) -> None:
self.cam_subsystem = CamSubsystem()
self.drive_subsystem = DriveSubsystem(MyRobot, self.cam_subsystem)
self.arm_subsystem = ArmSubsystem()
self.auton_chooser = AutonChooser()
# self.inrange = InRange(self.drive_subsystem)
self.balanceCommand = BalanceChargeStation(self.drive_subsystem)
self.driver_controller = commands2.button.CommandJoystick(0)
self.operator_controller = commands2.button.CommandJoystick(1)
self.drive_subsystem.setDefaultCommand(
commands2.cmd.run(
lambda: self.drive_subsystem.drive(
-self.driver_controller.getY(), -self.driver_controller.getZ()
),
[self.drive_subsystem],
),
)
self.configureButtonBindings()
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.
"""
# self.driver_controller.button(1).whileTrue(self.balanceCommand)
self.operator_controller.button(2).whileTrue(
commands2.cmd.run(
lambda: self.arm_subsystem.swallow(), [self.arm_subsystem]
)
)
self.operator_controller.button(1).whileTrue(
commands2.cmd.run(
lambda: self.arm_subsystem.spit(), [self.arm_subsystem]
)
)
self.operator_controller.button(4).toggleOnTrue(
commands2.cmd.runOnce(
lambda: self.arm_subsystem.changeMode(), [self.arm_subsystem]
)
)
self.operator_controller.button(3).whileTrue(
commands2.cmd.run(
lambda: self.arm_subsystem.stopIntake(), [self.arm_subsystem]
)
)
self.operator_controller.button(8).whileTrue(
commands2.cmd.run(
lambda: self.arm_subsystem.topRow(), [self.arm_subsystem]
)
)
self.operator_controller.button(10).whileTrue(
commands2.cmd.run(
lambda: self.arm_subsystem.midRow(), [self.arm_subsystem]
)
)
self.operator_controller.button(12).whileTrue(
commands2.cmd.run(
lambda: self.arm_subsystem.retract(), [self.arm_subsystem]
)
)
self.operator_controller.button(7).whileTrue(
commands2.cmd.run(
lambda: self.arm_subsystem.humanPlayer(), [self.arm_subsystem]
)
)
commands2.Trigger(condition= lambda: POVBindings.POVUpBinding(self.operator_controller.getPOV())).whileTrue(
commands2.cmd.run(
lambda: self.arm_subsystem.raiseArmManual(), [self.arm_subsystem]
).beforeStarting(
lambda: self.arm_subsystem.disable(), [self.arm_subsystem]
)
)
commands2.Trigger(condition= lambda: POVBindings.POVDownBinding(self.operator_controller.getPOV())).whileTrue(
commands2.cmd.run(
lambda: self.arm_subsystem.retractArmManual(), [self.arm_subsystem]
).beforeStarting(
lambda: self.arm_subsystem.disable(), [self.arm_subsystem]
)
)
self.operator_controller.button(6).whileTrue(
commands2.cmd.run(
lambda: self.arm_subsystem.stopArmManual(), [self.arm_subsystem]
).beforeStarting(
lambda: self.arm_subsystem.disable(), [self.arm_subsystem]
)
)
self.operator_controller.button(5).whileTrue(
commands2.cmd.runOnce(
lambda: self.arm_subsystem.enable(), [self.arm_subsystem]
)
)
def getAutonomousCommand(self) -> commands2.Command:
# return PathCommand(self.drive_subsystem, self.auton_chooser.generatePath()).getRamseteCommand()
return TopRowAndBalance(self.drive_subsystem, self.arm_subsystem,self.auton_chooser)