00001
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
00028
00029
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
00079
00080
00081
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
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)),
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
00124 transitions = {'succeeded':'succeeded'})
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
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
00158 tgoal = SingleJointPositionGoal()
00159 tgoal.position = 0.040
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
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
00185
00186 outcome = sm.execute()
00187
00188
00189 sis.stop()
00190
00191
00192