-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathoperatorinterface.py
More file actions
102 lines (83 loc) · 2.8 KB
/
Copy pathoperatorinterface.py
File metadata and controls
102 lines (83 loc) · 2.8 KB
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
from wpilib import Joystick, XboxController
from wpilib.interfaces import GenericHID
import typing
import constants
AnalogInput = typing.Callable[[], float]
def Deadband(input: AnalogInput, deadband: float) -> AnalogInput:
def withDeadband() -> float:
value = input()
if abs(value) <= deadband:
return 0
else:
return value
return withDeadband
def Invert(input: AnalogInput) -> AnalogInput:
def invert() -> float:
return -1 * input()
return invert
class HolonomicInput:
def __init__(
self,
forwardsBackwards: AnalogInput,
sideToSide: AnalogInput,
rotation: AnalogInput,
) -> None:
self.forwardsBackwards = forwardsBackwards
self.sideToSide = sideToSide
self.rotation = rotation
class OperatorInterface:
"""
The controls that the operator(s)/driver(s) interact with
"""
def __init__(self) -> None:
self.xboxController = XboxController(constants.kXboxControllerPort)
self.translationController = Joystick(constants.kTranslationControllerPort)
self.rotationController = Joystick(constants.kRotationControllerPort)
self.coordinateModeControl = (
self.xboxController,
XboxController.Button.kRightBumper,
)
self.resetSwerveControl = (
self.xboxController,
XboxController.Button.kX,
)
# self.chassisControls = HolonomicInput(
# Invert(
# Deadband(
# lambda: self.translationController.getLeftY(GenericHID.Hand.kLeftHand),
# constants.kKeyboardJoystickDeadband,
# )
# ),
# Invert(
# Deadband(
# lambda: self.translationController.getLeftX(GenericHID.Hand.kLeftHand),
# constants.kKeyboardJoystickDeadband,
# )
# ),
# Invert(
# Deadband(
# lambda: self.rotationController.getLeftX(GenericHID.Hand.kRightHand),
# constants.kKeyboardJoystickDeadband,
# )
# ),
# )
self.chassisControls = HolonomicInput(
Invert(
Deadband(
lambda: self.xboxController.getLeftY(),
constants.kXboxJoystickDeadband,
)
),
Invert(
Deadband(
lambda: self.xboxController.getLeftX(),
constants.kXboxJoystickDeadband,
)
),
Invert(
Deadband(
lambda: self.xboxController.getRightX(),
constants.kXboxJoystickDeadband,
)
),
)