[wpimath] Fix swerve kinematics util classes equals function (#4907)

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
ohowe
2023-01-08 17:29:35 -07:00
committed by GitHub
parent 51272ef6b3
commit 330ba45f9c
8 changed files with 102 additions and 13 deletions

View File

@@ -25,5 +25,13 @@ struct WPILIB_DLLEXPORT SwerveModulePosition {
* Angle of the module.
*/
Rotation2d angle;
/**
* Checks equality between this SwerveModulePosition and another object.
*
* @param other The other object.
* @return Whether the two objects are equal.
*/
bool operator==(const SwerveModulePosition& other) const;
};
} // namespace frc

View File

@@ -26,6 +26,14 @@ struct WPILIB_DLLEXPORT SwerveModuleState {
*/
Rotation2d angle;
/**
* Checks equality between this SwerveModuleState and another object.
*
* @param other The other object.
* @return Whether the two objects are equal.
*/
bool operator==(const SwerveModuleState& other) const;
/**
* Minimize the change in heading the desired swerve module state would
* require by potentially reversing the direction the wheel spins. If this is
@@ -36,13 +44,6 @@ struct WPILIB_DLLEXPORT SwerveModuleState {
* @param currentAngle The current module angle.
*/
static SwerveModuleState Optimize(const SwerveModuleState& desiredState,
const Rotation2d& currentAngle) {
auto delta = desiredState.angle - currentAngle;
if (units::math::abs(delta.Degrees()) > 90_deg) {
return {-desiredState.speed, desiredState.angle + Rotation2d{180_deg}};
} else {
return {desiredState.speed, desiredState.angle};
}
}
const Rotation2d& currentAngle);
};
} // namespace frc