network_fsm

Submodules

Classes

class brom_drake.utils.leaf_systems.network_fsm.config.NetworkXFSMConfig(name: str = 'NetworkXFSM', log_file_name: str = 'network_fsm.log', show_logs_in_terminal: bool = True)[source]

Configuration for the NetworkXFSM system.

Attributes:

name (str): Name of the FSM. initial_state (str): Initial state of the FSM. states (list): List of states in the FSM. transitions (dict): Mapping of transitions between states.

class brom_drake.utils.leaf_systems.network_fsm.errors.EdgeContainsNoConditionsError(edge: Tuple[int, int])[source]

Description

Raised when an edge in the FSM graph contains no conditions.

class brom_drake.utils.leaf_systems.network_fsm.errors.EdgeContainsNoLabelsError(edge: Tuple[int, int])[source]

Description

Raised when an edge in the FSM graph contains no labels.

class brom_drake.utils.leaf_systems.network_fsm.errors.MultipleConnectedComponentsError(connected_components: List[Set[int]])[source]

Description

Raised when the FSM graph has multiple connected components.

class brom_drake.utils.leaf_systems.network_fsm.errors.NumberOfStartNodesError(start_nodes: List[int])[source]

Description

Raised when the FSM graph has multiple start nodes.

class brom_drake.utils.leaf_systems.network_fsm.errors.OutputPortNotInitializedError(node_index: int, output_port: str, output_ports_initialized: List[str])[source]

Description

Raised when an output port is not intiialized in the FSM graph.

class brom_drake.utils.leaf_systems.network_fsm.fsm_edge_definition.FSMEdgeDefinition(conditions: List[FSMTransitionCondition], src: int, dst: int)[source]

Description

class brom_drake.utils.leaf_systems.network_fsm.fsm_output_definition.FSMOutputDefinition(output_port_name: str, output_port_value: bool | float | ndarray | str)[source]

Dataclass to represent the output of a state in a finite state machine.

class brom_drake.utils.leaf_systems.network_fsm.fsm_transition_condition.FSMTransitionCondition(condition_type: FSMTransitionConditionType, condition_value: bool | float | ndarray, input_port_name: str | None = None)[source]

Dataclass to represent a single condition that can be used to transition between states in a finite state machine.

static ForAfterThisManySeconds(seconds: float) FSMTransitionConditionType[source]

Convenience method for creating transition conditions that are ‘after seconds seconds’

evaluate_comparison(input_port_value: bool | float | ndarray)[source]

Description

This function evaluates the condition based on the input port value.

requires_input_port()[source]

Description

This function returns whether or not the condition requires an input port.

class brom_drake.utils.leaf_systems.network_fsm.fsm_transition_condition.FSMTransitionConditionType(*values)[source]

Enum to represent the different types of conditions that can be used to transition between states in a finite state machine.

class brom_drake.utils.leaf_systems.network_fsm.networkx_fsm.NetworkXFSM(fsm_graph: DiGraph, config: NetworkXFSMConfig = NetworkXFSMConfig(name='NetworkXFSM', log_file_name='network_fsm.log', show_logs_in_terminal=True))[source]
CalcFSMState(context: Context, fsm_state: BasicVector)[source]

Description

This function calculates the current state of the FSM. It uses the various Edge Definitions to determine the next state, based on the current state and the input values.

advance_state_if_necessary(context: Context, debug_flag: bool = False)[source]

Description

Checks the current values of all relevant inputs and advances the state if necessary according to the conditions established in the FSM graph.

collect_edge_definitions(fsm_graph: DiGraph, debug_flag: bool = False) List[FSMEdgeDefinition][source]

Description

This function collects the edge definitions from the FSM graph. It uses the data from the graph to create an internal representation (FSMEdgeDefinition) for each edge in the graph.

create_logger() Logger[source]

Description

This function configures the logger for the FSM. It sets the logger to log messages at the INFO level.

create_output_port_function(port_name_ii: str, create_abstract_port: bool = False) Callable[[Context, AbstractValue], None][source]

Description

This function creates the output port function for the FSM.

derive_input_ports_from_graph(debug_flag: bool = False)[source]

Description

This function creates the input ports for the FSM.

derive_output_ports_from_graph(debug_flag: bool = False)[source]

Description

This method uses the fsm_graph to infer what output ports should be created for the FSM.

Note

For speed, this assumes that the graph has already been checked for validity. Also, this method assumes that all necessary output ports can be inferred from the initial node.

derive_output_update_map(port_name_ii: str) Dict[int, str | int][source]

Description

This method constructs a small mapping of WHEN to change the value of port_name_ii.

The key to each element in the mapping is a value of the state (i.e., on this state, change the value of port_name_ii to this value) and the value is the value that the state should be changed to when we reach there.

Parameters

port_name_ii: str

The name of the port for which this mapping applies.

evaluate_transition_condition(condition: FSMTransitionCondition, context: Context) bool[source]

Description

This function evaluates the condition for a given input port value.

initialize_fsm_state()[source]

Description

This function initializes the FSM state by: - Creating the output port for the fsm state, - Setting the initial state of the FSM (as an internal variable)

initialize_last_output_value_map()[source]

Description

This function takes the initial node and then uses all of the output definitions for that node to define the initial values for the last_output_value map.

log(message: str, level: int = 20)[source]

Description

This function logs a message to the logger.

static supports_this_digraph(digraph: DiGraph, debug_flag: bool = False) None | ValueError[source]

Description

This function checks if the given directed graph is a valid FSM.

Parameters

digraphnx.DiGraph

The directed graph to check.

Returns

recognized_exception: Union[None, ValueError]

Either an error if the graph is not a valid FSM, or None if the graph is valid.

universal_allocation_lambda(port_name: str) AbstractValue[source]

Description

This function returns the allocation lambda for the given port name.

Functions

(None found)

Variables

brom_drake.utils.leaf_systems.network_fsm.networkx_fsm.DEFAULT_NETWORKX_FSM_DIR = './brom/networkx_fsm'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.