lidar_deskewing.cpp
Go to the documentation of this file.
1 
2 #include <ros/ros.h>
4 #include <nodelet/nodelet.h>
5 
7 
8 #include <sensor_msgs/PointCloud2.h>
9 #include <sensor_msgs/LaserScan.h>
10 
12 
13 #include <pcl_ros/transforms.h>
14 
16 #include <rtabmap/utilite/UTimer.h>
18 
19 namespace rtabmap_ros
20 {
21 
23 {
24 public:
27  slerp_(false),
28  tfListener_(0)
29  {
30  }
31 
32  virtual ~LidarDeskewing()
33  {
34  }
35 
36 private:
37  virtual void onInit()
38  {
42 
43  pnh.param("fixed_frame_id", fixedFrameId_, fixedFrameId_);
44  pnh.param("wait_for_transform", waitForTransformDuration_, waitForTransformDuration_);
45  pnh.param("slerp", slerp_, slerp_);
46 
47  NODELET_INFO("fixed_frame_id: %s", fixedFrameId_.c_str());
48  NODELET_INFO("wait_for_transform: %fs", waitForTransformDuration_);
49  NODELET_INFO("slerp: %s", slerp_?"true":"false");
50 
51  if(fixedFrameId_.empty())
52  {
53  NODELET_FATAL("fixed_frame_id parameter cannot be empty!");
54  }
55 
56  pubScan_ = nh.advertise<sensor_msgs::PointCloud2>(nh.resolveName("input_scan") + "/deskewed", 1);
57  pubCloud_ = nh.advertise<sensor_msgs::PointCloud2>(nh.resolveName("input_cloud") + "/deskewed", 1);
58  subScan_ = nh.subscribe("input_scan", 1, &LidarDeskewing::callbackScan, this);
59  subCloud_ = nh.subscribe("input_cloud", 1, &LidarDeskewing::callbackCloud, this);
60  }
61 
62  void callbackScan(const sensor_msgs::LaserScanConstPtr & msg)
63  {
64  // make sure the frame of the laser is updated during the whole scan time
66  msg->header.frame_id,
68  msg->header.stamp,
69  msg->header.stamp + ros::Duration().fromSec(msg->ranges.size()*msg->time_increment),
70  *tfListener_,
72  if(tmpT.isNull())
73  {
74  return;
75  }
76 
77  sensor_msgs::PointCloud2 scanOut;
79  projection.transformLaserScanToPointCloud(fixedFrameId_, *msg, scanOut, *tfListener_);
80 
81  sensor_msgs::PointCloud2 scanOutDeskewed;
82  if(!pcl_ros::transformPointCloud(msg->header.frame_id, scanOut, scanOutDeskewed, *tfListener_))
83  {
84  ROS_ERROR("Cannot transform back projected scan from \"%s\" frame to \"%s\" frame at time %fs.",
85  fixedFrameId_.c_str(), msg->header.frame_id.c_str(), msg->header.stamp.toSec());
86  return;
87  }
88  pubScan_.publish(scanOutDeskewed);
89  }
90 
91  void callbackCloud(const sensor_msgs::PointCloud2ConstPtr & msg)
92  {
93  sensor_msgs::PointCloud2 msgDeskewed;
95  {
96  pubCloud_.publish(msgDeskewed);
97  }
98  else
99  {
100  // Just republish the msg to not breakdown downstream
101  // A warning should be already shown (see deskew() source code)
102  ROS_WARN("deskewing failed! returning possible skewed cloud!");
103  pubCloud_.publish(msg);
104  }
105  }
106 
107 private:
112  std::string fixedFrameId_;
114  bool slerp_;
116 };
117 
119 }
120 
121 
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::NodeHandle & getNodeHandle() const
ros::NodeHandle & getPrivateNodeHandle() const
bool deskew(const sensor_msgs::PointCloud2 &input, sensor_msgs::PointCloud2 &output, const std::string &fixedFrameId, tf::TransformListener &listener, double waitForTransform, bool slerp=false)
#define ROS_WARN(...)
rtabmap::Transform getTransform(const std::string &fromFrameId, const std::string &toFrameId, const ros::Time &stamp, tf::TransformListener &listener, double waitForTransform)
tf::TransformListener * tfListener_
bool param(const std::string &param_name, T &param_val, const T &default_val) const
void publish(const boost::shared_ptr< M > &message) const
Duration & fromSec(double t)
void callbackCloud(const sensor_msgs::PointCloud2ConstPtr &msg)
std::string resolveName(const std::string &name, bool remap=true) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool isNull() const
#define false
#define NODELET_INFO(...)
void transformPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const tf::Transform &transform)
PLUGINLIB_EXPORT_CLASS(rtabmap_ros::CoreWrapper, nodelet::Nodelet)
void transformLaserScanToPointCloud(const std::string &target_frame, const sensor_msgs::LaserScan &scan_in, sensor_msgs::PointCloud &cloud_out, tf::Transformer &tf, double range_cutoff, int channel_options=channel_option::Default)
#define NODELET_FATAL(...)
void callbackScan(const sensor_msgs::LaserScanConstPtr &msg)
#define ROS_ERROR(...)


rtabmap_ros
Author(s): Mathieu Labbe
autogenerated on Tue Jan 24 2023 04:04:40