Package trclib.robotcore
Class TrcTaskMgr
java.lang.Object
trclib.robotcore.TrcTaskMgr
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
static interface
This interface can be provided by the platform dependent task scheduler who will be called before and after each IO task loop.static interface
Any class that is registering a task must implement this interface.static class
This class implements TaskObject that will be created whenever a class is registered as a cooperative multi-tasking task.static enum
These are the task type TrcTaskMgr supports: -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
private static final ArrayList<TrcTaskMgr.IoLoopCallbacks>
private static final HashMap<String,
TrcTaskMgr.IoLoopCallbacks> private static TrcPeriodicThread<Object>
private static final String
static long
private static final List<TrcTaskMgr.TaskObject>
static final long
private static final TrcDbgTrace
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TrcTaskMgr.TaskObject
createTask
(String taskName, TrcTaskMgr.Task task) This method creates a TRC task.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.private static void
This method runs the periodic an IO task loop.static void
This method prints all registered tasks.static void
This method prints the performance metrics of all tasks.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.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.static void
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.static void
unregisterIoTaskLoopCallback
(String callerId) This method unregisters callbacks at the beginning and ending of the IO task loop.private static void
unregisterIoTaskLoopCallback
(TrcTaskMgr.IoLoopCallbacks ioCallbacks) This method unregisters callbacks at the beginning and ending of the IO task loop.
-
Field Details
-
moduleName
-
tracer
-
PERIODIC_INTERVAL_MS
public static long PERIODIC_INTERVAL_MS -
IO_INTERVAL_MS
public static final long IO_INTERVAL_MS- See Also:
-
TASKTIME_THRESHOLD_MS
public static final long TASKTIME_THRESHOLD_MS -
taskList
-
ioThread
-
ioLoopCallbackList
-
ioLoopCallbackMap
-
-
Constructor Details
-
TrcTaskMgr
public TrcTaskMgr()
-
-
Method Details
-
createTask
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
This method unregisters callbacks at the beginning and ending of the IO task loop.- Parameters:
ioCallbacks
- specifies the IoLoopCallbacks object to be unregistered.
-
unregisterIoTaskLoopCallback
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
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.
-