00001
00002 import roslib
00003 roslib.load_manifest('rfid_datacapture')
00004 roslib.load_manifest('robotis')
00005 roslib.load_manifest('geometry_msgs')
00006 roslib.load_manifest('move_base_msgs')
00007 roslib.load_manifest('std_msgs')
00008 roslib.load_manifest('tf')
00009 import rospy
00010
00011 import smach
00012 from smach_ros import SimpleActionState, ServiceState, IntrospectionServer
00013 import actionlib
00014
00015 from rfid_servoing.msg import ServoAction, ServoGoal
00016 from robotis.srv import MoveAng, MoveAngRequest
00017 from geometry_msgs.msg import PoseStamped, Quaternion
00018 from move_base_msgs.msg import MoveBaseAction
00019 from std_msgs.msg import String
00020 from rfid_datacapture.srv import BagCapture, BagCaptureRequest
00021
00022 import rfid_datacapture.utils as rdut
00023
00024 import numpy as np, math
00025
00026
00027 def sm_rfid_servo_approach( yaml_fname ):
00028
00029 sm = smach.StateMachine( outcomes = ['succeeded','aborted','preempted'])
00030
00031
00032 with sm:
00033
00034 smach.StateMachine.add(
00035 'CAPTURE_MONITOR',
00036 rdut.YAMLproc( yaml_fname ),
00037 remapping = {'next_move_pose':'next_move_pose',
00038 'bagfile_name':'bagfile_name',
00039 'bagfile_topics':'bagfile_topics',
00040 'tagid':'tagid'},
00041 transitions = {'aborted':'succeeded',
00042 'succeeded':'MOVE_POSITION'})
00043
00044
00045 smach.StateMachine.add(
00046 'MOVE_POSITION',
00047 SimpleActionState( '/move_base',
00048 MoveBaseAction,
00049 goal_slots = [ 'target_pose' ]),
00050 remapping = { 'target_pose' : 'next_move_pose' },
00051 transitions = {'aborted':'MANUAL_SKIP',
00052 'preempted':'aborted',
00053 'succeeded':'START_BAG_CAPTURE'})
00054
00055 smach.StateMachine.add(
00056 'MANUAL_SKIP',
00057 rdut.ManualSkip(),
00058 transitions = {'succeeded':'START_BAG_CAPTURE',
00059 'aborted':'CAPTURE_MONITOR'})
00060
00061 smach.StateMachine.add(
00062 'START_BAG_CAPTURE',
00063 ServiceState( '/bag_cap/capture',
00064 BagCapture,
00065 request_slots = ['topics','dest'] ),
00066 remapping = {'topics':'bagfile_topics',
00067 'dest':'bagfile_name'},
00068 transitions = {'succeeded':'SERVO'})
00069
00070
00071
00072 smach.StateMachine.add(
00073 'SERVO',
00074 SimpleActionState( '/rfid_servo/servo_act',
00075 ServoAction,
00076 goal_slots = ['tagid']),
00077 transitions = { 'succeeded': 'STOP_BAG_CAPTURE' },
00078 remapping = {'tagid':'tagid'})
00079
00080 smach.StateMachine.add(
00081 'STOP_BAG_CAPTURE',
00082 ServiceState( '/bag_cap/capture',
00083 BagCapture,
00084 request = BagCaptureRequest('','') ),
00085 transitions = {'succeeded':'TUCK_LEFT'})
00086
00087
00088 smach.StateMachine.add(
00089 'TUCK_LEFT',
00090 ServiceState( 'robotis/servo_left_pan_moveangle',
00091 MoveAng,
00092 request = MoveAngRequest( 1.350, 0.2, 0 )),
00093 transitions = {'succeeded':'TUCK_RIGHT'})
00094
00095
00096 smach.StateMachine.add(
00097 'TUCK_RIGHT',
00098 ServiceState( 'robotis/servo_right_pan_moveangle',
00099 MoveAng,
00100 request = MoveAngRequest( -1.350, 0.2, 0 )),
00101 transitions = {'succeeded':'CAPTURE_MONITOR'})
00102
00103 return sm
00104
00105
00106 if __name__ == '__main__':
00107 import optparse
00108 p = optparse.OptionParser()
00109 p.add_option('--yaml', action='store', type='string', dest='yaml',
00110 help='Capture description yaml file', default='')
00111 opt, args = p.parse_args()
00112
00113 if opt.yaml == '':
00114 print 'ERROR: Must specify YAML file.'
00115 exit()
00116
00117 rospy.init_node('rfid_servo_capture')
00118
00119 sm = sm_rfid_servo_approach( opt.yaml )
00120
00121 sis = IntrospectionServer('RFID_servo_approach', sm, '/SM_RFID_SERVO_APPROACH')
00122 sis.start()
00123
00124 outcome = sm.execute()
00125
00126 sis.stop()
00127
00128
00129
00130