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_util
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!");
104  }
105  }
106 
107 private:
112  std::string fixedFrameId_;
114  bool slerp_;
116 };
117 
119 }
120 
121 
NODELET_FATAL
#define NODELET_FATAL(...)
rtabmap_conversions::deskew
bool deskew(const sensor_msgs::PointCloud2 &input, sensor_msgs::PointCloud2 &output, const std::string &fixedFrameId, tf::TransformListener &listener, double waitForTransform, bool slerp=false)
ros::Publisher
DurationBase< Duration >::fromSec
Duration & fromSec(double t)
nodelet::Nodelet::getNodeHandle
ros::NodeHandle & getNodeHandle() const
rtabmap_util::LidarDeskewing::pubScan_
ros::Publisher pubScan_
Definition: lidar_deskewing.cpp:108
laser_geometry::LaserProjection
rtabmap_util::LidarDeskewing::pubCloud_
ros::Publisher pubCloud_
Definition: lidar_deskewing.cpp:109
ros.h
projection
Expression< Point2 > projection(f, p_cam)
rtabmap_util
Definition: MapsManager.h:49
rtabmap::Transform::isNull
bool isNull() const
nodelet::Nodelet::getPrivateNodeHandle
ros::NodeHandle & getPrivateNodeHandle() const
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
rtabmap_util::LidarDeskewing::callbackCloud
void callbackCloud(const sensor_msgs::PointCloud2ConstPtr &msg)
Definition: lidar_deskewing.cpp:91
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
transforms.h
rtabmap_util::LidarDeskewing::subScan_
ros::Subscriber subScan_
Definition: lidar_deskewing.cpp:110
ros::NodeHandle::resolveName
std::string resolveName(const std::string &name, bool remap=true) const
laser_geometry.h
rtabmap_util::LidarDeskewing::fixedFrameId_
std::string fixedFrameId_
Definition: lidar_deskewing.cpp:112
ROS_WARN
#define ROS_WARN(...)
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
rtabmap_util::LidarDeskewing
Definition: lidar_deskewing.cpp:22
rtabmap_util::LidarDeskewing::callbackScan
void callbackScan(const sensor_msgs::LaserScanConstPtr &msg)
Definition: lidar_deskewing.cpp:62
NODELET_INFO
#define NODELET_INFO(...)
transform_listener.h
rtabmap::Transform
pcl_ros::transformPointCloud
void transformPointCloud(const Eigen::Matrix4f &transform, const sensor_msgs::PointCloud2 &in, sensor_msgs::PointCloud2 &out)
rtabmap_conversions::getMovingTransform
rtabmap::Transform getMovingTransform(const std::string &movingFrame, const std::string &fixedFrame, const ros::Time &stampFrom, const ros::Time &stampTo, tf::TransformListener &listener, double waitForTransform)
rtabmap_util::PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(rtabmap_util::DisparityToDepth, nodelet::Nodelet)
nodelet::Nodelet
nodelet.h
republish_tf_static.msg
msg
Definition: republish_tf_static.py:5
ROS_ERROR
#define ROS_ERROR(...)
class_list_macros.hpp
rtabmap_util::LidarDeskewing::slerp_
bool slerp_
Definition: lidar_deskewing.cpp:114
tf::TransformListener
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
rtabmap_util::LidarDeskewing::subCloud_
ros::Subscriber subCloud_
Definition: lidar_deskewing.cpp:111
false
#define false
UTimer.h
MsgConversion.h
util3d_transforms.h
ros::Duration
rtabmap_util::LidarDeskewing::~LidarDeskewing
virtual ~LidarDeskewing()
Definition: lidar_deskewing.cpp:32
rtabmap_util::LidarDeskewing::LidarDeskewing
LidarDeskewing()
Definition: lidar_deskewing.cpp:25
ros::NodeHandle
ros::Subscriber
rtabmap_util::LidarDeskewing::onInit
virtual void onInit()
Definition: lidar_deskewing.cpp:37
rtabmap_util::LidarDeskewing::tfListener_
tf::TransformListener * tfListener_
Definition: lidar_deskewing.cpp:115
rtabmap_util::LidarDeskewing::waitForTransformDuration_
double waitForTransformDuration_
Definition: lidar_deskewing.cpp:113


rtabmap_util
Author(s): Mathieu Labbe
autogenerated on Mon Apr 28 2025 02:40:50