ui_detect_sm.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 import roslib
00003 roslib.load_manifest('srs_assisted_detection')
00004 
00005 import rospy
00006 
00007 import threading
00008 
00009 import smach
00010 from smach import StateMachine ,Concurrence
00011 from smach_ros import IntrospectionServer, SimpleActionState, MonitorState, IntrospectionServer
00012 
00013 import ui_detection
00014 import ui_answer
00015 
00016 from geometry_msgs.msg import *
00017 
00018 class UI_detection(smach.State):
00019     def __init__(self):
00020         smach.State.__init__(self, 
00021                              outcomes=['outcome1'],
00022                              output_keys=['detections'])
00023         
00024     def execute(self, userdata):
00025         rospy.loginfo('Executing state UI_detection')
00026         userdata.detections=ui_detection.asisted_Detection_server()
00027         return 'outcome1'
00028 
00029 class Answer(smach.State):
00030     def __init__(self):
00031         smach.State.__init__(self, 
00032                              outcomes=['success','retry'],
00033                              input_keys=['detections'],
00034                              output_keys=['action','pose','pose2d'])
00035         
00036     def execute(self, userdata):
00037         rospy.loginfo('Executing state Answer')
00038 
00039         x=ui_answer.asisted_answer_server(userdata.detections)
00040         #action
00041         if x[0]==1:
00042             userdata.action=x[2]
00043             userdata.pose=x[1]
00044             return 'success'
00045         #bbmove    
00046         if x[0]==2:
00047             userdata.pose2d=x[2]
00048             return 'retry'
00049   
00050 def main():
00051     rospy.init_node('sm_detect')
00052 
00053     sm0 = StateMachine(outcomes=['succeeded','not successful'])
00054     
00055     sm0.userdata.action=''
00056     sm0.userdata.pose=Pose()
00057     
00058     with sm0:
00059         smach.StateMachine.add('UI_detection', UI_detection(),
00060                                       transitions={'outcome1':'Answer'})
00061         smach.StateMachine.add('Answer', Answer(), 
00062                                transitions={'success':'succeeded','retry':'not successful'})
00063                      
00064 
00065     # Attach a SMACH introspection server
00066     sis = IntrospectionServer('smach_usecase_01', sm0, '/USE_CASE')
00067     sis.start()
00068 
00069     # Set preempt handler
00070     #smach.set_preempt_handler(sm0)
00071 
00072     # Execute SMACH tree in a separate thread so that we can ctrl-c the script
00073     smach_thread = threading.Thread(target = sm0.execute)
00074     smach_thread.start()
00075 
00076     # Signal handler
00077     rospy.spin()
00078 
00079 if __name__ == '__main__':
00080     main()


srs_assisted_detection
Author(s): Heiko Hoennige
autogenerated on Mon Oct 6 2014 08:31:59