# RP lidar data plotting

44 views (last 30 days)
Kavish Ram on 26 Sep 2020
Commented: Kavish Ram on 8 Oct 2020
I'm currently working on a project where I want to plot a 3d diagram (sort of like terrain mapping) with the data obtain by Rp lidar.
I am able to get x,y,z axis in .csv format but I am not sure how I can display these values accurately so that it represents a terrain map.
I have tried scatter2, mesh and pcshow but those graphs have not been accurate and just shows me noise.
Any help will be highly apperciated.
Thank you.
K.

Kavish Ram on 3 Oct 2020
Hi,
Yes certainly tried the pcshow to plot a pointcloud. Please see attached the program code and csv file. The stepper motors however are programmed using C therefore wont be able to show that. But it is just simple principles of rotation.
Also, I am fairly new at Matlab and still getting used to the program so apologise for the messy code and unclear explanation.
x = DistanceX .* sin(AngleX) .* cos (pi);
y = DistanceY .* sin(AngleY) .* sin(pi);
z = DistanceZ .* cos(AngleZ);
points = [x(1:548),Y(1:548),Z(1:548)];
figure;
pcshow(points);
hold on
.......
Amrtanshu Raj on 6 Oct 2020
Can you share the document or link you used to model these equation. As you are multiplying with sin(pi) which is 0 to get the y values. I do not think it is the correct way to do it.
Also can you tell what do the Distance X. Distance Y, Distance Z, Angle X, Angle Y, Angle Z mean in the csv file.
Ideally when a lidar is recording data it should record the range value at a instant and the corresponding Y and Z angles.
Kavish Ram on 6 Oct 2020
Hi,
The equation used was found in a question/answer blog site. After doing mulitple reserach, I wasn't able to work out the equation which displays what I am after. Please to let me know if you have further insite as to which equation will be most suitable in this case.
The Distance X is the distance measured by the lidar (mm) and the Angle X is the angle value which the distance was measured in (Same for angle y and z). I know it seems a little bit confusing, but that is what the lidar is outputting. The values are given to me by the lidar software, which i have just transfered to the csv. format. No equations were used during this process.
Currently the rp lidar rotates 360 degrees to obtain the data angle and distance in 2d. By using an external stepper motor, and rotating the lidar, I am trying to aquire the y values. By rotating both external stepper motors, I am also trying to aquire Z axis. So that i can get data values which makes a 3d plot or Point cloud.
I am still in the learning stages of my project, so still trying to work out equations and the best way to get 3d out of a 2d lidar.

Amrtanshu Raj on 6 Oct 2020
Hi,
The problem is not in the plotting/visualisation part. We advise implementing the equations first to get proper values and then look into the visualisation part. If the values are recorded correct, then pcshow will be enough to visualise the plot.
My advice to get the desired values will be first to understand how a Lidar works and then try to record the Lidar range and theta (given by the lidar sensor) along with the time step. Then rotate the Lidar using the stepper along Y-axis( you should not need the Z stepper as the entire 3D area will be swept) and also record the angles(phi) along with the timestamp. Then you can try to sync both the set of readings(range and theta from RPLidar and phi from the stepper) with the help of the timestamp.
Then you can use sph2cart(theta will be the azimuth and phi will be elevation) to get the xyz values for each Lidar reading, after that use the PointCloud to store them as a point cloud. The use the pcshow function to get the desired Visualisation.

#### 1 Comment

Kavish Ram on 8 Oct 2020
Hi,
Thank you so much for that advice, appreciate it. I have noticed a few mistakes in the equation and will be looking further into that and try and work out a new equation.
Question. If I take out the Z stepper, how will I be able to obtain the Z axis values than? Will this be obtained by an equation? As pcshow and scatter3 require all xyz to display.