## How to parse data from 2D laser scanner in MATLAB?

Typically: "How do I... ", "How can I... " questions
strider
Posts: 1
Joined: 21 Jan 2017, 16:03

### How to parse data from 2D laser scanner in MATLAB?

Hello,

We are trying to read 2D laser scanner data from MATLAB via remote api.

We checked out the following post and managed to get laser scanner data (a 1xnumber_of_points matrix) to MATLAB with the code given below; however, we could not make any sense out of it.

We guess that the data is in the form of x,y,z coordinates for each laser point but we are not sure about evaluating/parsing the data matrix.

Is it with respect to robot coordinate frame or sensor coordinate frame?

viewtopic.php?f=9&t=1535

Code: Select all

Matlab Code:
[returnCode,signal] = vrep.simxGetStringSignal(clientID,'measuredDataAtThisTime',vrep.simx_opmode_buffer);
if(vrep.simx_return_ok == returnCode)
data=vrep.simxUnpackFloats(signal);


Aside from this issue, is there a way to represent occupancy grid maps in V-REP?

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

### Re: How to parse data from 2D laser scanner in MATLAB?

Hello,

the data is normally relative to the model reference frame. If you need another type of data (e.g. angle+detected distances), you will have to slightly modify the child script loop that reads out the points.

To read the data from a remote API client such as Matlab, there is now a better method: you can use simxCallScriptFunction.

Your question about the occupancy grid, is it related to visualization only? If yes, you have several possibilities:
Above functions can only be called locally (i.e. not from a remote API client). But you always have the possibility to indirectly call above function via simxCallScriptFunction, from your remote API client.

Cheers

Astronirav
Posts: 10
Joined: 03 Jul 2017, 06:00

### Re: How to parse data from 2D laser scanner in MATLAB?

Hello Coppelia,

I am using the same laser scanner and facing a similar problem.
I've added the following code in the child script of the robot:

Code: Select all

data=simPackFloats(points)
simSetStringSignal("measuredDataAtThisTime",data)
Now, to get the value of range I've written following code in MATLAB:

Code: Select all

[returnCode, signalValue] = vrep.simxGetStringSignal(clientID,'measuredDataAtThisTime',vrep.simx_opmode_streaming);
while(1)
[returnCode, signalValue] = vrep.simxGetStringSignal(clientID,'measuredDataAtThisTime',vrep.simx_opmode_buffer);
disp(signalValue);
pause(0.1);
end

It prints some kind of cryptic code like this: https://drive.google.com/open?id=0B65Re ... 19TUHFRSE0

Is it because the child script sent packed code and I didn't unpack it in MATLAB?
How can I overcome this problem?

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

### Re: How to parse data from 2D laser scanner in MATLAB?

Hello,

yes, if you packed the data, then you should unpack it on the Matlab side, with simxUnpackFloats.

Cheers

idkhowtovrep
Posts: 2
Joined: 27 Aug 2019, 04:32

### Re: How to parse data from 2D laser scanner in MATLAB?

Hi,

I am trying to get the data from the fast 3d laser scanner.

I used the code:
data=sim.packFloatTable(measuredData)
sim.setStringSignal("measuredDataAtThisTime",data)

at the bottom of sysCall_sensing function. Right before the end.

However, I am getting this error when I run the simulation:

[C]: in function 'packFloatTable'
[string "CHILD SCRIPT fast3DLaserScanner"]:99: in main chunk
Lua runtime error: [string "CHILD SCRIPT fast3DLaserScanner"]:99: One of the function's argument type is not correct. (sim.packFloatTable)

What could be causing this error?

Thanks

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

### Re: How to parse data from 2D laser scanner in MATLAB?

Hello,

did you try to print measuredData just before the error happens. My guess is that measuredData is either nil or empty (e.g. no points sensed).

Cheers