frc-docs icon indicating copy to clipboard operation
frc-docs copied to clipboard

Add detail to The Scheduler Run Sequence

Open tom131313 opened this issue 2 years ago • 2 comments

Regarding Document

An important use, of a subsystem as a Finite State Machine and its dependent commands as States of that FSM upon a trigger/button event to initiate a transition from one state to another, depends on the following sequence:

the end method of the current (interrupted) command (state) is run before the initialize method of the new (interrupting) command (state).

Using state exit and enter like this somewhat special case depends on the user correctly specifying a FSM as a subsystem and that subsystem being a requirement of all the commands that reflect states of that FSM and the commands can be interrupted by subsequent commands.

WPILib supports that sequence and adding detail to the documentation to describe that case works would help users.

ChiefDelphi reference

tom131313 avatar Jul 19 '23 22:07 tom131313

Just to make sure I understand, the request here is to clarify that interrupted command end is called before interrupting command init? Anything more than that?

Starlight220 avatar Jul 20 '23 05:07 Starlight220

Yes and all this happens in the same timestep to provide a bump-less transition to a new state:

  1. event triggers new command with dependency on a subsystem
  2. end() the running command for that subsystem
  3. initialize() new command for that subsystem

In ChiefDelphi I made this comment about an example application of this feature is to make a smooth, safe motor speed transition (assuming the motor set() speed is also properly handled and that might not be obvious coding).

tom131313 avatar Jul 20 '23 14:07 tom131313