报错内容:
home/ckq/catkin_ws_iit/src/semantic_slam_nav_ros/dense_surfel_mapping/src/surfel_map.cpp:767:46: required from here
/opt/ros/noetic/include/ros/message_traits.h:125:14: error: ‘const class std::shared_ptr<pcl::PointCloud<pcl::PointXYZI> >’ has no member named ‘__getMD5Sum’
return m.__getMD5Sum().c_str();
surfel_map.cpp:767的代码如下 以及相关代码:
raw_pointcloud_publish.publish(pointcloud);
ros::Publisher raw_pointcloud_publish;
raw_pointcloud_publish = nh.advertise(“raw_pointcloud”, 10);
这个错误表明你在发布点云消息时遇到了问题。具体来说,编译器抱怨 std::shared_ptr
类型没有成员函数 __getMD5Sum
。这通常是因为消息类型不匹配或者缺少某些ROS消息特质(message traits)的定义。
根据你提供的代码片段,我注意到你试图使用 PointCloud
作为 ros::Publisher
的模板参数,但并没有指明这个 PointCloud
是什么类型。在 ROS 中,如果你想发布 PCL 点云,通常会使用 sensor_msgs::PointCloud2
类型。
这里有几个可能的解决方案:
确保你使用正确的消息类型:如果你的 pointcloud
是 pcl::PointCloud
类型,你需要先将它转换为 sensor_msgs::PointCloud2
类型,然后再发布。你可以使用 pcl::toROSMsg
函数来做这个转换。
检查头文件和命名空间:确保你包含了所有必要的头文件,并正确使用了命名空间。对于PCL和ROS消息,通常需要包括以下头文件:
#include
#include
#include
修改发布器的类型:更改你的 ros::Publisher
对象的类型,使其匹配你想要发布的消息类型。如果你正在发布转换后的 sensor_msgs::PointCloud2
消息,你的发布器应该是这样定义的:
ros::Publisher raw_pointcloud_publish;
raw_pointcloud_publish = nh.advertise<sensor_msgs::PointCloud2>("raw_pointcloud", 10);
发布转换后的点云:当你准备发布点云时,确保它已经被转换为 sensor_msgs::PointCloud2
类型。使用 pcl::toROSMsg
进行转换,并发布转换后的消息:
sensor_msgs::PointCloud2 output;
pcl::toROSMsg(*pointcloud, output);
raw_pointcloud_publish.publish(output);
试试这些解决方案,看看是否能解决你的问题。