00001
00002
00003 import roslib; roslib.load_manifest('tibi_dabo_smachs')
00004 import rospy
00005 import smach
00006 import smach_ros
00007 import tf
00008
00009 from tf.transformations import euler_from_quaternion
00010 from geometry_msgs.msg import Point, Pose, Quaternion
00011 from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
00012 from tibi_dabo_msgs.msg import sequenceAction, sequenceGoal
00013 from iri_perception_msgs.msg import peopleTrackAction
00014 from actionlib import *
00015 from actionlib.msg import *
00016 from smach_ros import SimpleActionState, ServiceState
00017
00018
00019 def hri_goal_cb(userdata, goal):
00020 rospy.loginfo('hri_goal_cb')
00021 tts_goal = sequenceGoal()
00022 tts_goal.sequence_file = [None]*5
00023 tts_goal.sequence_file[0] = userdata.tts_in
00024 tts_goal.sequence_file[1] = ""
00025 tts_goal.sequence_file[2] = userdata.head_in
00026 tts_goal.sequence_file[3] = ""
00027 tts_goal.sequence_file[4] = ""
00028 return tts_goal
00029
00030
00031 def move_base_goal_cb(userdata, goal):
00032 rospy.loginfo('move_base_goal_cb')
00033 nav_goal = MoveBaseGoal()
00034 nav_goal.target_pose.header.stamp = rospy.Time.now()
00035 nav_goal.target_pose.header.frame_id = userdata.frame_id_in
00036 p = Point(userdata.goal_x_in, userdata.goal_y_in, 0)
00037 q = tf.transformations.quaternion_from_euler(0, 0, userdata.goal_theta_in)
00038 nav_goal.target_pose.pose = Pose(position=p, orientation=Quaternion(*q))
00039 return nav_goal
00040
00041
00042 def pt_result_cb(userdata, state, result):
00043 rospy.loginfo('result!! num_persons=%d',len(result.ps.peopleSet))
00044 if len(result.ps.peopleSet)<1:
00045 return 'aborted'
00046 else:
00047 userdata.frame_id_pt_out = result.ps.header.frame_id
00048 userdata.x_pt_out = result.ps.peopleSet[0].x
00049 userdata.y_pt_out = result.ps.peopleSet[0].y
00050 userdata.id_pt_out = result.ps.peopleSet[0].targetId
00051 userdata.theta_pt_out = 0
00052 return 'succeeded'
00053
00054
00055
00056
00057
00058
00059 def main():
00060 rospy.init_node('concurrent_hri_move_base')
00061
00062
00063 sm = smach.StateMachine(['succeeded','aborted','preempted'])
00064
00065
00066
00067
00068
00069
00070
00071
00072 def hri_mb_out_cb(outcome_map):
00073 if outcome_map['CC_HRI'] == 'succeeded' and outcome_map['CC_MOVE_BASE'] == 'succeeded':
00074 return 'succeeded'
00075 else:
00076 return 'aborted'
00077
00078
00079 hri_mb_cc = smach.Concurrence(outcomes=['succeeded', 'aborted', 'preempted'],
00080 default_outcome='aborted',
00081 input_keys=['cc_hri_tts', 'cc_hri_head', 'cc_frame_id',
00082 'cc_goal_x', 'cc_goal_y', 'cc_goal_theta'],
00083 child_termination_cb = lambda so: False,
00084 outcome_cb = hri_mb_out_cb)
00085 with hri_mb_cc:
00086 smach.Concurrence.add('CC_HRI',
00087 smach_ros.SimpleActionState('hri',
00088 sequenceAction,
00089 goal_cb=hri_goal_cb,
00090 input_keys=['tts_in','head_in']),
00091 remapping={'tts_in':'cc_hri_tts',
00092 'head_in':'cc_hri_head'})
00093
00094 smach.Concurrence.add('CC_MOVE_BASE',
00095 smach_ros.SimpleActionState('MoveBase',
00096 MoveBaseAction,
00097 goal_cb=move_base_goal_cb,
00098 input_keys=['frame_id_in', 'goal_x_in',
00099 'goal_y_in', 'goal_theta_in']),
00100 remapping={'frame_id_in':'cc_frame_id',
00101 'goal_x_in':'cc_goal_x',
00102 'goal_y_in':'cc_goal_y',
00103 'goal_theta_in':'cc_goal_theta'})
00104
00105
00106
00107 with sm:
00108
00109 sm.userdata.sm_hri_tts_1 = "I am looking for a person in the room"
00110 sm.userdata.sm_hri_head_1 = "head_random_4.xml"
00111 smach.StateMachine.add('HRI_BEFORE_CC',
00112 smach_ros.SimpleActionState('hri',
00113 sequenceAction,
00114 goal_cb=hri_goal_cb,
00115 input_keys=['tts_in', 'head_in']),
00116 transitions={'succeeded':'AC_PT'},
00117 remapping={'tts_in':'sm_hri_tts_1',
00118 'head_in':'sm_hri_head_1'})
00119
00120
00121 smach.StateMachine.add('AC_PT',
00122 smach_ros.SimpleActionState('people_tracking',
00123 peopleTrackAction,
00124 result_cb=pt_result_cb,
00125 output_keys=['frame_id_pt_out','x_pt_out',
00126 'y_pt_out','id_pt_out','theta_pt_out']),
00127 transitions={'succeeded':'CC_HRI_MB',
00128 'aborted':'HRI_FAIL'},
00129 remapping={'frame_id_pt_out':'sm_frame_id',
00130 'x_pt_out':'sm_goal_x',
00131 'y_pt_out':'sm_goal_y',
00132 'id_pt_out':'sm_target_id',
00133 'theta_pt_out':'sm_goal_theta'})
00134
00135
00136 sm.userdata.sm_hri_tts_2 = "I could not find anyone in this room"
00137 sm.userdata.sm_hri_head_2 = "head_random_4.xml"
00138 smach.StateMachine.add('HRI_FAIL',
00139 smach_ros.SimpleActionState('hri',
00140 sequenceAction,
00141 goal_cb=hri_goal_cb,
00142 input_keys=['tts_in', 'head_in']),
00143 transitions={'succeeded':'HRI_BEFORE_CC'},
00144 remapping={'tts_in':'sm_hri_tts_2',
00145 'head_in':'sm_hri_head_2'})
00146
00147
00148
00149 sm.userdata.sm_hri_tts_3 = "I found a person close to me. I am approaching the target"
00150 sm.userdata.sm_hri_head_3 = "head_random_4.xml"
00151 smach.StateMachine.add('CC_HRI_MB',
00152 hri_mb_cc,
00153 transitions={'succeeded':'HRI_AFTER_CC'},
00154 remapping={'cc_hri_tts':'sm_hri_tts_3',
00155 'cc_hri_head':'sm_hri_head_3',
00156 'cc_frame_id':'sm_frame_id',
00157 'cc_goal_x':'sm_goal_x',
00158 'cc_goal_y':'sm_goal_y',
00159 'cc_goal_theta':'sm_goal_theta'})
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 sm.userdata.sm_hri_tts_4 = "I wish I have someone standing in front of me"
00175 sm.userdata.sm_hri_head_4 = "head_random_4.xml"
00176 smach.StateMachine.add('HRI_AFTER_CC',
00177 smach_ros.SimpleActionState('hri',
00178 sequenceAction,
00179 goal_cb=hri_goal_cb,
00180 input_keys=['tts_in', 'head_in']),
00181 transitions={'succeeded':'succeeded'},
00182 remapping={'tts_in':'sm_hri_tts_4',
00183 'head_in':'sm_hri_head_4'})
00184
00185
00186 sis = smach_ros.IntrospectionServer('server_name', sm, '/SM_ROOT')
00187 sis.start()
00188
00189
00190 outcome = sm.execute()
00191
00192
00193 rospy.spin()
00194 sis.stop()
00195
00196
00197 if __name__ == '__main__':
00198 main()
00199