diff --git a/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java index 608c735e9e..390c037bbb 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java @@ -21,6 +21,7 @@ import edu.wpi.first.units.Time; import edu.wpi.first.units.Velocity; import edu.wpi.first.util.protobuf.ProtobufSerializable; import edu.wpi.first.util.struct.StructSerializable; +import java.util.Objects; /** * Represents the speed of a robot chassis. Although this class contains similar members compared to @@ -383,6 +384,28 @@ public class ChassisSpeeds implements ProtobufSerializable, StructSerializable { vxMetersPerSecond / scalar, vyMetersPerSecond / scalar, omegaRadiansPerSecond / scalar); } + @Override + public final int hashCode() { + return Objects.hash(vxMetersPerSecond, vyMetersPerSecond, omegaRadiansPerSecond); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + + if (!(o instanceof ChassisSpeeds)) { + return false; + } + + ChassisSpeeds c = (ChassisSpeeds) o; + + return vxMetersPerSecond == c.vxMetersPerSecond + && vyMetersPerSecond == c.vyMetersPerSecond + && omegaRadiansPerSecond == c.omegaRadiansPerSecond; + } + @Override public String toString() { return String.format( diff --git a/wpimath/src/main/native/include/frc/kinematics/ChassisSpeeds.h b/wpimath/src/main/native/include/frc/kinematics/ChassisSpeeds.h index d693b47068..dc490e9b41 100644 --- a/wpimath/src/main/native/include/frc/kinematics/ChassisSpeeds.h +++ b/wpimath/src/main/native/include/frc/kinematics/ChassisSpeeds.h @@ -267,6 +267,15 @@ struct WPILIB_DLLEXPORT ChassisSpeeds { constexpr ChassisSpeeds operator/(double scalar) const { return operator*(1.0 / scalar); } + + /** + * Compares the ChassisSpeeds with another ChassisSpeed. + * + * @param other The other ChassisSpeeds. + * + * @return The result of the comparison. Is true if they are the same. + */ + constexpr bool operator==(const ChassisSpeeds& other) const = default; }; } // namespace frc