def main():
    client = actionlib.SimpleActionClient('render_mobility', RenderItemAction)
    client.wait_for_server()

    goal = RenderItemGoal(name='mobility', data='move:home')
    client.send_goal(goal, done_cb=func_done, active_cb=func_active)

    rospy.sleep(2)
    goal = RenderItemGoal(name='mobility', data='stop')
    client.send_goal(goal, done_cb=func_done, active_cb=func_active)
    client.cancel_all_goals()
    # client.wait_for_result()
    rospy.signal_shutdown(0)
def main():
    client = actionlib.SimpleActionClient('render_screen', RenderItemAction)
    client.wait_for_server()

    goal = RenderItemGoal(name='screen', data='show:mainView/{}')
    client.send_goal(goal, done_cb=func_done, active_cb=func_active)

    client.wait_for_result()
    rospy.signal_shutdown(0)
Exemple #3
0
def main():
	client = actionlib.SimpleActionClient('render_facial_expression', RenderItemAction)
	client.wait_for_server()

	goal = RenderItemGoal(name='expression', data="happiness")
	client.send_goal(goal, done_cb=func_done, feedback_cb=func_feedback, active_cb=func_active)

	#rospy.sleep(10)
	#client.cancel_all_goals()

	client.wait_for_result()
	rospy.signal_shutdown(0)
def main():
    client = actionlib.SimpleActionClient('render_gesture', RenderItemAction)
    client.wait_for_server()

    goal = RenderItemGoal(name='gesture', data="gesture=play:sm/open/1")
    client.send_goal(goal,
                     done_cb=func_done,
                     feedback_cb=func_feedback,
                     active_cb=func_active)

    #rospy.sleep(10)
    #client.cancel_all_goals()

    client.wait_for_result()
    rospy.signal_shutdown(0)
def main():
    client = actionlib.SimpleActionClient('render_speech', RenderItemAction)
    client.wait_for_server()

    goal = RenderItemGoal(name='say', data="Hello! My name is silbot3.")
    client.send_goal(goal,
                     done_cb=func_done,
                     feedback_cb=func_feedback,
                     active_cb=func_active)

    #rospy.sleep(10)
    #client.cancel_all_goals()

    client.wait_for_result()
    rospy.signal_shutdown(0)
    def execute_callback(self, goal):
        rospy.loginfo('\033[94m[%s]\033[0m rendering started.' % rospy.get_name())
        result = RenderSceneResult()

        render_scene = json.loads(goal.render_scene)
        render_scene_time = {}
        for k, v in render_scene.items():
            if k != 'emotion' and k != 'br' and v['render'] != '':
                render_scene_time[k] = v['offset']

        try:
            if render_scene['expression'] != {}:
                # render_scene['expression']['render'] = render_scene['expression']['render'].rstrip('~')
                self.return_to_last_expression = False
        except KeyError:
            pass

        delay_time = render_scene['br']['time']

        for i in range(delay_time * 10):
            rospy.sleep(0.1)

        # Sort by delay time
        scene_item_sorted_by_time = sorted(render_scene_time, key=render_scene_time.get)
        print(scene_item_sorted_by_time)
        first_offset_time = render_scene[scene_item_sorted_by_time[0]]['offset']
        rospy.sleep(first_offset_time)

        for i in range(0, len(scene_item_sorted_by_time) - 1):
            if scene_item_sorted_by_time[i] == 'gaze':
                focusing_name = render_scene[scene_item_sorted_by_time[i]]['render']
                self.gazefocus_pub.publish(focusing_name)
            else:
                item_goal = RenderItemGoal()
                item_goal.name = scene_item_sorted_by_time[i]
                item_goal.data = render_scene[scene_item_sorted_by_time[i]]['render']

                # if item_goal.data == '':
                #     continue

                self.render_client[scene_item_sorted_by_time[i]].send_goal(
                    goal=item_goal,
                    done_cb=self.cb_done[scene_item_sorted_by_time[i]],
                    active_cb=self.cb_start[scene_item_sorted_by_time[i]])

                while not rospy.is_shutdown() and not self.is_rendering[scene_item_sorted_by_time[i]]:
                    rospy.sleep(0.01)
                    pass

            delta_time = render_scene[scene_item_sorted_by_time[i+1]]['offset'] - render_scene[scene_item_sorted_by_time[i]]['offset']
            rospy.sleep(delta_time)

        if scene_item_sorted_by_time[-1] == 'gaze':
            focusing_name = render_scene[scene_item_sorted_by_time[-1]]['render']
            self.gazefocus_pub.publish(focusing_name)
        else:
            item_goal = RenderItemGoal()
            item_goal.name = scene_item_sorted_by_time[-1]
            item_goal.data = render_scene[scene_item_sorted_by_time[-1]]['render']

            self.render_client[scene_item_sorted_by_time[-1]].send_goal(
                goal=item_goal,
                done_cb=self.cb_done[scene_item_sorted_by_time[-1]],
                active_cb=self.cb_start[scene_item_sorted_by_time[-1]])

            while not rospy.is_shutdown() and not self.is_rendering[scene_item_sorted_by_time[-1]]:
                rospy.sleep(0.01)
                pass

        while not rospy.is_shutdown():
            rendering = False
            for i in scene_item_sorted_by_time:
                if i != 'gaze':
                    rendering = rendering or self.is_rendering[i]
            if not rendering:
                break
            rospy.sleep(0.1)
        self.gazefocus_pub.publish('')

        if self.return_to_last_expression:
            item_goal = RenderItemGoal()
            item_goal.name = 'expression'
            item_goal.data = render_scene['emotion']['current_emotion']
            self.render_client['expression'].send_goal(
                goal=item_goal,
                done_cb=self.cb_done['expression'],
                active_cb=self.cb_start['expression'])

            while not rospy.is_shutdown() and not self.is_rendering['expression']:
                rospy.sleep(0.01)
            while not rospy.is_shutdown() and self.is_rendering['expression']:
                rospy.sleep(0.01)
            self.return_to_last_expression = False

        '''
        if goal.emotion == 'neutral':
        self.pub_face_emotion.publish(
            SetFacialExpression.NEUTRAL, goal.emotion_intensity)
        elif goal.emotion == 'happiness':
        self.pub_face_emotion.publish(
            SetFacialExpression.HAPPINESS, goal.emotion_intensity)
        elif goal.emotion == 'surprise':
        self.pub_face_emotion.publish(
            SetFacialExpression.HAPPINESS, goal.emotion_intensity)
        elif goal.emotion == 'anger':
        self.pub_face_emotion.publish(
            SetFacialExpression.HAPPINESS, goal.emotion_intensity)
        elif goal.emotion == 'sadness':
        self.pub_face_emotion.publish(
            SetFacialExpression.HAPPINESS, goal.emotion_intensity)
        elif goal.emotion == 'disgust':
        self.pub_face_emotion.publish(
            SetFacialExpression.HAPPINESS, goal.emotion_intensity)
        elif goal.emotion == 'fear':
        self.pub_face_emotion.publish(
            SetFacialExpression.HAPPINESS, goal.emotion_intensity)

        if goal.gesture != '':
        # When robot requested play gesture, the idle motion is disabled temporary
        self.is_playing_now = True

        # print goal.gesture
        recv_data = goal.gesture.split(':')
        if recv_data[0] == 'sm':
        # print recv_data
        if recv_data[1] in self.motion_tag:
        gesture_name = self.motion_tag[recv_data[1]][
            random.randrange(0, len(self.motion_tag[recv_data[1]]))]
        else:
        gesture_name = recv_data[1]
        elif recv_data[0] == 'pm':
        gesture_name = recv_data[1]

        gesture_goal = GestureActionGoal(gesture=gesture_name)
        self.gesture_client.send_goal(goal=gesture_goal, done_cb=self.gesture_done_cb,
                                      feedback_cb=self.gesture_playing_cb, active_cb=self.gesture_start_cb)

        # rospy.sleep(2)

        if goal.say != '':
        # When robot is speaking, the speech_recognition is disabled temporary
        self.is_speaking_now = True
        self.is_gesture_only = False
        speech_goal = SpeechActionGoal(say=goal.say)
        self.speech_client.send_goal(goal=speech_goal, done_cb=self.speech_done_cb,
                                     feedback_cb=self.speech_speaking_cb, active_cb=self.speech_start_cb)
        else:
        # Gesture Only
        self.is_gesture_only = True

        while self.is_speaking_now or self.is_playing_now:
        # rospy.logwarn('%d %d'%(self.is_speaking_now, self.is_playing_now))

        if self.is_gesture_only:
        rospy.sleep(0.2)
        continue

        if not self.is_speaking_now and self.is_playing_now:
        self.sync_count_gesture += 1
        if self.sync_count_gesture > 3:
        self.gesture_client.cancel_all_goals()
        self.sync_count_gesture = 0

        rospy.sleep(0.2)

        self.pub_face_emotion.publish(SetFacialExpression.PREVIOUS_FACE, 1.0)
        '''
        rospy.loginfo('\033[94m[%s]\033[0m rendering completed.' % rospy.get_name())

        result.result = True
        self.server.set_succeeded(result)