[wpimath] Move RobotDriveBase::ApplyDeadband() to MathUtil (#3529)

It's a useful function outside of the drive classes.

For backwards compatibility, deprecate (rather than remove) RobotDriveBase.applyDeadband()
This commit is contained in:
Tyler Veness
2021-08-28 20:52:05 -07:00
committed by GitHub
parent 3b5d0d141a
commit aa3848b2c8
16 changed files with 162 additions and 65 deletions

View File

@@ -2,6 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc/MathUtil.h>
#include <frc/TimedRobot.h>
#include <frc/XboxController.h>
#include <frc/filter/SlewRateLimiter.h>
@@ -30,20 +31,23 @@ class Robot : public frc::TimedRobot {
void DriveWithJoystick(bool fieldRelative) {
// Get the x speed. We are inverting this because Xbox controllers return
// negative values when we push forward.
const auto xSpeed = -m_xspeedLimiter.Calculate(m_controller.GetLeftY()) *
const auto xSpeed = -m_xspeedLimiter.Calculate(
frc::ApplyDeadband(m_controller.GetLeftY(), 0.02)) *
Drivetrain::kMaxSpeed;
// Get the y speed or sideways/strafe speed. We are inverting this because
// we want a positive value when we pull to the left. Xbox controllers
// return positive values when you pull to the right by default.
const auto ySpeed = -m_yspeedLimiter.Calculate(m_controller.GetLeftX()) *
const auto ySpeed = -m_yspeedLimiter.Calculate(
frc::ApplyDeadband(m_controller.GetLeftX(), 0.02)) *
Drivetrain::kMaxSpeed;
// Get the rate of angular rotation. We are inverting this because we want a
// positive value when we pull to the left (remember, CCW is positive in
// mathematics). Xbox controllers return positive values when you pull to
// the right by default.
const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) *
const auto rot = -m_rotLimiter.Calculate(
frc::ApplyDeadband(m_controller.GetRightX(), 0.02)) *
Drivetrain::kMaxAngularSpeed;
m_swerve.Drive(xSpeed, ySpeed, rot, fieldRelative);