module documentation

Drivers: which service, which encoding, which topic, and no state machine.

A Driver is the part of a lifecycle Binding that knows how one flavour of coordinator is commanded. The mapping onto Skill states is shared and lives in opensmi.ros2.server.lifecycle, so Components driven by different Drivers present the same OPC UA surface. Two ship:

  • StandardLifecycleDriver is the ROS2 standard, lifecycle_msgs, one node at a time via <node>/change_state.
  • Nav2ManagerDriver is a nav2-style coordinator that drives a set of nodes with one <manager>/manage_nodes call.

Observing is common to both, because a nav2-managed node is an ordinary lifecycle node. Every Driver gates each transition on what the node reports as available. An invalid change request kills an rclpy node (Jazzy 7.1.11: the RCLError propagates out of rclpy.spin()), and a finalized node offers nothing, so a node that does not offer a transition is skipped. Discovery uses each node's transition_event subscription (transitions and publisher matches) instead of polling the graph. A third flavour subclasses LifecycleDriver, implements ~LifecycleDriver.send and is given as the Binding's driver.

Nothing here imports rclpy or touches OPC UA, so a Driver is tested with the fake Runtime.

Class LifecycleDriver One coordinator flavour, commanded and observed. Holds no state machine.
Class Nav2ManagerDriver A nav2-style manager: one manage_nodes call covering the whole set it drives.
Class NodeTransition One transition a node announced: the node's path and its start and goal state ids.
Class StandardLifecycleDriver The ROS2 standard: lifecycle_msgs, one change_state call per node.
Constant CHANGE_STATE_TYPE The service type behind <node>/change_state, which only the standard flavour sends.
Constant DRIVERS Which coordinator flavour a declaration's driver= selects.
Constant GET_AVAILABLE_TRANSITIONS_TYPE The service type behind <node>/get_available_transitions, which is the gate.
Constant GET_STATE_TYPE The service type behind <node>/get_state: one query, answered by the node itself.
Constant MANAGE_NODES_TYPE The service type a nav2-style manager takes: one uint8 command covering a whole set.
Constant NAV2_COMMANDS Which nav2 manager command sends which lifecycle transition at the set it drives.
Constant TRANSITION_EVENT_TYPE The topic type every managed node announces its transitions on, whoever coordinates it.
Function _as_state Return the lifecycle state one id names, or UNKNOWN for a number ROS2 has not defined.
Function _state_id Return the id of one lifecycle_msgs/msg/State field, or UNKNOWN if it is missing.
Function _state_name Return a readable name for one lifecycle state id, for a representation or a log line.
CHANGE_STATE_TYPE: str =

The service type behind <node>/change_state, which only the standard flavour sends.

Value
'lifecycle_msgs/srv/ChangeState'
DRIVERS: Mapping[str, type[LifecycleDriver]] =

Which coordinator flavour a declaration's driver= selects.

A fixed table, so that a Binding file chooses among these by name and cannot introduce a class. A third flavour subclasses LifecycleDriver and is passed as the class.

Value
{StandardLifecycleDriver.flavour: StandardLifecycleDriver,
 Nav2ManagerDriver.flavour: Nav2ManagerDriver}
GET_AVAILABLE_TRANSITIONS_TYPE: str =

The service type behind <node>/get_available_transitions, which is the gate.

Value
'lifecycle_msgs/srv/GetAvailableTransitions'
GET_STATE_TYPE: str =

The service type behind <node>/get_state: one query, answered by the node itself.

Value
'lifecycle_msgs/srv/GetState'
MANAGE_NODES_TYPE: str =

The service type a nav2-style manager takes: one uint8 command covering a whole set.

Its interface package is nav2's, so naming this flavour without nav2 installed is fatal at init.

Value
'nav2_msgs/srv/ManageLifecycleNodes'
NAV2_COMMANDS: Mapping[LifecycleNodeTransition, int] =

Which nav2 manager command sends which lifecycle transition at the set it drives.

The numbers are spelled out because the constants live on a generated nav2 class that cannot be imported without nav2. RESUME and PAUSE are the manager's words for activate and deactivate. STARTUP and RESET are compounds already expressed in opensmi.ros2.server.lifecycle.TRANSITIONS_FOR, and SHUTDOWN ends in finalized, which this project never commands.

Value
{LifecycleNodeTransition.CONFIGURE: 5,
 LifecycleNodeTransition.CLEANUP: 6,
 LifecycleNodeTransition.ACTIVATE: 2,
 LifecycleNodeTransition.DEACTIVATE: 1}
TRANSITION_EVENT_TYPE: str =

The topic type every managed node announces its transitions on, whoever coordinates it.

Value
'lifecycle_msgs/msg/TransitionEvent'
def _as_state(identifier: object) -> LifecycleNodeState:

Return the lifecycle state one id names, or UNKNOWN for a number ROS2 has not defined.

def _state_id(message: object, field: str) -> int:

Return the id of one lifecycle_msgs/msg/State field, or UNKNOWN if it is missing.

UNKNOWN reads as no opinion instead of a traceback on a later task.

def _state_name(identifier: int) -> str:

Return a readable name for one lifecycle state id, for a representation or a log line.