Programming resources for FIRST Robotics team 1318
Tasks are used to control operations or groups of operations that run until a certain condition is met. They are used within macros and autonomous routines and can be composed to perform complex actions. Tasks themselves should aim to be relatively simple and only accomplish one thing if possible—this helps prevent code duplication later. An example of a single task is DriveDistanceTask, which drives forward for a specified distance.
Tasks implement the IControlTask interface and typically extend the ControlTaskBase class. Tasks work by applying certain values to one or more operations.
When the task first starts, the begin() function is called so that the task can check the current state of the robot. Every ~20 ms, the update() function is called to update the settings based on the criteria defined in the task. Before running update(), the hasCompleted() function is called to check whether the task should end. There are also functions such as shouldCancel() to indicate that the task needs to end even though it hasn’t officially completed, end() to do cleanup after the task has completed, and stop() to do cleanup if the task was canceled.
To create your own ControlTasks, reference the Writing Control Tasks page to guide you.