addSensors
Description
addSensors(
adds the sensors with the specified block paths sensorSim
,sensorBlkPath
,actorID
)sensorBlkPath
to the
vehicle actor with ID actorID
in the roadrunner scenario specified by
scenarioSim
. Use this syntax when you define sensor models in
Simulink®.
Examples
Add Sensors to RoadRunner Scenario Using MATLAB
Define sensor models in MATLAB®, and add them to vehicle actors in a RoadRunner Scenario. Then, obtain ground truth measurements from RoadRunner Scenario, process them into detections for visualization.
Set Up RoadRunner Scenario — MATLAB Interface
Configure your RoadRunner installation and project folder properties. Open the RoadRunner app.
rrInstallationPath = "C:\Program Files\RoadRunner R2023b\bin\win64"; rrProjectPath = "D:\RR\TestProjects"; s = settings; s.roadrunner.application.InstallationFolder.PersonalValue = rrInstallationPath; rrApp = roadrunner(rrProjectPath);
To open the scenario this example uses, you must add the TrajectoryCutIn-longRun.rrscenario
file from the example folder to your RoadRunner project folder. Then, open the scenario.
openScenario(rrApp,"TrajectoryCutIn-longRun")
Create a ScenarioSimulation
object to connect MATLAB to the RoadRunner Scenario simulation and set the step size.
scenarioSim = createSimulation(rrApp);
stepSize = 0.1;
set(scenarioSim,"StepSize",stepSize);
Create a SensorSimulation
object to control the sensor configuration for the RoadRunner Scenario simulation.
sensorSim = get(scenarioSim,"SensorSimulation");
Configure Sensors and Add to RoadRunner Scenario
Configure sensor models for vision, radar and lidar sensors to add to the ego vehicle using visionDetectionGenerator
, drivingRadarDataGenerator
and lidarPointCloudGenerator
objects. Specify unique IDs for each sensor.
visionSensor = visionDetectionGenerator(SensorIndex=1, ... SensorLocation=[2.4 0], MaxRange=50, ... DetectorOutput="Lanes and objects", ... UpdateInterval=stepSize); radarSensor = drivingRadarDataGenerator(SensorIndex=2,... MountingLocation=[1.8 0 0.2], FieldOfView=[80 5],... AzimuthResolution=1,UpdateRate=1/stepSize); lidarSensor = lidarPointCloudGenerator(SensorIndex=3,UpdateInterval=stepSize);
Add the sensor to the ego vehicle actor in the RoadRunner scenario. Specify the Actor
ID
property for the vehicle.
egoVehicleID = 1; addSensors(sensorSim,{visionSensor,radarSensor,lidarSensor},egoVehicleID);
Set up bird's-eye-plot for visualization.
[visionDetPlotter,radarDetPlotter,pcPlotter,lbGTPlotter,lbDetPlotter,bepAxes] = helperSetupBEP(visionSensor,radarSensor);
Simulate RoadRunner Scenario and Visualize Sensor Data
Use the ScenarioSimulation
object to step through the RoadRunner scenario. Retrieve target poses in the sensor range using the targetPoses
function, and process them into detections using the sensor model. Visualize detections and ground truth lane boundaries using birdsEyePlot
.
simTime = 0.0; set(scenarioSim,"SimulationCommand","Step"); pause(0.1) legend(bepAxes,"show") while ~isequal(get(scenarioSim,"SimulationStatus"),"Stopped") % Get ground truth target poses and lane boundaries from the sensor tgtPoses = targetPoses(sensorSim,1); gTruthLbs = laneBoundaries(sensorSim,1,OutputOption="EgoAdjacentLanes",inHostCoordinate=true); if ~isempty(gTruthLbs) % Get detections from vision and radar sensors [visionDets,numVisionDets,visionDetsValid,lbDets,numLbDets,lbDetsValid] = visionSensor(tgtPoses,gTruthLbs,simTime); [radarDets,numRadarDets,radarDetsValid] = radarSensor(tgtPoses,simTime); % Get point point cliud from lidar sensor [ptCloud,ptCloudValid] = lidarSensor(); % Plot ground-truth and detected lane boundaries helperPlotLaneBoundaries(lbGTPlotter,gTruthLbs) % Plot vision and radar detections if visionDetsValid detPos = cellfun(@(d)d.Measurement(1:2),visionDets,UniformOutput=false); detPos = vertcat(zeros(0,2),cell2mat(detPos')'); plotDetection(visionDetPlotter,detPos) end if lbDetsValid plotLaneBoundary(lbDetPlotter,vertcat(lbDets.LaneBoundaries)) end if radarDetsValid detPos = cellfun(@(d)d.Measurement(1:2),radarDets,UniformOutput=false); detPos = vertcat(zeros(0,2),cell2mat(detPos')'); plotDetection(radarDetPlotter,detPos) end % Plot lidar point cloud if ptCloudValid plotPointCloud(pcPlotter,ptCloud); end end if ~isequal(get(scenarioSim,"SimulationStatus"),"Stopped") set(scenarioSim,"SimulationCommand","Step"); end simTime = simTime + stepSize; pause(0.1) end
Helper Functions
helperSetupBEP
function creates a bird's-eye-plot and configures all the plotters for visualization.
helperPlotLaneBoundaries
function plots the lane boundaries on the birds'eye-plot.
Add Sensors to RoadRunner Scenario Using Simulink
Define sensor models in Simulink®, and add them to vehicle actors in a RoadRunner Scenario. Then, obtain ground truth measurements from RoadRunner Scenario, process them into detections in Simulink for visualization.
Set Up RoadRunner Scenario — Simulink Interface
Configure your RoadRunner installation and project folder properties. Open the RoadRunner app.
rrInstallationPath = "C:\Program Files\RoadRunner R2023b\bin\win64"; rrProjectPath = "D:\RR\TestProjects"; s = settings; s.roadrunner.application.InstallationFolder.PersonalValue = rrInstallationPath; rrApp = roadrunner(rrProjectPath);
To open the scenario this example uses, you must add these files from the example folder to your RoadRunner project folder:
straightCurvedFourLaneRoad.rrscene
— RoadRunner scene file that describes the four lane highway.SensorDerectionSimulation.rrscenario
— RoadRunner scenario file that describes actors and their trajectories on the four lane highway scene.SensorIntegration.rrbehavior.rrmeta
— Behavior file that associates the sensor detection processing and visualization behavior using Simulink, to the ego vehicle in the RoadRunner scenario.
copyfile("straightCurvedFourLaneRoad.rrscene",fullfile(rrProjectPath,"Scenes/")); copyfile("SensorDetectionSimulation.rrscenario",fullfile(rrProjectPath,"Scenarios/")) copyfile("SensorIntegration.rrbehavior.rrmeta",fullfile(rrProjectPath,"Assets","Behaviors/"))
Open the scenario and create a ScenarioSimulation
object to connect Simulink with the RoadRunner Scenario.
openScenario(rrApp,"SensorDetectionSimulation")
rrSim = createSimulation(rrApp);
Specify the step size for the RoadRunner scenario simulation. The Simulink model also uses the same step size. Units are in seconds.
simStepSize = 0.1;
set(rrSim,"StepSize",simStepSize);
Inspect Simulink Model and Simulate Scenario
The Simulink model rrScenarioSimWithSensors
configures sensor models for the vision, radar and lidar sensors using the Vision Detection Generator, Driving Radar Data Generator and Lidar Point Cloud Generator blocks respectively. The model reads ground truth data from the scenario and processes that into detections and visualizes the detections. It also reads the path defined for the ego vehicle from the RoadRunner Scenario, implements the path follower logic and controls the ego vehicle motion along the path.
Load the bus definitions and open the model. Note that the lidar sensor model block does not require any ground-truth target pose inputs.
load("busDefinitionsForRRSim.mat") modelName = 'rrScenarioSimWithSensors'; open_system(modelName)
Create a SensorSimulation
object. Specify the block paths for the radar, vision and lidar sensors in the model.
sensorSim = get(rrSim,"SensorSimulation"); visionSensorBlkPath = [modelName,'/Vision Detection Generator']; radarSensorBlkPath = [modelName,'/Driving Radar Data Generator']; lidarSensorBlkPath = [modelName,'/Lidar Point Cloud Generator'];
Add the three sensors to the ego vehicle using the addSensors
function.
egoVehicleId = 1; addSensors(sensorSim,{visionSensorBlkPath,radarSensorBlkPath,lidarSensorBlkPath},egoVehicleId);
To visualize the scenario and sensor detections, use the Bird'sEye Scope app. On the Simulink toolstrip, under Review Results, click Bird's-Eye Scope. Then in the scope, click Find Signals to establish connection with the RoadRunner scenario and populate the signals to visualize.
Start the scenario Simulation. The model visualizes the 3D point cloud using the Point Cloud Viewer block during the simulation. In Bird's-Eye Scope, you can visualize the 2D point cloud, object detections and lane detections alongside ground truth values.
set(rrSim,"SimulationCommand","Start")
Input Arguments
sensorSim
— Sensor simulation object
SensorSimulation
object
Sensor simulation object, specified as a SensorSimulation
object. The sensor simulation object must correspond to the
desired scenario created in RoadRunner Scenario.
sensors
— Sensors to add to RoadRunner Scenario simulation
visionDetectionGenerator
object | drivingRadarDataGenerator
object | ultrasonicDetectionGenerator
object | lidarPointCloudGenerator
object | cell array of detection generator objects
Sensors to add to the RoadRunner Scenario simulation, specified as one of these options:
A single
visionDetectionGenerator
,drivingRadarDataGenerator
,ultrasonicDetectionGenerator
orlidarPointCloudGenerator
objectA cell array of any combination of the previously listed detection generator objects
Each detection generator must have a unique sensor ID, specified by its
SensorIndex
property.
sensorBlkPath
— Block paths of sensors to add to RoadRunner Scenario simulation
cell array of character vectors
Block paths of sensors to add to the RoadRunner Scenario simulation, specified as a cell array of character vectors. Each block path must point to one of these detection generator blocks:
Each detection generator must have a unique sensor ID, specified by its
Unique sensor identifier
block parameter.
actorID
— Actor ID of vehicle in RoadRunner scenario
positive integer
Actor ID of the vehicle in the RoadRunner scenario, specified as a positive integer. The function adds sensors to the vehicle in the scenario with this actor ID.
Version History
Introduced in R2023a
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)