Main Content

velodynelidar

Connection to a Velodyne LiDAR sensor

Since R2022b

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

    Description

    This object represents a connection to a Velodyne LiDAR® sensor from the NVIDIA DRIVE® or Jetson™ hardware. To create this object, use the velodynelidar function. To configure the Velodyne LiDAR object settings, use the object properties listed in Properties. To interact with the Velodyne LiDAR sensor, use this object with the functions listed in Object Functions.

    Creation

    Description

    v = velodynelidar(hwObj,'model','calibrationFile') creates an object v that can read point clouds from the Velodyne LiDAR sensor of the indicated model.

    Note

    You cannot create multiple connection objects to the Velodyne LiDAR sensor.

    example

    v = velodynelidar(___,'Port',portValue,'Timeout',timeoutValue)specifies additional options with one or more name-value pair arguments. For example, you can specify a timeout value. There are three properties that you can set by using the name-value pair arguments: Port and Timeout.

    Input Arguments

    expand all

    Connection to a specific NVIDIA hardware board, specified as a jetson or drive object.

    Model name of Velodyne sensor, specified as a character vector or string.

    Possible values for model include the values listed in this table.

    Model ValueVelodyne Model
    'HDL32E'HDL-32E sensor
    'VLP16'VLP-16 Puck sensor

    Example: v = velodynelidar(hwobj,'HDL32E')

    Name of XML file containing Velodyne LiDAR laser calibration data, specified as the comma-separated pair consisting of 'CalibrationFile' and a character vector or string. It must include the full path to the file as well, as shown in the example. If you do not specify a calibration file, a default calibration file with data obtained from Velodyne device manuals is chosen.

    Example: v = velodynelidar(hwobj,'HDL32E','C:\...\utilities\velodyneFileReaderConfiguration\HDL32E.xml')

    Data port of the Velodyne LiDAR sensor, specified as the comma-separated pair consisting of 'Port' and a positive value of type double. The data port for your sensor is listed in the Velodyne Web Interface Data Port field. The default is 2368.

    Example: v = velodynelidar(hwobj,'HDL32E','C:\...\utilities\velodyneFileReaderConfiguration\HDL32E.xml','Port',3000)

    Maximum time in seconds to wait for a response from the Velodyne LiDAR sensor, specified as the comma-separated pair consisting of 'Timeout' and a positive value of type double. The timeout is for waiting for point clouds when you use the read command. The default is 10. You can change the value either during object creation or after you create the object.

    Example: v = velodynelidar(hwobj,'HDL32E','C:\...\utilities\velodyneFileReaderConfiguration\HDL32E.xml','Port',3000,'Timeout',20)

    Output Arguments

    expand all

    Object that represents a connection to a Velodyne LiDAR sensor from the NVIDIA DRIVE or Jetson hardware.

    Properties

    expand all

    Velodyne model, specified during object creation. Read-only after object is created.

    UDP data port of the sensor. The port is required when creating the object if it is different from the default of 2368. Read-only after object creation.

    Timeout specified for reading a Point Cloud from the sensor, in seconds. Can be set during object creation or after.

    Path and name of an XML file containing Velodyne LiDAR laser calibration data. The name can be set when creating the object. Read-only after object creation.

    Indicates whether the sensor is streaming data. A value of 0 means it is not streaming. A value of 1 means it is streaming data to the buffer. Read-only. You can use the start and stop functions to control streaming.

    Object Functions

    readAcquire point clouds from velodynelidar object buffer
    startStart streaming point clouds from Velodyne LiDAR sensor
    stopStop streaming point clouds from Velodyne LiDAR sensor

    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
    

    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