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 input_keys=[], 20 output_keys=[]):
21 """Constructor. 22 23 @type outcomes: list of string 24 @param outcomes: The potential outcomes of this container. 25 26 @type connector_outcome: string 27 @param connector_outcome: The outcome used to connect states in the 28 sequence. 29 """ 30 smach.state_machine.StateMachine.__init__(self, outcomes, input_keys, output_keys) 31 32 self._last_added_seq_label = None 33 self._connector_outcome = connector_outcome
34 35 ### Construction Methods 36 @staticmethod
37 - def add(label, state, transitions = None, remapping = None):
38 """Add a state to the sequence. 39 Each state added will receive an additional transition from it to the 40 state which is added after it. The transition will follow the outcome 41 specified at construction of this container. 42 43 @type label: string 44 @param label: The label of the state being added. 45 46 @param state: An instance of a class implementing the L{State} interface. 47 48 @param transitions: A dictionary mapping state outcomes to other state 49 labels. If one of these transitions follows the connector outcome 50 specified in the constructor, the provided transition will override 51 the automatically generated connector transition. 52 """ 53 # Get currently opened container 54 self = Sequence._currently_opened_container() 55 56 if transitions is None: 57 transitions = {} 58 59 # Perform sequence linking 60 if self._last_added_seq_label is not None: 61 #print self._transitions[self._last_added_seq_label] 62 63 last_label = self._last_added_seq_label 64 # Check if the connector outcome has been overriden 65 if self._connector_outcome not in self._transitions[last_label]\ 66 or self._transitions[last_label][self._connector_outcome] is None: 67 self._transitions[last_label][self._connector_outcome] = label 68 try: 69 self.check_state_spec(last_label, self._states[last_label], self._transitions[last_label]) 70 except: 71 smach.logerr("Attempting to construct smach state sequence failed.") 72 73 #print self._transitions[self._last_added_seq_label] 74 75 # Store the last added state label 76 self._last_added_seq_label = label 77 78 return smach.StateMachine.add(label, state, transitions, remapping)
79