Package smach :: Module state_machine :: Class StateMachine

Class StateMachine

source code


StateMachine

This is a finite state machine smach container. Note that though this is a state machine, it also implements the smach.State interface, so these can be composed hierarchically, if such a pattern is desired.

States are added to the state machine as 3-tuple specifications:

The label is a string, the state instance is any class that implements the smach.State interface, and transitions is a dictionary mapping strings onto strings which represent the transitions out of this new state. Transitions can take one of three forms:

Instance Methods
 
__init__(self, outcomes, input_keys=[], output_keys=[])
Constructor for smach StateMachine Container.
source code
 
execute(self, parent_ud=smach.UserData())
Run the state machine on entry to this state.
source code
 
request_preempt(self)
Propagate preempt to currently active state.
source code
dict of string: State
get_children(self)
Get the children of this container.
source code
smach.State
__getitem__(self, key)
Access child state by key.
source code
 
set_initial_state(self, initial_states, userdata=smach.UserData())
Set initial active states of a container.
source code
list of string
get_active_states(self)
Get a description of the current states.
source code
list of string
get_initial_states(self)
Get the initial states description.
source code
list of 3-tuple
get_internal_edges(self)
Get the internal outcome edges of this container.
source code
 
check_state_spec(self, label, state, transitions)
Validate full state specification (label, state, and transitions).
source code
 
check_consistency(self)
Check the entire state machine for consistency.
source code
 
is_running(self)
Returns true if the state machine is running.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

    Inherited from container.Container
 
__enter__(self) source code
 
__exit__(self, exc_type, exc_val, exc_tb) source code
 
assert_opened(self, msg='') source code
 
call_start_cbs(self)
Calls the registered start callbacks.
source code
 
call_termination_cbs(self, terminal_states, outcome)
Calls the registered termination callbacks.
source code
 
call_transition_cbs(self)
Calls the registered transition callbacks.
source code
 
close(self)
Close the container.
source code
bool
is_opened(self)
Returns True if this container is currently opened for construction.
source code
 
open(self)
Opens this container for modification.
source code
 
opened(self, **kwargs)
Context manager method for opening a smach container.
source code
 
register_start_cb(self, start_cb, cb_args=[])
Adds a start callback to this container.
source code
 
register_termination_cb(self, termination_cb, cb_args=[])
Adds a termination callback to this state machine.
source code
 
register_transition_cb(self, transition_cb, cb_args=[])
Adds a transition callback to this container.
source code
    Inherited from state.State
 
get_registered_input_keys(self)
Get a tuple of registered input keys.
source code
tuple of string
get_registered_outcomes(self)
Get a list of registered outcomes.
source code
 
get_registered_output_keys(self)
Get a tuple of registered output keys.
source code
 
preempt_requested(self)
True if a preempt has been requested.
source code
 
recall_preempt(self)
Sets preempt_requested to False
source code
 
register_input_keys(self, keys)
Add keys to the set of keys from which this state may read.
source code
 
register_io_keys(self, keys)
Add keys to the set of keys from which this state may read and write.
source code
 
register_outcomes(self, new_outcomes)
Add outcomes to the outcome set.
source code
 
register_output_keys(self, keys)
Add keys to the set of keys to which this state may write.
source code
 
service_preempt(self)
Sets preempt_requested to False
source code
Static Methods
 
add(label, state, transitions=None, remapping=None)
Add a state to the opened state machine.
source code
 
add_auto(label, state, connector_outcomes, transitions=None, remapping=None)
Add a state to the state machine such that it automatically transitions to the next added state.
source code
Instance Variables
    Inherited from container.Container
  userdata
Userdata to be passed to child states.
Properties

Inherited from object: __class__

Method Details

__init__(self, outcomes, input_keys=[], output_keys=[])
(Constructor)

source code 

Constructor for smach StateMachine Container.

Parameters:
  • outcomes (list of strings) - The potential outcomes of this state machine.
Overrides: object.__init__

add(label, state, transitions=None, remapping=None)
Static Method

source code 

Add a state to the opened state machine.

Parameters:
  • label (string) - The label of the state being added.
  • state - An instance of a class implementing the State interface.
  • transitions - A dictionary mapping state outcomes to other state labels or container outcomes.
  • remapping - A dictrionary mapping local userdata keys to userdata keys in the container.

add_auto(label, state, connector_outcomes, transitions=None, remapping=None)
Static Method

source code 

Add a state to the state machine such that it automatically transitions to the next added state.

Each state added will receive an additional transition from it to the state which is added after it for every outcome given via connector_outcomes.

Parameters:
  • label (string) - The label of the state being added.
  • state - An instance of a class implementing the State interface.
  • connector_outcomes (list of string) - For which of the added state's outcomes a transition to the next added state should be generated.
  • transitions - A dictionary mapping state outcomes to other state labels. If one of these transitions follows the connector outcome specified in the constructor, the provided transition will override the automatically generated connector transition.

execute(self, parent_ud=smach.UserData())

source code 

Run the state machine on entry to this state. This will set the "closed" flag and spin up the execute thread. Once this flag has been set, it will prevent more states from being added to the state machine.

Parameters:
  • ud - Userdata for the scope in which this state is executing
Overrides: state.State.execute

request_preempt(self)

source code 

Propagate preempt to currently active state.

This will attempt to preempt the currently active state.

Overrides: state.State.request_preempt

get_children(self)

source code 

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

Returns: dict of string: State
The sub-states of this container.
Overrides: container.Container.get_children
(inherited documentation)

__getitem__(self, key)
(Indexing operator)

source code 

Access child state by key.

Returns: smach.State
Child state with label equal to key
Overrides: container.Container.__getitem__
(inherited documentation)

set_initial_state(self, initial_states, userdata=smach.UserData())

source code 

Set initial active states of a container.

Parameters:
  • initial_states - A description of the initial active state of this container.
  • userdata - Initial userdata for this container.
Overrides: container.Container.set_initial_state
(inherited documentation)

get_active_states(self)

source code 

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

Returns: list of string
Overrides: container.Container.get_active_states
(inherited documentation)

get_initial_states(self)

source code 

Get the initial states description.

Returns: list of string
Overrides: container.Container.get_initial_states
(inherited documentation)

get_internal_edges(self)

source code 

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.

Returns: list of 3-tuple
Overrides: container.Container.get_internal_edges
(inherited documentation)

check_state_spec(self, label, state, transitions)

source code 

Validate full state specification (label, state, and transitions). This checks to make sure the required variables are in the state spec, as well as verifies that all outcomes referenced in the transitions are registered as valid outcomes in the state object. If a state specification fails validation, a smach.InvalidStateError is thrown.

check_consistency(self)

source code 

Check the entire state machine for consistency. This asserts that all transition targets are states that are in the state machine. If this fails, it raises an InvalidTransitionError with relevant information.

Overrides: container.Container.check_consistency