00001
00002
00003 import roslib; roslib.load_manifest('tibi_dabo_smachs')
00004 import rospy
00005 import smach
00006 import smach_ros
00007 import sys
00008 import tf
00009
00010 from tibi_dabo_msgs.msg import sequenceAction, sequenceGoal
00011 from geometry_msgs.msg import PoseStamped
00012 from smach_ros import ServiceState,SimpleActionState
00013 from tf import TransformListener
00014 from iri_perception_msgs.msg import peopleTrackingArray
00015 import time
00016 import threading
00017
00018 exit = 0
00019
00020 class SimpleActionWithFeedbackState(smach_ros.SimpleActionState):
00021
00022 def __init__(self,
00023
00024 action_name,
00025 action_spec,
00026
00027 goal = None,
00028 goal_key = None,
00029 goal_slots = [],
00030 goal_cb = None,
00031 goal_cb_args = [],
00032 goal_cb_kwargs = {},
00033
00034 result_key = None,
00035 result_slots = [],
00036 result_cb = None,
00037 result_cb_args = [],
00038 result_cb_kwargs = {},
00039
00040 input_keys = [],
00041 output_keys = [],
00042 outcomes = [],
00043
00044 exec_timeout = None,
00045 preempt_timeout = rospy.Duration(60.0),
00046 server_wait_timeout = rospy.Duration(60.0)
00047 ):
00048 smach_ros.SimpleActionState.__init__(self,action_name,action_spec,goal,goal_key,goal_slots,goal_cb,goal_cb_args,goal_cb_kwargs,result_key,result_slots,result_cb,result_cb_args,result_cb_kwargs,input_keys,output_keys,outcomes,exec_timeout,preempt_timeout,server_wait_timeout)
00049 self.subscriber = rospy.Subscriber('peopleSet', peopleTrackingArray, self.callback)
00050 self.tf = TransformListener()
00051 self.person_id = -1
00052
00053
00054
00055
00056
00057 def callback(self,data):
00058 sys.stdout.write('people callback called!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n')
00059 sys.stdout.flush()
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 def execute(self,userdata):
00074 self.person_id = userdata.person_id
00075 return smach_ros.SimpleActionState.execute(self,userdata)
00076
00077
00078 def hri_goal_cb(userdata, goal):
00079 rospy.loginfo('hri_goal_cb')
00080 tts_goal = sequenceGoal()
00081 tts_goal.sequence_file = [None]*5
00082 tts_goal.sequence_file[0] = userdata.tts_in
00083 tts_goal.sequence_file[1] = ""
00084 tts_goal.sequence_file[2] = ""
00085 tts_goal.sequence_file[3] = userdata.left_in
00086 tts_goal.sequence_file[4] = userdata.right_in
00087 return tts_goal
00088
00089
00090 def main():
00091 rospy.init_node('guiding')
00092
00093
00094 sm = smach.StateMachine(['succeeded','aborted','preempted'])
00095 sm.userdata.valid = 0
00096 sm.userdata.init_count = 0
00097 sm.userdata.detect_count = 0
00098 sm.userdata.ask_count = 0
00099
00100
00101
00102
00103
00104
00105
00106 with sm:
00107 sm.userdata.sm_hri_tts_exit = "El experimento ha acabado. Gracias por tu ayuda, ha sido un placer. Adios!"
00108 sm.userdata.sm_hri_left_exit = "left_arm_farewell.xml"
00109 sm.userdata.sm_hri_right_exit = "right_arm_farewell.xml"
00110 sm.userdata.sm_tracker_person_id=1;
00111 smach.StateMachine.add('HRI_EXIT',
00112 SimpleActionWithFeedbackState('hri',
00113 sequenceAction,
00114 goal_cb=hri_goal_cb,
00115 input_keys=['tts_in','left_in','right_in','person_id']),
00116 transitions={'succeeded':'succeeded'},
00117 remapping={'tts_in':'sm_hri_tts_exit',
00118 'left_in':'sm_hri_left_exit',
00119 'right_in':'sm_hri_right_exit',
00120 'person_id':'sm_tracker_person_id'})
00121
00122
00123 sis = smach_ros.IntrospectionServer('server_name', sm, '/SM_ROOT')
00124 sis.start()
00125
00126
00127 outcome = sm.execute()
00128
00129
00130 rospy.spin()
00131 sis.stop()
00132
00133
00134 if __name__ == '__main__':
00135 main()
00136