[wpilib] Rename MotorController setDutyCycle() to setThrottle() (#8720)

Fixes #8716.
This commit is contained in:
Tyler Veness
2026-04-09 22:28:01 -07:00
committed by GitHub
parent a4e035ba64
commit b6849a8da3
160 changed files with 659 additions and 706 deletions

View File

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

View File

@@ -31,8 +31,6 @@ void XRPMotor::CheckDeviceAllocation(int deviceNum) {
s_registeredDevices.insert(deviceNum);
}
WPI_IGNORE_DEPRECATED
XRPMotor::XRPMotor(int deviceNum) {
CheckDeviceAllocation(deviceNum);
@@ -43,27 +41,25 @@ XRPMotor::XRPMotor(int deviceNum) {
m_simDevice.CreateBoolean("init", hal::SimDevice::Direction::OUTPUT, true);
m_simInverted = m_simDevice.CreateBoolean(
"inverted", hal::SimDevice::Direction::INPUT, false);
m_simVelocity = m_simDevice.CreateDouble(
"velocity", hal::SimDevice::Direction::OUTPUT, 0.0);
m_simThrottle = m_simDevice.CreateDouble(
"throttle", hal::SimDevice::Direction::OUTPUT, 0.0);
}
}
WPI_UNIGNORE_DEPRECATED
void XRPMotor::SetDutyCycle(double velocity) {
if (m_simVelocity) {
void XRPMotor::SetThrottle(double throttle) {
if (m_simThrottle) {
bool invert = false;
if (m_simInverted) {
invert = m_simInverted.Get();
}
m_simVelocity.Set(invert ? -velocity : velocity);
m_simThrottle.Set(invert ? -throttle : throttle);
}
}
double XRPMotor::GetDutyCycle() const {
if (m_simVelocity) {
return m_simVelocity.Get();
double XRPMotor::GetThrottle() const {
if (m_simThrottle) {
return m_simThrottle.Get();
}
return 0.0;
@@ -84,11 +80,11 @@ bool XRPMotor::GetInverted() const {
}
void XRPMotor::Disable() {
SetDutyCycle(0.0);
SetThrottle(0.0);
}
void XRPMotor::StopMotor() {
SetDutyCycle(0.0);
SetThrottle(0.0);
}
std::string XRPMotor::GetDescription() const {

View File

@@ -11,12 +11,9 @@
#include "wpi/hal/SimDevice.hpp"
#include "wpi/hardware/motor/MotorController.hpp"
#include "wpi/hardware/motor/MotorSafety.hpp"
#include "wpi/util/deprecated.hpp"
namespace wpi::xrp {
WPI_IGNORE_DEPRECATED
/**
* @defgroup xrp_api XRP Hardware API
* @{
@@ -36,8 +33,8 @@ class XRPMotor : public wpi::MotorController, public wpi::MotorSafety {
*/
explicit XRPMotor(int deviceNum);
void SetDutyCycle(double value) override;
double GetDutyCycle() const override;
void SetThrottle(double throttle) override;
double GetThrottle() const override;
void SetInverted(bool isInverted) override;
bool GetInverted() const override;
@@ -49,7 +46,7 @@ class XRPMotor : public wpi::MotorController, public wpi::MotorSafety {
private:
hal::SimDevice m_simDevice;
hal::SimDouble m_simVelocity;
hal::SimDouble m_simThrottle;
hal::SimBoolean m_simInverted;
std::string m_deviceName;
@@ -62,6 +59,4 @@ class XRPMotor : public wpi::MotorController, public wpi::MotorSafety {
/** @} */
WPI_UNIGNORE_DEPRECATED
} // namespace wpi::xrp

View File

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