Class TrcAutoTask<T>

java.lang.Object
trclib.robotcore.TrcAutoTask<T>

public abstract class TrcAutoTask<T> extends Object
This class implements auto-assist task. It is intended to be extended by a specific auto-assist task that will implement the abstract methods performing the task.
  • Field Details

  • Constructor Details

    • TrcAutoTask

      protected TrcAutoTask(String instanceName, String owner, TrcTaskMgr.TaskType taskType)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the task name.
      owner - specifies the owner to acquire ownership, can be null if not requiring ownership.
      taskType - specifies the auto-assist task type (e.g. TaskType.FAST_POSTPERIODIC_TASK).
  • Method Details

    • acquireSubsystemsOwnership

      protected abstract boolean acquireSubsystemsOwnership()
      This method is called to acquire ownership of all subsystems involved in the auto-assist operation. This is typically done before starting an auto-assist operation.
      Returns:
      true if acquired all subsystems ownership, false otherwise. It releases all ownership if any acquire failed.
    • releaseSubsystemsOwnership

      protected abstract void releaseSubsystemsOwnership()
      This method is called to release ownership of all subsystems involved in the auto-assist operation. This is typically done if the auto-assist operation is completed or canceled.
    • stopSubsystems

      protected abstract void stopSubsystems()
      This method is called to stop all the subsystems.
    • runTaskState

      protected abstract void runTaskState(Object params, T state, TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop)
      This methods is called periodically to run the auto-assist task state.
      Parameters:
      params - specifies the task parameters.
      state - specifies the current state of the task.
      taskType - specifies the type of task being run.
      runMode - specifies the competition mode (e.g. Autonomous, TeleOp, Test).
      slowPeriodicLoop - specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • cancel

      public void cancel()
      This method cancels an in progress auto task operation if any.
    • startAutoTask

      protected void startAutoTask(T startState, Object taskParams, TrcEvent completionEvent)
      This method is called by the subclass to start the auto task.
      Parameters:
      startState - specifies the state to start the state machine.
      taskParams - specifies the task parameters.
      completionEvent - specifies the event to signal when the task is completed, can be null if none provided.
    • stopAutoTask

      protected void stopAutoTask(boolean completed)
      This method is called by the subclass to cancel the auto-assist operation in progress if any.
    • isActive

      public boolean isActive()
      This method checks if the auto task is active.
      Returns:
      true if auto assist task is active, false otherwise.
    • setTaskEnabled

      private void setTaskEnabled(boolean enabled)
      This method enables/disables the auto-assist task.
      Parameters:
      enabled - specifies true to enable, false to disable.
    • autoTask

      private void autoTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop)
      This methods is called periodically to run the auto-assist task.
      Parameters:
      taskType - specifies the type of task being run.
      runMode - specifies the competition mode (e.g. Autonomous, TeleOp, Test).
      slowPeriodicLoop - specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.