Main Content

read

Acquire point clouds from velodynelidar object buffer

Since R2022b

Add-On Required: This feature requires the MATLAB Coder Support Package for NVIDIA Jetson and NVIDIA DRIVE Platforms add-on.

Description

example

[pcloud,timestamps] = read(lidarobj) returns point clouds and their respective timestamps from the velodynelidar object lidarobj.

If the object is streaming, then this syntax returns the oldest point cloud in the buffer. Use start to begin streaming point cloud data.

If the object is not streaming and there are existing point clouds in the buffer, then this syntax returns the oldest point cloud. If the object is not streaming and there are no existing point clouds in the buffer, then this syntax starts streaming for one point cloud, stops streaming, and returns it.

Examples

collapse all

This example shows how to create a connection to a Velodyne LiDAR® sensor on an NVIDIA® Jetson™ platform and capture PointCloud frames from this sensor.

Create a live hardware connection from the MATLAB® software to the NVIDIA hardware by using the jetson function. To create a live hardware connection object, provide the host name or IP address, user name, and password of the target board. For example,

hwobj = jetson('jetson-board-name','ubuntu','ubuntu');

Create a MATLAB entry-point function to capture PointCloud frames from a Velodyne LiDAR sensor.

function outStruct = readPointCloudFrame(mdlName,calibFile,port)
%#codegen

% Create hwobj
hwobj = jetson();

% % Create Velodyne Lidar Object for 'VLP16' make
obj = velodynelidar(hwobj,mdlName,calibFile,'Port',port);

% Start Receiving LiDAR Packets
start(obj);
if strcmp(mdlName,'VLP16')
    lenOut = 120;
    outStructLen = 28000;
else
    lenOut = 70;
    outStructLen = 48000;
end
% timePause = uint8(1);
outStruct = cell(2,lenOut);

for i=1:lenOut
    outStruct{1,i} = zeros(outStructLen,3);
    outStruct{2,i} = zeros(outStructLen,1,'uint8');
end

for i=1:lenOut

    % Read a Point Cloud frame
    pcFrame = read(obj);

    outStruct{1,i} = pcFrame.Location(1:min(pcFrame.Count,outStructLen),:);
    outStruct{2,i} = pcFrame.Intensity(1:min(pcFrame.Count,outStructLen));

    pause(0.1);

end


% Stop receiving LiDAR Packets
stop(obj);

% xyz = pcFrame.Location;
% Intensity = pcFrame.Intensity;

end

Note

The entry-point function cannot have multiple connection objects to the Velodyne LiDAR sensor.

Deploy the readPointCloudFrame entry-point function to the NVIDIA Jetson platform

sensorModel = coder.Constant('VLP16');
port = 2368;
calibrationFile = coder.Constant(fullfile(pwd,'VLP16CalibFile.xml'));

cfg = coder.config('exe');
cfg.Hardware = coder.hardware('NVIDIA Jetson');
cfg.GenerateExampleMain = "GenerateCodeAndCompile";

codegen -config cfg -args {sensorModel,calibrationFile,port} readPointCloudFrame

Input Arguments

collapse all

Velodyne LiDAR sensor connection created by using velodynelidar, specified as a velodynelidar object.

Output Arguments

collapse all

3-D point cloud data from Velodyne LiDAR hardware, returned as a pointCloud (Computer Vision Toolbox) object.

Timestamps for each point cloud, returned as a datetime array.

Data Types: datetime

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2022b