sm_hfa_show_robot.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('rfid_behaviors')
00005 roslib.load_manifest('pr2_grasp_behaviors')
00006 roslib.load_manifest('hrl_trajectory_playback')
00007 roslib.load_manifest('pr2_controllers_msgs')
00008 roslib.load_manifest('robotis')
00009 import rospy
00010 
00011 import smach
00012 import actionlib
00013 
00014 from smach_ros import SimpleActionState, ServiceState, IntrospectionServer
00015 from geometry_msgs.msg import PoseStamped, PoseWithCovarianceStamped
00016 from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
00017 from rfid_behaviors.srv import NextBestVantage
00018 from rfid_behaviors.srv import HandoffSrv, HandoffSrvRequest
00019 from rfid_behaviors.srv import FloatFloat_Int32Request as RotateBackupSrvRequest
00020 from rfid_behaviors.srv import FloatFloat_Int32 as RotateBackupSrv
00021 from pr2_controllers_msgs.msg import PointHeadAction, PointHeadGoal
00022 from pr2_controllers_msgs.msg import SingleJointPositionAction, SingleJointPositionGoal
00023 from robotis.srv import MoveAng, MoveAngRequest
00024 from hrl_trajectory_playback.srv import TrajPlaybackSrv, TrajPlaybackSrvRequest
00025 
00026 import sm_rfid_delivery
00027 #from sm_next_best_vantage import BestVantage
00028 # import sm_fetch
00029 # import sm_rfid_explore
00030 
00031 class PrintStr(smach.State):
00032     def __init__(self, ins = 'Hand me an object [ENTER]'):
00033         smach.State.__init__(self, outcomes=['succeeded', 'aborted', 'preempted'])
00034         self.ins = ins
00035 
00036     def execute(self, userdata):
00037         rospy.logout( 'Executing PrintStr: %s' % self.ins )
00038         raw_input()
00039         return 'succeeded'
00040 
00041 class InitLocalization(smach.State):
00042     def __init__(self, init_pose = None):
00043         smach.State.__init__(self, outcomes=['succeeded', 'aborted'])
00044         self.init_pose = init_pose
00045                             
00046     def execute(self, userdata):
00047         rospy.logout( 'Initializing Localization' )
00048 
00049         pub = rospy.Publisher( '/initialpose', PoseWithCovarianceStamped )
00050         rospy.sleep( 0.5 )
00051 
00052         if not self.init_pose:
00053             msg = PoseWithCovarianceStamped()
00054             msg.header.frame_id = '\map'
00055 
00056             msg.pose.pose.position.x = -1.565
00057             msg.pose.pose.position.y =  0.807
00058             msg.pose.pose.position.z =  0.000
00059 
00060             msg.pose.pose.orientation.w = 1.000
00061 
00062             msg.pose.covariance = [0.25, 0.0, 0.0, 0.0,
00063                                               0.0, 0.0, 0.0, 0.25,
00064                                               0.0, 0.0, 0.0, 0.0,
00065                                               0.0, 0.0, 0.0, 0.0,
00066                                               0.0, 0.0, 0.0, 0.0,
00067                                               0.0, 0.068, 0.0, 0.0,
00068                                               0.0, 0.0, 0.0, 0.0,
00069                                               0.0, 0.0, 0.0, 0.0,
00070                                               0.0, 0.0, 0.0, 0.0]
00071 
00072             print 'RUNNING: ', msg
00073 
00074         raw_input( 'Drive the robot to the initial location (in kitchen by default).  Hit [ENTER] when done.' )
00075         msg.header.stamp = rospy.Time(0)
00076         pub.publish( msg )
00077 
00078         # for i in xrange( 5 ):
00079         #     msg.header.stamp = rospy.Time(0)
00080         #     pub.publish( msg )
00081         #     rospy.sleep( 0.05 )
00082             
00083         return 'succeeded'
00084 
00085 
00086 def init_local_test():
00087     sm = smach.StateMachine( outcomes=['succeeded','aborted'] )
00088     with sm:
00089         smach.StateMachine.add(
00090             'INIT_LOCALIZATION',
00091             InitLocalization(),
00092             transitions = { 'succeeded':'succeeded' })
00093     return sm
00094 
00095 
00096 def cousins_demo():
00097     # Create a SMACH state machine
00098     sm = smach.StateMachine(outcomes=['succeeded','aborted','preempted'],
00099                             input_keys = [ 'person_id' ])
00100 
00101     with sm:
00102 
00103         smach.StateMachine.add(
00104             'ROTATE_BEFORE_MOVE',
00105             ServiceState( '/rotate_backup',
00106                           RotateBackupSrv,
00107                           request = RotateBackupSrvRequest( 3.14, 0.0)),  # Full 180-deg spin.
00108             transitions = { 'succeeded':'MOVE_SHOW_OFF_POSE' })
00109 
00110         gd = MoveBaseGoal()
00111         gd.target_pose.header.frame_id = '/map'
00112         gd.target_pose.header.stamp = rospy.Time(0)
00113         gd.target_pose.pose.position.x = 2.956
00114         gd.target_pose.pose.position.y = 3.047
00115         gd.target_pose.pose.orientation.z = 0.349
00116         gd.target_pose.pose.orientation.w = 0.937
00117 
00118         smach.StateMachine.add(
00119             'MOVE_SHOW_OFF_POSE',
00120             SimpleActionState( '/move_base',
00121                                MoveBaseAction,
00122                                goal = gd ),
00123             # transitions = {'succeeded':'READY_RETURN_HALLWAY'})
00124             transitions = {'succeeded':'succeeded'})
00125 
00126 
00127         # smach.StateMachine.add(
00128         #     'READY_RETURN_HALLWAY',
00129         #     PrintStr('Ready to return to hallway [ENTER]'), 
00130         #     transitions = { 'succeeded':'MOVE_HALLWAY' })
00131 
00132         # go = MoveBaseGoal()
00133         # go.target_pose.header.frame_id = '/map'
00134         # go.target_pose.header.stamp = rospy.Time(0)
00135         # go.target_pose.pose.position.x = -5.07
00136         # go.target_pose.pose.position.y = 8.725
00137         # go.target_pose.pose.orientation.z = 0.926
00138         # go.target_pose.pose.orientation.w = 0.377
00139 
00140         # smach.StateMachine.add(
00141         #     'MOVE_HALLWAY',
00142         #     SimpleActionState( '/move_base',
00143         #                        MoveBaseAction,
00144         #                        goal = go ),  # Back down the hallway
00145         #     transitions = {'succeeded':'succeeded'})
00146 
00147         
00148 
00149             
00150     return sm
00151 
00152 if False:
00153     rospy.init_node('localization_trial')
00154 
00155     sm = smach.StateMachine( outcomes=['succeeded','aborted','preempted'] )
00156     with sm:
00157         # Just a precation
00158         tgoal = SingleJointPositionGoal()
00159         tgoal.position = 0.040  # all the way up is 0.200
00160         tgoal.min_duration = rospy.Duration( 2.0 )
00161         tgoal.max_velocity = 1.0
00162         smach.StateMachine.add(
00163             'TORSO_SETUP',
00164             SimpleActionState( 'torso_controller/position_joint_action',
00165                                SingleJointPositionAction,
00166                                goal = tgoal),
00167             transitions = { 'succeeded': 'succeeded' })
00168 
00169     sm.execute()
00170     
00171 
00172 if __name__ == '__main__':
00173 # if False:
00174     rospy.init_node('smach_aware_home')
00175 
00176     sm = cousins_demo()
00177 
00178     sis = IntrospectionServer('sm_aware_home', sm, '/SM_AWARE_HOME')
00179     sis.start()
00180 
00181     rospy.logout( 'READY TO RUN AWARE_HOME DEMO' )
00182 
00183     sm.userdata.person_id = 'person      '
00184     # sm.userdata.explore_radius = 1.5
00185     # sm.userdata.explore_rfid_reads = []
00186     outcome = sm.execute()
00187 
00188     # rospy.spin()
00189     sis.stop()
00190 
00191     
00192 


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