Package smach :: Module sequence

Source Code for Module smach.sequence

 1   
 2  import threading 
 3  from contextlib import contextmanager 
 4   
 5  import smach 
 6   
 7  __all__ = ['Sequence'] 
8 9 -class Sequence(smach.state_machine.StateMachine):
10 """Sequence Container 11 12 This container inherits functionality from L{smach.StateMachine} and adds 13 some auto-generated transitions that create a sequence of states from the 14 order in which said states are added to the container. 15 """
16 - def __init__(self, 17 outcomes, 18 connector_outcome):
19 """Constructor. 20 21 @type outcomes: list of string 22 @param outcomes: The potential outcomes of this container. 23 24 @type connector_outcome: string 25 @param connector_outcome: The outcome used to connect states in the 26 sequence. 27 """ 28 smach.state_machine.StateMachine.__init__(self, outcomes) 29 30 self._last_added_seq_label = None 31 self._connector_outcome = connector_outcome
32 33 ### Construction Methods 34 @staticmethod
35 - def add(label, state, transitions = None, remapping = None):
36 """Add a state to the sequence. 37 Each state added will receive an additional transition from it to the 38 state which is added after it. The transition will follow the outcome 39 specified at construction of this container. 40 41 @type label: string 42 @param label: The label of the state being added. 43 44 @param state: An instance of a class implementing the L{State} interface. 45 46 @param transitions: A dictionary mapping state outcomes to other state 47 labels. If one of these transitions follows the connector outcome 48 specified in the constructor, the provided transition will override 49 the automatically generated connector transition. 50 """ 51 # Get currently opened container 52 self = Sequence._currently_opened_container() 53 54 if transitions is None: 55 transitions = {} 56 57 # Perform sequence linking 58 if self._last_added_seq_label is not None: 59 #print self._transitions[self._last_added_seq_label] 60 61 last_label = self._last_added_seq_label 62 # Check if the connector outcome has been overriden 63 if self._connector_outcome not in self._transitions[last_label]\ 64 or self._transitions[last_label][self._connector_outcome] is None: 65 self._transitions[last_label][self._connector_outcome] = label 66 try: 67 self.check_state_spec(last_label, self._states[last_label], self._transitions[last_label]) 68 except: 69 smach.logerr("Attempting to construct smach state sequence failed.") 70 71 #print self._transitions[self._last_added_seq_label] 72 73 # Store the last added state label 74 self._last_added_seq_label = label 75 76 return smach.StateMachine.add(label, state, transitions, remapping)
77