Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 import roslib; roslib.load_manifest('srs_user_tests')
00029 import rospy
00030 from std_srvs.srv import Empty as EmptySrv
00031 from geometry_msgs.msg import Pose
00032 from gazebo_msgs.srv import SetModelState
00033 from gazebo_msgs.msg import ModelState
00034 from geometry_msgs.msg import PoseWithCovarianceStamped
00035 from std_msgs.msg import Empty as EmptyMsg
00036
00037
00038 def main():
00039 rospy.init_node('move_robot_to_given_place')
00040 while not rospy.is_shutdown():
00041 rospy.sleep(60)
00042 print "reposition robot now"
00043 reposition_robot()
00044
00045 def reposition_robot():
00046
00047 g_pause = rospy.ServiceProxy("/gazebo/pause_physics", EmptySrv)
00048 g_unpause = rospy.ServiceProxy("/gazebo/unpause_physics", EmptySrv)
00049 g_set_state = rospy.ServiceProxy("/gazebo/set_model_state",SetModelState)
00050 pub = rospy.Publisher("/initialpose", PoseWithCovarianceStamped,latch=True)
00051
00052
00053 rospy.wait_for_service("/gazebo/pause_physics")
00054
00055 rospy.loginfo("Pausing physics")
00056
00057 try:
00058
00059 g_pause()
00060
00061 except Exception, e:
00062
00063 rospy.logerr('Error on calling service: %s',str(e))
00064
00065
00066 pose = Pose()
00067
00068 pose.position.x = rospy.get_param('~position_x')
00069 pose.position.y = rospy.get_param('~position_y')
00070 pose.position.z = rospy.get_param('~position_z')
00071
00072 pose.orientation.x = rospy.get_param('~orientation_x')
00073 pose.orientation.y = rospy.get_param('~orientation_y')
00074 pose.orientation.z = rospy.get_param('~orientation_z')
00075 pose.orientation.w = rospy.get_param('~orientation_w')
00076
00077 state = ModelState()
00078
00079 state.model_name = "robot"
00080 state.pose = pose
00081
00082
00083 rospy.loginfo("Moving robot")
00084 try:
00085
00086 ret = g_set_state(state)
00087
00088 print ret.status_message
00089
00090 except Exception, e:
00091
00092 rospy.logerr('Error on calling service: %s',str(e))
00093
00094
00095
00096
00097 rospy.loginfo("Unpausing physics")
00098
00099 try:
00100
00101 g_unpause()
00102
00103 except Exception, e:
00104
00105 rospy.logerr('Error on calling service: %s',str(e))
00106
00107
00108
00109
00110 loc = PoseWithCovarianceStamped()
00111
00112 loc.pose.pose = pose
00113 loc.header.frame_id = "/map"
00114
00115
00116 rospy.loginfo("Adjusting localization")
00117 pub.publish(loc)
00118 pub.publish(loc)
00119 pub.publish(loc)
00120
00121
00122 if __name__ == '__main__':
00123 try:
00124 main()
00125 except rospy.ROSInterruptException: pass