Class AutoFactory

java.lang.Object
choreo.auto.AutoFactory

public class AutoFactory extends Object
A factory used to create AutoRoutines and AutoTrajectorys.
See Also:
  • Constructor Details

    • AutoFactory

      public <SampleType extends TrajectorySample<SampleType>> AutoFactory(Supplier<org.wpilib.math.geometry.Pose2d> poseSupplier, Consumer<org.wpilib.math.geometry.Pose2d> resetOdometry, Consumer<SampleType> controller, boolean useAllianceFlipping, org.wpilib.command2.Subsystem driveSubsystem, 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.
      driveSubsystem - The drive Subsystem to require for AutoTrajectory Commands.
      trajectoryLogger - A Choreo.TrajectoryLogger to log Trajectory as they start and finish.
      See Also:
    • AutoFactory

      public <ST extends TrajectorySample<ST>> AutoFactory(Supplier<org.wpilib.math.geometry.Pose2d> poseSupplier, Consumer<org.wpilib.math.geometry.Pose2d> resetOdometry, Consumer<ST> controller, boolean useAllianceFlipping, org.wpilib.command2.Subsystem driveSubsystem)
      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.
      driveSubsystem - The drive Subsystem to require for AutoTrajectory Commands.
      See Also:
  • Method Details

    • newRoutine

      public AutoRoutine newRoutine(String name)
      Creates a new AutoRoutine.
      Parameters:
      name - The name of the AutoRoutine.
      Returns:
      A new AutoRoutine.
    • warmupCmd

      public org.wpilib.command2.Command warmupCmd()
      Warms up Choreo to ensure that there is no delay at the start of auto. It is recommended to schedule this command in your Robot constructor, like so:
          CommandScheduler.getInstance().schedule(autoFactory.warmupCmd());
      
      Returns:
      A command that warms up Choreo's autonomous functionality.
    • trajectoryCmd

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

      Important

      trajectoryCmd(String) and trajectory(String, AutoRoutine, boolean) methods should not be mixed in the same auto routine. trajectoryCmd(String) is used as an escape hatch for teams that don't need the benefits of the trajectory(String, AutoRoutine, boolean) method and its Trigger API. trajectoryCmd(String) does not invoke bindings added via calling bind(String, Command) or AutoFactory.AutoBindings passed into the factory constructor.

      Parameters:
      trajectoryName - The name of the trajectory to use.
      Returns:
      A new AutoTrajectory.
    • trajectoryCmd

      public org.wpilib.command2.Command trajectoryCmd(String trajectoryName, int splitIndex, Function<AutoTrajectory, AutoTrajectory> transform)
      Creates a new AutoTrajectory command to be used in an auto routine.

      Important

      trajectoryCmd(String) and trajectory(String, AutoRoutine, boolean) methods should not be mixed in the same auto routine. trajectoryCmd(String) is used as an escape hatch for teams that don't need the benefits of the trajectory(String, AutoRoutine, boolean) method and its Trigger API. trajectoryCmd(String) does not invoke bindings added via calling bind(String, Command) or AutoFactory.AutoBindings passed into the factory constructor.

      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.command2.Command trajectoryCmd(String trajectoryName, Function<AutoTrajectory, AutoTrajectory> transform)
      Creates a new AutoTrajectory command to be used in an auto routine.

      Important

      trajectoryCmd(String) and trajectory(String, AutoRoutine, boolean) methods should not be mixed in the same auto routine. trajectoryCmd(String) is used as an escape hatch for teams that don't need the benefits of the trajectory(String, AutoRoutine, boolean) method and its Trigger API. trajectoryCmd(String) does not invoke bindings added via calling bind(String, Command) or AutoFactory.AutoBindings passed into the factory constructor.

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

      Important

      trajectoryCmd(String) and trajectory(String, AutoRoutine, boolean) methods should not be mixed in the same auto routine. trajectoryCmd(String) is used as an escape hatch for teams that don't need the benefits of the trajectory(String, AutoRoutine, boolean) method and its Trigger API. trajectoryCmd(String) does not invoke bindings added via calling bind(String, Command) or AutoFactory.AutoBindings passed into the factory constructor.

      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 TrajectorySample<ST>> org.wpilib.command2.Command trajectoryCmd(Trajectory<ST> trajectory)
      Creates a new AutoTrajectory command to be used in an auto routine.

      Important

      trajectoryCmd(String) and trajectory(String, AutoRoutine, boolean) methods should not be mixed in the same auto routine. trajectoryCmd(String) is used as an escape hatch for teams that don't need the benefits of the trajectory(String, AutoRoutine, boolean) method and its Trigger API. trajectoryCmd(String) does not invoke bindings added via calling bind(String, Command) or AutoFactory.AutoBindings passed into the factory constructor.

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

      public org.wpilib.command2.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.command2.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 TrajectorySample<ST>> org.wpilib.command2.Command resetOdometry(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.command2.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.command2.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.command2.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

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