Skip to content

Commit

Permalink
[examples] Convert the unitless joystick inputs to actual physical un…
Browse files Browse the repository at this point in the history
…its (#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.
  • Loading branch information
jasonli0616 authored Jul 18, 2023
1 parent 1f6428a commit 9b8d90b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.examples.swervecontrollercommand.Constants.AutoConstants;
import edu.wpi.first.wpilibj.examples.swervecontrollercommand.Constants.DriveConstants;
import edu.wpi.first.wpilibj.examples.swervecontrollercommand.Constants.ModuleConstants;
import edu.wpi.first.wpilibj.examples.swervecontrollercommand.Constants.OIConstants;
import edu.wpi.first.wpilibj.examples.swervecontrollercommand.subsystems.DriveSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
Expand Down Expand Up @@ -48,9 +49,13 @@ public RobotContainer() {
new RunCommand(
() ->
m_robotDrive.drive(
m_driverController.getLeftY(),
m_driverController.getLeftX(),
m_driverController.getRightX(),
// 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() * DriveConstants.kMaxSpeedMetersPerSecond,
m_driverController.getLeftX() * DriveConstants.kMaxSpeedMetersPerSecond,
m_driverController.getRightX()
* ModuleConstants.kMaxModuleAngularSpeedRadiansPerSecond,
false),
m_robotDrive));
}
Expand Down

0 comments on commit 9b8d90b

Please sign in to comment.