mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
SCRIPT: wpiformat
This commit is contained in:
committed by
Peter Johnson
parent
ae6bdc9d25
commit
2109161534
@@ -31,23 +31,23 @@ class Robot : public wpi::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(
|
||||
wpi::math::ApplyDeadband(m_controller.GetLeftY(), 0.02)) *
|
||||
const auto xSpeed = -m_xspeedLimiter.Calculate(wpi::math::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(
|
||||
wpi::math::ApplyDeadband(m_controller.GetLeftX(), 0.02)) *
|
||||
const auto ySpeed = -m_yspeedLimiter.Calculate(wpi::math::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(
|
||||
wpi::math::ApplyDeadband(m_controller.GetRightX(), 0.02)) *
|
||||
const auto rot = -m_rotLimiter.Calculate(wpi::math::ApplyDeadband(
|
||||
m_controller.GetRightX(), 0.02)) *
|
||||
Drivetrain::kMaxAngularSpeed;
|
||||
|
||||
m_swerve.Drive(xSpeed, ySpeed, rot, fieldRelative, GetPeriod());
|
||||
|
||||
@@ -33,7 +33,8 @@ SwerveModule::SwerveModule(const int driveMotorChannel,
|
||||
// Limit the PID Controller's input range between -pi and pi and set the input
|
||||
// to be continuous.
|
||||
m_turningPIDController.EnableContinuousInput(
|
||||
-wpi::units::radian_t{std::numbers::pi}, wpi::units::radian_t{std::numbers::pi});
|
||||
-wpi::units::radian_t{std::numbers::pi},
|
||||
wpi::units::radian_t{std::numbers::pi});
|
||||
}
|
||||
|
||||
wpi::math::SwerveModuleState SwerveModule::GetState() const {
|
||||
@@ -46,7 +47,8 @@ wpi::math::SwerveModulePosition SwerveModule::GetPosition() const {
|
||||
wpi::units::radian_t{m_turningEncoder.GetDistance()}};
|
||||
}
|
||||
|
||||
void SwerveModule::SetDesiredState(wpi::math::SwerveModuleState& referenceState) {
|
||||
void SwerveModule::SetDesiredState(
|
||||
wpi::math::SwerveModuleState& referenceState) {
|
||||
wpi::math::Rotation2d encoderRotation{
|
||||
wpi::units::radian_t{m_turningEncoder.GetDistance()}};
|
||||
|
||||
|
||||
@@ -21,8 +21,9 @@ class Drivetrain {
|
||||
Drivetrain() { m_imu.ResetYaw(); }
|
||||
|
||||
void Drive(wpi::units::meters_per_second_t xSpeed,
|
||||
wpi::units::meters_per_second_t ySpeed, wpi::units::radians_per_second_t rot,
|
||||
bool fieldRelative, wpi::units::second_t period);
|
||||
wpi::units::meters_per_second_t ySpeed,
|
||||
wpi::units::radians_per_second_t rot, bool fieldRelative,
|
||||
wpi::units::second_t period);
|
||||
void UpdateOdometry();
|
||||
|
||||
static constexpr wpi::units::meters_per_second_t kMaxSpeed =
|
||||
|
||||
@@ -49,8 +49,8 @@ class SwerveModule {
|
||||
0.0,
|
||||
{kModuleMaxAngularVelocity, kModuleMaxAngularAcceleration}};
|
||||
|
||||
wpi::math::SimpleMotorFeedforward<wpi::units::meters> m_driveFeedforward{1_V,
|
||||
3_V / 1_mps};
|
||||
wpi::math::SimpleMotorFeedforward<wpi::units::meters> m_driveFeedforward{
|
||||
1_V, 3_V / 1_mps};
|
||||
wpi::math::SimpleMotorFeedforward<wpi::units::radians> m_turnFeedforward{
|
||||
1_V, 0.5_V / 1_rad_per_s};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user