10 #include <sensor_msgs/NavSatStatus.h> 11 #include <sensor_msgs/NavSatFix.h> 13 #include <nav_msgs/Odometry.h> 22 void callback(
const nav_msgs::OdometryConstPtr& odom) {
32 double northing, easting, latitude, longitude;
34 sensor_msgs::NavSatFix fix;
36 northing = odom->pose.pose.position.y;
37 easting = odom->pose.pose.position.x;
42 fix.header.frame_id = odom->header.frame_id;
45 std::size_t pos = odom->header.frame_id.find(
"/utm_");
46 if(pos==std::string::npos) {
47 ROS_WARN(
"UTM zone not found in frame_id");
50 zone = odom->header.frame_id.substr(pos + 5, 3);
51 fix.header.frame_id = odom->header.frame_id.substr(0, pos);
56 fix.header.stamp = odom->header.stamp;
58 UTMtoLL(northing, easting, zone, latitude, longitude);
60 fix.latitude = latitude;
61 fix.longitude = longitude;
62 fix.altitude = odom->pose.pose.position.z;
64 fix.position_covariance[0] = odom->pose.covariance[0];
65 fix.position_covariance[1] = odom->pose.covariance[1];
66 fix.position_covariance[2] = odom->pose.covariance[2];
67 fix.position_covariance[3] = odom->pose.covariance[6];
68 fix.position_covariance[4] = odom->pose.covariance[7];
69 fix.position_covariance[5] = odom->pose.covariance[8];
70 fix.position_covariance[6] = odom->pose.covariance[12];
71 fix.position_covariance[7] = odom->pose.covariance[13];
72 fix.position_covariance[8] = odom->pose.covariance[14];
74 fix.status.status = sensor_msgs::NavSatStatus::STATUS_FIX;
79 int main (
int argc,
char **argv) {
80 ros::init(argc, argv,
"utm_odometry_to_navsatfix_node");
87 fix_pub = node.
advertise<sensor_msgs::NavSatFix>(
"odom_fix", 10);
std::string child_frame_id
int main(int argc, char **argv)
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
static void UTMtoLL(const double UTMNorthing, const double UTMEasting, const char *UTMZone, double &Lat, double &Long)
ROSCPP_DECL void spin(Spinner &spinner)
static ros::Publisher fix_pub
Universal Transverse Mercator transforms.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void callback(const nav_msgs::OdometryConstPtr &odom)