|
13 | 13 | import edu.wpi.first.units.AngleUnit; |
14 | 14 | import edu.wpi.first.units.Units; |
15 | 15 | import edu.wpi.first.units.measure.Angle; |
| 16 | +import edu.wpi.first.units.measure.Current; |
16 | 17 | import java.util.Objects; |
17 | 18 | import java.util.function.Supplier; |
18 | 19 | import org.apiguardian.api.API; |
|
36 | 37 | * setpoint and then maintain position at the setpoint under the control of the PID controller. |
37 | 38 | * |
38 | 39 | * <p>The <b>Direct User Input Mode</b> is activated when the user calls the {@link |
39 | | - * #setDemand(ControlMode, double)}. The PID Mode is interrupted and disengaged, and the provided |
40 | | - * demand will be directly sent to the motor. |
| 40 | + * #set(ControlMode, double)}. The PID Mode is interrupted and disengaged, and the provided demand |
| 41 | + * will be directly sent to the motor. |
41 | 42 | * |
42 | | - * <p>To stop the motor, call {@link #stopMotor()}. |
| 43 | + * <p>To stop the motor, call {@link #disable()}. |
43 | 44 | * |
44 | 45 | * @param <P> an enum implementing {@link Supplier<Angle>} used to specify setpoints. |
45 | 46 | */ |
46 | 47 | @API(status = API.Status.EXPERIMENTAL) |
47 | | -public final class PositionalMotor<P extends Enum<P> & Supplier<Angle>> implements AutoCloseable { |
| 48 | +public final class PositionalMotor<P extends Enum<P> & Supplier<Angle>> |
| 49 | + implements AutoCloseable, Motor { |
48 | 50 | /** The default acceptable position error. */ |
49 | 51 | public static final double DEFAULT_ERROR = 5.0; |
50 | 52 |
|
@@ -253,16 +255,32 @@ public void setSetpoint(P position) { |
253 | 255 | } |
254 | 256 |
|
255 | 257 | /** |
256 | | - * Sets the motor to run with a specified mode of control and disables PID control. |
| 258 | + * {@inheritDoc} |
257 | 259 | * |
258 | | - * @param mode The mode to control the motor with |
259 | | - * @param demand The demand of the motor. differentiating meaning with each control mode |
| 260 | + * <p>Additionally, this method disables PID control of the subsystem |
260 | 261 | */ |
261 | | - public void setDemand(ControlMode mode, double demand) { |
| 262 | + @Override |
| 263 | + public void set(ControlMode mode, double demand) { |
262 | 264 | isPIDControlEnabled = false; |
263 | 265 | motor.set(mode, demand); |
264 | 266 | } |
265 | 267 |
|
| 268 | + /** |
| 269 | + * {@inheritDoc} |
| 270 | + * |
| 271 | + * <p>Additionally, this method disables PID control of the subsystem |
| 272 | + */ |
| 273 | + @Override |
| 274 | + public void set(ControlMode mode, double demand, double feedForward) { |
| 275 | + isPIDControlEnabled = false; |
| 276 | + motor.set(mode, demand, feedForward); |
| 277 | + } |
| 278 | + |
| 279 | + @Override |
| 280 | + public Current getAppliedCurrent() { |
| 281 | + return motor.getAppliedCurrent(); |
| 282 | + } |
| 283 | + |
266 | 284 | /** |
267 | 285 | * Engages the PID Controller. |
268 | 286 | * |
@@ -291,7 +309,8 @@ public boolean isPIDControlEnabled() { |
291 | 309 | * <p>The motor voltage will be set to zero, and the motor will not adjust to move towards the |
292 | 310 | * current setpoint. |
293 | 311 | */ |
294 | | - public void stopMotor() { |
| 312 | + @Override |
| 313 | + public void disable() { |
295 | 314 | isPIDControlEnabled = false; |
296 | 315 | motor.disable(); |
297 | 316 | } |
|
0 commit comments