IncrementingTaskGroup

A group of tasks that is similar to a SequentialTaskGroup, but instead of queueing the next task after the previous one finishes, it queues the next task every time the task group is initialised.

The timeout of this group is calculated dynamically, based on the currently incremented task. This task retains information across resets and reinitialisation, wrapping around to the first task when the last task is reached and finished.

Author

Lucas Bubner, 2024

Since

7.0.0

Constructors

Link copied to clipboard
constructor(@NonNull tasks: Array<Task>)
Create a new IncrementingTaskGroup with tasks.
constructor(@NonNull tasks: List<Task>)
Create a new IncrementingTaskGroup with tasks.

Inherited properties

Link copied to clipboard
Link copied to clipboard
protected open var dashboard: TelemetryPacket

Convenience field to get a reference to a TelemetryPacket for sending telemetry to the dashboard. Available as soon as init has been called for this task.

Link copied to clipboard

Enabling will reject all future on calls. Useful for composing tasks that will internally re-schedule a wrapped Task.

Link copied to clipboard

Timeout value for an infinite task that will run forever.

Link copied to clipboard

Whether this task should override other tasks in the queue if they conflict with this task. Will only apply if this task has a dependency to run on (see dependency).

Link copied to clipboard
protected val tasks: ArrayList<Task>
Link copied to clipboard
open var timeout: Measure<Time>

Maximum timeout of the task. If set to 0 magnitude (or a timeout-less constructor) this will serve as an indefinite task, and will only finish when isTaskFinished returns true, or this task is manually interrupted via finish/finishNow.

Functions

Link copied to clipboard
open fun increment()
Increment this task group.
Link copied to clipboard
fun init()
Define code to run once, when the task is started.
Link copied to clipboard
protected open fun isTaskFinished(): Boolean
Return a boolean to this method to add custom criteria if a task should be considered finished.
Link copied to clipboard
fun periodic()
To run as an active loop during this task's duration.

Inherited functions

Link copied to clipboard
fun after(otherTasks: Array<Task>): SequentialTaskGroup

Compose this task into a SequentialTaskGroup with the supplied tasks to run before this one.

Link copied to clipboard
fun <T : Task?> cast(task: Task, cast: Class<T>): T

Utility to cast a task into the desired task class. Useful for ignoring task nullability to cast into a new type - ensure your task exists before calling.

Link copied to clipboard

Shorthand group utility for creating a DeadlineTaskGroup.

Link copied to clipboard
fun defer(taskBuilder: () -> out Task): DeferredTask

Constructor utility to create a new DeferredTask based on the supplied task builder.

Link copied to clipboard
fun during(otherTasks: Array<Task>): DeadlineTaskGroup

Compose this task into a DeadlineTaskGroup with the supplied tasks to run these extra tasks until this task is done.

Link copied to clipboard
fun execute()

Scheduling method that will either attach this task to a subsystem or run it as part of the standard run method. This is the recommended way to run a task as it will attempt to run on the context as provided by the dependency.

Link copied to clipboard
protected fun executeTask(@NonNull task: Task)
Link copied to clipboard
fun finish()

Tell a task to finish on the next iteration of poll.

Link copied to clipboard
protected fun finishAllTasks()
Link copied to clipboard
fun finishNow()

Force a task to finish immediately, and fire the onFinish method without waiting for the next polling loop.

Link copied to clipboard

Composes a ParallelTaskGroup with a WaitTask to run before this task. This will ensure the task runs for at least the specified time, and no-ops until the duration if it finishes early.

Link copied to clipboard
protected fun getDashboard(): TelemetryPacket

Convenience field to get a reference to a TelemetryPacket for sending telemetry to the dashboard. Available as soon as init has been called for this task.

Link copied to clipboard

Time 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
Link copied to clipboard

Shorthand group utility for creating a IncrementingTaskGroup.

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

Whether the task is currently running (i.e. has been started (init called) and not finished).

Link copied to clipboard
fun loop(function: Runnable): DynamicTask

Utility for creating a DynamicTask that will loop some function until the task is manually finished.

Link copied to clipboard

Creates a new DynamicTask instance by wrapping this existing Task instance, allowing you to add new functionality to a task without modifying the original task.

Link copied to clipboard
open fun named(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. Null values are ignored.

Link copied to clipboard

Compose this task into a IncrementingTaskGroup with the supplied tasks to run the next task in sequence after the previous one finishes, while looping back to the first task.

Link copied to clipboard
fun on(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
protected open fun onFinish()

Finalising function to run once the task is finished. This will always run regardless of whether the task was ended because of an interrupt or the task naturally finishing. Override to add your own callback.

protected fun onFinish()
Finalising function to run once the task is 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.

protected open fun onReset()
Called when the task is resetting now.
Link copied to clipboard

Shorthand group utility for creating a ParallelTaskGroup.

Link copied to clipboard
fun poll(): Boolean

Update and query the state of the task if it is finished. This will return true if the task is fully completed with all callbacks processed.

Link copied to clipboard
fun preview(fieldOverlay: Canvas)

RoadRunner Action implementation to preview the action on the field overlay. This method no-ops as previews are done via DualTelemetry and the Drawing util.

open fun preview(fieldOverlay: Canvas)
Link copied to clipboard
fun race(otherTasks: Array<Task>): RaceTaskGroup

Compose this task into a RaceTaskGroup with the supplied tasks to run all of these tasks until one finishes.

Link copied to clipboard
fun rce(tasks: Array<Task>): RaceTaskGroup

Shorthand group utility for creating a RaceTaskGroup.

Link copied to clipboard

Wrap this task in a RepeatTask where finish conditions are reset immediately.

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
fun run()

Execute one cycle of this task. The finish condition is separately polled in the poll method.

fun run(p: TelemetryPacket): Boolean

RoadRunner Action implementation to run this Task.

abstract fun run(p: TelemetryPacket): Boolean
abstract fun run()
Link copied to clipboard
fun runFor(time: Measure<Time>, function: Runnable): DynamicTask

Utility for creating a DynamicTask that will loop some function for some time.

Link copied to clipboard

Shorthand group utility for creating a SequentialTaskGroup.

Link copied to clipboard

Attempts to assign this task as the default task of the current dependency.

Link copied to clipboard
protected fun setDashboard(<set-?>: TelemetryPacket)

Convenience field to get a reference to a TelemetryPacket for sending telemetry to the dashboard. Available as soon as init has been called for this task.

Link copied to clipboard
protected open fun setTasks(@NonNull tasks: List<Task>)
Link copied to clipboard

Utility to create a new DynamicTask instance for building a new task.

Link copied to clipboard
fun then(otherTasks: Array<Task>): SequentialTaskGroup

Compose this task into a SequentialTaskGroup with the supplied tasks to follow after this one.

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

Set the timeout of this task dynamically and return the task. Null values are ignored.

Link copied to clipboard

Get the name of this task. By default, it will be the class simple name, but you can call named 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

Compose this task into a RaceTaskGroup with a wait condition based on this condition.

Link copied to clipboard

Utility for creating a DynamicTask that will wait for some condition and finish when the condition is true.

Link copied to clipboard
fun with(otherTasks: Array<Task>): ParallelTaskGroup

Compose this task into a ParallelTaskGroup with the supplied tasks to run all of these tasks at once.