Class PWMMotorController
java.lang.Object
org.wpilib.hardware.motor.MotorSafety
org.wpilib.hardware.motor.PWMMotorController
- All Implemented Interfaces:
AutoCloseable, MotorController, TelemetryLoggable
- Direct Known Subclasses:
Koors40, PWMSparkFlex, PWMSparkMax, PWMTalonFX, PWMTalonSRX, PWMVenom, PWMVictorSPX, Spark, SparkMini, Talon, VictorSP
public abstract class PWMMotorController
extends MotorSafety
implements MotorController, TelemetryLoggable, AutoCloseable
Common base class for all PWM Motor Controllers.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFollower(PWMMotorController follower) Make the given PWM motor controller follow the output of this one.voidclose()Free the resource associated with the PWM channel and set the value to 0.voiddisable()Disables the motor controller.voidenableDeadbandElimination(boolean eliminateDeadband) Optionally eliminate the deadband from a motor controller.intGets the PWM channel number.Returns a description to print when an error occurs.protected final doubleGets the duty cycle from -1 to 1 (the sign indicates direction), from the currently set pulse time.booleanGets the inversion state of the motor controller.intGets the backing PWM handle.Gets the telemetry table type.doubleGets the throttle of the motor controller.doubleGets the voltage output of the motor controller, nominally between -12 V and 12 V.voidlogTo(TelemetryTable table) Logs the object to aTelemetryTable.protected final voidsetBoundsMicroseconds(int maxPwm, int deadbandMaxPwm, int centerPwm, int deadbandMinPwm, int minPwm) Sets the bounds in microseconds for the controller.protected final voidsetDutyCycleInternal(double dutyCycle) Takes a duty cycle from -1 to 1 (the sign indicates direction), and outputs it in the microsecond format.voidsetInverted(boolean isInverted) Sets the inversion state of the motor controller.voidsetThrottle(double throttle) Sets the throttle of the motor controller.voidCalled to stop the motor when the timeout expires.Methods inherited from class MotorSafety
check, checkMotors, feed, getExpiration, isAlive, isSafetyEnabled, setExpiration, setSafetyEnabledMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MotorController
setVoltage, setVoltage
-
Field Details
-
m_pwm
PWM instances for motor controller.
-
-
Constructor Details
-
PWMMotorController
protected PWMMotorController(int channel) Constructor.- Parameters:
channel- The SmartIO channel that the controller is attached to.
-
-
Method Details
-
close
public void close()Free the resource associated with the PWM channel and set the value to 0.- Specified by:
closein interfaceAutoCloseable
-
setDutyCycleInternal
protected final void setDutyCycleInternal(double dutyCycle) Takes a duty cycle from -1 to 1 (the sign indicates direction), and outputs it in the microsecond format.- Parameters:
dutyCycle- The duty cycle between -1 and 1 (sign indicates direction).
-
getDutyCycleInternal
protected final double getDutyCycleInternal()Gets the duty cycle from -1 to 1 (the sign indicates direction), from the currently set pulse time.- Returns:
- motor controller duty cycle
-
setBoundsMicroseconds
protected final void setBoundsMicroseconds(int maxPwm, int deadbandMaxPwm, int centerPwm, int deadbandMinPwm, int minPwm) Sets the bounds in microseconds for the controller.- Parameters:
maxPwm- maximumdeadbandMaxPwm- deadband maxcenterPwm- centerdeadbandMinPwm- deadband minminPwm- minimum
-
setThrottle
public void setThrottle(double throttle) Description copied from interface:MotorControllerSets the throttle of the motor controller.- Specified by:
setThrottlein interfaceMotorController- Parameters:
throttle- The throttle where -1 indicates full reverse and 1 indicates full forward.
-
getThrottle
public double getThrottle()Description copied from interface:MotorControllerGets the throttle of the motor controller.- Specified by:
getThrottlein interfaceMotorController- Returns:
- The throttle where -1 represents full reverse and 1 represents full forward.
-
getVoltage
public double getVoltage()Gets the voltage output of the motor controller, nominally between -12 V and 12 V.- Returns:
- The voltage of the motor controller, nominally between -12 V and 12 V.
-
setInverted
public void setInverted(boolean isInverted) Description copied from interface:MotorControllerSets the inversion state of the motor controller.- Specified by:
setInvertedin interfaceMotorController- Parameters:
isInverted- The inversion state.
-
getInverted
public boolean getInverted()Description copied from interface:MotorControllerGets the inversion state of the motor controller.- Specified by:
getInvertedin interfaceMotorController- Returns:
- The inversion state.
-
disable
public void disable()Description copied from interface:MotorControllerDisables the motor controller.- Specified by:
disablein interfaceMotorController
-
stopMotor
public void stopMotor()Description copied from class:MotorSafetyCalled to stop the motor when the timeout expires.- Specified by:
stopMotorin classMotorSafety
-
getDescription
Description copied from class:MotorSafetyReturns a description to print when an error occurs.- Specified by:
getDescriptionin classMotorSafety- Returns:
- Description to print when an error occurs.
-
getPwmHandle
public int getPwmHandle()Gets the backing PWM handle.- Returns:
- The pwm handle.
-
getChannel
public int getChannel()Gets the PWM channel number.- Returns:
- The channel number.
-
enableDeadbandElimination
public void enableDeadbandElimination(boolean eliminateDeadband) Optionally eliminate the deadband from a motor controller.- Parameters:
eliminateDeadband- If true, set the motor curve for the motor controller to eliminate the deadband in the middle of the range. Otherwise, keep the full range without modifying any values.
-
addFollower
Make the given PWM motor controller follow the output of this one.- Parameters:
follower- The motor controller follower.
-
logTo
Description copied from interface:TelemetryLoggableLogs the object to aTelemetryTable.- Specified by:
logToin interfaceTelemetryLoggable- Parameters:
table- telemetry table
-
getTelemetryType
Description copied from interface:TelemetryLoggableGets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.- Specified by:
getTelemetryTypein interfaceTelemetryLoggable- Returns:
- Table type
-