utm_odometry_node.cpp
Go to the documentation of this file.
1 /*
2  * Translates sensor_msgs/NavSat{Fix,Status} into nav_msgs/Odometry using UTM
3  */
4 
5 #include <ros/ros.h>
8 #include <sensor_msgs/NavSatStatus.h>
9 #include <sensor_msgs/NavSatFix.h>
10 #include <gps_common/conversions.h>
11 #include <nav_msgs/Odometry.h>
12 
13 using namespace gps_common;
14 
16 std::string frame_id, child_frame_id;
17 double rot_cov;
18 
19 void callback(const sensor_msgs::NavSatFixConstPtr& fix) {
20  if (fix->status.status == sensor_msgs::NavSatStatus::STATUS_NO_FIX) {
21  ROS_DEBUG_THROTTLE(60,"No fix.");
22  return;
23  }
24 
25  if (fix->header.stamp == ros::Time(0)) {
26  return;
27  }
28 
29  double northing, easting;
30  std::string zone;
31 
32  LLtoUTM(fix->latitude, fix->longitude, northing, easting, zone);
33 
34  if (odom_pub) {
35  nav_msgs::Odometry odom;
36  odom.header.stamp = fix->header.stamp;
37 
38  if (frame_id.empty())
39  odom.header.frame_id = fix->header.frame_id;
40  else
41  odom.header.frame_id = frame_id;
42 
43  odom.child_frame_id = child_frame_id;
44 
45  odom.pose.pose.position.x = easting;
46  odom.pose.pose.position.y = northing;
47  odom.pose.pose.position.z = fix->altitude;
48 
49  odom.pose.pose.orientation.x = 0;
50  odom.pose.pose.orientation.y = 0;
51  odom.pose.pose.orientation.z = 0;
52  odom.pose.pose.orientation.w = 1;
53 
54  // Use ENU covariance to build XYZRPY covariance
55  boost::array<double, 36> covariance = {{
56  fix->position_covariance[0],
57  fix->position_covariance[1],
58  fix->position_covariance[2],
59  0, 0, 0,
60  fix->position_covariance[3],
61  fix->position_covariance[4],
62  fix->position_covariance[5],
63  0, 0, 0,
64  fix->position_covariance[6],
65  fix->position_covariance[7],
66  fix->position_covariance[8],
67  0, 0, 0,
68  0, 0, 0, rot_cov, 0, 0,
69  0, 0, 0, 0, rot_cov, 0,
70  0, 0, 0, 0, 0, rot_cov
71  }};
72 
73  odom.pose.covariance = covariance;
74 
75  odom_pub.publish(odom);
76  }
77 }
78 
79 int main (int argc, char **argv) {
80  ros::init(argc, argv, "utm_odometry_node");
81  ros::NodeHandle node;
82  ros::NodeHandle priv_node("~");
83 
84  priv_node.param<std::string>("frame_id", frame_id, "");
85  priv_node.param<std::string>("child_frame_id", child_frame_id, "");
86  priv_node.param<double>("rot_covariance", rot_cov, 99999.0);
87 
88  odom_pub = node.advertise<nav_msgs::Odometry>("odom", 10);
89 
90  ros::Subscriber fix_sub = node.subscribe("fix", 10, callback);
91 
92  ros::spin();
93 }
94 
static ros::Publisher odom_pub
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())
std::string child_frame_id
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
static void LLtoUTM(const double Lat, const double Long, double &UTMNorthing, double &UTMEasting, char *UTMZone)
Definition: conversions.h:148
int main(int argc, char **argv)
Universal Transverse Mercator transforms.
bool param(const std::string &param_name, T &param_val, const T &default_val) const
double rot_cov
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::string frame_id
void callback(const sensor_msgs::NavSatFixConstPtr &fix)
#define ROS_DEBUG_THROTTLE(period,...)


gps_common
Author(s):
autogenerated on Fri Jun 7 2019 21:42:10