[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

@@ -41,7 +41,7 @@ public class XRPMotor implements MotorController {
s_simDeviceNameMap.put(3, "motor4");
}
private final SimDouble m_simSpeed;
private final SimDouble m_simVelocity;
private final SimBoolean m_simInverted;
/**
@@ -59,29 +59,29 @@ public class XRPMotor implements MotorController {
if (xrpMotorSimDevice != null) {
xrpMotorSimDevice.createBoolean("init", Direction.kOutput, true);
m_simInverted = xrpMotorSimDevice.createBoolean("inverted", Direction.kInput, false);
m_simSpeed = xrpMotorSimDevice.createDouble("speed", Direction.kOutput, 0.0);
m_simVelocity = xrpMotorSimDevice.createDouble("velocity", Direction.kOutput, 0.0);
} else {
m_simInverted = null;
m_simSpeed = null;
m_simVelocity = null;
}
}
@Override
public void set(double speed) {
if (m_simSpeed != null) {
public void setDutyCycle(double velocity) {
if (m_simVelocity != null) {
boolean invert = false;
if (m_simInverted != null) {
invert = m_simInverted.get();
}
m_simSpeed.set(invert ? -speed : speed);
m_simVelocity.set(invert ? -velocity : velocity);
}
}
@Override
public double get() {
if (m_simSpeed != null) {
return m_simSpeed.get();
public double getDutyCycle() {
if (m_simVelocity != null) {
return m_simVelocity.get();
}
return 0.0;
@@ -101,6 +101,6 @@ public class XRPMotor implements MotorController {
@Override
public void disable() {
set(0.0);
setDutyCycle(0.0);
}
}

View File

@@ -43,27 +43,27 @@ XRPMotor::XRPMotor(int deviceNum) {
m_simDevice.CreateBoolean("init", hal::SimDevice::kOutput, true);
m_simInverted =
m_simDevice.CreateBoolean("inverted", hal::SimDevice::kInput, false);
m_simSpeed =
m_simDevice.CreateDouble("speed", hal::SimDevice::kOutput, 0.0);
m_simVelocity =
m_simDevice.CreateDouble("velocity", hal::SimDevice::kOutput, 0.0);
}
}
WPI_UNIGNORE_DEPRECATED
void XRPMotor::Set(double speed) {
if (m_simSpeed) {
void XRPMotor::SetDutyCycle(double velocity) {
if (m_simVelocity) {
bool invert = false;
if (m_simInverted) {
invert = m_simInverted.Get();
}
m_simSpeed.Set(invert ? -speed : speed);
m_simVelocity.Set(invert ? -velocity : velocity);
}
}
double XRPMotor::Get() const {
if (m_simSpeed) {
return m_simSpeed.Get();
double XRPMotor::GetDutyCycle() const {
if (m_simVelocity) {
return m_simVelocity.Get();
}
return 0.0;
@@ -84,11 +84,11 @@ bool XRPMotor::GetInverted() const {
}
void XRPMotor::Disable() {
Set(0.0);
SetDutyCycle(0.0);
}
void XRPMotor::StopMotor() {
Set(0.0);
SetDutyCycle(0.0);
}
std::string XRPMotor::GetDescription() const {

View File

@@ -36,8 +36,8 @@ class XRPMotor : public wpi::MotorController, public wpi::MotorSafety {
*/
explicit XRPMotor(int deviceNum);
void Set(double value) override;
double Get() const override;
void SetDutyCycle(double value) override;
double GetDutyCycle() const override;
void SetInverted(bool isInverted) override;
bool GetInverted() const override;
@@ -49,7 +49,7 @@ class XRPMotor : public wpi::MotorController, public wpi::MotorSafety {
private:
hal::SimDevice m_simDevice;
hal::SimDouble m_simSpeed;
hal::SimDouble m_simVelocity;
hal::SimBoolean m_simInverted;
std::string m_deviceName;

View File

@@ -2,8 +2,8 @@ classes:
wpi::xrp::XRPMotor:
methods:
XRPMotor:
Set:
Get:
SetDutyCycle:
GetDutyCycle:
SetInverted:
GetInverted:
Disable: