RepeatTask

open class RepeatTask : ForeverTask

A task that will auto-reset and repeat itself after it is completed.

Author

Lucas Bubner, 2024

Since

1.0.0-pre

Constructors

Link copied to clipboard
constructor(task: Task)
Create a new RepeatTask with the given task.

Inherited properties

Link copied to clipboard
Link copied to clipboard

Timeout value for an infinite task that will run forever.

Link copied to clipboard
protected val opMode: BunyipsOpMode
Link copied to clipboard

Whether the task is finished or not via timeout or custom condition. Will be true regardless of the finisher being fired or not, as some tasks will handle this via finishNow().

Link copied to clipboard
open var timeout: Measure<Time>

Functions

Link copied to clipboard
protected open fun init()
Define code to run once, when the task is started.
Link copied to clipboard
protected open fun onFinish()
Finalising function to run once the task is finished.
Link copied to clipboard
protected open fun periodic()
To run as an active loop during this task's duration.

Inherited functions

Link copied to clipboard
fun finish()

Tell a task to finish on the next iteration.

Link copied to clipboard
fun finishNow()

Force a task to finish immediately, and fire the onFinish() method without waiting for the next polling loop. This method is useful when your task needs to die and needs to finish up immediately. If your finisher has already been fired, this method will do nothing but ensure that the task is marked as finished.

Link copied to clipboard

Time in seconds since the task was started.

Link copied to clipboard

Get the subsystem reference that this task has elected a dependency on. Will return an Optional where if it is not present, this task is not dependent on any subsystem.

Link copied to clipboard

Return whether this task has elected a dependency on a subsystem or not.

Link copied to clipboard

Query (but not update) the finished state of the task. This will return true if the task is finished and the finisher has been fired.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
protected fun isTaskFinished(): Boolean
Return a boolean to this method to add custom criteria if a task should be considered finished.
protected abstract fun isTaskFinished(): Boolean

Return a boolean to this method to add custom criteria if a task should be considered finished.

Link copied to clipboard
protected open fun onInterrupt()

Finalising function that will be called after onFinish in the event this task is finished via a call to finish or finishNow. Override to add your own callback.

Link copied to clipboard
protected open fun onReset()

Called when the task is resetting now. Override this method to add custom reset behaviour, such as resetting any internal state variables such as iterators or lists.

Link copied to clipboard
open fun onSubsystem(subsystem: BunyipsSubsystem, override: Boolean): Task

Set the subsystem you want to elect this task to run on, notifying the runner that this task should run there.

Link copied to clipboard

Update and query the state of the task if it is finished. This will return true if the task is finished and the finisher has been fired.

Link copied to clipboard
fun reset()

Reset a task to an uninitialised and unfinished state. Will no-op if the task is already fully reset.

Link copied to clipboard
abstract fun run()

fun run()

Should be called by your polling loop to run the task and manage all state properly.

Link copied to clipboard

Get the name of this task. By default, it will be the class simple name, but you can call withName to set a custom name.

Link copied to clipboard

Get a verbose string representation of this task, including all of its properties.

Link copied to clipboard

Mute task reports from the Scheduler.

Link copied to clipboard
open fun withName(name: String): Task

Set the name of this task to be displayed in the OpMode. You may override this method if required to enforce a naming convention/prefix.

Link copied to clipboard
fun withTimeout(timeout: Measure<Time>): Task

Set the timeout of this task dynamically and return the task.