Class Trajectory<SampleType extends TrajectorySample<SampleType>>

java.lang.Object
choreo.trajectory.Trajectory<SampleType>
Type Parameters:
SampleType - DifferentialSample or SwerveSample.

public class Trajectory<SampleType extends TrajectorySample<SampleType>> extends Object
A trajectory loaded from Choreo.
  • Constructor Details

    • Trajectory

      public Trajectory(String name, List<SampleType> samples, List<Integer> splits, List<EventMarker> events)
      Constructs a Trajectory with the specified parameters.
      Parameters:
      name - The name of the trajectory.
      samples - The samples of the trajectory.
      splits - The indices of the splits in the trajectory.
      events - The events in the trajectory.
  • Method Details

    • name

      public String name()
      Returns the name of the trajectory.
      Returns:
      the name of the trajectory.
    • samples

      public List<SampleType> samples()
      Returns the samples of the trajectory.
      Returns:
      the samples of the trajectory.
    • splits

      public List<Integer> splits()
      Returns the indices of the splits in the trajectory.
      Returns:
      the indices of the splits in the trajectory.
    • events

      public List<EventMarker> events()
      Returns the events in the trajectory.
      Returns:
      the events in the trajectory.
    • getInitialSample

      public SampleType getInitialSample(boolean mirrorForRedAlliance)
      Returns the first Trajectory in the trajectory.

      NULL SAFETY: This function will return null if the trajectory is empty.

      Parameters:
      mirrorForRedAlliance - whether or not to return the sample as mirrored across the field
      Returns:
      The first Trajectory in the trajectory.
    • getFinalSample

      public SampleType getFinalSample(boolean mirrorForRedAlliance)
      Returns the last Trajectory in the trajectory.

      NULL SAFETY: This function will return null if the trajectory is empty.

      Parameters:
      mirrorForRedAlliance - whether or not to return the sample as mirrored across the field
      Returns:
      The last Trajectory in the trajectory.
    • sampleAt

      public SampleType sampleAt(double timestamp, boolean mirrorForRedAlliance)
      Return an interpolated sample of the trajectory at the given timestamp.

      NULL SAFETY: This function will return null if the trajectory is empty.

      Parameters:
      timestamp - The timestamp of this sample relative to the beginning of the trajectory.
      mirrorForRedAlliance - whether or not to return the sample as mirrored across the field midline (as in 2023).
      Returns:
      The SampleType at the given time.
    • getInitialPose

      public Pose2d getInitialPose(boolean mirrorForRedAlliance)
      Returns the initial pose of the trajectory.

      NULL SAFETY: This function will return null if the trajectory is empty.

      Parameters:
      mirrorForRedAlliance - whether or not to return the pose as mirrored across the field
      Returns:
      the initial pose of the trajectory.
    • getFinalPose

      public Pose2d getFinalPose(boolean mirrorForRedAlliance)
      Returns the final pose of the trajectory.

      NULL SAFETY: This function will return null if the trajectory is empty.

      Parameters:
      mirrorForRedAlliance - whether or not to return the pose as mirrored across the field
      Returns:
      the final pose of the trajectory.
    • getTotalTime

      public double getTotalTime()
      Returns the total time of the trajectory (the timestamp of the last sample)
      Returns:
      the total time of the trajectory (the timestamp of the last sample)
    • getPoses

      public Pose2d[] getPoses()
      Returns the array of poses corresponding to the trajectory.
      Returns:
      the array of poses corresponding to the trajectory.
    • sampleArray

      public SampleType[] sampleArray()
      Returns an array of samples
      Returns:
      an array of samples
    • flipped

      Returns this trajectory, mirrored across the field midline.
      Returns:
      this trajectory, mirrored across the field midline.
    • getEvents

      public List<EventMarker> getEvents(String eventName)
      Returns a list of all events with the given name in the trajectory.
      Parameters:
      eventName - The name of the event.
      Returns:
      A list of all events with the given name in the trajectory, if no events are found, an empty list is returned.
    • getSplit

      public Optional<Trajectory<SampleType>> getSplit(int splitIndex)
      Returns a choreo trajectory that represents the split of the trajectory at the given index.
      Parameters:
      splitIndex - the index of the split trajectory to return.
      Returns:
      a choreo trajectory that represents the split of the trajectory at the given index.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object