laser_odom.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <memory>
  2. #include <iostream>
  3. #include <ros/ros.h>
  4. #include <ros/time.h>
  5. #include <ros/duration.h>
  6. #include <pcl_ros/point_cloud.h>
  7. #include <tf_conversions/tf_eigen.h>
  8. #include <tf/transform_listener.h>
  9. #include <tf/transform_broadcaster.h>
  10. #include <std_msgs/Time.h>
  11. #include <nav_msgs/Odometry.h>
  12. #include <sensor_msgs/PointCloud2.h>
  13. #include <geometry_msgs/TransformStamped.h>
  14. #include <geometry_msgs/PoseWithCovarianceStamped.h>
  15. #include <nodelet/nodelet.h>
  16. #include <pluginlib/class_list_macros.h>
  17. #include <pcl/filters/voxel_grid.h>
  18. #include <pcl/filters/passthrough.h>
  19. #include <pcl/filters/approximate_voxel_grid.h>
  20. #include <hdl_graph_slam/ros_utils.hpp>
  21. #include <hdl_graph_slam/registrations.hpp>
  22. #include <hdl_graph_slam/ScanMatchingStatus.h>
  23. #include <laser_geometry/laser_geometry.h>
  24. #include <fast_gicp/gicp/fast_gicp.hpp>
  25. #include <new>
  26. #undef new
  27. // namespace laser_odom_ns {
  28. typedef pcl::PointXYZI PointT;
  29. class Laser_Odom {
  30. private:
  31. laser_geometry::LaserProjection projector;
  32. sensor_msgs::PointCloud2 cloud2; // 点云数据类型转换的中间变量
  33. pcl::PointCloud<PointT>::Ptr cloud; // 点云数据
  34. pcl::PointCloud<PointT>::ConstPtr keyframe; // 关键帧
  35. ros::Time prev_time;
  36. Eigen::Matrix4f prev_trans; // 地图起点到当前 帧 的放射变换
  37. Eigen::Matrix4f keyframe_pose; // 地图起点到当前 关键帧 的仿射变换
  38. ros::Time keyframe_stamp; // 关键帧的时间戳
  39. // pcl::Registration<PointT, PointT>::Ptr registration;
  40. fast_gicp::FastGICP<PointT, PointT>::Ptr registration;
  41. pcl::Filter<PointT>::Ptr downsample_filter;
  42. double keyframe_delta_trans = 0.25;
  43. double keyframe_delta_angle = 0.15;
  44. double keyframe_delta_time = 1.0;
  45. // std::string odom_frame_id = "odom";
  46. tf::TransformBroadcaster keyframe_broadcaster;
  47. tf::TransformBroadcaster odom_broadcaster;
  48. ros::NodeHandle nh;
  49. ros::Publisher odom_pub; // 里程计发布
  50. ros::Publisher path_pub;
  51. // ros::Publisher read_until_pub; //
  52. ros::Publisher aligned_points_pub;
  53. ros::Publisher map_points_pub;
  54. static Laser_Odom* laser_odom;
  55. Eigen::Matrix4f odom;
  56. double downsample_resolution = 0.1; // 下采样分辨率
  57. ros::NodeHandle private_nh;
  58. public:
  59. Laser_Odom();
  60. ~Laser_Odom();
  61. void init();
  62. static void cloud_callback(const sensor_msgs::LaserScan::ConstPtr& laser_scan_msg);
  63. Eigen::Matrix4f matching(const ros::Time& stamp, const pcl::PointCloud<PointT>::ConstPtr& cloud);
  64. pcl::PointCloud<PointT>::ConstPtr downsample(const pcl::PointCloud<PointT>::ConstPtr& cloud);
  65. geometry_msgs::TransformStamped matrix2transform(const ros::Time& stamp, const Eigen::Matrix4f& pose, const std::string& frame_id, const std::string& child_frame_id);
  66. void publish_odometry(const ros::Time& stamp, const std::string& base_frame_id, const Eigen::Matrix4f& pose);
  67. void publish_keyfrrame(const ros::Time& stamp, const std::string& base_frame_id, const Eigen::Matrix4f& pose); // 发布里程计数据
  68. };
  69. // }; // namespace laser_odom_ns