예제 #1
0
파일: robot.py 프로젝트: jdddog/hri
    def expression(self, expression, intensity=None, speed=None, duration=None):
        if not self.expression_found:
            self.wait_for_action_servers(self.expression_client)
            self.expression_found = True

        ParamFormatting.assert_types(self.expression, expression, IExpression)

        goal = ExpressionGoal()
        goal.expression = expression.name

        if intensity is None:
            goal.intensity = -1
        else:
            ParamFormatting.assert_types(self.expression, intensity, float)
            ParamFormatting.assert_range(self.expression, intensity, 0.0, 1.0)
            goal.intensity = intensity

        if speed is None:
            goal.speed = -1
        else:
            ParamFormatting.assert_types(self.expression, speed, float)
            ParamFormatting.assert_range(self.expression, speed, 0.0, 1.0)
            goal.speed = speed

        if duration is None:
            goal.duration = -1
        else:
            ParamFormatting.assert_types(self.expression, duration, float)
            ParamFormatting.assert_greater_than(self.expression, duration, 0.0)
            goal.duration = duration

        gh = self.expression_client.send_goal(goal, done_cb=self.expression_done)
        ah = MultiGoalActionHandle(self.expression_client, gh)
        self.add_action_handle(ah)
        return ah
예제 #2
0
파일: robot.py 프로젝트: jdddog/hri
    def expression(self, expression, intensity=None, speed=None, duration=None):
        if not self.expression_found:
            self.wait_for_action_servers(self.expression_client)
            self.expression_found = True

        ParamFormatting.assert_types(self.expression, expression, IExpression)

        goal = ExpressionGoal()
        goal.expression = expression.name

        if intensity is None:
            goal.intensity = -1
        else:
            ParamFormatting.assert_types(self.expression, intensity, float)
            ParamFormatting.assert_range(self.expression, intensity, 0.0, 1.0)
            goal.intensity = intensity

        if speed is None:
            goal.speed = -1
        else:
            ParamFormatting.assert_types(self.expression, speed, float)
            ParamFormatting.assert_range(self.expression, speed, 0.0, 1.0)
            goal.speed = speed

        if duration is None:
            goal.duration = -1
        else:
            ParamFormatting.assert_types(self.expression, duration, float)
            ParamFormatting.assert_greater_than(self.expression, duration, 0.0)
            goal.duration = duration

        gh = self.expression_client.send_goal(goal, done_cb=self.expression_done)
        ah = MultiGoalActionHandle(self.expression_client, gh)
        self.add_action_handle(ah)
        return ah
예제 #3
0
파일: robot.py 프로젝트: jdddog/hri
    def parse_parameters(self, text, audience, expression_enum, gesture_enum, tts_duration_srv):
        self.reset()
        self.audience = audience

        ParamFormatting.assert_types(self.parse_parameters, text, str)
        ParamFormatting.assert_types(self.parse_parameters, audience, Entity, Query)

        # if not is_callable(tts_duration_srv):
        #     raise TypeError("parse_parameters() parameter tts_duration_srv={0} is not callable".format(tts_duration_srv))

        self.sentence = SayToPlan.get_sentence(text)  # Get sentence
        self.gaze_change_locations = SayToPlan.get_gaze_change_locations(self.sentence)

        # Get expressions and gestures
        xml_tree = ET.fromstring("<sayto>" + text + "</sayto>")
        seen_text = ''

        for node in xml_tree.iter():
            if node.tag == "sayto":
                if node.text is not None:
                    seen_text += node.text + " "
            else:
                start_word_i = SayToPlan.num_words(seen_text)

                if node.text is not None:
                    seen_text += node.text + " "

                end_word_i = SayToPlan.num_words(seen_text)

                goal_name = node.tag

                if SayToPlan.enum_contains(expression_enum, goal_name):
                    goal = ExpressionGoal()
                    goal.expression = goal_name
                    goal.intensity = 0.5
                    goal.speed = 0.5

                    if 'intensity' in node.attrib:
                        goal.intensity = float(node.attrib["intensity"])

                    if 'speed' in node.attrib:
                        goal.speed = float(node.attrib["speed"])

                    goal.duration = tts_duration_srv(self.sentence, start_word_i, end_word_i).duration
                    self.expression_lookup[start_word_i] = goal

                elif SayToPlan.enum_contains(gesture_enum, goal_name):
                    goal = GestureGoal()
                    goal.gesture = goal_name

                    if 'target' in node.attrib:     # Check if target is Entity
                        goal.target = node.attrib["target"]
                    else:
                        raise AttributeError('Please specify a target attribute for {0} gesture'.format(goal_name))

                    goal.duration = tts_duration_srv(self.sentence, start_word_i, end_word_i).duration
                    self.gesture_lookup[start_word_i] = goal

                else:
                    raise TypeError('No gesture or expression called: {0}'.format(goal_name))

                if node.tail is not None:
                    seen_text += node.tail + " "
예제 #4
0
파일: robot.py 프로젝트: jdddog/hri
    def parse_parameters(self, text, audience, expression_enum, gesture_enum, tts_duration_srv):
        self.reset()
        self.audience = audience

        ParamFormatting.assert_types(self.parse_parameters, text, str)
        ParamFormatting.assert_types(self.parse_parameters, audience, Entity, Query)

        # if not is_callable(tts_duration_srv):
        #     raise TypeError("parse_parameters() parameter tts_duration_srv={0} is not callable".format(tts_duration_srv))

        self.sentence = SayToPlan.get_sentence(text)  # Get sentence
        self.gaze_change_locations = SayToPlan.get_gaze_change_locations(self.sentence)

        # Get expressions and gestures
        xml_tree = ET.fromstring("<sayto>" + text + "</sayto>")
        seen_text = ""

        for node in xml_tree.iter():
            if node.tag == "sayto":
                if node.text is not None:
                    seen_text += node.text + " "
            else:
                start_word_i = SayToPlan.num_words(seen_text)

                if node.text is not None:
                    seen_text += node.text + " "

                end_word_i = SayToPlan.num_words(seen_text)

                goal_name = node.tag

                if SayToPlan.enum_contains(expression_enum, goal_name):
                    goal = ExpressionGoal()
                    goal.expression = goal_name
                    goal.intensity = 0.5
                    goal.speed = 0.5

                    if "intensity" in node.attrib:
                        goal.intensity = float(node.attrib["intensity"])

                    if "speed" in node.attrib:
                        goal.speed = float(node.attrib["speed"])

                    goal.duration = tts_duration_srv(self.sentence, start_word_i, end_word_i).duration
                    self.expression_lookup[start_word_i] = goal

                elif SayToPlan.enum_contains(gesture_enum, goal_name):
                    goal = GestureGoal()
                    goal.gesture = goal_name

                    if "target" in node.attrib:  # Check if target is Entity
                        goal.target = node.attrib["target"]
                    else:
                        raise AttributeError("Please specify a target attribute for {0} gesture".format(goal_name))

                    goal.duration = tts_duration_srv(self.sentence, start_word_i, end_word_i).duration
                    self.gesture_lookup[start_word_i] = goal

                else:
                    raise TypeError("No gesture or expression called: {0}".format(goal_name))

                if node.tail is not None:
                    seen_text += node.tail + " "