Class AutoRoutine
- All Implemented Interfaces:
AutoCloseable, org.wpilib.opmode.OpMode
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
ConstructorsModifierConstructorDescriptionprotectedAutoRoutine(AutoFactory factory, String name) Creates a new routine with a specific name. -
Method Summary
Modifier and TypeMethodDescriptionorg.wpilib.command3.Triggeractive()Returns aTriggerthat 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.TriggerallInactive(AutoTrajectory trajectory, AutoTrajectory... trajectories) Creates a trigger that returns true when all of the trajectories given are inactive.org.wpilib.command3.TriggeranyActive(AutoTrajectory trajectory, AutoTrajectory... trajectories) Creates a trigger that returns true when any of the trajectories given are active.org.wpilib.command3.TriggeranyDone(AutoTrajectory trajectory, AutoTrajectory... trajectories) Creates a trigger that produces a rising edge when any of the trajectories are finished.org.wpilib.command3.TriggeranyDoneDelayed(double secondsToDelay, AutoTrajectory trajectory, AutoTrajectory... trajectories) Creates a trigger that produces a rising edge when any of the trajectories are finished.voidend()Ends the routine.org.wpilib.command3.Triggeridle()Creates a trigger that is true when the routine is idle.name()Gets the name of this routine.org.wpilib.command3.Triggerobserve(BooleanSupplier condition) Creates aTriggerfrom a condition that is only true while this routine is running.voidstart()Starts the routine.<SampleType extends choreo.trajectory.TrajectorySample<SampleType>>
AutoTrajectorytrajectory(choreo.trajectory.Trajectory<SampleType> trajectory) Creates a newAutoTrajectoryto be used in an auto routine.trajectory(String trajectoryName) Creates a newAutoTrajectoryto be used in an auto routine.trajectory(String trajectoryName, int splitIndex) Creates a newAutoTrajectoryto be used in an auto routine.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.wpilib.opmode.OpMode
close, disabledPeriodic, getCallbacks, periodic
-
Constructor Details
-
AutoRoutine
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
@AutonomousorOpModeRobot.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 trajectoriesname- The name of the routine- See Also:
-
-
Method Details
-
name
-
active
Returns aTriggerthat 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
Triggerthat is true while this routine is running.
-
observe
Creates aTriggerfrom a condition that is only true while this routine is running.- Parameters:
condition- The condition represented by the trigger.- Returns:
- A
Triggerthat mirrors the state of the providedconditionwhile the routine isactive, and is false otherwise.
-
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
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:
startin interfaceorg.wpilib.opmode.OpMode
-
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:
endin interfaceorg.wpilib.opmode.OpMode
-
trajectory
Creates a newAutoTrajectoryto be used in an auto routine.- Parameters:
trajectoryName- The name of the trajectory to use.- Returns:
- A new
AutoTrajectory.
-
trajectory
Creates a newAutoTrajectoryto 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 newAutoTrajectoryto 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
-