Class AutoChooser
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A function that generates anAutoRoutine
from anAutoFactory
. -
Constructor Summary
ConstructorDescriptionAutoChooser
(AutoFactory factory, String tableName) Create a new auto chooser. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAutoRoutine
(String name, AutoChooser.AutoRoutineGenerator generator) Add an auto routine to the chooser.Get the currently selected auto routine.void
update()
Update the auto chooser.
-
Constructor Details
-
AutoChooser
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
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
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.
-