-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcommandjoystick.py
210 lines (158 loc) · 6.02 KB
/
commandjoystick.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
# validated: 2024-01-20 DS 92aecab2ef05 button/CommandJoystick.java
from typing import Optional
from wpilib import Joystick
from wpilib.event import EventLoop
from ..commandscheduler import CommandScheduler
from .commandgenerichid import CommandGenericHID
from .trigger import Trigger
class CommandJoystick(CommandGenericHID):
"""
A version of :class:`wpilib.Joystick` with :class:`.Trigger` factories for command-based.
"""
_hid: Joystick
def __init__(self, port: int):
"""
Construct an instance of a controller.
:param port: The port index on the Driver Station that the controller is plugged into.
"""
super().__init__(port)
self._hid = Joystick(port)
def getHID(self) -> Joystick:
"""
Get the underlying GenericHID object.
:returns: the wrapped GenericHID object
"""
return self._hid
def trigger(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs an event instance around the trigger button's digital signal.
:param loop: the event loop instance to attach the event to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: an event instance representing the trigger button's digital signal attached to the
given loop.
"""
if loop is None:
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
return Trigger(loop, lambda: self._hid.getTrigger())
def top(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs an event instance around the top button's digital signal.
:param loop: the event loop instance to attach the event to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: an event instance representing the top button's digital signal attached to the given
loop.
"""
if loop is None:
loop = CommandScheduler.getInstance().getDefaultButtonLoop()
return Trigger(loop, lambda: self._hid.getTop())
def setXChannel(self, channel: int):
"""
Set the channel associated with the X axis.
:param channel: The channel to set the axis to.
"""
self._hid.setXChannel(channel)
def setYChannel(self, channel: int):
"""
Set the channel associated with the Y axis.
:param channel: The channel to set the axis to.
"""
self._hid.setYChannel(channel)
def setZChannel(self, channel: int):
"""
Set the channel associated with the Z axis.
:param channel: The channel to set the axis to.
"""
self._hid.setZChannel(channel)
def setThrottleChannel(self, channel: int):
"""
Set the channel associated with the throttle axis.
:param channel: The channel to set the axis to.
"""
self._hid.setThrottleChannel(channel)
def setTwistChannel(self, channel: int):
"""
Set the channel associated with the twist axis.
:param channel: The channel to set the axis to.
"""
self._hid.setTwistChannel(channel)
def getXChannel(self) -> int:
"""
Get the channel currently associated with the X axis.
:returns: The channel for the axis.
"""
return self._hid.getXChannel()
def getYChannel(self) -> int:
"""
Get the channel currently associated with the Y axis.
:returns: The channel for the axis.
"""
return self._hid.getYChannel()
def getZChannel(self) -> int:
"""
Get the channel currently associated with the Z axis.
:returns: The channel for the axis.
"""
return self._hid.getZChannel()
def getTwistChannel(self) -> int:
"""
Get the channel currently associated with the twist axis.
:returns: The channel for the axis.
"""
return self._hid.getTwistChannel()
def getThrottleChannel(self) -> int:
"""
Get the channel currently associated with the throttle axis.
:returns: The channel for the axis.
"""
return self._hid.getThrottleChannel()
def getX(self) -> float:
"""
Get the x position of the HID.
:returns: the x position
"""
return self._hid.getX()
def getY(self) -> float:
"""
Get the y position of the HID.
:returns: the y position
"""
return self._hid.getY()
def getZ(self) -> float:
"""
Get the z position of the HID.
:returns: the z position
"""
return self._hid.getZ()
def getTwist(self) -> float:
"""
Get the twist value of the current joystick. This depends on the mapping of the joystick
connected to the current port.
:returns: The Twist value of the joystick.
"""
return self._hid.getTwist()
def getThrottle(self) -> float:
"""
Get the throttle value of the current joystick. This depends on the mapping of the joystick
connected to the current port.
:returns: The Throttle value of the joystick.
"""
return self._hid.getThrottle()
def getMagnitude(self) -> float:
"""
Get the magnitude of the direction vector formed by the joystick's current position relative to
its origin.
:returns: The magnitude of the direction vector
"""
return self._hid.getMagnitude()
def getDirectionRadians(self) -> float:
"""
Get the direction of the vector formed by the joystick and its origin in radians.
:returns: The direction of the vector in radians
"""
return self._hid.getDirectionRadians()
def getDirectionDegrees(self) -> float:
"""
Get the direction of the vector formed by the joystick and its origin in degrees.
:returns: The direction of the vector in degrees
"""
return self._hid.getDirectionDegrees()