- Write robot code in the structure of a command:
- Initialise (when the command starts)
- Execute (while the command is running)
- Finished (returns true when the command is done)
- End (when the command ends)
- Compose individual commands into larger command groups, in order to run commands in parallel, sequence, etc.
- Use subsystems to group related hardware access together, and thus also group commands related to each subsystem together.
- Declaratively bind commands to gamepad inputs and other events.
- A scheduler runs commands and polls bindings to start up new commands.
The combination of commands and a scheduler to run them forms a Finite State
Machine, or at least, an automata that is similar enough. Command based’s
automata is a dynamically composed and run one and many teams’ command based
code could have hundreds to thousands of ‘states’ that one might write by hand
in a traditional FSM. It is also common for a command to contain its own sub
FSM, and Mercurial has good support for this.