[wpimath] Replace Speeds with Velocities (#8479)

I left "free speed" alone since that's the technical term for it. In
general, velocity is a vector quantity, and speed is a magnitude (i.e.,
a strictly positive value).

This PR also replaces the speed verbiage in MotorController with duty
cycle.

Fixes #8423.
This commit is contained in:
Tyler Veness
2026-03-06 14:19:15 -08:00
committed by GitHub
parent 1e39f39128
commit 9bd9656871
594 changed files with 8073 additions and 7875 deletions

View File

@@ -16,49 +16,52 @@ class MotorController {
virtual ~MotorController() = default;
/**
* Common interface for setting the speed of a motor controller.
* Sets the duty cycle of the motor controller.
*
* @param speed The speed to set. Value should be between -1.0 and 1.0.
* @param dutyCycle The duty cycle between -1 and 1 (sign indicates
* direction).
*/
virtual void Set(double speed) = 0;
virtual void SetDutyCycle(double dutyCycle) = 0;
/**
* Sets the voltage output of the MotorController. Compensates for
* the current bus voltage to ensure that the desired voltage is output even
* if the battery voltage is below 12V - highly useful when the voltage
* outputs are "meaningful" (e.g. they come from a feedforward calculation).
* Sets the voltage output of the motor controller.
*
* <p>NOTE: This function *must* be called regularly in order for voltage
* Compensates for the current bus voltage to ensure that the desired voltage
* is output even if the battery voltage is below 12V - highly useful when the
* voltage outputs are "meaningful" (e.g. they come from a feedforward
* calculation).
*
* NOTE: This function *must* be called regularly in order for voltage
* compensation to work properly - unlike the ordinary set function, it is not
* "set it and forget it."
*
* @param output The voltage to output.
* @param voltage The voltage.
*/
virtual void SetVoltage(wpi::units::volt_t output);
virtual void SetVoltage(wpi::units::volt_t voltage);
/**
* Common interface for getting the current set speed of a motor controller.
* Gets the duty cycle of the motor controller.
*
* @return The current set speed. Value is between -1.0 and 1.0.
* @return The duty cycle between -1 and 1 (sign indicates direction).
*/
virtual double Get() const = 0;
virtual double GetDutyCycle() const = 0;
/**
* Common interface for inverting direction of a motor controller.
* Sets the inversion state of the motor controller.
*
* @param isInverted The state of inversion, true is inverted.
* @param isInverted The inversion state.
*/
virtual void SetInverted(bool isInverted) = 0;
/**
* Common interface for returning the inversion state of a motor controller.
* Gets the inversion state of the motor controller.
*
* @return isInverted The state of inversion, true is inverted.
* @return The inversion state.
*/
virtual bool GetInverted() const = 0;
/**
* Common interface for disabling a motor.
* Disables the motor controller.
*/
virtual void Disable() = 0;
};

View File

@@ -37,45 +37,16 @@ class PWMMotorController
PWMMotorController(PWMMotorController&&) = default;
PWMMotorController& operator=(PWMMotorController&&) = default;
/**
* Set the PWM value.
*
* The PWM value is set using a range of -1.0 to 1.0, appropriately scaling
* the value for the FPGA.
*
* @param value The speed value between -1.0 and 1.0 to set.
*/
void Set(double value) override;
void SetDutyCycle(double dutyCycle) override;
/**
* Sets the voltage output of the PWMMotorController. Compensates for
* the current bus voltage to ensure that the desired voltage is output even
* if the battery voltage is below 12V - highly useful when the voltage
* outputs are "meaningful" (e.g. they come from a feedforward calculation).
*
* <p>NOTE: This function *must* be called regularly in order for voltage
* compensation to work properly - unlike the ordinary set function, it is not
* "set it and forget it."
*
* @param output The voltage to output.
*/
void SetVoltage(wpi::units::volt_t output) override;
/**
* Get the recently set value of the PWM. This value is affected by the
* inversion property. If you want the value that is sent directly to the
* MotorController, use PWM::GetSpeed() instead.
*
* @return The most recently set value for the PWM between -1.0 and 1.0.
*/
double Get() const override;
double GetDutyCycle() const override;
/**
* Gets the voltage output of the motor controller, nominally between -12 V
* and 12 V.
*
* @return The voltage of the motor controller, nominally between -12 V and 12
* V.
* V.
*/
virtual wpi::units::volt_t GetVoltage() const;
@@ -134,8 +105,8 @@ class PWMMotorController
/// PWM instances for motor controller.
PWM m_pwm;
void SetSpeed(double speed);
double GetSpeed() const;
void SetDutyCycleInternal(double dutyCycle);
double GetDutyCycleInternal() const;
void SetBounds(wpi::units::microsecond_t maxPwm,
wpi::units::microsecond_t deadbandMaxPwm,
@@ -149,7 +120,7 @@ class PWMMotorController
std::vector<std::unique_ptr<PWMMotorController>> m_owningFollowers;
wpi::hal::SimDevice m_simDevice;
wpi::hal::SimDouble m_simSpeed;
wpi::hal::SimDouble m_simDutyCycle;
bool m_eliminateDeadband{0};
wpi::units::microsecond_t m_minPwm{0};