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

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}));
}
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.
calcmogul marked this conversation as resolved.
Show resolved Hide resolved
m_driverController.getLeftY() * DriveConstants.kMaxSpeedMetersPerSecond,
m_driverController.getLeftX() * DriveConstants.kMaxSpeedMetersPerSecond,
m_driverController.getRightX()
* ModuleConstants.kMaxModuleAngularSpeedRadiansPerSecond,
false),
m_robotDrive));
}
Expand Down