Go to the documentation of this file.00001
00002 import roslib
00003 roslib.load_manifest('rfid_demos')
00004 import rospy
00005
00006 import smach
00007 from smach_ros import SimpleActionState, ServiceState, IntrospectionServer
00008 import actionlib
00009
00010 from rfid_servoing.msg import ServoAction, ServoGoal
00011 from rfid_artoolkit.msg import UpCloseAction, UpCloseGoal
00012 from pr2_controllers_msgs.msg import PointHeadAction, PointHeadGoal
00013 from explore_hrl.msg import ExploreAction, ExploreActionGoal
00014 from rfid_behaviors.srv import HandoffSrv
00015 from rfid_behaviors.srv import FlapEarsSrv
00016 from rfid_behaviors.srv import OrientSrv, OrientSrvRequest
00017 from robotis.srv import MoveAng, MoveAngRequest
00018
00019
00020 import yaml
00021
00022
00023
00024 def sm_delivery():
00025
00026 sm = smach.StateMachine( outcomes = ['succeeded','aborted','preempted'],
00027 input_keys = ['tagid'])
00028
00029
00030 with sm:
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 smach.StateMachine.add(
00046 'FLAP_EARS',
00047 ServiceState( '/rfid_orient/flap', FlapEarsSrv ),
00048 transitions = { 'succeeded' : 'ORIENT' })
00049
00050
00051 smach.StateMachine.add(
00052 'ORIENT',
00053 ServiceState( '/rfid_orient/orient',
00054 OrientSrv,
00055 request_slots = ['data'],
00056 input_keys=['data']),
00057 transitions = { 'succeeded' : 'SERVO' },
00058 remapping = {'data':'tagid'})
00059
00060
00061 smach.StateMachine.add(
00062 'SERVO',
00063 SimpleActionState( '/rfid_servo/servo_act',
00064 ServoAction,
00065 goal_slots = ['tagid']),
00066 transitions = { 'succeeded': 'TUCK_LEFT' },
00067 remapping = {'tagid':'tagid'})
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 smach.StateMachine.add(
00113 'TUCK_LEFT',
00114 ServiceState( 'robotis/servo_left_pan_moveangle',
00115 MoveAng,
00116 request = MoveAngRequest( 1.350, 0.2, 0 )),
00117 transitions = {'succeeded':'TUCK_RIGHT'})
00118
00119
00120 smach.StateMachine.add(
00121 'TUCK_RIGHT',
00122 ServiceState( 'robotis/servo_right_pan_moveangle',
00123 MoveAng,
00124 request = MoveAngRequest( -1.350, 0.2, 0 )),
00125 transitions = {'succeeded':'HANDOFF'})
00126
00127
00128 smach.StateMachine.add(
00129 'HANDOFF',
00130 ServiceState( '/rfid_handoff/handoff', HandoffSrv ),
00131 transitions = { 'succeeded' : 'succeeded' })
00132
00133
00134
00135 return sm
00136
00137
00138 if __name__ == '__main__':
00139 rospy.init_node('smach_example_state_machine')
00140
00141 sm = sm_delivery()
00142
00143 sis = IntrospectionServer('RFID_delivery', sm, '/SM_ROOT')
00144 sis.start()
00145
00146 sm.userdata.tagid = 'person '
00147 outcome = sm.execute()
00148
00149 rospy.spin()
00150 sis.stop()
00151
00152
00153