Skip to content
Snippets Groups Projects
Commit 4f2ccdbc authored by Tixiao Shan's avatar Tixiao Shan
Browse files

adjust publishCloud()

parent 20fdc6d0
No related branches found
No related tags found
No related merge requests found
...@@ -279,14 +279,14 @@ public: ...@@ -279,14 +279,14 @@ public:
}; };
template<typename T> template<typename T>
sensor_msgs::PointCloud2 publishCloud(ros::Publisher *thisPub, const T& thisCloud, ros::Time thisStamp, std::string thisFrame) sensor_msgs::PointCloud2 publishCloud(const ros::Publisher& thisPub, const T& thisCloud, ros::Time thisStamp, std::string thisFrame)
{ {
sensor_msgs::PointCloud2 tempCloud; sensor_msgs::PointCloud2 tempCloud;
pcl::toROSMsg(*thisCloud, tempCloud); pcl::toROSMsg(*thisCloud, tempCloud);
tempCloud.header.stamp = thisStamp; tempCloud.header.stamp = thisStamp;
tempCloud.header.frame_id = thisFrame; tempCloud.header.frame_id = thisFrame;
if (thisPub->getNumSubscribers() != 0) if (thisPub.getNumSubscribers() != 0)
thisPub->publish(tempCloud); thisPub.publish(tempCloud);
return tempCloud; return tempCloud;
} }
......
...@@ -30,5 +30,6 @@ sensor_msgs/PointCloud2 cloud_surface # extracted surface feature ...@@ -30,5 +30,6 @@ sensor_msgs/PointCloud2 cloud_surface # extracted surface feature
# 3rd party messages # 3rd party messages
sensor_msgs/PointCloud2 key_frame_cloud sensor_msgs/PointCloud2 key_frame_cloud
sensor_msgs/PointCloud2 key_frame_color
sensor_msgs/PointCloud2 key_frame_poses sensor_msgs/PointCloud2 key_frame_poses
sensor_msgs/PointCloud2 key_frame_map sensor_msgs/PointCloud2 key_frame_map
...@@ -250,8 +250,8 @@ public: ...@@ -250,8 +250,8 @@ public:
// free cloud info memory // free cloud info memory
freeCloudInfoMemory(); freeCloudInfoMemory();
// save newly extracted features // save newly extracted features
cloudInfo.cloud_corner = publishCloud(&pubCornerPoints, cornerCloud, cloudHeader.stamp, lidarFrame); cloudInfo.cloud_corner = publishCloud(pubCornerPoints, cornerCloud, cloudHeader.stamp, lidarFrame);
cloudInfo.cloud_surface = publishCloud(&pubSurfacePoints, surfaceCloud, cloudHeader.stamp, lidarFrame); cloudInfo.cloud_surface = publishCloud(pubSurfacePoints, surfaceCloud, cloudHeader.stamp, lidarFrame);
// publish to mapOptimization // publish to mapOptimization
pubLaserCloudInfo.publish(cloudInfo); pubLaserCloudInfo.publish(cloudInfo);
} }
......
...@@ -588,7 +588,7 @@ public: ...@@ -588,7 +588,7 @@ public:
void publishClouds() void publishClouds()
{ {
cloudInfo.header = cloudHeader; cloudInfo.header = cloudHeader;
cloudInfo.cloud_deskewed = publishCloud(&pubExtractedCloud, extractedCloud, cloudHeader.stamp, lidarFrame); cloudInfo.cloud_deskewed = publishCloud(pubExtractedCloud, extractedCloud, cloudHeader.stamp, lidarFrame);
pubLaserCloudInfo.publish(cloudInfo); pubLaserCloudInfo.publish(cloudInfo);
} }
}; };
......
...@@ -74,7 +74,6 @@ public: ...@@ -74,7 +74,6 @@ public:
ros::Publisher pubLoopConstraintEdge; ros::Publisher pubLoopConstraintEdge;
ros::Publisher pubSLAMInfo; ros::Publisher pubSLAMInfo;
ros::Publisher pubSLAMDummy;
ros::Subscriber subCloud; ros::Subscriber subCloud;
ros::Subscriber subGPS; ros::Subscriber subGPS;
...@@ -183,7 +182,6 @@ public: ...@@ -183,7 +182,6 @@ public:
pubCloudRegisteredRaw = nh.advertise<sensor_msgs::PointCloud2>("lio_sam/mapping/cloud_registered_raw", 1); pubCloudRegisteredRaw = nh.advertise<sensor_msgs::PointCloud2>("lio_sam/mapping/cloud_registered_raw", 1);
pubSLAMInfo = nh.advertise<lio_sam::cloud_info>("lio_sam/mapping/slam_info", 1); pubSLAMInfo = nh.advertise<lio_sam::cloud_info>("lio_sam/mapping/slam_info", 1);
pubSLAMDummy = nh.advertise<sensor_msgs::PointCloud2>("lio_sam/mapping/slam_dummy", 1);
downSizeFilterCorner.setLeafSize(mappingCornerLeafSize, mappingCornerLeafSize, mappingCornerLeafSize); downSizeFilterCorner.setLeafSize(mappingCornerLeafSize, mappingCornerLeafSize, mappingCornerLeafSize);
downSizeFilterSurf.setLeafSize(mappingSurfLeafSize, mappingSurfLeafSize, mappingSurfLeafSize); downSizeFilterSurf.setLeafSize(mappingSurfLeafSize, mappingSurfLeafSize, mappingSurfLeafSize);
...@@ -488,7 +486,7 @@ public: ...@@ -488,7 +486,7 @@ public:
downSizeFilterGlobalMapKeyFrames.setLeafSize(globalMapVisualizationLeafSize, globalMapVisualizationLeafSize, globalMapVisualizationLeafSize); // for global map visualization downSizeFilterGlobalMapKeyFrames.setLeafSize(globalMapVisualizationLeafSize, globalMapVisualizationLeafSize, globalMapVisualizationLeafSize); // for global map visualization
downSizeFilterGlobalMapKeyFrames.setInputCloud(globalMapKeyFrames); downSizeFilterGlobalMapKeyFrames.setInputCloud(globalMapKeyFrames);
downSizeFilterGlobalMapKeyFrames.filter(*globalMapKeyFramesDS); downSizeFilterGlobalMapKeyFrames.filter(*globalMapKeyFramesDS);
publishCloud(&pubLaserCloudSurround, globalMapKeyFramesDS, timeLaserInfoStamp, odometryFrame); publishCloud(pubLaserCloudSurround, globalMapKeyFramesDS, timeLaserInfoStamp, odometryFrame);
} }
...@@ -554,7 +552,7 @@ public: ...@@ -554,7 +552,7 @@ public:
if (cureKeyframeCloud->size() < 300 || prevKeyframeCloud->size() < 1000) if (cureKeyframeCloud->size() < 300 || prevKeyframeCloud->size() < 1000)
return; return;
if (pubHistoryKeyFrames.getNumSubscribers() != 0) if (pubHistoryKeyFrames.getNumSubscribers() != 0)
publishCloud(&pubHistoryKeyFrames, prevKeyframeCloud, timeLaserInfoStamp, odometryFrame); publishCloud(pubHistoryKeyFrames, prevKeyframeCloud, timeLaserInfoStamp, odometryFrame);
} }
// ICP Settings // ICP Settings
...@@ -579,7 +577,7 @@ public: ...@@ -579,7 +577,7 @@ public:
{ {
pcl::PointCloud<PointType>::Ptr closed_cloud(new pcl::PointCloud<PointType>()); pcl::PointCloud<PointType>::Ptr closed_cloud(new pcl::PointCloud<PointType>());
pcl::transformPointCloud(*cureKeyframeCloud, *closed_cloud, icp.getFinalTransformation()); pcl::transformPointCloud(*cureKeyframeCloud, *closed_cloud, icp.getFinalTransformation());
publishCloud(&pubIcpKeyFrames, closed_cloud, timeLaserInfoStamp, odometryFrame); publishCloud(pubIcpKeyFrames, closed_cloud, timeLaserInfoStamp, odometryFrame);
} }
// Get pose transformation // Get pose transformation
...@@ -1702,9 +1700,9 @@ public: ...@@ -1702,9 +1700,9 @@ public:
if (cloudKeyPoses3D->points.empty()) if (cloudKeyPoses3D->points.empty())
return; return;
// publish key poses // publish key poses
publishCloud(&pubKeyPoses, cloudKeyPoses3D, timeLaserInfoStamp, odometryFrame); publishCloud(pubKeyPoses, cloudKeyPoses3D, timeLaserInfoStamp, odometryFrame);
// Publish surrounding key frames // Publish surrounding key frames
publishCloud(&pubRecentKeyFrames, laserCloudSurfFromMapDS, timeLaserInfoStamp, odometryFrame); publishCloud(pubRecentKeyFrames, laserCloudSurfFromMapDS, timeLaserInfoStamp, odometryFrame);
// publish registered key frame // publish registered key frame
if (pubRecentKeyFrame.getNumSubscribers() != 0) if (pubRecentKeyFrame.getNumSubscribers() != 0)
{ {
...@@ -1712,7 +1710,7 @@ public: ...@@ -1712,7 +1710,7 @@ public:
PointTypePose thisPose6D = trans2PointTypePose(transformTobeMapped); PointTypePose thisPose6D = trans2PointTypePose(transformTobeMapped);
*cloudOut += *transformPointCloud(laserCloudCornerLastDS, &thisPose6D); *cloudOut += *transformPointCloud(laserCloudCornerLastDS, &thisPose6D);
*cloudOut += *transformPointCloud(laserCloudSurfLastDS, &thisPose6D); *cloudOut += *transformPointCloud(laserCloudSurfLastDS, &thisPose6D);
publishCloud(&pubRecentKeyFrame, cloudOut, timeLaserInfoStamp, odometryFrame); publishCloud(pubRecentKeyFrame, cloudOut, timeLaserInfoStamp, odometryFrame);
} }
// publish registered high-res raw cloud // publish registered high-res raw cloud
if (pubCloudRegisteredRaw.getNumSubscribers() != 0) if (pubCloudRegisteredRaw.getNumSubscribers() != 0)
...@@ -1721,7 +1719,7 @@ public: ...@@ -1721,7 +1719,7 @@ public:
pcl::fromROSMsg(cloudInfo.cloud_deskewed, *cloudOut); pcl::fromROSMsg(cloudInfo.cloud_deskewed, *cloudOut);
PointTypePose thisPose6D = trans2PointTypePose(transformTobeMapped); PointTypePose thisPose6D = trans2PointTypePose(transformTobeMapped);
*cloudOut = *transformPointCloud(cloudOut, &thisPose6D); *cloudOut = *transformPointCloud(cloudOut, &thisPose6D);
publishCloud(&pubCloudRegisteredRaw, cloudOut, timeLaserInfoStamp, odometryFrame); publishCloud(pubCloudRegisteredRaw, cloudOut, timeLaserInfoStamp, odometryFrame);
} }
// publish path // publish path
if (pubPath.getNumSubscribers() != 0) if (pubPath.getNumSubscribers() != 0)
...@@ -1741,16 +1739,15 @@ public: ...@@ -1741,16 +1739,15 @@ public:
pcl::PointCloud<PointType>::Ptr cloudOut(new pcl::PointCloud<PointType>()); pcl::PointCloud<PointType>::Ptr cloudOut(new pcl::PointCloud<PointType>());
*cloudOut += *laserCloudCornerLastDS; *cloudOut += *laserCloudCornerLastDS;
*cloudOut += *laserCloudSurfLastDS; *cloudOut += *laserCloudSurfLastDS;
slamInfo.key_frame_cloud = publishCloud(&pubSLAMDummy, cloudOut, timeLaserInfoStamp, lidarFrame); slamInfo.key_frame_cloud = publishCloud(ros::Publisher(), cloudOut, timeLaserInfoStamp, lidarFrame);
slamInfo.key_frame_poses = publishCloud(&pubSLAMDummy, cloudKeyPoses6D, timeLaserInfoStamp, odometryFrame); slamInfo.key_frame_poses = publishCloud(ros::Publisher(), cloudKeyPoses6D, timeLaserInfoStamp, odometryFrame);
pcl::PointCloud<PointType>::Ptr localMapOut(new pcl::PointCloud<PointType>()); pcl::PointCloud<PointType>::Ptr localMapOut(new pcl::PointCloud<PointType>());
*localMapOut += *laserCloudCornerFromMapDS; *localMapOut += *laserCloudCornerFromMapDS;
*localMapOut += *laserCloudSurfFromMapDS; *localMapOut += *laserCloudSurfFromMapDS;
slamInfo.key_frame_map = publishCloud(&pubSLAMDummy, localMapOut, timeLaserInfoStamp, odometryFrame); slamInfo.key_frame_map = publishCloud(ros::Publisher(), localMapOut, timeLaserInfoStamp, odometryFrame);
pubSLAMInfo.publish(slamInfo); pubSLAMInfo.publish(slamInfo);
lastSLAMInfoPubSize = cloudKeyPoses6D->size(); lastSLAMInfoPubSize = cloudKeyPoses6D->size();
} }
} }
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment