Class TrcTaskMgr

java.lang.Object
trclib.robotcore.TrcTaskMgr

public class TrcTaskMgr extends Object
This class provides methods for the callers to register/unregister cooperative multi-tasking tasks. It manages these tasks and will work with the cooperative multi-tasking scheduler to run these tasks.
  • Field Details

  • Constructor Details

    • TrcTaskMgr

      public TrcTaskMgr()
  • Method Details

    • createTask

      public static TrcTaskMgr.TaskObject createTask(String taskName, TrcTaskMgr.Task task)
      This method creates a TRC task. If the TRC task is registered as a STANDALONE task, it is run on a separately created thread. Otherwise, it is run on the main robot thread as a cooperative multi-tasking task.
      Parameters:
      taskName - specifies the task name.
      task - specifies the Task interface for this task.
      Returns:
      created task object.
    • terminateAllThreads

      public static void terminateAllThreads()
      This method is mainly for FtcOpMode to call at the end of the opMode loop because runOpMode could be terminated before shutdown can be called especially if stopMode code is doing logging I/O (e.g. printPerformanceMetrics). This provides an earlier chance for us to stop all task threads before it's too late.
    • shutdown

      public static void shutdown()
      This method is called at the end of the robot program (FtcOpMode in FTC or FrcRobotBase in FRC) to terminate all threads if any and remove all task from the task list.
    • executeTaskType

      public static void executeTaskType(TrcTaskMgr.TaskType type, TrcRobot.RunMode mode, boolean slowPeriodicLoop)
      This method is called by the main robot thread to enumerate the task list and calls all the tasks that matches the given task type.
      Parameters:
      type - specifies the task type to be executed.
      mode - specifies the robot run mode.
      slowPeriodicLoop - specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
    • registerIoTaskLoopCallback

      public static void registerIoTaskLoopCallback(String callerId, TrcTaskMgr.IoTaskCallback ioLoopBeginCallback, TrcTaskMgr.IoTaskCallback ioLoopEndCallback)
      This method registers callbacks at the beginning and ending of the IO task loop.
      Parameters:
      callerId - specifies the caller that registers the IO Task Loop callback.
      ioLoopBeginCallback - specifies the IO task loop begin callback, null if not provided.
      ioLoopEndCallback - specifies the IO task loop end callback, null if not provided.
    • unregisterIoTaskLoopCallback

      private static void unregisterIoTaskLoopCallback(TrcTaskMgr.IoLoopCallbacks ioCallbacks)
      This method unregisters callbacks at the beginning and ending of the IO task loop.
      Parameters:
      ioCallbacks - specifies the IoLoopCallbacks object to be unregistered.
    • unregisterIoTaskLoopCallback

      public static void unregisterIoTaskLoopCallback(String callerId)
      This method unregisters callbacks at the beginning and ending of the IO task loop.
      Parameters:
      callerId - specifies the caller that registered the IoLoopCallbacks object and unregister it.
    • ioTask

      private static void ioTask(Object context)
      This method runs the periodic an IO task loop.
      Parameters:
      context - specifies the context (not used).
    • printTaskPerformanceMetrics

      public static void printTaskPerformanceMetrics()
      This method prints the performance metrics of all tasks.
    • printAllRegisteredTasks

      public static void printAllRegisteredTasks()
      This method prints all registered tasks.