Package trclib.pathdrive
Class TrcPidDrive
java.lang.Object
trclib.pathdrive.TrcPidDrive
This class implements a PID controlled robot drive. A PID controlled robot drive consist of a robot drive base
and three PID controllers, one for the X direction, one for the Y direction and one for turn. If the robot drive
base is incapable of moving in the X direction, the X PID controller will be null. In addition, it has stall
detection support which will detect drive base stall condition. The drive base could stall if the robot runs into
an obstacle in low power or the robot is very close to target and doesn't have enough power to overcome steady
state error. When stall condition is detected, PID drive will be aborted so that the robot won't get stuck waiting
forever trying to reach target.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Turn mode specifies how PID controlled drive is turning the robot. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private TrcPose2D
private boolean
private TrcRobotBattery
private TrcTone
private double
private double
private boolean
private static final double
private static final double
private final TrcDriveBase
private final TrcTaskMgr.TaskObject
private double
private boolean
private final String
private boolean
private boolean
private double
private double
private boolean
private TrcEvent
private String
final TrcLoopProfiler
private boolean
private final TrcTaskMgr.TaskObject
private boolean
final TrcDbgTrace
private TrcPidDrive.TurnMode
private boolean
private final TrcPidController
private double
private boolean
private TrcWarpSpace
private boolean
private final TrcPidController
private double
private final TrcPidController
private double
-
Constructor Summary
ConstructorsConstructorDescriptionTrcPidDrive
(String instanceName, TrcDriveBase driveBase, TrcPidController.PidCoefficients yPidCoeffs, double yTolerance, TrcPidController.PidInput yPidInput, TrcPidController.PidCoefficients turnPidCoeffs, double turnTolerance, TrcPidController.PidInput turnPidInput) Constructor: Create an instance of the object.TrcPidDrive
(String instanceName, TrcDriveBase driveBase, TrcPidController.PidCoefficients xPidCoeffs, double xTolerance, TrcPidController.PidInput xPidInput, TrcPidController.PidCoefficients yPidCoeffs, double yTolerance, TrcPidController.PidInput yPidInput, TrcPidController.PidCoefficients turnPidCoeffs, double turnTolerance, TrcPidController.PidInput turnPidInput) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
This method cancels an active PID drive operation and stops all motors.void
This method cancels an active PID drive operation and stops all motors.void
driveMaintainHeading
(double xPower, double yPower, double headingTarget) This method allows a mecanum drive base to drive and maintain a fixed angle.void
driveMaintainHeading
(String owner, double xPower, double yPower, double headingTarget) This method allows a mecanum drive base to drive and maintain a fixed angle.private void
driveTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to execute the PID drive operation.This method returns the robot's current absolute pose relative to the origin of the coordinate system.This method returns the current absolute target pose.This method returns the current turn mode.This method returns the Turn PID controller if any.This method returns the X PID controller if any.This method returns the Y PID controller if any.boolean
This method checks if Absolute Target Mode is enabled.boolean
isActive()
This method checks if a PID drive operation is currently active.boolean
This method checks if a PID drive operation was canceled.boolean
This method checks if warpspace processing is enabled in a PID controlled turn.void
This method sets the current robot pose as the absolute target pose.void
setAbsoluteHeadingTarget
(double absHeading, TrcEvent event) This method sets the PID controlled absolute drive targets.void
setAbsoluteHeadingTarget
(double absHeading, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.void
setAbsolutePose
(TrcPose2D pose) This method sets the robot's current absolute pose to the given pose.void
setAbsoluteTarget
(double absX, double absY, double absHeading, boolean holdTarget) This method sets the PID controlled absolute drive targets.void
setAbsoluteTarget
(double absX, double absY, double absHeading, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.void
setAbsoluteTarget
(double absX, double absY, double absHeading, TrcEvent event) This method sets the PID controlled absolute drive targets.void
setAbsoluteTarget
(double absX, double absY, double absHeading, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.void
setAbsoluteTarget
(String owner, double absX, double absY, double absHeading, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.void
setAbsoluteTarget
(String owner, TrcPose2D targetPose, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.void
setAbsoluteTarget
(TrcPose2D targetPose, boolean holdTarget) This method sets the PID controlled absolute drive targets.void
setAbsoluteTarget
(TrcPose2D targetPose, boolean holdTarget, TrcEvent event) This method sets the PID controlled absolute drive targets.void
setAbsoluteTarget
(TrcPose2D targetPose, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.void
setAbsoluteTarget
(TrcPose2D targetPose, TrcEvent event) This method sets the PID controlled absolute drive targets.void
setAbsoluteTarget
(TrcPose2D targetPose, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.void
setAbsoluteTargetModeEnabled
(boolean enabled) This method enables/disables absolute target mode.void
This method sets the current absolute target pose to the given pose.void
setAbsoluteXTarget
(double absX, TrcEvent event) This method sets the PID controlled absolute drive targets.void
setAbsoluteXTarget
(double absX, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.void
setAbsoluteXYTarget
(double absX, double absY, TrcEvent event) This method sets the PID controlled absolute drive targets.void
setAbsoluteXYTarget
(double absX, double absY, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.void
setAbsoluteYTarget
(double absY, TrcEvent event) This method sets the PID controlled absolute drive targets.void
setAbsoluteYTarget
(double absY, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.void
This method sets the beep device so that it can play beeps at default frequency and duration when motor stalled or if the limit switches are activated/deactivated.void
This method sets the beep device and the beep tones so that it can play beeps when motor stalled or if the limit switches are activated/deactivated.void
setNoOscillation
(boolean noOscillation) This method enables/disables NoOscillation mode.void
setPidTolerances
(double yTolerance, double turnTolerance) This method sets the PID tolerances for X, Y and Turn.void
setPidTolerances
(double xTolerance, double yTolerance, double turnTolerance) This method sets the PID tolerances for X, Y and Turn.void
setRelativeTarget
(double xDelta, double yDelta, double turnDelta, boolean holdTarget) This method sets the PID controlled relative drive targets.void
setRelativeTarget
(double xDelta, double yDelta, double turnDelta, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled relative drive targets.void
setRelativeTarget
(double xDelta, double yDelta, double turnDelta, TrcEvent event) This method sets the PID controlled relative drive targets.void
setRelativeTarget
(double xDelta, double yDelta, double turnDelta, TrcEvent event, double timeout) This method sets the PID controlled relative drive targets.void
setRelativeTarget
(String owner, double xDelta, double yDelta, double turnDelta, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled relative drive targets.void
setRelativeTurnTarget
(double turnDelta, TrcEvent event) This method sets the PID controlled relative drive targets.void
setRelativeTurnTarget
(double turnDelta, TrcEvent event, double timeout) This method sets the PID controlled relative drive targets.void
setRelativeXTarget
(double xDelta, TrcEvent event) This method sets the PID controlled relative drive targets.void
setRelativeXTarget
(double xDelta, TrcEvent event, double timeout) This method sets the PID controlled relative drive targets.void
setRelativeXYTarget
(double xDelta, double yDelta, TrcEvent event) This method sets the PID controlled relative drive targets.void
setRelativeXYTarget
(double xDelta, double yDelta, TrcEvent event, double timeout) This method sets the PID controlled relative drive targets.void
setRelativeYTarget
(double yDelta, TrcEvent event) This method sets the PID controlled relative drive targets.void
setRelativeYTarget
(double yDelta, TrcEvent event, double timeout) This method sets the PID controlled relative drive targets.void
setSensorTarget
(double xTarget, double yTarget, double turnTarget, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled drive referencing sensors as targets.void
setSensorTarget
(double xTarget, double yTarget, double turnTarget, TrcEvent event) This method sets the PID controlled drive referencing sensors as targets.void
setSensorTarget
(String owner, double xTarget, double yTarget, double turnTarget, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled drive referencing sensors as targets.void
setStallDetectionEnabled
(boolean enabled) This method enables/disables stall detection.void
setStallDetectionEnabled
(double stallDetectionDelay, double stallDetectionTimeout, double stallErrorRateThreshold) This method enables/disables stall detection.private void
setTarget
(double xTarget, double yTarget, double turnTarget, boolean holdTarget, TrcEvent event, double timeout) This method starts a PID operation by setting the PID targets.private void
setTaskEnabled
(boolean enabled) This method enables/disables the PID drive task.void
setTraceLevel
(TrcDbgTrace.MsgLevel msgLevel, boolean logRobotPoseEvents, boolean tracePidInfo, boolean verbosePidInfo) This method sets the message tracer for logging trace messages.void
setTraceLevel
(TrcDbgTrace.MsgLevel msgLevel, boolean logRobotPoseEvents, boolean tracePidInfo, boolean verbosePidInfo, TrcRobotBattery battery) This method sets the message tracer for logging trace messages.void
setTurnMode
(TrcPidDrive.TurnMode turnMode) This methods sets the turn mode.void
setWarpSpaceEnabled
(boolean enabled) This method enables/disables warpspace processing when doing a PID controlled turn.private void
This method stops the PID drive operation and reset the states.private void
stopTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called when the competition mode is about to end to stop the PID drive operation if any.toString()
This method returns the instance name.
-
Field Details
-
DEF_BEEP_FREQUENCY
private static final double DEF_BEEP_FREQUENCY- See Also:
-
DEF_BEEP_DURATION
private static final double DEF_BEEP_DURATION- See Also:
-
tracer
-
instanceName
-
driveBase
-
xPidCtrl
-
yPidCtrl
-
turnPidCtrl
-
pidDriveTaskProfiler
-
xTolerance
private double xTolerance -
yTolerance
private double yTolerance -
turnTolerance
private double turnTolerance -
driveTaskObj
-
stopTaskObj
-
logRobotPoseEvents
private boolean logRobotPoseEvents -
tracePidInfo
private boolean tracePidInfo -
verbosePidInfo
private boolean verbosePidInfo -
battery
-
savedReferencePose
private boolean savedReferencePose -
warpSpace
-
warpSpaceEnabled
private boolean warpSpaceEnabled -
absTargetModeEnabled
private boolean absTargetModeEnabled -
noOscillation
private boolean noOscillation -
turnMode
-
beepDevice
-
beepFrequency
private double beepFrequency -
beepDuration
private double beepDuration -
notifyEvent
-
expiredTime
private double expiredTime -
manualX
private double manualX -
manualY
private double manualY -
active
private boolean active -
holdTarget
private boolean holdTarget -
turnOnly
private boolean turnOnly -
maintainHeading
private boolean maintainHeading -
canceled
private boolean canceled -
owner
-
absTargetPose
-
-
Constructor Details
-
TrcPidDrive
public TrcPidDrive(String instanceName, TrcDriveBase driveBase, TrcPidController.PidCoefficients xPidCoeffs, double xTolerance, TrcPidController.PidInput xPidInput, TrcPidController.PidCoefficients yPidCoeffs, double yTolerance, TrcPidController.PidInput yPidInput, TrcPidController.PidCoefficients turnPidCoeffs, double turnTolerance, TrcPidController.PidInput turnPidInput) Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.driveBase
- specifies the drive base object.xPidCoeffs
- specifies the PID coefficients of the X PID controller.xTolerance
- specifies the X PID tolerance.xPidInput
- specifies the method to call to get X input.yPidCoeffs
- specifies the PID coefficients of the Y PID controller.yTolerance
- specifies the Y PID tolerance.yPidInput
- specifies the method to call to get Y input.turnPidCoeffs
- specifies the PID coefficients of the turn PID controller.turnTolerance
- specifies the Turn PID tolerance.turnPidInput
- specifies the method to call to get turn input.
-
TrcPidDrive
public TrcPidDrive(String instanceName, TrcDriveBase driveBase, TrcPidController.PidCoefficients yPidCoeffs, double yTolerance, TrcPidController.PidInput yPidInput, TrcPidController.PidCoefficients turnPidCoeffs, double turnTolerance, TrcPidController.PidInput turnPidInput) Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.driveBase
- specifies the drive base object.yPidCoeffs
- specifies the PID coefficients of the Y PID controller.yTolerance
- specifies the Y PID tolerance.yPidInput
- specifies the method to call to get Y input.turnPidCoeffs
- specifies the PID coefficients of the turn PID controller.turnTolerance
- specifies the Turn PID tolerance.turnPidInput
- specifies the method to call to get turn input.
-
-
Method Details
-
toString
This method returns the instance name. -
setPidTolerances
public void setPidTolerances(double xTolerance, double yTolerance, double turnTolerance) This method sets the PID tolerances for X, Y and Turn.- Parameters:
xTolerance
- specifies X PID tolerance.yTolerance
- specifies Y PID tolerance.turnTolerance
- specifies Turn PID tolerance.
-
setPidTolerances
public void setPidTolerances(double yTolerance, double turnTolerance) This method sets the PID tolerances for X, Y and Turn.- Parameters:
yTolerance
- specifies Y PID tolerance.turnTolerance
- specifies Turn PID tolerance.
-
setAbsoluteTargetModeEnabled
public void setAbsoluteTargetModeEnabled(boolean enabled) This method enables/disables absolute target mode. This class always keep track of the absolute position of the robot. When absolute target mode is enabled, all setRelativeTarget calls will adjust the relative targets by subtracting the current robot position from the absolute target position. This will essentially canceling out cumulative errors of multi-segment PID drive.- Parameters:
enabled
- specifies true to enable absolute target mode, false to disable.
-
setNoOscillation
public void setNoOscillation(boolean noOscillation) This method enables/disables NoOscillation mode. When NoOscillation is enabled, PIDDrive will determine which degrees of freedom are moving and set the corresponding PID controllers to enable noOscillation mode. For the degrees of freedom that are maintaining previous position, we need to allow oscillation.- Parameters:
noOscillation
- specifies true to enable no oscillation, false to disable.
-
isAbsoluteTargetModeEnabled
public boolean isAbsoluteTargetModeEnabled()This method checks if Absolute Target Mode is enabled.- Returns:
- true if Absolute Target Mode is enabled, false otherwise.
-
setTraceLevel
public void setTraceLevel(TrcDbgTrace.MsgLevel msgLevel, boolean logRobotPoseEvents, boolean tracePidInfo, boolean verbosePidInfo, TrcRobotBattery battery) This method sets the message tracer for logging trace messages.- Parameters:
msgLevel
- specifies the message level.logRobotPoseEvents
- specifies true to log robot pose events, false otherwise.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.
-
setTraceLevel
public void setTraceLevel(TrcDbgTrace.MsgLevel msgLevel, boolean logRobotPoseEvents, boolean tracePidInfo, boolean verbosePidInfo) This method sets the message tracer for logging trace messages.- Parameters:
msgLevel
- specifies the message level.logRobotPoseEvents
- specifies true to log robot pose events, false otherwise.tracePidInfo
- specifies true to enable tracing of PID info, false otherwise.verbosePidInfo
- specifies true to trace verbose PID info, false otherwise.
-
isWarpSpaceEnabled
public boolean isWarpSpaceEnabled()This method checks if warpspace processing is enabled in a PID controlled turn.- Returns:
- true if warpspace processing is enabled, false otherwise.
-
setWarpSpaceEnabled
public void setWarpSpaceEnabled(boolean enabled) This method enables/disables warpspace processing when doing a PID controlled turn.- Parameters:
enabled
- specifies true to enable warpspace processing, false to disable.
-
getAbsoluteTargetPose
This method returns the current absolute target pose. It is useful if you have multiple instances of the TrcEnhancedPidDrive that you want to sync their target poses.- Returns:
- current absolute target pose.
-
setAbsoluteTargetPose
This method sets the current absolute target pose to the given pose.- Parameters:
pose
- specifies the pose to be set as the current absolute target pose.
-
resetAbsoluteTargetPose
public void resetAbsoluteTargetPose()This method sets the current robot pose as the absolute target pose. -
setAbsolutePose
This method sets the robot's current absolute pose to the given pose. It also updates the absolute target pose to the same pose. This can be used to set the robot's absolute starting position relative to the origin of the coordinate system.- Parameters:
pose
- specifies the absolute pose of the robot relative to the origin of the coordinate system.
-
getAbsolutePose
This method returns the robot's current absolute pose relative to the origin of the coordinate system.- Returns:
- robot's current absolute pose.
-
getXPidCtrl
This method returns the X PID controller if any.- Returns:
- X PID controller.
-
getYPidCtrl
This method returns the Y PID controller if any.- Returns:
- Y PID controller.
-
getTurnPidCtrl
This method returns the Turn PID controller if any.- Returns:
- Turn PID controller.
-
setTurnMode
This methods sets the turn mode. Supported modes are in-place (default), pivot and curve.- Parameters:
turnMode
- specifies the turn mode to set to.
-
getTurnMode
This method returns the current turn mode.- Returns:
- current turn mode.
-
setBeep
This method sets the beep device and the beep tones so that it can play beeps when motor stalled or if the limit switches are activated/deactivated.- Parameters:
beepDevice
- specifies the beep device object.beepFrequency
- specifies the beep frequency.beepDuration
- specifies the beep duration.
-
setBeep
This method sets the beep device so that it can play beeps at default frequency and duration when motor stalled or if the limit switches are activated/deactivated.- Parameters:
beepDevice
- specifies the beep device object.
-
setStallDetectionEnabled
public void setStallDetectionEnabled(double stallDetectionDelay, double stallDetectionTimeout, double stallErrorRateThreshold) This method enables/disables 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.
-
setStallDetectionEnabled
public void setStallDetectionEnabled(boolean enabled) This method enables/disables stall detection.- Parameters:
enabled
- specifies true to enable stall detection, false to disable.
-
setTarget
private void setTarget(double xTarget, double yTarget, double turnTarget, boolean holdTarget, TrcEvent event, double timeout) This method starts a PID operation by setting the PID targets.- Parameters:
xTarget
- specifies the X target position.yTarget
- specifies the Y target position.turnTarget
- specifies the target angle.holdTarget
- specifies true for holding the target position at the end, false otherwise.event
- specifies an event object to signal when done.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.
-
setSensorTarget
public void setSensorTarget(String owner, double xTarget, double yTarget, double turnTarget, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled drive referencing sensors as targets. It is sometimes useful to use sensors as target referencing devices. For example, this can be used to do vision target drive where the camera can provide the target distance as well as the target angle. Note that when doing sensor target drive, you cannot turn on Absolute Target Mode because Absolute Target Mode assumes wheel odometry is the target referencing device.- Parameters:
owner
- specifies the ID string of the caller requesting exclusive access.xTarget
- specifies the X target position.yTarget
- specifies the Y target position.turnTarget
- specifies the target angle.holdTarget
- specifies true for holding the target position at the end, false otherwise.event
- specifies an event object to signal when done.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.
-
setSensorTarget
public void setSensorTarget(double xTarget, double yTarget, double turnTarget, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled drive referencing sensors as targets. It is sometimes useful to use sensors as target referencing devices. For example, this can be used to do vision target drive where the camera can provide the target distance as well as the target angle. Note that when doing sensor target drive, you cannot turn on Absolute Target Mode because Absolute Target Mode assumes wheel odometry is the target referencing device.- Parameters:
xTarget
- specifies the X target position.yTarget
- specifies the Y target position.turnTarget
- specifies the target angle.holdTarget
- specifies true for holding the target position at the end, false otherwise.event
- specifies an event object to signal when done.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.
-
setSensorTarget
This method sets the PID controlled drive referencing sensors as targets. It is sometimes useful to use sensors as target referencing devices. For example, this can be used to do vision target drive where the camera can provide the target distance as well as the target angle. Note that when doing sensor target drive, you cannot turn on Absolute Target Mode because Absolute Target Mode assumes wheel odometry is the target referencing device.- Parameters:
xTarget
- specifies the X target position.yTarget
- specifies the Y target position.turnTarget
- specifies the target angle.event
- specifies an event object to signal when done.
-
setRelativeTarget
public void setRelativeTarget(String owner, double xDelta, double yDelta, double turnDelta, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled relative drive targets.- Parameters:
owner
- specifies the ID string of the caller requesting exclusive access.xDelta
- specifies the X target relative to the current X position.yDelta
- specifies the Y target relative to the current Y position.turnDelta
- specifies the turn target relative to the current angle.holdTarget
- specifies true for holding the target position at the end, false otherwise.event
- specifies an event object to signal when done.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.
-
setRelativeTarget
public void setRelativeTarget(double xDelta, double yDelta, double turnDelta, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled relative drive targets.- Parameters:
xDelta
- specifies the X target relative to the current X position.yDelta
- specifies the Y target relative to the current Y position.turnDelta
- specifies the turn target relative to the current angle.holdTarget
- specifies true for holding the target position at the end, false otherwise.event
- specifies an event object to signal when done.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.
-
setRelativeTarget
public void setRelativeTarget(double xDelta, double yDelta, double turnDelta, TrcEvent event, double timeout) This method sets the PID controlled relative drive targets.- Parameters:
xDelta
- specifies the X target relative to the current X position.yDelta
- specifies the Y target relative to the current Y position.turnDelta
- specifies the turn target relative to the current angle.event
- specifies an event object to signal when done.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.
-
setRelativeTarget
This method sets the PID controlled relative drive targets.- Parameters:
xDelta
- specifies the X target relative to the current X position.yDelta
- specifies the Y target relative to the current Y position.turnDelta
- specifies the turn target relative to the current angle.event
- specifies an event object to signal when done.
-
setRelativeTarget
public void setRelativeTarget(double xDelta, double yDelta, double turnDelta, boolean holdTarget) This method sets the PID controlled relative drive targets.- Parameters:
xDelta
- specifies the X target relative to the current X position.yDelta
- specifies the Y target relative to the current Y position.turnDelta
- specifies the turn target relative to the current angle.holdTarget
- specifies true for holding the target position at the end, false otherwise.
-
setRelativeXYTarget
This method sets the PID controlled relative drive targets.- Parameters:
xDelta
- specifies the X target relative to the current X position.yDelta
- specifies the Y target relative to the current Y position.event
- specifies an event object to signal when done.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.
-
setRelativeXYTarget
This method sets the PID controlled relative drive targets.- Parameters:
xDelta
- specifies the X target relative to the current X position.yDelta
- specifies the Y target relative to the current Y position.event
- specifies an event object to signal when done.
-
setRelativeXTarget
This method sets the PID controlled relative drive targets.- Parameters:
xDelta
- specifies the X target relative to the current X position.event
- specifies an event object to signal when done.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.
-
setRelativeXTarget
This method sets the PID controlled relative drive targets.- Parameters:
xDelta
- specifies the X target relative to the current X position.event
- specifies an event object to signal when done.
-
setRelativeYTarget
This method sets the PID controlled relative drive targets.- Parameters:
yDelta
- specifies the Y target relative to the current Y position.event
- specifies an event object to signal when done.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.
-
setRelativeYTarget
This method sets the PID controlled relative drive targets.- Parameters:
yDelta
- specifies the Y target relative to the current Y position.event
- specifies an event object to signal when done.
-
setRelativeTurnTarget
This method sets the PID controlled relative drive targets.- Parameters:
turnDelta
- specifies the turn target relative to the current angle.event
- specifies an event object to signal when done.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.
-
setRelativeTurnTarget
This method sets the PID controlled relative drive targets.- Parameters:
turnDelta
- specifies the turn target relative to the current angle.event
- specifies an event object to signal when done.
-
setAbsoluteTarget
public void setAbsoluteTarget(String owner, double absX, double absY, double absHeading, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.- Parameters:
owner
- specifies the ID string of the caller requesting exclusive access.absX
- specifies the absolute X target position.absY
- specifies the absolute Y target position.absHeading
- specifies the absolute target angle.holdTarget
- specifies true for holding the target position at the end, false otherwise.event
- specifies an event object to signal when done.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.
-
setAbsoluteTarget
public void setAbsoluteTarget(double absX, double absY, double absHeading, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.- Parameters:
absX
- specifies the absolute X target position.absY
- specifies the absolute Y target position.absHeading
- specifies the absolute target angle.holdTarget
- specifies true for holding the target position at the end, false otherwise.event
- specifies an event object to signal when done.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.
-
setAbsoluteTarget
public void setAbsoluteTarget(double absX, double absY, double absHeading, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.- Parameters:
absX
- specifies the absolute X target position.absY
- specifies the absolute Y target position.absHeading
- specifies the absolute target angle.event
- specifies an event object to signal when done.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.
-
setAbsoluteTarget
This method sets the PID controlled absolute drive targets.- Parameters:
absX
- specifies the absolute X target position.absY
- specifies the absolute Y target position.absHeading
- specifies the absolute target angle.event
- specifies an event object to signal when done.
-
setAbsoluteTarget
public void setAbsoluteTarget(double absX, double absY, double absHeading, boolean holdTarget) This method sets the PID controlled absolute drive targets.- Parameters:
absX
- specifies the absolute X target position.absY
- specifies the absolute Y target position.absHeading
- specifies the absolute target angle.holdTarget
- specifies true for holding the target position at the end, false otherwise.
-
setAbsoluteTarget
public void setAbsoluteTarget(String owner, TrcPose2D targetPose, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.- Parameters:
owner
- specifies the ID string of the caller requesting exclusive access.targetPose
- specifies the target position.holdTarget
- specifies true for holding the target position at the end, false otherwise.event
- specifies an event object to signal when done.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.
-
setAbsoluteTarget
public void setAbsoluteTarget(TrcPose2D targetPose, boolean holdTarget, TrcEvent event, double timeout) This method sets the PID controlled absolute drive targets.- Parameters:
targetPose
- specifies the target position.holdTarget
- specifies true for holding the target position at the end, false otherwise.event
- specifies an event object to signal when done.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.
-
setAbsoluteTarget
This method sets the PID controlled absolute drive targets.- Parameters:
targetPose
- specifies the target position.event
- specifies an event object to signal when done.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.
-
setAbsoluteTarget
This method sets the PID controlled absolute drive targets.- Parameters:
targetPose
- specifies the target position.event
- specifies an event object to signal when done.
-
setAbsoluteTarget
This method sets the PID controlled absolute drive targets.- Parameters:
targetPose
- specifies the target position.holdTarget
- specifies true for holding the target position at the end, false otherwise.event
- specifies an event object to signal when done.
-
setAbsoluteTarget
This method sets the PID controlled absolute drive targets.- Parameters:
targetPose
- specifies the target position.holdTarget
- specifies true for holding the target position at the end, false otherwise.
-
setAbsoluteXYTarget
This method sets the PID controlled absolute drive targets.- Parameters:
absX
- specifies the absolute X target position.absY
- specifies the absolute Y target position.event
- specifies an event object to signal when done.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.
-
setAbsoluteXYTarget
This method sets the PID controlled absolute drive targets.- Parameters:
absX
- specifies the absolute X target position.absY
- specifies the absolute Y target position.event
- specifies an event object to signal when done.
-
setAbsoluteXTarget
This method sets the PID controlled absolute drive targets.- Parameters:
absX
- specifies the absolute X target position.event
- specifies an event object to signal when done.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.
-
setAbsoluteXTarget
This method sets the PID controlled absolute drive targets.- Parameters:
absX
- specifies the absolute X target position.event
- specifies an event object to signal when done.
-
setAbsoluteYTarget
This method sets the PID controlled absolute drive targets.- Parameters:
absY
- specifies the absolute Y target position.event
- specifies an event object to signal when done.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.
-
setAbsoluteYTarget
This method sets the PID controlled absolute drive targets.- Parameters:
absY
- specifies the absolute Y target position.event
- specifies an event object to signal when done.
-
setAbsoluteHeadingTarget
This method sets the PID controlled absolute drive targets.- Parameters:
absHeading
- specifies the absolute target angle.event
- specifies an event object to signal when done.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.
-
setAbsoluteHeadingTarget
This method sets the PID controlled absolute drive targets.- Parameters:
absHeading
- specifies the absolute target angle.event
- specifies an event object to signal when done.
-
driveMaintainHeading
This method allows a mecanum drive base to drive and maintain a fixed angle.- Parameters:
owner
- specifies the ID string of the caller requesting exclusive access.xPower
- specifies the X drive power.yPower
- specifies the Y drive power.headingTarget
- specifies the angle to maintain.
-
driveMaintainHeading
public void driveMaintainHeading(double xPower, double yPower, double headingTarget) This method allows a mecanum drive base to drive and maintain a fixed angle.- Parameters:
xPower
- specifies the X drive power.yPower
- specifies the Y drive power.headingTarget
- specifies the angle to maintain.
-
isActive
public boolean isActive()This method checks if a PID drive operation is currently active.- Returns:
- true if PID drive is active, false otherwise.
-
cancel
This method cancels an active PID drive operation and stops all motors.- Parameters:
owner
- specifies the ID string of the caller requesting exclusive access.
-
cancel
public void cancel()This method cancels an active PID drive operation and stops all motors. -
isCanceled
public boolean isCanceled()This method checks if a PID drive operation was canceled.- Returns:
- true if PID drive is active, false otherwise.
-
stopPid
This method stops the PID drive operation and reset the states.- Parameters:
owner
- specifies the ID string of the caller requesting exclusive access.
-
setTaskEnabled
private void setTaskEnabled(boolean enabled) This method enables/disables the PID drive task. It assumes the caller has the synchronized lock.- Parameters:
enabled
- specifies true to enable PID drive task, false to disable.
-
driveTask
private void driveTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to execute the PID drive operation.- Parameters:
taskType
- specifies the type of task being run.runMode
- specifies the competition mode that is about to end (e.g. Autonomous, TeleOp, Test).slowPeriodicLoop
- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-
stopTask
private void stopTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called when the competition mode is about to end to stop the PID drive operation if any.- Parameters:
taskType
- specifies the type of task being run.runMode
- specifies the competition mode that is about to end (e.g. Autonomous, TeleOp, Test).slowPeriodicLoop
- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-