原因:ubuntu20.04的rostopic格式更加严格,之前版本/rostopic和rostopic发出消息均是/rostopic。ubuntu20.04/rostopic发出消息是//rostopic。
解决:在mapOptmization.cpp文件中将以下代码中的/camera_init更改为camera_init,去除 / 符号
void publishKeyPosesAndFrames(){
if (pubKeyPoses.getNumSubscribers() != 0){
sensor_msgs::PointCloud2 cloudMsgTemp;
pcl::toROSMsg(*cloudKeyPoses3D, cloudMsgTemp);
cloudMsgTemp.header.stamp = ros::Time().fromSec(timeLaserOdometry);
cloudMsgTemp.header.frame_id = "/camera_init";
pubKeyPoses.publish(cloudMsgTemp);
}
if (pubRecentKeyFrames.getNumSubscribers() != 0){
sensor_msgs::PointCloud2 cloudMsgTemp;
pcl::toROSMsg(*laserCloudSurfFromMapDS, cloudMsgTemp);
cloudMsgTemp.header.stamp = ros::Time().fromSec(timeLaserOdometry);
cloudMsgTemp.header.frame_id = "/camera_init";
pubRecentKeyFrames.publish(cloudMsgTemp);
}
if (pubRegisteredCloud.getNumSubscribers() != 0){
pcl::PointCloud<PointType>::Ptr cloudOut(new pcl::PointCloud<PointType>());
PointTypePose thisPose6D = trans2PointTypePose(transformTobeMapped);
*cloudOut += *transformPointCloud(laserCloudCornerLastDS, &thisPose6D);
*cloudOut += *transformPointCloud(laserCloudSurfTotalLast, &thisPose6D);
sensor_msgs::PointCloud2 cloudMsgTemp;
pcl::toROSMsg(*cloudOut, cloudMsgTemp);
cloudMsgTemp.header.stamp = ros::Time().fromSec(timeLaserOdometry);
cloudMsgTemp.header.frame_id = "/camera_init";
pubRegisteredCloud.publish(cloudMsgTemp);
}
}
引用:https://blog.csdn.net/HUASHUDEYANJING/article/details/121107774