File-By-File
TaskTrajectory

TaskTrajectory

A task-oriented Trajectory interface that does not require the robot to move. Instead, a TaskTrajectory instructs the robot to perform a task and will block Pathfinder's queue until that task is completed. This makes it easier to create simple autonomous programs.

Key Concepts

  • Task-Oriented: Focuses on executing a Runnable task rather than moving the robot to a specific point.
  • Blocking: While active, a TaskTrajectory will prevent other trajectories in the queue from executing until its task is complete.
  • Lifecycle Callbacks: Provides initial, during, and onFinish Runnables for different stages of the task execution.
  • Time Constraints: Can be configured with minimum and maximum execution times.

Fields

initial

A Runnable to be executed once, the first time the trajectory's isDone(PointXYZ) method is called.

during

A Runnable to be executed repeatedly every time the trajectory's isDone(PointXYZ) method is called (while the task is active).

onFinish

A Runnable to be executed once, when the task is finished.

isFinished

A Supplier<Boolean> that indicates whether the task is finished. The trajectory will continue to execute until this supplier returns true.

minTimeMs

The minimum time, in milliseconds, the trajectory will be active for.

maxTimeMs

The maximum time, in milliseconds, the trajectory will be active for.

timer

An ElapsedTimer used to track the duration of the task.

hasExecuted

A boolean flag indicating whether the initial runnable has been executed.

hasFinished

A boolean flag indicating whether the onFinish runnable has been executed.

speed

The speed at which the robot should move during this trajectory. For a TaskTrajectory, this is typically 0 as the robot is performing a task rather than moving.

Methods

TaskTrajectory(Runnable initial, Runnable during, Runnable onFinish, Supplier<Boolean> isFinished, double minTimeMs, double maxTimeMs)

Constructs a new TaskTrajectory with full control over its lifecycle and time constraints.

TaskTrajectory(Runnable initial, Runnable during, Runnable onFinish, Supplier<Boolean> isFinished, double maxTimeMs)

Constructs a new TaskTrajectory with a default minTimeMs of 0.

setSpeed(double speed)

Sets the speed for this trajectory. Returns this for method chaining.

nextMarker(PointXYZ current)

Always returns the current PointXYZ, indicating that the robot should not move during this task.

isDone(PointXYZ current)

Determines if the task is complete. It checks the isFinished supplier and also considers the minTimeMs and maxTimeMs constraints. It executes the initial runnable once, the during runnable repeatedly, and the onFinish runnable once when the task is truly finished.

speed(PointXYZ current)

Returns the configured speed for this trajectory.

end()

Immediately ends the trajectory by forcing the isFinished supplier to return true.

toString()

Returns a string representation of the TaskTrajectory, including its minimum and maximum time constraints.