def test_parse_say_to(self): valid_gestures = ['wave', 'point'] goal_actual = SayToParser.parse_say_to("Hello I am a robot", 1, valid_gestures, tts_duration_srv) goal_expected = SayToGoal() goal_expected.text = "Hello I am a robot" goal_expected.gestures = [] goal_expected.gesture_indicies = [] goal_expected.audience_id = 1 self.assertEqual(goal_actual, goal_expected) goal_actual_1 = SayToParser.parse_say_to("<wave>Hello I am a robot</wave>", 1, valid_gestures, tts_duration_srv) goal_expected_1 = SayToGoal() goal_expected_1.text = "Hello I am a robot" wave = GestureGoal() wave.type = 'wave' wave.duration = 1.0 goal_expected_1.gestures = [wave] goal_expected_1.gesture_indicies = [0] goal_expected_1.audience_id = 1 self.assertEqual(goal_actual_1, goal_expected_1) self.assertRaises(GestureDoesNotExistError, SayToParser.parse_say_to, "<nod>Hello I am a robot</nod>", 1, valid_gestures, tts_duration_srv) self.assertRaises(TypeError, SayToParser.parse_say_to, "<nod>Hello I am a robot</nod>", 'hello', valid_gestures, tts_duration_srv) self.assertRaises(TypeError, SayToParser.parse_say_to, "<nod>Hello I am a robot</nod>", 1, 1, tts_duration_srv) self.assertRaises(TypeError, SayToParser.parse_say_to, "<nod>Hello I am a robot</nod>", 1, valid_gestures, '1')
def __init__(self, gesture, duration=Default(), target=None, feedback_cb=None, done_cb=None): """ Makes the robot perform a gesture, e.g. make a robot wave its left arm. The default values for the duration of each gesture are specified in the robots IGesture enumeration definition. :param gesture: the gesture to perform, an IGesture Python enumeration member e.g. for Nao, Gesture.WaveLArm. :type gesture: IGesture :param duration: the length of time the gesture plays for (seconds). If Default then the gesture is performed for its default duration. Use positive infinity for a never ending gesture, hint: float('inf') :type duration: float, Default :param target: the target to orient the gesture toward :type target: None, Entity :param feedback_cb: a function that will be called when the state of the gesture action changes. The function should have one parameter, which will be filled with a GestureActionFeedback instance. :type feedback_cb: Callable :param done_cb: a function that will be called when the gesture action finishes. :type done_cb: Callable :return: an action handle to keep track of the action :rtype: MultiGoalActionHandle :raises TypeError: gesture is not an IGesture member, duration is not a float or Default, target is not None or an Entity, feedback_cb is not None or Callable, done_cb is not None or Callable """ TypeChecker.accepts(inspect.currentframe().f_code.co_name, (IGesture, (Default, float), (None, Entity), (None, Callable), (None, Callable)), gesture, duration, feedback_cb, done_cb) IGestureGoal.__init__(self) self.gesture = gesture.name if duration is Default: self.duration = gesture.default_duration else: self.duration = duration self.target = target self.feedback_cb = feedback_cb self.done_cb = done_cb
def gesture(self, gesture, target=None, duration=None): if not self.gesture_found: self.wait_for_action_servers(self.gesture_client) self.gesture_found = True ParamFormatting.assert_types(self.gesture, gesture, IGesture) goal = GestureGoal() goal.gesture = gesture.name if target is None: goal.target = '' else: World().add_to_world(target) ParamFormatting.assert_types(self.gesture, target, Entity) goal.target = target.get_id() 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.gesture_client.send_goal(goal, done_cb=self.gesture_done) ah = MultiGoalActionHandle(self.gesture_client, gh) self.add_action_handle(ah) return ah
def gesture(self, gesture, target=None, duration=None): if not self.gesture_found: self.wait_for_action_servers(self.gesture_client) self.gesture_found = True ParamFormatting.assert_types(self.gesture, gesture, IGesture) goal = GestureGoal() goal.gesture = gesture.name if target is None: goal.target = "" else: World().add_to_world(target) ParamFormatting.assert_types(self.gesture, target, Entity) goal.target = target.get_id() 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.gesture_client.send_goal(goal, done_cb=self.gesture_done) ah = MultiGoalActionHandle(self.gesture_client, gh) self.add_action_handle(ah) return ah
def test_parse_say_to(self): valid_gestures = ['wave', 'point'] goal_actual = SayToParser.parse_say_to("Hello I am a robot", 1, valid_gestures, tts_duration_srv) goal_expected = SayToGoal() goal_expected.text = "Hello I am a robot" goal_expected.gestures = [] goal_expected.gesture_indicies = [] goal_expected.audience_id = 1 self.assertEqual(goal_actual, goal_expected) goal_actual_1 = SayToParser.parse_say_to( "<wave>Hello I am a robot</wave>", 1, valid_gestures, tts_duration_srv) goal_expected_1 = SayToGoal() goal_expected_1.text = "Hello I am a robot" wave = GestureGoal() wave.type = 'wave' wave.duration = 1.0 goal_expected_1.gestures = [wave] goal_expected_1.gesture_indicies = [0] goal_expected_1.audience_id = 1 self.assertEqual(goal_actual_1, goal_expected_1) self.assertRaises(GestureDoesNotExistError, SayToParser.parse_say_to, "<nod>Hello I am a robot</nod>", 1, valid_gestures, tts_duration_srv) self.assertRaises(TypeError, SayToParser.parse_say_to, "<nod>Hello I am a robot</nod>", 'hello', valid_gestures, tts_duration_srv) self.assertRaises(TypeError, SayToParser.parse_say_to, "<nod>Hello I am a robot</nod>", 1, 1, tts_duration_srv) self.assertRaises(TypeError, SayToParser.parse_say_to, "<nod>Hello I am a robot</nod>", 1, valid_gestures, '1')
def serialize(self, buff): if self.duration < 0.0: rospy.logwarn("GestureGoal duration value of {0} is out of range, clipping to normal bounds: duration > 0".format(self.duration)) self.duration = max(0.0, self.duration) IGestureGoal.serialize(buff)
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 + " "