Main Content

Autonomous Emergency Braking with RoadRunner Scenario

This example shows how to simulate an autonomous emergency braking (AEB) system, designed in Simulink®, with RoadRunner Scenario.

Introduction

RoadRunner Scenario is an interactive editor that enables you to design scenarios for simulating and testing automated driving systems. You can place vehicles, define their paths and interactions in the scenario, and then simulate the scenario in the editor. RoadRunner Scenario supports in-editor playback for scenario visualization and connecting to other simulators, such as MATLAB® and Simulink, for cosimulation.

AEB is an advanced active safety system that helps drivers avoid or mitigate collisions with other vehicles. This example shows how to use RoadRunner Scenario to simulate the AEB test bench model used in the Autonomous Emergency Braking with Sensor Fusion example.

This figure shows an overview of the information exchanged between RoadRunner Scenario, and autonomous emergency braking test bench model in Simulink. The autonomous emergency braking model reads all actor runtimes from RoadRunner Scenario and utilizes the actors pose and ego pose information for Simulation. The model gets the vision and radar detections from the sensors and uses this information to control the ego vehicle and writes back the updated ego pose to RoadRunner Scenario.

In this example, you:

  • Set up the environment — Configure MATLAB settings to interact with RoadRunner Scenario.

  • Author Euro NCAP scenario using RoadRunner Scenario — Author the RoadRunner scene and scenario for testing the AEB system using the European New Car Assessment Programme (Euro NCAP) test protocol.

  • Explore the AEB test bench — The test bench model has interfaces for RoadRunner Scenario, sensors, sensor fusion and tracking, decision logic, an AEB controller, vehicle dynamics, and metrics assessment.

  • Simulate with Car-to-Car Front Turn-Across-Path scenario — Cosimulate the AEB test bench model with RoadRunner Scenario for the Car-to-Car Front turn-across-path (CCFtap) test scenario, and plot the simulation results.

  • Simulate with scenario variants — Create variants of the CCFtap scenario, with speed variations of both the vehicles under test (VUT) and the global vehicle target (GVT), to assess the AEB test bench per the Euro NCAP specifications.

  • Explore other scenarios — Test the system under additional conditions.

Set Up Environment

This section shows how to set up the environment to cosimulate the AEB application with RoadRunner Scenario.

Specify the path to your local RoadRunner installation folder. This code shows the path for the default installation location on Windows®.

rrAppPath = "C:\Program Files\RoadRunner R2022b\bin\win64";

Specify the path to your RoadRunner project. This code shows a sample project folder on Windows.

rrProjectPath = "C:\RR\MyProjects";

To update the path for the RoadRunner installation folder, get the root object within the settings hierarchical tree. For more information, see SettingsGroup.

s = settings;
s.roadrunner.application.InstallationFolder.TemporaryValue = rrAppPath;

Open RoadRunner using the specified path to your project.

rrApp = roadrunner(rrProjectPath);

The rrApp RoadRunner object enables you to interact with RoadRunner from the MATLAB workspace. You can open the scenario and update the scenario variables using this object. For more information on this object, see roadrunner.

Open a working copy of the files for an AEB with RoadRunner Scenario project. MATLAB copies all the required files to the present working directory so that you can edit them.

helperDrivingProjectSetup("AEBWithRRScenario.zip",workDir=pwd)

To reduce Command Window output, turn off model predictive controller (MPC) update messages.

mpcverbosity("off");

Copy the RoadRunner scene, scenario, and behavior files to the RoadRunner project.

copyfile("AEBWithRRScenario/AEBTestScenarios/RoadRunner/Scenes",fullfile(rrProjectPath,"Scenes"))
copyfile("AEBWithRRScenario/AEBTestScenarios/RoadRunner/Scenarios",fullfile(rrProjectPath,"Scenarios"))
copyfile("AEBWithRRScenario/AEBWithRRScenario/TestBench/AEB.rrbehavior.rrmeta",fullfile(rrProjectPath,"Assets","Behaviors"))

Author Euro NCAP Scenario Using RoadRunner Scenario

This example reuses the AEB components from the Autonomous Emergency Braking with Sensor Fusion example, but shows you how you can simulate an AEB application with a Euro NCAP scenario authored using RoadRunner Scenario. This example uses a CCFtap Euro NCAP scenario authored using a junction scene, JunctionWithConnectingLanes. Open the scene.

openScene(rrApp,"JunctionWithConnectingLanes.rrscene")

The Euro NCAP specification refers to the ego vehicle as the vehicle under test (VUT) and the target vehicle as a global vehicle target (GVT).

The scenario_01_CarToCar_FrontTAP.rrscenario file is a RoadRunner scenario compatible with the AEBWithRRTestBench model. In this scenario, a VUT turns across the path of an oncoming GVT that is traveling at a constant speed, causing a collision in which the frontal structure of the GVT strikes the frontal structure of the VUT. The VUT and GVT follow predefined paths specified in the scenario. Open the scenario in the JunctionWithConnectingLanes scene.

openScenario(rrApp,"scenario_01_CarToCar_FrontTAP.rrscenario")

The GVT travels on a straight-line path. The VUT travels straight, makes a left turn, and then travels straight again. The initial and final straight-line trajectories of the VUT are clothoid, and during the turn, the trajectory has a fixed radius per the Euro NCAP Test Protocol - AEB Car-to-Car systems version 3.0.1. The scenario_01_CarToCar_FrontTAP scenario has a VUT test speed of 10 km/h, or 2.778 m/s. The VUT trajectory parameters, Computed Arc Radius and Circular Arc Angle are 9 m and 48.76 degrees, respectively. You can also configure this scenario for other VUT speeds. For more details, see the Simulate with Scenario Variants section of this example.

To simulate the AEB behavior, use the AEB.rrbehavior.rrmeta file to assign custom behavior to the ego vehicle.

Connect to the RoadRunner Scenario server for cosimulation using the createSimulation function, and enable data logging.

rrSim = rrApp.createSimulation;
set(rrSim,Logging="on")

rrSim is a Simulink.ScenarioSimulation object. Use this object to set variables and read scenarios and map-related information.

The AEB application is designed to run at a step size of 0.05 seconds. Set the simulation step size of RoadRunner Scenario to 0.05 seconds.

Ts = 0.05;
set(rrSim,StepSize=Ts)

Explore Test Bench

In this example, you use a system-level simulation test bench model to simulate and test the behavior of the AEB model with the RoadRunner Scenario. Open the test bench model.

modelName = "AEBWithRRTestBench";
open_system(modelName)

The test bench model contains RoadRunner Scenario blocks, which configure, read from, and write to RoadRunner Scenario, as well as these modules:

  • Sensors — Subsystem that specifies the actors, camera, and radar sensor used for simulation from the RoadRunner scenario.

  • Sensor Fusion and Tracking — Algorithm model that fuses vehicle detections from the camera to those from the radar sensor.

  • AEB Decision Logic — Algorithm model that specifies the lateral and longitudinal decision logic that provides the most important object (MIO) related information and ego vehicle reference path information to the controller.

  • AEB Controller — Algorithm model that specifies the steering angle and acceleration controls.

  • Vehicle Dynamics — Subsystem that specifies the dynamic model of the ego vehicle.

  • Generate EgoReference Path — Subsystem that calculates the reference path attributes using the path information from RoadRunner Scenario.

  • Pack Actor Poses — MATLAB System object that outputs the driving scenario compatible poses of target actors read from RoadRunner Scenario.

  • Metrics Assessment — Subsystem that assesses system-level behavior.

The Sensor Fusion and Tracking, AEB Decision Logic, AEB Controller, Vehicle Dynamics, and Metrics Assessment are reused from the Autonomous Emergency Braking with Sensor Fusion example.

This example focuses on the RoadRunner Scenario blocks and the Sensors subsystem.

RoadRunner Scenario Blocks

The RoadRunner Scenario blocks consist of:

  • RoadRunner Scenario — Defines the interface for an actor model.

  • Self Actor Runtime Reader — RoadRunner Scenario Reader block that reads ego actor runtime information.

  • All Actor Runtime — RoadRunner Scenario Reader block that reads the runtime information of all the vehicles.

  • Path Action — RoadRunner Scenario Reader block that reads the reference path of the ego vehicle.

  • Self Actor Runtime Writer — RoadRunner Scenario Writer block that writes the ego vehicle runtime to RoadRunner Scenario.

Sensors

The Sensors subsystem synthesizes the vision and radar sensors, which are attached to the ego vehicle.

Open the Sensors subsystem.

open_system("AEBWithRRTestBench/Sensors")

The Sensors subsystem contains these blocks:

Simulate with CCFtap Scenario

This example uses the helperSLAEBWithRRSetup helper function to set up the ego profile, and target actor profiles, along with the sensor parameters based on the ego vehicle speed. These values are scenario dependent, and can change based on the selected scenario. Configure the model with the scenario_01_CarToCar_FrontTAP scenario.

helperSLAEBWithRRSetup(rrApp,rrSim,scenarioFileName="scenario_01_CarToCar_FrontTAP")

This model may take few seconds to update the diagram when compiling for the first time. Update the model before running the simulation.

set_param(modelName,SimulationCommand="update")

Simulate the scenario and observe how the AEB system avoids collision.

set(rrSim,SimulationCommand="Start")
while strcmp(rrSim.get("SimulationStatus"),"Running")
  pause(1)
end

Notice that the sensor fusion and tracking algorithm tracks the target vehicle and the decision logic algorithm finds that target as the MIO, and that the AEB system applies the brake to mitigate the collision.

Plot the simulation results by using the helperPlotAEBResults helper function.

helperPlotAEBResults(logsout,"scenario_01_CarToCar_FrontTAP")

  • TTC vs. Stopping Time — Compares the time-to-collision and the stopping times for the forward collision warning (FCW), first stage partial brake, second stage partial brake, and full brake, respectively. For more information about multi-stage partial braking, see Autonomous Emergency Braking with Sensor Fusion.

  • FCW and AEB Status — Displays the FCW and AEB activation status based on the comparison results from the first plot.

  • Ego Car Acceleration — Shows the acceleration of the ego vehicle.

  • Ego Car Yaw and Yaw Rate — Shows the yaw and yaw rate of the ego vehicle.

  • Ego Car Velocity — Shows the velocity of the ego vehicle.

  • Headway — Shows the headway between the ego vehicle and the MIO.

In the first few seconds, the ego vehicle travels with its specified velocity of 2.778 m/s. The sensors detect the target vehicle at the intersection. Immediately after the detection, the FCW system activates.

The AEB system then applies the first stage of the partial brake, and the ego vehicle starts to slow down.

The ego vehicle reduces its velocity to mitigate the collision in this scenario.

Simulate with Scenario Variants

The Euro NCAP standard recommends testing CCFtap scenarios with speed variations for the VUT and GVT. This example supports these speed variations for the VUT and GVT, which results in a total of nine scenario variations:

  • VUT — 10, 15, or 20 km/h

  • GVT — 30, 45, or 55 km/h

To keep the same collision point for all these variations, the example modifies the wait time of the GVT. The example also updates the trajectory of the VUT with the change in its test speed, as shown in this table.

This example uses a CCFTapVariationData.mat file that contains the VUT trajectory parameters and precalculated GVT wait times for all nine scenario variations.

Load the mat file.

load("CCFtapVariationData.mat")
disp(CCFTapVariationData)
    vutSpeed    gvtSpeed    vutAlpha    vutBeta    vutRadius    gvtWaitTime
    ________    ________    ________    _______    _________    ___________

       10          30        20.62       48.76           9        6.1779   
       10          45        20.62       48.76           9        7.4019   
       10          55        20.62       48.76           9         7.847   
       15          30        20.93       48.14       11.75           2.2   
       15          45        20.93       48.14       11.75           3.5   
       15          55        20.93       48.14       11.75        3.9728   
       20          30        21.79       46.42       14.75             0   
       20          45        21.79       46.42       14.75        1.3668   
       20          55        21.79       46.42       14.75        1.8728   

scenario_01_CarToCar_FrontTAP contains variables that enable you to vary the VUT trajectory parameters and GVT wait times, as shown in this image.

You can use the setScenarioVariable function to modify these variables.

Follow these steps to simulate the AEB test bench with a scenario variant:

1. Select the variant to run and set the VUT and GVT speeds. This example shows the ninth variation, which specifies a VUT speed of 20 km/h and a GVT speed of 55 km/h.

variantID = 9;
vutSpeed = table2array(CCFTapVariationData(variantID,1));
gvtSpeed = table2array(CCFTapVariationData(variantID,2));

vutSpeed  = vutSpeed * 0.2778; % convert VUT speed from km/hr to m/s
gvtSpeed  = gvtSpeed * 0.2778; % convert GVT speed from km/hr to m/s
rrApp.setScenarioVariable("VUT_Speed",num2str(vutSpeed))
rrApp.setScenarioVariable("GVT_Speed",num2str(gvtSpeed))

2. Get the GVT wait time value from CCFtapVariationData.

gvtWaitTime = table2array(CCFTapVariationData(variantID,6));

Update the GVT_WaitTime variable of RoadRunner Scenario.

rrApp.setScenarioVariable("GVT_WaitTime",num2str(gvtWaitTime))

Based on the VUT speed, set the Euro NCAP path parameters in the RoadRunner Scenario.

rrApp.setScenarioVariable("CCFtap_Alpha",num2str(table2array(CCFTapVariationData(variantID,3))))
rrApp.setScenarioVariable("CCFtap_Beta",num2str(table2array(CCFTapVariationData(variantID,4))))
rrApp.setScenarioVariable("CCFtap_Radius",num2str(table2array(CCFTapVariationData(variantID,5))))

3. Run the setup script to initialize the required variables for the test bench.

helperSLAEBWithRRSetup(rrApp,rrSim,scenarioFileName="scenario_01_CarToCar_FrontTAP")

4. Simulate the model and plot the results.

set(rrSim,SimulationCommand="Start")
while strcmp(rrSim.get("SimulationStatus"),"Running")
  pause(1)
end

Plot the simulation results by using the helperPlotAEBResults helper function.

helperPlotAEBResults(logsout,"scenario_01_CarToCar_FrontTAP")

Explore Other Scenarios

In this example, you have explored the behavior for the scenario_01_CarToCar_FrontTAP.rrscenario scenario, which uses the JunctionWithConnectingLanes.rrscene scene. You can use the same test bench model to explore other scenarios. This example provides these additional scenarios that are compatible with the AEBWithRRTestBench model.

  • scenario_02_CarToCar_RearStationary.rrscenario — In this scenario, the VUT collides with the GVT that is stationary in the VUT lane.

  • scenario_03_CarToPedestrian_NearSide_Adult.rrscenario — In this scenario, the ego vehicle collides with a pedestrian who is traveling from the right side of the road, which Euro NCAP test protocols refer to as the near side.

Using these test scenarios, you can verify whether the AEB system successfully applies the brake and avoids or mitigates a collision with the target.

These scenarios use the HighwayStraightRoad.rrscene scene, which contains a two-way, four-lane, straight highway road. You can explore these scenarios in RoadRunner Scenario. For example, to open the scenario_02_CarToCar_RearStationary.rrscenario scenario, enter this command.

openScenario(rrApp,"scenario_02_CarToCar_RearStationary.rrscenario")

You can configure the AEBWithRRTestBench model to simulate this scenario by using the helperSLAEBWithRRSetup function. To configure the model to run the scenario_02_CarToCar_RearStationary.rrscenario scenario, enter this command.

helperSLAEBWithRRSetup(rrApp,rrSim,scenarioFileName="scenario_02_CarToCar_RearStationary")

When you are finished with this example, enable MPC update messages.

mpcverbosity("on");

See Also

Blocks

Related Topics