This example shows you how to build a driving scenario and generate vision and radar sensor detections from it by using the Driving Scenario Designer app. You can use these detections to test your controllers or sensor fusion algorithms.
This example covers the entire workflow for creating a scenario and generating synthetic detections. Alternatively, you can generate detections from prebuilt scenarios. For more details, see Prebuilt Driving Scenarios in Driving Scenario Designer.
To open the app, at the MATLAB® command prompt, enter
Add a curved road to the scenario canvas. On the app toolstrip, click Add Road. Then click one corner of the canvas, extend the road to the opposite corner, and double-click to create the road.
To make the road curve, add a road center around which to curve it. Right-click the middle of the road and select Add Road Center. Then drag the added road center to one of the empty corners of the canvas.
To adjust the road further, you can click and drag any of the road centers. To create more complex curves, add more road centers.
By default, the road is a single lane and has no lane markings. To make the scenario
more realistic, convert the road into a two-lane highway. In the left pane, on the
Roads tab, expand the Lanes section. Set
the Number of lanes to
[1 1] and the
Lane Width to
3.6 meters, which is a
typical highway lane width.
The white, solid lanes markings on either edge of the road indicate the road shoulder. The yellow, double-solid lane marking in the center indicates that the road is two-way. To inspect or modify these lanes, from the Marking list, select one of the lanes and modify the lane parameters.
By default, the first car that you add to a scenario is the ego vehicle, which is the main car in the driving scenario. The ego vehicle contains the sensors that detect the lane markings, pedestrians, or other cars in the scenario. Add the ego vehicle, and then add a second car for the ego vehicle to detect.
To add the ego vehicle, right-click one end of the road, and select Add Car. To specify the trajectory of the car, right-click the car, select Add Waypoints, and add waypoints along the road for the car to pass through. After you add the last waypoint along the road, press Enter. The car autorotates in the direction of the first waypoint. For finer precision over the trajectory, you can adjust the waypoints. You can also right-click the path to add new waypoints.
Now adjust the speed of the car. In the left pane, on the
Actors tab, set Constant Speed to
15 m/s. For more control over the speed of the car, clear
the Constant Speed check box and set the velocity between
waypoints in the Waypoints table.
Add a vehicle for the ego vehicle to detect. On the app toolstrip, click Add Actor and select Car. Add the second car with waypoints, driving in the lane opposite from the ego vehicle and on the other end of the road. Leave the speed and other settings of the car unchanged.
Add to the scenario a pedestrian crossing the road. Zoom in (Ctrl+Plus) on the middle of the road, right-click one side of the road, and click Add Pedestrian. Then, to set the path of the pedestrian, add a waypoint on the other side of the road.
By default, the color of the pedestrian nearly matches the color of the lane markings. To make the pedestrian stand out more, from the Actors tab, click the corresponding color patch for the pedestrian to modify its color.
To test the speed of the cars and the pedestrian, run the simulation. Adjust actor speeds or other properties as needed by selecting the actor from the left pane of the Actors tab.
Add front-facing radar and vision (camera) sensors to the ego vehicle. Use these sensors to generate detections of the pedestrian, the lane boundaries, and the other vehicle.
On the app toolstrip, click Add Camera. The sensor canvas shows standard locations at which to place sensors. Click the front-most predefined sensor location to add a camera sensor to the front bumper of the ego vehicle. To place sensors more precisely, you can disable snapping options. In the bottom-left corner of the sensor canvas, click the Configure the Sensor Canvas button .
By default, the camera detects only actors and not lanes. To enable lane
detections, on the Sensors tab in the left pane, expand the
Detection Parameters section and set Detection
Objects & Lanes. Then expand
the Lane Settings section and update the settings as
Snap a radar sensor to the front-left wheel. Right-click the predefined sensor location for the wheel and select Add Radar. By default, sensors added to the wheels are short range.
Tilt the radar sensor toward the front of the car. Move your cursor over the coverage area, then click and drag the angle marking.
Add an identical radar sensor to the front-right wheel. Right-click the sensor on the front-left wheel and click Copy. Then right-click the predefined sensor location for the front-right wheel and click Paste. The orientation of the copied sensor mirrors the orientation of the sensor on the opposite wheel.
The camera and radar sensors now provide overlapping coverage of the front of the ego vehicle.
To generate detections from the sensors, click Run. As the scenario runs, the Ego-Centric View displays the scenario from the perspective of the ego vehicle. The Bird’s-Eye Plot displays the detections.
To turn off certain types of detections, in the bottom-left corner of the bird's-eye plot, click the Configure the Bird's-Eye Plot button .
By default, the scenario ends when the first actor stops. To run the scenario for a set amount of time, on the app toolstrip, click Settings and change the stop condition.
To export detections to the MATLAB workspace, on the app toolstrip, select Export > Export Sensor Data. Name the workspace variable and click OK. The app saves the sensor data as a structure containing the actor poses, object detections, and lane detections at each time step.
To export a MATLAB function that generates the scenario and its detections, select Export > Export MATLAB Function. This function returns the sensor detections as a structure, the scenario
drivingScenario object, and the sensor
radarDetectionGenerator System objects. By modifying this function, you
can create variations of the original scenario. For an example of this process, see
Create Driving Scenario Variations Programmatically.
After you generate the detections, click Save to save the scenario file. In addition, you can save the sensor models as separate files. You can also save the road and actor models together as a separate scenario file.
You can reopen this scenario file from the app. Alternatively, at the MATLAB command prompt, you can use this syntax.
drivingScenarioobject. At the MATLAB command prompt, use this syntax, where
scenariois the name of the exported object.
visionDetectionGeneratorobject, or a cell array of such objects.
drivingScenarioobject into your model. This block does not directly read sensor data. To add sensors created in the app to a Simulink model, you can generate a model containing your scenario and sensors by selecting Export > Export Simulink Model. In this model, a Scenario Reader block reads the scenario and Radar Detection Generator and Vision Detection Generator blocks model the sensors.