Go to the documentation of this file.00001
00002
00003
00004 __author__ = "Raul Perula-Martinez"
00005 __copyright__ = "Social Robots Group. Robotics Lab. University Carlos III of Madrid"
00006 __credits__ = ["Raul Perula-Martinez"]
00007 __license__ = "LEUC3M v1.0"
00008 __version__ = "0.0.0"
00009 __maintainer__ = "Raul Perula-Martinez"
00010 __email__ = "raul.perula@uc3m.es"
00011 __status__ = "Development"
00012
00013 import math
00014
00015 from geometry_msgs.msg import PoseWithCovarianceStamped, Quaternion
00016 from tf.transformations import quaternion_from_euler
00017
00018 import roslib
00019 import rosparam
00020 import rospy
00021
00022
00023 pkg_name = "maggie_navigation_config"
00024 roslib.load_manifest(pkg_name)
00025
00026
00027 class InitialposeSender():
00028
00029 """
00030 InitialposeSender class.
00031 """
00032
00033 def __init__(self):
00034 """
00035 Init method.
00036 """
00037
00038
00039 self.__initialpose_pub = rospy.Publisher('initialpose',
00040 PoseWithCovarianceStamped, queue_size=1, latch=True)
00041
00042 def run(self):
00043 """
00044 Spinner of the node.
00045
00046 @raise KeyError: exception when dictionary has an invalid key.
00047 @raise rosparam.RosParamException: exception when cannot open the config file.
00048 """
00049
00050 try:
00051
00052 data = rosparam.load_file(roslib.packages.get_pkg_dir(pkg_name) + "/config/initialpose.yaml",
00053 rospy.get_name())
00054 try:
00055
00056 place_data = data[0][0]
00057
00058
00059 msg = PoseWithCovarianceStamped()
00060
00061 msg.header.frame_id = "/map"
00062 msg.header.stamp = rospy.Time.now()
00063
00064 msg.pose.pose.position.x = place_data['x']
00065 msg.pose.pose.position.y = place_data['y']
00066 msg.pose.pose.position.z = 0
00067
00068 msg.pose.covariance[0] = place_data['cov_x']
00069 msg.pose.covariance[7] = place_data['cov_y']
00070 msg.pose.covariance[35] = place_data['cov_th']
00071
00072
00073 quat = quaternion_from_euler(0.0, 0.0, place_data['th'])
00074 msg.pose.pose.orientation = Quaternion(*quat.tolist())
00075
00076
00077 self.__initialpose_pub.publish(msg)
00078 except KeyError:
00079 rospy.logerr('[INITIAL_STATUS_SENDER] Error.')
00080 except rosparam.RosParamException:
00081 rospy.logerr('[INITIAL_STATUS_SENDER] Error loading config file')
00082
00083
00084 if __name__ == '__main__':
00085 try:
00086
00087 rospy.init_node(pkg_name)
00088
00089
00090 node = InitialposeSender()
00091 node.run()
00092
00093 rospy.spin()
00094 except rospy.ROSInterruptException:
00095 pass