remove_latency.cpp
Go to the documentation of this file.
1 
7 #include <ros/ros.h>
8 #include <sensor_msgs/NavSatFix.h>
9 #include <sensor_msgs/Imu.h>
10 #include <nav_msgs/Odometry.h>
11 #include <iostream>
12 #include <string>
13 
14 
16  {
17 public:
18  RemoveLatency(const ros::NodeHandle &node_handle, const ros::NodeHandle &private_node_handle)
19  : nh_(node_handle), pnh_(private_node_handle)
20  {
21  this->init();
22  }
23  ~RemoveLatency() = default;
24 
25  void init();
26  void gpsCallback(const sensor_msgs::NavSatFixConstPtr& msg);
27  void headingCallback(const sensor_msgs::ImuConstPtr& heading_msg);
28  void ekfCallback(const nav_msgs::OdometryConstPtr& ekf_msg);
29  // Initialize Variables
30  double gps_latency_{0.0};
31  double ekf_latency_{0.0};
32  // public and private ros node handle
35  // Subscribers and publishers
42 };
43 
45 {
46  // Load params
47  nh_.getParam("/remove_latency/gps_latency", gps_latency_);
48  nh_.getParam("/remove_latency/ekf_latency", ekf_latency_);
49 
50  gps_sub_ = nh_.subscribe("/piksi_receiver/navsatfix_best_fix", 1000, &RemoveLatency::gpsCallback, this);
51  heading_sub_ = nh_.subscribe("/heading", 1000, &RemoveLatency::headingCallback, this);
52  gps_pub_ = nh_.advertise<sensor_msgs::NavSatFix>("/piksi_receiver/navsatfix_best_fix/corrected_latency", 1000);
53  heading_pub_ = nh_.advertise<sensor_msgs::Imu>("/heading/corrected_latency", 1000);
54 
55  if (ekf_latency_!=0){
56  ekf_sub_ = nh_.subscribe("/odometry/filtered/global", 1000, &RemoveLatency::ekfCallback, this);
57  ekf_pub_ = nh_.advertise<nav_msgs::Odometry>("/odometry/filtered/global/corrected_latency", 1000);
58  }
59 
60 }
61 
62 
63 void RemoveLatency::gpsCallback(const sensor_msgs::NavSatFixConstPtr& gps_msg)
64 {
65  if (gps_latency_==0.0){
66  gps_pub_.publish(*gps_msg);
67  }
68  else{
69  sensor_msgs::NavSatFix gps_latency_msg;
70  gps_latency_msg = *gps_msg;
71  ros::Duration gps_latency_2rosdur(gps_latency_*0.001);
72  gps_latency_msg.header.stamp = gps_msg->header.stamp - gps_latency_2rosdur;
73  gps_pub_.publish(gps_latency_msg);
74  }
75 }
76 
77 void RemoveLatency::headingCallback(const sensor_msgs::ImuConstPtr& heading_msg)
78 {
79  if (gps_latency_==0.0){
80  heading_pub_.publish(*heading_msg);
81  }
82  else{
83  sensor_msgs::Imu heading_latency_msg;
84  heading_latency_msg = *heading_msg;
85  ros::Duration gps_latency_2rosdur(gps_latency_*0.001);
86  heading_latency_msg.header.stamp = heading_msg->header.stamp - gps_latency_2rosdur;
87  heading_pub_.publish(heading_latency_msg);
88  }
89 }
90 
91 void RemoveLatency::ekfCallback(const nav_msgs::OdometryConstPtr& ekf_msg)
92 {
93  nav_msgs::Odometry ekf_latency_msg;
94  ekf_latency_msg = *ekf_msg;
95  ros::Duration ekf_latency_2rosdur(ekf_latency_*0.001);
96  ekf_latency_msg.header.stamp = ekf_msg->header.stamp - ekf_latency_2rosdur;
97  ekf_pub_.publish(ekf_latency_msg);
98 }
99 
100 int main(int argc, char **argv)
101 {
102  ros::init(argc, argv, "remove_latency");
103  ros::NodeHandle nh;
104  ros::NodeHandle nh_private("~");
105  RemoveLatency node(nh, nh_private);
106  ros::spin();
107 
108  return 0;
109 }
msg
void ekfCallback(const nav_msgs::OdometryConstPtr &ekf_msg)
ros::Publisher heading_pub_
RemoveLatency(const ros::NodeHandle &node_handle, const ros::NodeHandle &private_node_handle)
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())
ros::Publisher gps_pub_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void gpsCallback(const sensor_msgs::NavSatFixConstPtr &msg)
ROSCPP_DECL void spin(Spinner &spinner)
~RemoveLatency()=default
ros::NodeHandle pnh_
ros::Subscriber heading_sub_
int main(int argc, char **argv)
ros::Publisher ekf_pub_
ros::NodeHandle nh_
ros::Subscriber gps_sub_
ros::Subscriber ekf_sub_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool getParam(const std::string &key, std::string &s) const
void headingCallback(const sensor_msgs::ImuConstPtr &heading_msg)


earth_rover_localization
Author(s):
autogenerated on Wed Apr 28 2021 02:15:34