This example shows how to test an open-loop ADAS (advanced driver assistance system) algorithm in Simulink®. In an open-loop ADAS algorithm, the ego vehicle behavior is predefined and does not change as the scenario advances during simulation.
To test the scenario, you use a driving scenario that was saved from the Driving Scenario Designer app. In this example, you read in a scenario using a Scenario Reader block, and then visually verify the performance of sensor algorithms on the Bird's-Eye Scope.
Before beginning this example, add the example file folder to the MATLAB® search path.
addpath(genpath(fullfile(matlabroot,'examples','driving')))
This example uses a driving scenario that is based on one of the prebuilt scenarios that you can access through the Driving Scenario Designer app. For more details on these scenarios, see Prebuilt Driving Scenarios in Driving Scenario Designer.
Open the scenario file in the app.
drivingScenarioDesigner('LeftTurnScenario.mat')
Click Run to simulate the scenario. In this scenario, the ego vehicle travels north and goes straight through an intersection. Meanwhile, a vehicle coming from the left side of the intersection turns left and ends up in front of the ego vehicle.
The ego vehicle also includes a front-facing radar for generating object detections and front-facing and rear-facing cameras for generating object and lane boundary detections.
The model used in this example was generated from the app by selecting Export > Export Simulink Model. In the model, a Scenario Reader block reads the actors and roads from the scenario file and outputs the non-ego actors and lane boundaries. Open the model.
open_system('OpenLoopWithScenarios.slx')
In the Scenario Reader block, the Driving Scenario Designer file name parameter specifies the name of the scenario file. You can specify a scenario file that is on the MATLAB search path, such as the scenario file used in this example, or the full path to a scenario file. Alternatively, you can specify a
object by setting Source of driving scenario to drivingScenario
From workspace
and then setting MATLAB or model workspace variable name to the name of a valid drivingScenario
object workspace variable.
The Scenario Reader block outputs the poses of the non-ego actors in the scenario and the left-lane and right-lane boundaries of the ego vehicle. To output all lane boundaries of the road on which the ego vehicle is traveling, select the corresponding option for the Lane boundaries to output parameter.
The actors and lane boundaries are passed to a subsystem containing the sensor blocks. Open the subsystem.
open_system('OpenLoopWithScenarios/Detection Generators')
The Radar Detection Generator block accepts the actors as input. The Vision Detection Generator block accepts the actors and lane boundaries as input. These sensor blocks produce synthetic detections from the scenario. The outputs are in vehicle coordinates, where:
The X-axis points forward from the ego vehicle.
The Y-axis points to the left of the ego vehicle.
The origin is located at the center of the rear axle of the ego vehicle.
If a scenario has multiple ego vehicles, in the Scenario Reader block, set the Coordinate system of outputs parameter to World coordinates
instead of Vehicle coordinates
. In the world coordinate system, the actors and lane boundaries are in the world coordinates of the driving scenario. When this parameter is set to World coordinates
, however, visualization of the scenario using the Bird's-Eye Scope is not supported.
Because this model is open loop, the ego vehicle behavior does not change as the simulation advances. Therefore, the Source of ego vehicle parameter is set to Scenario
, and the block reads the predefined ego vehicle pose and trajectory from the scenario file. For vehicle controllers and other closed-loop models, set the Source of ego vehicle parameter to Input port
. With this option, you specify an ego vehicle that is defined in the model as an input to the Scenario Reader block. For an example, see Test Closed-Loop ADAS Algorithm Using Driving Scenario.
To visualize the scenario and the object and lane boundary detections, use the Bird's-Eye Scope. From the Simulink toolstrip, under Review Results, click Bird's-Eye Scope. Then, in the scope, click Find Signals and run the simulation. The sensors generate detections for the non-ego actor and lane boundaries.
This model uses the default simulation stop time of 10 seconds. However, because the scenario is only about 5 seconds long, the simulation continues to run in the Bird's-Eye Scope even after the scenario has ended. To synchronize the simulation and scenario stop times, in the Simulink model toolbar, set the simulation stop time to 5.2
seconds, which is the exact stop time of the app scenario. After you run the simulation, the app displays this value in the bottom-right corner of the scenario canvas.
If the simulation runs too fast in the Bird's-Eye Scope, you can slow down the simulation by using simulation pacing. From the Simulink toolstrip, select Run > Simulation Pacing. Select the Enable pacing to slow down simulation check box and decrease the simulation time to slightly less than 1 second per wall-clock second, such as 0.8 seconds. Then, rerun the simulation in the Bird's-Eye Scope.
When you are done with this example, remove the example file folder from the MATLAB search path.
rmpath(genpath(fullfile(matlabroot,'examples','driving')))