Skip to content

Commit e3c8a9e

Browse files
authored
Merge pull request #81 from KangarooKoala/hid-direction-documentation
Improve HID direction documentation (NFC)
2 parents 23a4f87 + 0598434 commit e3c8a9e

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

commands2/button/commandjoystick.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ def getX(self) -> float:
146146
"""
147147
Get the x position of the HID.
148148
149+
This depends on the mapping of the joystick connected to the current port. On most
150+
joysticks, positive is to the right.
151+
149152
:returns: the x position
150153
"""
151154
return self._hid.getX()
@@ -154,6 +157,9 @@ def getY(self) -> float:
154157
"""
155158
Get the y position of the HID.
156159
160+
This depends on the mapping of the joystick connected to the current port. On most
161+
joysticks, positive is to the back.
162+
157163
:returns: the y position
158164
"""
159165
return self._hid.getY()
@@ -186,24 +192,34 @@ def getThrottle(self) -> float:
186192

187193
def getMagnitude(self) -> float:
188194
"""
189-
Get the magnitude of the direction vector formed by the joystick's current position relative to
190-
its origin.
195+
Get the magnitude of the vector formed by the joystick's current position relative to its
196+
origin.
191197
192198
:returns: The magnitude of the direction vector
193199
"""
194200
return self._hid.getMagnitude()
195201

196202
def getDirectionRadians(self) -> float:
197203
"""
198-
Get the direction of the vector formed by the joystick and its origin in radians.
204+
Get the direction of the vector formed by the joystick and its origin in radians. 0 is forward
205+
and clockwise is positive. (Straight right is π/2.)
199206
200207
:returns: The direction of the vector in radians
201208
"""
209+
# https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html#joystick-and-controller-coordinate-system
210+
# A positive rotation around the X axis moves the joystick right, and a
211+
# positive rotation around the Y axis moves the joystick backward. When
212+
# treating them as translations, 0 radians is measured from the right
213+
# direction, and angle increases clockwise.
214+
#
215+
# It's rotated 90 degrees CCW (y is negated and the arguments are reversed)
216+
# so that 0 radians is forward.
202217
return self._hid.getDirectionRadians()
203218

204219
def getDirectionDegrees(self) -> float:
205220
"""
206-
Get the direction of the vector formed by the joystick and its origin in degrees.
221+
Get the direction of the vector formed by the joystick and its origin in degrees. 0 is forward
222+
and clockwise is positive. (Straight right is 90.)
207223
208224
:returns: The direction of the vector in degrees
209225
"""

commands2/button/commandps4controller.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -231,31 +231,31 @@ def touchpad(self, loop: Optional[EventLoop] = None) -> Trigger:
231231

232232
def getLeftX(self) -> float:
233233
"""
234-
Get the X axis value of left side of the controller.
234+
Get the X axis value of left side of the controller. Right is positive.
235235
236236
:returns: the axis value.
237237
"""
238238
return self._hid.getLeftX()
239239

240240
def getRightX(self) -> float:
241241
"""
242-
Get the X axis value of right side of the controller.
242+
Get the X axis value of right side of the controller. Right is positive.
243243
244244
:returns: the axis value.
245245
"""
246246
return self._hid.getRightX()
247247

248248
def getLeftY(self) -> float:
249249
"""
250-
Get the Y axis value of left side of the controller.
250+
Get the Y axis value of left side of the controller. Back is positive.
251251
252252
:returns: the axis value.
253253
"""
254254
return self._hid.getLeftY()
255255

256256
def getRightY(self) -> float:
257257
"""
258-
Get the Y axis value of right side of the controller.
258+
Get the Y axis value of right side of the controller. Back is positive.
259259
260260
:returns: the axis value.
261261
"""

commands2/button/commandxboxcontroller.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -213,31 +213,31 @@ def rightTrigger(
213213

214214
def getLeftX(self) -> float:
215215
"""
216-
Get the X axis value of left side of the controller.
216+
Get the X axis value of left side of the controller. Right is positive.
217217
218218
:returns: The axis value.
219219
"""
220220
return self._hid.getLeftX()
221221

222222
def getRightX(self) -> float:
223223
"""
224-
Get the X axis value of right side of the controller.
224+
Get the X axis value of right side of the controller. Right is positive.
225225
226226
:returns: The axis value.
227227
"""
228228
return self._hid.getRightX()
229229

230230
def getLeftY(self) -> float:
231231
"""
232-
Get the Y axis value of left side of the controller.
232+
Get the Y axis value of left side of the controller. Back is positive.
233233
234234
:returns: The axis value.
235235
"""
236236
return self._hid.getLeftY()
237237

238238
def getRightY(self) -> float:
239239
"""
240-
Get the Y axis value of right side of the controller.
240+
Get the Y axis value of right side of the controller. Back is positive.
241241
242242
:returns: The axis value.
243243
"""

0 commit comments

Comments
 (0)