Page 1 of 2
simxReadProximitySensor not working on python & matlab
Posted: 17 Nov 2015, 13:13
by Space
Hi,
I am using matlab and python to simulate the navigation of my robot a pioneer p3dx.
for this, i added a Sick 2D laser on the robot but each time i try to get the data from it it returns 0.
before you ask, the connection with Vrep is working as i get the handle value of the laser and my version of python is 2.7 and matlab 2010, see below :
Code: Select all
[~,laserScannerHandle] = vrep.simxGetObjectHandle(clientID,'LaserScanner_2D',vrep.simx_opmode_oneshot_wait);
for t =1:0.1:200
[~,detectionState,detectedPointL,detectedObjectHandle,detectedSurfaceNormalVector] = vrep.simxReadProximitySensor(clientID,laserScannerHandle,vrep.simx_opmode_streaming);
[~,detectionState,detectedPointL,detectedObjectHandle,detectedSurfaceNormalVector] = vrep.simxReadProximitySensor(clientID,laserScannerHandle,vrep.simx_opmode_buffer)
thank you for your replay
Re: simxReadProximitySensor not working on python & matlab
Posted: 17 Nov 2015, 16:03
by coppelia
You have several problems. The first is that object LaserScanner_2D is not a proximity sensor! It is a shape.
Then, ALWAYS check the first return value, that will tell you if some sort of error happended, or if a time-out happended.
Finally, since your laser scanner is scanning several points in a second, if you try to read the proximity sensor as you are doing it, you will only get very sparse data. The best to do is to pack all the points for an entire scan into a string signal, and read that string signal from the Matlab side.
Cheers
Re: simxReadProximitySensor not working on python & matlab
Posted: 17 Nov 2015, 16:59
by Space
Hi,
thank you for your replay.
May i ask you what are the functions to use? i am a bit new on manipulating Vrep.
thanks in advance!
Re: simxReadProximitySensor not working on python & matlab
Posted: 17 Nov 2015, 17:13
by coppelia
On V-REP side, try with
simPackFloats and
simSetStringSignal. On the Matlab side, use
simxGetStringSignal and
simxUnpackFloats.
Cheers
Re: simxReadProximitySensor not working on python & matlab
Posted: 17 Nov 2015, 19:45
by Space
Hi Coppelia,
i tried to run the code
on the Vrep side :
Code: Select all
laserScannerHandle=simGetObjectHandle("LaserScanner_2D")
laserScannerObjectName=simGetObjectName(laserScannerHandle)
communicationTube=simTubeOpen(0,laserScannerObjectName..'_2D_SCANNER_DATA',1)
data=simTubeRead(communicationTube)
if (data) then
laserDetectedPoints=simUnpackFloats(data)
end
on the matlab side :
Code: Select all
[~,data] = vrep.simxGetStringSignal(clientID,'data',vrep.simx_opmode_streaming)
if (data)
laserDetectedPoints= vrep.simUnpackFloats(data);
end
getting through the docs, i am not sure how to get the signal on simxGetStringSignal
thanks for your help
Re: simxReadProximitySensor not working on python & matlab
Posted: 18 Nov 2015, 03:48
by coppelia
The simplest is to put something like that in the code that generates the sensor points:
Code: Select all
if (sim_call_type==sim_childscriptcall_sensing) then
...
if #points>0 then
local ptsPacked=simPackFloats(points)
simSetStringSignal("myPts",ptsPacked)
else
simClearStringSignal("myPts")
end
end
and on the Matlab side:
Code: Select all
[res,data]=vrep.simxGetStringSignal(clientID,'myPts',vrep.simx_opmode_buffer)
...
Make sure you understand how to use
data streaming with the remote API.
Cheers
Re: simxReadProximitySensor not working on python & matlab
Posted: 18 Nov 2015, 09:57
by Space
Hi coppelia,
after applying the program, I get an error message :
Lua API call error: [string "SCRIPT LaserScanner_2D"]:64: One of the function's argument type is not correct. (simSetFloatSignal)
it seems like MyPts is note defined.
I am a bit lost!!!
Thanks
Re: simxReadProximitySensor not working on python & matlab
Posted: 18 Nov 2015, 15:50
by coppelia
Sorry, made a mistake in my previous post, but corrected it now. Basically it should be simSetStringSignal, not simSetFloatSignal, and simClearStringSignal, not simClearFloatSignal.
Sorry about that.
Re: simxReadProximitySensor not working on python & matlab
Posted: 18 Nov 2015, 17:19
by Space
Thank you!
I will try it
Re: simxReadProximitySensor not working on python & matlab
Posted: 18 Nov 2015, 18:35
by Space
Hi again,
on the matlab side :
Code: Select all
[~,data]=vrep.simxGetStringSignal(clientID,'myPts',vrep.simx_opmode_buffer);
[data]=simxUnpackFloats(data)
still don't get my data!!