0
$\begingroup$

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:

Lidar:

<gazebo reference="${name}">
      <sensor name="${name}" type="gpu_lidar">
        <update_rate>${update_rate}</update_rate>
        <visualize>true</visualize>
        <always_on>true</always_on>
        <ignition_frame_id>${name}</ignition_frame_id>
        <lidar>
          <scan>
            <horizontal>
              <samples>${horizontal_samples}</samples>
              <resolution>1</resolution>
              <min_angle>-${pi}</min_angle>
              <max_angle>${pi}</max_angle>
            </horizontal>
            <vertical>
              <samples>${vertical_samples}</samples>
              <resolution>1</resolution>
              <min_angle>-${45.0*pi/180.0}</min_angle>
              <max_angle>${45.0*pi/180.0}</max_angle>
            </vertical>
          </scan>
          <range>
            <min>${min_range}</min>
            <max>${max_range}</max>
            <resolution>0.01</resolution>
          </range>
        </lidar>
      </sensor>
    </gazebo>

PCL:

#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
{
public:
  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));
  }

private:
  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);
  rclcpp::spin(std::make_shared<PointCloudPrinter>());
  rclcpp::shutdown();
  return 0;
}

Please let me know if any additional information is needed

$\endgroup$

0

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.