-
Notifications
You must be signed in to change notification settings - Fork 0
/
oi.py
133 lines (98 loc) · 5.08 KB
/
oi.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
"""
Ctrl-Z FRC Team 4096
FIRST Robotics Competition 2019
Code for robot "----"
"""
import wpilib
### IMPORTS ###
# Subsystems
# Commands
import commands.drivetrain
import commands.hatch
import commands.cargo
import commands.climber
# Controls
from customcontroller.xbox_command_controller import XboxCommandController
import const
## CONSTANTS ##
class OI:
"""
Operator Input - This class ties together controls and commands.
"""
def __init__(self, robot):
self.robot = robot
# Controllers
# Xbox
self.driver1 = XboxCommandController(0)
self.driver2 = XboxCommandController(1)
self.driver1.RIGHT_JOY_X.setDeadzone(.1)
self.driver1.LEFT_JOY_Y.setDeadzone(.1)
self.driver1.RIGHT_JOY_X.setInverted(True)
self.driver1.addCustomButton('28-30 secs', lambda: 28 < self.robot.driverstation.getMatchTime() < 30
and not self.robot.driverstaion.isAutonomous())
self.driver2.LEFT_JOY_Y.setDeadzone(.1)
self.driver2.LEFT_JOY_Y.setInverted(True)
self.driver2.RIGHT_JOY_Y.setInverted(True)
self.driver2.addCustomButton('Joystick_Up', lambda: self.driver2.RIGHT_JOY_Y() > .9)
self.driver2.addCustomButton('Joystick_Down', lambda: self.driver2.RIGHT_JOY_Y() < -.9)
self.driver2.addCustomButton('Joystick_Left', lambda: self.driver2.RIGHT_JOY_X() < -.9)
self.driver2.addCustomButton('Joystick_Right', lambda: self.driver2.RIGHT_JOY_X() > .9)
self.driver2.addCustomButton('Joystick_None', lambda: abs(self.driver2.RIGHT_JOY_X()) < .3 and abs(self.driver2.RIGHT_JOY_Y()) < .3)
### COMMANDS ###
# DRIVE COMMANDS #
self.drive_command = commands.drivetrain.Drive_With_Tank_Values(
self.robot,
self.driver1.RIGHT_JOY_X,
self.driver1.LEFT_JOY_Y,
)
# HATCH #
self.hatch_command = commands.hatch.Strafe_Carriage(self.robot,
self.driver2.BOTH_TRIGGERS
)
# CARGO #
self.cargo_arm_command = commands.cargo.Run_Cargo_Arm(self.robot,
self.driver2.LEFT_JOY_Y
)
# CLIMBER #
# Set default commands
self.robot.drive.setDefaultCommand(self.drive_command)
self.robot.hatch.setDefaultCommand(self.hatch_command)
# self.robot.cargo.setDefaultCommand(self.cargo_arm_command)
# Controller 1: driver
self.driver1.POV.UP.whenActive(commands.climber.Auto_Stilts_Down(self.robot))
self.driver1.POV.UP.whenInactive(commands.climber.Stop_Stilts_Up_and_Down(self.robot))
self.driver1.Y.whenActive(commands.climber.Run_Both_Stilts_Down(self.robot, speed = 0.4))
self.driver1.Y.whenInactive(commands.climber.Stop_Stilts_Up_and_Down(self.robot))
self.driver1.A.whenActive(commands.climber.Run_Both_Stilts_Up(self.robot, speed = 0.4))
self.driver1.A.whenInactive(commands.climber.Stop_Stilts_Up_and_Down(self.robot))
self.driver1.X.whenActive(commands.climber.Run_Front_Stilts_Up(self.robot, speed = -0.4))
self.driver1.X.whenInactive(commands.climber.Stop_Stilts_Up_and_Down(self.robot))
self.driver1.B.whenActive(commands.climber.Run_Back_Stilts_Up(self.robot, speed = -0.4))
self.driver1.B.whenInactive(commands.climber.Stop_Stilts_Up_and_Down(self.robot))
self.driver1.RIGHT_BUMPER.whenActive(commands.climber.Drive_Front_Climber(self.robot, speed = 1))
self.driver1.RIGHT_BUMPER.whenInactive(commands.climber.Stop_Stilts_Up_and_Down(self.robot))
self.driver1.START.whenActive(lambda: self.robot.limelight.toggle_driver_mode())
self.driver1.customButtons['28-30 secs'].whenActive(lambda: self.driver1.setRumble())
self.driver1.customButtons['28-30 secs'].whenInactive(lambda: self.driver1.setRumble(0))
# Controller 2: everything else
# Cargo...
self.driver2.RIGHT_BUMPER.whenActive(commands.cargo.Run_Cargo_Intake_Inward(self.robot, speed = 1))
self.driver2.RIGHT_BUMPER.whenInactive(commands.cargo.Stop_Cargo_Intake(self.robot))
self.driver2.LEFT_BUMPER.whenActive(commands.cargo.Run_Cargo_Intake_Outward(self.robot, speed = 1))
self.driver2.LEFT_BUMPER.whenInactive(commands.cargo.Stop_Cargo_Intake(self.robot))
self.driver2.START.whenActive(lambda: self.robot.cargo.toggle_manual_mode())
self.driver2.customButtons['Joystick_Up'].whenActive(commands.cargo.Run_Cargo_Arm_Distance(self.robot, 35))
self.driver2.customButtons['Joystick_Down'].whenActive(commands.cargo.Run_Cargo_Arm_Distance(self.robot, 5))
self.driver2.customButtons['Joystick_Left'].whenActive(commands.cargo.Run_Cargo_Arm_Distance(self.robot, 90))
self.driver2.customButtons['Joystick_Right'].whenActive(commands.cargo.Run_Cargo_Arm_Distance(self.robot, 135))
self.driver2.customButtons['Joystick_None'].whenActive(commands.cargo.Stop_Cargo_Arm(self.robot))
# Hatch...
self.driver2.POV.UP.whenActive(commands.hatch.Push_Out_Carriage(self.robot))
self.driver2.POV.DOWN.whenActive(commands.hatch.Pull_In_Carriage(self.robot))
self.driver2.POV.LEFT.whenActive(commands.hatch.Close_Beak(self.robot))
self.driver2.POV.RIGHT.whenActive(commands.hatch.Open_Beak(self.robot))
self.driver2.A.whenActive(commands.hatch.Intake_Hatch(self.robot))
self.driver2.Y.whenActive(commands.hatch.Place_Hatch(self.robot))
self.driver2.B.whenActive(commands.hatch.Auto_Strafe_Carriage_To_Line(self.robot))
self.driver2.X.whenActive(commands.hatch.Auto_Strafe_Carriage(self.robot, 5.5))