sm_rfid_servo_approach.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 import roslib
00003 roslib.load_manifest('rfid_demos')
00004 roslib.load_manifest('robotis')
00005 import rospy
00006 
00007 import smach
00008 from smach_ros import SimpleActionState, ServiceState, IntrospectionServer
00009 import actionlib
00010 
00011 from rfid_servoing.msg import ServoAction, ServoGoal
00012 from rfid_artoolkit.msg import UpCloseAction, UpCloseGoal
00013 from pr2_controllers_msgs.msg import PointHeadAction, PointHeadGoal
00014 from explore_hrl.msg import ExploreAction, ExploreActionGoal
00015 from rfid_behaviors.srv import HandoffSrv
00016 from rfid_behaviors.srv import FlapEarsSrv
00017 from rfid_behaviors.srv import String_Int32 as OrientSrv
00018 from rfid_behaviors.srv import String_Int32Request as OrientSrvRequest
00019 from robotis.srv import MoveAng, MoveAngRequest
00020 
00021 #import rfid_search
00022 import yaml
00023 
00024 def sm_rfid_servo_approach():
00025     # Create a SMACH state machine
00026     sm = smach.StateMachine( outcomes = ['succeeded','aborted','preempted'],
00027                              input_keys = ['tagid'])
00028 
00029     # Open the container
00030     with sm:
00031         # Initial RFID Ear Flapping
00032         smach.StateMachine.add(
00033             'FLAP_EARS',
00034             ServiceState( '/rfid_orient/flap', FlapEarsSrv ),
00035             transitions = { 'succeeded' : 'ORIENT' })
00036 
00037         # Orient towards tag
00038         smach.StateMachine.add(
00039             'ORIENT',
00040             ServiceState( '/rfid_orient/orient',
00041                           OrientSrv,
00042                           request_slots = ['data']), #request = OrientSrvRequest( 'person      ' )
00043             transitions = { 'succeeded' : 'SERVO' },
00044             remapping = {'data':'tagid'}) # input
00045 
00046         # Servoing is a basic state machine.  Success means servoing finished @ obs.
00047         smach.StateMachine.add(
00048             'SERVO',
00049             SimpleActionState( '/rfid_servo/servo_act',
00050                                ServoAction,
00051                                goal_slots = ['tagid']), #goal = ServoGoal( 'person      ' ),
00052             transitions = { 'succeeded': 'TUCK_LEFT' },
00053             remapping = {'tagid':'tagid'}) # input
00054 
00055         # Tuck Left (non-blocking)
00056         smach.StateMachine.add(
00057             'TUCK_LEFT',
00058             ServiceState( 'robotis/servo_left_pan_moveangle',
00059                           MoveAng,
00060                           request = MoveAngRequest( 1.350, 0.2, 0 )), # ang (float), angvel (float), blocking (bool)
00061             transitions = {'succeeded':'TUCK_RIGHT'})
00062 
00063         # Tuck Right (non-blocking)
00064         smach.StateMachine.add(
00065             'TUCK_RIGHT',
00066             ServiceState( 'robotis/servo_right_pan_moveangle',
00067                           MoveAng,
00068                           request = MoveAngRequest( -1.350, 0.2, 0 )), # ang (float), angvel (float), blocking (bool)
00069             transitions = {'succeeded':'succeeded'})
00070 
00071     return sm
00072 
00073 
00074 if __name__ == '__main__':
00075     import optparse
00076     p = optparse.OptionParser()
00077     p.add_option('--tag', action='store', type='string', dest='tagid',
00078                  help='Tagid to approach', default='person      ')
00079     opt, args = p.parse_args()
00080 
00081     print 'SERVO APPROACH to ID: \'%s\'' % (opt.tagid)
00082 
00083     rospy.init_node('smach_example_state_machine')
00084 
00085     sm = sm_rfid_servo_approach()
00086 
00087     sis = IntrospectionServer('RFID_servo_approach', sm, '/SM_RFID_SERVO_APPROACH')
00088     sis.start()
00089 
00090     sm.userdata.tagid = opt.tagid
00091     outcome = sm.execute()
00092     
00093     sis.stop()
00094 
00095     
00096 


rfid_demos
Author(s): Travis Deyle
autogenerated on Wed Nov 27 2013 11:50:51