Package trclib.motor
Class TrcMotor
java.lang.Object
trclib.motor.TrcMotor
- All Implemented Interfaces:
TrcMotorController
,TrcExclusiveSubsystem
,TrcOdometrySensor
- Direct Known Subclasses:
FtcCRServo
,FtcDcMotor
public abstract class TrcMotor
extends Object
implements TrcMotorController, TrcExclusiveSubsystem, TrcOdometrySensor
This class implements a platform independent generic motor controller. Typically, this class is extended by a
platform dependent motor controller class. Not all motor controllers are created equal. Some have more features
than the others. This class attempts to simulate some of the features in software. If the platform dependent motor
controller supports those features in hardware it should override the corresponding methods and call the hardware
directly. For some features that there is no software emulation, this class will throw an
UnsupportedOperationException.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum
static class
protected class
This class encapsulates a follower motor with the associated scale factor.static interface
Some actuators are non-linear.private static class
This class encapsulates all the parameters required to perform an operation.Nested classes/interfaces inherited from interface trclib.robotcore.TrcExclusiveSubsystem
TrcExclusiveSubsystem.OwnershipParams
Nested classes/interfaces inherited from interface trclib.sensor.TrcOdometrySensor
TrcOdometrySensor.Odometry
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate TrcRobotBattery
private Double
private TrcTone
private double
private double
private double
private Double
private Double
private Double
private Double
private Double
private Double
private Double
private TrcPidController
private TrcMotor.PowerCompensation
private double
private double
private static final double
private static final double
private static final double
private TrcTriggerDigitalInput
private final TrcEncoder
private final ArrayList<TrcMotor.FollowerMotor>
protected final String
private boolean
private final TrcDigitalInput
private boolean
private static final String
protected static TrcElapsedTimer
protected static TrcElapsedTimer
protected static TrcElapsedTimer
protected static TrcElapsedTimer
protected static TrcElapsedTimer
private final TrcOdometrySensor.Odometry
private boolean
private static TrcTaskMgr.TaskObject
private TrcPerformanceTimer
private TrcPidController
private TrcMotor.PowerCompensation
private double
private TrcPresets
private TrcEvent
private double
private double
private double
private Double
private Double
private boolean
private final TrcMotor.TaskParams
private final TrcTimer
private boolean
final TrcDbgTrace
private TrcEvent.Callback
private AtomicBoolean
private TrcEvent
private final TrcDigitalInput
private boolean
private boolean
private TrcPidController
private TrcMotor.PowerCompensation
private double
private boolean
private double
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor: Create an instance of the object.TrcMotor
(String instanceName, TrcMotor.ExternalSensors sensors) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addFollower
(TrcMotor motor, double scale, boolean nativeFollower) This method adds the given motor to the list that will follow this motor.void
cancel()
This method cancels a previous operation by resetting the state set by the previous operation.private void
cancel
(boolean releaseOwnership) This method cancels a previous operation by resetting the state set by the previous operation.static void
clearOdometryMotorsList
(boolean removeOdometryTask) This method clears the list of motors that register for odometry monitoring.double
convertPositionToScaledUnits
(double pos) This method converts position sensor units to scaled units.double
convertPositionToSensorUnits
(double pos) This method converts position scaled units to sensor units.private void
delayPositionExpiredCallback
(Object context) This method is called when set motor position delay timer has expired.private void
delayValueExpiredCallback
(Object context) This method is called when set motor value delay timer has expired.void
This method disables the lower limit switch.void
This method disables motion profile support.void
This method disables the upper limit switch.private void
durationExpiredCallback
(Object context) This method is called when set motor power duration timer has expired.void
enableLowerLimitSwitch
(boolean normalClose) This method enables the lower limit switch and configures it to the specified type.void
enableMotionProfile
(double velocity, double acceleration, double jerk) This method enables motion profile support.void
enableUpperLimitSwitch
(boolean normalClose) This method enables the upper limit switch and configures it to the specified type.void
This method sets this motor to follow another motor.void
This method sets this motor to follow another motor.private double
getControllerPosition
(boolean zeroAdjust) This method gets the scaled position from an external position sensor if provided.double
This method returns the motor current.boolean
This method checks if current PID control has reached target.This method returns the PID coefficients of the motor's current PID controller.This method returns the software current PID controller if one was created by enabling software PID control.double
This method returns the normalized raw position of the external encoder if one is provided.getFollower
(int index) This method returns the follower with the specified index.getName()
This method returns the instance name.static int
This method returns the number of motors in the list registered for odometry monitoring.getOdometry
(int axisIndex) This method returns a copy of the odometry data of the specified axis.double
This method returns the PID control target.double
This method returns the motor position by reading the position sensor.boolean
This method checks if position PID control has reached target.This method returns the PID coefficients of the motor's position PID controller.This method returns the software position PID controller if one was created by enabling software PID control.double
getPower()
This method returns the motor power.private double
getPower
(boolean cached) This method returns the motor power.double
This method returns the motor velocity.boolean
This method checks if velocity PID control has reached target.This method returns the PID coefficients of the motor's velocity PID controller.This method returns the software velocity PID controller if one was created by enabling software PID control.boolean
This method checks if the PID motor is in the middle of zero calibration.boolean
This method returns the state of the lower limit switch.boolean
This method checks if the lower limit switch is enabled.private boolean
isMotorStalled
(double power) This method performs motor stall detection to protect the motor from burning out.boolean
This method checks if the odometry of this motor is enabled.boolean
This method returns the state of the position sensor direction.boolean
This method returns the state of the upper limit switch.boolean
This method checks if the upper limit switch is enabled.boolean
This method checks if voltage compensation is enabled.private void
odometryCleanupTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called before the runMode is about to stop so we can disable odometry.private static void
odometryTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to update motor odometry data.private void
pidCtrlTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method performs software PID control or monitors completion of motor controller PID control.private TrcPidController
pidCtrlToUse
(TrcMotor.ControlMode controlMode, boolean useSoftwarePid) This method checks which PID controller to use for close-loop control.private Double
pidToleranceToUse
(TrcMotor.ControlMode controlMode, boolean useSoftwarePid) This method checks which PID error tolerance to use for close-loop control.private TrcMotor.PowerCompensation
powerCompToUse
(TrcMotor.ControlMode controlMode, boolean useSoftwarePid) This method checks which PID Power Compensation callback to use for close-loop control.void
presetPositionDown
(String owner, double powerLimit) This method sets the motor to the next preset position down from the current position.void
presetPositionUp
(String owner, double powerLimit) This method sets the motor to the next preset position up from the current position.void
presetVelocityDown
(String owner) This method sets the motor to the next preset velocity down from the current velocity.void
presetVelocityUp
(String owner) This method sets the motor to the next preset velocity up from the current velocity.static void
printElapsedTime
(TrcDbgTrace tracer) This method prints the elapsed time info using the given tracer.void
This method prints the PID control task performance info.void
resetOdometry
(boolean resetHardware) This method resets the odometry data and sensor.void
This method resets the motor position sensor, typically an encoder.void
resetPosition
(boolean hardware) This method resets the motor position sensor if provided, typically an encoder.void
This method creates a digital trigger on the motor's lower limit switch.void
resetPositionOnLowerLimitSwitch
(TrcEvent.Callback triggerCallback) This method creates a digital trigger on the motor's lower limit switch.void
resetPositionOnLowerLimitSwitch
(TrcTrigger.TriggerMode triggerMode) This method creates a digital trigger on the motor's lower limit switch.void
resetPositionOnLowerLimitSwitch
(TrcTrigger.TriggerMode triggerMode, TrcEvent.Callback triggerCallback) This method creates a digital trigger on the motor's lower limit switch.private boolean
resetStall
(double power) This method checks if the motor was stalled and if power has been removed for at least resetTimeout, the stalled condition is then cleared.private void
resetTriggerCallback
(Object context) This method is called when the digital input device has changed state.void
This method sets the beep device so that it can play beeps at default frequencies and duration when motor stalled.void
This method sets the beep device and the beep tones so that it can play beeps when motor stalled.private void
setControllerMotorCurrent
(double current) This method sets the motor current and will do the same to the followers.private void
setControllerMotorPosition
(double position, double powerLimit, double feedforward) This method sets the motor position and will do the same to the followers.private void
setControllerMotorPower
(double power, boolean changeControlMode) This method sets the motor power and will do the same to the followers.private void
setControllerMotorVelocity
(double velocity, double feedforward) This method sets the motor velocity and will do the same to the followers.void
setCurrent
(double current) This method sets the motor current.void
setCurrent
(double delay, double current, double duration) This method sets the motor current.void
setCurrent
(double delay, double current, double duration, TrcEvent event) This method sets the motor current.void
setCurrent
(String owner, double delay, double current, double duration, TrcEvent event) This method sets the motor current.void
setCurrentPidParameters
(double kP, double kI, double kD, double kF, double tolerance) This method sets the PID parameters of the motor's current PID controller.void
setCurrentPidParameters
(double kP, double kI, double kD, double kF, double iZone, double tolerance) This method sets the PID parameters of the motor's current PID controller.void
setCurrentPidParameters
(TrcPidController.PidCoefficients pidCoeff, double tolerance) This method sets the PID parameters of the motor's current PID controller.void
setCurrentPidPowerComp
(TrcMotor.PowerCompensation powerComp) This method sets the power compensation callback of the motor's current PID controller.void
setCurrentPidTolerance
(double tolerance) This method sets the current tolerance for PID control.static void
setElapsedTimerEnabled
(boolean enabled) This method enables/disables the elapsed timers for performance monitoring.void
setLimitSwitchesSwapped
(boolean swapped) This method swaps the forward and reverse limit switches.void
setLowerLimitSwitchInverted
(boolean inverted) This method inverts the active state of the lower limit switch, typically reflecting whether the switch is wired normally open or normally close.private void
setMotorControlMode
(TrcMotor.ControlMode controlMode, boolean useSoftwarePid) This method sets the motor control mode and initializes ActionParams appropriately for the control mode.private void
setMotorValue
(String owner, TrcMotor.ControlMode controlMode, double delay, double value, double duration, TrcEvent completionEvent) This method sets the motor value.private void
setNextPresetPosition
(String owner, boolean presetUp, double powerLimit) This method sets the motor to the next preset position up or down from the current position.private void
setNextPresetVelocity
(String owner, boolean presetUp) This method sets the motor to the next preset velocity up or down from the current velocity.void
setOdometryEnabled
(boolean enabled, boolean resetOdometry, boolean resetHardware) This method enables/disables the task that monitors the motor odometry.void
setPerformanceMonitorEnabled
(boolean enabled) This method enables/disables performance monitoring of the PID control task.void
setPidPower
(double power, double minPos, double maxPos, boolean holdTarget) This method sets the motor power with PID control.void
setPidPower
(String owner, double power, double minPos, double maxPos, boolean holdTarget) This method sets the motor power with PID control.void
setPidStallDetectionEnabled
(boolean enabled) This method enables/disables PID stall detection.void
setPidStallDetectionEnabled
(double stallDetectionDelay, double stallDetectionTimeout, double stallErrorRateThreshold) This method enables/disables PID stall detection.void
setPosition
(double position) This method sets the motor position.void
setPosition
(double position, boolean holdTarget) This method sets the motor position.void
setPosition
(double position, boolean holdTarget, double powerLimit) This method sets the motor position.void
setPosition
(double delay, double position, boolean holdTarget, double powerLimit) This method sets the motor position.void
setPosition
(double delay, double position, boolean holdTarget, double powerLimit, TrcEvent completionEvent) This method sets the motor position.void
setPosition
(double delay, double position, boolean holdTarget, double powerLimit, TrcEvent completionEvent, double timeout) This method sets the motor position.void
setPosition
(String owner, double delay, double position, boolean holdTarget, double powerLimit, TrcEvent completionEvent, double timeout) This method sets the motor position.void
setPositionPidParameters
(double kP, double kI, double kD, double kF, double tolerance) This method sets the PID parameters of the motor's position PID controller.void
setPositionPidParameters
(double kP, double kI, double kD, double kF, double iZone, double tolerance) This method sets the PID parameters of the motor's position PID controller.void
setPositionPidParameters
(TrcPidController.PidCoefficients pidCoeff, double tolerance) This method sets the PID parameters of the motor's position PID controller.void
This method sets the power compensation callback of the motor's position PID controller.void
setPositionPidTolerance
(double tolerance) This method sets the position tolerance for PID control.void
setPositionSensorInverted
(boolean inverted) This method inverts the position sensor direction.void
setPositionSensorScaleAndOffset
(double scale, double offset) This method sets the position sensor scale and offset for translating sensor units to real world units.void
setPositionSensorScaleAndOffset
(double scale, double offset, double zeroOffset) This method sets the position sensor scale and offset for translating sensor units to real world units.void
setPower
(double power) This method sets the motor power.void
setPower
(double delay, double power, double duration) This method sets the motor power.void
This method sets the motor power.void
This method sets the motor power.void
setPresetPosition
(String owner, double delay, int presetIndex, boolean holdTarget, double powerLimit, TrcEvent event, double timeout) This method sets the motor to the specified preset position.void
setPresets
(boolean velocityPresets, double tolerance, double... presets) This method sets an array of presets for the motor.void
setPresetVelocity
(String owner, double delay, int presetIndex, double duration, TrcEvent event) This method sets the motor to the specified preset velocity.void
setSoftPositionLimits
(Double lowerLimit, Double upperLimit, boolean swapped) This method sets the lower and upper soft position limits.private void
setSoftwarePidCurrent
(double current) This method commands the motor to run at the given current using software PID control.void
setSoftwarePidEnabled
(boolean enabled) This method enables/disable software PID as the close-loop control.private void
setSoftwarePidPosition
(double position) This method commands the motor to run to the given position using software PID control.private void
setSoftwarePidVelocity
(double velocity) This method commands the motor to run at the given velocity using software PID control.void
setStallProtection
(double stallMinPower, double stallTolerance, double stallTimeout, double resetTimeout) This method sets stall protection.private void
setTaskParams
(TrcMotor.ControlMode controlMode, double motorValue, double duration, TrcEvent completionEvent, boolean holdTarget, Double powerLimit, double timeout) This method is called to set task parameters in an atomic operation.void
setTraceLevel
(TrcDbgTrace.MsgLevel msgLevel, boolean tracePidInfo, boolean verbosePidInfo, TrcRobotBattery battery) This method sets the message trace level for the tracer.void
setUpperLimitSwitchInverted
(boolean inverted) This method inverts the active state of the upper limit switch, typically reflecting whether the switch is wired normally open or normally close.void
setVelocity
(double velocity) This method sets the motor velocity.void
setVelocity
(double delay, double velocity, double duration) This method sets the motor velocity.void
setVelocity
(double delay, double velocity, double duration, TrcEvent event) This method sets the motor velocity.void
setVelocity
(String owner, double delay, double velocity, double duration, TrcEvent event) This method sets the motor velocity.void
setVelocityParameters
(double kP, double kI, double kD, double kF, double iZone, double tolerance) This method sets the PID parameters of the motor's velocity PID controller.void
setVelocityPidParameters
(double kP, double kI, double kD, double kF, double tolerance) This method sets the PID parameters of the motor's velocity PID controller.void
setVelocityPidParameters
(TrcPidController.PidCoefficients pidCoeff, double tolerance) This method sets the PID parameters of the motor's velocity PID controller.void
This method sets the power compensation callback of the motor's velocity PID controller.void
setVelocityPidTolerance
(double tolerance) This method sets the velocity tolerance for PID control.void
setVoltageCompensationEnabled
(Double batteryNominalVoltage) This method enables/disables voltage compensation so that it will maintain the motor output regardless of battery voltage.void
stop()
This method stops the motor regardless of the control mode and resets it to power control mode.private void
stop
(boolean releaseOwnership) This method stops the motor regardless of the control mode and resets it to power control mode.toString()
This method returns the instance name.private double
voltageCompensation
(double power) This method performs voltage compensation.void
zeroCalibrate
(double calPower) This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled.void
zeroCalibrate
(double calPower, TrcEvent completionEvent) This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled.void
zeroCalibrate
(double calPower, TrcEvent.Callback callback) This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled.void
zeroCalibrate
(String owner, double calPower) This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled.void
zeroCalibrate
(String owner, double calPower, TrcEvent completionEvent) This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled.void
zeroCalibrate
(String owner, double calPower, TrcEvent.Callback callback) This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled.private void
zeroCalibrate
(String owner, double calPower, TrcEvent completionEvent, TrcEvent.Callback callback) This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled.private boolean
zeroCalibratingMotor
(double calPower) This method is called by the calibration task to zero calibrate a motor.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface trclib.robotcore.TrcExclusiveSubsystem
acquireExclusiveAccess, acquireOwnership, cancelExclusiveAccess, getCurrentOwner, hasOwnership, releaseExclusiveAccess, releaseOwnership, validateOwnership
Methods inherited from interface trclib.motor.TrcMotorController
disableMotorFwdLimitSwitch, disableMotorRevLimitSwitch, enableMotorFwdLimitSwitch, enableMotorRevLimitSwitch, getBusVoltage, getMotorCurrent, getMotorCurrentPidCoefficients, getMotorPosition, getMotorPositionPidCoefficients, getMotorPower, getMotorVelocity, getMotorVelocityPidCoefficients, isMotorFwdLimitSwitchActive, isMotorFwdLimitSwitchEnabled, isMotorInverted, isMotorPositionSensorInverted, isMotorRevLimitSwitchActive, isMotorRevLimitSwitchEnabled, resetFactoryDefault, resetMotorPosition, setBrakeModeEnabled, setCloseLoopRampRate, setCurrentLimit, setMotorCurrent, setMotorCurrentPidCoefficients, setMotorFwdLimitSwitchInverted, setMotorFwdSoftPositionLimit, setMotorInverted, setMotorPosition, setMotorPositionPidCoefficients, setMotorPositionSensorInverted, setMotorPower, setMotorRevLimitSwitchInverted, setMotorRevSoftPositionLimit, setMotorVelocity, setMotorVelocityPidCoefficients, setOpenLoopRampRate, setStatorCurrentLimit
Methods inherited from interface trclib.sensor.TrcOdometrySensor
getOdometries, getOdometry
-
Field Details
-
moduleName
-
DEF_BEEP_LOW_FREQUENCY
private static final double DEF_BEEP_LOW_FREQUENCY- See Also:
-
DEF_BEEP_HIGH_FREQUENCY
private static final double DEF_BEEP_HIGH_FREQUENCY- See Also:
-
DEF_BEEP_DURATION
private static final double DEF_BEEP_DURATION- See Also:
-
odometryMotors
-
odometryTaskObj
-
motorGetPositionElapsedTimer
-
motorSetPowerElapsedTimer
-
motorSetVelocityElapsedTimer
-
motorSetPositionElapsedTimer
-
motorSetCurrentElapsedTimer
-
followingMotorsList
-
taskParams
-
tracer
-
instanceName
-
lowerLimitSwitch
-
upperLimitSwitch
-
encoder
-
odometry
-
timer
-
pidCtrlTaskPerformanceTimer
-
odometryEnabled
private boolean odometryEnabled -
releaseOwnershipEvent
-
softwarePidEnabled
private boolean softwarePidEnabled -
batteryNominalVoltage
-
limitSwitchesSwapped
private boolean limitSwitchesSwapped -
lowerLimitSwitchEnabled
private boolean lowerLimitSwitchEnabled -
upperLimitSwitchEnabled
private boolean upperLimitSwitchEnabled -
softLowerLimit
-
softUpperLimit
-
sensorScale
private double sensorScale -
sensorOffset
private double sensorOffset -
sensorZeroOffset
private double sensorZeroOffset -
zeroPosition
private double zeroPosition -
currMotorPower
private double currMotorPower -
controllerPower
-
controllerVelocity
-
controllerPosition
-
controllerPowerLimit
-
controllerFeedforward
-
controllerCurrent
-
velPidCtrl
-
velTolerance
private double velTolerance -
velPowerComp
-
posPidCtrl
-
posTolerance
private double posTolerance -
posPowerComp
-
currentPidCtrl
-
currentTolerance
private double currentTolerance -
currentPowerComp
-
closeLoopControlTarget
-
tracePidInfo
private boolean tracePidInfo -
verbosePidInfo
private boolean verbosePidInfo -
battery
-
beepDevice
-
beepLowFrequency
private double beepLowFrequency -
beepHighFrequency
private double beepHighFrequency -
beepDuration
private double beepDuration -
digitalTrigger
-
triggerCallback
-
triggerCallbackContext
-
triggerCallbackEvent
-
velocityPresets
private boolean velocityPresets -
presets
-
-
Constructor Details
-
TrcMotor
Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.sensors
- specifies external sensors, can be null if none.
-
TrcMotor
Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.
-
-
Method Details
-
toString
This method returns the instance name. -
setPerformanceMonitorEnabled
public void setPerformanceMonitorEnabled(boolean enabled) This method enables/disables performance monitoring of the PID control task.- Parameters:
enabled
- specifies true to enable, false to disable.
-
setTraceLevel
public void setTraceLevel(TrcDbgTrace.MsgLevel msgLevel, boolean tracePidInfo, boolean verbosePidInfo, TrcRobotBattery battery) This method sets the message trace level for the tracer.- Parameters:
msgLevel
- specifies the message level.tracePidInfo
- specifies true to enable tracing of PID info, false otherwise.verbosePidInfo
- specifies true to trace verbose PID info, false otherwise.battery
- specifies the battery object to get battery info for the message.
-
setBeep
public void setBeep(TrcTone beepDevice, double beepLowFrequency, double beepHighFrequency, double beepDuration) This method sets the beep device and the beep tones so that it can play beeps when motor stalled.- Parameters:
beepDevice
- specifies the beep device object.beepLowFrequency
- specifies the low frequency beep.beepHighFrequency
- specifies the high frequency beep.beepDuration
- specifies the beep duration.
-
setBeep
This method sets the beep device so that it can play beeps at default frequencies and duration when motor stalled.- Parameters:
beepDevice
- specifies the beep device object.
-
convertPositionToScaledUnits
public double convertPositionToScaledUnits(double pos) This method converts position sensor units to scaled units.- Parameters:
pos
- specifies position in sensor units.- Returns:
- position in scaled units.
-
convertPositionToSensorUnits
public double convertPositionToSensorUnits(double pos) This method converts position scaled units to sensor units.- Parameters:
pos
- specifies position in scaled units.- Returns:
- position in sensor units.
-
setVoltageCompensationEnabled
This method enables/disables voltage compensation so that it will maintain the motor output regardless of battery voltage.- Specified by:
setVoltageCompensationEnabled
in interfaceTrcMotorController
- Parameters:
batteryNominalVoltage
- specifies the nominal voltage of the battery to enable, null to disable.
-
isVoltageCompensationEnabled
public boolean isVoltageCompensationEnabled()This method checks if voltage compensation is enabled.- Specified by:
isVoltageCompensationEnabled
in interfaceTrcMotorController
- Returns:
- true if voltage compensation is enabled, false if disabled.
-
enableMotionProfile
public void enableMotionProfile(double velocity, double acceleration, double jerk) This method enables motion profile support.- Specified by:
enableMotionProfile
in interfaceTrcMotorController
- Parameters:
velocity
- specifies cruise velocity in the unit of rps.acceleration
- specifies acceleration in the unit of rot per sec square.jerk
- specifies acceleration derivation in the unit of rot per sec cube.
-
disableMotionProfile
public void disableMotionProfile()This method disables motion profile support.- Specified by:
disableMotionProfile
in interfaceTrcMotorController
-
addFollower
This method adds the given motor to the list that will follow this motor. It should only be called by the given motor to add it to the follower list of the motor it wants to follow.- Parameters:
motor
- specifies the motor that will follow this motor.scale
- specifies the value scale for the follower motor, 1.0 by default.nativeFollower
- specifies true if the motor supports following natively, false otherwise.
-
follow
This method sets this motor to follow another motor.- Specified by:
follow
in interfaceTrcMotorController
- Parameters:
motor
- specifies the motor to follow.inverted
- specifies true if this motor is inverted from the motor it is following, false otherwise.scale
- specifies the value scale for the follower motor, 1.0 by default.
-
follow
This method sets this motor to follow another motor.- Parameters:
motor
- specifies the motor to follow.inverted
- specifies true if this motor is inverted from the motor it is following, false otherwise.
-
getFollower
This method returns the follower with the specified index.- Specified by:
getFollower
in interfaceTrcMotorController
- Parameters:
index
- specifies the follower index.- Returns:
- follower.
-
setStallProtection
public void setStallProtection(double stallMinPower, double stallTolerance, double stallTimeout, double resetTimeout) This method sets stall protection. When stall protection is turned ON, it will monitor the motor movement for stalled condition. A motor is considered stalled if: - the power applied to the motor is above or equal to stallMinPower. - the motor has not moved or movement stayed within stallTolerance for at least stallTimeout. Note: By definition, holding target position doing software PID control is stalling. If you decide to enable stall protection while holding target, please make sure to set a stallMinPower much greater than the power necessary to hold position against gravity, for example. However, if you want to zero calibrate on motor stall (e.g. don't have lower limit switch), you want to make sure calPower is at least stallMinPower.- Parameters:
stallMinPower
- specifies the minimum motor power to detect stalled condition. If the motor power is below stallMinPower, it won't consider it as a stalled condition even if the motor does not move.stallTolerance
- specifies the movement tolerance within which is still considered stalled.stallTimeout
- specifies the time in seconds that the motor must stopped before it is declared stalled.resetTimeout
- specifies the time in seconds the motor must be set to zero power after it is declared stalled will the stalled condition be reset. If this is set to zero, the stalled condition won't be cleared.
-
setPidStallDetectionEnabled
public void setPidStallDetectionEnabled(double stallDetectionDelay, double stallDetectionTimeout, double stallErrorRateThreshold) This method enables/disables PID stall detection.- Parameters:
stallDetectionDelay
- specifies stall detection start delay in seconds, zero to disable stall detection.stallDetectionTimeout
- specifies stall timeout in seconds which is the minimum elapsed time for the motor to be motionless to be considered stalled.stallErrorRateThreshold
- specifies the error rate threshold below which it will consider stalling.
-
setPidStallDetectionEnabled
public void setPidStallDetectionEnabled(boolean enabled) This method enables/disables PID stall detection.- Parameters:
enabled
- specifies true to enable stall detection, false to disable.
-
setLimitSwitchesSwapped
public void setLimitSwitchesSwapped(boolean swapped) This method swaps the forward and reverse limit switches. By default, the lower limit switch is associated with the reverse limit switch and the upper limit switch is associated with the forward limit switch. This method will swap the association. Note: if you need to configure the lower and upper limit switches, you must configure them after this call.- Parameters:
swapped
- specifies true to swap the limit switches, false otherwise.
-
enableLowerLimitSwitch
public void enableLowerLimitSwitch(boolean normalClose) This method enables the lower limit switch and configures it to the specified type.- Parameters:
normalClose
- specifies true as the normal close switch type, false as normal open.
-
enableUpperLimitSwitch
public void enableUpperLimitSwitch(boolean normalClose) This method enables the upper limit switch and configures it to the specified type.- Parameters:
normalClose
- specifies true as the normal close switch type, false as normal open.
-
disableLowerLimitSwitch
public void disableLowerLimitSwitch()This method disables the lower limit switch. -
disableUpperLimitSwitch
public void disableUpperLimitSwitch()This method disables the upper limit switch. -
setLowerLimitSwitchInverted
public void setLowerLimitSwitchInverted(boolean inverted) This method inverts the active state of the lower limit switch, typically reflecting whether the switch is wired normally open or normally close.- Parameters:
inverted
- specifies true to invert the limit switch to normal close, false to normal open.
-
setUpperLimitSwitchInverted
public void setUpperLimitSwitchInverted(boolean inverted) This method inverts the active state of the upper limit switch, typically reflecting whether the switch is wired normally open or normally close.- Parameters:
inverted
- specifies true to invert the limit switch to normal close, false to normal open.
-
isLowerLimitSwitchEnabled
public boolean isLowerLimitSwitchEnabled()This method checks if the lower limit switch is enabled.- Returns:
- true if enabled, false if disabled.
-
isUpperLimitSwitchEnabled
public boolean isUpperLimitSwitchEnabled()This method checks if the upper limit switch is enabled.- Returns:
- true if enabled, false if disabled.
-
isLowerLimitSwitchActive
public boolean isLowerLimitSwitchActive()This method returns the state of the lower limit switch.- Returns:
- true if lower limit switch is active, false otherwise.
-
isUpperLimitSwitchActive
public boolean isUpperLimitSwitchActive()This method returns the state of the upper limit switch.- Returns:
- true if upper limit switch is active, false otherwise.
-
setSoftPositionLimits
This method sets the lower and upper soft position limits.- Parameters:
lowerLimit
- specifies the position of the lower limit in scaled units, null to disable lower limit.upperLimit
- specifies the position of the upper limit in scaled units, null to disable upper limit.swapped
- specifies true to swap the direction (lowerLimit is forward and upperLimit is reverse), false otherwise. This is only applicable for motor controller soft limits.
-
setPositionSensorInverted
public void setPositionSensorInverted(boolean inverted) This method inverts the position sensor direction. This may be rare but there are scenarios where the motor encoder may be mounted somewhere in the power train that it rotates opposite to the motor rotation. This will cause the encoder reading to go down when the motor is receiving positive power. This method can correct this situation.- Parameters:
inverted
- specifies true to invert position sensor direction, false otherwise.
-
isPositionSensorInverted
public boolean isPositionSensorInverted()This method returns the state of the position sensor direction.- Returns:
- true if the motor direction is inverted, false otherwise.
-
setPositionSensorScaleAndOffset
public void setPositionSensorScaleAndOffset(double scale, double offset, double zeroOffset) This method sets the position sensor scale and offset for translating sensor units to real world units.- Parameters:
scale
- specifies scale factor to multiply the position sensor reading.offset
- specifies offset added to the scaled sensor reading.zeroOffset
- specifies the zero offset for absolute encoder.
-
setPositionSensorScaleAndOffset
public void setPositionSensorScaleAndOffset(double scale, double offset) This method sets the position sensor scale and offset for translating sensor units to real world units.- Parameters:
scale
- specifies scale factor to multiply the position sensor reading.offset
- specifies offset added to the scaled sensor reading.
-
getEncoderRawPosition
public double getEncoderRawPosition()This method returns the normalized raw position of the external encoder if one is provided.- Returns:
- external encoder normalized raw position.
-
getControllerPosition
private double getControllerPosition(boolean zeroAdjust) This method gets the scaled position from an external position sensor if provided. Otherwise, it gets it from motor controller if it supports one.- Parameters:
zeroAdjust
- specifies true to zero adjust the position, false otherwise.
-
resetPosition
public void resetPosition(boolean hardware) This method resets the motor position sensor if provided, typically an encoder. Otherwise, it resets the one on the motor controller if it supports one. If hardware is false, it simulates the reset by reading the current position as the zero position.- Parameters:
hardware
- specifies true for resetting hardware position, false for resetting software position.
-
resetPosition
public void resetPosition()This method resets the motor position sensor, typically an encoder. This method emulates a reset for a potentiometer by doing a soft reset. -
setSoftwarePidEnabled
public void setSoftwarePidEnabled(boolean enabled) This method enables/disable software PID as the close-loop control.- Parameters:
enabled
- specifies true to enable software PID control, false to disable.
-
getPidTarget
public double getPidTarget()This method returns the PID control target. It could be a position, velocity or current depending on the current active PID controller.- Returns:
- PID control target, zero if no active PID controller.
-
pidCtrlToUse
This method checks which PID controller to use for close-loop control.- Parameters:
controlMode
- specifies the control mode.useSoftwarePid
- specifies true to use software PID control, false otherwise.- Returns:
- the PID controller to used for close-loop control.
-
pidToleranceToUse
This method checks which PID error tolerance to use for close-loop control.- Parameters:
controlMode
- specifies the control mode.useSoftwarePid
- specifies true to use software PID control, false otherwise.- Returns:
- the PID error tolerance to used for close-loop control.
-
powerCompToUse
private TrcMotor.PowerCompensation powerCompToUse(TrcMotor.ControlMode controlMode, boolean useSoftwarePid) This method checks which PID Power Compensation callback to use for close-loop control.- Parameters:
controlMode
- specifies the control mode.useSoftwarePid
- specifies true to use software PID control, false otherwise.- Returns:
- the Power Compensation callback to used for close-loop control.
-
setMotorControlMode
This method sets the motor control mode and initializes ActionParams appropriately for the control mode.- Parameters:
controlMode
- specifies the motor control mode.useSoftwarePid
- specifies true to use software PID control, false to use motor built-in PID.
-
setControllerMotorPower
private void setControllerMotorPower(double power, boolean changeControlMode) This method sets the motor power and will do the same to the followers. This method should be used instead of setMotorPower because this will set the correct control mode and will do the optimization of not sending same value to the motor repeatedly and also will take care of the followers.- Parameters:
power
- specifies the percentage power (range -1.0 to 1.0) to be set.changeControlMode
- specifies true to change control mode, false otherwise.
-
setControllerMotorVelocity
private void setControllerMotorVelocity(double velocity, double feedforward) This method sets the motor velocity and will do the same to the followers. This method should be used instead of setMotorVelocity because this will set the correct control mode and do the optimization of not sending same value to the motor repeatedly and also will take care of the followers.- Parameters:
velocity
- specifies the velocity in scaled units/sec.feedforward
- specifies the feedforward value
-
setControllerMotorPosition
private void setControllerMotorPosition(double position, double powerLimit, double feedforward) This method sets the motor position and will do the same to the followers. This method should be used instead of setMotorPosition because this will set the correct control mode and will take care of the followers.- Parameters:
position
- specifies the position in scaled units.powerLimit
- specifies the maximum power output limits.feedforward
- specifies the feedforward value
-
setControllerMotorCurrent
private void setControllerMotorCurrent(double current) This method sets the motor current and will do the same to the followers. This method should be used instead of setMotorCurrent because this will set the correct control mode and do the optimization of not sending same value to the motor repeatedly and also will take care of the followers.- Parameters:
current
- specifies the current in amperes.
-
setSoftwarePidVelocity
private void setSoftwarePidVelocity(double velocity) This method commands the motor to run at the given velocity using software PID control.- Parameters:
velocity
- specifies the velocity in scaled units/sec.
-
setSoftwarePidPosition
private void setSoftwarePidPosition(double position) This method commands the motor to run to the given position using software PID control.- Parameters:
position
- specifies the position in scaled units.
-
setSoftwarePidCurrent
private void setSoftwarePidCurrent(double current) This method commands the motor to run at the given current using software PID control.- Parameters:
current
- specifies the current in amperes.
-
cancel
private void cancel(boolean releaseOwnership) This method cancels a previous operation by resetting the state set by the previous operation. Note: cancel does not stop the motor and therefore it will still hold its position. If you want to stop the motor, call the stop method instead. If releaseOwnership is false, it is called internally to cancel a previous operation either has no owner or by the same owner in which case we do not want to release the ownership.- Parameters:
releaseOwnership
- specifies true to release ownership, false otherwise.
-
cancel
public void cancel()This method cancels a previous operation by resetting the state set by the previous operation. Note: cancel does not stop the motor and therefore it will still hold its position. If you want to stop the motor, call the stop method instead. This could be called by an external caller who may not have ownership. -
stop
private void stop(boolean releaseOwnership) This method stops the motor regardless of the control mode and resets it to power control mode. If releaseOwnership is false, it is called internally to stop a previous operation either has no owner or by the same owner in which case we do not want to release the ownership.- Parameters:
releaseOwnership
- specifies true to release ownership, false otherwise.
-
stop
public void stop()This method stops the motor regardless of the control mode and resets it to power control mode. -
delayValueExpiredCallback
This method is called when set motor value delay timer has expired. It will set the specified motor value.- Parameters:
context
- specifies the timer object (not used).
-
durationExpiredCallback
This method is called when set motor power duration timer has expired. It will turn the motor off.- Parameters:
context
- specifies the timer object (not used).
-
voltageCompensation
private double voltageCompensation(double power) This method performs voltage compensation. If motor controller supports this natively, batteryNominalVoltage will be zero and therefore a no-op.- Parameters:
power
- specifies the power to be compensated.- Returns:
- compensated value.
-
setTaskParams
private void setTaskParams(TrcMotor.ControlMode controlMode, double motorValue, double duration, TrcEvent completionEvent, boolean holdTarget, Double powerLimit, double timeout) This method is called to set task parameters in an atomic operation.- Parameters:
controlMode
- specifies motor control mode.motorValue
- specifies motor value (can be power, velocity, position or current depending on controlMode);duration
- specifies duration to run the motor in seconds.completionEvent
- specifies the event to signal when completed.holdTarget
- specifies true to hold target (applicable for Position mode only).powerLimit
- specifies the max power applied to the motor (applicable for Position mode only).timeout
- specifies timeout in seconds for the operation (applicable for Position mode only).
-
setMotorValue
private void setMotorValue(String owner, TrcMotor.ControlMode controlMode, double delay, double value, double duration, TrcEvent completionEvent) This method sets the motor value. The value can be power, velocity or current. If the motor is not in the correct control mode, it will stop the motor and set it to the appropriate mode for the value. Optionally, you can specify a delay before running the motor and a duration for which the motor will be turned off afterwards.- Parameters:
owner
- specifies the ID string of the caller for taking ownership, can be null if caller does not require ownership.controlMode
- specifies the motor control mode (Power, Velocity, Current).delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.value
- specifies the percentage power (range -1.0 to 1.0) or velocity (scaled units/sec).duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.completionEvent
- specifies the event to signal when the motor operation is completed.
-
setPower
This method sets the motor power. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode. Optionally, you can specify a delay before running the motor and a duration for which the motor will be turned off afterwards.- Parameters:
owner
- specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.power
- specifies the percentage power (range -1.0 to 1.0).duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.event
- specifies the event to signal when the motor operation is completed
-
setPower
This method sets the motor power. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode. Optionally, you can specify a delay before running the motor and a duration for which the motor will be turned off afterwards.- Parameters:
delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.power
- specifies the percentage power (range -1.0 to 1.0).duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.event
- specifies the event to signal when the motor operation is completed
-
setPower
public void setPower(double delay, double power, double duration) This method sets the motor power. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode. Optionally, you can specify a delay before running the motor and a duration for which the motor will be turned off afterwards.- Parameters:
delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.power
- specifies the percentage power (range -1.0 to 1.0).duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.
-
setPower
public void setPower(double power) This method sets the motor power. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode.- Parameters:
power
- specifies the percentage power (range -1.0 to 1.0).
-
getPower
private double getPower(boolean cached) This method returns the motor power.- Returns:
- current motor percentage power (range -1.0 to 1.0).
-
getPower
public double getPower()This method returns the motor power.- Returns:
- current motor percentage power (range -1.0 to 1.0).
-
setVelocity
public void setVelocity(String owner, double delay, double velocity, double duration, TrcEvent event) This method sets the motor velocity. If the motor is not in the correct control mode, it will stop the motor and set it to velocity control mode. Optionally, you can specify a delay before running the motor and a duration for which the motor will be turned off afterwards.- Parameters:
owner
- specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.velocity
- specifies velocity in scaled units/sec.duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.event
- specifies the event to signal when the motor operation is completed
-
setVelocity
This method sets the motor velocity. If the motor is not in the correct control mode, it will stop the motor and set it to velocity control mode. Optionally, you can specify a delay before running the motor and a duration for which the motor will be turned off afterwards.- Parameters:
delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.velocity
- specifies velocity in scaled units/sec.duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.event
- specifies the event to signal when the motor operation is completed
-
setVelocity
public void setVelocity(double delay, double velocity, double duration) This method sets the motor velocity. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode. Optionally, you can specify a delay before running the motor and a duration for which the motor will be turned off afterwards.- Parameters:
delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.velocity
- specifies velocity in scaled units/sec.duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.
-
setVelocity
public void setVelocity(double velocity) This method sets the motor velocity. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode.- Parameters:
velocity
- specifies velocity in scaled units/sec.
-
getVelocity
public double getVelocity()This method returns the motor velocity. Velocity could either be obtained by calling the motor hardware if it supports it or using the odometry task to monitor the position sensor value. However, accessing hardware may impact performance because it may involve initiating USB/CAN/I2C bus cycles. Therefore, it may be beneficial to enable the odometry task to calculate the velocity value.- Returns:
- motor velocity in scaled units/sec.
-
delayPositionExpiredCallback
This method is called when set motor position delay timer has expired. It will set the specified motor position.- Parameters:
context
- specifies the timer object (not used).
-
setPosition
public void setPosition(String owner, double delay, double position, boolean holdTarget, double powerLimit, TrcEvent completionEvent, double timeout) This method sets the motor position. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode.- Parameters:
owner
- specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.position
- specifies the position in scaled units to be set.holdTarget
- specifies true to hold position target, false otherwise.powerLimit
- specifies the maximum power output limits.completionEvent
- specifies the event to signal when the motor operation is completed.timeout
- specifies timeout in seconds.
-
setPosition
public void setPosition(double delay, double position, boolean holdTarget, double powerLimit, TrcEvent completionEvent, double timeout) This method sets the motor position. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode.- Parameters:
delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.position
- specifies the position in scaled units to be set.holdTarget
- specifies true to hold position target, false otherwise.powerLimit
- specifies the maximum power output limits.completionEvent
- specifies the event to signal when the motor operation is completed.timeout
- specifies timeout in seconds.
-
setPosition
public void setPosition(double delay, double position, boolean holdTarget, double powerLimit, TrcEvent completionEvent) This method sets the motor position. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode.- Parameters:
delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.position
- specifies the position in scaled units to be set.holdTarget
- specifies true to hold position target, false otherwise.powerLimit
- specifies the maximum power output limits.completionEvent
- specifies the event to signal when the motor operation is completed.
-
setPosition
public void setPosition(double delay, double position, boolean holdTarget, double powerLimit) This method sets the motor position. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode.- Parameters:
delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.position
- specifies the position in scaled units to be set.holdTarget
- specifies true to hold position target, false otherwise.powerLimit
- specifies the maximum power output limits.
-
setPosition
public void setPosition(double position, boolean holdTarget, double powerLimit) This method sets the motor position. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode.- Parameters:
position
- specifies the position in scaled units to be set.holdTarget
- specifies true to hold position target, false otherwise.powerLimit
- specifies the maximum power output limits.
-
setPosition
public void setPosition(double position, boolean holdTarget) This method sets the motor position. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode.- Parameters:
position
- specifies the position in scaled units to be set.holdTarget
- specifies true to hold position target, false otherwise.
-
setPosition
public void setPosition(double position) This method sets the motor position. If the motor is not in the correct control mode, it will stop the motor and set it to power control mode.- Parameters:
position
- specifies the position in scaled units to be set.
-
getPosition
public double getPosition()This method returns the motor position by reading the position sensor. As a performance optimization, it gets the position from cached odometry if odometry is enabled.- Returns:
- current motor position in scaled units.
-
setPidPower
public void setPidPower(String owner, double power, double minPos, double maxPos, boolean holdTarget) This method sets the motor power with PID control. This is basically the same as setPosition but with dynamically changing powerLimit. The motor will be under position PID control and the power specifies the maximum limit of how fast the motor can go. The actual motor power is controlled by a PID controller with the target either set to minPos or maxPos depending on the direction of the motor. This is very useful in scenarios such as an elevator where you want to have the elevator controlled by a joystick but would like PID control to pay attention to the upper and lower limits and slow down when approaching those limits. The joystick value will specify the maximum limit of the elevator power. So if the joystick is only pushed half way, the elevator will only go half power even though it is far away from the target.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the motor.power
- specifies the upper bound power of the motor.minPos
- specifies the minimum of the position range.maxPos
- specifies the maximum of the position range.holdTarget
- specifies true to hold target when speed is set to 0, false otherwise.
-
setPidPower
public void setPidPower(double power, double minPos, double maxPos, boolean holdTarget) This method sets the motor power with PID control. The motor will be under PID control and the power specifies the upper bound of how fast the motor will spin. The actual motor power is controlled by a PID controller with the target either set to minPos or maxPos depending on the direction of the motor. This is very useful in scenarios such as an elevator where you want to have the elevator controlled by a joystick but would like PID control to pay attention to the upper and lower limits and slow down when approaching those limits. The joystick value will specify the upper bound of the elevator power. So if the joystick is only pushed half way, the elevator will only go half power even though it is far away from the target.- Parameters:
power
- specifies the upper bound power of the motor.minPos
- specifies the minimum of the position range.maxPos
- specifies the maximum of the position range.holdTarget
- specifies true to hold target when speed is set to 0, false otherwise.
-
setCurrent
This method sets the motor current. If the motor is not in the correct control mode, it will stop the motor and set it to current control mode. Optionally, you can specify a delay before running the motor and a duration for which the motor will be turned off afterwards.- Parameters:
owner
- specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.current
- specifies the current in amperes.duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.event
- specifies the event to signal when the motor operation is completed
-
setCurrent
This method sets the motor current. If the motor is not in the correct control mode, it will stop the motor and set it to current control mode. Optionally, you can specify a delay before running the motor and a duration for which the motor will be turned off afterwards.- Parameters:
delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.current
- specifies the current in amperes.duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.event
- specifies the event to signal when the motor operation is completed
-
setCurrent
public void setCurrent(double delay, double current, double duration) This method sets the motor current. If the motor is not in the correct control mode, it will stop the motor and set it to current control mode. Optionally, you can specify a delay before running the motor and a duration for which the motor will be turned off afterwards.- Parameters:
delay
- specifies the time in seconds to delay before setting the value, 0.0 if no delay.current
- specifies the current in amperes.duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.
-
setCurrent
public void setCurrent(double current) This method sets the motor current. If the motor is not in the correct control mode, it will stop the motor and set it to current control mode.- Parameters:
current
- specifies the current in amperes.
-
getCurrent
public double getCurrent()This method returns the motor current.- Returns:
- current motor current in amperes.
-
setVelocityPidParameters
This method sets the PID parameters of the motor's velocity PID controller. Note that PID coefficients are different for software PID and controller built-in PID. If you enable/disable software PID, you need to set the appropriate PID coefficients accordingly.- Parameters:
pidCoeff
- specifies the PID coefficients to set.tolerance
- specifies the PID tolerance.
-
setVelocityParameters
public void setVelocityParameters(double kP, double kI, double kD, double kF, double iZone, double tolerance) This method sets the PID parameters of the motor's velocity PID controller. Note that PID coefficients are different for software PID and controller built-in PID. If you enable/disable software PID, you need to set the appropriate PID coefficients accordingly.- Parameters:
kP
- specifies the Kp coefficient.kI
- specifies the Ki coefficient.kD
- specifies the Kd coefficient.kF
- specifies the Kf coefficient.iZone
- specifies IZone, can be 0.0 if not provided.tolerance
- specifies the PID tolerance.
-
setVelocityPidParameters
public void setVelocityPidParameters(double kP, double kI, double kD, double kF, double tolerance) This method sets the PID parameters of the motor's velocity PID controller. Note that PID coefficients are different for software PID and controller built-in PID. If you enable/disable software PID, you need to set the appropriate PID coefficients accordingly.- Parameters:
kP
- specifies the Kp coefficient.kI
- specifies the Ki coefficient.kD
- specifies the Kd coefficient.kF
- specifies the Kf coefficient.tolerance
- specifies the PID tolerance.
-
setVelocityPidTolerance
public void setVelocityPidTolerance(double tolerance) This method sets the velocity tolerance for PID control.- Parameters:
tolerance
- specifies the tolerance in scaled units per second.
-
getVelocityPidCoefficients
This method returns the PID coefficients of the motor's velocity PID controller.- Returns:
- PID coefficients of the motor's velocity PID controller.
-
getVelocityOnTarget
public boolean getVelocityOnTarget()This method checks if velocity PID control has reached target.- Returns:
- true if velocity has reached target, false otherwise.
-
setVelocityPidPowerComp
This method sets the power compensation callback of the motor's velocity PID controller.- Parameters:
powerComp
- specifies the power compensation callback.
-
getVelocityPidController
This method returns the software velocity PID controller if one was created by enabling software PID control. It does not mean software PID control is current enable. It just means software PID control was enabled at one point. This allows you to configure the software PID controller. For example, whether the target is absolute or relative, specifying noOscillation etc.- Returns:
- software velocity PID controller.
-
setPositionPidParameters
This method sets the PID parameters of the motor's position PID controller. Note that PID coefficients are different for software PID and controller built-in PID. If you enable/disable software PID, you need to set the appropriate PID coefficients accordingly.- Parameters:
pidCoeff
- specifies the PID coefficients to set.tolerance
- specifies the PID tolerance.
-
setPositionPidParameters
public void setPositionPidParameters(double kP, double kI, double kD, double kF, double iZone, double tolerance) This method sets the PID parameters of the motor's position PID controller. Note that PID coefficients are different for software PID and controller built-in PID. If you enable/disable software PID, you need to set the appropriate PID coefficients accordingly.- Parameters:
kP
- specifies the Kp coefficient.kI
- specifies the Ki coefficient.kD
- specifies the Kd coefficient.kF
- specifies the Kf coefficient.iZone
- specifies IZone, can be 0.0 if not provided.tolerance
- specifies the PID tolerance.
-
setPositionPidParameters
public void setPositionPidParameters(double kP, double kI, double kD, double kF, double tolerance) This method sets the PID parameters of the motor's position PID controller. Note that PID coefficients are different for software PID and controller built-in PID. If you enable/disable software PID, you need to set the appropriate PID coefficients accordingly.- Parameters:
kP
- specifies the Kp coefficient.kI
- specifies the Ki coefficient.kD
- specifies the Kd coefficient.kF
- specifies the Kf coefficient.tolerance
- specifies the PID tolerance.
-
setPositionPidTolerance
public void setPositionPidTolerance(double tolerance) This method sets the position tolerance for PID control.- Parameters:
tolerance
- specifies the tolerance in scaled units.
-
getPositionPidCoefficients
This method returns the PID coefficients of the motor's position PID controller.- Returns:
- PID coefficients of the motor's position PID controller.
-
getPositionOnTarget
public boolean getPositionOnTarget()This method checks if position PID control has reached target.- Returns:
- true if position has reached target, false otherwise.
-
setPositionPidPowerComp
This method sets the power compensation callback of the motor's position PID controller.- Parameters:
powerComp
- specifies the power compensation callback.
-
getPositionPidController
This method returns the software position PID controller if one was created by enabling software PID control. It does not mean software PID control is current enable. It just means software PID control was enabled at one point. This allows you to configure the software PID controller. For example, whether the target is absolute or relative, specifying noOscillation etc.- Returns:
- software position PID controller.
-
setCurrentPidParameters
This method sets the PID parameters of the motor's current PID controller. Note that PID coefficients are different for software PID and controller built-in PID. If you enable/disable software PID, you need to set the appropriate PID coefficients accordingly.- Parameters:
pidCoeff
- specifies the PID coefficients to set.tolerance
- specifies the PID tolerance.
-
setCurrentPidParameters
public void setCurrentPidParameters(double kP, double kI, double kD, double kF, double iZone, double tolerance) This method sets the PID parameters of the motor's current PID controller. Note that PID coefficients are different for software PID and controller built-in PID. If you enable/disable software PID, you need to set the appropriate PID coefficients accordingly.- Parameters:
kP
- specifies the Kp coefficient.kI
- specifies the Ki coefficient.kD
- specifies the Kd coefficient.kF
- specifies the Kf coefficient.iZone
- specifies IZone, can be 0.0 if not provided.tolerance
- specifies the PID tolerance.
-
setCurrentPidParameters
public void setCurrentPidParameters(double kP, double kI, double kD, double kF, double tolerance) This method sets the PID parameters of the motor's current PID controller. Note that PID coefficients are different for software PID and controller built-in PID. If you enable/disable software PID, you need to set the appropriate PID coefficients accordingly.- Parameters:
kP
- specifies the Kp coefficient.kI
- specifies the Ki coefficient.kD
- specifies the Kd coefficient.kF
- specifies the Kf coefficient.tolerance
- specifies the PID tolerance.
-
setCurrentPidTolerance
public void setCurrentPidTolerance(double tolerance) This method sets the current tolerance for PID control.- Parameters:
tolerance
- specifies the tolerance in amperes.
-
getCurrentPidCoefficients
This method returns the PID coefficients of the motor's current PID controller.- Returns:
- PID coefficients of the motor's current PID controller.
-
getCurrentOnTarget
public boolean getCurrentOnTarget()This method checks if current PID control has reached target.- Returns:
- true if current has reached target, false otherwise.
-
setCurrentPidPowerComp
This method sets the power compensation callback of the motor's current PID controller.- Parameters:
powerComp
- specifies the power compensation callback.
-
getCurrentPidController
This method returns the software current PID controller if one was created by enabling software PID control. It does not mean software PID control is current enable. It just means software PID control was enabled at one point. This allows you to configure the software PID controller. For example, whether the target is absolute or relative, specifying noOscillation etc.- Returns:
- software current PID controller.
-
isMotorStalled
private boolean isMotorStalled(double power) This method performs motor stall detection to protect the motor from burning out. A motor is considered stalled when at least stallMinPower is applied to the motor and the motor is not turning for at least stallTimeout. This assumes the caller has acquired the taskParams lock.- Parameters:
power
- specifies the current motor power.- Returns:
- true if the motor is stalled, false otherwise.
-
resetStall
private boolean resetStall(double power) This method checks if the motor was stalled and if power has been removed for at least resetTimeout, the stalled condition is then cleared. This assumes the caller has acquired the taskParams lock.- Parameters:
power
- specifies the power applying to the motor.- Returns:
- true if the motor was stalled, false otherwise.
-
zeroCalibratingMotor
private boolean zeroCalibratingMotor(double calPower) This method is called by the calibration task to zero calibrate a motor. This assumes the caller has acquired the taskParams lock. This method will update currPower and stalled in taskParams.- Parameters:
calPower
- specifies the zero calibration power applied to the motor.- Returns:
- true if calibration is done, false otherwise.
-
pidCtrlTask
private void pidCtrlTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method performs software PID control or monitors completion of motor controller PID control. It is called periodically to check if PID control is on target. If it is not on target and we are doing software control, it will calculate the power applying to the motor to get it there. If we reached target in doing software control and we are holding target, it will maintain target until software control is turned off. If performing motor controller PID control, this task only monitors progress and sync followers. If it has reached target, it will signal completion event.- Parameters:
taskType
- specifies the type of task being run.runMode
- specifies the competition mode that is running.slowPeriodicLoop
- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-
resetPositionOnLowerLimitSwitch
public void resetPositionOnLowerLimitSwitch(TrcTrigger.TriggerMode triggerMode, TrcEvent.Callback triggerCallback) This method creates a digital trigger on the motor's lower limit switch. It resets the position sensor reading when the digital input is triggered. This is intended to be called as part of motor initialization. Therefore, it is not designed to be ownership-aware.- Parameters:
triggerMode
- specifies the trigger mode.triggerCallback
- specifies an event callback if the trigger occurred, null if none specified.
-
resetPositionOnLowerLimitSwitch
This method creates a digital trigger on the motor's lower limit switch. It resets the position sensor reading when the digital input is triggered. This is intended to be called as part of motor initialization. Therefore, it is not designed to be ownership-aware.- Parameters:
triggerMode
- specifies the trigger mode.
-
resetPositionOnLowerLimitSwitch
This method creates a digital trigger on the motor's lower limit switch. It resets the position sensor reading when the digital input is triggered. This is intended to be called as part of motor initialization. Therefore, it is not designed to be ownership-aware.- Parameters:
triggerCallback
- specifies an event callback if the trigger occurred, null if none specified.
-
resetPositionOnLowerLimitSwitch
public void resetPositionOnLowerLimitSwitch()This method creates a digital trigger on the motor's lower limit switch. It resets the position sensor reading when the digital input is triggered. This is intended to be called as part of motor initialization. Therefore, it is not designed to be ownership-aware. -
resetTriggerCallback
This method is called when the digital input device has changed state.- Parameters:
context
- specifies true if the digital device state is active, false otherwise.
-
isCalibrating
public boolean isCalibrating()This method checks if the PID motor is in the middle of zero calibration.- Returns:
- true if zero calibrating, false otherwise.
-
zeroCalibrate
private void zeroCalibrate(String owner, double calPower, TrcEvent completionEvent, TrcEvent.Callback callback) This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled. Generally, calibration power should be negative so that the motor will move towards the lower limit switch. However, in some scenarios such as a turret that can turn all the way around and has only one limit switch, it may be necessary to use a positive calibration power to move it towards the limit switch instead of using negative calibration power and turning the long way around that may cause wires to entangle. If this method specifies an owner and the subsystem was not owned by it, it will acquire exclusive ownership on its behalf and release ownership after the operation is completed.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the motor.calPower
- specifies the motor power for the zero calibration, can be positive or negative depending on the desire direction of movement.completionEvent
- specifies an event to signal when zero calibration is done, can be null if not provided.callback
- specifies a callback handler when zero calibration is done.
-
zeroCalibrate
This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled. Generally, calibration power should be negative so that the motor will move towards the lower limit switch. However, in some scenarios such as a turret that can turn all the way around and has only one limit switch, it may be necessary to use a positive calibration power to move it towards the limit switch instead of using negative calibration power and turning the long way around that may cause wires to entangle. If this method specifies an owner and the subsystem was not owned by it, it will acquire exclusive ownership on its behalf and release ownership after the operation is completed.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the motor.calPower
- specifies the motor power for the zero calibration, can be positive or negative depending on the desire direction of movement.completionEvent
- specifies an event to signal when zero calibration is done, can be null if not provided.
-
zeroCalibrate
This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled. Generally, calibration power should be negative so that the motor will move towards the lower limit switch. However, in some scenarios such as a turret that can turn all the way around and has only one limit switch, it may be necessary to use a positive calibration power to move it towards the limit switch instead of using negative calibration power and turning the long way around that may cause wires to entangle.- Parameters:
calPower
- specifies the motor power for the zero calibration, can be positive or negative depending on the desire direction of movement.completionEvent
- specifies an event to signal when zero calibration is done, can be null if not provided.
-
zeroCalibrate
This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled. Generally, calibration power should be negative so that the motor will move towards the lower limit switch. However, in some scenarios such as a turret that can turn all the way around and has only one limit switch, it may be necessary to use a positive calibration power to move it towards the limit switch instead of using negative calibration power and turning the long way around that may cause wires to entangle. If this method specifies an owner and the subsystem was not owned by it, it will acquire exclusive ownership on its behalf and release ownership after the operation is completed.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the motor.calPower
- specifies the motor power for the zero calibration, can be positive or negative depending on the desire direction of movement.callback
- specifies a callback handler when zero calibration is done.
-
zeroCalibrate
This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled. Generally, calibration power should be negative so that the motor will move towards the lower limit switch. However, in some scenarios such as a turret that can turn all the way around and has only one limit switch, it may be necessary to use a positive calibration power to move it towards the limit switch instead of using negative calibration power and turning the long way around that may cause wires to entangle.- Parameters:
calPower
- specifies the motor power for the zero calibration, can be positive or negative depending on the desire direction of movement.callback
- specifies a callback handler when zero calibration is done.
-
zeroCalibrate
This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled. Generally, calibration power should be negative so that the motor will move towards the lower limit switch. However, in some scenarios such as a turret that can turn all the way around and has only one limit switch, it may be necessary to use a positive calibration power to move it towards the limit switch instead of using negative calibration power and turning the long way around that may cause wires to entangle.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the motor.calPower
- specifies the motor power for the zero calibration, can be positive or negative depending on the desire direction of movement.
-
zeroCalibrate
public void zeroCalibrate(double calPower) This method starts zero calibration mode by moving the motor with specified calibration power until a limit switch is hit or the motor is stalled. Generally, calibration power should be negative so that the motor will move towards the lower limit switch. However, in some scenarios such as a turret that can turn all the way around and has only one limit switch, it may be necessary to use a positive calibration power to move it towards the limit switch instead of using negative calibration power and turning the long way around that may cause wires to entangle.- Parameters:
calPower
- specifies the motor power for the zero calibration, can be positive or negative depending on the desire direction of movement.
-
setPresets
public void setPresets(boolean velocityPresets, double tolerance, double... presets) This method sets an array of presets for the motor.- Parameters:
velocityPresets
- specifies true for velocity presets, false for position presets.tolerance
- specifies the preset tolerance.presets
- specifies an array of presets in scaled unit.
-
setPresetPosition
public void setPresetPosition(String owner, double delay, int presetIndex, boolean holdTarget, double powerLimit, TrcEvent event, double timeout) This method sets the motor to the specified preset position.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.delay
- specifies delay time in seconds before setting position, can be zero if no delay.presetIndex
- specifies the index to the preset position array.holdTarget
- specifies true to hold target after PID operation is completed.powerLimit
- specifies the maximum power limit.event
- specifies the event to signal when target is reached, can be null if not provided.timeout
- specifies a timeout value in seconds. If the operation is not completed without the specified timeout, the operation will be canceled and the event will be signaled. If no timeout is specified, it should be set to zero.
-
setPresetVelocity
public void setPresetVelocity(String owner, double delay, int presetIndex, double duration, TrcEvent event) This method sets the motor to the specified preset velocity.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.delay
- specifies delay time in seconds before setting velocity, can be zero if no delay.presetIndex
- specifies the index to the preset velocity array.duration
- specifies the duration in seconds to run the motor and turns it off afterwards, 0.0 if not turning off.event
- specifies the event to signal when target is reached, can be null if not provided.
-
setNextPresetPosition
This method sets the motor to the next preset position up or down from the current position.- Parameters:
owner
- specifies the owner ID that will acquire ownership before setting the preset position and will automatically release ownership when the motor movement is completed, can be null if no ownership is required.presetUp
- specifies true to move to next preset up, false to move to next preset down.powerLimit
- specifies the maximum power limit.
-
presetPositionUp
This method sets the motor to the next preset position up from the current position.- Parameters:
owner
- specifies the owner ID that will acquire ownership before setting the preset position and will automatically release ownership when the motor movement is completed, can be null if no ownership is required.powerLimit
- specifies the maximum power limit.
-
presetPositionDown
This method sets the motor to the next preset position down from the current position.- Parameters:
owner
- specifies the owner ID that will acquire ownership before setting the preset position and will automatically release ownership when the motor movement is completed, can be null if no ownership is required.powerLimit
- specifies the maximum power limit.
-
setNextPresetVelocity
This method sets the motor to the next preset velocity up or down from the current velocity.- Parameters:
owner
- specifies the owner ID that will acquire ownership before setting the preset position and will automatically release ownership when the motor movement is completed, can be null if no ownership is required.presetUp
- specifies true to move to next preset up, false to move to next preset down.
-
presetVelocityUp
This method sets the motor to the next preset velocity up from the current velocity.- Parameters:
owner
- specifies the owner ID that will acquire ownership before setting the preset position and will automatically release ownership when the motor movement is completed, can be null if no ownership is required.
-
presetVelocityDown
This method sets the motor to the next preset velocity down from the current velocity.- Parameters:
owner
- specifies the owner ID that will acquire ownership before setting the preset position and will automatically release ownership when the motor movement is completed, can be null if no ownership is required.
-
clearOdometryMotorsList
public static void clearOdometryMotorsList(boolean removeOdometryTask) This method clears the list of motors that register for odometry monitoring. This method should only be called by the task scheduler.- Parameters:
removeOdometryTask
- specifies true to also remove the odometry task object, false to leave it alone. This is mainly for FTC, FRC should always set this to false.
-
getNumOdometryMotors
public static int getNumOdometryMotors()This method returns the number of motors in the list registered for odometry monitoring.- Returns:
- number of motors in the list.
-
setOdometryEnabled
public void setOdometryEnabled(boolean enabled, boolean resetOdometry, boolean resetHardware) This method enables/disables the task that monitors the motor odometry. Since odometry task takes up CPU cycle, it should not be enabled if the user doesn't need motor odometry info.- Parameters:
enabled
- specifies true to enable odometry task, disable otherwise.resetOdometry
- specifies true to reset odometry, false otherwise.resetHardware
- specifies true to reset odometry hardware, false otherwise. This is only applicable when enabling odometry, not used when disabling.
-
isOdometryEnabled
public boolean isOdometryEnabled()This method checks if the odometry of this motor is enabled.- Returns:
- true if odometry of this motor is enabled, false if disabled.
-
getName
This method returns the instance name.- Specified by:
getName
in interfaceTrcOdometrySensor
- Returns:
- instance name.
-
resetOdometry
public void resetOdometry(boolean resetHardware) This method resets the odometry data and sensor.- Specified by:
resetOdometry
in interfaceTrcOdometrySensor
- Parameters:
resetHardware
- specifies true to do a hardware reset, false to do a software reset. Hardware reset may require some time to complete and will block this method from returning until finish.
-
getOdometry
This method returns a copy of the odometry data of the specified axis. It must be a copy so it won't change while the caller is accessing the data fields.- Specified by:
getOdometry
in interfaceTrcOdometrySensor
- Parameters:
axisIndex
- specifies the axis index if it is a multi-axes sensor, 0 if it is a single axis sensor (not used).- Returns:
- a copy of the odometry data of the specified axis.
-
odometryTask
private static void odometryTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to update motor odometry data. Odometry data includes position and velocity data. By using this task to update odometry at a periodic rate, it allows robot code to obtain odometry data from the cached data maintained by this task instead of repeatedly reading it directly from the motor controller which may impact performance because it may involve initiating USB/CAN/I2C bus cycles. So even though some motor controller hardware may keep track of its own velocity, it may be beneficial to just let the odometry task to calculate it.- Parameters:
taskType
- specifies the type of task being run.runMode
- specifies the competition mode that is running.slowPeriodicLoop
- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-
odometryCleanupTask
private void odometryCleanupTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called before the runMode is about to stop so we can disable odometry.- Parameters:
taskType
- specifies the type of task being run.runMode
- specifies the competition mode that is running.slowPeriodicLoop
- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-
setElapsedTimerEnabled
public static void setElapsedTimerEnabled(boolean enabled) This method enables/disables the elapsed timers for performance monitoring.- Parameters:
enabled
- specifies true to enable elapsed timers, false to disable.
-
printElapsedTime
This method prints the elapsed time info using the given tracer.- Parameters:
tracer
- specifies the tracer to be used to print the info.
-
printPidControlTaskPerformance
public void printPidControlTaskPerformance()This method prints the PID control task performance info.
-