Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the unitless joystick inputs to actual physical units #5451

Conversation

jasonli0616
Copy link
Contributor

Taking the joystick inputs from -1 to 1, multiply them by the max speed (as defined in Constants.java) to get the target speed, rather than using the unitless raw joystick inputs.

This resolves issue #5417.

Taking the joystick inputs from -1 to 1, multiply them by the max speed (defined in Constants.java) to get the specified speed.
@calcmogul
Copy link
Member

calcmogul commented Jul 17, 2023

Here's the corresponding change for C++:

diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp
index 52b25b9cb..60b493e52 100644
--- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp
+++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp
@@ -34,10 +34,9 @@ RobotContainer::RobotContainer() {
   // Turning is controlled by the X axis of the right stick.
   m_drive.SetDefaultCommand(frc2::RunCommand(
       [this] {
-        m_drive.Drive(
-            units::meters_per_second_t{m_driverController.GetLeftY()},
-            units::meters_per_second_t{m_driverController.GetLeftX()},
-            units::radians_per_second_t{m_driverController.GetRightX()}, false);
+        m_drive.Drive(m_driverController.GetLeftY() * kMaxSpeed,
+                      m_driverController.GetLeftX() * kMaxSpeed,
+                      m_driverController.GetRightX() * kMaxAngularSpeed, false);
       },
       {&m_drive}));
 }

Copy link
Member

@calcmogul calcmogul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java side looks good, but needs C++.

Taking the joystick inputs from -1 to 1, multiply them by the max speed to get the specified speed.
@jasonli0616
Copy link
Contributor Author

jasonli0616 commented Jul 17, 2023

Made the corresponding change in C++

@calcmogul
Copy link
Member

/format

calcmogul
calcmogul previously approved these changes Jul 17, 2023
@calcmogul
Copy link
Member

/format

calcmogul
calcmogul previously approved these changes Jul 17, 2023
@jasonli0616
Copy link
Contributor Author

jasonli0616 commented Jul 17, 2023

The build (GitHub Actions check) was failing in cpp.

I used kMaxSpeed and kMaxAngularSpeed instead of AutoConstants::kMaxSpeed and AutoConstants::kMaxAngularSpeed.

Should be fixed now in the commit.

@calcmogul
Copy link
Member

/format

@PeterJohnson PeterJohnson merged commit 9b8d90b into wpilibsuite:main Jul 18, 2023
21 checks passed
@jasonli0616 jasonli0616 deleted the swerve-controller-example-fix-manual-drive-units branch February 5, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Swerve controller command example uses unitless joystick inputs for velocity parameters
3 participants