00001
00002
00003
00004
00005 #include <ros/ros.h>
00006 #include <message_filters/subscriber.h>
00007 #include <message_filters/time_synchronizer.h>
00008 #include <sensor_msgs/NavSatStatus.h>
00009 #include <sensor_msgs/NavSatFix.h>
00010 #include <gps_common/conversions.h>
00011 #include <nav_msgs/Odometry.h>
00012
00013 using namespace gps_common;
00014
00015 static ros::Publisher odom_pub;
00016 std::string frame_id;
00017 double rot_cov;
00018
00019 void callback(const sensor_msgs::NavSatFixConstPtr& fix) {
00020 if (fix->status.status == sensor_msgs::NavSatStatus::STATUS_NO_FIX) {
00021 ROS_INFO("No fix.");
00022 return;
00023 }
00024
00025 double northing, easting;
00026 std::string zone;
00027
00028 LLtoUTM(fix->latitude, fix->longitude, northing, easting, zone);
00029
00030 if (odom_pub) {
00031 nav_msgs::Odometry odom;
00032 odom.header.stamp = fix->header.stamp;
00033
00034 if (frame_id.empty())
00035 odom.header.frame_id = fix->header.frame_id;
00036 else
00037 odom.header.frame_id = frame_id;
00038
00039 odom.pose.pose.position.x = easting;
00040 odom.pose.pose.position.y = northing;
00041 odom.pose.pose.position.z = fix->altitude;
00042
00043 odom.pose.pose.orientation.x = 1;
00044 odom.pose.pose.orientation.y = 0;
00045 odom.pose.pose.orientation.z = 0;
00046 odom.pose.pose.orientation.w = 0;
00047
00048
00049 boost::array<double, 36> covariance = {{
00050 fix->position_covariance[0],
00051 fix->position_covariance[1],
00052 fix->position_covariance[2],
00053 0, 0, 0,
00054 fix->position_covariance[3],
00055 fix->position_covariance[4],
00056 fix->position_covariance[5],
00057 0, 0, 0,
00058 fix->position_covariance[6],
00059 fix->position_covariance[7],
00060 fix->position_covariance[8],
00061 0, 0, 0,
00062 0, 0, 0, rot_cov, 0, 0,
00063 0, 0, 0, 0, rot_cov, 0,
00064 0, 0, 0, 0, 0, rot_cov
00065 }};
00066
00067 odom.pose.covariance = covariance;
00068
00069 odom_pub.publish(odom);
00070 }
00071 }
00072
00073 int main (int argc, char **argv) {
00074 ros::init(argc, argv, "utm_odometry_node");
00075 ros::NodeHandle node;
00076 ros::NodeHandle priv_node("~");
00077
00078 priv_node.param<std::string>("frame_id", frame_id, "");
00079 priv_node.param<double>("rot_covariance", rot_cov, 99999.0);
00080
00081 odom_pub = node.advertise<nav_msgs::Odometry>("odom", 10);
00082
00083 ros::Subscriber fix_sub = node.subscribe("fix", 10, callback);
00084
00085 ros::spin();
00086 }
00087