Class Task

java.lang.Object
com.cdarobotics.cdalib.tasks.Task
Direct Known Subclasses:
BasicTask, DeadlineTask, DeferredTask, FollowPathTask, HoldPointTask, InstantTask, NullTask, ParallelTask, RaceTask, RepeatTask, SequentialTask, SleepTask, WaitUntilTask

public abstract class Task extends Object
Base type for all actions in the task framework. A task is initialized once via init(), then run() is polled every loop until it returns true to signal completion.

Tasks compose into larger behaviors through the fluent builders:

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    alongWith(Task... others)
    Runs this task in parallel with the given tasks, finishing once all of them finish.
    andThen(Task... next)
    Runs this task, then the given tasks one after another.
    abstract void
    Called once before the first run().
    raceWith(Task... others)
    Runs this task in parallel with the given tasks, finishing as soon as any one finishes.
    abstract boolean
    run()
    Called every loop after init().
    abstract String
     
    withDeadline(Task deadline)
    Runs this task until deadline finishes, then stops regardless of this task's state.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Task

      public Task()
  • Method Details

    • init

      public abstract void init()
      Called once before the first run(). Set up state and issue starting commands here.
    • run

      public abstract boolean run()
      Called every loop after init().
      Returns:
      true when the task is finished, false to keep running.
    • toString

      @NonNull public abstract String toString()
      Overrides:
      toString in class Object
    • andThen

      public Task andThen(Task... next)
      Runs this task, then the given tasks one after another.
    • alongWith

      public Task alongWith(Task... others)
      Runs this task in parallel with the given tasks, finishing once all of them finish.
    • raceWith

      public Task raceWith(Task... others)
      Runs this task in parallel with the given tasks, finishing as soon as any one finishes.
    • withDeadline

      public Task withDeadline(Task deadline)
      Runs this task until deadline finishes, then stops regardless of this task's state.