Package choreo.auto

Class AutoChooser

java.lang.Object
choreo.auto.AutoChooser

public class AutoChooser extends Object
An auto chooser that allows for the selection of auto routines at runtime.

This chooser takes a lazy loading approach to auto routines, only generating the auto routine when it is selected. This approach has the benefit of not loading all autos on startup, but also not loading the auto during auto start causing a delay.

Once the AutoChooser is made you can add auto routines to it using the addAutoRoutine(String, AutoRoutineGenerator) method. Unlike SendableChooser this chooser has to be updated every cycle by calling the update() method in your IterativeRobotBase.robotPeriodic().

You can retrieve the AutoRoutine that is currently selected by calling the getSelectedAutoRoutine() method.

  • Constructor Details

    • AutoChooser

      public AutoChooser(AutoFactory factory, String tableName)
      Create a new auto chooser.
      Parameters:
      factory - The auto factory to use for auto routine generation.
      tableName - The name of the network table to use for the chooser, passing in an empty string will put this chooser at the root of the network tables.
  • Method Details

    • update

      public void update()
      Update the auto chooser.

      This method should be called every cycle in the IterativeRobotBase.robotPeriodic(). It will check if the selected auto routine has changed and update the active auto routine.

    • addAutoRoutine

      public void addAutoRoutine(String name, AutoChooser.AutoRoutineGenerator generator)
      Add an auto routine to the chooser.

      An auto routine is a function that takes an AutoFactory and returns a Command. These functions can be static, a lambda or belong to a local variable.

      A good paradigm is making an `AutoRoutines` class that has a reference to all your subsystems and has helper methods for auto commands inside it. Then you crate methods inside that class that take an `AutoFactory` and return a `Command`.

      Parameters:
      name - The name of the auto routine.
      generator - The function that generates the auto routine.
    • getSelectedAutoRoutine

      Get the currently selected auto routine.
      Returns:
      The currently selected auto routine.