Class Trajectory<SampleType extends TrajectorySample>
java.lang.Object
org.wpilib.math.trajectory.Trajectory<SampleType>
- Type Parameters:
SampleType- The type of the samples in the trajectory.
- Direct Known Subclasses:
DifferentialTrajectory, DrivetrainSplineTrajectory, HolonomicTrajectory
Represents a trajectory consisting of a list of
TrajectorySamples, kinematically
interpolating between them.-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal doubleThe total duration of the trajectory.protected final List<SampleType> The samples this Trajectory is composed of. -
Constructor Summary
ConstructorsConstructorDescriptionTrajectory(List<SampleType> samples) Constructs a Trajectory.Trajectory(SampleType[] samples) Constructs a Trajectory. -
Method Summary
Modifier and TypeMethodDescriptionabstract Trajectory<SampleType> concatenate(Trajectory<SampleType> other) Concatenates this trajectory with another trajectory.end()Gets the last sample in the trajectory.Gets the samples of the trajectory.abstract SampleTypeinterpolate(SampleType start, SampleType end, double t) Interpolates between two samples.abstract Trajectory<SampleType> relativeTo(Pose2d other) Returns a new trajectory that is relative to the given pose.sampleAt(double time) Gets the sample at the given time.Gets the sample at the given time.start()Gets the first sample in the trajectory.abstract Trajectory<SampleType> transformBy(Transform2d transform) Transforms all poses in the trajectory by the given transform.
-
Field Details
-
samples
The samples this Trajectory is composed of. -
duration
public final double durationThe total duration of the trajectory.
-
-
Constructor Details
-
Trajectory
Constructs a Trajectory.- Parameters:
samples- the samples of the trajectory. Order does not matter as they will be ordered internally.
-
Trajectory
Constructs a Trajectory.- Parameters:
samples- the samples of the trajectory. Order does not matter as they will be ordered internally.
-
-
Method Details
-
getSamples
Gets the samples of the trajectory.- Returns:
- the samples of the trajectory as an unmodifiable list.
-
interpolate
Interpolates between two samples. This method must be implemented by subclasses to provide drivetrain-specific interpolation logic.- Parameters:
start- The starting sample.end- The ending sample.t- The interpolation parameter between 0 and 1.- Returns:
- The interpolated sample.
-
start
Gets the first sample in the trajectory.- Returns:
- the first sample in the trajectory.
-
end
Gets the last sample in the trajectory.- Returns:
- the last sample in the trajectory.
-
sampleAt
Gets the sample at the given time.- Parameters:
time- the time since the beginning of the trajectory to sample.- Returns:
- the sample at that point in time.
-
sampleAt
Gets the sample at the given time.- Parameters:
time- the time since the beginning of the trajectory to sample, in seconds.- Returns:
- the sample at that point in time.
-
transformBy
Transforms all poses in the trajectory by the given transform. This is useful for converting a robot-relative trajectory into a field-relative trajectory. This works with respect to the first pose in the trajectory.- Parameters:
transform- The transform to transform the trajectory by.- Returns:
- The transformed trajectory.
-
concatenate
Concatenates this trajectory with another trajectory. If the other trajectory is empty, this trajectory is returned. To work correctly, the other trajectory should start at the end of this trajectory.- Parameters:
other- the other trajectory to concatenate with this one.- Returns:
- a new trajectory that is the concatenation of this trajectory and the other trajectory.
-
relativeTo
Returns a new trajectory that is relative to the given pose. This is useful for converting a field-relative trajectory into a robot-relative trajectory. The returned trajectory will have the same times, velocities, and accelerations as the original trajectory, but the poses will be relative to the given pose.- Parameters:
other- the pose to which the trajectory should be relative. This is typically the robot's starting pose.- Returns:
- a new trajectory that is relative to the given pose.
-