sensor - Capture and Update Lidar Scan Data in Matlab -
i want hokuyo ubg-04lx-f01 lidar scan , read range data matlab. code returns data 1 scan, can provide on how can code continuously return scan data (continuously update lidar scans). code matlab. thanks.
%this function capture , display scan data %it displays range data 1 scan 682 steps function [rangescan] = capturedata(urg_device) proceed=0; while (proceed==0) fprintf(urg_device, 'gd0044072500\n'); pause(0.1); data = fscanf(urg_device); if numel(data) == 2134 proceed = 1; end end = find(data == data(13)); rangedata = data(i(3)+1:end-1); onlyrangedata = []; j=0:31 onlyrangedata((64*j)+1:(64*j)+64) = rangedata( 1+(66*j):64+(66*j)); end j=0; i=1:floor(numel(onlyrangedata)/3) encodeddist(i,:)=[onlyrangedata((3*j)+1) onlyrangedata((3*j)+2) onlyrangedata((3*j)+3)]; j=j+1; end k=1:size(encodeddist,1) rangescan(k)=decodescip(encodeddist(k,:)); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function decodes data, works 2 or 3 bit character encoding function rangeval=decodescip(rangeenc) % check 2 or 3 character encoding if rangeenc(1)=='0' && rangeenc(2)=='0' && rangeenc(3)=='0' rangeval=0; return; end if rangeenc(1)=='0' dig1=((rangeenc(2)-'!')+33); dig2=((rangeenc(3)-'!')+33); dig1sub=dig1-48; dig2sub=dig2-48; dig1bin=dec2bin(dig1sub,6); dig2bin=dec2bin(dig2sub,6); rangeval=bin2dec([dig1bin dig2bin]); return; else dig1=((rangeenc(1)-'!')+33); dig2=((rangeenc(2)-'!')+33); dig3=((rangeenc(3)-'!')+33); dig1sub=dig1-48; dig2sub=dig2-48; dig3sub=dig3-48; dig1bin=dec2bin(dig1sub,6); dig2bin=dec2bin(dig2sub,6); dig3bin=dec2bin(dig3sub,6); rangeval=bin2dec([dig1bin dig2bin dig3bin]); return; end end
Comments
Post a Comment