[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

@@ -76,7 +76,7 @@ class Arm:
# In this method, we update our simulation of what our arm is doing
# First, we set our "inputs" (voltages)
self.armSim.setInput(
[self.motor.getDutyCycle() * wpilib.RobotController.getBatteryVoltage()]
[self.motor.getThrottle() * wpilib.RobotController.getBatteryVoltage()]
)
# Next, we update it. The standard loop time is 20ms.
@@ -111,4 +111,4 @@ class Arm:
self.motor.setVoltage(pidOutput)
def stop(self) -> None:
self.motor.setDutyCycle(0.0)
self.motor.setThrottle(0.0)

View File

@@ -244,8 +244,8 @@ class Drivetrain:
# simulation, and write the simulated positions and velocities to our
# simulated encoder and gyro.
self.drivetrainSimulator.setInputs(
self.leftLeader.getDutyCycle() * wpilib.RobotController.getInputVoltage(),
self.rightLeader.getDutyCycle() * wpilib.RobotController.getInputVoltage(),
self.leftLeader.getThrottle() * wpilib.RobotController.getInputVoltage(),
self.rightLeader.getThrottle() * wpilib.RobotController.getInputVoltage(),
)
self.drivetrainSimulator.update(0.02)

View File

@@ -84,7 +84,7 @@ class Elevator:
# In this method, we update our simulation of what our elevator is doing
# First, we set our "inputs" (voltages)
self.elevatorSim.setInputVoltage(
self.motorSim.getDutyCycle() * wpilib.RobotController.getBatteryVoltage()
self.motorSim.getThrottle() * wpilib.RobotController.getBatteryVoltage()
)
# Next, we update it. The standard loop time is 20ms.
@@ -120,7 +120,7 @@ class Elevator:
def stop(self) -> None:
"""Stop the control loop and motor output."""
self.motor.setDutyCycle(0.0)
self.motor.setThrottle(0.0)
def reset(self) -> None:
"""Reset Exponential profile to begin from current position on enable."""

View File

@@ -68,7 +68,7 @@ class Elevator:
# In this method, we update our simulation of what our elevator is doing
# First, we set our "inputs" (voltages)
self.elevatorSim.setInputVoltage(
self.motorSim.getDutyCycle() * wpilib.RobotController.getBatteryVoltage()
self.motorSim.getThrottle() * wpilib.RobotController.getBatteryVoltage()
)
# Next, we update it. The standard loop time is 20ms.
@@ -99,7 +99,7 @@ class Elevator:
def stop(self) -> None:
"""Stop the control loop and motor output."""
self.controller.setGoal(0.0)
self.motor.setDutyCycle(0.0)
self.motor.setThrottle(0.0)
def updateTelemetry(self) -> None:
"""Update telemetry, including the mechanism visualization."""

View File

@@ -102,7 +102,7 @@ class MyRobot(wpilib.TimedRobot):
# To update our simulation, we set motor voltage inputs, update the
# simulation, and write the simulated velocities to our simulated encoder
self.flywheelSim.setInputVoltage(
self.flywheelMotor.getDutyCycle() * wpilib.RobotController.getInputVoltage()
self.flywheelMotor.getThrottle() * wpilib.RobotController.getInputVoltage()
)
self.flywheelSim.update(0.02)
self.encoderSim.setRate(self.flywheelSim.getAngularVelocity())

View File

@@ -56,5 +56,5 @@ class MyRobot(wpilib.TimedRobot):
self.wrist.setAngle(self.wristPot.get())
def teleopPeriodic(self):
self.elevatorMotor.setDutyCycle(self.joystick.getRawAxis(0))
self.wristMotor.setDutyCycle(self.joystick.getRawAxis(1))
self.elevatorMotor.setThrottle(self.joystick.getRawAxis(0))
self.wristMotor.setThrottle(self.joystick.getRawAxis(1))

View File

@@ -43,4 +43,4 @@ class MyRobot(wpilib.TimedRobot):
wpilib.SmartDashboard.putNumber("Encoder", self.encoder.getDistance())
def teleopPeriodic(self):
self.motor.setDutyCycle(self.joystick.getY())
self.motor.setThrottle(self.joystick.getY())

View File

@@ -145,8 +145,8 @@ class Drivetrain:
# simulated encoder and gyro. We negate the right side so that positive
# voltages make the right side move forward.
self.drivetrainSimulator.setInputs(
self.leftLeader.getDutyCycle() * wpilib.RobotController.getInputVoltage(),
self.rightLeader.getDutyCycle() * wpilib.RobotController.getInputVoltage(),
self.leftLeader.getThrottle() * wpilib.RobotController.getInputVoltage(),
self.rightLeader.getThrottle() * wpilib.RobotController.getInputVoltage(),
)
self.drivetrainSimulator.update(0.02)

View File

@@ -93,7 +93,7 @@ class Shooter(Subsystem):
)
+ self.shooter_feedforward.calculate(target_velocity_radians)
)
self.feeder_motor.setDutyCycle(ShooterConstants.kFeederVelocity)
self.feeder_motor.setThrottle(ShooterConstants.kFeederVelocity)
def _stop_motors(interrupted: bool) -> None:
self.shooter_motor.stopMotor()

View File

@@ -20,17 +20,17 @@ class Intake:
)
def deploy(self) -> None:
self.piston.setDutyCycle(wpilib.DoubleSolenoid.Value.FORWARD)
self.piston.setThrottle(wpilib.DoubleSolenoid.Value.FORWARD)
def retract(self) -> None:
self.piston.setDutyCycle(wpilib.DoubleSolenoid.Value.REVERSE)
self.motor.setDutyCycle(0) # turn off the motor
self.piston.setThrottle(wpilib.DoubleSolenoid.Value.REVERSE)
self.motor.setThrottle(0) # turn off the motor
def activate(self, velocity: float) -> None:
if self.isDeployed():
self.motor.setDutyCycle(velocity)
self.motor.setThrottle(velocity)
else: # if piston isn't open, do nothing
self.motor.setDutyCycle(0)
self.motor.setThrottle(0)
def isDeployed(self) -> bool:
return self.piston.get() == wpilib.DoubleSolenoid.Value.FORWARD

View File

@@ -32,7 +32,7 @@ class Drivetrain(commands2.Subsystem):
# Set up the differential drive controller
self.drive = wpilib.DifferentialDrive(
self.leftMotor.setDutyCycle, self.rightMotor.setDutyCycle
self.leftMotor.setThrottle, self.rightMotor.setThrottle
)
# TODO: these don't work

View File

@@ -15,7 +15,7 @@ public class RomiMotor extends PWMMotorController {
/** Common initialization code called by all constructors. */
protected final void initRomiMotor() {
m_pwm.setOutputPeriod(5);
setDutyCycle(0.0);
setThrottle(0.0);
}
/**

View File

@@ -8,5 +8,5 @@ using namespace wpi::romi;
RomiMotor::RomiMotor(int channel) : PWMMotorController("Romi Motor", channel) {
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
{{ name }}::{{ name }}(int channel) : PWMMotorController("{{ name }}", channel) {
SetBounds({{ pulse_width_ms.max }}_ms, {{ pulse_width_ms.deadbandMax }}_ms, {{ pulse_width_ms.center }}_ms, {{ pulse_width_ms.deadbandMin }}_ms, {{ pulse_width_ms.min }}_ms);
m_pwm.SetOutputPeriod({{ OutputPeriod | default("5", true)}}_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "{{ ResourceName }}");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
Koors40::Koors40(int channel) : PWMMotorController("Koors40", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(20_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "Koors40");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMSparkFlex::PWMSparkFlex(int channel) : PWMMotorController("PWMSparkFlex", channel) {
SetBounds(2.003_ms, 1.55_ms, 1.5_ms, 1.46_ms, 0.999_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "RevSparkFlexPWM");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMSparkMax::PWMSparkMax(int channel) : PWMMotorController("PWMSparkMax", channel) {
SetBounds(2.003_ms, 1.55_ms, 1.5_ms, 1.46_ms, 0.999_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "RevSparkMaxPWM");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMTalonFX::PWMTalonFX(int channel) : PWMMotorController("PWMTalonFX", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "TalonFX");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMTalonSRX::PWMTalonSRX(int channel) : PWMMotorController("PWMTalonSRX", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "PWMTalonSRX");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMVenom::PWMVenom(int channel) : PWMMotorController("PWMVenom", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "FusionVenom");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
PWMVictorSPX::PWMVictorSPX(int channel) : PWMMotorController("PWMVictorSPX", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "PWMVictorSPX");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
Spark::Spark(int channel) : PWMMotorController("Spark", channel) {
SetBounds(2.003_ms, 1.55_ms, 1.5_ms, 1.46_ms, 0.999_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "RevSPARK");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
SparkMini::SparkMini(int channel) : PWMMotorController("SparkMini", channel) {
SetBounds(2.5_ms, 1.51_ms, 1.5_ms, 1.49_ms, 0.5_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "RevSPARK");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
Talon::Talon(int channel) : PWMMotorController("Talon", channel) {
SetBounds(2.037_ms, 1.539_ms, 1.513_ms, 1.487_ms, 0.989_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "Talon");
}

View File

@@ -13,7 +13,7 @@ using namespace wpi;
VictorSP::VictorSP(int channel) : PWMMotorController("VictorSP", channel) {
SetBounds(2.004_ms, 1.52_ms, 1.5_ms, 1.48_ms, 0.997_ms);
m_pwm.SetOutputPeriod(5_ms);
SetDutyCycle(0.0);
SetThrottle(0.0);
HAL_ReportUsage("IO", GetChannel(), "VictorSP");
}

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

View File

@@ -2,7 +2,7 @@ classes:
wpi::ExpansionHubMotor:
methods:
ExpansionHubMotor:
SetDutyCycle:
SetThrottle:
SetVoltage:
SetPositionSetpoint:
SetVelocitySetpoint:

View File

@@ -1,9 +1,9 @@
classes:
wpi::MotorController:
methods:
SetDutyCycle:
SetThrottle:
SetVoltage:
GetDutyCycle:
GetThrottle:
SetInverted:
GetInverted:
Disable:

View File

@@ -33,9 +33,9 @@ classes:
param_override:
args:
ignore: true
SetDutyCycle:
SetThrottle:
SetVoltage:
GetDutyCycle:
GetThrottle:
SetInverted:
GetInverted:
Disable:

View File

@@ -8,8 +8,8 @@ classes:
attributes:
m_pwm:
methods:
SetDutyCycle:
GetDutyCycle:
SetThrottle:
GetThrottle:
GetVoltage:
SetInverted:
GetInverted:

View File

@@ -5,4 +5,4 @@ classes:
overloads:
const PWMMotorController&:
int:
GetDutyCycle:
GetThrottle:

View File

@@ -17,9 +17,9 @@ void PyMotorControllerGroup::Initialize() {
wpi::util::SendableRegistry::Add(this, "MotorControllerGroup", instances);
}
void PyMotorControllerGroup::SetDutyCycle(double dutyCycle) {
void PyMotorControllerGroup::SetThrottle(double throttle) {
for (auto motorController : m_motorControllers) {
motorController->SetDutyCycle(m_isInverted ? -dutyCycle : dutyCycle);
motorController->SetThrottle(m_isInverted ? -throttle : throttle);
}
}
@@ -29,9 +29,9 @@ void PyMotorControllerGroup::SetVoltage(wpi::units::volt_t voltage) {
}
}
double PyMotorControllerGroup::GetDutyCycle() const {
double PyMotorControllerGroup::GetThrottle() const {
if (!m_motorControllers.empty()) {
return m_motorControllers.front()->GetDutyCycle() * (m_isInverted ? -1 : 1);
return m_motorControllers.front()->GetThrottle() * (m_isInverted ? -1 : 1);
}
return 0.0;
}
@@ -51,6 +51,6 @@ void PyMotorControllerGroup::Disable() {
void PyMotorControllerGroup::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("Motor Controller");
builder.SetActuator(true);
builder.AddDoubleProperty("Value", [=, this]() { return GetDutyCycle(); },
[=, this](double value) { SetDutyCycle(value); });
builder.AddDoubleProperty("Value", [=, this]() { return GetThrottle(); },
[=, this](double value) { SetThrottle(value); });
}

View File

@@ -26,9 +26,9 @@ class PyMotorControllerGroup : public wpi::util::Sendable,
PyMotorControllerGroup(PyMotorControllerGroup&&) = default;
PyMotorControllerGroup& operator=(PyMotorControllerGroup&&) = default;
void SetDutyCycle(double dutyCycle) override;
void SetThrottle(double throttle) override;
void SetVoltage(wpi::units::volt_t voltage) override;
double GetDutyCycle() const override;
double GetThrottle() const override;
void SetInverted(bool isInverted) override;
bool GetInverted() const override;
void Disable() override;

View File

@@ -244,232 +244,232 @@ TEST(DifferentialDriveTest, ArcadeDrive) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.ArcadeDrive(1.0, 0.0, false);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.ArcadeDrive(0.5, 0.5, false);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.5, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.5, right.GetThrottle());
// Forward right turn
drive.ArcadeDrive(0.5, -0.5, false);
EXPECT_DOUBLE_EQ(0.5, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.5, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward
drive.ArcadeDrive(-1.0, 0.0, false);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.ArcadeDrive(-0.5, 0.5, false);
EXPECT_DOUBLE_EQ(-0.5, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.5, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward right turn
drive.ArcadeDrive(-0.5, -0.5, false);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.5, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-0.5, right.GetThrottle());
}
TEST(DifferentialDriveTest, ArcadeDriveSquared) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.ArcadeDrive(1.0, 0.0, true);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.ArcadeDrive(0.5, 0.5, true);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.25, right.GetThrottle());
// Forward right turn
drive.ArcadeDrive(0.5, -0.5, true);
EXPECT_DOUBLE_EQ(0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward
drive.ArcadeDrive(-1.0, 0.0, true);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.ArcadeDrive(-0.5, 0.5, true);
EXPECT_DOUBLE_EQ(-0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward right turn
drive.ArcadeDrive(-0.5, -0.5, true);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-0.25, right.GetThrottle());
}
TEST(DifferentialDriveTest, CurvatureDrive) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.CurvatureDrive(1.0, 0.0, false);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.CurvatureDrive(0.5, 0.5, false);
EXPECT_DOUBLE_EQ(0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.75, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.75, right.GetThrottle());
// Forward right turn
drive.CurvatureDrive(0.5, -0.5, false);
EXPECT_DOUBLE_EQ(0.75, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.75, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.25, right.GetThrottle());
// Backward
drive.CurvatureDrive(-1.0, 0.0, false);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.CurvatureDrive(-0.5, 0.5, false);
EXPECT_DOUBLE_EQ(-0.75, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.75, left.GetThrottle());
EXPECT_DOUBLE_EQ(-0.25, right.GetThrottle());
// Backward right turn
drive.CurvatureDrive(-0.5, -0.5, false);
EXPECT_DOUBLE_EQ(-0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.75, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(-0.75, right.GetThrottle());
}
TEST(DifferentialDriveTest, CurvatureDriveTurnInPlace) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.CurvatureDrive(1.0, 0.0, true);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.CurvatureDrive(0.5, 0.5, true);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward right turn
drive.CurvatureDrive(0.5, -0.5, true);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward
drive.CurvatureDrive(-1.0, 0.0, true);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.CurvatureDrive(-0.5, 0.5, true);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.0, right.GetThrottle());
// Backward right turn
drive.CurvatureDrive(-0.5, -0.5, true);
EXPECT_DOUBLE_EQ(0.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
}
TEST(DifferentialDriveTest, TankDrive) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.TankDrive(1.0, 1.0, false);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.TankDrive(0.5, 1.0, false);
EXPECT_DOUBLE_EQ(0.5, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.5, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward right turn
drive.TankDrive(1.0, 0.5, false);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.5, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.5, right.GetThrottle());
// Backward
drive.TankDrive(-1.0, -1.0, false);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.TankDrive(-0.5, -1.0, false);
EXPECT_DOUBLE_EQ(-0.5, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.5, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward right turn
drive.TankDrive(-0.5, 1.0, false);
EXPECT_DOUBLE_EQ(-0.5, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.5, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
}
TEST(DifferentialDriveTest, TankDriveSquared) {
wpi::MockPWMMotorController left;
wpi::MockPWMMotorController right;
wpi::DifferentialDrive drive{
[&](double output) { left.SetDutyCycle(output); },
[&](double output) { right.SetDutyCycle(output); }};
[&](double output) { left.SetThrottle(output); },
[&](double output) { right.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.TankDrive(1.0, 1.0, true);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward left turn
drive.TankDrive(0.5, 1.0, true);
EXPECT_DOUBLE_EQ(0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, right.GetThrottle());
// Forward right turn
drive.TankDrive(1.0, 0.5, true);
EXPECT_DOUBLE_EQ(1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(0.25, right.GetThrottle());
// Backward
drive.TankDrive(-1.0, -1.0, true);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward left turn
drive.TankDrive(-0.5, -1.0, true);
EXPECT_DOUBLE_EQ(-0.25, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, left.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, right.GetThrottle());
// Backward right turn
drive.TankDrive(-1.0, -0.5, true);
EXPECT_DOUBLE_EQ(-1.0, left.GetDutyCycle());
EXPECT_DOUBLE_EQ(-0.25, right.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, left.GetThrottle());
EXPECT_DOUBLE_EQ(-0.25, right.GetThrottle());
}

View File

@@ -87,46 +87,46 @@ TEST(MecanumDriveTest, Cartesian) {
wpi::MockPWMMotorController rl;
wpi::MockPWMMotorController fr;
wpi::MockPWMMotorController rr;
wpi::MecanumDrive drive{[&](double output) { fl.SetDutyCycle(output); },
[&](double output) { rl.SetDutyCycle(output); },
[&](double output) { fr.SetDutyCycle(output); },
[&](double output) { rr.SetDutyCycle(output); }};
wpi::MecanumDrive drive{[&](double output) { fl.SetThrottle(output); },
[&](double output) { rl.SetThrottle(output); },
[&](double output) { fr.SetThrottle(output); },
[&](double output) { rr.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.DriveCartesian(1.0, 0.0, 0.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Left
drive.DriveCartesian(0.0, -1.0, 0.0);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
// Right
drive.DriveCartesian(0.0, 1.0, 0.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CCW
drive.DriveCartesian(0.0, 0.0, -1.0);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CW
drive.DriveCartesian(0.0, 0.0, 1.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
}
TEST(MecanumDriveTest, CartesianGyro90CW) {
@@ -134,46 +134,46 @@ TEST(MecanumDriveTest, CartesianGyro90CW) {
wpi::MockPWMMotorController rl;
wpi::MockPWMMotorController fr;
wpi::MockPWMMotorController rr;
wpi::MecanumDrive drive{[&](double output) { fl.SetDutyCycle(output); },
[&](double output) { rl.SetDutyCycle(output); },
[&](double output) { fr.SetDutyCycle(output); },
[&](double output) { rr.SetDutyCycle(output); }};
wpi::MecanumDrive drive{[&](double output) { fl.SetThrottle(output); },
[&](double output) { rl.SetThrottle(output); },
[&](double output) { fr.SetThrottle(output); },
[&](double output) { rr.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward in global frame; left in robot frame
drive.DriveCartesian(1.0, 0.0, 0.0, 90_deg);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
// Left in global frame; backward in robot frame
drive.DriveCartesian(0.0, -1.0, 0.0, 90_deg);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
// Right in global frame; forward in robot frame
drive.DriveCartesian(0.0, 1.0, 0.0, 90_deg);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CCW
drive.DriveCartesian(0.0, 0.0, -1.0, 90_deg);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CW
drive.DriveCartesian(0.0, 0.0, 1.0, 90_deg);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
}
TEST(MecanumDriveTest, Polar) {
@@ -181,44 +181,44 @@ TEST(MecanumDriveTest, Polar) {
wpi::MockPWMMotorController rl;
wpi::MockPWMMotorController fr;
wpi::MockPWMMotorController rr;
wpi::MecanumDrive drive{[&](double output) { fl.SetDutyCycle(output); },
[&](double output) { rl.SetDutyCycle(output); },
[&](double output) { fr.SetDutyCycle(output); },
[&](double output) { rr.SetDutyCycle(output); }};
wpi::MecanumDrive drive{[&](double output) { fl.SetThrottle(output); },
[&](double output) { rl.SetThrottle(output); },
[&](double output) { fr.SetThrottle(output); },
[&](double output) { rr.SetThrottle(output); }};
drive.SetDeadband(0.0);
// Forward
drive.DrivePolar(1.0, 0_deg, 0.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Left
drive.DrivePolar(1.0, -90_deg, 0.0);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
// Right
drive.DrivePolar(1.0, 90_deg, 0.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CCW
drive.DrivePolar(0.0, 0_deg, -1.0);
EXPECT_DOUBLE_EQ(-1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rr.GetThrottle());
// Rotate CW
drive.DrivePolar(0.0, 0_deg, 1.0);
EXPECT_DOUBLE_EQ(1.0, fl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, rl.GetDutyCycle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetDutyCycle());
EXPECT_DOUBLE_EQ(1.0, fl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, fr.GetThrottle());
EXPECT_DOUBLE_EQ(1.0, rl.GetThrottle());
EXPECT_DOUBLE_EQ(-1.0, rr.GetThrottle());
}

View File

@@ -6,12 +6,12 @@
using namespace wpi;
void MockMotorController::SetDutyCycle(double dutyCycle) {
m_dutyCycle = m_isInverted ? -dutyCycle : dutyCycle;
void MockMotorController::SetThrottle(double throttle) {
m_throttle = m_isInverted ? -throttle : throttle;
}
double MockMotorController::GetDutyCycle() const {
return m_dutyCycle;
double MockMotorController::GetThrottle() const {
return m_throttle;
}
void MockMotorController::SetInverted(bool isInverted) {
@@ -23,5 +23,5 @@ bool MockMotorController::GetInverted() const {
}
void MockMotorController::Disable() {
m_dutyCycle = 0;
m_throttle = 0;
}

View File

@@ -6,12 +6,12 @@
using namespace wpi;
void MockPWMMotorController::SetDutyCycle(double dutyCycle) {
m_dutyCycle = m_isInverted ? -dutyCycle : dutyCycle;
void MockPWMMotorController::SetThrottle(double throttle) {
m_throttle = m_isInverted ? -throttle : throttle;
}
double MockPWMMotorController::GetDutyCycle() const {
return m_dutyCycle;
double MockPWMMotorController::GetThrottle() const {
return m_throttle;
}
void MockPWMMotorController::SetInverted(bool isInverted) {
@@ -23,7 +23,7 @@ bool MockPWMMotorController::GetInverted() const {
}
void MockPWMMotorController::Disable() {
m_dutyCycle = 0;
m_throttle = 0;
}
void MockPWMMotorController::StopMotor() {

View File

@@ -37,7 +37,7 @@ TEST(DCMotorSimTest, VoltageSteadyState) {
// Then, SimulationPeriodic runs
wpi::sim::RoboRioSim::SetVInVoltage(
wpi::sim::BatterySim::Calculate({sim.GetCurrentDraw()}));
sim.SetInputVoltage(motor.GetDutyCycle() *
sim.SetInputVoltage(motor.GetThrottle() *
wpi::RobotController::GetBatteryVoltage());
sim.Update(20_ms);
encoderSim.SetRate(sim.GetAngularVelocity().value());
@@ -53,7 +53,7 @@ TEST(DCMotorSimTest, VoltageSteadyState) {
// Then, SimulationPeriodic runs
wpi::sim::RoboRioSim::SetVInVoltage(
wpi::sim::BatterySim::Calculate({sim.GetCurrentDraw()}));
sim.SetInputVoltage(motor.GetDutyCycle() *
sim.SetInputVoltage(motor.GetThrottle() *
wpi::RobotController::GetBatteryVoltage());
sim.Update(20_ms);
encoderSim.SetRate(sim.GetAngularVelocity().value());
@@ -80,12 +80,12 @@ TEST(DCMotorSimTest, PositionFeedbackControl) {
for (int i = 0; i < 140; i++) {
// RobotPeriodic runs first
motor.SetDutyCycle(controller.Calculate(encoder.GetDistance(), 750));
motor.SetThrottle(controller.Calculate(encoder.GetDistance(), 750));
// Then, SimulationPeriodic runs
wpi::sim::RoboRioSim::SetVInVoltage(
wpi::sim::BatterySim::Calculate({sim.GetCurrentDraw()}));
sim.SetInputVoltage(motor.GetDutyCycle() *
sim.SetInputVoltage(motor.GetThrottle() *
wpi::RobotController::GetBatteryVoltage());
sim.Update(20_ms);
encoderSim.SetDistance(sim.GetAngularPosition().value());

View File

@@ -30,9 +30,9 @@ TEST(ElevatorSimTest, StateSpaceSim) {
for (size_t i = 0; i < 100; ++i) {
controller.SetSetpoint(2.0);
auto nextVoltage = controller.Calculate(encoderSim.GetDistance());
motor.SetDutyCycle(nextVoltage / wpi::RobotController::GetInputVoltage());
motor.SetThrottle(nextVoltage / wpi::RobotController::GetInputVoltage());
wpi::math::Vectord<1> u{motor.GetDutyCycle() *
wpi::math::Vectord<1> u{motor.GetThrottle() *
wpi::RobotController::GetInputVoltage()};
sim.SetInput(u);
sim.Update(20_ms);

View File

@@ -15,13 +15,13 @@ TEST(PWMMotorControllerSimTest, TestMotor) {
wpi::Spark spark{0};
wpi::sim::PWMMotorControllerSim sim{spark};
spark.SetDutyCycle(0);
EXPECT_EQ(0, sim.GetDutyCycle());
spark.SetThrottle(0);
EXPECT_EQ(0, sim.GetThrottle());
spark.SetDutyCycle(0.354);
EXPECT_EQ(0.354, sim.GetDutyCycle());
spark.SetThrottle(0.354);
EXPECT_EQ(0.354, sim.GetThrottle());
spark.SetDutyCycle(-0.785);
EXPECT_EQ(-0.785, sim.GetDutyCycle());
spark.SetThrottle(-0.785);
EXPECT_EQ(-0.785, sim.GetThrottle());
}
} // namespace wpi::sim

View File

@@ -42,7 +42,7 @@ TEST(StateSpaceSimTest, FlywheelSim) {
wpi::sim::RoboRioSim::SetVInVoltage(
wpi::sim::BatterySim::Calculate({sim.GetCurrentDraw()}));
sim.SetInput(wpi::math::Vectord<1>{
motor.GetDutyCycle() * wpi::RobotController::GetInputVoltage()});
motor.GetThrottle() * wpi::RobotController::GetInputVoltage()});
sim.Update(20_ms);
encoderSim.SetRate(sim.GetAngularVelocity().value());
}

View File

@@ -5,25 +5,20 @@
#pragma once
#include "wpi/hardware/motor/MotorController.hpp"
#include "wpi/util/deprecated.hpp"
namespace wpi {
WPI_IGNORE_DEPRECATED
class MockMotorController : public MotorController {
public:
void SetDutyCycle(double dutyCycle) override;
double GetDutyCycle() const override;
void SetThrottle(double throttle) override;
double GetThrottle() const override;
void SetInverted(bool isInverted) override;
bool GetInverted() const override;
void Disable() override;
private:
double m_dutyCycle = 0.0;
double m_throttle = 0.0;
bool m_isInverted = false;
};
WPI_UNIGNORE_DEPRECATED
} // namespace wpi

View File

@@ -8,15 +8,15 @@ namespace wpi {
class MockPWMMotorController {
public:
void SetDutyCycle(double dutyCycle);
double GetDutyCycle() const;
void SetThrottle(double throttle);
double GetThrottle() const;
void SetInverted(bool isInverted);
bool GetInverted() const;
void Disable();
void StopMotor();
private:
double m_dutyCycle = 0.0;
double m_throttle = 0.0;
bool m_isInverted = false;
};

View File

@@ -27,13 +27,13 @@ def test_motorcontrollergroup():
t2 = wpilib.Talon(8)
g = wpilib.MotorControllerGroup(t1, t2)
g.setDutyCycle(1)
assert t1.getDutyCycle() == pytest.approx(1)
assert t2.getDutyCycle() == pytest.approx(1)
g.setThrottle(1)
assert t1.getThrottle() == pytest.approx(1)
assert t2.getThrottle() == pytest.approx(1)
g.setDutyCycle(-1)
assert t1.getDutyCycle() == pytest.approx(-1)
assert t2.getDutyCycle() == pytest.approx(-1)
g.setThrottle(-1)
assert t1.getThrottle() == pytest.approx(-1)
assert t2.getThrottle() == pytest.approx(-1)
def test_motorcontrollergroup_error():

View File

@@ -15,8 +15,8 @@ class Robot : public wpi::TimedRobot {
wpi::PWMSparkMax m_leftMotor{0};
wpi::PWMSparkMax m_rightMotor{1};
wpi::DifferentialDrive m_robotDrive{
[&](double output) { m_leftMotor.SetDutyCycle(output); },
[&](double output) { m_rightMotor.SetDutyCycle(output); }};
[&](double output) { m_leftMotor.SetThrottle(output); },
[&](double output) { m_rightMotor.SetThrottle(output); }};
wpi::Gamepad m_driverController{0};
public:

View File

@@ -24,7 +24,7 @@ void Arm::SimulationPeriodic() {
// In this method, we update our simulation of what our arm is doing
// First, we set our "inputs" (voltages)
m_armSim.SetInput(wpi::math::Vectord<1>{
m_motor.GetDutyCycle() * wpi::RobotController::GetInputVoltage()});
m_motor.GetThrottle() * wpi::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms.
m_armSim.Update(20_ms);
@@ -59,5 +59,5 @@ void Arm::ReachSetpoint() {
}
void Arm::Stop() {
m_motor.SetDutyCycle(0.0);
m_motor.SetThrottle(0.0);
}

View File

@@ -123,9 +123,9 @@ void Drivetrain::SimulationPeriodic() {
// simulation, and write the simulated positions and velocities to our
// simulated encoder and gyro.
m_drivetrainSimulator.SetInputs(
wpi::units::volt_t{m_leftLeader.GetDutyCycle()} *
wpi::units::volt_t{m_leftLeader.GetThrottle()} *
wpi::RobotController::GetInputVoltage(),
wpi::units::volt_t{m_rightLeader.GetDutyCycle()} *
wpi::units::volt_t{m_rightLeader.GetThrottle()} *
wpi::RobotController::GetInputVoltage());
m_drivetrainSimulator.Update(20_ms);

View File

@@ -20,7 +20,7 @@ void Elevator::SimulationPeriodic() {
// In this method, we update our simulation of what our elevator is doing
// First, we set our "inputs" (voltages)
m_elevatorSim.SetInput(wpi::math::Vectord<1>{
m_motorSim.GetDutyCycle() * wpi::RobotController::GetInputVoltage()});
m_motorSim.GetThrottle() * wpi::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms.
m_elevatorSim.Update(20_ms);
@@ -59,5 +59,5 @@ void Elevator::Reset() {
}
void Elevator::Stop() {
m_motor.SetDutyCycle(0.0);
m_motor.SetThrottle(0.0);
}

View File

@@ -20,7 +20,7 @@ void Elevator::SimulationPeriodic() {
// In this method, we update our simulation of what our elevator is doing
// First, we set our "inputs" (voltages)
m_elevatorSim.SetInput(wpi::math::Vectord<1>{
m_motorSim.GetDutyCycle() * wpi::RobotController::GetInputVoltage()});
m_motorSim.GetThrottle() * wpi::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms.
m_elevatorSim.Update(20_ms);
@@ -50,5 +50,5 @@ void Elevator::ReachGoal(wpi::units::meter_t goal) {
void Elevator::Stop() {
m_controller.SetGoal(0.0_m);
m_motor.SetDutyCycle(0.0);
m_motor.SetThrottle(0.0);
}

View File

@@ -52,8 +52,8 @@ class Robot : public wpi::TimedRobot {
wpi::PWMSparkMax m_left{0};
wpi::PWMSparkMax m_right{1};
wpi::DifferentialDrive m_robotDrive{
[&](double output) { m_left.SetDutyCycle(output); },
[&](double output) { m_right.SetDutyCycle(output); }};
[&](double output) { m_left.SetThrottle(output); },
[&](double output) { m_right.SetThrottle(output); }};
wpi::Gamepad m_controller{0};
wpi::Timer m_timer;

View File

@@ -51,8 +51,8 @@ class Robot : public wpi::TimedRobot {
wpi::PWMSparkMax m_left{kLeftMotorPort};
wpi::PWMSparkMax m_right{kRightMotorPort};
wpi::DifferentialDrive m_drive{
[&](double output) { m_left.SetDutyCycle(output); },
[&](double output) { m_right.SetDutyCycle(output); }};
[&](double output) { m_left.SetThrottle(output); },
[&](double output) { m_right.SetThrottle(output); }};
wpi::OnboardIMU m_imu{kIMUMountOrientation};
wpi::Joystick m_joystick{kJoystickPort};

View File

@@ -63,8 +63,8 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase {
// The robot's drive
wpi::DifferentialDrive m_drive{
[&](double output) { m_left1.SetDutyCycle(output); },
[&](double output) { m_right1.SetDutyCycle(output); }};
[&](double output) { m_left1.SetThrottle(output); },
[&](double output) { m_right1.SetThrottle(output); }};
// The left-side drive encoder
wpi::Encoder m_leftEncoder;

View File

@@ -63,8 +63,8 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase {
// The robot's drive
wpi::DifferentialDrive m_drive{
[&](double output) { m_left1.SetDutyCycle(output); },
[&](double output) { m_right1.SetDutyCycle(output); }};
[&](double output) { m_left1.SetThrottle(output); },
[&](double output) { m_right1.SetThrottle(output); }};
// The left-side drive encoder
wpi::Encoder m_leftEncoder;

View File

@@ -52,10 +52,10 @@ class Robot : public wpi::TimedRobot {
wpi::PWMSparkMax m_frontRight{kFrontRightMotorPort};
wpi::PWMSparkMax m_rearRight{kRearRightMotorPort};
wpi::MecanumDrive m_robotDrive{
[&](double output) { m_frontLeft.SetDutyCycle(output); },
[&](double output) { m_rearLeft.SetDutyCycle(output); },
[&](double output) { m_frontRight.SetDutyCycle(output); },
[&](double output) { m_rearRight.SetDutyCycle(output); }};
[&](double output) { m_frontLeft.SetThrottle(output); },
[&](double output) { m_rearLeft.SetThrottle(output); },
[&](double output) { m_frontRight.SetThrottle(output); },
[&](double output) { m_rearRight.SetThrottle(output); }};
wpi::OnboardIMU m_imu{kIMUMountOrientation};
wpi::Joystick m_joystick{kJoystickPort};

View File

@@ -44,8 +44,8 @@ class Robot : public wpi::TimedRobot {
}
void TeleopPeriodic() override {
m_elevatorMotor.SetDutyCycle(m_joystick.GetRawAxis(0));
m_wristMotor.SetDutyCycle(m_joystick.GetRawAxis(1));
m_elevatorMotor.SetThrottle(m_joystick.GetRawAxis(0));
m_wristMotor.SetThrottle(m_joystick.GetRawAxis(1));
}
private:

View File

@@ -6,7 +6,7 @@
wpi::cmd::CommandPtr Intake::IntakeCommand() {
return RunOnce([this] { m_piston.Set(wpi::DoubleSolenoid::FORWARD); })
.AndThen(Run([this] { m_motor.SetDutyCycle(1.0); }))
.AndThen(Run([this] { m_motor.SetThrottle(1.0); }))
.WithName("Intake");
}

View File

@@ -34,6 +34,6 @@ wpi::cmd::CommandPtr Shooter::ShootCommand(
// run the feeder
wpi::cmd::cmd::WaitUntil([this] {
return m_shooterFeedback.AtSetpoint();
}).AndThen([this] { m_feederMotor.SetDutyCycle(1.0); }))
}).AndThen([this] { m_feederMotor.SetThrottle(1.0); }))
.WithName("Shoot");
}

View File

@@ -10,5 +10,5 @@ Storage::Storage() {
}
wpi::cmd::CommandPtr Storage::RunCommand() {
return Run([this] { m_motor.SetDutyCycle(1.0); }).WithName("Run");
return Run([this] { m_motor.SetThrottle(1.0); }).WithName("Run");
}

View File

@@ -55,8 +55,8 @@ class Drive : public wpi::cmd::SubsystemBase {
wpi::PWMSparkMax m_rightFollower{DriveConstants::kRightMotor2Port};
wpi::DifferentialDrive m_drive{
[&](double output) { m_leftLeader.SetDutyCycle(output); },
[&](double output) { m_rightLeader.SetDutyCycle(output); }};
[&](double output) { m_leftLeader.SetThrottle(output); },
[&](double output) { m_rightLeader.SetThrottle(output); }};
wpi::Encoder m_leftEncoder{DriveConstants::kLeftEncoderPorts[0],
DriveConstants::kLeftEncoderPorts[1],

View File

@@ -106,8 +106,8 @@ class Drivetrain : public wpi::cmd::SubsystemBase {
wpi::Encoder m_rightEncoder{6, 7};
wpi::DifferentialDrive m_drive{
[&](double output) { m_leftMotor.SetDutyCycle(output); },
[&](double output) { m_rightMotor.SetDutyCycle(output); }};
[&](double output) { m_leftMotor.SetThrottle(output); },
[&](double output) { m_rightMotor.SetThrottle(output); }};
wpi::romi::RomiGyro m_gyro;
};

View File

@@ -43,9 +43,9 @@ void Drivetrain::SimulationPeriodic() {
// simulated encoder and gyro. We negate the right side so that positive
// voltages make the right side move forward.
m_drivetrainSimulator.SetInputs(
wpi::units::volt_t{m_leftLeader.GetDutyCycle()} *
wpi::units::volt_t{m_leftLeader.GetThrottle()} *
wpi::RobotController::GetInputVoltage(),
wpi::units::volt_t{m_rightLeader.GetDutyCycle()} *
wpi::units::volt_t{m_rightLeader.GetThrottle()} *
wpi::RobotController::GetInputVoltage());
m_drivetrainSimulator.Update(20_ms);

View File

@@ -22,7 +22,7 @@ wpi::cmd::CommandPtr Shooter::RunShooterCommand(
m_shooterEncoder.GetRate(), shooterVelocity())} +
m_shooterFeedforward.Calculate(
wpi::units::turns_per_second_t{shooterVelocity()}));
m_feederMotor.SetDutyCycle(constants::shooter::kFeederVelocity);
m_feederMotor.SetThrottle(constants::shooter::kFeederVelocity);
},
{this})
.WithName("Set Shooter Velocity");

View File

@@ -27,8 +27,8 @@ class Drive : public wpi::cmd::SubsystemBase {
wpi::PWMSparkMax m_leftMotor{constants::drive::kLeftMotor1Port};
wpi::PWMSparkMax m_rightMotor{constants::drive::kRightMotor1Port};
wpi::DifferentialDrive m_drive{
[this](auto val) { m_leftMotor.SetDutyCycle(val); },
[this](auto val) { m_rightMotor.SetDutyCycle(val); }};
[this](auto val) { m_leftMotor.SetThrottle(val); },
[this](auto val) { m_rightMotor.SetThrottle(val); }};
wpi::Encoder m_leftEncoder{constants::drive::kLeftEncoderPorts[0],
constants::drive::kLeftEncoderPorts[1],
@@ -48,13 +48,13 @@ class Drive : public wpi::cmd::SubsystemBase {
},
[this](wpi::sysid::SysIdRoutineLog* log) {
log->Motor("drive-left")
.voltage(m_leftMotor.GetDutyCycle() *
.voltage(m_leftMotor.GetThrottle() *
wpi::RobotController::GetBatteryVoltage())
.position(wpi::units::meter_t{m_leftEncoder.GetDistance()})
.velocity(
wpi::units::meters_per_second_t{m_leftEncoder.GetRate()});
log->Motor("drive-right")
.voltage(m_rightMotor.GetDutyCycle() *
.voltage(m_rightMotor.GetThrottle() *
wpi::RobotController::GetBatteryVoltage())
.position(wpi::units::meter_t{m_rightEncoder.GetDistance()})
.velocity(

View File

@@ -41,7 +41,7 @@ class Shooter : public wpi::cmd::SubsystemBase {
},
[this](wpi::sysid::SysIdRoutineLog* log) {
log->Motor("shooter-wheel")
.voltage(m_shooterMotor.GetDutyCycle() *
.voltage(m_shooterMotor.GetThrottle() *
wpi::RobotController::GetBatteryVoltage())
.position(wpi::units::turn_t{m_shooterEncoder.GetDistance()})
.velocity(

View File

@@ -15,8 +15,8 @@ class Robot : public wpi::TimedRobot {
wpi::PWMSparkMax m_leftMotor{0};
wpi::PWMSparkMax m_rightMotor{1};
wpi::DifferentialDrive m_robotDrive{
[&](double output) { m_leftMotor.SetDutyCycle(output); },
[&](double output) { m_rightMotor.SetDutyCycle(output); }};
[&](double output) { m_leftMotor.SetThrottle(output); },
[&](double output) { m_rightMotor.SetThrottle(output); }};
wpi::Gamepad m_driverController{0};
public:

View File

@@ -10,14 +10,14 @@ void Intake::Deploy() {
void Intake::Retract() {
m_piston.Set(wpi::DoubleSolenoid::Value::REVERSE);
m_motor.SetDutyCycle(0); // turn off the motor
m_motor.SetThrottle(0); // turn off the motor
}
void Intake::Activate(double velocity) {
if (IsDeployed()) {
m_motor.SetDutyCycle(velocity);
m_motor.SetThrottle(velocity);
} else { // if piston isn't open, do nothing
m_motor.SetDutyCycle(0);
m_motor.SetThrottle(0);
}
}

View File

@@ -111,8 +111,8 @@ class Drivetrain : public wpi::cmd::SubsystemBase {
wpi::Encoder m_rightEncoder{6, 7};
wpi::DifferentialDrive m_drive{
[&](double output) { m_leftMotor.SetDutyCycle(output); },
[&](double output) { m_rightMotor.SetDutyCycle(output); }};
[&](double output) { m_leftMotor.SetThrottle(output); },
[&](double output) { m_rightMotor.SetThrottle(output); }};
wpi::xrp::XRPGyro m_gyro;
};

View File

@@ -27,6 +27,6 @@ class Robot : public wpi::TimedRobot {
wpi::Timer m_timer;
wpi::DifferentialDrive m_drive{
[&](double output) { m_leftMotor.SetDutyCycle(output); },
[&](double output) { m_rightMotor.SetDutyCycle(output); }};
[&](double output) { m_leftMotor.SetThrottle(output); },
[&](double output) { m_rightMotor.SetThrottle(output); }};
};

View File

@@ -44,8 +44,8 @@ class Robot : public wpi::TimedRobot {
wpi::Spark rightLeader{2};
wpi::Spark rightFollower{3};
wpi::DifferentialDrive drive{
[&](double output) { leftLeader.SetDutyCycle(output); },
[&](double output) { rightLeader.SetDutyCycle(output); }};
[&](double output) { leftLeader.SetThrottle(output); },
[&](double output) { rightLeader.SetThrottle(output); }};
};
#ifndef RUNNING_WPILIB_TESTS

View File

@@ -17,9 +17,9 @@ class Robot : public wpi::TimedRobot {
// Runs the motor backwards at half velocity until the limit switch is
// pressed then turn off the motor and reset the encoder
if (!m_limit.Get()) {
m_spark.SetDutyCycle(-0.5);
m_spark.SetThrottle(-0.5);
} else {
m_spark.SetDutyCycle(0);
m_spark.SetThrottle(0);
m_encoder.Reset();
}
}

View File

@@ -36,14 +36,14 @@ class Robot : public wpi::TimedRobot {
// and there is not a ball at the kicker
&& !isBallAtKicker)
// activate the intake
.IfHigh([&intake = m_intake] { intake.SetDutyCycle(0.5); });
.IfHigh([&intake = m_intake] { intake.SetThrottle(0.5); });
// if the thumb button is not held
(!intakeButton
// or there is a ball in the kicker
|| isBallAtKicker)
// stop the intake
.IfHigh([&intake = m_intake] { intake.SetDutyCycle(0.0); });
.IfHigh([&intake = m_intake] { intake.SetThrottle(0.0); });
wpi::BooleanEvent shootTrigger{
&m_loop, [&joystick = m_joystick] { return joystick.GetTrigger(); }};
@@ -60,7 +60,7 @@ class Robot : public wpi::TimedRobot {
});
// if not, stop
(!shootTrigger).IfHigh([&shooter = m_shooter] {
shooter.SetDutyCycle(0.0);
shooter.SetThrottle(0.0);
});
wpi::BooleanEvent atTargetVelocity =
@@ -71,13 +71,13 @@ class Robot : public wpi::TimedRobot {
.Debounce(0.2_s);
// if we're at the target velocity, kick the ball into the shooter wheel
atTargetVelocity.IfHigh([&kicker = m_kicker] { kicker.SetDutyCycle(0.7); });
atTargetVelocity.IfHigh([&kicker = m_kicker] { kicker.SetThrottle(0.7); });
// when we stop being at the target velocity, it means the ball was shot
atTargetVelocity
.Falling()
// so stop the kicker
.IfHigh([&kicker = m_kicker] { kicker.SetDutyCycle(0.0); });
.IfHigh([&kicker = m_kicker] { kicker.SetThrottle(0.0); });
}
void RobotPeriodic() override { m_loop.Poll(); }

View File

@@ -52,7 +52,7 @@ class Robot : public wpi::TimedRobot {
// To update our simulation, we set motor voltage inputs, update the
// simulation, and write the simulated velocities to our simulated encoder
m_flywheelSim.SetInputVoltage(
m_flywheelMotor.GetDutyCycle() *
m_flywheelMotor.GetThrottle() *
wpi::units::volt_t{wpi::RobotController::GetInputVoltage()});
m_flywheelSim.Update(20_ms);
m_encoderSim.SetRate(m_flywheelSim.GetAngularVelocity().value());

View File

@@ -18,20 +18,20 @@ class Robot : public wpi::TimedRobot {
if (velocity > 0) {
if (m_toplimitSwitch.Get()) {
// We are going up and top limit is tripped so stop
m_motor.SetDutyCycle(0);
m_motor.SetThrottle(0);
} else {
// We are going up but top limit is not tripped so go at commanded
// velocity
m_motor.SetDutyCycle(velocity);
m_motor.SetThrottle(velocity);
}
} else {
if (m_bottomlimitSwitch.Get()) {
// We are going down and bottom limit is tripped so stop
m_motor.SetDutyCycle(0);
m_motor.SetThrottle(0);
} else {
// We are going down but bottom limit is not tripped so go at commanded
// velocity
m_motor.SetDutyCycle(velocity);
m_motor.SetThrottle(velocity);
}
}
}

View File

@@ -23,7 +23,7 @@
*/
class Robot : public wpi::TimedRobot {
public:
void TeleopPeriodic() override { m_motor.SetDutyCycle(m_stick.GetY()); }
void TeleopPeriodic() override { m_motor.SetThrottle(m_stick.GetY()); }
/*
* The RobotPeriodic function is called every control packet no matter the

View File

@@ -134,7 +134,7 @@ TEST_P(ArmSimulationTest, Teleop) {
wpi::sim::StepTiming(3_s);
ASSERT_NEAR(0.0, m_motorSim.GetDutyCycle(), 0.05);
ASSERT_NEAR(0.0, m_motorSim.GetThrottle(), 0.05);
EXPECT_NEAR(kMinAngle.value(), m_encoderSim.GetDistance(), 2.0);
}
}

View File

@@ -118,7 +118,7 @@ TEST_F(ElevatorSimulationTest, Teleop) {
// advance 75 timesteps
wpi::sim::StepTiming(1.5_s);
ASSERT_NEAR(0.0, m_motorSim.GetDutyCycle(), 0.05);
ASSERT_NEAR(0.0, m_motorSim.GetThrottle(), 0.05);
ASSERT_NEAR(0.0, m_encoderSim.GetDistance(), 0.05);
}
}

View File

@@ -27,13 +27,13 @@ TEST_F(IntakeTest, DoesntWorkWhenClosed) {
EXPECT_DOUBLE_EQ(
0.0,
simMotor
.GetDutyCycle()); // make sure that the value set to the motor is 0
.GetThrottle()); // make sure that the value set to the motor is 0
}
TEST_F(IntakeTest, WorksWhenOpen) {
intake.Deploy();
intake.Activate(0.5);
EXPECT_DOUBLE_EQ(0.5, simMotor.GetDutyCycle());
EXPECT_DOUBLE_EQ(0.5, simMotor.GetThrottle());
}
TEST_F(IntakeTest, Retract) {

View File

@@ -37,7 +37,7 @@ public class {{ name }} extends PWMMotorController {
setBoundsMicroseconds({{ (pulse_width_ms.max * 1000) | int }}, {{ (pulse_width_ms.deadbandMax * 1000) | int }}, {{ (pulse_width_ms.center * 1000) | int }}, {{ (pulse_width_ms.deadbandMin * 1000) | int }}, {{ (pulse_width_ms.min * 1000) | int }});
m_pwm.setOutputPeriod({{ OutputPeriod | default("5", true)}});
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "{{ ResourceName }}");
}

View File

@@ -37,7 +37,7 @@ public class Koors40 extends PWMMotorController {
setBoundsMicroseconds(2004, 1520, 1500, 1480, 997);
m_pwm.setOutputPeriod(20);
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "Koors40");
}

View File

@@ -37,7 +37,7 @@ public class PWMSparkFlex extends PWMMotorController {
setBoundsMicroseconds(2003, 1550, 1500, 1460, 999);
m_pwm.setOutputPeriod(5);
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "RevSparkFlexPWM");
}

View File

@@ -37,7 +37,7 @@ public class PWMSparkMax extends PWMMotorController {
setBoundsMicroseconds(2003, 1550, 1500, 1460, 999);
m_pwm.setOutputPeriod(5);
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "RevSparkMaxPWM");
}

View File

@@ -37,7 +37,7 @@ public class PWMTalonFX extends PWMMotorController {
setBoundsMicroseconds(2004, 1520, 1500, 1480, 997);
m_pwm.setOutputPeriod(5);
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "TalonFX");
}

View File

@@ -37,7 +37,7 @@ public class PWMTalonSRX extends PWMMotorController {
setBoundsMicroseconds(2004, 1520, 1500, 1480, 997);
m_pwm.setOutputPeriod(5);
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "PWMTalonSRX");
}

View File

@@ -37,7 +37,7 @@ public class PWMVenom extends PWMMotorController {
setBoundsMicroseconds(2004, 1520, 1500, 1480, 997);
m_pwm.setOutputPeriod(5);
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "FusionVenom");
}

View File

@@ -37,7 +37,7 @@ public class PWMVictorSPX extends PWMMotorController {
setBoundsMicroseconds(2004, 1520, 1500, 1480, 997);
m_pwm.setOutputPeriod(5);
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "PWMVictorSPX");
}

View File

@@ -37,7 +37,7 @@ public class Spark extends PWMMotorController {
setBoundsMicroseconds(2003, 1550, 1500, 1460, 999);
m_pwm.setOutputPeriod(5);
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "RevSPARK");
}

View File

@@ -37,7 +37,7 @@ public class SparkMini extends PWMMotorController {
setBoundsMicroseconds(2500, 1510, 1500, 1490, 500);
m_pwm.setOutputPeriod(5);
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "RevSPARK");
}

View File

@@ -37,7 +37,7 @@ public class Talon extends PWMMotorController {
setBoundsMicroseconds(2037, 1539, 1513, 1487, 989);
m_pwm.setOutputPeriod(5);
setDutyCycle(0.0);
setThrottle(0.0);
HAL.reportUsage("IO", getChannel(), "Talon");
}

Some files were not shown because too many files have changed in this diff Show More