Hokuyo communication with Matlab

Typically: "How do I... ", "How can I... " questions
Space
Posts: 27
Joined: 16 Nov 2015, 17:07

Hokuyo communication with Matlab

Post by Space » 29 Feb 2016, 14:03

Hi,

I am trying to get the information from my hokuyo used on a pioneer robot, for that i used :

on V-Rep side :

Code: Select all

-- To read the data from another script, use following instructions (in that other script):
	--
	-- INITIALIZATION PHASE:
	-- laserScannerHandle=simGetObjectHandle("Hokuyo_URG_04LX_UG01")
	-- laserScannerObjectName=simGetObjectName(laserScannerHandle) -- is not necessarily "Hokuyo_URG_04LX_UG01"!!!
	-- communicationTube=simTubeOpen(0,laserScannerObjectName..'_HOKUYO',1)
	--
	-- TO READ THE DATA:
	data=simTubeRead(communicationTube)
	if (data) then
		local packedData=simPackFloats(laserData)
		local mySignal=simGetStringSignal('measuredData')
	if not mySignal then
		mySignal=''
end
		simSetStringSignal('measuredData',mySignal..packedData)
	

 
	-- data=simTubeRead(communicationTube)
	-- if (data) then
	--     laserDetectedPoints=simUnpackFloats(data)
	-- end
	--
	-- The data in laserDetectedPoints will be RELATIVE to the laser scanner base! 
	
end 
end
I put even the commented line in case!

on the matlab side :

Code: Select all

% Establish Remote Connection with vRep (test)
    % ----------------Initializations------------------------ %
       disp('Program started');
       % vrep=remApi('remoteApi','extApi.h'); % using the header (requires a compiler)
       vrep=remApi('remoteApi'); % using the prototype file (remoteApiProto.m)
       vrep.simxFinish(-1); % just in case, close all opened connections
       clientID=vrep.simxStart('127.0.0.1',19997,true,true,5000,5);
       

     % -------------Start V-REP Simulation------------------- %
        vrep.simxStartSimulation(clientID,vrep.simx_opmode_oneshot_wait);
       

    %  while we are connected:
 try
     while (vrep.simxGetConnectionId(clientID)~=-1)    
     % Initialization phase:
[err,signal]=vrep.simxReadStringStream(clientID,'measuredData',vrep.simx_opmode_streaming);

% while we are connected:
    
        if (err==vrep.simx_return_ok)
         [err,signal]=vrep.simxReadStringStream(clientID,'measuredData',vrep.simx_opmode_buffer)
    % Data produced by the child script was retrieved!
     end
end
end
the thing is that i get an empty signal!
can you let me know what is wrong about my code?

thanks

coppelia
Site Admin
Posts: 6851
Joined: 14 Dec 2012, 00:25

Re: Hokuyo communication with Matlab

Post by coppelia » 29 Feb 2016, 17:15

Hello,

first, make sure that the signal is not empty by checking it with the model Models/other/signal monitor.ttm.

Then, does simulation start when you run the Matlab client?

Also, your code should rather look like:

Code: Select all

if (vrep.simxGetConnectionId(clientID)~=-1)
    % Initialization phase:
    [ret,signal]=vrep.simxGetStringSignal(clientID,'measuredData',vrep.simx_opmode_streaming);
    % while we are connected:
    while (vrep.simxGetConnectionId(clientID)~=-1)    
        [ret,signal]=vrep.simxReadStringStream(clientID,'measuredData',vrep.simx_opmode_buffer)
        if (ret==vrep.simx_return_ok)
            % Data produced by the child script was retrieved!
        end
    end
end
Cheers

Space
Posts: 27
Joined: 16 Nov 2015, 17:07

Re: Hokuyo communication with Matlab

Post by Space » 03 Mar 2016, 11:43

Hi,

yes, the simulation is running and other information are collected but still no signal from the hokuyo!!
even after trying your code.
perhaps it is the lua code part, because i am new and i never use the lua code to retreive information.

thanks

Space

coppelia
Site Admin
Posts: 6851
Joined: 14 Dec 2012, 00:25

Re: Hokuyo communication with Matlab

Post by coppelia » 03 Mar 2016, 12:00

Does the V-REP side generate any error? Simply try to set a test signal and see if you can read it from the remote API client.

Cheers

Space
Posts: 27
Joined: 16 Nov 2015, 17:07

Re: Hokuyo communication with Matlab

Post by Space » 05 Mar 2016, 21:29

Hi,

No error from the V-REP side and i don't know how to make a signal test!

Thanks

Space

coppelia
Site Admin
Posts: 6851
Joined: 14 Dec 2012, 00:25

Re: Hokuyo communication with Matlab

Post by coppelia » 07 Mar 2016, 09:49

You can set a string signal on the V-REP side simply with:

Code: Select all

simSetStringSignal('measuredData','hello world')
Cheers

Space
Posts: 27
Joined: 16 Nov 2015, 17:07

Re: Hokuyo communication with Matlab

Post by Space » 19 Sep 2016, 21:53

Hi,

After so many tentatives, i would like to ask your help again on the matter.

my signal is still empty after the test you ask me to perform.

thanks

Space

coppelia
Site Admin
Posts: 6851
Joined: 14 Dec 2012, 00:25

Re: Hokuyo communication with Matlab

Post by coppelia » 20 Sep 2016, 21:16

Please show us how you read the signal (and how you indicate that the signal is empty/not empty) on the Matlab side..

Cheers

Space
Posts: 27
Joined: 16 Nov 2015, 17:07

Re: Hokuyo communication with Matlab

Post by Space » 04 Oct 2016, 16:56

Hi,

I already provided this also obviously it is just the matlab prompt showing signal = [ ]

Thanks Space

runner
Posts: 1
Joined: 02 Jan 2018, 16:35

Re: Hokuyo communication with Matlab

Post by runner » 18 Jan 2018, 16:52

I don't know how others working with V-rep. But for me, I tried to read suggestions from many posts here. I still could not get data from Hokuyo Fast sensor using Matlab at the end. Could you please provide a simple test project with code(both in V-rep and Matlab's code) that i can refer to read this sensor using Matlab API function?
Many thanks.

Post Reply