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 R2022b\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 and radar sensors to be added to the ego vehicle using Vision Detection Generator and Radar Detection 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.
load("busDefinitionsForRRSim.mat") modelName = 'rrScenarioSimWithSensors'; open_system(modelName)
Create a SensorSimulation
object. Specify the block paths for the radar and vision sensors in the model.
sensorSim = get(rrSim,"SensorSimulation"); visionSensorBlkPath = [modelName,'/Vision Detection Generator']; radarSensorBlkPath = [modelName,'/Driving Radar Data Generator'];
Add the two sensors to the ego vehicle using the addSensors
function.
egoVehicleId = 1; addSensors(sensorSim,{visionSensorBlkPath,radarSensorBlkPath},egoVehicleId);
Get the actor profiles of all the actors in the scenario for visualization.
rrScenario = getScenario(rrSim); actorProfiles = helperGetActorProfiles(rrScenario); numActors = length(actorProfiles); numTargets = numActors - 1;
Start the scenario Simulation. You can visualize the object detections and lane detections alongside ground truth values.
set(rrSim,"SimulationCommand","Start")
See Also
RoadRunner Scenario Reader | RoadRunner Scenario Writer | Radar Detection Generator | Vision Detection Generator