Python YASMIN (Yet Another State MachINe)
|
Public Member Functions | |
None | __init__ (self, str fsm_name, StateMachine fsm, int rate=4, Node node=None) |
List[TransitionMsg] | parse_transitions (self, Dict[str, str] transitions) |
None | parse_state (self, str state_name, Dict[str, str] state_info, List[StateMsg] states_list, int parent=-1) |
Public Attributes | |
Node | pub = self._node.create_publisher(StateMachineMsg, "/fsm_viewer", 10) |
The publisher for the state machine messages. | |
Protected Member Functions | |
None | _publish_data (self) |
Protected Attributes | |
StateMachine | _fsm = fsm |
The finite state machine to be published. | |
str | _fsm_name = fsm_name |
The name of the finite state machine. | |
Node | _node = node |
The ROS 2 node instance used for publishing. | |
Node | _timer = self._node.create_timer(1 / rate, self._publish_data) |
A timer to periodically publish the FSM state. | |
A class to publish the state of a Finite State Machine (FSM) for visualization. Attributes: _node (Node): The ROS 2 node instance used for publishing. _fsm (StateMachine): The finite state machine to be published. _fsm_name (str): The name of the finite state machine. pub: The publisher for the state machine messages. _timer: A timer to periodically publish the FSM state. Methods: parse_transitions(transitions): Converts a dictionary of transitions to a list of TransitionMsg. parse_state(state_name, state_info, states_list, parent): Parses a state and its children recursively. _publish_data(): Publishes the current state of the FSM.
None yasmin_viewer.yasmin_viewer_pub.YasminViewerPub.__init__ | ( | self, | |
str | fsm_name, | ||
StateMachine | fsm, | ||
int | rate = 4, | ||
Node | node = None ) |
Initializes the YasminViewerPub instance. Args: fsm_name (str): The name of the FSM. fsm (StateMachine): The FSM instance to be published. rate (int): The rate in Hz at which to publish updates. Defaults to 4. node (Node, optional): A custom Node instance. If None, a new YasminNode is created. Raises: ValueError: If fsm_name is empty.
|
protected |
Publishes the current state of the FSM. This method validates the FSM, gathers its state data, and publishes it. If validation fails, an error message is logged. Returns: None Raises: Exception: If the FSM validation fails, an error is logged and the function exits without publishing.
None yasmin_viewer.yasmin_viewer_pub.YasminViewerPub.parse_state | ( | self, | |
str | state_name, | ||
Dict[str, str] | state_info, | ||
List[StateMsg] | states_list, | ||
int | parent = -1 ) |
Recursively parses a state and its transitions, adding the resulting StateMsg to the states list. Args: state_name (str): The name of the state. state_info (Dict[str, str]): Information about the state, including its transitions. states_list (List[StateMsg]): A list to which the parsed StateMsg will be appended. parent (int, optional): The ID of the parent state. Defaults to -1. Returns: None
List[TransitionMsg] yasmin_viewer.yasmin_viewer_pub.YasminViewerPub.parse_transitions | ( | self, | |
Dict[str, str] | transitions ) |
Converts a dictionary of transitions into a list of TransitionMsg. Args: transitions (Dict[str, str]): A dictionary where keys are outcome names and values are state names. Returns: List[TransitionMsg]: A list of TransitionMsg representing the FSM transitions.
|
protected |
The finite state machine to be published.
|
protected |
The name of the finite state machine.
|
protected |
The ROS 2 node instance used for publishing.
|
protected |
A timer to periodically publish the FSM state.
Node yasmin_viewer.yasmin_viewer_pub.YasminViewerPub.pub = self._node.create_publisher(StateMachineMsg, "/fsm_viewer", 10) |
The publisher for the state machine messages.