Main Content

Generate Lidar Point Cloud Data for Driving Scenario with Multiple Actors

This example shows you how to generate lidar point cloud data for a driving scene with roads, pedestrians, and vehicles. First create a driving scenario by using the drivingScenario (Automated Driving Toolbox) object, and then configure a lidarSensor object to generate point cloud data for the scenario.

Create Driving Scenario

Create a driving scenario using the drivingScenario (Automated Driving Toolbox) object, and define the ego vehicle.

scenario = drivingScenario;

% Add the ego vehicle
egoVehicle = vehicle(scenario, ...
    ClassID=1, ...
    Mesh=driving.scenario.carMesh);
waypoints = [1 -2 0; 35 -2 0];
trajectory(egoVehicle,waypoints,10);

Define the road and the lanes for the scenario as Actor objects using the actor (Automated Driving Toolbox) function. Specify a custom value for the ClassID property of each actor. Using the actor (Automated Driving Toolbox) function to create roads enables you to define the mesh representation for the road, to generate point cloud data. Otherwise, the function does not generate points for the road.

actor(scenario,ClassID=7,Length=200,Width=20,Height=0.1);
actor(scenario,ClassID=7,Length=200,Width=0.3, ...
      Height=0.1,Position=[0 -5 0.02]);
actor(scenario,ClassID=7,Length=200,Width=0.3, ...
      Height=0.1,Position=[0 5 0.02]);

Add a car, truck, pedestrian, and bicycle to the scene as other actors.

% Add a moving car with a speed of 20 meters per second.
movingCar = vehicle(scenario, ...
     ClassID=1, ...
     Mesh=driving.scenario.carMesh);
waypoints = [90 -5 0; 15 -5 0];
speed = 20;
trajectory(movingCar,waypoints,speed);

% Add a truck with a speed of 15 meters per second.
truck = vehicle(scenario, ...
    ClassID=2, ...
    Length=8.2, ...
    Width=2.5, ...
    Height=3.5, ...
    Mesh=driving.scenario.truckMesh);
waypoints = [70 1.7 0; 20 1.9 0];
speed = 15;
trajectory(truck,waypoints,speed);

% Add a pedestrian.
pedestrian = actor(scenario, ...
    ClassID=4, ...
    Length=0.24, ...
    Width=0.45, ...
    Height=1.7, ...
    Mesh=driving.scenario.pedestrianMesh);
waypoints = [23 -4 0; 10.4 -4 0];
speed = 1.5;
trajectory(pedestrian,waypoints,speed);

% Add a bicycle.
bicycle = actor(scenario, ...
    ClassID=3, ...
    Length=1.7, ...
    Width=0.45, ...
    Height=1.7, ...
    Mesh=driving.scenario.bicycleMesh);
waypoints = [12.7 -3.3 0; 49.3 -3.3 0];
speed = 5;
trajectory(bicycle,waypoints,speed);
plot(scenario,Waypoints="on")
title("Driving scenario with actors")

Generate Point Cloud Data

Create a lidarSensor object.

lidar = lidarSensor(AzimuthResolution=0.5, ...
        ElevationAngles=[-25:1.6:10 11:1:20]); 

Generate the actor profiles from your driving scenario and assign them to the lidarSensor object.

lidar.ActorProfiles = actorProfiles(scenario);

Create a pcplayer object to visualize the output point cloud.

player = pcplayer([-60 60],[-20 20],[0 5]);

Advance the scene and generate point cloud data.

while advance(scenario) && player.isOpen()
    % Get updated target poses from the scenario object
    tgts = targetPoses(egoVehicle);

    % Generate and visualize point cloud data
    [ptCloud,isValidTime] = lidar(tgts,scenario.SimulationTime);
    if isValidTime
        view(player,ptCloud);
    end
end

Figure contains an axes object. The axes object with title Driving scenario with actors contains 19 objects of type patch, line.

{"String":"Figure Point Cloud Player contains an axes object. The axes object contains an object of type scatter.","Tex":[],"LaTex":[]}

See Also

Functions