Class DifferentialTrajectory

java.lang.Object
org.wpilib.math.trajectory.Trajectory<DifferentialSample>
org.wpilib.math.trajectory.DifferentialTrajectory

public class DifferentialTrajectory extends Trajectory<DifferentialSample>
A trajectory for differential drive robots with drivetrain-specific interpolation.
  • Field Details

  • Constructor Details

    • DifferentialTrajectory

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

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

      public DifferentialTrajectory(DifferentialDriveKinematics kinematics, List<? extends HolonomicSample> samples)
      Constructs a DifferentialTrajectory.
      Parameters:
      kinematics - the kinematics of the drivetrain.
      samples - the samples of the trajectory. Order does not matter as they will be ordered internally.
  • Method Details

    • interpolate

      public DifferentialSample interpolate(DifferentialSample start, DifferentialSample end, double t)
      Interpolates between two samples using numerical integration of the differential drive differential equation.
      Specified by:
      interpolate in class Trajectory<DifferentialSample>
      Parameters:
      start - The starting sample.
      end - The ending sample.
      t - The interpolation parameter between 0 and 1.
      Returns:
      The interpolated sample.
    • transformBy

      public DifferentialTrajectory transformBy(Transform2d transform)
      Transforms all poses in the trajectory by the given transform.
      Specified by:
      transformBy in class Trajectory<DifferentialSample>
      Parameters:
      transform - The transform to apply to the trajectory.
      Returns:
      The transformed trajectory.
    • concatenate

      Concatenates this trajectory with another trajectory.
      Specified by:
      concatenate in class Trajectory<DifferentialSample>
      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 DifferentialTrajectory relativeTo(Pose2d other)
      Returns a new trajectory that is relative to the given pose.
      Specified by:
      relativeTo in class Trajectory<DifferentialSample>
      Parameters:
      other - the pose to which the trajectory should be relative.
      Returns:
      a new trajectory relative to the given pose.
    • loadFromStream

      public static DifferentialTrajectory loadFromStream(InputStream stream) throws IOException
      Loads a trajectory from a JSON stream.
      Parameters:
      stream - the stream to read from
      Returns:
      the deserialized trajectory
      Throws:
      IOException - if there's an error reading the file or parsing the JSON
    • loadFromFile

      public static DifferentialTrajectory loadFromFile(File file) throws IOException
      Loads a trajectory from a JSON file.
      Parameters:
      file - the file to read from
      Returns:
      the deserialized trajectory
      Throws:
      IOException - if there's an error reading the file or parsing the JSON
    • loadFromFile

      public static DifferentialTrajectory loadFromFile(String filename) throws IOException
      Loads a trajectory from a JSON file.
      Parameters:
      filename - the path to the file to read from
      Returns:
      the deserialized trajectory
      Throws:
      IOException - if there's an error reading the file or parsing the JSON