Skip to content

Commit

Permalink
Improve formatting
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler Veness <[email protected]>
  • Loading branch information
KangarooKoala and calcmogul committed Jan 16, 2025
1 parent 8dfe283 commit 0f232fc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,13 @@ public double getMagnitude() {
*/
public double getDirectionRadians() {
// 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 m_hid.getDirectionRadians();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ double CommandJoystick::GetMagnitude() const {

units::radian_t CommandJoystick::GetDirection() const {
// 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 m_hid.GetDirection();
}
9 changes: 7 additions & 2 deletions wpilibc/src/main/native/cpp/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ double Joystick::GetMagnitude() const {

units::radian_t Joystick::GetDirection() const {
// 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 units::radian_t{std::atan2(GetX(), -GetY())};
}
9 changes: 7 additions & 2 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/Joystick.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,13 @@ public double getMagnitude() {
*/
public double getDirectionRadians() {
// 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 Math.atan2(getX(), -getY());
}

Expand Down

0 comments on commit 0f232fc

Please sign in to comment.