Class AutoFactory

java.lang.Object
choreo.commands3.AutoFactory

public class AutoFactory extends Object
A factory used to create AutoRoutines and AutoTrajectorys for Commands v3.
See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     <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 create AutoRoutine and AutoTrajectory.
     <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 create AutoRoutine and AutoTrajectory.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addRoutine(org.wpilib.framework.OpModeRobot robot, String name, String group, Consumer<AutoRoutine> body)
    Registers an autonomous routine as an opmode named name in the given group, shown on the Driver Station.
    void
    addRoutine(org.wpilib.framework.OpModeRobot robot, String name, Consumer<AutoRoutine> body)
    Registers an autonomous routine as an opmode named name, shown on the Driver Station.
    bind(String name, org.wpilib.command3.Command cmd)
    Binds a command to an event in all trajectories created after this point.
    choreo.Choreo.TrajectoryCache
    The AutoFactory caches trajectories with a Choreo.TrajectoryCache to avoid reloading the same trajectory multiple times.
    <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.
    org.wpilib.command3.Command
    resetOdometry(String trajectoryName)
    Creates a command that resets the robot's odometry to the start of a trajectory.
    org.wpilib.command3.Command
    resetOdometry(String trajectoryName, int splitIndex)
    Creates a command that resets the robot's odometry to the start of a trajectory.
    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
    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
    <ST extends choreo.trajectory.TrajectorySample<ST>>
    org.wpilib.command3.Command
    trajectoryCmd(choreo.trajectory.Trajectory<ST> trajectory)
    Creates a new AutoTrajectory command to be used in an auto routine.
    org.wpilib.command3.Command
    trajectoryCmd(String trajectoryName)
    Creates a new AutoTrajectory command to be used in an auto routine.
    org.wpilib.command3.Command
    trajectoryCmd(String trajectoryName, int splitIndex)
    Creates a new AutoTrajectory command to be used in an auto routine.
    org.wpilib.command3.Command
    trajectoryCmd(String trajectoryName, int splitIndex, Function<AutoTrajectory, AutoTrajectory> transform)
    Creates a new AutoTrajectory command to be used in an auto routine.
    org.wpilib.command3.Command
    Creates a new AutoTrajectory command to be used in an auto routine.
    org.wpilib.command3.Command
    Warms up Choreo so there is no delay at the start of auto.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 create AutoRoutine and AutoTrajectory.
      Type Parameters:
      SampleType - The type of samples in the trajectory.
      Parameters:
      poseSupplier - A function that returns the current field-relative Pose2d of the robot.
      resetOdometry - A function that receives a field-relative Pose2d to reset the robot's odometry to.
      controller - A function that receives the current SampleType and 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 drive Mechanism to require for AutoTrajectory Commands.
      trajectoryLogger - A Choreo.TrajectoryLogger to log Trajectory as 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 create AutoRoutine and AutoTrajectory.
      Type Parameters:
      ST - DifferentialSample or SwerveSample
      Parameters:
      poseSupplier - A function that returns the current field-relative Pose2d of the robot.
      resetOdometry - A function that receives a field-relative Pose2d to reset the robot's odometry to.
      controller - A function that receives the current ST and 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 drive Mechanism to require for AutoTrajectory Commands.
  • Method Details

    • addRoutine

      public void addRoutine(org.wpilib.framework.OpModeRobot robot, String name, Consumer<AutoRoutine> body)
      Registers an autonomous routine as an opmode named name, shown on the Driver Station.

      body does not run now. It runs each time the opmode is selected on the Driver Station, on a fresh AutoRoutine, 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 named name in 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

      public org.wpilib.command3.Command 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

      public org.wpilib.command3.Command trajectoryCmd(String trajectoryName)
      Creates a new AutoTrajectory command to be used in an auto routine.

      Don't mix trajectoryCmd(String) and AutoRoutine.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 with bind(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 new AutoTrajectory command 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 new AutoTrajectory command 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

      public org.wpilib.command3.Command trajectoryCmd(String trajectoryName, int splitIndex)
      Creates a new AutoTrajectory command 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 new AutoTrajectory command to be used in an auto routine.

      See trajectoryCmd(String) for caveats.

      Type Parameters:
      ST - DifferentialSample or SwerveSample
      Parameters:
      trajectory - The trajectory to use.
      Returns:
      A new AutoTrajectory.
    • resetOdometry

      public org.wpilib.command3.Command resetOdometry(String trajectoryName)
      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

      public org.wpilib.command3.Command resetOdometry(String trajectoryName, int splitIndex)
      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 - DifferentialSample or SwerveSample
      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 an Optional<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 - An Optional<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

      public AutoFactory bind(String name, org.wpilib.command3.Command cmd)
      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

      public choreo.Choreo.TrajectoryCache cache()
      The AutoFactory caches trajectories with a Choreo.TrajectoryCache to avoid reloading the same trajectory multiple times.
      Returns:
      The trajectory cache.