#ifndef SLAM_SCAN_MATCH_H_ #define SLAM_SCAN_MATCH_H_ // C++ 标准库头文件 #include #include #include #include #include #include // C++ 第三方库头文件 #include // ROS 相关头文件 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // PCL 库头文件 #include #include #include // fast_gicp 相关头文件 #include // 项目内部头文件 #include "odom_laser/registrations.hpp" #include "odom_laser/ScanMatchingStatus.h" #include "odom_laser/ros_utils.hpp" #undef new typedef pcl::PointXYZI PointT; struct MatchPCL { ros::Time time; pcl::PointCloud cloud; }; namespace laser_odom_ns { class Laser_Odom { private: static Laser_Odom *laser_odom; ros::NodeHandle nh; ros::Publisher odom_pub; // 里程计发布 ros::Publisher path_pub; ros::Publisher transformed_cloud_pub; sensor_msgs::PointCloud2 cloud2; // 点云数据类型转换的中间变量 pcl::PointCloud::Ptr cloud; // 点云数据 pcl::PointCloud::Ptr trans_cloud; // 转换后的点云数据 pcl::PointCloud::ConstPtr keyframe; // 关键帧 pcl::Filter::Ptr downsample_filter; fast_gicp::FastGICP::Ptr registration; ros::Time prev_time; ros::Time keyframe_stamp; // 关键帧的时间戳 Eigen::Matrix4f prev_trans; // 地图起点到当前帧的仿射变换 Eigen::Matrix4f keyframe_pose; // 地图起点到当前关键帧的仿射变换 Eigen::Matrix4f odom; double downsample_resolution; double keyframe_delta_trans; double keyframe_delta_angle; double keyframe_delta_time; laser_geometry::LaserProjection projector; std::mutex mutex_; std::queue clouds_; void procThread(); void point_cloud_callback(const sensor_msgs::LaserScan::ConstPtr &laser_scan_msg); void publish_odometry(const ros::Time &stamp, const std::string &base_frame_id, const Eigen::Matrix4f &pose); void publish_keyfrrame(const ros::Time &stamp, const std::string &base_frame_id, const Eigen::Matrix4f &pose); // 发布里程计数据 pcl::PointCloud::ConstPtr downsample(const pcl::PointCloud::ConstPtr &cloud); Eigen::Matrix4f matching(const ros::Time &stamp, const pcl::PointCloud::ConstPtr &cloud); geometry_msgs::TransformStamped matrix2transform(const ros::Time &stamp, const Eigen::Matrix4f &pose, const std::string &frame_id, const std::string &child_frame_id); public: Laser_Odom(); ~Laser_Odom(); void init(); }; }; // namespace laser_odom_ns #endif // SLAM_SCAN_MATCH_H_