The Trajectory
system lies at the very heart of Pathfinder's movement. The
concept of a Trajectory
is relatively simple - it's a movement-oriented and
stateful object that guides your robot along a certain path at a certain speed.
Well, it guides your robot along a specified path at a specified speed. The
Trajectory
interface is extremely minimal and it only has three methods:
PointXYZ nextMarker(PointXYZ current)
boolean isDone(PointXYZ current)
double speed(PointXYZ current)
Each of those methods accepts a single PointXYZ
parameter, representing the
robot's current position. Based on the robot's position, the Trajectory
should be capable of instructing the robot on what to do next.
Through Follower
s. Beyond the Follower
interface, you won't need to know
much about how Pathfinder actually follows trajectories - if you're curious,
check out FollowerExecutor
.
In order for Pathfinder to be able to follow a Trajectory
, you need to use a
Follower
. As the name would suggest, a Follower
... well, it follows a
trajectory, of course!
I can't think of any reasons you'd want to use a Follower
implementation
other than the default GenericFollower
, but you have the option to do so if
you so desire.
Followers are executed with follower executors. I genuinely cannot conceive a
single reason why you'd ever need to know how a FollowerExecutor
works, but
you can feel free to check out the FollowerExecutor
class.
Several implementations of the Trajectory
interface are provided within
Pathfinder.
LinearTrajectory
: The simplest trajectory implementation. Moves to a single point at a linear speed. This will dynamically correct for any movement error.MutableLinearTrajectory
: Just likeLinearTrajectory
, but it's mutable - that's really all I can say.FastTrajectory
: Similar toLinearTrajectory
in the sense that it moves to a single target point at a linear speed, butFastTrajectory
will correct if it overshoots the target. Additionally,FastTrajectory
does not require the robot's heading to be correct in order for the trajectory to be finished.TimedTrajectory
: A trajectory with time constraints.TaskTrajectory
: A trajectory that executes an action not related to movement.SplineTrajectory
: A trajectory that utilizes aSpline
to guide the robot.AdvancedSplineTrajectory
: The most advanced form ofTrajectory
provided in Pathfinder,AdvancedSplineTrajectory
has separate spline interpolation functions responsible for controlling the trajectory's X/Y target, desired heading, and even speed.ArcTrajectory
: A trajectory based onCircle
that follows an arc.EmptyTrajectory
: A trajectory that does absolutely nothing.ControlledTrajectory
: A trajectory that utilizes aController
to determine speed.MultiSegmentTrajectory
: ATrajectory
composed of several other trajectories. Each of these trajectories will be executed sequentially.MultiTargetTrajectory
: Sort of like aMultiSegmentTrajectory
of many linear trajectories: aMultiTargetTrajectory
will guide the robot to a series of points.
There's a whole guide available here.