24 units::meters_per_second_t frontLeft = 0_mps;
29 units::meters_per_second_t frontRight = 0_mps;
34 units::meters_per_second_t rearLeft = 0_mps;
39 units::meters_per_second_t rearRight = 0_mps;
53 constexpr void Desaturate(units::meters_per_second_t attainableMaxSpeed) {
54 std::array<units::meters_per_second_t, 4> wheelSpeeds{frontLeft, frontRight,
57 *std::max_element(wheelSpeeds.begin(), wheelSpeeds.end(),
58 [](
const auto& a,
const auto& b) {
59 return units::math::abs(a) < units::math::abs(b);
62 if (realMaxSpeed > attainableMaxSpeed) {
63 for (
int i = 0; i < 4; ++i) {
64 wheelSpeeds[i] = wheelSpeeds[i] / realMaxSpeed * attainableMaxSpeed;
66 frontLeft = wheelSpeeds[0];
67 frontRight = wheelSpeeds[1];
68 rearLeft = wheelSpeeds[2];
69 rearRight = wheelSpeeds[3];
85 return {frontLeft + other.frontLeft, frontRight + other.frontRight,
86 rearLeft + other.rearLeft, rearRight + other.rearRight};
102 return *
this + -other;
113 return {-frontLeft, -frontRight, -rearLeft, -rearRight};
142 return operator*(1.0 /
scalar);
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
constexpr UnitType abs(const UnitType x) noexcept
Compute absolute value.
Definition math.h:726
Represents the wheel speeds for a mecanum drive drivetrain.
Definition MecanumDriveWheelSpeeds.h:20
constexpr MecanumDriveWheelSpeeds operator-(const MecanumDriveWheelSpeeds &other) const
Subtracts the other MecanumDriveWheelSpeeds from the current MecanumDriveWheelSpeeds and returns the ...
Definition MecanumDriveWheelSpeeds.h:100
constexpr MecanumDriveWheelSpeeds operator/(double scalar) const
Divides the MecanumDriveWheelSpeeds by a scalar and returns the new MecanumDriveWheelSpeeds.
Definition MecanumDriveWheelSpeeds.h:141
constexpr MecanumDriveWheelSpeeds operator*(double scalar) const
Multiplies the MecanumDriveWheelSpeeds by a scalar and returns the new MecanumDriveWheelSpeeds.
Definition MecanumDriveWheelSpeeds.h:126
constexpr MecanumDriveWheelSpeeds operator-() const
Returns the inverse of the current MecanumDriveWheelSpeeds.
Definition MecanumDriveWheelSpeeds.h:112
constexpr void Desaturate(units::meters_per_second_t attainableMaxSpeed)
Renormalizes the wheel speeds if any individual speed is above the specified maximum.
Definition MecanumDriveWheelSpeeds.h:53
constexpr MecanumDriveWheelSpeeds operator+(const MecanumDriveWheelSpeeds &other) const
Adds two MecanumDriveWheelSpeeds and returns the sum.
Definition MecanumDriveWheelSpeeds.h:83
Type representing an arbitrary unit.
Definition base.h:888