Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved parsing of parallel states #19

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/scxml_interpreter/scxml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ def convert_to_concurence_map(cond):
list_ = cond_or.split('.')
map_list.append({list_[0]: list_[1]})
else:
map_ = {}
for cond_and in cond_.split(' AND '):
list_and = cond_and.split('.')
map_[list_and[0]] = list_and[1]
map_list.append(map_)
map_list.append({list_and[0]: list_and[1]})
return map_list


Expand Down Expand Up @@ -68,27 +66,25 @@ def convert_transitions(self, xml_node, state_id):

def convert_parallel_transitions(self, xml_node, state_id):
transitions = {}
default = None
default = "failed"
outcome_map = {}
for transition in xml_node.findall('transition'):
event = transition.attrib.get('event')
target = transition.attrib.get('target')
cond = transition.attrib.get('cond')
if (event == "default"):
default = target
transitions["default"] = default
continue
if (event is None):
raise KeyError("No Transition Event for %s !" % state_id)
if (target is None):
raise KeyError("No Transition Target for %s !" % state_id)
if (cond is None):
raise KeyError("No Transition Condition for %s !" % state_id)

map_list = convert_to_concurence_map(cond)
for map_ in map_list:
outcome_map[event] = map_
if event != default and event not in transitions.keys():
raise KeyError("No Transition Condition for %s !" % state_id)
else:
map_list = convert_to_concurence_map(cond)
outcome_map[event] = map_list
transitions[event] = target
if (event == default and (default not in transitions.keys())):
transitions[default] = default
if default is None:
rospy.logwarn("No default outcome defined for Parallel %s !" % state_id)
return transitions, default, outcome_map
Expand Down
2 changes: 1 addition & 1 deletion src/scxml_interpreter/smach_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def create_compound_state(self, state_interface):

def create_parallel_state(self, state_interface):
return smach.Concurrence(state_interface.get_outcomes(),
default_outcome="default",
default_outcome="failed",
outcome_map=state_interface.outcome_map,
)

Expand Down