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 created using a drivingScenario
(Automated Driving Toolbox) object.
Create Driving Scenario
Create a driving scenario using the drivingScenario
(Automated Driving Toolbox) object, and define the ego vehicle.
scenario = drivingScenario; scenario.SampleTime=0.1; % 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);
Generate the actor profiles from your driving scenario.
aProfiles = actorProfiles(scenario);
Generate Point Cloud Data
Using lidarSensor
Object
Use these steps to programmatically generate point cloud data for the driving scenario using a lidarSensor
object.
Create a lidarSensor
object.
lidar = lidarSensor(AzimuthResolution=0.5, ...
ElevationAngles=[-25:1.6:10 11:1:20]);
Add lidar sensor to the scenario by using the addSensors
(Automated Driving Toolbox) function.
scenario.addSensors(lidar);
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() % Generate and visualize point cloud data [ptCloud,isValidTime] = lidar(scenario.SimulationTime); if isValidTime view(player,ptCloud); end end
Using Lidar Sensor Simulink Block
Use these steps to generate point cloud data for the driving scenario in Simulink®.
Open the Simulink model.
open_system("GeneratePointCloudForDrivingScenario.slx")
This model uses:
A Scenario Reader (Automated Driving Toolbox) block to read the actors and roads of the scenario. In the block parameters, set the Source of driving scenario parameter to
From workspace,
and specify the name of a validdrivingScenario
(Automated Driving Toolbox) object workspace variable in the MATLAB or model workspace variable name parameter. The block outputs the poses of the actors in the scenario.A Lidar Sensor block that generates synthetic lidar data of the scenario in the ego vehicle coordinate system. You must specify the actor profiles generated from the scenario in the MATLAB or Model workspace Actor profiles variable name parameter. You can add noise, as well as simulate weather conditions such as rain and fog, using this block. The block outputs point cloud data along with the intensity and segmentation values of the points.
A Point Cloud Viewer block to visualize the generated point cloud data.
A To Workspace block that exports segmentation and intensity values to the MATLAB® workspace.
Run the model to visualize the point cloud.
sim("GeneratePointCloudForDrivingScenario");
Tips
You can use the Driving Scenario Designer (Automated Driving Toolbox) app to interactively create a driving scenario. You can export the scenario from the app into a MATLAB function or Simulink model, and generate synthetic sensor data for a scenario.
The app also has some prebuilt scenarios you can work with. For more details on prebuilt scenarios, see Prebuilt Driving Scenarios in Driving Scenario Designer (Automated Driving Toolbox).
To learn more about the app, see these videos:
See Also
Functions
lidarSensor
|drivingScenario
(Automated Driving Toolbox)