smach.container module

class smach.container.Container(outcomes=[], input_keys=[], output_keys=[])

Bases: State

Smach container interface.

This provides an interface for hooking into smach containers. This includes methods to get and set state, as well as provide start / transition / termination callback storage and registration utilities.

Note that it is up to the implementation of the containers both when the callbacks are called as well as what arguments are given to them.

Callback semantics:
  • Start: Called when a container is entered

  • Transition: Called when a container’s state changes

  • Termination: Called when a container is left

assert_opened(msg='')
call_start_cbs()

Calls the registered start callbacks. Callback functions are called with two arguments in addition to any user-supplied arguments:

  • userdata

  • a list of initial states

call_termination_cbs(terminal_states, outcome)

Calls the registered termination callbacks. Callback functions are called with three arguments in addition to any user-supplied arguments:

  • userdata

  • a list of terminal states

  • the outcome of this container

call_transition_cbs()

Calls the registered transition callbacks. Callback functions are called with two arguments in addition to any user-supplied arguments:

  • userdata

  • a list of active states

check_consistency()

Check consistency of this container.

close()

Close the container.

get_active_states()

Get a description of the current states. Note that this is specific to container implementation.

@rtype: list of string

get_children()

Get the children of this container. This is empty for leaf states.

@rtype: dict of string: State @return: The sub-states of this container.

get_initial_states()

Get the initial states description.

@rtype: list of string

get_internal_edges()

Get the internal outcome edges of this container. Get a list of 3-tuples (OUTCOME, LABEL_FROM, LABEL_TO) which correspond to transitions inside this container.

@rtype: list of 3-tuple

is_opened()

Returns True if this container is currently opened for construction. @rtype: bool

open()

Opens this container for modification.

This appends the container to the construction stack and locks the reentrant lock if it is a valid container to open.

opened(**kwargs)

Context manager method for opening a smach container.

register_start_cb(start_cb, cb_args=[])

Adds a start callback to this container. Start callbacks receive arguments:

  • userdata

  • local_userdata

  • initial_states

  • *cb_args

register_termination_cb(termination_cb, cb_args=[])

Adds a termination callback to this state machine. Termination callbacks receive arguments:

  • userdata

  • local_userdata

  • terminal_states

  • container_outcome

  • *cb_args

register_transition_cb(transition_cb, cb_args=[])

Adds a transition callback to this container. Transition callbacks receive arguments:

  • userdata

  • local_userdata

  • active_states

  • *cb_args

set_initial_state(initial_states, userdata)

Set initial active states of a container.

@type initial_states: list of string @param initial_states: A description of the initial active state of this container.

@type userdata: L{UserData} @param userdata: Initial userdata for this container.

userdata

Userdata to be passed to child states.