Class TrcTaskMgr.TaskObject

java.lang.Object
trclib.robotcore.TrcTaskMgr.TaskObject
Enclosing class:
TrcTaskMgr

public static class TrcTaskMgr.TaskObject extends Object
This class implements TaskObject that will be created whenever a class is registered as a cooperative multi-tasking task. The created task objects will be entered into an array list of task objects to be scheduled by the scheduler.
  • Field Details

    • taskName

      private final String taskName
    • task

      private final TrcTaskMgr.Task task
    • taskTypes

      private final HashSet<TrcTaskMgr.TaskType> taskTypes
    • taskStartTimes

      private final long[] taskStartTimes
    • taskTotalIntervals

      private final long[] taskTotalIntervals
    • taskTotalElapsedTimes

      private final long[] taskTotalElapsedTimes
    • taskTimeSlotCounts

      private final int[] taskTimeSlotCounts
    • taskThread

      private TrcPeriodicThread<Object> taskThread
  • Constructor Details

    • TaskObject

      private TaskObject(String taskName, TrcTaskMgr.Task task)
      Constructor: Creates an instance of the task object with the given name and the given task type.
      Parameters:
      taskName - specifies the instance name of the task.
      task - specifies the object that implements the TrcTaskMgr.Task interface.
  • Method Details

    • toString

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

      public boolean registerTask(TrcTaskMgr.TaskType type, long taskInterval, int taskPriority)
      This method adds the given task type to the task object.
      Parameters:
      type - specifies the task type.
      taskInterval - specifies the periodic interval for STANDALONE_TASK, ignore for any other task types. If zero interval is specified, the task will be run in a tight loop.
      taskPriority - specifies the priority of the associated thread. Only valid for STANDALONE_TASK, ignored for any other task types.
      Returns:
      true if successful, false if the task with that task type is already registered in the task list.
    • registerTask

      public boolean registerTask(TrcTaskMgr.TaskType type, long taskInterval)
      This method adds the given task type to the task object.
      Parameters:
      type - specifies the task type.
      taskInterval - specifies the periodic interval for STANDALONE_TASK, ignore for any other task types. If zero interval is specified, the task will be run in a tight loop.
      Returns:
      true if successful, false if the task with that task type is already registered in the task list.
    • registerTask

      public boolean registerTask(TrcTaskMgr.TaskType type)
      This method adds the given task type to the task object.
      Parameters:
      type - specifies the task type.
      Returns:
      true if successful, false if the task with that task type is already registered in the task list.
    • unregisterTask

      public boolean unregisterTask(TrcTaskMgr.TaskType type)
      This method removes the given task type from the task object.
      Parameters:
      type - specifies the task type.
      Returns:
      true if successful, false if the task with that type is not found the task list.
    • unregisterTask

      public boolean unregisterTask()
      This method unregisters the given task object from all task types.
      Returns:
      true if successfully removed from any task type, false otherwise.
    • isRegistered

      public boolean isRegistered(TrcTaskMgr.TaskType type)
      This method checks if the given task type is registered with this task object.
      Parameters:
      type - specifies the task type to be checked against.
      Returns:
      true if this task is registered with the given type, false otherwise.
    • isRegistered

      public boolean isRegistered()
      This method checks if this task object is registered for any task type.
      Returns:
      true if this task is registered with any type, false otherwise.
    • hasType

      private boolean hasType(TrcTaskMgr.TaskType type)
      This method checks if the given task type is registered with this task object.
      Parameters:
      type - specifies the task type to be checked against.
      Returns:
      true if this task is registered as the given type, false otherwise.
    • getTask

      private TrcTaskMgr.Task getTask()
      This method returns the class object that was associated with this task object.
      Returns:
      class object associated with the task.
    • getTaskInterval

      public long getTaskInterval()
      This method returns the task interval for TaskType.STANDALONE_TASK.
      Returns:
      task interval in msec. If there is no STANDALONE_TASK type in the task object, zero is returned.
    • setTaskInterval

      public void setTaskInterval(long taskInterval)
      This method sets the task interval for TaskType.STANDALONE_TASK. It has no effect for any other types.
      Parameters:
      taskInterval - specifies the periodic interval for STANDALONE_TASK, ignore for any other task types. If zero interval is specified, the task will be run in a tight loop.
    • setTaskData

      public void setTaskData(Object data)
      This method sets the task data for TaskType.STANDALONE_TASK. It has no effect for any other types.
      Parameters:
      data - specifies the thread data for STANDALONE_TASK, ignore for any other task types.
    • standaloneTask

      private void standaloneTask(Object context)
      This method runs the periodic standalone task.
      Parameters:
      context - specifies the context (not used).
    • recordStartTime

      private void recordStartTime(TrcTaskMgr.TaskType taskType)
      This method records the task start timestamp in the task performance arrays. It is used to calculate task elapsed time after the execution of a task.
      Parameters:
      taskType - specifies the task type to index into the task performance arrays.
    • recordElapsedTime

      private void recordElapsedTime(TrcTaskMgr.TaskType taskType)
      This method records the task elapsed time in the task performance arrays.
      Parameters:
      taskType - specifies the task type to index into the task performance arrays.
    • getAverageTaskElapsedTime

      private double getAverageTaskElapsedTime(TrcTaskMgr.TaskType taskType)
      This method returns the average task elapsed time in seconds.
      Parameters:
      taskType - specifies the task type to index into the task performance arrays.
      Returns:
      average task elapsed time in seconds.
    • getAverageTaskInterval

      private double getAverageTaskInterval(TrcTaskMgr.TaskType taskType)
      This method returns the average task interval time in seconds.
      Parameters:
      taskType - specifies the task type to index into the task performance arrays.
      Returns:
      average task interval time in seconds.