Ejemplo n.º 1
0
    def __init__(self, server_ip, robot, dialogflow_key_file, dialogflow_agent_id):
        self.sic = BasicSICConnector(server_ip, robot, dialogflow_key_file, dialogflow_agent_id)
        self.action_runner = ActionRunner(self.sic)

        self.user_model = {}
        self.recognition_manager = {'attempt_success': False,
                                    'attempt_number': 0}
Ejemplo n.º 2
0
class Example:
    """For this example you will need to turn on the PeopleDetection and FaceRecognition services."""
    def __init__(self, server_ip: str):
        self.sic = BasicSICConnector(server_ip)

    def run(self) -> None:
        self.sic.start()
        action_runner = ActionRunner(self.sic)

        action_runner.run_waiting_action('set_language', 'en-US')
        action_runner.run_waiting_action('set_idle')
        action_runner.run_vision_listener('people',
                                          self.i_spy_with_my_little_eye, False)
        action_runner.run_waiting_action('say', 'Hello, I see you')

        action_runner.run_vision_listener('face', self.face_recognition, True)
        sleep(10)

        self.sic.stop()

    @staticmethod
    def i_spy_with_my_little_eye() -> None:
        print('I see someone!')

    @staticmethod
    def face_recognition(identifier: str) -> None:
        print('I recognize you as face #' + identifier)
Ejemplo n.º 3
0
class Example:
    """For this example you will need to turn on the PeopleDetection and FaceRecognition services on the
    Social Interaction Cloud webportal"""

    def __init__(self, server_ip, robot):
        self.sic = BasicSICConnector(server_ip, robot)

    def run(self):
        self.sic.start()
        action_runner = ActionRunner(self.sic)

        action_runner.run_waiting_action('set_language', 'en-US')
        action_runner.run_vision_listener('people', self.i_spy_with_my_little_eye, False)
       # action_runner.run_waiting_action('say', 'Hello, I see you')

        action_runner.run_vision_listener('face', self.face_recognition, True)
        time.sleep(10)

        self.sic.stop()

    def i_spy_with_my_little_eye(self):
        print("I see someone!")

    def face_recognition(self, identifier):
        print(identifier)
        if identifier != '0':
            print(">>>>>>>>>>I recognize you as " + identifier)
        else:
            print(">>>>>>>>>>I don't recognize you")
Ejemplo n.º 4
0
class Example:
    def __init__(self, server_ip: str):
        self.sic = BasicSICConnector(server_ip)

    def run(self) -> None:
        self.sic.start()
        action_runner = ActionRunner(self.sic)

        action_runner.run_waiting_action('wake_up')
        action_runner.run_waiting_action('set_language', 'en-US')

        action_runner.load_waiting_action('say', 'I\'m going to crouch now.')
        action_runner.load_waiting_action(
            'go_to_posture',
            RobotPosture.CROUCH,
            additional_callback=self.posture_callback)
        action_runner.run_loaded_actions()

        action_runner.load_waiting_action('say', 'I\'m going to stand now.')
        action_runner.load_waiting_action(
            'go_to_posture',
            RobotPosture.STAND,
            additional_callback=self.posture_callback)
        action_runner.run_loaded_actions()

        action_runner.run_waiting_action('rest')

        self.sic.stop()

    @staticmethod
    def posture_callback(success: bool) -> None:
        print('It worked!' if success else 'It failed...')
class Example:
    """Example that uses speech recognition. Prerequisites are the availability of a dialogflow_key_file,
    a dialogflow_agent_id, and a running Dialogflow service. For help meeting these Prerequisites see
    https://socialrobotics.atlassian.net/wiki/spaces/CBSR/pages/260276225/The+Social+Interaction+Cloud+Manual"""
    def __init__(self, server_ip, robot, dialogflow_key_file,
                 dialogflow_agent_id):
        self.sic = BasicSICConnector(server_ip, robot, dialogflow_key_file,
                                     dialogflow_agent_id)

        self.user_model = {}

    def run(self):
        self.sic.start()
        action_runner = ActionRunner(self.sic)
        action_runner.load_waiting_action('set_language', 'en-US')
        action_runner.load_waiting_action('wake_up')
        action_runner.run_loaded_actions()

        action_runner.run_waiting_action('say',
                                         'Hi I am Nao. What is your name?')
        action_runner.run_waiting_action('speech_recognition',
                                         'answer_name',
                                         3,
                                         additional_callback=self.on_intent)
        action_runner.run_waiting_action(
            'say', 'Nice to meet you ' + self.user_model['name'])

        action_runner.run_waiting_action('rest')
        self.sic.stop()

    def on_intent(self, intent_name, *args):
        if intent_name == 'answer_name' and len(args) > 0:
            self.user_model['name'] = args[0]
class Example:
    """Example that uses speech recognition. Prerequisites are the availability of a dialogflow_key_file,
    a dialogflow_agent_id, and a running Dialogflow service. For help meeting these Prerequisites see
    https://socialrobotics.atlassian.net/wiki/spaces/CBSR/pages/260276225/The+Social+Interaction+Cloud+Manual"""
    def __init__(self, server_ip: str, dialogflow_key_file: str,
                 dialogflow_agent_id: str):
        self.sic = BasicSICConnector(server_ip, 'en-US', dialogflow_key_file,
                                     dialogflow_agent_id)
        self.action_runner = ActionRunner(self.sic)

        self.user_model = {}
        self.recognition_manager = {
            'attempt_success': False,
            'attempt_number': 0
        }

    def run(self) -> None:
        self.sic.start()

        self.action_runner.load_waiting_action('set_language', 'en-US')
        self.action_runner.load_waiting_action('wake_up')
        self.action_runner.run_loaded_actions()

        while not self.recognition_manager[
                'attempt_success'] and self.recognition_manager[
                    'attempt_number'] < 2:
            self.action_runner.run_waiting_action(
                'say', 'Hi I am Nao. What is your name?')
            self.action_runner.run_waiting_action(
                'speech_recognition',
                'answer_name',
                3,
                additional_callback=self.on_intent)
        self.reset_recognition_management()

        if 'name' in self.user_model:
            self.action_runner.run_waiting_action(
                'say', 'Nice to meet you ' + self.user_model['name'])
        else:
            self.action_runner.run_waiting_action('say', 'Nice to meet you')

        self.action_runner.run_waiting_action('rest')
        self.sic.stop()

    def on_intent(self, detection_result: DetectionResult) -> None:
        if detection_result and detection_result.intent == 'answer_name' and len(
                detection_result.parameters) > 0:
            self.user_model['name'] = detection_result.parameters[
                'name'].struct_value['name']
            self.recognition_manager['attempt_success'] = True
        else:
            self.recognition_manager['attempt_number'] += 1

    def reset_recognition_management(self) -> None:
        self.recognition_manager.update({
            'attempt_success': False,
            'attempt_number': 0
        })
 def __init__(self, server_ip, dialogflow_key_file, dialogflow_agent_id):
     """
     :param server_ip: IP address of Social Interaction Cloud server
     :param dialogflow_key_file: path to Google's Dialogflow key file (JSON)
     :param dialogflow_agent_id: ID number of Dialogflow agent to be used (project ID)
     """
     self.sic = BasicSICConnector(
         server_ip, 'en-US', dialogflow_key_file, dialogflow_agent_id)
     self.conversation = Conversation(self.sic, robot_present=True, animation=True)
     self.story = Story(interactive=True)
class StateMachineExample(object):
    def __init__(self, server_ip, robot, dialogflow_key_file,
                 dialogflow_agent_id):
        self.sic = BasicSICConnector(server_ip, robot, dialogflow_key_file,
                                     dialogflow_agent_id)
        self.sic.start()
        self.robot = ExampleRobot(self.sic)

    def run(self):
        self.robot.start()
        self.sic.stop()
Ejemplo n.º 9
0
    def __init__(self, server_ip, robot, dialogflow_key_file,
                 dialogflow_agent_id):
        self.sic = BasicSICConnector(server_ip, robot, dialogflow_key_file,
                                     dialogflow_agent_id)
        self.action_runner = ActionRunner(self.sic)

        self.user_model = {
            'move_number': 1,
            'continue_move': False,
            'complete_dance': True
        }
        self.recognition_manager = {
            'attempt_success': False,
            'attempt_number': 0
        }

        self.show_questions = [
            'Laten we deze stap samen nog een keer herhalen',
            'Kun jij die stap nu doen? Ik doe met je mee',
            'Nog een keer, nu doe je mee!',
            'Probeer jij die nu samen met mij maar na te doen. ',
            'Laten we m samen nog een keer doen',
            'Deze stap oefenen we ook nog maar even samen'
        ]
        self.repeat_questions = [
            'Dat voelt goed! Wil je deze stap nog een keer zien?',
            'We zijn lekker bezig, wil je het nog een keer zien?',
            'Voelt goed als je meedoet! Zal ik deze stap nog een keer herhalen?',
            'Volgens mij kun jij het wel. Wil je het pasje nog een keer zien?'
        ]
        self.continue_phrases = [
            'Oke, door naar de volgende stap! Komt ie',
            'Yes, dan gaan we door! Ga ik weer', 'Op naar de volgende stap!',
            'Alright, hier komt de volgende stap',
            'Oke, door naar de volgende danspas!'
        ]
        self.repeat_phrases = [
            'Oke, ik doe m nog een keer voor, daarna mag jij m weer herhalen.',
            'Ik ga m nog een keer voor je laten zien, daarna doe jij hem weer na toch?',
            'Oke, ik zal de stap opnieuw laten zien, Daarna kan jij m weer oefenen.'
        ]

        self.action_runner = ActionRunner(self.sic)

        self.total_nr_moves = 10
class Example:

    def __init__(self, server_ip, robot, dialogflow_key_file, dialogflow_agent_id):
        self.sic = BasicSICConnector(server_ip, robot, dialogflow_key_file, dialogflow_agent_id)
        self.action_runner = ActionRunner(self.sic)

        self.user_model = {'move_number': 1,
                           'continue_move' : False,
                           'complete_dance': True}
        self.recognition_manager = {'attempt_success': False,
                                    'attempt_number': 0}

        self.action_runner = ActionRunner(self.sic)


    def practice(self):
        self.sic.start()

        self.action_runner.load_waiting_action('set_language', 'nl-NL')
        self.action_runner.load_waiting_action('wake_up')
        self.action_runner.run_loaded_actions()

        while not self.recognition_manager['attempt_success'] and self.recognition_manager['attempt_number'] < 2:
            self.action_runner.run_waiting_action('say', 'Hoi Ik ben Nao. Hoe heet jij?')
            self.action_runner.run_waiting_action('speech_recognition', 'answer_name', 3, additional_callback=self.on_name)
        self.reset_recognition_management()

        if 'name' in self.user_model:
            self.action_runner.run_waiting_action('say', 'Leuk je te ontmoeten' + self.user_model['name'])
        else:
            self.action_runner.run_waiting_action('say', 'Leuk je te ontmoeten!')

        self.action_runner.run_waiting_action('rest')
        self.sic.stop()

    def on_name(self, intent_name, *args):
        if intent_name == 'answer_name' and len(args) > 0:
            self.user_model['name'] = args[0]
            self.recognition_manager['attempt_success'] = True
        elif intent_name == 'fail':
            self.recognition_manager['attempt_number'] += 1

    def reset_recognition_management(self):
        self.recognition_manager.update({'attempt_success': False,
                                         'attempt_number': 0})
class Example:
    def __init__(self, server_ip: str):
        self.sic = BasicSICConnector(server_ip)
        self.action_runner = ActionRunner(self.sic)
        self.motion = None

    def run(self) -> None:
        self.sic.start()

        joints = ['RArm']
        self.action_runner.load_waiting_action('set_language', 'en-US')
        self.action_runner.load_waiting_action('wake_up')
        self.action_runner.run_loaded_actions()

        self.action_runner.run_waiting_action('set_stiffness', joints, 0)
        self.action_runner.load_waiting_action(
            'say', 'You can now move my right arm.')
        self.action_runner.load_waiting_action('start_record_motion', joints)
        self.action_runner.run_loaded_actions()
        sleep(5)
        self.action_runner.load_waiting_action(
            'stop_record_motion',
            additional_callback=self.retrieve_recorded_motion)
        self.action_runner.load_waiting_action('say', 'Finished recording')
        self.action_runner.run_loaded_actions()

        self.action_runner.run_waiting_action('set_stiffness', joints, 100)
        if self.motion:
            self.action_runner.run_waiting_action(
                'say', 'I will now replay your movement')
            self.action_runner.run_waiting_action('play_motion', self.motion)
        else:
            self.action_runner.run_waiting_action('say',
                                                  'Something went wrong.')

        self.action_runner.run_waiting_action('rest')
        self.sic.stop()

    def retrieve_recorded_motion(self, motion) -> None:
        self.motion = motion
class Storyteller:
    """
    Represents the logic guiding conversations between a robot and a human.
    """
    def __init__(self, server_ip, dialogflow_key_file, dialogflow_agent_id):
        """
        :param server_ip: IP address of Social Interaction Cloud server
        :param dialogflow_key_file: path to Google's Dialogflow key file (JSON)
        :param dialogflow_agent_id: ID number of Dialogflow agent to be used (project ID)
        """
        self.sic = BasicSICConnector(server_ip, 'en-US', dialogflow_key_file,
                                     dialogflow_agent_id)
        self.conversation = Conversation(self.sic,
                                         robot_present=True,
                                         animation=False)
        self.story = Story(interactive=False)

    def run(self) -> None:
        """
        Start the social interaction cloud and a conversation.
        :return:
        """
        self.sic.start()
        self.conversation.introduce(interaction=False)
        self.sic.subscribe_touch_listener('MiddleTactilTouched',
                                          self.conversation.detect_stop)

        # START STORY
        part = None
        branch_option = None
        while True:
            if self.conversation.stop:
                break

            part = self.story.getFollowUp(part, branch_option)
            if (part is None):
                break

            storypart = part.content
            self.conversation.tell_story_part(Storypart.format(
                storypart, self.conversation.user_model, part.id),
                                              movement=part.movement,
                                              movement_type=part.movement_type,
                                              eye_color=part.eye_color,
                                              soundfile=part.soundfile)

        self.conversation.end_conversation()
        self.sic.stop()
class Storyteller:
    """
    Represents the logic guiding conversations between a robot and a human.
    """

    def __init__(self, server_ip, dialogflow_key_file, dialogflow_agent_id):
        """
        :param server_ip: IP address of Social Interaction Cloud server
        :param dialogflow_key_file: path to Google's Dialogflow key file (JSON)
        :param dialogflow_agent_id: ID number of Dialogflow agent to be used (project ID)
        """
        self.sic = BasicSICConnector(
            server_ip, 'en-US', dialogflow_key_file, dialogflow_agent_id)
        self.conversation = Conversation(self.sic, robot_present=True, animation=True)
        self.story = Story(interactive=True)

    def run(self) -> None:
        """
        Start the social interaction cloud and a conversation.
        :return:
        """
        self.sic.start()
        self.conversation.introduce(interaction=True)
        self.sic.subscribe_touch_listener(
            'MiddleTactilTouched', self.conversation.detect_stop)

        path = self.conversation.ask_question(
            "Do you want to hear a story or a joke?", intent="joke_path")
        while path == ReturnType.SUCCESS and self.conversation.current_choice == "joke":
            # tell joke
            joke = self.conversation.get_joke()
            for joke_part in joke:
                self.conversation.tell_story_part(text=joke_part)
            path = self.conversation.ask_question(
                "Do you want to hear a story or another joke?", intent="joke_path")
            pass

        # START STORY
        part = None
        branch_option = None
        while True:
            if self.conversation.stop:
                break

            part = self.story.getFollowUp(part, branch_option)
            if (part is None):
                break

            if part.type == "question":
                question, intent, expected_answer = part.content
                res = self.conversation.ask_question(question=Storypart.format(question, user_model=self.conversation.user_model, story_part_id=part.id),
                                                     intent=Storypart.format(
                                                         intent, user_model=self.conversation.user_model, story_part_id="intent_" + part.id),
                                                     expected_answer=Storypart.format(expected_answer, user_model=self.conversation.user_model,
                                                                                      story_part_id="answer_" + part.id))
                if res == ReturnType.STOP:
                    break
                elif res == ReturnType.MAX_ATTEMPTS:
                    self.conversation.tell_story_part(
                        "Sorry, I did not understand your answer.")

                    # TODO ask for repetetion or ending through fist bump
                    # res = self.conversation.ask_question(question, intent)
                    # last_choice = self.conversation.current_choice
                    # self.sic.subscribe_touch_listener(
                    #     'HandRightBackTouched', lambda: self.conversation.set_current_choice(0))
                    # self.sic.subscribe_touch_listener(
                    #     'HandLeftBackTouched', lambda: self.conversation.set_current_choice(1))
                    # self.conversation.request_choice(
                    #     "To repeat the last part fistbump my right fist. To stop fistbump my left fist.")
                    # while (last_choice == self.conversation.current_choice):
                    #     pass
                    # if last_choice == 0:
                    #     # TODO implement repetition
                    #     pass
                    # elif last_choice == 1:
                    #     break
                elif res == ReturnType.WRONG_ANSWER:
                    branch_option = 0
                elif res == ReturnType.SUCCESS:
                    if expected_answer is not None:
                        branch_option = 1
                    else:
                        branch_option = None

            elif part.type == "storypart":
                storypart = part.content
                self.conversation.tell_story_part(Storypart.format(
                    storypart, self.conversation.user_model, part.id), movement=part.movement, movement_type=part.movement_type, eye_color=part.eye_color, soundfile=part.soundfile)

            elif part.type == "choice":
                self.conversation.current_choice = None
                storypart = part.content

                if self.conversation.robot_present:
                    self.sic.subscribe_touch_listener(
                        'HandRightBackTouched', lambda: self.conversation.set_current_choice(0))
                    self.sic.subscribe_touch_listener(
                        'HandLeftBackTouched', lambda: self.conversation.set_current_choice(1))
                else:
                    self.conversation.current_choice = 1
                    
                self.conversation.request_choice(question=Storypart.format(
                    storypart, self.conversation.user_model, part.id))
                while (self.conversation.current_choice is None):
                    pass
                branch_option = self.conversation.current_choice

            elif part.type == "highfive":
                self.sic.subscribe_touch_listener(
                    'HandLeftLeftTouched', self.conversation.detect_highfive)
                self.sic.subscribe_touch_listener(
                    'HandLeftRightTouched', self.conversation.detect_highfive)

                self.conversation.request_highfive(part.content)


                while (self.conversation.current_choice != 1):
                    pass

        if not self.conversation.stop:
            path = self.conversation.ask_question(
                "Do you want to hear another joke or stop?", intent="joke_path")
            while path == ReturnType.SUCCESS and self.conversation.current_choice == "joke":
                # tell joke
                joke = self.conversation.get_joke()
                for joke_part in joke:
                    self.conversation.tell_story_part(text=joke_part)
                path = self.conversation.ask_question(
                    "Do you want to hear another joke or stop?", intent="joke_path")
                pass

        self.conversation.end_conversation()
        self.sic.stop()
 def __init__(self, server_ip: str):
     self.sic = BasicSICConnector(server_ip)
     self.hello_action_lock = Event()
Ejemplo n.º 15
0
class Main:
    def __init__(self, server_ip, robot, dialogflow_key_file,
                 dialogflow_agent_id):
        self.sic = BasicSICConnector(server_ip, robot, dialogflow_key_file,
                                     dialogflow_agent_id)
        self.action_runner = ActionRunner(self.sic)

        self.user_model = {
            'move_number': 1,
            'continue_move': False,
            'complete_dance': True
        }
        self.recognition_manager = {
            'attempt_success': False,
            'attempt_number': 0
        }

        self.show_questions = [
            'Laten we deze stap samen nog een keer herhalen',
            'Kun jij die stap nu doen? Ik doe met je mee',
            'Nog een keer, nu doe je mee!',
            'Probeer jij die nu samen met mij maar na te doen. ',
            'Laten we m samen nog een keer doen',
            'Deze stap oefenen we ook nog maar even samen'
        ]
        self.repeat_questions = [
            'Dat voelt goed! Wil je deze stap nog een keer zien?',
            'We zijn lekker bezig, wil je het nog een keer zien?',
            'Voelt goed als je meedoet! Zal ik deze stap nog een keer herhalen?',
            'Volgens mij kun jij het wel. Wil je het pasje nog een keer zien?'
        ]
        self.continue_phrases = [
            'Oke, door naar de volgende stap! Komt ie',
            'Yes, dan gaan we door! Ga ik weer', 'Op naar de volgende stap!',
            'Alright, hier komt de volgende stap',
            'Oke, door naar de volgende danspas!'
        ]
        self.repeat_phrases = [
            'Oke, ik doe m nog een keer voor, daarna mag jij m weer herhalen.',
            'Ik ga m nog een keer voor je laten zien, daarna doe jij hem weer na toch?',
            'Oke, ik zal de stap opnieuw laten zien, Daarna kan jij m weer oefenen.'
        ]

        self.action_runner = ActionRunner(self.sic)

        self.total_nr_moves = 10

    def run(self):
        self.sic.start()

        self.action_runner.load_waiting_action('set_language', 'nl-NL')
        self.action_runner.load_waiting_action('wake_up')
        self.action_runner.run_loaded_actions()

        while not self.recognition_manager[
                'attempt_success'] and self.recognition_manager[
                    'attempt_number'] < 2:
            self.action_runner.run_waiting_action(
                'say', 'Hoi Ik ben Nao. Hoe heet jij?')
            self.action_runner.run_waiting_action(
                'speech_recognition',
                'answer_name',
                3,
                additional_callback=self.on_name)
        self.reset_recognition_management()

        if 'name' in self.user_model:
            self.action_runner.run_waiting_action(
                'say', 'Leuk je te ontmoeten' + self.user_model['name'])
        else:
            self.action_runner.run_waiting_action('say',
                                                  'Leuk je te ontmoeten!')

        while not self.recognition_manager[
                'attempt_success'] and self.recognition_manager[
                    'attempt_number'] < 2:
            self.action_runner.run_waiting_action(
                'say', 'Heb je zin om een dans spel te spelen?')
            self.action_runner.run_waiting_action(
                'speech_recognition',
                'answer_yesno',
                3,
                additional_callback=self.on_play_game)

        self.reset_recognition_management()

        if self.user_model['play_game']:
            self.start_game()
        else:
            self.stop_game()

        self.action_runner.run_waiting_action('rest')
        self.sic.stop()

    def on_name(self, intent_name, *args):
        if intent_name == 'answer_name' and len(args) > 0:
            self.user_model['name'] = args[0]
            self.recognition_manager['attempt_success'] = True
        elif intent_name == 'fail':
            self.recognition_manager['attempt_number'] += 1

    def on_play_game(self, intent_name, *args):
        if intent_name == 'answer_yes':
            self.user_model['play_game'] = True
            self.recognition_manager['attempt_success'] = True
        elif intent_name == 'answer_no':
            self.user_model['play_game'] = False
            self.recognition_manager['attempt_success'] = True
        elif intent_name == 'fail':
            self.user_model['play_game'] = True
            self.recognition_manager['attempt_number'] += 1

    def on_continue_move(self, intent_name, *args):
        if intent_name == 'answer_yes':
            self.user_model['continue_move'] = False
            self.recognition_manager['attempt_success'] = True
        elif intent_name == 'answer_no':
            self.user_model['continue_move'] = True
            self.recognition_manager['attempt_success'] = True
        elif intent_name == 'fail':
            self.user_model['continue_move'] = True
            self.recognition_manager['attempt_number'] += 1

    def on_complete_dance(self, intent_name, *args):
        if intent_name == 'answer_yes':
            self.user_model['complete_dance'] = True
            self.recognition_manager['attempt_success'] = True
        elif intent_name == 'answer_no':
            self.user_model['complete_dance'] = False
            self.recognition_manager['attempt_success'] = True
        elif intent_name == 'fail':
            self.user_model['complete_dance'] = False
            self.recognition_manager['attempt_number'] += 1

    def reset_recognition_management(self):
        self.recognition_manager.update({
            'attempt_success': False,
            'attempt_number': 0
        })

    def start_game(self):
        if 'name' in self.user_model:
            self.action_runner.run_waiting_action(
                'say',
                'Top, laten we beginnen dan, ' + self.user_model['name'])
        else:
            self.action_runner.run_waiting_action(
                'say', 'Top, laten we beginnen dan!')

        self.action_runner.run_waiting_action(
            'say',
            'Ik ga je een dans leren, aan het einde kunnen we die samen optreden!'
        )

        self.teach_dance()

    def teach_dance(self):

        self.action_runner.run_waiting_action(
            'say',
            'Oke, ik zal beginnen met je de hele dans te laten zien. Daarna leer ik je stap voor stap de pasjes.'
        )
        self.action_runner.run_waiting_action('do_gesture',
                                              'dances/behavior_1')
        self.action_runner.run_waiting_action(
            'say', 'Dat was de complete dans, laten we beginnen met stap 1!')
        self.action_runner.run_waiting_action(
            'say',
            'Ik start altijd met een openings move, daarna begint de rest van de dans. Deze gaat zo '
        )
        self.action_runner.run_waiting_action('do_gesture',
                                              'dances/openingMove')
        self.action_runner.run_waiting_action(
            'say',
            'Heb je m? Dan gaan we nu door naar de rest van de dans. Hier komt stap 1.'
        )

        while self.user_model['move_number'] < self.total_nr_moves:
            self.action_runner.run_waiting_action(
                'do_gesture',
                'dances/Move' + str(self.user_model['move_number']))
            self.action_runner.run_waiting_action('go_to_posture',
                                                  BasicNaoPosture.STAND)

            self.action_runner.run_waiting_action(
                'say', random.choice(self.show_questions))
            self.action_runner.run_waiting_action(
                'do_gesture',
                'dances/Move' + str(self.user_model['move_number']))
            self.action_runner.run_waiting_action(
                'say', random.choice(self.repeat_questions))
            self.action_runner.run_waiting_action(
                'speech_recognition',
                'answer_yesno',
                3,
                additional_callback=self.on_continue_move)

            if self.user_model['continue_move'] == True:
                self.user_model['move_number'] += 1
                if not self.user_model['move_number'] == self.total_nr_moves:
                    self.action_runner.run_waiting_action(
                        'say', random.choice(self.continue_phrases))

            if self.user_model['continue_move'] == False:
                self.action_runner.run_waiting_action(
                    'say', random.choice(self.repeat_phrases))

        self.action_runner.run_waiting_action(
            'say',
            'Dat waren ze bijna allemaal. Maar een dans is een performance, dus je eindigt natuurlijk met een buiging'
        )
        self.action_runner.run_waiting_action('do_gesture', 'dances/TakeABow')

        self.action_runner.run_waiting_action(
            'say',
            'Nu is ie echt compleet. Laten we de hele dans samen uitvoeren. 1 2 3 4 5 6 7 8'
        )

        while self.user_model['complete_dance'] == True:
            self.action_runner.run_waiting_action('do_gesture',
                                                  'dances/behavior_1')
            self.action_runner.run_waiting_action(
                'say', 'Wil je nog een keer de hele dans doen?')
            self.action_runner.run_waiting_action(
                'speech_recognition',
                'answer_yesno',
                3,
                additional_callback=self.on_complete_dance)

            if self.user_model['complete_dance'] == True:
                self.action_runner.run_waiting_action(
                    'say', 'Oke, gaan we nog een keer!')
            if self.user_model['complete_dance'] == False:
                self.action_runner.run_waiting_action(
                    'say',
                    'Oke, dat was het. Goed gedaan! Tot de volgende keer.')
Ejemplo n.º 16
0
 def __init__(self, server_ip, robot):
     self.sic = BasicSICConnector(server_ip, robot)
 def __init__(self, server_ip: str):
     self.sic = BasicSICConnector(server_ip)
     self.action_runner = ActionRunner(self.sic)
     self.motion = None
 def __init__(self, server_ip, robot, dialogflow_key_file,
              dialogflow_agent_id):
     self.sic = BasicSICConnector(server_ip, robot, dialogflow_key_file,
                                  dialogflow_agent_id)
     self.sic.start()
     self.robot = ExampleRobot(self.sic)
Ejemplo n.º 19
0
    def __init__(self, server_ip, robot):

        self.sic = BasicSICConnector(server_ip, robot)

        self.awake_lock = threading.Event()
    def __init__(self, server_ip, robot):
        self.sic = BasicSICConnector(server_ip, robot)

        self.hello_action_lock = threading.Event()
class Example:
    """Example that shows how to use the Action, ActionFactory, and ActionRunner classes. For more information go to
    https://socialrobotics.atlassian.net/wiki/spaces/CBSR/pages/616398873/Python+Examples#Action,-ActionFactory,-and-ActionRunner"""

    def __init__(self, server_ip, robot):
        self.sic = BasicSICConnector(server_ip, robot)

        self.hello_action_lock = threading.Event()

    def run(self):
        self.sic.start()
        self.sic.set_language('en-US')

        #################
        # Action        #
        #################
        # Create an action that can be executed when needed and reused
        hello_action = Action(self.sic.say, 'Hello, Action!', callback=self.hello_action_callback,
                              lock=self.hello_action_lock)
        hello_action.perform().wait()  # perform() returns the lock, so you can immediately call wait() on it.
        hello_action.perform().wait()  # you can reuse an action.

        #################
        # Action Factory#
        #################
        # Use the ActionFactory to build actions. You can build actions with a lock build inside of them by
        # using build_waiting_action(). It saves you from keeping track of your locks.
        # build_action() and build_waiting_action() use the name of SIC method instead of an explicit reference to it
        # as input. For example build_action('say', ...) instead of build_action(self.sic.say, ...).
        action_factory = ActionFactory(self.sic)
        hello_action_factory = action_factory.build_waiting_action('say', 'Hello, Action Factory!',
                                                                   additional_callback=self.hello_action_factory_callback)
        hello_action_factory.perform().wait()

        #################
        # Action Runner #
        #################
        # With an ActionRunner you can run regular and waiting actions right away or load them to run them in parallel.
        # When running the loaded actions, it will wait automatically for all loaded waiting actions to finish.
        action_runner = ActionRunner(self.sic)
        action_runner.run_waiting_action('say', 'Hello, Action Runner!',
                                         additional_callback=self.hello_action_runner_callback)
        # run_waiting_action('say', ...) waits to finish talking before continuing

        # The following actions will run in parallel.
        #action_runner.load_waiting_action('wake_up')
        action_runner.load_waiting_action('set_eye_color', 'green')
        action_runner.load_waiting_action('say', 'I am standing up now')
        action_runner.run_loaded_actions()  # If you want to keep an action sequence for reuse, add False as input.
        # run_loaded_actions() will wait automatically before all loaded waiting actions (not regular actions) to finish
        # before continuing

        action_runner.run_action('say', 'I will start sitting down as I say this. Because I am not a waiting action')
        action_runner.run_action('set_eye_color', 'white')
        action_runner.run_waiting_action('rest')

        self.sic.stop()

    def hello_action_callback(self):
        print('Hello Action Done')
        self.hello_action_lock.set()
        self.hello_action_lock.clear()  # necessary for reuse

    def hello_action_factory_callback(self):
        print('Hello Action Factory Done')

    def hello_action_runner_callback(self):
        print('Hello Action Runner Done')
Ejemplo n.º 22
0
 def __init__(self, server_ip: str):
     self.sic = BasicSICConnector(server_ip)
     self.awake_lock = Event()
Ejemplo n.º 23
0
class Example:
    """Example that shows how to use the BasicSICConnector. For more information go to
    https://socialrobotics.atlassian.net/wiki/spaces/CBSR/pages/616398873/Python+Examples#Basic-SIC-Connector"""

    def __init__(self, server_ip: str):
        self.sic = BasicSICConnector(server_ip)
        self.awake_lock = Event()

    def run(self) -> None:
        # active Social Interaction Cloud connection
        self.sic.start()

        # set language to English
        self.sic.set_language('en-US')

        # stand up and wait until this action is done (whenever the callback function self.awake is called)
        self.sic.wake_up(self.awake)
        self.awake_lock.wait()  # see https://docs.python.org/3/library/threading.html#event-objects

        self.sic.say_animated('You can tickle me by touching my head.')
        # Execute that_tickles call each time the middle tactile is touched
        self.sic.subscribe_touch_listener('MiddleTactilTouched', self.that_tickles)

        # You have 10 seconds to tickle the robot
        sleep(10)

        # Unsubscribe the listener if you don't need it anymore.
        self.sic.unsubscribe_touch_listener('MiddleTactilTouched')

        # Go to rest mode
        self.sic.rest()

        # close the Social Interaction Cloud connection
        self.sic.stop()

    def awake(self) -> None:
        """Callback function for wake_up action. Called only once.
        It lifts the lock, making the program continue from self.awake_lock.wait()"""
        self.awake_lock.set()

    def that_tickles(self) -> None:
        """Callback function for touch listener. Every time the MiddleTactilTouched event is generated, this
         callback function is called, making the robot say 'That tickles!'"""
        self.sic.say_animated('That tickles!')
Ejemplo n.º 24
0
 def __init__(self, server_ip: str):
     self.sic = BasicSICConnector(server_ip)
    def __init__(self, server_ip, robot, dialogflow_key_file,
                 dialogflow_agent_id):
        self.sic = BasicSICConnector(server_ip, robot, dialogflow_key_file,
                                     dialogflow_agent_id)

        self.user_model = {}