ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to render raw Lidar scan data to PointCloud2?

asked 2022-09-06 15:58:00 -0600

mrezzaaa gravatar image

updated 2023-06-18 10:04:44 -0600

lucasw gravatar image

I am very new to ROS. I am running ROS in MacOS with the ROS (version 1.5) inside the conda environment. I have tried reading raw data from lidar with hex code output via the serial port using Python (version 3.9). Later, I tried publishing parsed data from lidar to PointCloud2.data with this format:

[convertedhex1,convertedhex2,convertedhex3....convertedhexN]

*generated with looping and reading each 2 hex to integer data with PointCloud2.fields:

name:"x",offset:0,count:1,datatype:7
name:"y",offset:1,count:1,datatype:7
name:"z",offset:2,count:1,datatype:7

Assuming every offset in iteration reading XYZ points.

The PointCloud2 data is not rendering in RViz with the same topic and frame id, but the "messages received" field is incrementing. Rendering the scan to LaserScan is successful, but drawing using circles is looking like this.

I am using solid-state Lidar CygLidar D1 with 120° horizontal FOV and 65° vertical FOV (not rotating Lidar). I think LaserScan is showing wrong, or I parsed error data? Based on the user Manual with a 3D response sample, the data show like on the screenshot with LaserScan.

Is PointCloud2.data support a 3-dimensional array? Or can someone maybe help me? I am literally stuck here.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2022-09-07 05:47:18 -0600

ravijoshi gravatar image
  1. There is no need to reinvent the wheel. Please read page # 18 of the user manual. I am attaching it below for reference:

    page # 18 of the user manual

    The package CygLiDAR-ROS/cyglidar_d1 is designed to visualize the 2D/3D distance dataset in real time. This is exactly what you are trying to achieve. Feel free to look at the source code for more details.

  2. Undoubtedly, PointCloud2 supports 3D. I think this is what a point cloud is designed for!


PS: Given the explanation in the question, I strongly recommend going through ROS/Tutorials. These tutorials are easy to understand and are worth spending time, please!

edit flag offensive delete link more

Comments

Hi, thanks for the response first.

  1. I need to re-write in python because i need to fusion with another sensor
  2. Already tested but failed in compile (this one of the reason i want to rewrite in python)
  3. I mean 3 dimensional array not 3D, like [ [x,x,x,x,x],[y,y,y,y,y],[z,z,z,z,z] ] so i can put the point data cleanly ( if supported, that's great!)
mrezzaaa gravatar image mrezzaaa  ( 2022-09-07 06:04:35 -0600 )edit
  1. You can always look up to the package and understand how they have done it. Later you can mimic it in Python. BTW, a fusion of point clouds in Python could take time.
  2. You can share those errors in a new question. But please do not post them in this question.
  3. A point cloud is defined as a set of data points in space. In 3 dimensional space, it is a set of XYZ points. If you are interested in the PointCloud2 message definition, please check sensor_msgs/PointCloud2.
ravijoshi gravatar image ravijoshi  ( 2022-09-07 06:37:33 -0600 )edit
  1. Yeah, thanks for advice
  2. No, i wont post in this question. Better i find the raw data and proccess the data and make it on my own :D
  3. Already trying , but in rviz did not showing anything. Can you make an example the data format inside uint8 data[] ? It will very helping me. Like [ x,y,z,x,y,z....] or [x,x,x,y,y,y,z,z,z], which one correct formatting for Pointcloud2.data? I have read the docs and still confused. Many tutorial i read just throwing scan data as params to topic publisher, not how the data look like(in format). Just a numbers in array.
mrezzaaa gravatar image mrezzaaa  ( 2022-09-07 08:06:56 -0600 )edit
1

You seem to skip essential readings in this stage which is not recommended. The best I can do is provide references. Quoting from the documentation:

The newly revised ROS point cloud message (currently the de facto standard in PCL) now represents arbitrary n-D (n-dimensional) data. Point values can now be of any primitive data types (int, float, double, etc.), and the message can be specified as 'dense', with height and width values, giving the data a 2D structure, e.g., to correspond to an image of the same region in space. For more information on the rationale behind the new structure, see: PCL_March_2010.pdf and pcl_icra2010.pdf

ravijoshi gravatar image ravijoshi  ( 2022-09-07 21:06:55 -0600 )edit

Big thanks! This is help me out to understanding how properly generating PointCloud2 data.

mrezzaaa gravatar image mrezzaaa  ( 2022-09-08 02:07:05 -0600 )edit

Glad you made it!

ravijoshi gravatar image ravijoshi  ( 2022-09-08 02:13:30 -0600 )edit

More question about PointCloud2.data: Field data is uint8[] , so maximum value is 255. What if i scaled measured distance by percentage its resulting float data, but the field only accept integer, how to putting data value to showed correctly in rviz ? Little bit confused about pointCloud2.fields with datatype with many numbers datatype but the pointcloud2.data is only accept uint8.

mrezzaaa gravatar image mrezzaaa  ( 2022-09-08 02:48:52 -0600 )edit

You can push float data to point cloud. I am sharing following snippet;

// reserve the memory at the beginning
cloud.data.resize(total_size);
// do something here such as shown below
// define a 3D vector of float
Eigen::Vector3f xyz;
// initializing with dummy values
xyz << 1.2f, 3.4f, 5.6f; 
// copy x to our point cloud
std::memcpy(&cloud.data[curr[0]], &xyz[0], sizeof(float));
// copy y to our point cloud
std::memcpy(&cloud.data[curr[1]], &xyz[1], sizeof(float));
// copy z to our point cloud
std::memcpy(&cloud.data[curr[2]], &xyz[2], sizeof(float));
ravijoshi gravatar image ravijoshi  ( 2022-09-08 03:09:52 -0600 )edit
0

answered 2022-09-07 18:44:08 -0600

Mike Scheutzow gravatar image

If you are asking how to create a PointCloud2 message in python, see the answer to #q405667.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-09-06 15:56:21 -0600

Seen: 348 times

Last updated: Sep 07 '22