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 roslib.load_manifest('rfid_behaviors')
00010 roslib.load_manifest('robotis')
00011 import rospy
00012
00013 import smach
00014 from smach_ros import SimpleActionState, ServiceState, IntrospectionServer
00015 import actionlib
00016
00017 from rfid_servoing.msg import ServoAction, ServoGoal
00018 from robotis.srv import MoveAng, MoveAngRequest
00019 from geometry_msgs.msg import PoseStamped, Quaternion
00020 from move_base_msgs.msg import MoveBaseAction
00021 from std_msgs.msg import String
00022 from rfid_datacapture.srv import BagCapture, BagCaptureRequest
00023 from rfid_behaviors.srv import FlapEarsSrv
00024
00025 import rfid_datacapture.utils as rdut
00026
00027 import numpy as np, math
00028
00029
00030 def sm_rfid_servo_approach( yaml_fname ):
00031
00032 sm = smach.StateMachine( outcomes = ['succeeded','aborted','preempted'])
00033
00034
00035 with sm:
00036
00037 smach.StateMachine.add(
00038 'CAPTURE_POSITIONS',
00039 rdut.YAMLprocPoses( yaml_fname ),
00040 remapping = {'next_move_pose':'next_move_pose'},
00041 transitions = {'aborted':'succeeded',
00042 'succeeded':'READY_MOVE'})
00043
00044 smach.StateMachine.add(
00045 'READY_MOVE',
00046 rdut.MoveNotify(),
00047 transitions = {'succeeded':'MOVE_POSITION'})
00048
00049 smach.StateMachine.add(
00050 'MOVE_POSITION',
00051 SimpleActionState( '/move_base',
00052 MoveBaseAction,
00053 goal_slots = [ 'target_pose' ]),
00054 remapping = { 'target_pose' : 'next_move_pose' },
00055 transitions = {'aborted':'MANUAL_SKIP',
00056 'preempted':'aborted',
00057 'succeeded':'CAPTURE_TAGS'})
00058
00059 smach.StateMachine.add(
00060 'MANUAL_SKIP',
00061 rdut.ManualSkip(),
00062 transitions = {'succeeded':'CAPTURE_TAGS',
00063 'aborted':'CAPTURE_POSITIONS'})
00064
00065 smach.StateMachine.add(
00066 'CAPTURE_TAGS',
00067 rdut.YAMLprocMultitag( yaml_fname ),
00068 remapping = {'bagfile_name':'bagfile_name',
00069 'bagfile_topics':'bagfile_topics',
00070 'panrate':'panrate',
00071 'tagid':'tagid',
00072 'tilt_left':'tilt_left',
00073 'tilt_right':'tilt_right',
00074 'tilt_rate':'tilt_rate',
00075 'tilt_block':'tilt_block'},
00076 transitions = {'aborted':'CAPTURE_POSITIONS',
00077 'succeeded':'TILT_LEFT'})
00078
00079 smach.StateMachine.add(
00080 'TILT_LEFT',
00081 ServiceState( '/robotis/servo_left_tilt_moveangle',
00082 MoveAng,
00083 request_slots = ['angle','angvel','blocking']),
00084 transitions = {'succeeded':'TILT_RIGHT'},
00085 remapping = {'angle':'tilt_left',
00086 'angvel':'tilt_rate',
00087 'blocking':'tilt_block'})
00088
00089 smach.StateMachine.add(
00090 'TILT_RIGHT',
00091 ServiceState( '/robotis/servo_right_tilt_moveangle',
00092 MoveAng,
00093 request_slots = ['angle','angvel','blocking']),
00094 transitions = {'succeeded':'START_BAG_CAPTURE'},
00095 remapping = {'angle':'tilt_right',
00096 'angvel':'tilt_rate',
00097 'blocking':'tilt_block'})
00098
00099
00100 smach.StateMachine.add(
00101 'START_BAG_CAPTURE',
00102 ServiceState( '/bag_cap/capture',
00103 BagCapture,
00104 request_slots = ['topics','dest'] ),
00105 remapping = {'topics':'bagfile_topics',
00106 'dest':'bagfile_name'},
00107 transitions = {'succeeded':'FLAP'})
00108
00109
00110
00111 smach.StateMachine.add(
00112 'FLAP',
00113 ServiceState( '/rfid_orient/flap',
00114 FlapEarsSrv,
00115 request_slots = ['data','panrate']),
00116 transitions = { 'succeeded': 'STOP_BAG_CAPTURE' },
00117 remapping = {'data':'tagid',
00118 'panrate':'panrate'})
00119
00120 smach.StateMachine.add(
00121 'STOP_BAG_CAPTURE',
00122 ServiceState( '/bag_cap/capture',
00123 BagCapture,
00124 request = BagCaptureRequest('','') ),
00125 transitions = {'succeeded':'TUCK_LEFT'})
00126
00127
00128 smach.StateMachine.add(
00129 'TUCK_LEFT',
00130 ServiceState( 'robotis/servo_left_pan_moveangle',
00131 MoveAng,
00132 request = MoveAngRequest( 1.250, 0.2, 0 )),
00133 transitions = {'succeeded':'TUCK_RIGHT'})
00134
00135
00136 smach.StateMachine.add(
00137 'TUCK_RIGHT',
00138 ServiceState( 'robotis/servo_right_pan_moveangle',
00139 MoveAng,
00140 request = MoveAngRequest( -1.250, 0.2, 0 )),
00141 transitions = {'succeeded':'CAPTURE_TAGS'})
00142
00143 return sm
00144
00145
00146 if __name__ == '__main__':
00147 import optparse
00148 p = optparse.OptionParser()
00149 p.add_option('--yaml', action='store', type='string', dest='yaml',
00150 help='Capture description yaml file', default='')
00151 opt, args = p.parse_args()
00152
00153 if opt.yaml == '':
00154 print 'ERROR: Must specify YAML file.'
00155 exit()
00156
00157 rospy.init_node('rfid_servo_capture')
00158
00159 sm = sm_rfid_servo_approach( opt.yaml )
00160
00161 sis = IntrospectionServer('RFID_servo_approach', sm, '/SM_RFID_SERVO_APPROACH')
00162 sis.start()
00163
00164 outcome = sm.execute()
00165
00166 sis.stop()
00167
00168
00169
00170