Class TrcPidDrive

java.lang.Object
trclib.pathdrive.TrcPidDrive

public class TrcPidDrive extends Object
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.
  • 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

      public final TrcDbgTrace tracer
    • instanceName

      private final String instanceName
    • driveBase

      private final TrcDriveBase driveBase
    • xPidCtrl

      private final TrcPidController xPidCtrl
    • yPidCtrl

      private final TrcPidController yPidCtrl
    • turnPidCtrl

      private final TrcPidController turnPidCtrl
    • pidDriveTaskProfiler

      public final TrcLoopProfiler pidDriveTaskProfiler
    • xTolerance

      private double xTolerance
    • yTolerance

      private double yTolerance
    • turnTolerance

      private double turnTolerance
    • driveTaskObj

      private final TrcTaskMgr.TaskObject driveTaskObj
    • stopTaskObj

      private final TrcTaskMgr.TaskObject stopTaskObj
    • logRobotPoseEvents

      private boolean logRobotPoseEvents
    • tracePidInfo

      private boolean tracePidInfo
    • verbosePidInfo

      private boolean verbosePidInfo
    • battery

      private TrcRobotBattery battery
    • savedReferencePose

      private boolean savedReferencePose
    • warpSpace

      private TrcWarpSpace warpSpace
    • warpSpaceEnabled

      private boolean warpSpaceEnabled
    • absTargetModeEnabled

      private boolean absTargetModeEnabled
    • noOscillation

      private boolean noOscillation
    • turnMode

      private TrcPidDrive.TurnMode turnMode
    • beepDevice

      private TrcTone beepDevice
    • beepFrequency

      private double beepFrequency
    • beepDuration

      private double beepDuration
    • notifyEvent

      private TrcEvent 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

      private String owner
    • absTargetPose

      private TrcPose2D 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

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      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

      public TrcPose2D 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

      public void setAbsoluteTargetPose(TrcPose2D pose)
      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

      public void setAbsolutePose(TrcPose2D pose)
      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

      public TrcPose2D 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

      public TrcPidController getXPidCtrl()
      This method returns the X PID controller if any.
      Returns:
      X PID controller.
    • getYPidCtrl

      public TrcPidController getYPidCtrl()
      This method returns the Y PID controller if any.
      Returns:
      Y PID controller.
    • getTurnPidCtrl

      public TrcPidController getTurnPidCtrl()
      This method returns the Turn PID controller if any.
      Returns:
      Turn PID controller.
    • setTurnMode

      public void setTurnMode(TrcPidDrive.TurnMode turnMode)
      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

      public TrcPidDrive.TurnMode getTurnMode()
      This method returns the current turn mode.
      Returns:
      current turn mode.
    • setBeep

      public void setBeep(TrcTone beepDevice, double beepFrequency, double beepDuration)
      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

      public void setBeep(TrcTone beepDevice)
      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

      public void setSensorTarget(double xTarget, double yTarget, double turnTarget, TrcEvent event)
      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

      public void setRelativeTarget(double xDelta, double yDelta, double turnDelta, TrcEvent event)
      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

      public void setRelativeXYTarget(double xDelta, double yDelta, 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.
      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

      public void setRelativeXYTarget(double xDelta, double yDelta, TrcEvent event)
      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

      public void setRelativeXTarget(double xDelta, 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.
      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

      public void setRelativeXTarget(double xDelta, TrcEvent event)
      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

      public void setRelativeYTarget(double yDelta, TrcEvent event, double timeout)
      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

      public void setRelativeYTarget(double yDelta, TrcEvent event)
      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

      public void setRelativeTurnTarget(double turnDelta, TrcEvent event, double timeout)
      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

      public void setRelativeTurnTarget(double turnDelta, TrcEvent event)
      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

      public void setAbsoluteTarget(double absX, double absY, double absHeading, TrcEvent event)
      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

      public void setAbsoluteTarget(TrcPose2D targetPose, TrcEvent event, double timeout)
      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

      public void setAbsoluteTarget(TrcPose2D targetPose, TrcEvent event)
      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

      public void setAbsoluteTarget(TrcPose2D targetPose, boolean holdTarget, TrcEvent event)
      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

      public void setAbsoluteTarget(TrcPose2D targetPose, boolean holdTarget)
      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

      public void setAbsoluteXYTarget(double absX, double absY, 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.
      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

      public void setAbsoluteXYTarget(double absX, double absY, TrcEvent event)
      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

      public void setAbsoluteXTarget(double absX, TrcEvent event, double timeout)
      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

      public void setAbsoluteXTarget(double absX, TrcEvent event)
      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

      public void setAbsoluteYTarget(double absY, TrcEvent event, double timeout)
      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

      public void setAbsoluteYTarget(double absY, TrcEvent event)
      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

      public void setAbsoluteHeadingTarget(double absHeading, TrcEvent event, double timeout)
      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

      public void setAbsoluteHeadingTarget(double absHeading, TrcEvent event)
      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

      public void driveMaintainHeading(String owner, double xPower, double yPower, double headingTarget)
      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

      public void cancel(String owner)
      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

      private void stopPid(String owner)
      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.