[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

@@ -17,19 +17,15 @@
using namespace wpi;
WPI_IGNORE_DEPRECATED
DifferentialDrive::DifferentialDrive(MotorController& leftMotor,
MotorController& rightMotor)
: DifferentialDrive{
[&](double output) { leftMotor.SetDutyCycle(output); },
[&](double output) { rightMotor.SetDutyCycle(output); }} {
[&](double output) { leftMotor.SetThrottle(output); },
[&](double output) { rightMotor.SetThrottle(output); }} {
wpi::util::SendableRegistry::AddChild(this, &leftMotor);
wpi::util::SendableRegistry::AddChild(this, &rightMotor);
}
WPI_UNIGNORE_DEPRECATED
DifferentialDrive::DifferentialDrive(std::function<void(double)> leftMotor,
std::function<void(double)> rightMotor)
: m_leftMotor{std::move(leftMotor)}, m_rightMotor{std::move(rightMotor)} {

View File

@@ -17,25 +17,20 @@
using namespace wpi;
WPI_IGNORE_DEPRECATED
MecanumDrive::MecanumDrive(MotorController& frontLeftMotor,
MotorController& rearLeftMotor,
MotorController& frontRightMotor,
MotorController& rearRightMotor)
: MecanumDrive{
[&](double output) { frontLeftMotor.SetDutyCycle(output); },
[&](double output) { rearLeftMotor.SetDutyCycle(output); },
[&](double output) { frontRightMotor.SetDutyCycle(output); },
[&](double output) { rearRightMotor.SetDutyCycle(output); }} {
: MecanumDrive{[&](double output) { frontLeftMotor.SetThrottle(output); },
[&](double output) { rearLeftMotor.SetThrottle(output); },
[&](double output) { frontRightMotor.SetThrottle(output); },
[&](double output) { rearRightMotor.SetThrottle(output); }} {
wpi::util::SendableRegistry::AddChild(this, &frontLeftMotor);
wpi::util::SendableRegistry::AddChild(this, &rearLeftMotor);
wpi::util::SendableRegistry::AddChild(this, &frontRightMotor);
wpi::util::SendableRegistry::AddChild(this, &rearRightMotor);
}
WPI_UNIGNORE_DEPRECATED
MecanumDrive::MecanumDrive(std::function<void(double)> frontLeftMotor,
std::function<void(double)> rearLeftMotor,
std::function<void(double)> frontRightMotor,

View File

@@ -92,10 +92,10 @@ ExpansionHubMotor::~ExpansionHubMotor() noexcept {
m_hub.UnreserveMotor(m_channel);
}
void ExpansionHubMotor::SetDutyCycle(double dutyCycle) {
void ExpansionHubMotor::SetThrottle(double throttle) {
SetEnabled(true);
m_modePublisher.Set(kPercentageMode);
m_setpointPublisher.Set(dutyCycle);
m_setpointPublisher.Set(throttle);
}
void ExpansionHubMotor::SetVoltage(wpi::units::volt_t voltage) {

View File

@@ -10,5 +10,5 @@ using namespace wpi;
void MotorController::SetVoltage(wpi::units::volt_t voltage) {
// NOLINTNEXTLINE(bugprone-integer-division)
SetDutyCycle(voltage / RobotController::GetBatteryVoltage());
SetThrottle(voltage / RobotController::GetBatteryVoltage());
}

View File

@@ -14,28 +14,28 @@
using namespace wpi;
void PWMMotorController::SetDutyCycle(double dutyCycle) {
void PWMMotorController::SetThrottle(double throttle) {
if (m_isInverted) {
dutyCycle = -dutyCycle;
throttle = -throttle;
}
SetDutyCycleInternal(dutyCycle);
SetDutyCycleInternal(throttle);
for (auto& follower : m_nonowningFollowers) {
follower->SetDutyCycle(dutyCycle);
follower->SetThrottle(throttle);
}
for (auto& follower : m_owningFollowers) {
follower->SetDutyCycle(dutyCycle);
follower->SetThrottle(throttle);
}
Feed();
}
double PWMMotorController::GetDutyCycle() const {
double PWMMotorController::GetThrottle() const {
return GetDutyCycleInternal() * (m_isInverted ? -1.0 : 1.0);
}
wpi::units::volt_t PWMMotorController::GetVoltage() const {
return GetDutyCycle() * RobotController::GetBatteryVoltage();
return GetThrottle() * RobotController::GetBatteryVoltage();
}
void PWMMotorController::SetInverted(bool isInverted) {
@@ -49,8 +49,8 @@ bool PWMMotorController::GetInverted() const {
void PWMMotorController::Disable() {
m_pwm.SetDisabled();
if (m_simDutyCycle) {
m_simDutyCycle.Set(0.0);
if (m_simThrottle) {
m_simThrottle.Set(0.0);
}
for (auto& follower : m_nonowningFollowers) {
@@ -81,28 +81,24 @@ void PWMMotorController::AddFollower(PWMMotorController& follower) {
m_nonowningFollowers.emplace_back(&follower);
}
WPI_IGNORE_DEPRECATED
PWMMotorController::PWMMotorController(std::string_view name, int channel)
: m_pwm(channel, false) {
wpi::util::SendableRegistry::Add(this, name, channel);
m_simDevice = wpi::hal::SimDevice{"PWMMotorController", channel};
if (m_simDevice) {
m_simDutyCycle = m_simDevice.CreateDouble(
"DutyCycle", wpi::hal::SimDevice::Direction::OUTPUT, 0.0);
m_simThrottle = m_simDevice.CreateDouble(
"Throttle", wpi::hal::SimDevice::Direction::OUTPUT, 0.0);
m_pwm.SetSimDevice(m_simDevice);
}
}
WPI_UNIGNORE_DEPRECATED
void PWMMotorController::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("Motor Controller");
builder.SetActuator(true);
builder.AddDoubleProperty(
"Value", [=, this] { return GetDutyCycle(); },
[=, this](double value) { SetDutyCycle(value); });
"Value", [=, this] { return GetThrottle(); },
[=, this](double value) { SetThrottle(value); });
}
wpi::units::microsecond_t PWMMotorController::GetMinPositivePwm() const {
@@ -136,8 +132,8 @@ void PWMMotorController::SetDutyCycleInternal(double dutyCycle) {
dutyCycle = 0.0;
}
if (m_simDutyCycle) {
m_simDutyCycle.Set(dutyCycle);
if (m_simThrottle) {
m_simThrottle.Set(dutyCycle);
}
wpi::units::microsecond_t rawValue;

View File

@@ -16,9 +16,9 @@ PWMMotorControllerSim::PWMMotorControllerSim(
PWMMotorControllerSim::PWMMotorControllerSim(int channel) {
wpi::sim::SimDeviceSim deviceSim{"PWMMotorController", channel};
m_simDutyCycle = deviceSim.GetDouble("DutyCycle");
m_simThrottle = deviceSim.GetDouble("Throttle");
}
double PWMMotorControllerSim::GetDutyCycle() const {
return m_simDutyCycle.Get();
double PWMMotorControllerSim::GetThrottle() const {
return m_simThrottle.Get();
}

View File

@@ -8,7 +8,6 @@
#include <string>
#include "wpi/drive/RobotDriveBase.hpp"
#include "wpi/util/deprecated.hpp"
#include "wpi/util/sendable/Sendable.hpp"
#include "wpi/util/sendable/SendableHelper.hpp"
@@ -70,8 +69,6 @@ class DifferentialDrive : public RobotDriveBase,
double right = 0.0;
};
WPI_IGNORE_DEPRECATED
/**
* Construct a DifferentialDrive.
*
@@ -84,8 +81,6 @@ class DifferentialDrive : public RobotDriveBase,
*/
DifferentialDrive(MotorController& leftMotor, MotorController& rightMotor);
WPI_UNIGNORE_DEPRECATED
/**
* Construct a DifferentialDrive.
*

View File

@@ -5,13 +5,11 @@
#pragma once
#include <functional>
#include <memory>
#include <string>
#include "wpi/drive/RobotDriveBase.hpp"
#include "wpi/math/geometry/Rotation2d.hpp"
#include "wpi/units/angle.hpp"
#include "wpi/util/deprecated.hpp"
#include "wpi/util/sendable/Sendable.hpp"
#include "wpi/util/sendable/SendableHelper.hpp"
@@ -71,8 +69,6 @@ class MecanumDrive : public RobotDriveBase,
double rearRight = 0.0;
};
WPI_IGNORE_DEPRECATED
/**
* Construct a MecanumDrive.
*
@@ -87,8 +83,6 @@ class MecanumDrive : public RobotDriveBase,
MotorController& frontRightMotor,
MotorController& rearRightMotor);
WPI_UNIGNORE_DEPRECATED
/**
* Construct a MecanumDrive.
*

View File

@@ -4,7 +4,6 @@
#pragma once
#include <memory>
#include <span>
#include <string>

View File

@@ -4,16 +4,12 @@
#pragma once
#include <memory>
#include "wpi/hardware/expansionhub/ExpansionHub.hpp"
#include "wpi/hardware/expansionhub/ExpansionHubPidConstants.hpp"
#include "wpi/nt/BooleanTopic.hpp"
#include "wpi/nt/DoubleTopic.hpp"
#include "wpi/nt/IntegerTopic.hpp"
#include "wpi/units/angle.hpp"
#include "wpi/units/current.hpp"
#include "wpi/units/time.hpp"
#include "wpi/units/voltage.hpp"
namespace wpi {
@@ -33,12 +29,12 @@ class ExpansionHubMotor {
~ExpansionHubMotor() noexcept;
/**
* Sets the duty cycle.
* Sets the throttle.
*
* @param dutyCycle The duty cycle between -1 and 1 (sign indicates
* direction).
* @param throttle The throttle where -1 indicates full reverse and 1
* indicates full forward.
*/
void SetDutyCycle(double dutyCycle);
void SetThrottle(double throttle);
/**
* Sets the voltage to run the motor at. This value will be continously scaled

View File

@@ -16,12 +16,12 @@ class MotorController {
virtual ~MotorController() = default;
/**
* Sets the duty cycle of the motor controller.
* Sets the throttle of the motor controller.
*
* @param dutyCycle The duty cycle between -1 and 1 (sign indicates
* direction).
* @param throttle The throttle where -1 indicates full reverse and 1
* indicates full forward.
*/
virtual void SetDutyCycle(double dutyCycle) = 0;
virtual void SetThrottle(double throttle) = 0;
/**
* Sets the voltage output of the motor controller.
@@ -40,11 +40,12 @@ class MotorController {
virtual void SetVoltage(wpi::units::volt_t voltage);
/**
* Gets the duty cycle of the motor controller.
* Gets the throttle of the motor controller.
*
* @return The duty cycle between -1 and 1 (sign indicates direction).
* @return The throttle where -1 represents full reverse and 1 represents full
* forward.
*/
virtual double GetDutyCycle() const = 0;
virtual double GetThrottle() const = 0;
/**
* Sets the inversion state of the motor controller.

View File

@@ -17,14 +17,11 @@
#include "wpi/hardware/motor/MotorController.hpp"
#include "wpi/hardware/motor/MotorSafety.hpp"
#include "wpi/units/voltage.hpp"
#include "wpi/util/deprecated.hpp"
#include "wpi/util/sendable/Sendable.hpp"
#include "wpi/util/sendable/SendableHelper.hpp"
namespace wpi {
WPI_IGNORE_DEPRECATED
/**
* Common base class for all PWM Motor Controllers.
*/
@@ -37,9 +34,9 @@ class PWMMotorController
PWMMotorController(PWMMotorController&&) = default;
PWMMotorController& operator=(PWMMotorController&&) = default;
void SetDutyCycle(double dutyCycle) override;
void SetThrottle(double throttle) override;
double GetDutyCycle() const override;
double GetThrottle() const override;
/**
* Gets the voltage output of the motor controller, nominally between -12 V
@@ -119,7 +116,7 @@ class PWMMotorController
std::vector<std::unique_ptr<PWMMotorController>> m_owningFollowers;
wpi::hal::SimDevice m_simDevice;
wpi::hal::SimDouble m_simDutyCycle;
wpi::hal::SimDouble m_simThrottle;
bool m_eliminateDeadband{0};
wpi::units::microsecond_t m_minPwm{0};
@@ -136,6 +133,4 @@ class PWMMotorController
PWM* GetPwm() { return &m_pwm; }
};
WPI_UNIGNORE_DEPRECATED
} // namespace wpi

View File

@@ -19,10 +19,10 @@ class PWMMotorControllerSim {
explicit PWMMotorControllerSim(int channel);
double GetDutyCycle() const;
double GetThrottle() const;
private:
wpi::hal::SimDouble m_simDutyCycle;
wpi::hal::SimDouble m_simThrottle;
};
} // namespace sim
} // namespace wpi