bpod_core.fsm.StateMachine
- class bpod_core.fsm.StateMachine
Represents a state machine with a collection of states.
- add_state(name, timer, state_change_conditions, output_actions, comment=None)
Adds a new state to the state machine.
- Parameters:
name (
str
) – The name of the state to be added.timer (
float
, optional) – The duration of the state’s timer in seconds. Default to 0.state_change_conditions (
dict
, optional) – A dictionary mapping conditions to target states for transitions. Defaults to an empty dictionary.output_actions (
dict
, optional) – A dictionary of actions to be executed during the state. Defaults to an empty dictionary.comment (
Comment
, optional) – An optional comment describing the state.
- Raises:
ValueError – If a state with the given name already exists in the state machine.
- Return type:
- property digraph: Digraph
Returns a graphviz Digraph instance representing the state machine.
The Digraph includes:
A point-shaped node representing the start of the state machine,
An optional ‘exit’ node if any state transitions to ‘exit’,
Record-like nodes for each state displaying state name, timer, comment and output actions, and
Edges representing state transitions based on conditions.
- Returns:
A graphviz Digraph instance representing the state machine.
- Return type:
Digraph
Notes
This method depends on theGraphviz system libraries to be installed. See https://graphviz.readthedocs.io/en/stable/manual.html#installation
- model_config: ClassVar[ConfigDict] = {'json_schema_extra': {'additionalProperties': False}, 'validate_assignment': True}
Configuration for the StateMachine model.
-
states:
OrderedDict
[Annotated
[str
],State
] An ordered dictionary of states in the state machine.