module documentation

The correspondence between lifecycle nodes and Skill states, written down as data.

A ROS2 lifecycle node's state machine and the SkillSet continuous-skill state machine are the same machine:

Skill state Lifecycle state Trigger Lifecycle transition
Halted unconfigured reset configure
Ready inactive start activate
Running active halt deactivate + cleanup

The row Suspended / inactive / suspend / deactivate is not offered, because the StartupSkill is never suspendable. A node observed deactivating is still read as Suspended and the Skill follows it down to Halted. halt is never shutdown: finalized is terminal, so a shut-down node could never be reset, and the shutdown transitions are absent from LifecycleNodeTransition.

The Binding follows the state pair of a transition_event, not its transition field, which rcl_lifecycle leaves empty on every event (verified live on Jazzy). Entering inactive from configuring is Ready, from deactivating it is Suspended, and from activating (a failed activation) it is Halted. opensmi's SkillState is not ordered, so _RANKS names every state it covers.

Everything here is a pure function of integers and enumerations. The Drivers are in opensmi.ros2.server.drivers and the Skill in opensmi.ros2.server.startup.

Class LifecycleNodeState The states of a ROS2 managed node, with the identifiers lifecycle_msgs/msg/State gives.
Class LifecycleNodeTransition The transitions this project ever commands, with lifecycle_msgs/msg/Transition's ids.
Function aggregate Return what several nodes under one Skill say together: lowest wins.
Function resting_skill_state Return the Skill state one resting lifecycle state means, with no route to read.
Function skill_state_for Return the Skill state one observed transition puts a node in, from the pair alone.
Function trigger_toward Return the trigger that moves a Skill from where it is toward what its nodes report.
Constant PRIMARY_STATES The states a node rests in, and therefore the only ones a Skill state is read off.
Constant RESTING The three Skill states a StartupSkill rests in.
Constant TRANSITIONS_FOR What each Skill trigger sends at the robot, in order.
Constant TRIGGERS Which trigger reaches each of the three Skill states the Skill can rest in.
Constant UNDONE_BY Which transition a halt step rolls back: deactivate undoes activate, cleanup undoes configure.
Function _rank Return how much a Skill state claims: 0 halted, 1 inactive, 2 running.
Constant _RANKS How much each Skill state claims about a node, which is what "lowest wins" compares.
def aggregate(states: Iterable[SkillState | None]) -> SkillState | None:

Return what several nodes under one Skill say together: lowest wins.

Running means every node is active. A node nobody has heard from contributes None and is skipped, so a node that vanishes while the Skill is Running does not halt it. Between equal ranks the answer is Suspended if any node reported one.

Returns
SkillState | NoneThe lowest-ranked state anything reported, or None when nothing has.
def resting_skill_state(state: LifecycleNodeState | int) -> SkillState | None:

Return the Skill state one resting lifecycle state means, with no route to read.

unconfigured and finalized are Halted, active is Running and inactive is Ready. A node in a transition state answers None (no opinion). finalized differs from unconfigured only by the Binding being Terminal, which refuses Reset.

def skill_state_for(*, start: LifecycleNodeState | int, goal: LifecycleNodeState | int) -> SkillState | None:

Return the Skill state one observed transition puts a node in, from the pair alone.

Parameters
start:LifecycleNodeState | intThe state the node left, as transition_event.start_state.id.
goal:LifecycleNodeState | intThe state it entered, as transition_event.goal_state.id.
Returns
SkillState | NoneThe Skill state, or None when the node merely entered a transition state.
def trigger_toward(current: SkillState, target: SkillState) -> TRIGGER | None:

Return the trigger that moves a Skill from where it is toward what its nodes report.

Only downward, and always halt. Following a robot down keeps the address space truthful; following it up would start a Skill nobody asked to start.

Parameters
current:SkillStateThe state the Skill is in. An intermediate state answers None, because a handler is already in flight.
target:SkillStateWhat aggregate says the nodes are.
Returns
TRIGGER | Nonehalt, or None when the Skill is at or below the nodes.
PRIMARY_STATES =

The states a node rests in, and therefore the only ones a Skill state is read off.

A node passing through configuring is not news: the Skill is already in its own intermediate state for the same moment.

Value
frozenset(set([LifecycleNodeState.UNCONFIGURED,
               LifecycleNodeState.INACTIVE,
               LifecycleNodeState.ACTIVE,
               LifecycleNodeState.FINALIZED]))
RESTING =

The three Skill states a StartupSkill rests in.

Suspended can be observed on a node (it ranks in _RANKS) but never entered.

Value
frozenset(set([SkillState.HALTED, SkillState.READY, SkillState.RUNNING]))
TRANSITIONS_FOR: Mapping[TRIGGER, tuple[LifecycleNodeTransition, ...]] =

What each Skill trigger sends at the robot, in order.

halt is two ordered steps: an active node has to be deactivated before it can be cleaned up, and an inactive one does not offer the first. The Driver's gate decides which go out.

Value
{'reset': (LifecycleNodeTransition.CONFIGURE),
 'start': (LifecycleNodeTransition.ACTIVATE),
 'halt': (LifecycleNodeTransition.DEACTIVATE, LifecycleNodeTransition.CLEANUP)}
TRIGGERS: Mapping[SkillState, TRIGGER] =

Which trigger reaches each of the three Skill states the Skill can rest in.

The triggers are named for the act, so reset is the only way into Ready and out of Halted. Suspended has no entry because there is no suspend trigger.

Value
{SkillState.HALTED: 'halt',
 SkillState.READY: 'reset',
 SkillState.RUNNING: 'start'}

Which transition a halt step rolls back: deactivate undoes activate, cleanup undoes configure.

A halt sends a step only when the StartupSkill itself performed the transition it undoes , so a node that was already active is left as it was found.

Value
{LifecycleNodeTransition.DEACTIVATE: LifecycleNodeTransition.ACTIVATE,
 LifecycleNodeTransition.CLEANUP: LifecycleNodeTransition.CONFIGURE}
def _rank(state: SkillState) -> int:

Return how much a Skill state claims: 0 halted, 1 inactive, 2 running.

Raises
KeyErrorFor a state outside the correspondence (intermediate states, Completed).
_RANKS: Mapping[SkillState, int] =

How much each Skill state claims about a node, which is what "lowest wins" compares.

Ready and Suspended share a rank because both are inactive and both accept start.

Value
{SkillState.HALTED: 0,
 SkillState.READY: 1,
 SkillState.SUSPENDED: 1,
 SkillState.RUNNING: 2}