Skip to content

Commit

Permalink
swapped optimize and cos scaling with wpi builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
r4stered committed Oct 5, 2024
1 parent 1e9c27f commit 140f8e3
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/main/cpp/str/SwerveModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,17 @@ SwerveModule::GoToState(frc::SwerveModuleState desiredState, bool optimize,
bool openLoopDrive, units::ampere_t arbff) {
frc::SwerveModuleState currentState = GetCurrentState();
if (optimize) {
desiredState =
frc::SwerveModuleState::Optimize(desiredState, currentState.angle);
desiredState.Optimize(currentState.angle);
}

desiredState.CosineScale(currentState.angle);

steerMotor.SetControl(
steerAngleSetter.WithPosition(desiredState.angle.Radians()));

units::radians_per_second_t motorSpeed =
ConvertWheelVelToMotorVel(ConvertLinearVelToWheelVel(desiredState.speed));

// The drive motors will start turning before the module reaches the desired
// angle, so scale down the speed if we are far away from our setpoint Based
// of FRC 900 ZebROS 2023 Whitepaper
units::radian_t steerError =
desiredState.angle.Radians() - currentState.angle.Radians();
units::scalar_t errorMulti = units::math::cos(steerError);
if (errorMulti < 0.0) {
errorMulti = 0.0;
}
motorSpeed *= errorMulti;

// Reverse the modules expected backout because of coupling
units::radians_per_second_t driveBackout =
steerVelocitySig.GetValue() * couplingRatio;
Expand Down

0 comments on commit 140f8e3

Please sign in to comment.