Skip to content

Commit 3426491

Browse files
committed
Update PositionalMotor to implement Motor
1 parent 75547e0 commit 3426491

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

lib/src/main/java/com/team2813/lib2813/control/motors/PositionalMotor.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import edu.wpi.first.units.AngleUnit;
1414
import edu.wpi.first.units.Units;
1515
import edu.wpi.first.units.measure.Angle;
16+
import edu.wpi.first.units.measure.Current;
1617
import java.util.Objects;
1718
import java.util.function.Supplier;
1819
import org.apiguardian.api.API;
@@ -36,15 +37,16 @@
3637
* setpoint and then maintain position at the setpoint under the control of the PID controller.
3738
*
3839
* <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.
4142
*
42-
* <p>To stop the motor, call {@link #stopMotor()}.
43+
* <p>To stop the motor, call {@link #disable()}.
4344
*
4445
* @param <P> an enum implementing {@link Supplier<Angle>} used to specify setpoints.
4546
*/
4647
@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 {
4850
/** The default acceptable position error. */
4951
public static final double DEFAULT_ERROR = 5.0;
5052

@@ -253,16 +255,32 @@ public void setSetpoint(P position) {
253255
}
254256

255257
/**
256-
* Sets the motor to run with a specified mode of control and disables PID control.
258+
* {@inheritDoc}
257259
*
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
260261
*/
261-
public void setDemand(ControlMode mode, double demand) {
262+
@Override
263+
public void set(ControlMode mode, double demand) {
262264
isPIDControlEnabled = false;
263265
motor.set(mode, demand);
264266
}
265267

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+
266284
/**
267285
* Engages the PID Controller.
268286
*
@@ -291,7 +309,8 @@ public boolean isPIDControlEnabled() {
291309
* <p>The motor voltage will be set to zero, and the motor will not adjust to move towards the
292310
* current setpoint.
293311
*/
294-
public void stopMotor() {
312+
@Override
313+
public void disable() {
295314
isPIDControlEnabled = false;
296315
motor.disable();
297316
}

0 commit comments

Comments
 (0)