46 static wpi::math::SwerveModuleVelocity
Optimize(
47 const wpi::math::SwerveModuleVelocity& desired,
49 const std::optional<wpi::math::Rotation2d>& lastCommanded,
50 wpi::units::degree_t hysteresis = wpi::units::degree_t{30}) {
51 wpi::math::SwerveModuleVelocity state = desired.Optimize(measured.angle);
52 if (!lastCommanded || wpi::units::math::abs((state.angle - *lastCommanded).Degrees()) <=
53 wpi::units::degree_t{90}) {
57 wpi::math::SwerveModuleVelocity lastOrientation{
58 -state.velocity, state.angle.RotateBy(wpi::math::Rotation2d{wpi::units::degree_t{180}})};
59 return wpi::units::math::abs((lastOrientation.angle - measured.angle).Degrees()) <
60 wpi::units::degree_t{90} + hysteresis