presentation_tibi.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import roslib; roslib.load_manifest('tibi_dabo_smachs')
00004 import rospy
00005 import smach
00006 import smach_ros
00007 import tf
00008 import math
00009 
00010 from tf.transformations import euler_from_quaternion
00011 from geometry_msgs.msg import Point, Pose, Quaternion
00012 from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
00013 from tibi_dabo_msgs.msg import sequenceAction, sequenceGoal
00014 from iri_perception_msgs.msg import peopleTrackAction
00015 from actionlib import *
00016 from actionlib.msg import *
00017 from smach_ros import SimpleActionState, ServiceState
00018 
00019 # hri goal callback
00020 def hri_goal_cb(userdata, goal):
00021   rospy.loginfo('hri_goal_cb')
00022   tts_goal = sequenceGoal()
00023   tts_goal.sequence_file = [None]*5
00024   tts_goal.sequence_file[0] = userdata.tts_in
00025   tts_goal.sequence_file[1] = ""
00026   tts_goal.sequence_file[2] = userdata.head_in
00027   tts_goal.sequence_file[3] = ""
00028   tts_goal.sequence_file[4] = ""
00029   return tts_goal
00030 
00031 # move base goal callback
00032 #def move_base_goal_cb(userdata, goal):
00033 #   rospy.loginfo('rotate_base_goal_cb')
00034 #  nav_goal = MoveBaseGoal()
00035   #nav_goal.target_pose.header.stamp    = rospy.Time.now()
00036   #nav_goal.target_pose.header.frame_id = userdata.frame_id_in
00037   #p = Point(0,1, 0)
00038   #q = tf.transformations.quaternion_from_euler(0, 0, 2)
00039   #nav_goal.target_pose.pose = Pose(position=p, orientation=Quaternion(*q))
00040   #return nav_goal
00041 
00042 # main
00043 def main():
00044     rospy.init_node('concurrent_hri_move_base')
00045 
00046     # Create a SMACH state machine
00047     sm = smach.StateMachine(['succeeded','aborted','preempted'])
00048     
00049     # Define userdata
00050     sm.userdata.sm_frame_id   = "/tibi/base_link"
00051     sm.userdata.sm_goal_x     = 0.0
00052     sm.userdata.sm_goal_y     = 0.0
00053     sm.userdata.sm_goal_theta = 0.0
00054 
00055   # Concurrence State: HRI + Rotate Base
00056    # hri_rb_cc = smach.Concurrence(outcomes=['succeeded', 'aborted', 'preempted'],
00057     #                              default_outcome='aborted',
00058      #                             input_keys=['cc_hri_tts', 'cc_hri_head', 'cc_hri_left', 'cc_frame_id', 
00059       #                                        'cc_goal_x', 'cc_goal_y', 'cc_goal_theta'],
00060        #                           child_termination_cb = lambda so: False,
00061         #                          outcome_cb = hri_mb_out_cb)
00062    # with hri_rb_cc:
00063     #    smach.Concurrence.add('CC_HRI',
00064      #                         smach_ros.SimpleActionState('hri',
00065       #                                                    sequenceAction,
00066        #                                                   goal_cb=hri_goal_cb,
00067         #                                                  input_keys=['tts_in','head_in','left_in']),
00068          #                     remapping={'tts_in':'cc_hri_tts',
00069           #                               'head_in':'cc_hri_head',
00070            #                              'left_in':'cc_hri_left'})
00071 
00072         #smach.Concurrence.add('CC_ROTATE_BASE',
00073          #                     smach_ros.SimpleActionState('MoveBase',
00074           #                                                MoveBaseAction,
00075            #                                               goal_cb=move_base_goal_cb,
00076             #                                              input_keys=['frame_id_in', 'goal_x_in', 
00077              #                                                         'goal_y_in', 'goal_theta_in']),
00078               #                remapping={'frame_id_in':'cc_frame_id',
00079                #                          'goal_x_in':'cc_goal_x',
00080                 #                         'goal_y_in':'cc_goal_y',
00081                  #                        'goal_theta_in':'cc_goal_theta'})
00082 
00083 
00084 
00085     # Add states to the State Machine
00086     with sm:
00087         # HRI Presentation
00088         sm.userdata.sm_hri_tts_1  = "Hola a tothom. Benvinguts a l'edicio numero trenta del salo del comic de Barcelona. Jo soc la Tibi, un robot social. Estic aqui per explicar-vos  curiositats sobre el salo."
00089         sm.userdata.sm_hri_head_1 = "head_random_1.xml"
00090         sm.userdata.sm_hri_left_1 = "left_arm_greeting.xml"
00091         smach.StateMachine.add('HRI_1',
00092                                smach_ros.SimpleActionState('hri',
00093                                                            sequenceAction,
00094                                                            goal_cb=hri_goal_cb,
00095                                                            input_keys=['tts_in', 'head_in','left_in']),
00096                                transitions={'succeeded':'CC_HRI_RB_1'},
00097                                remapping={'tts_in':'sm_hri_tts_1',
00098                                           'head_in':'sm_hri_head_1',
00099                                           'left_in':'sm_hri_left_1'})
00100 
00101         # First concurrent state , robot approaches person
00102         sm.userdata.sm_hri_tts_2  = "Si necessiteu qualsevol cosa no dubteu en preguntar-me, tot i que ara que hi penso millor parleu amb en Dabo, es el meu germa, ens assemblem molt, pero a ell li agrada el color blau, no el taronja"
00103         sm.userdata.sm_hri_head_2 = "head_random_2.xml"
00104         sm.userdata.sm_hri_left_2=  "left_arm_random_1.xml"
00105         smach.StateMachine.add('CC_HRI_RB_1',
00106                                hri_rb_cc,
00107                                transitions={'succeeded':'HRI_2',
00108                                             'aborted':'HRI_BLOCKED'},
00109                                remapping={'cc_hri_tts':'sm_hri_tts_2',
00110                                           'cc_hri_head':'sm_hri_head_2',
00111                                           'left_in':'sm_hri_left_2',
00112                                           'cc_frame_id':'sm_frame_id', 
00113                                           'cc_goal_x':'sm_goal_x',  
00114                                           'cc_goal_y':'sm_goal_y',  
00115                                           'cc_goal_theta':'sm_goal_theta'})
00116 
00117         # HRI Presentation
00118         sm.userdata.sm_hri_tts_3  = "Per aqui tambe esta el meu cosi, es diu Teo, es aquest trasto de quatre rodes que nomes sap fer mapes. Semple parla de mapes, es un aborrit, despres podeu demanar-li que us fassi un mapa del recinte."
00119         sm.userdata.sm_hri_head_3 = "head_random_3.xml"
00120         sm.userdata.sm_hri_left_3 = "left_arm_random_2.xml"
00121         smach.StateMachine.add('HRI_2',
00122                                smach_ros.SimpleActionState('hri',
00123                                                            sequenceAction,
00124                                                            goal_cb=hri_goal_cb,
00125                                                            input_keys=['tts_in', 'head_in','left_in']),
00126                                transitions={'succeeded':'CC_HRI_RB_2'},
00127                                remapping={'tts_in':'sm_hri_tts_3',
00128                                           'head_in':'sm_hri_head_3',
00129                                           'left_in':'sm_hri_left_3'})
00130 
00131         # Second concurrent state , robot approaches person
00132         sm.userdata.sm_hri_tts_4  = " Ah! me n'oblidava tambe ha vingut l'auron, es aquell robot aranya amb tantes potes, ara esta hivernant, aixi que no el desperteu, que s'enfada i es desperta de mal humor"
00133         sm.userdata.sm_hri_head_4 = "head_random_3.xml"
00134         sm.userdata.sm_hri_left_4 = "left_arm_random_3.xml"
00135         smach.StateMachine.add('CC_HRI_RB_2',
00136                                hri_rb_cc,
00137                                transitions={'succeeded':'HRI_3',
00138                                             'aborted':'HRI_BLOCKED'},
00139                                remapping={'cc_hri_tts':'sm_hri_tts_4',
00140                                           'cc_hri_head':'sm_hri_head_4',
00141                                           'left_in':'sm_hri_left_4',
00142                                           'cc_frame_id':'sm_frame_id', 
00143                                           'cc_goal_x':'sm_goal_x',  
00144                                           'cc_goal_y':'sm_goal_y',  
00145                                           'cc_goal_theta':'sm_goal_theta'})
00146 
00147         # HRI Presentation
00148         sm.userdata.sm_hri_tts_5  = "I despres esta la uait mun , es la nostra mascota, es la bola blanca. I per ultim el Darwin, el mimat, tothmo diu que es el millor de tots, pero  com un nen petit. I alla al davant tenim el Rim, es de la competencia, pero a vegades ens trobem per pendre xocolata."
00149         sm.userdata.sm_hri_head_5 = "head_random_3.xml"
00150         sm.userdata.sm_hri_left_5= "left_arm_random_2.xml"
00151         smach.StateMachine.add('HRI_3',
00152                                smach_ros.SimpleActionState('hri',
00153                                                            sequenceAction,
00154                                                            goal_cb=hri_goal_cb,
00155                                                            input_keys=['tts_in', 'head_in','left_in']),
00156                                transitions={'succeeded':'FAREWELL'},
00157                                remapping={'tts_in':'sm_hri_tts_5',
00158                                           'head_in':'sm_hri_head_5',
00159                                           'left_in':'sm_hri_left_5'})
00160 
00161 
00162 
00163 
00164         # HRI 2, FAREWELL 3
00165         sm.userdata.sm_hri_tts_farewell  = "Si algu vol entrar per saber mes coses es benvingut. Espero veure-us aviat. Adeu a tots"
00166         sm.userdata.sm_hri_head_farewell = "head_farewell.xml"
00167         sm.userdata.sm_hri_left_farewell= "left_arm_farewell.xml"
00168         smach.StateMachine.add('FAREWELL',
00169                                smach_ros.SimpleActionState('hri',
00170                                                            sequenceAction,
00171                                                            goal_cb=hri_goal_cb,
00172                                                            input_keys=['tts_in', 'head_in','left_in']),
00173                                transitions={'succeeded':'succeeded'}, 
00174                                remapping={'tts_in':'sm_hri_tts_farewell',
00175                                           'head_in':'sm_hri_head_farewell',
00176                                           'left_in':'sm_hri_left_farewell'})
00177 
00178 
00179         # HRI , Robot is blocked, 
00180         sm.userdata.sm_hri_tts_blocked  = "Sergi, Fernando, Anais, no em puc moure, ajudeu-me"
00181         sm.userdata.sm_hri_head_blocked = "head_farewell.xml"
00182         sm.userdata.sm_hri_left_blocked= "left_arm_random_4.xml"
00183         smach.StateMachine.add('HRI_BLOCKED',
00184                                smach_ros.SimpleActionState('hri',
00185                                                            sequenceAction,
00186                                                            goal_cb=hri_goal_cb,
00187                                                            input_keys=['tts_in', 'head_in','left_in']),
00188                                transitions={'succeeded':'succeeded'}, 
00189                                remapping={'tts_in':'sm_hri_tts_blocked',
00190                                           'head_in':'sm_hri_head_blocked',
00191                                           'left_in':'sm_hri_left_blocked'})
00192 
00193     # Create and start the introspection server
00194     sis = smach_ros.IntrospectionServer('server_name', sm, '/SM_ROOT')
00195     sis.start()
00196 
00197     # Execute the state machine
00198     outcome = sm.execute()
00199 
00200     # Wait for ctrl-c to stop the application
00201     rospy.spin()
00202     sis.stop()
00203 
00204 
00205 if __name__ == '__main__':
00206     main()
00207 


tibi_dabo_smachs
Author(s): Joan Perez, jnperez at iri.upc.edu
autogenerated on Fri Dec 6 2013 20:04:35