From 092edf970f91e1d4a64d91a048e2b94e238a9891 Mon Sep 17 00:00:00 2001 From: Joseph Eng Date: Sun, 12 Jan 2025 17:57:30 -0800 Subject: [PATCH 1/2] Improve HID direction documentation --- commands2/button/commandjoystick.py | 19 +++++++++++++++---- commands2/button/commandps4controller.py | 8 ++++---- commands2/button/commandxboxcontroller.py | 8 ++++---- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/commands2/button/commandjoystick.py b/commands2/button/commandjoystick.py index 909fb00b..4a956101 100644 --- a/commands2/button/commandjoystick.py +++ b/commands2/button/commandjoystick.py @@ -146,6 +146,9 @@ def getX(self) -> float: """ Get the x position of the HID. + This depends on the mapping of the joystick connected to the current port. On most + joysticks, positive is to the right. + :returns: the x position """ return self._hid.getX() @@ -154,6 +157,9 @@ def getY(self) -> float: """ Get the y position of the HID. + This depends on the mapping of the joystick connected to the current port. On most + joysticks, positive is to the back. + :returns: the y position """ return self._hid.getY() @@ -186,8 +192,8 @@ def getThrottle(self) -> float: def getMagnitude(self) -> float: """ - Get the magnitude of the direction vector formed by the joystick's current position relative to - its origin. + Get the magnitude of the vector formed by the joystick's current position relative to its + origin. :returns: The magnitude of the direction vector """ @@ -195,15 +201,20 @@ def getMagnitude(self) -> float: def getDirectionRadians(self) -> float: """ - Get the direction of the vector formed by the joystick and its origin in radians. + Get the direction of the vector formed by the joystick and its origin in radians. 0 is forward + and clockwise is positive. (Straight right is π/2.) :returns: The direction of the vector in radians """ + # https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html#joystick-and-controller-coordinate-system + # +X is right and +Y is back, so 0 radians is right and CW is positive. Rotate by 90 degrees + # CCW to make 0 radians forward and CW positive. return self._hid.getDirectionRadians() def getDirectionDegrees(self) -> float: """ - Get the direction of the vector formed by the joystick and its origin in degrees. + Get the direction of the vector formed by the joystick and its origin in degrees. 0 is forward + and clockwise is positive. (Straight right is 90.) :returns: The direction of the vector in degrees """ diff --git a/commands2/button/commandps4controller.py b/commands2/button/commandps4controller.py index 562839f9..8703ef82 100644 --- a/commands2/button/commandps4controller.py +++ b/commands2/button/commandps4controller.py @@ -231,7 +231,7 @@ def touchpad(self, loop: Optional[EventLoop] = None) -> Trigger: def getLeftX(self) -> float: """ - Get the X axis value of left side of the controller. + Get the X axis value of left side of the controller. Right is positive. :returns: the axis value. """ @@ -239,7 +239,7 @@ def getLeftX(self) -> float: def getRightX(self) -> float: """ - Get the X axis value of right side of the controller. + Get the X axis value of right side of the controller. Right is positive. :returns: the axis value. """ @@ -247,7 +247,7 @@ def getRightX(self) -> float: def getLeftY(self) -> float: """ - Get the Y axis value of left side of the controller. + Get the Y axis value of left side of the controller. Back is positive. :returns: the axis value. """ @@ -255,7 +255,7 @@ def getLeftY(self) -> float: def getRightY(self) -> float: """ - Get the Y axis value of right side of the controller. + Get the Y axis value of right side of the controller. Back is positive. :returns: the axis value. """ diff --git a/commands2/button/commandxboxcontroller.py b/commands2/button/commandxboxcontroller.py index 54880810..926883c6 100644 --- a/commands2/button/commandxboxcontroller.py +++ b/commands2/button/commandxboxcontroller.py @@ -213,7 +213,7 @@ def rightTrigger( def getLeftX(self) -> float: """ - Get the X axis value of left side of the controller. + Get the X axis value of left side of the controller. Right is positive. :returns: The axis value. """ @@ -221,7 +221,7 @@ def getLeftX(self) -> float: def getRightX(self) -> float: """ - Get the X axis value of right side of the controller. + Get the X axis value of right side of the controller. Right is positive. :returns: The axis value. """ @@ -229,7 +229,7 @@ def getRightX(self) -> float: def getLeftY(self) -> float: """ - Get the Y axis value of left side of the controller. + Get the Y axis value of left side of the controller. Back is positive. :returns: The axis value. """ @@ -237,7 +237,7 @@ def getLeftY(self) -> float: def getRightY(self) -> float: """ - Get the Y axis value of right side of the controller. + Get the Y axis value of right side of the controller. Back is positive. :returns: The axis value. """ From 059843416315d929cd440262d1640be94714b848 Mon Sep 17 00:00:00 2001 From: Joseph Eng Date: Tue, 14 Jan 2025 16:50:46 -0800 Subject: [PATCH 2/2] Update comment --- commands2/button/commandjoystick.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/commands2/button/commandjoystick.py b/commands2/button/commandjoystick.py index 4a956101..0b43d8d2 100644 --- a/commands2/button/commandjoystick.py +++ b/commands2/button/commandjoystick.py @@ -207,8 +207,13 @@ def getDirectionRadians(self) -> float: :returns: The direction of the vector in radians """ # https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html#joystick-and-controller-coordinate-system - # +X is right and +Y is back, so 0 radians is right and CW is positive. Rotate by 90 degrees - # CCW to make 0 radians forward and CW positive. + # A positive rotation around the X axis moves the joystick right, and a + # positive rotation around the Y axis moves the joystick backward. When + # treating them as translations, 0 radians is measured from the right + # direction, and angle increases clockwise. + # + # It's rotated 90 degrees CCW (y is negated and the arguments are reversed) + # so that 0 radians is forward. return self._hid.getDirectionRadians() def getDirectionDegrees(self) -> float: