Esempio n. 1
0
    def __init__(self,
                 GRAMMAR_NAME='categories',
                 command_key='finn',
                 command_value='xxx'):
        smach.StateMachine.__init__(self,
                                    ['succeeded', 'preempted', 'aborted'])

        GRAMMAR_NAME = 'gpsr/' + GRAMMAR_NAME

        self.userdata.cat = GRAMMAR_NAME
        self.userdata.objectList = []
        self.userdata.locList = []
        self.userdata.location_name = ''
        self.userdata.grammar_name = GRAMMAR_NAME
        self.userdata.tts_wait_before_speaking = 0
        self.userdata.tts_text = ''
        self.userdata.tts_lang = ''

        with self:

            smach.StateMachine.add('CONFG_QUESTION',
                                   config_loc_question(),
                                   transitions={'succeeded': 'ENABLE_GRAMMAR'},
                                   remapping={
                                       'DataType': 'DataType',
                                       'locList': 'locList'
                                   })

            smach.StateMachine.add(
                'ENABLE_GRAMMAR',
                ActivateASR(GRAMMAR_NAME),
                transitions={'succeeded': 'PREPARATION_ASK_INFO'})

            smach.StateMachine.add('PREPARATION_ASK_INFO',
                                   prepare_ask_info_loc(),
                                   transitions={'succeeded': 'ASK_INFO'},
                                   remapping={'tosay': 'tts_text'})

            smach.StateMachine.add('ASK_INFO',
                                   text_to_say(),
                                   transitions={
                                       'succeeded': 'HEAR_COMMAND',
                                       'aborted': 'aborted'
                                   })

            smach.StateMachine.add('HEAR_COMMAND',
                                   ReadASR(),
                                   transitions={
                                       'aborted': 'HEAR_COMMAND',
                                       'succeeded': 'BRING_ORDER',
                                       'preempted': 'preempted'
                                   },
                                   remapping={
                                       'asr_userSaid': 'userSaidData',
                                       'asr_userSaid_tags': 'userSaidTags'
                                   })

            smach.StateMachine.add('BRING_ORDER',
                                   BringOrderLoc(),
                                   transitions={
                                       'aborted': 'HEAR_COMMAND',
                                       'succeeded':
                                       'PREPARATION_CONFIRM_OBJECT',
                                       'preempted': 'preempted'
                                   })

            smach.StateMachine.add('PREPARATION_CONFIRM_OBJECT',
                                   prepare_confirm_info(),
                                   transitions={'succeeded': 'CONFIRM_OBJECT'},
                                   remapping={'tosay': 'tts_text'})

            smach.StateMachine.add('CONFIRM_OBJECT',
                                   text_to_say(),
                                   transitions={
                                       'succeeded': 'DISABLE_GRAMMAR',
                                       'aborted': 'DISABLE_GRAMMAR'
                                   })

            smach.StateMachine.add('RECOGNIZE_COMMAND',
                                   RecognizeCommand(command_key,
                                                    command_value),
                                   transitions={
                                       'notvalid_command': 'NOT_VALID_COMMAND',
                                       'valid_command': 'VALID_COMMAND',
                                       'preempted': 'preempted',
                                       'aborted': 'aborted'
                                   },
                                   remapping={'speechData': 'userSaidData'})

            smach.StateMachine.add(
                'VALID_COMMAND',
                text_to_say("Ok, understood."),
                transitions={'succeeded': 'DISABLE_GRAMMAR'})

            smach.StateMachine.add(
                'NOT_VALID_COMMAND',
                text_to_say(
                    "Sorry, I couldn't understand what you said. Can you repeat?"
                ),
                transitions={'succeeded': 'HEAR_COMMAND'})

            smach.StateMachine.add('DISABLE_GRAMMAR',
                                   DeactivateASR(GRAMMAR_NAME),
                                   transitions={'succeeded': 'succeeded'})
Esempio n. 2
0
    def __init__(self,
                 GRAMMAR_NAME,
                 command_key='finn',
                 command_value='xxx',
                 ask_for_confirmation=False):
        smach.StateMachine.__init__(self,
                                    ['succeeded', 'preempted', 'aborted'])
        with self:

            smach.StateMachine.add('ENABLE_GRAMMAR',
                                   ActivateASR(GRAMMAR_NAME),
                                   transitions={'succeeded': 'HEAR_COMMAND'})

            smach.StateMachine.add('HEAR_COMMAND',
                                   ReadASR(),
                                   transitions={
                                       'aborted': 'HEAR_COMMAND',
                                       'succeeded': 'PROCESS_COMMAND',
                                       'preempted': 'preempted'
                                   },
                                   remapping={
                                       'asr_userSaid': 'userSaidData',
                                       'asr_userSaid_tags': 'userSaidTags'
                                   })

            smach.StateMachine.add(
                'PROCESS_COMMAND',
                ProcessCommandState(),
                transitions={
                    'succeeded':
                    'ASK_COMMAND_CONFIRMATION'
                    if ask_for_confirmation else 'PRINT_MESSAGE',
                    'preempted':
                    'preempted',
                    'aborted':
                    'aborted'
                },
                remapping={
                    'in_heard': 'userSaidData',
                    'value_heard_out': 'word_heard'
                })

            if ask_for_confirmation:
                smach.StateMachine.add(
                    'ASK_COMMAND_CONFIRMATION',
                    text_to_say('Did you say ' + userdata.word_heard + '?'),
                    transitions={
                        'succeeded': 'LISTEN_COMMAND_CONFIRMATION',
                        'aborted': 'SLEEP_STATE',
                        'preempted': 'preempted'
                    })

                smach.StateMachine.add(
                    'LISTEN_COMMAND_CONFIRMATION',
                    SayYesOrNoSM(),
                    transitions={
                        'succeeded': 'DISABLE_GRAMMAR',
                        'aborted': 'SLEEP_STATE',
                        'preempted': 'preempted'
                    },
                    remapping={'in_message_heard': 'word_heard'})

                smach.StateMachine.add('SLEEP_STATE',
                                       SleepState(0.5),
                                       transitions={
                                           'succeeded': 'HEAR_COMMAND',
                                           'preempted': 'preempted'
                                       })

            smach.StateMachine.add('PRINT_MESSAGE',
                                   PrintUserData(),
                                   transitions={
                                       'succeeded': 'DISABLE_GRAMMAR',
                                       'preempted': 'preempted'
                                   })

            smach.StateMachine.add('DISABLE_GRAMMAR',
                                   DeactivateASR(GRAMMAR_NAME),
                                   transitions={'succeeded': 'succeeded'})
Esempio n. 3
0
    def __init__(self,
                 Type,
                 objectName,
                 GRAMMAR_NAME='robocup/locations',
                 command_key='finn',
                 command_value='xxx'):
        smach.StateMachine.__init__(self,
                                    ['succeeded', 'preempted', 'aborted'])

        self.userdata.dataType = Type
        self.userdata.object_name = objectName
        self.userdata.location_name = ''
        self.userdata.grammar_name = GRAMMAR_NAME
        self.userdata.tts_wait_before_speaking = 0
        self.userdata.tts_text = ''
        self.userdata.tts_lang = ''

        with self:

            smach.StateMachine.add('ENABLE_GRAMMAR',
                                   ActivateASR(GRAMMAR_NAME),
                                   transitions={'succeeded': 'ASK_LOCATION'})

            smach.StateMachine.add(
                'ASK_LOCATION',
                text_to_say("I don't know where the " +
                            self.userdata.object_name +
                            ' is. Do you know where could I find it?'),
                transitions={
                    'succeeded': 'HEAR_COMMAND',
                    'aborted': 'aborted'
                })

            smach.StateMachine.add('HEAR_COMMAND',
                                   ReadASR(),
                                   transitions={
                                       'aborted': 'HEAR_COMMAND',
                                       'succeeded': 'BRING_LOCATION',
                                       'preempted': 'preempted'
                                   },
                                   remapping={
                                       'asr_userSaid': 'userSaidData',
                                       'asr_userSaid_tags': 'userSaidTags'
                                   })

            smach.StateMachine.add(
                'BRING_LOCATION',
                BringOrderLoc(),
                transitions={
                    'aborted': 'HEAR_COMMAND',
                    'succeeded': 'PREPARATION_CONFIRM_OBJECT',
                    'preempted': 'preempted'
                },
                remapping={'location_name': 'location_name'})

            smach.StateMachine.add('PREPARATION_CONFIRM_OBJECT',
                                   prepare_confirm_info(),
                                   transitions={'succeeded': 'CONFIRM_OBJECT'},
                                   remapping={'tosay': 'tts_text'})

            smach.StateMachine.add('CONFIRM_OBJECT',
                                   text_to_say(),
                                   transitions={
                                       'succeeded': 'DISABLE_GRAMMAR',
                                       'aborted': 'DISABLE_GRAMMAR'
                                   })

            smach.StateMachine.add('RECOGNIZE_COMMAND',
                                   RecognizeCommand(command_key,
                                                    command_value),
                                   transitions={
                                       'notvalid_command': 'NOT_VALID_COMMAND',
                                       'valid_command': 'VALID_COMMAND',
                                       'preempted': 'preempted',
                                       'aborted': 'aborted'
                                   },
                                   remapping={'speechData': 'userSaidData'})

            smach.StateMachine.add(
                'VALID_COMMAND',
                text_to_say("Ok, understood."),
                transitions={'succeeded': 'DISABLE_GRAMMAR'})

            smach.StateMachine.add(
                'NOT_VALID_COMMAND',
                text_to_say(
                    "I couldn't understand what you said. Can you repeat?"),
                transitions={'succeeded': 'HEAR_COMMAND'})

            smach.StateMachine.add('DISABLE_GRAMMAR',
                                   DeactivateASR(),
                                   transitions={'succeeded': 'succeeded'})
Esempio n. 4
0
    def __init__(self):
        smach.StateMachine.__init__(
            self,
            outcomes=['succeeded', 'preempted', 'aborted'],
            output_keys=['object_array'])

        with self:
            # We must initialize the userdata keys if they are going to be accessed or they won't exist and crash!
            self.userdata.nav_to_poi_name = None
            self.userdata.grammar_name = None
            self.userdata.type_movment = None
            self.userdata.tts_wait_before_speaking = 0
            self.userdata.tts_lang = None
            self.userdata.standard_error = 'OK'
            self.userdata.object_name = ''
            self.userdata.object_index = 0

            # Activate the server
            smach.StateMachine.add('ActivateASR',
                                   ActivateASR(GRAMMAR_NAME),
                                   transitions={
                                       'succeeded': 'ask_restaurant_order',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # Ask Order
            smach.StateMachine.add(
                'ask_restaurant_order',
                text_to_say("What would you like to order?"),
                transitions={
                    'succeeded': 'ReadASR',
                    'aborted': 'aborted',
                    'preempted': 'preempted'
                })

            # Read from server
            smach.StateMachine.add('ReadASR',
                                   ReadASR(),
                                   transitions={
                                       'succeeded': 'process_restaurant_order',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # Listen Order
            #             smach.StateMachine.add(
            #                 'listen_restaurant_order',
            #                 ListenToSM(GRAMMAR_NAME),
            #                 transitions={'succeeded': 'process_restaurant_order', 'aborted': 'aborted',
            #                 'preempted': 'preempted'})
            #
            # Process order
            smach.StateMachine.add('process_restaurant_order',
                                   process_restaurant_order(),
                                   transitions={
                                       'succeeded': 'ActivateASR_yesno',
                                       'aborted': 'aborted'
                                   })

            # Load grammar yes/no
            smach.StateMachine.add('ActivateASR_yesno',
                                   ActivateASR("robocup/yes_no"),
                                   transitions={
                                       'succeeded': 'confirm_restaurant_order',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # Confirm Order
            smach.StateMachine.add('confirm_restaurant_order',
                                   acknowledgment(type_movement="yes"),
                                   transitions={
                                       'succeeded': 'yesno_restaurant_order',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # Wait for yes or no
            smach.StateMachine.add('yesno_restaurant_order',
                                   SayYesOrNoSM(),
                                   transitions={
                                       'succeeded': 'ok_im_going',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # Ask for repeat the order
            smach.StateMachine.add(
                'repeat_restaurant_order',
                acknowledgment(
                    type_movement="no",
                    tts_text=
                    "Excuse me, I don't understand you. Can you repeat your order?"
                ),
                transitions={
                    'succeeded': 'ReadASR',
                    'aborted': 'aborted',
                    'preempted': 'preempted'
                })

            # Confirm Order
            smach.StateMachine.add('ok_im_going',
                                   text_to_say("OK i'm going to service"),
                                   transitions={
                                       'succeeded': 'succeeded',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # Search for object information - It says where the object is, go to it and start object recognition -> RESTAURANT
            # TODO: Add some messages in search object


#             smach.StateMachine.add(
#                 'search_food_order',
#                 SearchObjectSM(),
#                 transitions={'succeeded': 'go_to_storage', 'aborted': 'go_to_storage',
#                 'preempted': 'preempted'})
Esempio n. 5
0
    def __init__(self):
        smach.StateMachine.__init__(self, ['succeeded', 'preempted', 'aborted'])

        with self:
            self.lfjs = LearnFromJointState()
            self.gesture_generator = gestureGeneration()
            self.gesture_executor = gestureExecution()
            
#             smach.StateMachine.add('ActivateKWASR_learn_gesture',
#                     ActivateKeywordASR(keyword=LEARN_GESTURE_SENTENCE),
#                     transitions={'succeeded': 'check_loop', 'aborted': 'aborted', 'preempted': 'preempted'})
            smach.StateMachine.add(
                 'Explain_how_it_works',
                 text_to_say("Hello, you will teach me a new gesture.\
                  First tell me which arms and hands to use. Remember, I only have two!", wait=False),
                 transitions={'succeeded': 'listen_groups_to_use', 'aborted': 'aborted'})

            smach.StateMachine.add(
                'listen_groups_to_use',
                ListenRepeatSM(grammar=CHOOSE_GROUP_GRAMMAR_NAME),
                transitions={'succeeded': 'confirm_groups', 'aborted': 'aborted', 
                'preempted': 'preempted'})

            smach.StateMachine.add(
                'confirm_groups',
                SayYesOrNoSM_2(),
                transitions={'succeeded': 'prepare_groups_to_make_loose', 'aborted': 'listen_groups_to_use', 
                'preempted': 'preempted'})
            
                       
            smach.StateMachine.add(
                 'prepare_groups_to_make_loose',
                 prepareGroups(),
                 transitions={'succeeded': 'Warn_loose_joints', 'aborted': 'aborted'})

            smach.StateMachine.add(
                 'Warn_loose_joints',
                 text_to_say("I'm going to lower the current on my joints, be careful.", wait=False),
                 transitions={'succeeded': 'look_to_place', 'aborted': 'aborted'})
            
#             def look_point_goal_cb(userdata, goal):
#                 phg = PointHeadGoal()
#                 phg.min_duration = rospy.Duration(2.0)
#                 phg.pointing_axis.x = 1.0
#                 phg.pointing_frame = "stereo_link"
#                 phg.target.header.frame_id = "base_link"
#                 phg.target.point.x = 1.0
#                 phg.target.point.y = -1.0
#                 phg.target.point.z = 1.0
#                 return phg
#             
#             smach.StateMachine.add(
#                  'look_to_place',
#                  SimpleActionState('/head_controller/point_head_action',
#                                    PointHeadAction,
#                                    goal_cb=look_point_goal_cb),
#                  transitions={'succeeded': 'make_groups_loose', 'aborted': 'aborted'})

            smach.StateMachine.add(
                 'look_to_place',
                 sendPointHeadGoalByPublisher(Point(1.0, -1.0, 1.0)),
                 transitions={'succeeded': 'make_groups_loose', 'aborted': 'aborted'})
            

            smach.StateMachine.add(
                 'make_groups_loose',
                 setJointsCurrent(curr_limit=0.01),
                 transitions={'succeeded': 'ActivateKWASR_start', 'aborted': 'aborted'})

            smach.StateMachine.add('ActivateKWASR_start',
                    ActivateKeywordASR(keyword=START_SENTENCE),
                    transitions={'succeeded': 'Say_ready', 'aborted': 'aborted', 'preempted': 'preempted'})
            
            smach.StateMachine.add(
                 'Say_ready',
                 text_to_say("Please say, start, when you want to start recording. Then say, wait here, when you finish the gesture."),
                 transitions={'succeeded': 'listen_to_start', 'aborted': 'aborted'})
            
            
            smach.StateMachine.add(
                'listen_to_start',
                ReadASR(), # We can only listen to one word, so we dont care about the content
                transitions={'succeeded': 'ActivateKWASR_stop', 'aborted': 'aborted', 
                'preempted': 'preempted'}) 

            smach.StateMachine.add('ActivateKWASR_stop',
                    ActivateKeywordASR(keyword=STOP_SENTENCE),
                    transitions={'succeeded': 'Say_recording', 'aborted': 'aborted', 'preempted': 'preempted'})
            
            smach.StateMachine.add(
                 'Say_recording',
                 text_to_say("Ok, I'll start recording... now."),
                 transitions={'succeeded': 'record_gesture', 'aborted': 'aborted'})
            
            smach.StateMachine.add(
                 'record_gesture',
                 startRecordGesture(self.lfjs),
                 transitions={'succeeded': 'listen_to_stop', 'aborted': 'aborted'})
            
            smach.StateMachine.add(
                'listen_to_stop',
                ReadASR(),
                transitions={'succeeded': 'stop_recording_gesture', 'aborted': 'aborted', 
                'preempted': 'preempted'}) 
            
            smach.StateMachine.add(
                 'stop_recording_gesture',
                 stopRecordGesture(self.lfjs),
                 transitions={'succeeded': 'Say_recorded_and_processing', 'aborted': 'aborted'})
            
            smach.StateMachine.add(
                 'Say_recorded_and_processing',
                 text_to_say("Got the gesture, now I'm going to process it. Give me some seconds please.", wait=False),
                 transitions={'succeeded': 'look_to_place_middle', 'aborted': 'aborted'})

#             def look_point_goal_cb2(userdata, goal):
#                 phg = PointHeadGoal()
#                 phg.min_duration = rospy.Duration(2.0)
#                 phg.pointing_axis.x = 1.0
#                 phg.pointing_frame = "stereo_link"
#                 phg.target.header.frame_id = "base_link"
#                 phg.target.point.x = 1.0
#                 phg.target.point.y = 0.0
#                 phg.target.point.z = 1.7
#                 return phg
#             
#             smach.StateMachine.add(
#                  'look_to_place_middle',
#                  SimpleActionState('/head_controller/point_head_action',
#                                    PointHeadAction,
#                                    goal_cb=look_point_goal_cb2),
#                  transitions={'succeeded': 'train_gesture', 'aborted': 'aborted'})

            smach.StateMachine.add(
                 'look_to_place_middle',
                 sendPointHeadGoalByPublisher(Point(1.0, 0.0, 1.7)),
                 transitions={'succeeded': 'train_gesture', 'aborted': 'aborted'})

            smach.StateMachine.add(
                 'train_gesture',
                 gestureTrainer(self.gesture_generator),
                 transitions={'succeeded': 'Say_gesture_learnt', 'aborted': 'aborted'})
            
            smach.StateMachine.add(
                 'Say_gesture_learnt',
                 text_to_say("Ok, I learnt the gesture, as Neeo would say, now I know kung fu. \
                 Put my arm where you want me to start the motion and say now."),
                 transitions={'succeeded': 'ActivateKWASR_now', 'aborted': 'aborted'})
            
            smach.StateMachine.add('ActivateKWASR_now',
                    ActivateKeywordASR(keyword=EXECUTE_SENTENCE),
                    transitions={'succeeded': 'listen_to_now', 'aborted': 'aborted', 'preempted': 'preempted'})
            
            smach.StateMachine.add(
                'listen_to_now',
                ReadASR(),
                transitions={'succeeded': 'make_group_stiff', 'aborted': 'aborted', 
                'preempted': 'preempted'}) 
        
            smach.StateMachine.add(
                 'make_group_stiff',
                 setJointsCurrent(curr_limit=1.0),
                 transitions={'succeeded': 'Say_executing', 'aborted': 'aborted'})
        
            smach.StateMachine.add(
                 'Say_executing',
                 text_to_say("Ok, I'm going to execute the gesture from my current configuration!", wait=False),
                 transitions={'succeeded': 'execute_gesture_from_current_pose', 'aborted': 'aborted'})
            
            smach.StateMachine.add(
                 'execute_gesture_from_current_pose',
                 gestureExecuterFromPlace(self.gesture_executor, self.gesture_generator),
                 transitions={'succeeded': 'Say_try_from_another_position', 'aborted': 'Say_fail_exec'})
            
            smach.StateMachine.add(
                 'Say_try_from_another_position',
                 text_to_say("That went well, try again from a different position. I'm making my joints loose again. When you want me to execute again the gesture say now."),
                 transitions={'succeeded': 'make_groups_loose_again', 'aborted': 'aborted'})
            
            smach.StateMachine.add(
                 'Say_fail_exec',
                 text_to_say("The safety check of this movement failed, try again from a safer position. Making my joints loose again, say now when you want to execute."),
                 transitions={'succeeded': 'make_groups_loose_again', 'aborted': 'aborted'})

            smach.StateMachine.add(
                 'make_groups_loose_again',
                 setJointsCurrent(curr_limit=0.01),
                 transitions={'succeeded': 'ActivateKWASR_now', 'aborted': 'aborted'})
Esempio n. 6
0
    def __init__(self):
        smach.StateMachine.__init__(self, ['succeeded', 'preempted', 'aborted'])

        with self:
            # We must initialize the userdata keys if they are going to be accessed or they won't exist and crash!
            self.userdata.loop_iterations = 0
            self.userdata.nav_to_poi_name = ""
            self.userdata.faces = ""
            self.userdata.name=''
            self.userdata.tts_text = None
            self.userdata.tts_wait_before_speaking = 0
            self.userdata.tts_lang = ''
            
            # Listen the first question
            self.userdata.grammar_name = GRAMMAR_NAME
            
            # Home position
            smach.StateMachine.add(
                'home_position_init',
                play_motion_sm('home'),
                transitions={'succeeded': 'ActivateASR', 'aborted': 'home_position_init', #TODO: Change aborted to try again
                'preempted': 'preempted'}) 
                     
            # Enter room
            smach.StateMachine.add(
                 'say_what_did_you_say',
                 text_to_say("I'm beginning the what did you say test, I'm going to looking for the referee"),
                 #transitions={'succeeded': 'go_location', 'aborted': 'aborted'})
                 transitions={'succeeded': 'search_face', 'aborted': 'search_face'})
            
#             # Go to the location
#             smach.StateMachine.add(
#                  'go_location',
#                  nav_to_poi("init_what_say"),
#                  transitions={'succeeded': 'search_face', 'aborted': 'aborted', 
#                  'preempted': 'preempted'})    
             
#             smach.StateMachine.add(
#                  'say_faces',
#                  text_to_say("Searching for faces"),
#                  transitions={'succeeded': 'search_face', 'aborted': 'aborted'})
            
            # Look for a face
            smach.StateMachine.add(
                 'search_face',
                 go_find_person(),
                 transitions={'succeeded': 'Say_Found_Face', 'aborted': 'ask_for_tc', 
                 'preempted': 'preempted'},
                  remapping={'face_frame':'face_frame'})
             
            # Go to the person - We assume that find person will return the position for the person
            smach.StateMachine.add(
                                   'Say_Found_Face',
                                   text_to_say('Referee! I have found you at last. Now I am going to you, wait for me.'),
                                   transitions={'succeeded': 'get_current_pose_yaw', 'aborted': 'Say_Found_Face', 
                                                'preempted': 'preempted'})
            smach.StateMachine.add(
               'get_current_pose_yaw',
               get_current_robot_pose(),
               transitions={'succeeded': 'prepare_coord_person', 'aborted': 'ask_for_tc',
                                'preempted': 'preempted'})
            
            smach.StateMachine.add(
                 'prepare_coord_person',
                 prepare_coord_person(),
                 transitions={'succeeded': 'go_to_person', 'aborted': 'aborted',
                 'preempted': 'preempted'})
            
            
            smach.StateMachine.add(
                 'go_to_person',
                 nav_to_coord_ud(),
                 transitions={'succeeded': 'say_found', 'aborted': 'Say_person_not_reached',
                 'preempted': 'preempted'})
            
            smach.StateMachine.add(
               'Say_person_not_reached',
               text_to_say('I Found you, but cannot reach you, can you come to me please?'),
               transitions={'succeeded': 'wait_for_tc', 'aborted': 'aborted'})
             
            # Say "I found you!" + Small Talk
            smach.StateMachine.add(
                 'say_found',
                 text_to_say("I found you! I have arrived to where you are."),
                 transitions={'succeeded': 'ActivateASR', 'aborted': 'aborted'})
             
            # Ask for TC if we don't find him
            smach.StateMachine.add(
                 'ask_for_tc',
                 text_to_say("I can't find you. Can you come to me?"),
                 transitions={'succeeded': 'wait_for_tc', 'aborted': 'aborted'})
              
            # Wait for TC
            smach.StateMachine.add(
                 'wait_for_tc',
                 detect_face(),
                 transitions={'succeeded': 'say_found', 'aborted': 'aborted'})
            
            # Question Part ---------------------------------------------------------------------------------------------
            
            # Init the asr service

            # Activate the server
            smach.StateMachine.add('ActivateASR',
                    ActivateASR(),
                    transitions={'succeeded': 'check_loop', 'aborted': 'aborted', 'preempted': 'preempted'})
            
            # loop test - It checks the number of iterations
            smach.StateMachine.add(
                'check_loop',
                checkLoop(),
                transitions={'succeeded': 'ask_next_question', 'aborted': 'aborted', 
                'preempted': 'preempted', 'end':'DeactivateASR'})
            
            # Ask for next question
            smach.StateMachine.add(
                'ask_next_question',
                text_to_say("I'm ready, ask me a question"),
                transitions={'succeeded': 'listen_question', 'aborted': 'aborted', 
                'preempted': 'preempted'}) 
            
            smach.StateMachine.add(
                'listen_question',
                ReadASR(),
                transitions={'succeeded': 'prepear_repeat', 'aborted': 'aborted', 
                'preempted': 'preempted'})  
            
            smach.StateMachine.add(
                'prepear_repeat',
                prepear_repeat(),
                transitions={'succeeded': 'repeat_question', 'aborted': 'aborted', 
                'preempted': 'preempted'})  
             
            # Repeat question
            smach.StateMachine.add(
                'repeat_question',
                text_to_say(),
                transitions={'succeeded': 'search_answer', 'aborted': 'aborted', 
                'preempted': 'preempted'})  
            
            # Search the answer
            smach.StateMachine.add(
                'search_answer',
                SelectAnswer(),
                transitions={'succeeded': 'say_answer', 'aborted': 'say_answer', 
                'preempted': 'preempted', 'None': 'aborted'})    

            # Say the answer
            smach.StateMachine.add(
                'say_answer',
                text_to_say(),
                transitions={'succeeded': 'check_loop', 'aborted': 'aborted', 
                'preempted': 'preempted'})  
            
            # Deactivate ASR
            smach.StateMachine.add('DeactivateASR',
                DeactivateASR(),
                transitions={'succeeded': 'say_end', 'aborted': 'aborted', 'preempted': 'preempted'})
            
            smach.StateMachine.add(
                 'say_end',
                 text_to_say("What did you say test finished"),
                 transitions={'succeeded': 'succeeded', 'aborted': 'aborted'})
Esempio n. 7
0
    def __init__(self):
        smach.StateMachine.__init__(self,
                                    ['succeeded', 'preempted', 'aborted'])

        with self:
            # We must initialize the userdata keys if they are going to be accessed or they won't exist and crash!
            self.userdata.loop_iterations = 0
            self.userdata.nav_to_poi_name = ""
            self.userdata.faces = ""
            self.userdata.name = ''
            self.userdata.tts_text = None
            self.userdata.tts_wait_before_speaking = 0
            self.userdata.tts_lang = ''

            # Listen the first question
            self.userdata.grammar_name = GRAMMAR_NAME

            # Find me Part

            # Enter room
            smach.StateMachine.add(
                'say_what_did_you_say',
                text_to_say(
                    "I'm beginning the what did you say test,. I'm going to the place where ther referee should be"
                ),
                #transitions={'succeeded': 'go_location', 'aborted': 'aborted'})
                transitions={
                    'succeeded': 'go_location',
                    'aborted': 'aborted'
                })

            # Go to the location
            smach.StateMachine.add('go_location',
                                   nav_to_poi("find_me"),
                                   transitions={
                                       'succeeded': 'say_faces',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            smach.StateMachine.add('say_faces',
                                   text_to_say("Searching for faces"),
                                   transitions={
                                       'succeeded': 'search_face',
                                       'aborted': 'aborted'
                                   })

            # Look for a face
            smach.StateMachine.add('search_face',
                                   SearchFacesSM(),
                                   transitions={
                                       'succeeded': 'prepare_coord_person',
                                       'aborted': 'ask_for_tc',
                                       'preempted': 'preempted'
                                   })

            # Go to the person - We assume that find person will return the position for the person
            smach.StateMachine.add('prepare_coord_person',
                                   prepare_coord_person(),
                                   transitions={
                                       'succeeded': 'go_to_person',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            smach.StateMachine.add('go_to_person',
                                   nav_to_coord('/base_link'),
                                   transitions={
                                       'succeeded': 'say_found',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # Say "I found you!" + Small Talk
            smach.StateMachine.add('say_found',
                                   text_to_say("I found you!"),
                                   transitions={
                                       'succeeded': 'ActivateASR',
                                       'aborted': 'aborted'
                                   })

            # Ask for TC if we dont find him
            smach.StateMachine.add(
                'ask_for_tc',
                text_to_say("I can't find you. Can you come to me?"),
                transitions={
                    'succeeded': 'wait_for_tc',
                    'aborted': 'aborted'
                })

            # Wait for TC
            smach.StateMachine.add('wait_for_tc',
                                   detect_face(),
                                   transitions={
                                       'succeeded': 'say_found',
                                       'aborted': 'aborted'
                                   })

            # Question Part ---------------------------------------------------------------------------------------------

            # Init the asr service

            # Activate the server
            smach.StateMachine.add('ActivateASR',
                                   ActivateASR(),
                                   transitions={
                                       'succeeded': 'check_loop',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # loop test - It checks the number of iterations
            smach.StateMachine.add('check_loop',
                                   checkLoop(),
                                   transitions={
                                       'succeeded': 'ask_next_question',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted',
                                       'end': 'DeactivateASR'
                                   })

            # Ask for next question
            smach.StateMachine.add('ask_next_question',
                                   text_to_say("I'm ready, ask me a question"),
                                   transitions={
                                       'succeeded': 'listen_question',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            smach.StateMachine.add('listen_question',
                                   ReadASR(),
                                   transitions={
                                       'succeeded': 'prepear_repeat',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            smach.StateMachine.add('prepear_repeat',
                                   prepear_repeat(),
                                   transitions={
                                       'succeeded': 'repeat_question',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # Repeat question
            smach.StateMachine.add('repeat_question',
                                   text_to_say(),
                                   transitions={
                                       'succeeded': 'search_answer',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # Search the answer
            smach.StateMachine.add('search_answer',
                                   SelectAnswer(),
                                   transitions={
                                       'succeeded': 'say_answer',
                                       'aborted': 'say_answer',
                                       'preempted': 'preempted',
                                       'None': 'aborted'
                                   })

            # Say the answer
            smach.StateMachine.add('say_answer',
                                   text_to_say(),
                                   transitions={
                                       'succeeded': 'check_loop',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            # Deactivate ASR
            smach.StateMachine.add('DeactivateASR',
                                   DeactivateASR(),
                                   transitions={
                                       'succeeded': 'say_end',
                                       'aborted': 'aborted',
                                       'preempted': 'preempted'
                                   })

            smach.StateMachine.add(
                'say_end',
                text_to_say("What did you say test finished"),
                transitions={
                    'succeeded': 'succeeded',
                    'aborted': 'aborted'
                })