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

public abstract class Trajectory<SampleType extends TrajectorySample> extends Object
Represents a trajectory consisting of a list of TrajectorySamples, kinematically interpolating between them.
  • Field Details

    • samples

      protected final List<SampleType extends TrajectorySample> samples
      The samples this Trajectory is composed of.
    • duration

      public final double duration
      The total duration of the trajectory.
  • Constructor Details

    • Trajectory

      public Trajectory(SampleType[] samples)
      Constructs a Trajectory.
      Parameters:
      samples - the samples of the trajectory. Order does not matter as they will be ordered internally.
    • Trajectory

      public Trajectory(List<SampleType> samples)
      Constructs a Trajectory.
      Parameters:
      samples - the samples of the trajectory. Order does not matter as they will be ordered internally.
  • Method Details

    • getSamples

      public List<SampleType> getSamples()
      Gets the samples of the trajectory.
      Returns:
      the samples of the trajectory as an unmodifiable list.
    • interpolate

      public abstract SampleType interpolate(SampleType start, SampleType end, double t)
      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

      public SampleType start()
      Gets the first sample in the trajectory.
      Returns:
      the first sample in the trajectory.
    • end

      public SampleType end()
      Gets the last sample in the trajectory.
      Returns:
      the last sample in the trajectory.
    • sampleAt

      public SampleType sampleAt(Time time)
      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

      public SampleType sampleAt(double time)
      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

      public abstract Trajectory<SampleType> transformBy(Transform2d transform)
      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

      public abstract Trajectory<SampleType> concatenate(Trajectory<SampleType> other)
      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

      public abstract Trajectory<SampleType> relativeTo(Pose2d other)
      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.