Code covered by the BSD License  

Highlights from
HOKUYO UTM-30LX-EW Matlab API

image thumbnail

HOKUYO UTM-30LX-EW Matlab API

by

 

Adapted to support the Hokuyo to request HE measurements, i.e. multiecho distance and intensity.

utmGetScan(t,start,stop);
function [dat_a timestamp] = utmGetScan(t,start,stop);
% Returns a scan from hokuyo utm30-lx-ew laser
% t = tcpip object created with utmOpen
% start = starting point
% stop = end point of laser reading
% skipping and groupin is both zero

if nargin==1
    start=0;
    stop=1080;
end

noPoints=(stop-start+1);

% Measurement command code, function - multiecho distance and intensity acquisition
cmd=sprintf('HE%04d%04d%02d\n',start,stop,0);
fprintf(t,'%s', cmd);
timestamp=etime(clock,[1970 1 1 0 0 0]);

% we only read DATA, the header is retreived by fscanf
noBlocks=ceil(noPoints*6/64 ); % ceil rounds the elements to the nearest integers
%bytesToGet=noPoints*6+noBlocks*2+1;

header=fscanf(t);
status=fscanf(t);
time=fscanf(t);

if ~strcmp(cmd,header) || ~strncmp('00P',status,3)
    error('HOKUYO UTM-30-LX-EW returned a wrong status');
end
%scan = fread(t,bytesToGet);

% Pause for the communication delay
pause(0.07); % without this pause, error will appear

% Number of bytes currently available to be read from the input buffer
bytes2read=t.BytesAvailable;

% Avoiding that BytesAvailable value is zero
while bytes2read==0
      bytes2read=t.BytesAvailable;
end

% Reads data from the laser scanner into column vector
sca_n = fread(t,t.BytesAvailable);

noBlocks=ceil(bytes2read/66);

%% Extracting data from the scan
dat_a=[];
for i=1:noBlocks-1
    dat_a=[dat_a; sca_n( (i-1)*66+1 : (i-1)*66 + 64 )];
end

dat_a=[dat_a; sca_n((noBlocks-1)*66+1:end-3)]; % save('data','data');

end

Contact us