odom_estimation_node.cpp
Go to the documentation of this file.
1 
2 
4 
5 // Original Author of FLOAM: Wang Han
6 // Email wh200720041@gmail.com
7 // Homepage https://wanghan.pro
8 
9 #include <ros/ros.h>
10 #include <sensor_msgs/PointCloud2.h>
12 #include <nav_msgs/Odometry.h>
15 
16 //pcl lib
18 #include <pcl/point_cloud.h>
19 #include <pcl/point_types.h>
20 
21 //local lib
24 
25 namespace floam
26 {
27 namespace odom
28 {
29 
31 {
32  // constructor
33 }
34 
36 {
37  // destructor
38 }
39 
41 {
43 
44  m_nodeHandle.getParam("use_exact_sync", m_useExactSync);
45  m_nodeHandle.getParam("queue_size", m_queueSize);
46  m_nodeHandle.getParam("map_resolution", m_mapResolution);
47  m_nodeHandle.getParam("frame_id", m_frameId);
48  m_nodeHandle.getParam("parent_frame_id", m_parentFrameId);
49 
51 
52 
53  ROS_INFO_STREAM(m_nodeHandle.getNamespace() << "/frame_id: " << m_frameId);
54  ROS_INFO_STREAM(m_nodeHandle.getNamespace() << "/parent_frame_id: " << m_parentFrameId);
55  ROS_INFO_STREAM(m_nodeHandle.getNamespace() << "/use_exact_sync: " << m_useExactSync);
56  ROS_INFO_STREAM(m_nodeHandle.getNamespace() << "/queue_size: " << m_queueSize);
57  ROS_INFO_STREAM(m_nodeHandle.getNamespace() << "/map_resolution: " << m_mapResolution);
58 
59  m_tfGlobal.reset(new geometry_msgs::TransformStamped());
60 
61  m_tfGlobal->child_frame_id = m_frameId;
62 
63  // should these topic names be parameters instead of remapped?
64  m_subEdges.subscribe(m_nodeHandle, "points_edge", 100);
65  m_subSurfaces.subscribe(m_nodeHandle, "points_surface", 100);
66 
67  m_pubLidarOdometry = m_nodeHandle.advertise<nav_msgs::Odometry>("odom", 100);
68 
69  // initialize callbacks using sync policy
70  if (m_useExactSync) {
71  ROS_INFO("Exact Synchronization Policy chosen");
73  m_exactSync->registerCallback(
74  std::bind(&OdomEstimationNode::handleClouds, this, std::placeholders::_1, std::placeholders::_2));
75  } else {
76  ROS_INFO("Approximate Synchronization Policy chosen");
78  m_approximateSync->registerCallback(
79  std::bind(&OdomEstimationNode::handleClouds, this, std::placeholders::_1, std::placeholders::_2));
80  }
81 }
82 
84  const sensor_msgs::PointCloud2ConstPtr & edges_msg,
85  const sensor_msgs::PointCloud2ConstPtr & surfaces_msg)
86 {
87  // convert to PCL msgs
88  pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud_surf_in(new pcl::PointCloud<pcl::PointXYZ>());
89  pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud_edge_in(new pcl::PointCloud<pcl::PointXYZ>());
90  pcl::fromROSMsg(*edges_msg, *pointcloud_edge_in);
91  pcl::fromROSMsg(*surfaces_msg, *pointcloud_surf_in);
92 
93  // get timestamp from edges pointcloud msg, should (always) be the same as
94  ros::Time pointcloud_time = edges_msg->header.stamp;
95 
96  // check if odometry is initialized
97  if (m_isInitialized == false) {
98  m_odomEstimation.initMapWithPoints(pointcloud_edge_in, pointcloud_surf_in);
99  m_isInitialized = true;
100  ROS_INFO("odometry initialized"); // should only be called once
101  } else {
102  std::chrono::time_point<std::chrono::system_clock> start, end;
103  start = std::chrono::system_clock::now();
104  m_odomEstimation.updatePointsToMap(pointcloud_edge_in, pointcloud_surf_in);
105  end = std::chrono::system_clock::now();
106  // calculate elapsted time
107  std::chrono::duration<float> elapsed_seconds = end - start;
108  m_totals.frames++;
109  float time_temp = elapsed_seconds.count() * 1000;
110  m_totals.time += time_temp;
111  ROS_INFO("average odom estimation time %f ms", m_totals.time / m_totals.frames);
112  }
113 
115  m_tfGlobal->transform.translation.x = m_odomEstimation.m_currentTranslation.x();
116  m_tfGlobal->transform.translation.y = m_odomEstimation.m_currentTranslation.y();
117  m_tfGlobal->transform.translation.z = m_odomEstimation.m_currentTranslation.z();
118 
119  m_tfGlobal->transform.rotation.x = m_odomEstimation.m_currentRotation.x();
120  m_tfGlobal->transform.rotation.y = m_odomEstimation.m_currentRotation.y();
121  m_tfGlobal->transform.rotation.z = m_odomEstimation.m_currentRotation.z();
122  m_tfGlobal->transform.rotation.w = m_odomEstimation.m_currentRotation.w();
123 
126  m_tfGlobal->header.stamp = edges_msg->header.stamp;
127  m_tfGlobal->header.frame_id = m_parentFrameId;
129 
130  // publish odometry
131  nav_msgs::Odometry lidarOdometry;
132  lidarOdometry.header.frame_id = m_parentFrameId;
133  lidarOdometry.child_frame_id = m_frameId;
134  lidarOdometry.header.stamp = pointcloud_time;
135  lidarOdometry.pose.pose.orientation.x = m_tfGlobal->transform.rotation.x;
136  lidarOdometry.pose.pose.orientation.y = m_tfGlobal->transform.rotation.y;
137  lidarOdometry.pose.pose.orientation.z = m_tfGlobal->transform.rotation.z;
138  lidarOdometry.pose.pose.orientation.w = m_tfGlobal->transform.rotation.w;
139  lidarOdometry.pose.pose.position.x = m_tfGlobal->transform.translation.x;
140  lidarOdometry.pose.pose.position.y = m_tfGlobal->transform.translation.y;
141  lidarOdometry.pose.pose.position.z = m_tfGlobal->transform.translation.z;
142  m_pubLidarOdometry.publish(lidarOdometry);
143 }
144 
145 } // namespace odom
146 } // namespace floam
147 
148 #include <pluginlib/class_list_macros.h> // NO LINT
floam::odom::OdomEstimationNode::m_queueSize
int m_queueSize
Definition: odom_estimation_node.hpp:77
floam::odom::OdomEstimationNode::m_nodeHandle
ros::NodeHandle m_nodeHandle
Definition: odom_estimation_node.hpp:54
floam::odom::OdomEstimation::updatePointsToMap
void updatePointsToMap(const pcl::PointCloud< pcl::PointXYZ >::Ptr &edges, const pcl::PointCloud< pcl::PointXYZ >::Ptr &surfaces)
Definition: odom_estimation.cpp:51
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
ros.h
floam::odom::OdomEstimationNode::m_approximateSync
std::shared_ptr< ApproximateSynchronizer > m_approximateSync
Definition: odom_estimation_node.hpp:67
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(floam::lidar::LidarMappingNode, nodelet::Nodelet)
floam::odom::OdomEstimationNode::m_tfGlobal
geometry_msgs::TransformStampedPtr m_tfGlobal
ROS Transorm.
Definition: odom_estimation_node.hpp:59
floam::odom::OdomEstimationNode::handleClouds
void handleClouds(const sensor_msgs::PointCloud2ConstPtr &edges, const sensor_msgs::PointCloud2ConstPtr &surfaces)
Definition: odom_estimation_node.cpp:83
floam::odom::OdomEstimationNode::m_totals
floam::lidar::Total m_totals
Definition: odom_estimation_node.hpp:83
pcl::fromROSMsg
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
nodelet::Nodelet::getPrivateNodeHandle
ros::NodeHandle & getPrivateNodeHandle() const
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
floam::odom::OdomEstimationNode::m_frameId
std::string m_frameId
Definition: odom_estimation_node.hpp:81
transform_broadcaster.h
floam::odom::OdomEstimationNode::m_exactSync
std::shared_ptr< ExactSynchronizer > m_exactSync
Definition: odom_estimation_node.hpp:68
class_list_macros.h
floam::odom::OdomEstimationNode::~OdomEstimationNode
~OdomEstimationNode()
Definition: odom_estimation_node.cpp:35
tf2_ros::TransformBroadcaster::sendTransform
void sendTransform(const geometry_msgs::TransformStamped &transform)
floam::lidar::Total::time
double time
Definition: lidar_utils.hpp:76
floam::odom::OdomEstimationNode::m_subEdges
message_filters::Subscriber< sensor_msgs::PointCloud2 > m_subEdges
Definition: odom_estimation_node.hpp:64
subscriber.h
floam::odom::OdomEstimation::m_currentRotation
Eigen::Map< Eigen::Quaterniond > m_currentRotation
Definition: odom_estimation.hpp:66
floam::odom::OdomEstimationNode::ExactSynchronizer
message_filters::Synchronizer< ExactSyncPolicy > ExactSynchronizer
Definition: odom_estimation_node.hpp:62
floam::odom::OdomEstimationNode::m_subSurfaces
message_filters::Subscriber< sensor_msgs::PointCloud2 > m_subSurfaces
Definition: odom_estimation_node.hpp:65
floam::odom::OdomEstimationNode
Definition: odom_estimation_node.hpp:33
floam::odom::OdomEstimationNode::m_useExactSync
bool m_useExactSync
Definition: odom_estimation_node.hpp:75
floam::odom::OdomEstimationNode::onInit
void onInit()
Definition: odom_estimation_node.cpp:40
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
floam::odom::OdomEstimationNode::ApproximateSynchronizer
message_filters::Synchronizer< ApproximateSyncPolicy > ApproximateSynchronizer
Definition: odom_estimation_node.hpp:61
message_filters::Subscriber::subscribe
void subscribe()
start
ROSCPP_DECL void start()
floam::odom::OdomEstimationNode::m_isInitialized
bool m_isInitialized
Definition: odom_estimation_node.hpp:74
floam::odom::OdomEstimationNode::m_odomEstimation
floam::odom::OdomEstimation m_odomEstimation
Definition: odom_estimation_node.hpp:86
nodelet::Nodelet
ros::Time
floam::odom::OdomEstimationNode::m_pubLidarOdometry
ros::Publisher m_pubLidarOdometry
Definition: odom_estimation_node.hpp:56
floam::odom::ApproximateSyncPolicy
message_filters::sync_policies::ApproximateTime< sensor_msgs::PointCloud2, sensor_msgs::PointCloud2 > ApproximateSyncPolicy
Definition: odom_estimation_node.hpp:31
floam::odom::OdomEstimationNode::m_mapResolution
double m_mapResolution
Definition: odom_estimation_node.hpp:79
tf2_ros::TransformBroadcaster
floam::lidar::Total::frames
int frames
Definition: lidar_utils.hpp:77
floam::odom::OdomEstimationNode::OdomEstimationNode
OdomEstimationNode()
Definition: odom_estimation_node.cpp:30
floam::odom::OdomEstimationNode::m_parentFrameId
std::string m_parentFrameId
Definition: odom_estimation_node.hpp:81
tf2_geometry_msgs.h
odom_estimation.hpp
ros::NodeHandle::getNamespace
const std::string & getNamespace() const
floam::odom::ExactSyncPolicy
message_filters::sync_policies::ExactTime< sensor_msgs::PointCloud2, sensor_msgs::PointCloud2 > ExactSyncPolicy
Definition: odom_estimation_node.hpp:30
ROS_INFO
#define ROS_INFO(...)
floam::odom::OdomEstimation::init
void init(const double &mapResolution)
Definition: odom_estimation.cpp:23
floam
Major rewrite Author: Evan Flynn.
Definition: lidar.hpp:15
odom_estimation_node.hpp
floam::odom::OdomEstimation::initMapWithPoints
void initMapWithPoints(const pcl::PointCloud< pcl::PointXYZ >::Ptr &edges, const pcl::PointCloud< pcl::PointXYZ >::Ptr &surfaces)
Definition: odom_estimation.cpp:40
floam::odom::OdomEstimation::m_currentTranslation
Eigen::Map< Eigen::Vector3d > m_currentTranslation
Definition: odom_estimation.hpp:67
pcl_conversions.h


floam
Author(s): Han Wang
autogenerated on Wed Mar 2 2022 00:23:09