## Velodyne VPL-16 rotation issue

Report crashes, strange behaviour, or apparent bugs
Filipe Rocha
Posts: 10
Joined: 28 May 2017, 20:51

### Velodyne VPL-16 rotation issue

Hello everyone.

I am having a small issue with the velodyne VPL-16 sensor that comes with V-REP.

I want to export its pointcloud to ROS. So, in my first steps, I add the velodyne to the scene, uncomment this code part:

Code: Select all

 -- if we want to display the detected points ourselves:
if ptCloud then
sim.removePointsFromPointCloud(ptCloud,0,nil,0)
else
ptCloud=sim.createPointCloud(0.02,20,0,pointSize)
end
m=sim.getObjectMatrix(visionSensorHandles[1],-1)
for i=0,#data/3-1,1 do
d={data[3*i+1],data[3*i+2],data[3*i+3]}
d=sim.multiplyVector(m,d)
data[3*i+1]=d[1]
data[3*i+2]=d[2]
data[3*i+3]=d[3]
end
sim.insertPointsIntoPointCloud(ptCloud,0,data)
and run the program. Everything runs ok.

However, I have to rotate the sensor 90 degrees with respect to its Y axis, due to my model geometry.
When I just rotate the sensor and run again the program, LUA code gives me this error:

Code: Select all

[C]: in function 'insertPointsIntoPointCloud'
[string "SCRIPT velodyneVPL_16"]:32: in main chunk
Simulation stopping...
Lua runtime error: [string "SCRIPT velodyneVPL_16"]:32: One of the function's table size is not correct. (sim.insertPointsIntoPointCloud)
stack traceback:
I simply don't understand why the code stops working only because I have rotated the sensor.

Hope someone could help me.
Thank you a lot in advance.

coppelia
Posts: 7445
Joined: 14 Dec 2012, 00:25

### Re: Velodyne VPL-16 rotation issue

Hello Filipe,

this actually happens because sometimes the data array is simply empty (no points are detected for a given sensor rotation). And you can't provide an array with size 0 to simInsertPointsIntoPointCloud.

The provided lua code should be modified in following way. Instead of:

Code: Select all

    sim.insertPointsIntoPointCloud(ptCloud,0,data)

do

Code: Select all

    if #data>0 then
sim.insertPointsIntoPointCloud(ptCloud,0,data)
end

Cheers