guiding.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 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 #class SimpleActionWithFeedbackState(smach.State):
00022     def __init__(self,
00023             # Action info
00024             action_name,
00025             action_spec,
00026             # Default goal 
00027             goal = None,
00028             goal_key = None,
00029             goal_slots = [],
00030             goal_cb = None,
00031             goal_cb_args = [],
00032             goal_cb_kwargs = {},
00033             # Result modes
00034             result_key = None,
00035             result_slots = [],
00036             result_cb = None,
00037             result_cb_args = [],
00038             result_cb_kwargs = {},
00039             # Keys
00040             input_keys = [],
00041             output_keys = [],
00042             outcomes = [],
00043             # Timeouts
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 #    def _goal_feedback_cb(self, feedback):
00054 #        sys.stdout.write('feedback callback called')
00055 #        sys.stdout.flush()
00056    
00057     def callback(self,data):
00058         sys.stdout.write('people callback called!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n')
00059         sys.stdout.flush()
00060 #        for i in range(0,len(peopleSet.peopleSet)):
00061 #           if peopleSet.peopleSet[i].target_id == self.person_id:
00062 #                target_frame = "/base_link"
00063 #                source_fame  = peopleSet.header.frame_id
00064 #                time         = peopleSet.header.stamp
00065 #                if self.tf.canTransform(target_frame, source_frame, time):
00066 #                    pose_msg = PoseStamped()
00067 #                    pose_msg.header = peopleSet.header
00068 #                    pose_msg.pose.position.x = peopleSet.peopleSet.x
00069 #                    pose_msg.pose.position.y = peopleSet.peopleSet.y
00070 #                    self.person_pose=self.tf.TransformPose(target_frame, pose_msg)
00071 #                break
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 # main
00090 def main():
00091     rospy.init_node('guiding')
00092 
00093     # Create a SMACH state machine
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     # Define userdata
00100     #sm.userdata.sm_frame_id   = "/tibi/base_link"
00101     #sm.userdata.sm_goal_x     = 2.0
00102     #sm.userdata.sm_goal_y     = 0.0
00103     #sm.userdata.sm_goal_theta = 0.0
00104 
00105     # Add states to the State Machine
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     # Create and start the introspection server
00123     sis = smach_ros.IntrospectionServer('server_name', sm, '/SM_ROOT')
00124     sis.start()
00125 
00126     # Execute the state machine
00127     outcome = sm.execute()
00128 
00129     # Wait for ctrl-c to stop the application
00130     rospy.spin()
00131     sis.stop()
00132 
00133 
00134 if __name__ == '__main__':
00135     main()
00136 


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