Class AutoRoutine

java.lang.Object
choreo.commands3.AutoRoutine
All Implemented Interfaces:
AutoCloseable, org.wpilib.opmode.OpMode

public class AutoRoutine extends Object implements org.wpilib.opmode.OpMode
An autonomous routine, which is an OpMode.

Instead of picking a routine from a chooser, register each routine as an autonomous opmode with AutoFactory.addRoutine(OpModeRobot, String, java.util.function.Consumer) and select it on the Driver Station:

factory.addRoutine(this, "Two Piece", routine -> {
  var first = routine.trajectory("first");
  var second = routine.trajectory("second");
  routine.active().onTrue(first.resetOdometry().andThen(first.cmd()).withAutomaticName());
  first.chain(second);
});

To use the @Autonomous annotation's description and colors, or to keep a routine in its own file, subclass instead. OpModeRobot constructs the class with the robot as its argument when the opmode is selected:

@Autonomous(name = "Two Piece", group = "Choreo")
public class TwoPiece extends AutoRoutine {
  public TwoPiece(Robot robot) {
    super(robot.autoFactory, "Two Piece");
    var first = trajectory("first");
    var second = trajectory("second");
    active().onTrue(first.resetOdometry().andThen(first.cmd()).withAutomaticName());
    first.chain(second);
  }
}

The routine is built each time its opmode is selected, never ahead of time. Commands v3 scopes the triggers and commands created while an opmode is selected to that opmode, so a routine needs no polling or killing of its own. Everything it bound goes away when the opmode ends. As a safeguard, the routine's own triggers (active(), idle(), observe(BooleanSupplier) and everything on AutoTrajectory) are also gated on the routine running.

See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AutoRoutine(AutoFactory factory, String name)
    Creates a new routine with a specific name.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.wpilib.command3.Trigger
    Returns a Trigger that is true while this routine is running, that is, from when its opmode starts until it ends or the robot is disabled.
    org.wpilib.command3.Trigger
    allInactive(AutoTrajectory trajectory, AutoTrajectory... trajectories)
    Creates a trigger that returns true when all of the trajectories given are inactive.
    org.wpilib.command3.Trigger
    anyActive(AutoTrajectory trajectory, AutoTrajectory... trajectories)
    Creates a trigger that returns true when any of the trajectories given are active.
    org.wpilib.command3.Trigger
    anyDone(AutoTrajectory trajectory, AutoTrajectory... trajectories)
    Creates a trigger that produces a rising edge when any of the trajectories are finished.
    org.wpilib.command3.Trigger
    anyDoneDelayed(double secondsToDelay, AutoTrajectory trajectory, AutoTrajectory... trajectories)
    Creates a trigger that produces a rising edge when any of the trajectories are finished.
    void
    end()
    Ends the routine.
    org.wpilib.command3.Trigger
    Creates a trigger that is true when the routine is idle.
    Gets the name of this routine.
    org.wpilib.command3.Trigger
    Creates a Trigger from a condition that is only true while this routine is running.
    void
    Starts the routine.
    <SampleType extends choreo.trajectory.TrajectorySample<SampleType>>
    AutoTrajectory
    trajectory(choreo.trajectory.Trajectory<SampleType> trajectory)
    Creates a new AutoTrajectory to be used in an auto routine.
    trajectory(String trajectoryName)
    Creates a new AutoTrajectory to be used in an auto routine.
    trajectory(String trajectoryName, int splitIndex)
    Creates a new AutoTrajectory to be used in an auto routine.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.wpilib.opmode.OpMode

    close, disabledPeriodic, getCallbacks, periodic
  • Constructor Details

    • AutoRoutine

      protected AutoRoutine(AutoFactory factory, String name)
      Creates a new routine with a specific name.

      Subclasses call this to define a routine as its own opmode class. Create the triggers and bindings in the subclass constructor, and register the class with @Autonomous or OpModeRobot.addOpMode. The framework then constructs it when the opmode is selected, which scopes what the constructor creates. Don't construct a subclass yourself ahead of time, such as in the robot constructor, as it would not be scoped.

      Parameters:
      factory - The factory used to create this routine's trajectories
      name - The name of the routine
      See Also:
  • Method Details

    • name

      public String name()
      Gets the name of this routine.
      Returns:
      The name of this routine.
    • active

      public org.wpilib.command3.Trigger active()
      Returns a Trigger that is true while this routine is running, that is, from when its opmode starts until it ends or the robot is disabled.

      This is the usual way to start the first command of a routine, such as routine.active().onTrue(...).

      Returns:
      A Trigger that is true while this routine is running.
    • observe

      public org.wpilib.command3.Trigger observe(BooleanSupplier condition)
      Creates a Trigger from a condition that is only true while this routine is running.
      Parameters:
      condition - The condition represented by the trigger.
      Returns:
      A Trigger that mirrors the state of the provided condition while the routine is active, and is false otherwise.
    • idle

      public org.wpilib.command3.Trigger idle()
      Creates a trigger that is true when the routine is idle.

      Idle is defined as the routine running with no trajectories made by it running.

      Returns:
      A trigger that is true when the routine is idle.
    • start

      public void start()
      Starts the routine. Called by the framework when the opmode is started.

      If the alliance is required for flipping and is not yet known, the routine does not start.

      Specified by:
      start in interface org.wpilib.opmode.OpMode
    • end

      public void end()
      Ends the routine. Called by the framework when the opmode ends.

      Trajectory commands notice the routine is no longer active and finish on their own.

      Specified by:
      end in interface org.wpilib.opmode.OpMode
    • trajectory

      public AutoTrajectory trajectory(String trajectoryName)
      Creates a new AutoTrajectory to be used in an auto routine.
      Parameters:
      trajectoryName - The name of the trajectory to use.
      Returns:
      A new AutoTrajectory.
    • trajectory

      public AutoTrajectory trajectory(String trajectoryName, int splitIndex)
      Creates a new AutoTrajectory to be used in an auto routine.
      Parameters:
      trajectoryName - The name of the trajectory to use.
      splitIndex - The index of the split trajectory to use.
      Returns:
      A new AutoTrajectory.
    • trajectory

      public <SampleType extends choreo.trajectory.TrajectorySample<SampleType>> AutoTrajectory trajectory(choreo.trajectory.Trajectory<SampleType> trajectory)
      Creates a new AutoTrajectory to be used in an auto routine.
      Type Parameters:
      SampleType - The type of the trajectory samples.
      Parameters:
      trajectory - The trajectory to use.
      Returns:
      A new AutoTrajectory.
    • anyDone

      public org.wpilib.command3.Trigger anyDone(AutoTrajectory trajectory, AutoTrajectory... trajectories)
      Creates a trigger that produces a rising edge when any of the trajectories are finished.
      Parameters:
      trajectory - The first trajectory to watch.
      trajectories - The other trajectories to watch
      Returns:
      a trigger that determines if any of the trajectories are finished
      See Also:
    • anyDoneDelayed

      public org.wpilib.command3.Trigger anyDoneDelayed(double secondsToDelay, AutoTrajectory trajectory, AutoTrajectory... trajectories)
      Creates a trigger that produces a rising edge when any of the trajectories are finished.
      Parameters:
      secondsToDelay - The delay after completion, in seconds.
      trajectory - The first trajectory to watch.
      trajectories - The other trajectories to watch
      Returns:
      a trigger that goes true for one cycle whenever any of the trajectories finishes, delayed by the given number of seconds.
      See Also:
    • anyActive

      public org.wpilib.command3.Trigger anyActive(AutoTrajectory trajectory, AutoTrajectory... trajectories)
      Creates a trigger that returns true when any of the trajectories given are active.
      Parameters:
      trajectory - The first trajectory to watch.
      trajectories - The other trajectories to watch
      Returns:
      a trigger that determines if any of the trajectories are active
    • allInactive

      public org.wpilib.command3.Trigger allInactive(AutoTrajectory trajectory, AutoTrajectory... trajectories)
      Creates a trigger that returns true when all of the trajectories given are inactive.

      This trigger will only return true if the routine is active.

      Parameters:
      trajectory - The first trajectory to watch.
      trajectories - The other trajectories to watch
      Returns:
      a trigger that determines if all of the trajectories are inactive