ros发布彩色点云

#include 
#include 
#include 
#include 

int main(int argc, char** argv) {
  ros::init(argc, argv, "color");
  ros::NodeHandle n;
  ros::Publisher pub = n.advertise<sensor_msgs::PointCloud2>("color_cloud", 10);
//   pcl::PointCloud::Ptr colored_cloud_toshow(
//       new pcl::PointCloud);
//   for (int i = 0; i < 30; i++) {
//     pcl::PointXYZRGB point;
//     point.x = i;
//     point.y = i;
//     point.z = i;
//     point.r = 255;
//     point.g = 0;
//     point.b = 0;
//     colored_cloud_toshow->points.push_back(point);
//   }
//   for (int i = 30; i < 60; i++) {
//     pcl::PointXYZRGB point;
//     point.x = i;
//     point.y = i;
//     point.z = i;
//     point.r = 0;
//     point.g = 255;
//     point.b = 0;
//     colored_cloud_toshow->points.push_back(point);
//   }
//   for (int i = 60; i < 90; i++) {
//     pcl::PointXYZRGB point;
//     point.x = i;
//     point.y = i;
//     point.z = i;
//     point.r = 0;
//     point.g = 0;
//     point.b = 255;
//     colored_cloud_toshow->points.push_back(point);
//   }
  pcl::PointCloud<pcl::PointXYZRGB> lwd;
  lwd.points.resize(30);
  for (int i = 0; i < 30; i++) {
      lwd.points[i].x = i;
      lwd.points[i].y = i;
      lwd.points[i].z = i;
      lwd.points[i].r = 255;
  }
  sensor_msgs::PointCloud2 output_msg;
  pcl::toROSMsg(lwd, output_msg);
  output_msg.header.frame_id = "mmwave";
  while (ros::ok()) {
    output_msg.header.stamp = ros::Time::now();
    pub.publish(output_msg);
  }
  ros::spin();

  return 0;
}

你可能感兴趣的:(ROS,第三方库)