Skip to content

Commit

Permalink
Merge pull request #5 from ipa-bnm/fix/iterator_preemption
Browse files Browse the repository at this point in the history
fixed possible iterator preemption error
  • Loading branch information
Florian Weisshardt committed Jul 3, 2017
2 parents ac6e030 + 3f926f6 commit 9760afa
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions smach/src/smach/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self,
@staticmethod
def 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
Expand All @@ -81,10 +81,10 @@ def set_contained_state(
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.
Expand Down Expand Up @@ -167,14 +167,16 @@ def execute(self, parent_ud):
raise ex
except:
raise smach.InvalidUserCodeError("Could not execute iterator state '%s' of type '%s': " % ( self._state_label, self._state) + traceback.format_exc())



# Check if we should stop preemptively
if self._preempt_requested\
or outcome in self._break_outcomes\
if self.preempt_requested():
self.service_preempt()
outcome = 'preempted'
break;
if outcome in self._break_outcomes\
or (len(self._loop_outcomes) > 0 and outcome not in self._loop_outcomes):
self._preempt_requested = False
break
self.call_transition_cbs()

Expand All @@ -192,10 +194,9 @@ def execute(self, parent_ud):
return outcome

def request_preempt(self):
self._preempt_requested = True
if self._is_running:
self._state.request_preempt()

rospy.loginfo("Preempt requested on iterator")
smach.State.request_preempt(self)

### Container interface
def get_children(self):
return {self._state_label: self._state}
Expand Down Expand Up @@ -229,7 +230,7 @@ def get_active_states(self):

def get_internal_edges(self):
int_edges = []

for outcome in self._loop_outcomes:
int_edges.append([outcome, self._state_label, self._state_label])

Expand Down

0 comments on commit 9760afa

Please sign in to comment.