Class AutoFactory
AutoRoutines and AutoTrajectorys for Commands v3.- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescription<SampleType extends choreo.trajectory.TrajectorySample<SampleType>>AutoFactory(Supplier<org.wpilib.math.geometry.Pose2d> poseSupplier, Consumer<org.wpilib.math.geometry.Pose2d> resetOdometry, Consumer<SampleType> controller, boolean useAllianceFlipping, org.wpilib.command3.Mechanism driveMechanism, choreo.Choreo.TrajectoryLogger<SampleType> trajectoryLogger) Create a factory that can be used to createAutoRoutineandAutoTrajectory.<ST extends choreo.trajectory.TrajectorySample<ST>>AutoFactory(Supplier<org.wpilib.math.geometry.Pose2d> poseSupplier, Consumer<org.wpilib.math.geometry.Pose2d> resetOdometry, Consumer<ST> controller, boolean useAllianceFlipping, org.wpilib.command3.Mechanism driveMechanism) Create a factory that can be used to createAutoRoutineandAutoTrajectory. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRoutine(org.wpilib.framework.OpModeRobot robot, String name, String group, Consumer<AutoRoutine> body) Registers an autonomous routine as an opmode namednamein the given group, shown on the Driver Station.voidaddRoutine(org.wpilib.framework.OpModeRobot robot, String name, Consumer<AutoRoutine> body) Registers an autonomous routine as an opmode namedname, shown on the Driver Station.Binds a command to an event in all trajectories created after this point.choreo.Choreo.TrajectoryCachecache()TheAutoFactorycaches trajectories with aChoreo.TrajectoryCacheto avoid reloading the same trajectory multiple times.<ST extends choreo.trajectory.TrajectorySample<ST>>
org.wpilib.command3.CommandresetOdometry(choreo.trajectory.Trajectory<ST> trajectory) Creates a command that resets the robot's odometry to the start of a trajectory.org.wpilib.command3.CommandresetOdometry(String trajectoryName) Creates a command that resets the robot's odometry to the start of a trajectory.org.wpilib.command3.CommandresetOdometry(String trajectoryName, int splitIndex) Creates a command that resets the robot's odometry to the start of a trajectory.org.wpilib.command3.CommandresetOdometry(Supplier<Optional<org.wpilib.math.geometry.Pose2d>> pose) Creates a command that resets the robot's odometry to the supplied poseorg.wpilib.command3.CommandresetOdometry(Optional<org.wpilib.math.geometry.Pose2d> pose, boolean doFlipForAlliance) Creates a command that resets the robot's odometry to the given pose<ST extends choreo.trajectory.TrajectorySample<ST>>
org.wpilib.command3.CommandtrajectoryCmd(choreo.trajectory.Trajectory<ST> trajectory) Creates a newAutoTrajectorycommand to be used in an auto routine.org.wpilib.command3.CommandtrajectoryCmd(String trajectoryName) Creates a newAutoTrajectorycommand to be used in an auto routine.org.wpilib.command3.CommandtrajectoryCmd(String trajectoryName, int splitIndex) Creates a newAutoTrajectorycommand to be used in an auto routine.org.wpilib.command3.CommandtrajectoryCmd(String trajectoryName, int splitIndex, Function<AutoTrajectory, AutoTrajectory> transform) Creates a newAutoTrajectorycommand to be used in an auto routine.org.wpilib.command3.CommandtrajectoryCmd(String trajectoryName, Function<AutoTrajectory, AutoTrajectory> transform) Creates a newAutoTrajectorycommand to be used in an auto routine.org.wpilib.command3.CommandWarms up Choreo so there is no delay at the start of auto.
-
Constructor Details
-
AutoFactory
public <SampleType extends choreo.trajectory.TrajectorySample<SampleType>> AutoFactory(Supplier<org.wpilib.math.geometry.Pose2d> poseSupplier, Consumer<org.wpilib.math.geometry.Pose2d> resetOdometry, Consumer<SampleType> controller, boolean useAllianceFlipping, org.wpilib.command3.Mechanism driveMechanism, choreo.Choreo.TrajectoryLogger<SampleType> trajectoryLogger) Create a factory that can be used to createAutoRoutineandAutoTrajectory.- Type Parameters:
SampleType- The type of samples in the trajectory.- Parameters:
poseSupplier- A function that returns the current field-relativePose2dof the robot.resetOdometry- A function that receives a field-relativePose2dto reset the robot's odometry to.controller- A function that receives the currentSampleTypeand controls the robot.useAllianceFlipping- If this is true, when on the red alliance, the path will be mirrored to the opposite side, while keeping the same coordinate system origin.driveMechanism- The driveMechanismto require forAutoTrajectoryCommands.trajectoryLogger- AChoreo.TrajectoryLoggerto logTrajectoryas they start and finish.
-
AutoFactory
public <ST extends choreo.trajectory.TrajectorySample<ST>> AutoFactory(Supplier<org.wpilib.math.geometry.Pose2d> poseSupplier, Consumer<org.wpilib.math.geometry.Pose2d> resetOdometry, Consumer<ST> controller, boolean useAllianceFlipping, org.wpilib.command3.Mechanism driveMechanism) Create a factory that can be used to createAutoRoutineandAutoTrajectory.- Type Parameters:
ST-DifferentialSampleorSwerveSample- Parameters:
poseSupplier- A function that returns the current field-relativePose2dof the robot.resetOdometry- A function that receives a field-relativePose2dto reset the robot's odometry to.controller- A function that receives the currentSTand controls the robot.useAllianceFlipping- If this returns true, when on the red alliance, the path will be mirrored to the opposite side, while keeping the same coordinate system origin.driveMechanism- The driveMechanismto require forAutoTrajectoryCommands.
-
-
Method Details
-
addRoutine
public void addRoutine(org.wpilib.framework.OpModeRobot robot, String name, Consumer<AutoRoutine> body) Registers an autonomous routine as an opmode namedname, shown on the Driver Station.bodydoes not run now. It runs each time the opmode is selected on the Driver Station, on a freshAutoRoutine, which is what scopes the triggers and commands it creates to that opmode. The routine object is deliberately not returned, so it can't be built ahead of time (such as in the robot constructor) where it would not be scoped.This does not publish the opmode to the Driver Station. Call
OpModeRobot.publishOpModes()after registering all of your opmodes, such as at the end of the robot constructor, or the routine will not appear in the Driver Station's opmode list.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); });- Parameters:
robot- The robot to register the opmode with.name- The name of the opmode, as shown on the Driver Station. Must be unique among autonomous opmodes.body- A function that receives the new routine and sets up its triggers.
-
addRoutine
public void addRoutine(org.wpilib.framework.OpModeRobot robot, String name, String group, Consumer<AutoRoutine> body) Registers an autonomous routine as an opmode namednamein the given group, shown on the Driver Station.- Parameters:
robot- The robot to register the opmode with.name- The name of the opmode, as shown on the Driver Station. Must be unique among autonomous opmodes.group- The group the opmode is listed under on the Driver Station.body- A function that receives the new routine and sets up its triggers.- See Also:
-
warmupCmd
Warms up Choreo so there is no delay at the start of auto. Schedule this command in your Robot constructor:Scheduler.getDefault().schedule(autoFactory.warmupCmd());The command requires no mechanisms, so it can run while the robot is disabled.
- Returns:
- A command that warms up Choreo's autonomous functionality.
-
trajectoryCmd
Creates a newAutoTrajectorycommand to be used in an auto routine.Don't mix
trajectoryCmd(String)andAutoRoutine.trajectory(String)in the same auto routine.trajectoryCmd(String)is an escape hatch for teams that don't need the trigger API, and it does not run bindings added withbind(String, Command).- Parameters:
trajectoryName- The name of the trajectory to use.- Returns:
- A new
AutoTrajectory.
-
trajectoryCmd
public org.wpilib.command3.Command trajectoryCmd(String trajectoryName, int splitIndex, Function<AutoTrajectory, AutoTrajectory> transform) Creates a newAutoTrajectorycommand to be used in an auto routine.See
trajectoryCmd(String)for caveats.- Parameters:
trajectoryName- The name of the trajectory to use.splitIndex- The index of the split trajectory to use.transform- A function that takes in the loaded trajectory and applies a transformation to it, such as left-to-right mirroring.- Returns:
- A new
AutoTrajectory.
-
trajectoryCmd
public org.wpilib.command3.Command trajectoryCmd(String trajectoryName, Function<AutoTrajectory, AutoTrajectory> transform) Creates a newAutoTrajectorycommand to be used in an auto routine.See
trajectoryCmd(String)for caveats.- Parameters:
trajectoryName- The name of the trajectory to use.transform- A function that takes in the loaded trajectory and applies a transformation to it, such as left-to-right mirroring.- Returns:
- A new
AutoTrajectory.
-
trajectoryCmd
Creates a newAutoTrajectorycommand to be used in an auto routine.See
trajectoryCmd(String)for caveats.- Parameters:
trajectoryName- The name of the trajectory to use.splitIndex- The index of the split trajectory to use.- Returns:
- A new
AutoTrajectory.
-
trajectoryCmd
public <ST extends choreo.trajectory.TrajectorySample<ST>> org.wpilib.command3.Command trajectoryCmd(choreo.trajectory.Trajectory<ST> trajectory) Creates a newAutoTrajectorycommand to be used in an auto routine.See
trajectoryCmd(String)for caveats.- Type Parameters:
ST-DifferentialSampleorSwerveSample- Parameters:
trajectory- The trajectory to use.- Returns:
- A new
AutoTrajectory.
-
resetOdometry
Creates a command that resets the robot's odometry to the start of a trajectory.- Parameters:
trajectoryName- The name of the trajectory to use.- Returns:
- A command that resets the robot's odometry.
-
resetOdometry
Creates a command that resets the robot's odometry to the start of a trajectory.- Parameters:
trajectoryName- The name of the trajectory to use.splitIndex- The index of the split trajectory to use.- Returns:
- A command that resets the robot's odometry.
-
resetOdometry
public <ST extends choreo.trajectory.TrajectorySample<ST>> org.wpilib.command3.Command resetOdometry(choreo.trajectory.Trajectory<ST> trajectory) Creates a command that resets the robot's odometry to the start of a trajectory.- Type Parameters:
ST-DifferentialSampleorSwerveSample- Parameters:
trajectory- The trajectory to use.- Returns:
- A command that resets the robot's odometry.
-
resetOdometry
public org.wpilib.command3.Command resetOdometry(Supplier<Optional<org.wpilib.math.geometry.Pose2d>> pose) Creates a command that resets the robot's odometry to the supplied pose- Parameters:
pose- A function that is called when the command is run. It returns anOptional<Pose2d>of the robot's desired odometry position.- Returns:
- A command that resets the robot's odometry to the supplied pose, or does nothing if the supplied Optional is empty.
-
resetOdometry
public org.wpilib.command3.Command resetOdometry(Optional<org.wpilib.math.geometry.Pose2d> pose, boolean doFlipForAlliance) Creates a command that resets the robot's odometry to the given pose- Parameters:
pose- AnOptional<Pose2d>of the robot's desired odometry position.doFlipForAlliance- True if the given pose still needs to be flipped according to the alliance (usually true). False if it is an absolute field position.- Returns:
- A command that resets the robot's odometry to the given pose (flipped as directed), or does nothing if the supplied Optional is empty.
-
bind
Binds a command to an event in all trajectories created after this point.- Parameters:
name- The name of the trajectory to bind the command to.cmd- The command to bind to the trajectory.- Returns:
- The AutoFactory the method was called from.
-
cache
TheAutoFactorycaches trajectories with aChoreo.TrajectoryCacheto avoid reloading the same trajectory multiple times.- Returns:
- The trajectory cache.
-