[examples] Convert the unitless joystick inputs to actual physical units (#5451)

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 commit is contained in:
Jason
2023-07-17 20:18:34 -04:00
committed by GitHub
parent 1f6428ab63
commit 9b8d90b852
2 changed files with 15 additions and 6 deletions

View File

@@ -35,9 +35,13 @@ RobotContainer::RobotContainer() {
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);
// Multiply by max speed to map the joystick unitless inputs to
// actual units. This will map the [-1, 1] to [max speed backwards,
// max speed forwards], converting them to actual units.
m_driverController.GetLeftY() * AutoConstants::kMaxSpeed,
m_driverController.GetLeftX() * AutoConstants::kMaxSpeed,
m_driverController.GetRightX() * AutoConstants::kMaxAngularSpeed,
false);
},
{&m_drive}));
}