mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilib] Rename MotorController setDutyCycle() to setThrottle() (#8720)
Fixes #8716.
This commit is contained in:
@@ -104,8 +104,8 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC
|
||||
@SuppressWarnings({"removal", "this-escape"})
|
||||
public DifferentialDrive(MotorController leftMotor, MotorController rightMotor) {
|
||||
this(
|
||||
(double output) -> leftMotor.setDutyCycle(output),
|
||||
(double output) -> rightMotor.setDutyCycle(output));
|
||||
(double output) -> leftMotor.setThrottle(output),
|
||||
(double output) -> rightMotor.setThrottle(output));
|
||||
SendableRegistry.addChild(this, leftMotor);
|
||||
SendableRegistry.addChild(this, rightMotor);
|
||||
}
|
||||
|
||||
@@ -120,10 +120,10 @@ public class MecanumDrive extends RobotDriveBase implements Sendable, AutoClosea
|
||||
MotorController frontRightMotor,
|
||||
MotorController rearRightMotor) {
|
||||
this(
|
||||
(double output) -> frontLeftMotor.setDutyCycle(output),
|
||||
(double output) -> rearLeftMotor.setDutyCycle(output),
|
||||
(double output) -> frontRightMotor.setDutyCycle(output),
|
||||
(double output) -> rearRightMotor.setDutyCycle(output));
|
||||
(double output) -> frontLeftMotor.setThrottle(output),
|
||||
(double output) -> rearLeftMotor.setThrottle(output),
|
||||
(double output) -> frontRightMotor.setThrottle(output),
|
||||
(double output) -> rearRightMotor.setThrottle(output));
|
||||
SendableRegistry.addChild(this, frontLeftMotor);
|
||||
SendableRegistry.addChild(this, rearLeftMotor);
|
||||
SendableRegistry.addChild(this, frontRightMotor);
|
||||
|
||||
@@ -151,14 +151,14 @@ public class ExpansionHubMotor implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 represents full reverse and 1 represents full forward.
|
||||
*/
|
||||
public void setDutyCycle(double dutyCycle) {
|
||||
public void setThrottle(double throttle) {
|
||||
setEnabled(true);
|
||||
m_modePublisher.set(kPercentageMode);
|
||||
m_setpointPublisher.set(dutyCycle);
|
||||
m_setpointPublisher.set(throttle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,11 +12,11 @@ import org.wpilib.units.measure.Voltage;
|
||||
/** Interface for motor controlling devices. */
|
||||
public interface MotorController {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void setDutyCycle(double dutyCycle);
|
||||
void setThrottle(double throttle);
|
||||
|
||||
/**
|
||||
* Sets the voltage output of the motor controller.
|
||||
@@ -31,7 +31,7 @@ public interface MotorController {
|
||||
* @param voltage The voltage.
|
||||
*/
|
||||
default void setVoltage(double voltage) {
|
||||
setDutyCycle(voltage / RobotController.getBatteryVoltage());
|
||||
setThrottle(voltage / RobotController.getBatteryVoltage());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,11 +51,11 @@ public interface MotorController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
double getDutyCycle();
|
||||
double getThrottle();
|
||||
|
||||
/**
|
||||
* Sets the inversion state of the motor controller.
|
||||
|
||||
@@ -25,7 +25,7 @@ public abstract class PWMMotorController extends MotorSafety
|
||||
protected PWM m_pwm;
|
||||
|
||||
private SimDevice m_simDevice;
|
||||
private SimDouble m_simDutyCycle;
|
||||
private SimDouble m_simThrottle;
|
||||
|
||||
private boolean m_eliminateDeadband;
|
||||
private int m_minPwm;
|
||||
@@ -47,7 +47,7 @@ public abstract class PWMMotorController extends MotorSafety
|
||||
|
||||
m_simDevice = SimDevice.create("PWMMotorController", channel);
|
||||
if (m_simDevice != null) {
|
||||
m_simDutyCycle = m_simDevice.createDouble("DutyCycle", Direction.OUTPUT, 0.0);
|
||||
m_simThrottle = m_simDevice.createDouble("Throttle", Direction.OUTPUT, 0.0);
|
||||
m_pwm.setSimDevice(m_simDevice);
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public abstract class PWMMotorController extends MotorSafety
|
||||
if (m_simDevice != null) {
|
||||
m_simDevice.close();
|
||||
m_simDevice = null;
|
||||
m_simDutyCycle = null;
|
||||
m_simThrottle = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,8 +102,8 @@ public abstract class PWMMotorController extends MotorSafety
|
||||
dutyCycle = 0.0;
|
||||
}
|
||||
|
||||
if (m_simDutyCycle != null) {
|
||||
m_simDutyCycle.set(dutyCycle);
|
||||
if (m_simThrottle != null) {
|
||||
m_simThrottle.set(dutyCycle);
|
||||
}
|
||||
|
||||
int rawValue;
|
||||
@@ -161,21 +161,21 @@ public abstract class PWMMotorController extends MotorSafety
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDutyCycle(double dutyCycle) {
|
||||
public void setThrottle(double throttle) {
|
||||
if (m_isInverted) {
|
||||
dutyCycle = -dutyCycle;
|
||||
throttle = -throttle;
|
||||
}
|
||||
setDutyCycleInternal(dutyCycle);
|
||||
setDutyCycleInternal(throttle);
|
||||
|
||||
for (var follower : m_followers) {
|
||||
follower.setDutyCycle(dutyCycle);
|
||||
follower.setThrottle(throttle);
|
||||
}
|
||||
|
||||
feed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDutyCycle() {
|
||||
public double getThrottle() {
|
||||
return getDutyCycleInternal() * (m_isInverted ? -1.0 : 1.0);
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ public abstract class PWMMotorController extends MotorSafety
|
||||
* @return The voltage of the motor controller, nominally between -12 V and 12 V.
|
||||
*/
|
||||
public double getVoltage() {
|
||||
return getDutyCycle() * RobotController.getBatteryVoltage();
|
||||
return getThrottle() * RobotController.getBatteryVoltage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -202,8 +202,8 @@ public abstract class PWMMotorController extends MotorSafety
|
||||
public void disable() {
|
||||
m_pwm.setDisabled();
|
||||
|
||||
if (m_simDutyCycle != null) {
|
||||
m_simDutyCycle.set(0.0);
|
||||
if (m_simThrottle != null) {
|
||||
m_simThrottle.set(0.0);
|
||||
}
|
||||
|
||||
for (var follower : m_followers) {
|
||||
@@ -263,6 +263,6 @@ public abstract class PWMMotorController extends MotorSafety
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("Motor Controller");
|
||||
builder.setActuator(true);
|
||||
builder.addDoubleProperty("Value", this::getDutyCycle, this::setDutyCycle);
|
||||
builder.addDoubleProperty("Value", this::getThrottle, this::setThrottle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.wpilib.hardware.motor.PWMMotorController;
|
||||
|
||||
/** Class to control a simulated PWM motor controller. */
|
||||
public class PWMMotorControllerSim {
|
||||
private final SimDouble m_simDutyCycle;
|
||||
private final SimDouble m_simThrottle;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -27,15 +27,15 @@ public class PWMMotorControllerSim {
|
||||
*/
|
||||
public PWMMotorControllerSim(int channel) {
|
||||
SimDeviceSim simDevice = new SimDeviceSim("PWMMotorController", channel);
|
||||
m_simDutyCycle = simDevice.getDouble("DutyCycle");
|
||||
m_simThrottle = simDevice.getDouble("Throttle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the motor duty cycle.
|
||||
* Gets the motor throttle.
|
||||
*
|
||||
* @return Duty cycle
|
||||
* @return Throttle
|
||||
*/
|
||||
public double getDutyCycle() {
|
||||
return m_simDutyCycle.get();
|
||||
public double getThrottle() {
|
||||
return m_simThrottle.get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user