Example #1
0
    def _create_condition_container(self, node, name='Conditions Group', sequence=None,
                                    maneuver=None, success_on_all=True):
        """
        This is a generic function to handle conditions utilising ConditionGroups
        Each ConditionGroup is represented as a Sequence of Conditions
        The ConditionGroups are grouped under a SUCCESS_ON_ONE Parallel
        """

        parallel_condition_groups = py_trees.composites.Parallel(name,
                                                                 policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)

        for condition_group in node.iter("ConditionGroup"):
            if success_on_all:
                condition_group_sequence = py_trees.composites.Parallel(
                    name="Condition Group", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ALL)
            else:
                condition_group_sequence = py_trees.composites.Parallel(
                    name="Condition Group", policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)
            for condition in condition_group.iter("Condition"):
                criterion = OpenScenarioParser.convert_condition_to_atomic(
                    condition, self.other_actors + self.ego_vehicles)
                if sequence is not None and maneuver is not None:
                    xml_path = get_xml_path(self.config.story, sequence) + '>' + \
                        get_xml_path(maneuver, condition)  # See note in get_xml_path
                else:
                    xml_path = get_xml_path(self.config.story, condition)
                criterion = oneshot_behavior(variable_name=xml_path, behaviour=criterion)
                condition_group_sequence.add_child(criterion)

            if condition_group_sequence.children:
                parallel_condition_groups.add_child(condition_group_sequence)

        return parallel_condition_groups
Example #2
0
    def _create_condition_container(self, node, name='Conditions Group', oneshot=False):
        """
        This is a generic function to handle conditions utilising ConditionGroups
        Each ConditionGroup is represented as a Sequence of Conditions
        The ConditionGroups are grouped under a SUCCESS_ON_ONE Parallel
        If oneshot is set to True, oneshot_behaviour will be applied to conditions
        """

        parallel_condition_groups = py_trees.composites.Parallel(name,
                                                                 policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)

        for condition_group in node.iter("ConditionGroup"):
            condition_group_sequence = py_trees.composites.Sequence(
                name="Condition Group")
            for condition in condition_group.iter("Condition"):
                criterion = OpenScenarioParser.convert_condition_to_atomic(
                    condition, self.other_actors + self.ego_vehicles)
                if oneshot:
                    criterion = oneshot_behavior(criterion)
                condition_group_sequence.add_child(criterion)

            if condition_group_sequence.children:
                parallel_condition_groups.add_child(condition_group_sequence)

        return parallel_condition_groups
    def _create_test_criteria(self):
        """
        A list of all test criteria will be created that is later used
        in parallel behavior tree.
        """
        parallel_criteria = py_trees.composites.Parallel("EndConditions (Criteria Group)",
                                                         policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)

        for condition in self.config.criteria.iter("Condition"):

            criterion = OpenScenarioParser.convert_condition_to_atomic(condition, self.ego_vehicles)
            parallel_criteria.add_child(criterion)

        return parallel_criteria
Example #4
0
    def _create_test_criteria(self):
        """
        A list of all test criteria will be created that is later used
        in parallel behavior tree.
        """
        parallel_criteria = py_trees.composites.Parallel("EndConditions (Criteria Group)",
                                                         policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE)

        criteria = []
        for endcondition in self.config.storyboard.iter("StopTrigger"):
            for condition in endcondition.iter("Condition"):
                if condition.attrib.get('name').startswith('criteria_'):
                    criteria.append(condition)

        for condition in criteria:
            criterion = OpenScenarioParser.convert_condition_to_atomic(condition, self.ego_vehicles)
            parallel_criteria.add_child(criterion)

        return parallel_criteria
    def _create_behavior(self):
        """
        Basic behavior do nothing, i.e. Idle
        """

        story_behavior = py_trees.composites.Sequence("Story")

        for act in self.config.story.iter("Act"):

            if act.attrib.get('name') != 'Behavior':
                continue

            parallel_behavior = py_trees.composites.Parallel(
                policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ONE,
                name="Maneuver + EndConditions Group")

            for sequence in act.iter("Sequence"):
                sequence_behavior = py_trees.composites.Sequence()
                repetitions = sequence.attrib.get('numberOfExecutions', 1)
                actor_ids = []
                for actor in sequence.iter("Actors"):
                    for entity in actor.iter("Entity"):
                        for k, _ in enumerate(self.other_actors):
                            if entity.attrib.get(
                                    'name', None
                            ) == self.config.other_actors[k].rolename:
                                actor_ids.append(k)
                                break

                tmp_sequence_behavior = py_trees.composites.Sequence(
                    name=sequence.attrib.get('name'))
                for maneuver in sequence.iter("Maneuver"):
                    maneuver_sequence = py_trees.composites.Sequence(
                        name="Maneuver " + maneuver.attrib.get('name'))
                    for event in maneuver.iter("Event"):
                        event_sequence = py_trees.composites.Sequence(
                            name="Event " + event.attrib.get('name'))
                        parallel_actions = py_trees.composites.Parallel(
                            policy=py_trees.common.ParallelPolicy.
                            SUCCESS_ON_ALL,
                            name="Actions")
                        for child in event.iter():
                            if child.tag == "Action":
                                for actor_id in actor_ids:
                                    maneuver_behavior = OpenScenarioParser.convert_maneuver_to_atomic(
                                        child, self.other_actors[actor_id])
                                    parallel_actions.add_child(
                                        maneuver_behavior)

                            if child.tag == "StartConditions":
                                # There is always on StartConditions block per Event
                                for condition in child.iter('Condition'):
                                    condition_behavior = OpenScenarioParser.convert_condition_to_atomic(
                                        condition,
                                        self.other_actors + self.ego_vehicles)

                                    condition_behavior.name += " for {}".format(
                                        parallel_actions.name)

                                    if condition_behavior:
                                        event_sequence.add_child(
                                            condition_behavior)

                        event_sequence.add_child(parallel_actions)
                        maneuver_sequence.add_child(event_sequence)
                    tmp_sequence_behavior.add_child(maneuver_sequence)

                for _ in range(int(repetitions)):
                    sequence_behavior.add_child(tmp_sequence_behavior)

                if sequence_behavior.children:
                    parallel_behavior.add_child(sequence_behavior)

            for conditions in act.iter("Conditions"):
                start_condition_behavior = py_trees.composites.Parallel(
                    policy=py_trees.common.ParallelPolicy.SUCCESS_ON_ALL,
                    name="StartConditions Group")
                for start_condition in conditions.iter("Start"):
                    for condition in start_condition.iter('Condition'):
                        condition_behavior = OpenScenarioParser.convert_condition_to_atomic(
                            condition, self.other_actors + self.ego_vehicles)
                        oneshot_idiom = oneshot_behavior(
                            name=condition_behavior.name,
                            variable_name=condition_behavior.name,
                            behaviour=condition_behavior)
                        start_condition_behavior.add_child(oneshot_idiom)
                for end_condition in conditions.iter("End"):
                    for condition in end_condition.iter('Condition'):
                        condition_behavior = OpenScenarioParser.convert_condition_to_atomic(
                            condition, self.other_actors + self.ego_vehicles)
                        parallel_behavior.add_child(condition_behavior)
                for end_condition in conditions.iter("Cancel"):
                    for condition in end_condition.iter('Condition'):
                        condition_behavior = OpenScenarioParser.convert_condition_to_atomic(
                            condition, self.other_actors + self.ego_vehicles)
                        parallel_behavior.add_child(condition_behavior)

            if start_condition_behavior.children:
                story_behavior.add_child(start_condition_behavior)

            if parallel_behavior.children:
                story_behavior.add_child(parallel_behavior)

        # Build behavior tree
        # sequence.add_child(maneuver_behavior)

        return story_behavior