smach.iterator module
- class smach.iterator.Iterator(outcomes, input_keys, output_keys, it=[], it_label='it_data', exhausted_outcome='exhausted')
Bases:
Container
Sequence Container
This container inherits functionality from L{smach.StateMachine} and adds some auto-generated transitions that create a sequence of states from the order in which said states are added to the container.
- check_consistency()
Check consistency of this container.
- execute(parent_ud=None)
Called when executing a state. In the base class this raises a NotImplementedError.
@type ud: L{UserData} structure @param ud: Userdata for the scope in which this state is executing
- 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
- request_preempt()
Sets preempt_requested to True
- static set_contained_state(label, state, loop_outcomes=[], break_outcomes=[], final_outcome_map={})
Set the contained state
@type label: string @param label: The label of the state being added.
@type state: L{smach.State} @param state: An instance of a class implementing the L{smach.State} interface.
@param loop_outcomes: List of contained state outcomes that should cause the iterator to continue. If this is empty, all outcomes that are not in the break_outcomes list will cause the iterator to continue to iterate. NOTE: loop_outcomes will be overriden by break_outcomes if both parameters are used.
@param break_outcomes: List of contained state outcomes that should cause the iterator to break. When the contained state emits an outcome in this list, the container will terminate and return either that outcome or the outcome it is mapped to in final_outcome_map. NOTE: loop_outcomes will be overriden by break_outcomes if both parameters are used.
@param final_outcome_map: A map from contained state outcomes to container outcomes. On termination of the iterator (either from finishing or from a break) this map will be used to translate contained state outcomes to container outcomes. Unspecified contained state outcomes will fall through as container outcomes.
- 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.
- static set_iteritems(it, it_label='it_data')
Set the list or generator for the iterator to iterate over.
@type it: iterable @param iteritems: Items to iterate over on each cycle
@type it_label: string @param iteritems_label: The label that the item in the current iteration will be given when it is put into the container’s local userdata.
@type exhausted_outcome: string @param exhausted_outcome: If the iterable is exhausted without a break condition this outcome is emitted by the container.