Class AutoTrajectory

java.lang.Object
choreo.auto.AutoTrajectory

public class AutoTrajectory extends Object
A class that represents a trajectory that can be used in an autonomous routine and have triggers based off of it.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.wpilib.command2.button.Trigger
    Returns a trigger that is true while the trajectory is scheduled.
    org.wpilib.command2.button.Trigger
    atPose(String eventName, double toleranceMeters, double toleranceRadians)
    Returns a trigger that is true when the robot is within toleranceMeters and toleranceRadians of the given event's pose.
    org.wpilib.command2.button.Trigger
    atPose(org.wpilib.math.geometry.Pose2d pose, double toleranceMeters, double toleranceRadians)
    Returns a trigger that is true when the robot is within toleranceMeters of the given pose.
    org.wpilib.command2.button.Trigger
    atTime(double timeSinceStart)
    Returns a trigger that will go true for 1 cycle when the desired time has elapsed
    org.wpilib.command2.button.Trigger
    atTime(String eventName)
    Returns a trigger that is true when the event with the given name has been reached based on time.
    org.wpilib.command2.button.Trigger
    atTimeBeforeEnd(double timeBeforeEnd)
    Returns a trigger that will go true for 1 cycle when the desired before the end of the trajectory time.
    org.wpilib.command2.button.Trigger
    atTranslation(String eventName, double toleranceMeters)
    Returns a trigger that is true when the robot is within toleranceMeters and toleranceRadians of the given event's translation.
    org.wpilib.command2.button.Trigger
    atTranslation(org.wpilib.math.geometry.Translation2d translation, double toleranceMeters)
    Returns a trigger that is true when the robot is within toleranceMeters of the given translation.
    void
    chain(AutoTrajectory otherTrajectory)
    A shorthand for `.done().onTrue(otherTrajectory.cmd())`
    org.wpilib.command2.Command
    cmd()
    Creates a command that allocates the drive subsystem and follows the trajectory using the factories control function
    org.wpilib.math.geometry.Pose2d[]
    Returns an array of all the poses of the events with the given name.
    double[]
    Returns an array of all the timestamps of the events with the given name.
    org.wpilib.command2.button.Trigger
    Returns a trigger that is true after the trajectory completes.
    org.wpilib.command2.button.Trigger
    doneDelayed(double seconds)
    Returns a trigger that becomes true after the trajectory completes and the given delay.
    org.wpilib.command2.button.Trigger
    doneFor(double seconds)
    Returns a trigger that remains true for the given duration after completion.
    boolean
     
    Optional<org.wpilib.math.geometry.Pose2d>
    Will get the ending pose of the trajectory.
    Optional<org.wpilib.math.geometry.Pose2d>
    Will get the starting pose of the trajectory.
    <SampleType extends TrajectorySample<SampleType>>
    Trajectory<SampleType>
    Will get the underlying Trajectory object.
    org.wpilib.command2.button.Trigger
    Returns a trigger that is true while the command is not scheduled.
    <SampleType extends TrajectorySample<SampleType>>
    AutoTrajectory
    Returns this auto trajectory, mirrored to the other alliance.
    <SampleType extends TrajectorySample<SampleType>>
    AutoTrajectory
    Returns this auto trajectory, mirrored left-to-right from the driver's perspective.
    org.wpilib.command2.button.Trigger
    Returns a trigger that remains true after completion until the routine becomes idle.
    org.wpilib.command2.Command
    Creates a command that resets the robot's odometry to the start of this trajectory.
    <SampleType extends TrajectorySample<SampleType>>
    AutoTrajectory
    Returns this auto trajectory, rotated 180 degrees around the field center.
    org.wpilib.command2.Command
    Creates a command that will schedule another command that will follow the trajectory.

    Methods inherited from class Object

    clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • cmd

      public org.wpilib.command2.Command cmd()
      Creates a command that allocates the drive subsystem and follows the trajectory using the factories control function
      Returns:
      The command that will follow the trajectory
    • spawnCmd

      public org.wpilib.command2.Command spawnCmd()
      Creates a command that will schedule another command that will follow the trajectory.

      This can be useful when putting AutoTrajectory commands in sequences that require subsystems also required by in AutoTrajectory-bound subsystems.

      Returns:
      The command that will schedule the trajectory following command.
    • resetOdometry

      public org.wpilib.command2.Command resetOdometry()
      Creates a command that resets the robot's odometry to the start of this trajectory.
      Returns:
      A command that resets the robot's odometry.
    • getRawTrajectory

      public <SampleType extends TrajectorySample<SampleType>> Trajectory<SampleType> getRawTrajectory()
      Will get the underlying Trajectory object.

      WARNING: This method is not type safe and should be used with caution. The sample type of the trajectory should be known before calling this method.

      Type Parameters:
      SampleType - The type of the trajectory samples.
      Returns:
      The underlying Trajectory object.
    • mirrorX

      public <SampleType extends TrajectorySample<SampleType>> AutoTrajectory mirrorX()
      Returns this auto trajectory, mirrored to the other alliance.
      Type Parameters:
      SampleType - The type of the trajectory samples. Due to Java limitations, you have to specify the sample type again here even if it was already specified when creating the AutoTrajectory.
      Returns:
      this auto trajectory, mirrored to the other alliance.
    • mirrorY

      public <SampleType extends TrajectorySample<SampleType>> AutoTrajectory mirrorY()
      Returns this auto trajectory, mirrored left-to-right from the driver's perspective.
      Type Parameters:
      SampleType - The type of the trajectory samples. Due to Java limitations, you have to specify the sample type again here even if it was already specified when creating the AutoTrajectory.
      Returns:
      this auto trajectory, mirrored left-to-right from the driver's perspective.
    • rotateAround

      public <SampleType extends TrajectorySample<SampleType>> AutoTrajectory rotateAround()
      Returns this auto trajectory, rotated 180 degrees around the field center.
      Type Parameters:
      SampleType - The type of the trajectory samples. Due to Java limitations, you have to specify the sample type again here even if it was already specified when creating the AutoTrajectory.
      Returns:
      this auto trajectory, rotated 180 degrees around the field center.
    • getInitialPose

      public Optional<org.wpilib.math.geometry.Pose2d> getInitialPose()
      Will get the starting pose of the trajectory.

      This position is flipped if alliance flipping is enabled and the alliance supplier returns Red.

      This method returns an empty Optional if the trajectory is empty. This method returns an empty Optional if alliance flipping is enabled and the alliance supplier returns an empty Optional.

      Returns:
      The starting pose
    • getFinalPose

      public Optional<org.wpilib.math.geometry.Pose2d> getFinalPose()
      Will get the ending pose of the trajectory.

      This position is flipped if alliance flipping is enabled and the alliance supplier returns Red.

      This method returns an empty Optional if the trajectory is empty. This method returns an empty Optional if alliance flipping is enabled and the alliance supplier returns an empty Optional.

      Returns:
      The starting pose
    • active

      public org.wpilib.command2.button.Trigger active()
      Returns a trigger that is true while the trajectory is scheduled.
      Returns:
      A trigger that is true while the trajectory is scheduled.
    • inactive

      public org.wpilib.command2.button.Trigger inactive()
      Returns a trigger that is true while the command is not scheduled.

      The same as calling active().negate().

      Returns:
      A trigger that is true while the command is not scheduled.
    • done

      public org.wpilib.command2.button.Trigger done()
      Returns a trigger that is true after the trajectory completes.
      Returns:
      a trigger that is true after the trajectory completes
    • doneDelayed

      public org.wpilib.command2.button.Trigger doneDelayed(double seconds)
      Returns a trigger that becomes true after the trajectory completes and the given delay.
      Parameters:
      seconds - the delay after completion, in seconds
      Returns:
      a trigger that is true after the trajectory completes and the given delay
    • doneFor

      public org.wpilib.command2.button.Trigger doneFor(double seconds)
      Returns a trigger that remains true for the given duration after completion.
      Parameters:
      seconds - the duration for which the trigger remains true, in seconds
      Returns:
      a trigger that remains true for the given duration after completion
    • recentlyDone

      public org.wpilib.command2.button.Trigger recentlyDone()
      Returns a trigger that remains true after completion until the routine becomes idle.
      Returns:
      a trigger that remains true after completion until the routine becomes idle
    • chain

      public void chain(AutoTrajectory otherTrajectory)
      A shorthand for `.done().onTrue(otherTrajectory.cmd())`
      Parameters:
      otherTrajectory - The other trajectory to run when this one is done.
    • atTime

      public org.wpilib.command2.button.Trigger atTime(double timeSinceStart)
      Returns a trigger that will go true for 1 cycle when the desired time has elapsed
      Parameters:
      timeSinceStart - The time since the command started in seconds.
      Returns:
      A trigger that is true when timeSinceStart has elapsed.
    • atTimeBeforeEnd

      public org.wpilib.command2.button.Trigger atTimeBeforeEnd(double timeBeforeEnd)
      Returns a trigger that will go true for 1 cycle when the desired before the end of the trajectory time.
      Parameters:
      timeBeforeEnd - The time before the end of the trajectory.
      Returns:
      A trigger that is true when timeBeforeEnd has elapsed.
    • atTime

      public org.wpilib.command2.button.Trigger atTime(String eventName)
      Returns a trigger that is true when the event with the given name has been reached based on time.

      A warning will be printed to the DriverStation if the event is not found and the trigger will always be false.

      Parameters:
      eventName - The name of the event.
      Returns:
      A trigger that is true when the event with the given name has been reached based on time.
      See Also:
    • atPose

      public org.wpilib.command2.button.Trigger atPose(org.wpilib.math.geometry.Pose2d pose, double toleranceMeters, double toleranceRadians)
      Returns a trigger that is true when the robot is within toleranceMeters of the given pose.

      The pose is flipped if alliance flipping is enabled and the alliance supplier returns Red.

      While alliance flipping is enabled and the alliance supplier returns empty, the trigger will return false.

      Parameters:
      pose - The pose to check against, unflipped.
      toleranceMeters - The tolerance in meters.
      toleranceRadians - The heading tolerance in radians.
      Returns:
      A trigger that is true when the robot is within toleranceMeters of the given pose.
    • atPose

      public org.wpilib.command2.button.Trigger atPose(String eventName, double toleranceMeters, double toleranceRadians)
      Returns a trigger that is true when the robot is within toleranceMeters and toleranceRadians of the given event's pose.

      A warning will be printed to the DriverStation if the event is not found and the trigger will always be false.

      Parameters:
      eventName - The name of the event.
      toleranceMeters - The tolerance in meters.
      toleranceRadians - The heading tolerance in radians.
      Returns:
      A trigger that is true when the robot is within toleranceMeters of the given events pose.
      See Also:
    • atTranslation

      public org.wpilib.command2.button.Trigger atTranslation(org.wpilib.math.geometry.Translation2d translation, double toleranceMeters)
      Returns a trigger that is true when the robot is within toleranceMeters of the given translation.

      The translation is flipped if alliance flipping is enabled and the alliance supplier returns Red.

      While alliance flipping is enabled and the alliance supplier returns empty, the trigger will return false.

      Parameters:
      translation - The translation to check against, unflipped.
      toleranceMeters - The tolerance in meters.
      Returns:
      A trigger that is true when the robot is within toleranceMeters of the given translation.
    • atTranslation

      public org.wpilib.command2.button.Trigger atTranslation(String eventName, double toleranceMeters)
      Returns a trigger that is true when the robot is within toleranceMeters and toleranceRadians of the given event's translation.

      A warning will be printed to the DriverStation if the event is not found and the trigger will always be false.

      Parameters:
      eventName - The name of the event.
      toleranceMeters - The tolerance in meters.
      Returns:
      A trigger that is true when the robot is within toleranceMeters of the given events translation.
      See Also:
    • collectEventTimes

      public double[] collectEventTimes(String eventName)
      Returns an array of all the timestamps of the events with the given name.
      Parameters:
      eventName - The name of the event.
      Returns:
      An array of all the timestamps of the events with the given name.
      See Also:
    • collectEventPoses

      public org.wpilib.math.geometry.Pose2d[] collectEventPoses(String eventName)
      Returns an array of all the poses of the events with the given name.

      The returned poses are always unflipped. If you use them in a trigger like `atPose` or `atTranslation`, the library will automatically flip them if necessary. If you intend using them in a different context, you can use ChoreoAllianceFlipUtil.flip(Translation2d) to flip them.

      Parameters:
      eventName - The name of the event.
      Returns:
      An array of all the poses of the events with the given name.
      See Also:
    • equals

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