Main Content

read

Acquire point clouds from velodynelidar object buffer

Since R2020b

Add-On Required: This feature requires the Lidar Toolbox Support Package for Velodyne LiDAR Sensors add-on.

Description

pcloud = read(lidarobj) returns a point cloud 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.

example

pcloud = read(lidarobj,'all') returns all point clouds from the velodynelidar object lidarobj.

If the object is streaming, then this syntax returns all existing point clouds in the buffer at the moment when the function is called. After acquiring them, it deletes them from the buffer, then continues streaming.

If the object is not streaming and there are existing point clouds in the buffer, then this syntax returns all available point clouds and deletes them from the buffer. If the object is not streaming and there are no existing point clouds in the buffer, then this syntax returns an empty array.

pcloud = read(lidarobj,numPC,mode) returns the number of point clouds specified by numPC from the velodynelidar object lidarobj. Acquire point clouds from a specific position in the buffer by setting the mode to 'oldest' or 'latest'. After this syntax acquires point clouds, it deletes them and any point clouds older than them from the buffer.

If the object is not streaming and there are existing point clouds in the buffer, then this syntax returns data from those point clouds. If the object is not streaming and there are no existing point clouds in the buffer, then this syntax starts streaming for the specified number of point clouds. Then, the function stops streaming and returns those specified point clouds.

The input arguments numPC and mode can also be used individually in this syntax. When they are not specified, the default value for numPC is 1 and the default value for mode is 'oldest'.

example

[pcloud,timestamps] = read(___) returns point clouds and their respective timestamps from the velodynelidar object lidarobj using any of the available syntaxes listed.

example

Examples

collapse all

You can acquire point clouds with or without using start to stream data to the object buffer. If you do not start streaming, the read function starts streaming, acquires the specified point clouds, then stops streaming.

For more information about acquiring point cloud data from your Velodyne LiDAR® sensor, see Read Point Clouds.

Create a velodynelidar object for an HDL-32E sensor.

v = velodynelidar('HDL32E');

Acquire the latest point cloud. Because the velodynelidar object is not currently streaming, this starts streaming, reads the specified point cloud, then stops streaming.

[pcloud,timestamp] = read(v);

Display the point cloud in a figure window by using pcshow. This function requires the Computer Vision Toolbox.

pcshow(pcloud);

You can acquire point clouds with or without using start to stream data to the object buffer. If you do start streaming, you can read the latest or oldest point clouds in the buffer and specify the number of point clouds to read. After you call the read function, it deletes the point clouds you acquired and any point clouds older than the ones you acquired from the buffer.

For more information about acquiring point cloud data from your Velodyne LiDAR sensor, see Read Point Clouds.

Create a velodynelidar object for an HDL-32E sensor. Then start streaming point clouds. Once the start function is called, streaming continues in the background.

v = velodynelidar('HDL32E');
start(v)

After some time has passed and point cloud data has been recorded, acquire the ten oldest point clouds in the buffer.

[pclouds,timestamps] = read(v,10,'oldest');

After calling read, these ten point clouds are no longer in the buffer, but newer ones will continue to be available.

Stop streaming when you are finished.

stop(v)

Input Arguments

collapse all

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

Number of point clouds to acquire, specified as a double. If the buffer has fewer than the number of point clouds specified and streaming is stopped, it returns all the point clouds in the buffer. If the buffer has fewer than the number of point clouds specified and streaming is on, it waits until the number of specified point clouds is available. If this value is not specified, the function returns one point cloud.

This input argument is optional. If you do specify a value, the default is 1.

When you specify this value, the input argument mode cannot be 'all'. It must be 'latest' or 'oldest'.

Data Types: double

Position of point clouds in the buffer, specified as a character vector. The possible values are:

  • 'oldest' — returns the earliest point clouds and timestamps

  • 'latest' — returns the most recent point clouds and timestamps

  • 'all' — returns all point clouds and timestamps

This input argument is optional. If you do specify a value, the default is 'oldest'.

When you set the mode to 'all', you cannot specify the argument numPC because this mode returns all available data. If you do not specify numPC, the function returns one point cloud.

When you set the mode to 'oldest', newer point clouds continue to be available in the buffer after calling the read function. When you set the mode to 'latest', older point clouds are discarded after calling the read function.

Data Types: char | string

Output Arguments

collapse all

3-D point cloud data from Velodyne LiDAR hardware, returned as a pointCloud object.

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

Data Types: datetime

Version History

Introduced in R2020b