I was trying to work on lidar point cloud using PCL by simulating a lidar in gazebo fortress and ROS 2. I am able to process the data but I always get the intensity as zero. Is there a way I could get the intensity of the ray or has this feature not been implemented. I am mentioning below my lidar and pcl code below:


<gazebo reference="${name}">
      <sensor name="${name}" type="gpu_lidar">


#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <iomanip>

using std::placeholders::_1;
class PointCloudPrinter : public rclcpp::Node
  PointCloudPrinter() : Node("pointcloud_printer_cpp")
    subscription_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
        "/j100_0000/sensors/lidar3d_0/points", 10, std::bind(&PointCloudPrinter::print_pointcloud, this, _1));

  void print_pointcloud(const sensor_msgs::msg::PointCloud2::SharedPtr msg)
    // Convert to PCL PointCloud with intensity
    pcl::PointCloud<pcl::PointXYZI>::Ptr pcl_cloud(new pcl::PointCloud<pcl::PointXYZI>);
    pcl::fromROSMsg(*msg, *pcl_cloud);

    // Print the point cloud data
    for (const auto &point : pcl_cloud->points)
      RCLCPP_INFO(this->get_logger(), "(%.3f, %.3f, %.3f, %.3f)", point.x, point.y, point.z, point.intensity);
    RCLCPP_INFO(this->get_logger(), "-----\n"); // Separator

  rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr subscription_;

int main(int argc, char *argv[])
  rclcpp::init(argc, argv);
  return 0;

Please let me know if any additional information is needed



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.