Main Content

drivingRadarDataGenerator

Generate radar sensor detections or track reports from driving scenario or RoadRunner Scenario

Since R2021a

Description

The drivingRadarDataGenerator System object™ generates detections or track reports of targets from an automotive radar sensor model. Use this object to generate sensor data from a driving scenario containing actors and trajectories, which you can create by using a drivingScenario object. When creating scenarios using the Driving Scenario Designer app, the radar sensors mounted on the ego vehicle are output as drivingRadarDataGenerator objects.

The drivingRadarDataGenerator object can simulate clustered or unclustered detections with added random noise and also generate false alarm detections. You can fuse the generated detections with other sensor data and track objects using a multiObjectTracker object. You can also output tracks directly from the drivingRadarDataGenerator object. To configure whether targets are output as clustered detections, unclustered detections, or tracks, use the TargetReportFormat property.

You can also use the drivingRadarDataGenerator object with vehicle actors in RoadRunner Scenario simulation. First you must create a SensorSimulation object to interface sensors with RoadRunner Scenario and then register the lidar as a sensor model using the addSensors object function before simulation.

To generate radar detection or track reports:

  1. Create the drivingRadarDataGenerator object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

rdr = drivingRadarDataGenerator creates a radar sensor that reports clustered detections and uses default property values.

rdr = drivingRadarDataGenerator(id) sets the SensorIndex property to id.

rdr = drivingRadarDataGenerator(___,Name,Value) sets properties using one or more name-value pairs. Enclose each property name in quotes. For example, drivingRadarDataGenerator('TargetReportFormat','Tracks','FilterInitializationFcn',@initcvkf) creates a radar sensor that generates track reports by using a tracker that is initialized by a constant-velocity linear Kalman filter.

example

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Sensor Identification

Unique sensor identifier, specified as a positive integer. Use this property to distinguish between detections or tracks that come from different sensors in a multisensor system. Specify a unique value for each sensor. If you do not update SensorIndex from the default value of 0, then the radar returns an error at the start of simulation.

Data Types: double

Sensor update rate, in hertz, specified as a positive real scalar. The reciprocal of the update rate must be an integer multiple of the simulation time interval. The radar generates new reports at intervals defined by this reciprocal value. Any sensor update requested between update intervals contains no detections or tracks.

Data Types: double

Sensor Mounting

Sensor location on the ego vehicle body frame, in meters, specified as a 1-by-3 real-valued vector of the form [x y z]. This property defines the coordinates of the sensor along the x-axis, y-axis, and z-axis relative to the ego vehicle origin, where:

  • The x-axis points forward from the vehicle.

  • The y-axis points to the left of the vehicle.

  • The z-axis points up from the ground.

The default value corresponds to a radar that is mounted at the center of the front grill of a sedan.

For more details on the ego vehicle coordinate system, see Coordinate Systems in Automated Driving Toolbox.

Data Types: double

Mounting rotation angles of the radar, in degrees, specified as a 1-by-3 real-valued vector of form [zyaw ypitch xroll]. This property defines the intrinsic Euler angle rotation of the sensor around the z-axis, y-axis, and x-axis with respect to the ego vehicle body frame, where:

  • zyaw, or yaw angle, rotates the sensor around the z-axis of the ego vehicle.

  • ypitch, or pitch angle, rotates the sensor around the y-axis of the ego vehicle. This rotation is relative to the sensor position that results from the zyaw rotation.

  • xroll, or roll angle, rotates the sensor about the x-axis of the ego vehicle. This rotation is relative to the sensor position that results from the zyaw and ypitch rotations.

These angles are clockwise-positive when looking in the forward direction of the z-axis, y-axis, and x-axis, respectively. If you visualize sensor data from a bird's-eye view perspective, then the yaw angle is counterclockwise-positive because you are viewing the data in the negative direction of the z-axis, which points up from the ground.

For more details on this coordinate system, see Coordinate Systems in Automated Driving Toolbox.

Data Types: double

Detection Reporting

Enable the radar to measure target elevation angles, specified as a logical 0 (false) or 1 (true). Set this property to true to model a radar sensor that can estimate target elevation.

Data Types: logical

Enable the radar to measure target range rates, specified as a logical 1 (true) or 0 (false). Set this property to true to model a radar sensor that can measure range rates from target detections.

Data Types: logical

Enable the addition of noise to radar sensor measurements, specified as a logical 1 (true) or 0 (false). Set this property to true to add noise to the radar measurements. Otherwise, the measurements have no noise. Even if you set HasNoise to false, the measurement noise covariance matrix reported in the MeasurementNoise property of the generated object detections output, dets, represents the measurement noise that is added when HasNoise is true.

Data Types: logical

Enable creating false alarm radar measurements, specified as a logical 1 (true) or 0 (false). Set this property to true to report false alarms. Otherwise, the radar reports only actual detections.

Data Types: logical

Enable line-of-sight occlusion, specified as a logical 1 (true) or 0 (false). To generate detections only from objects for which the radar has a direct line of sight, set this property to true. For example, with this property enabled, the radar does not generate a detection for a vehicle that is behind another vehicle and blocked from view.

Data Types: logical

Source of the maximum for the number of detection or track reports, specified as one of these options:

  • 'Auto' — The sensor reports all detections or tracks.

  • 'Property' — The sensor reports the first N valid detections or tracks, where N is equal to the MaxNumReports property value.

Maximum number of detections or tracks that the sensor reports, specified as a positive integer. The sensor reports detections in the order of increasing distance from the sensor until reaching this maximum number.

Dependencies

To enable this property, set the MaxNumReportsSource property to 'Property'.

Data Types: double

Format of generated target reports, specified as one of these options:

  • 'Clustered detections' — The sensor generates target reports as clustered detections, where each target is reported as a single detection that is the centroid of the unclustered target detections. The sensor returns clustered detections as an array of objectDetection objects, as described in the dets output argument.

  • 'Tracks' — The sensor generates target reports as tracks, which are clustered detections that have been processed by a tracking filter. The sensor returns tracks as an array of objectTrack objects, as described in the tracks output argument.

  • 'Detections' — The sensor generates target reports as unclustered detections, where each target can have multiple detections. The sensor returns unclustered detections as an array of objectDetection objects, as described in the dets output argument.

Coordinate system of reported detections, specified as one of these options:

  • 'Body' — Detections are reported in the rectangular body system of the ego vehicle.

  • 'Sensor rectangular' — Detections are reported in the rectangular body system of the radar sensor.

  • 'Sensor spherical' — Detections are reported in a spherical coordinate system that is centered at the radar sensor and aligned with the orientation of the radar on the ego vehicle.

Measurement Resolution

Azimuth resolution of the radar, in degrees, specified as a positive scalar. The azimuth resolution defines the minimum separation in azimuth angle at which the radar can distinguish between two targets. The azimuth resolution is typically the 3 dB downpoint of the azimuth angle beamwidth of the radar.

Data Types: double

Elevation resolution of the radar, in degrees, specified as a positive real scalar. The elevation resolution defines the minimum separation in elevation angle at which the radar can distinguish between two targets. The elevation resolution is typically the half-power beamwidth of the elevation angle beamwidth of the radar.

Dependencies

To enable this property, set the HasElevation property to true.

Data Types: double

Range resolution of the radar, in meters, specified as a positive real scalar. The range resolution defines the minimum separation in range at which the radar can distinguish between two targets.

Data Types: double

Range rate resolution of the radar, in meters per second, specified as a positive real scalar. The range rate resolution defines the minimum separation in range rate at which the radar can distinguish between two targets.

Dependencies

To enable this property, set the HasRangeRate property to true.

Data Types: double

Measurement Bias

Azimuth bias fraction of the radar, specified as a nonnegative scalar. Azimuth bias is expressed as a fraction of the azimuth resolution specified in the AzimuthResolution property. This value sets a lower bound on the azimuthal accuracy of the radar and is dimensionless.

Data Types: double

Elevation bias fraction of the radar, specified as a nonnegative scalar. Elevation bias is expressed as a fraction of the elevation resolution specified by the ElevationResolution property. This value sets a lower bound on the elevation accuracy of the radar and is dimensionless.

Dependencies

To enable this property, set the HasElevation property to true.

Data Types: double

Range bias fraction of the radar, specified as a nonnegative scalar. Range bias is expressed as a fraction of the range resolution specified by the RangeResolution property. This property sets a lower bound on the range accuracy of the radar and is dimensionless.

Data Types: double

Range-rate bias fraction of the radar, specified as a nonnegative scalar. Range-rate bias is expressed as a fraction of the range-rate resolution specified by the RangeRateResolution property. This property sets a lower bound on the range rate accuracy of the radar and is dimensionless.

Dependencies

To enable this property, set the HasRangeRate property to true.

Data Types: double

Detection Settings

Probability of detecting a target, specified as a scalar in the range (0, 1]. This property defines the probability of detecting a target with a radar cross-section (RCS), ReferenceRCS, at the reference detection range, ReferenceRange.

Data Types: double

Reference range for the given probability of detection and the given reference radar cross-section (RCS), in meters, specified as a positive real scalar. The reference range is the range at which a target having a radar cross-section specified by the ReferenceRCS property is detected with a probability of detection specified by the DetectionProbability property.

Data Types: double

Reference radar cross-section (RCS) for a given probability of detection and reference range, in decibel square meters, specified as a real scalar. The reference RCS is the RCS value at which a target is detected with a probability specified by DetectionProbability at the specified ReferenceRange value.

Data Types: double

False alarm report rate within each radar resolution cell, specified as a positive real scalar in the range [10–7, 10–3]. Units are dimensionless. The object determines resolution cells from the AzimuthResolution and RangeResolution properties and, when enabled, from the ElevationResolution and RangeRateResolution properties.

Data Types: double

Center frequency of the radar band, in hertz, specified as a positive scalar.

Data Types: double

Angular field of view of radar, in degrees, specified as a 1-by-2 positive real-valued vector of the form [azfov elfov]. The field of view defines the total angular extent spanned by the sensor. The azimuth field of view, azfov, must lie in the interval (0, 360]. The elevation field of view, elfov, must lie in the interval (0, 180].

Data Types: double

Minimum and maximum range of radar, in meters, specified as a 1-by-2 nonnegative real-valued vector of the form [min max]. The radar does not detect targets that are outside this range. The maximum range, max, must be greater than the minimum range, min.

Minimum and maximum range rate of radar, in meters per second, specified as a 1-by-2 real-valued vector of the form [min max]. The radar does not detect targets that are outside this range rate. The maximum range rate, max, must be greater than the minimum range rate, min.

Dependencies

To enable this property, set the HasRangeRate property to true.

This property is read-only.

Radar loop gain, specified as a real scalar. RadarLoopGain depends on the values of the DetectionProbability, ReferenceRange, ReferenceRCS, and FalseAlarmRate properties. Radar loop gain is a function of the reported signal-to-noise ratio of the radar, SNR, the target radar cross-section, RCS, and the target range, R, as described by this equation:

SNR = RadarLoopGain + RCS – 40log10(R)

SNR and RCS are in decibels and decibel square meters, respectively, R is in meters, and RadarLoopGain is in decibels.

Data Types: double

Tracking Settings

Kalman filter initialization function, specified as a function handle or as a character vector or string scalar of the name of a valid Kalman filter initialization function.

The table shows the initialization functions that you can use to specify FilterInitializationFcn.

Initialization FunctionFunction Definition
initcaabfInitialize constant-acceleration alpha-beta Kalman filter
initcvabfInitialize constant-velocity alpha-beta Kalman filter
initcakfInitialize constant-acceleration linear Kalman filter.
initcvkfInitialize constant-velocity linear Kalman filter.
initcaekfInitialize constant-acceleration extended Kalman filter.
initctekf Initialize constant-turnrate extended Kalman filter.
initcvekfInitialize constant-velocity extended Kalman filter.
initcaukf Initialize constant-acceleration unscented Kalman filter.
initctukfInitialize constant-turnrate unscented Kalman filter.
initcvukfInitialize constant-velocity unscented Kalman filter.

You can also write your own initialization function. The function must have the following syntax:

filter = filterInitializationFcn(detection)
The input to this function is a detection report like those created by an objectDetection object. The output of this function must be a tracking filter object, such as trackingKF, trackingEKF, trackingUKF, or trackingABF.

To guide you in writing this function, you can examine the details of the supplied functions from within MATLAB®. For example:

type initcvekf

Dependencies

To enable this property, set the TargetReportFormat property to 'Tracks'.

Data Types: function_handle | char | string

Threshold for track confirmation, specified as a 1-by-2 vector of positive integers of the form [M N]. A track is confirmed if it receives at least M detections in the last N updates. M must be less than or equal to N.

  • When setting M, take into account the probability of object detection for the sensors. The probability of detection depends on factors such as occlusion or clutter. You can reduce M when tracks fail to be confirmed or increase M when too many false detections are assigned to tracks.

  • When setting N, consider the number of times you want the tracker to update before it makes a confirmation decision. For example, if a tracker updates every 0.05 seconds, and you want to allow 0.5 seconds to make a confirmation decision, set N = 10.

Example: [3 5]

Dependencies

To enable this property, set the TargetReportFormat property to 'Tracks'.

Data Types: double

Threshold for track deletion, specified as a 1-by-2 vector of positive integers of the form [P R]. If a confirmed track is not assigned to any detection P times in the last R tracker updates, then the track is deleted. P must be less than or equal to R.

  • To reduce how long the radar maintains tracks, decrease R or increase P.

  • To maintain tracks for a longer time, increase R or decrease P.

Example: [3 5]

Dependencies

To enable this property, set the TargetReportFormat property to 'Tracks'.

Data Types: double

Coordinate system of reported tracks, specified as one of these options:

  • 'Body' — Tracks are reported in the rectangular body system of the ego vehicle.

  • 'Sensor' — Tracks are reported in the rectangular body system of the radar sensor.

Dependencies

To enable this property, set the TargetReportFormat property to 'Tracks'.

Target Profiles

Actor profiles, specified as a structure or as an array of structures. Each structure contains the physical and radar characteristics of an actor.

  • If ActorProfiles is a single structure, all actors passed into the drivingRadarDataGenerator object use this profile.

  • If ActorProfiles is an array, each actor passed into the object must have a unique actor profile.

To generate an array of structures for your driving scenario, use the actorProfiles function. The table shows the valid structure fields. If you do not specify a field, that field is set to its default value. If no actors are passed into the object, then the ActorID field is not included.

FieldDescription
ActorIDScenario-defined actor identifier, specified as a positive integer.
ClassIDClassification identifier, specified as a nonnegative integer. 0 is reserved for an object of an unknown or unassigned class.
LengthLength of actor, specified as a positive real scalar. The default is 4.7. Units are in meters.
WidthWidth of actor, specified as a positive real scalar. The default is 1.8. Units are in meters.
HeightHeight of actor, specified as a positive real scalar. The default is 1.4. Units are in meters.
OriginOffset

Offset of the rotational center of the actor from its geometric center, specified as an [x y z] real-valued vector. The rotational center, or origin, is located at the bottom center of the actor. For vehicles, the rotational center is the point on the ground beneath the center of the rear axle. The default is [0 0 0]. Units are in meters.

RCSPatternRadar cross-section pattern of actor, specified as a numel(RCSElevationAngles)-by-numel(RCSAzimuthAngles) real-valued matrix. The default is [10 10; 10 10]. Units are in decibels per square meter.
RCSAzimuthAnglesAzimuth angles corresponding to rows of RCSPattern, specified as a vector of real values in the range [–180, 180]. The default is [-180 180]. Units are in degrees.
RCSElevationAnglesElevation angles corresponding to rows of RCSPattern, specified as a vector of real values in the range [–90, 90]. The default is [-90 90]. Units are in degrees.

For full definitions of the structure fields, see the actor and vehicle functions.

Data Types: struct

Usage

Description

Generate Detections

These syntaxes apply when you set the TargetReportFormat property to 'Clustered detections' or 'Detections'.

dets = rdr(targets,simTime) creates radar detections, dets, from sensor measurements taken of target poses, targets, relative to the ego vehicle at the current simulation time, simTime. The object can generate sensor detections for multiple actors simultaneously.

[dets,numReports] = rdr(targets,simTime) also returns the number of valid detections reported, numReports.

[dets,numReports,isValidTime] = rdr(targets,simTime) also returns a logical value, isValidTime, indicating whether simTime is a valid time for generating detections. If simTime is an integer multiple of the reciprocal of the UpdateRate property value, then isValidTime is 1 (true).

example

Generate Tracks

These syntaxes apply when you set the TargetReportFormat property to 'Tracks'.

tracks = rdr(targets,simTime) creates radar tracks, tracks, from sensor measurements taken of target poses, targets, relative to the ego vehicle at the current simulation time, simTime. The object can generate sensor tracks for multiple actors simultaneously.

[tracks,numReports] = rdr(targets,simTime) also returns the number of valid tracks reported, numReports.

[tracks,numReports,isValidTime] = rdr(targets,simTime) also returns a logical value, isValidTime, indicating whether simTime is a valid time for generating tracks. If simTime is an integer multiple of the reciprocal of the UpdateRate property value, then isValidTime is 1 (true).

example

Input Arguments

expand all

Target actor poses, specified as a structure or structure array. Each structure corresponds to the pose of a target actor relative to the ego vehicle. To generate these structures, use the targetPoses function. You can also create these structures manually. Do not include the ego vehicle pose in the structure array.

This table shows the required fields for the structures.

FieldDescription
ActorID

Scenario-defined actor identifier, specified as a positive integer.

ClassIDClassification identifier, specified as a nonnegative integer. 0 represents an object of an unknown or unassigned class.
Position

Position of actor, specified as a real-valued vector of the form [x y z]. Units are in meters.

Velocity

Velocity (v) of actor in the x-, y-, and z-directions, specified as a real-valued vector of the form [vx vy vz]. Units are in meters per second.

Roll

Roll angle of actor, specified as a real scalar. Units are in degrees.

Pitch

Pitch angle of actor, specified as a real scalar. Units are in degrees.

Yaw

Yaw angle of actor, specified as a real scalar. Units are in degrees.

AngularVelocity

Angular velocity (ω) of actor in the x-, y-, and z-directions, specified as a real-valued vector of the form [ωx ωy ωz]. Units are in degrees per second.

Current simulation time, in seconds, specified as a nonnegative real scalar.

Example: 10.5

Data Types: double

Output Arguments

expand all

Generated detections, returned as a cell array of objectDetection objects. Each object contains these properties:

PropertyDefinition
TimeMeasurement time
MeasurementObject measurements
MeasurementNoiseMeasurement noise covariance matrix
SensorIndexUnique ID of the sensor
ObjectClassIDObject classification
MeasurementParametersParameters used by initialization functions of nonlinear Kalman tracking filters
ObjectAttributesAdditional information passed to tracker

For rectangular coordinates, Measurement and MeasurementNoise are reported in the rectangular coordinate system specified by the DetectionCoordinates property of the drivingRadarDataGenerator object.

For spherical coordinates, Measurement and MeasurementNoise are reported in the spherical coordinate system, which is based on the sensor rectangular coordinate system.

Measurement and MeasurementNoise

DetectionCoordinates ValueMeasurement and MeasurementNoise Coordinates
'Body'

Coordinate Dependence on HasRangeRate

HasRangeRateCoordinates
true[x;y;z;vx;vy;vz]
false[x;y;z]
'Sensor rectangular'
'Sensor spherical'

Coordinate Dependence on HasRangeRate and HasElevation

HasRangeRateHasElevationCoordinates
truetrue[az;el;rng;rr]
truefalse[az;rng;rr]
falsetrue[az;el;rng]
falsefalse[az;rng]

For ObjectAttributes, this table describes the additional information used for tracking.

ObjectAttributes

AttributeDefinition
TargetIndexIdentifier of the actor, ActorID, that generated the detection. For false alarms, this value is negative.
SNRDetection signal-to-noise ratio, in dB.

For MeasurementParameters, the measurements are relative to the parent frame. When you set the DetectionCoordinates property to 'Body', the parent frame is the ego vehicle body. When you set DetectionCoordinates to 'Sensor rectangular' or 'Sensor spherical', the parent frame is the sensor.

MeasurementParameters

ParameterDefinition
Frame Enumerated type indicating the frame used to report measurements. When Frame is set to 'rectangular', detections are reported in rectangular coordinates. When Frame is set to 'spherical', detections are reported in spherical coordinates.
OriginPosition3-D vector offset of the sensor origin from the parent frame origin.
OriginVelocityVelocity of the sensor coordinate system with respect to the parent frame.
OrientationOrientation of the radar sensor coordinate system with respect to the parent frame.
IsParentToChildLogical scalar indicating if Orientation performs a frame rotation from the parent coordinate frame to the child coordinate frame. When IsParentToChild is false, then Orientation performs a frame rotation from the child coordinate frame to the parent coordinate frame.
HasAzimuthIndicates whether measurements contain azimuth components.
HasElevationIndicates whether measurements contain elevation components.
HasRangeIndicates whether measurements contain range components.
HasVelocityIndicates whether measurements contain velocity or range rate components.

Generated tracks, returned as an objectTrack array in MATLAB and a structure array in generated code. In generated code, the field names of the returned structure are same as the property names of the objectTrack object.

The sensor returns only confirmed tracks, which are tracks that satisfy the confirmation threshold specified in the ConfirmationThreshold property. For these tracks, the IsConfirmed property of the object or field of the structure is true.

Data Types: struct | object

Number of reported detections or tracks, returned as a nonnegative integer. numReports is equal to the length of dets when generating detections and tracks when generating tracks.

Data Types: double

Valid time for generating reports, returned as a logical 0 (false) or 1 (true).

If isValidTime is 0 (false), then the reports returned by dets (for generated detections) or tracks (for generated tracks) are invalid because the sensor generated them at a time that is inconsistent with the sensor update rate.

The sensor generates reports only when the current simulation time, simTime, is an integer multiple of the time interval at which the sensor generates reports. This time interval is equal to the reciprocal of the UpdateRate property value.

Data Types: logical

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

isLockedDetermine if System object is in use
cloneCreate duplicate System object
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Use a radar sensor to generate clustered detections, unclustered detections, and tracks of multiple vehicles in a driving scenario.

Create Driving Scenario

Create an empty driving scenario and add a two-lane, 100-meter road segment. Separate the lanes by using dashed lane markings.

scenario = drivingScenario('SampleTime',0.02);
roadCenters = [0 0 0; 100 0 0];
marking = [laneMarking('Solid') laneMarking('Dashed') laneMarking('Solid')];
laneSpecification = lanespec([1 1],'Marking',marking);
road(scenario,roadCenters,'Lanes',laneSpecification);

Add the ego vehicle. The vehicle travels 90 meters in the right lane at a constant speed of 20 meters per second.

ego = vehicle(scenario,'ClassID',1,'Position',[5 -1.8 0]);
egoWaypoints = [ego.Position; ...
               (ego.Position(1) + 90) ego.Position(2:3)];
egoSpeed = 20; % m/s
smoothTrajectory(ego,egoWaypoints,egoSpeed)

Add the target vehicles that the radar can generate detections and tracks from.

  • The first vehicle is a car that starts 10 meters in front of the ego vehicle and travels along the lane at a constant speed of 30 meters per second.

  • The second vehicle is a truck that travels in the left lane at a constant speed of 30 meters per second.

car = vehicle(scenario,'ClassID',1,'Position',[ego.Position(1)+10 -1.8 0]);
carWaypoints = [car.Position; ...
               (car.Position(1) + 75) car.Position(2:3)];
carSpeed = 30; % m/s
smoothTrajectory(car,carWaypoints,carSpeed)

truck = vehicle(scenario,'ClassID',2,'Position',[5 1.8 0], ...
    'Length',8.2,'Width',2.5,'Height',3.5);
truckWaypoints = [truck.Position; ...
                 (truck.Position(1) + 90) truck.Position(2:3)];
truckSpeed = 30; % m/s
smoothTrajectory(truck,truckWaypoints,truckSpeed)

Plot the driving scenario and pause to allow time for the plot to update.

plot(scenario)
while advance(scenario)
    pause(scenario.SampleTime)
end

Create Radar Sensor

Create a radar sensor with a maximum range of 100 meters and mount it to the front mirror of the ego vehicle. Configure the sensor to update at the same rate as the sample time of the scenario. Specify for the radar to use the target profiles of the car and truck for generating data.

close(gcf)

maxRange = 100; % m
frontMirror = [ego.FrontOverhang 0 (ego.Height-0.1)];
profiles = actorProfiles(scenario);
targetProfiles = profiles(2:end);

id = 1;
rdr = drivingRadarDataGenerator(id,'UpdateRate',1/scenario.SampleTime, ...
                                   'MountingLocation',frontMirror, ...
                                   'RangeLimits',[0 maxRange], ...
                                   'Profiles',targetProfiles)
rdr = 

  drivingRadarDataGenerator with properties:

             SensorIndex: 1
              UpdateRate: 50

        MountingLocation: [0.9000 0 1.3000]
          MountingAngles: [0 0 0]

             FieldOfView: [20 5]
             RangeLimits: [0 100]
         RangeRateLimits: [-100 100]

    DetectionProbability: 0.9000
          FalseAlarmRate: 1.0000e-06

  Use get to show all properties

Create Bird's-Eye Plot

Create a bird's-eye plot for visualizing the sensor data. Add plotters for visualizing the lane markings, vehicle outlines, and radar coverage area. Use the helperPlotScenario function to plot these aspects of the scenario. This helper function is defined at the end of the example.

bep = birdsEyePlot('XLim',[0 60],'YLim',[-35 35]);

lmPlotter = laneMarkingPlotter(bep,'Tag','lm','DisplayName','Lane markings');
olPlotter = outlinePlotter(bep,'Tag','ol');
caPlotter = coverageAreaPlotter(bep, ...
    'Tag','ca', ...
    'DisplayName','Radar coverage area', ...
    'FaceColor','red','EdgeColor','red');

helperPlotScenario(bep,rdr,ego)

Generate Clustered Detections

Use the radar to generate clustered detections of the target vehicles. Visualize these detections on the bird's-eye plot. At each simulation time step, the radar generates only one detection per target.

clusterDetPlotter = detectionPlotter(bep, ...
    'DisplayName','Clustered detections', ...
    'MarkerEdgeColor','red', ...
    'MarkerFaceColor','red');

restart(scenario)
while advance(scenario)

    simTime = scenario.SimulationTime;
    targets = targetPoses(ego);
    [dets,numDets,isValidTime] = rdr(targets,simTime);

    helperPlotScenario(bep,rdr,ego)

    if isValidTime && numDets > 0
        detPos = cell2mat(cellfun(@(d)d.Measurement(1:2),dets, ...
            'UniformOutput',false)')';
        plotDetection(clusterDetPlotter,detPos)
    end

end

Generate Unclustered Detections

Use the radar to generate unclustered detections of the target vehicles. Visualize these detections on the bird's-eye plot. At each simulation time step, the radar generates multiple detections per target.

clearData(clusterDetPlotter)
release(rdr)

rdr.TargetReportFormat = "Detections";
detPlotter = detectionPlotter(bep, ...
    'DisplayName','Unclustered detections', ...
    'MarkerEdgeColor','red');

restart(scenario)
while advance(scenario)

    simTime = scenario.SimulationTime;
    targets = targetPoses(ego);
    [dets,numDets,isValidTime] = rdr(targets,simTime);

    helperPlotScenario(bep,rdr,ego)

    if isValidTime && numDets > 0
        detPos = cell2mat(cellfun(@(d)d.Measurement(1:2),dets, ...
            'UniformOutput',false)')';
        plotDetection(detPlotter,detPos)
    end

end

Generate Tracks

Use the radar to generate tracks of the target vehicles. Visualize these tracks and the track history on the bird's-eye plot.

clearData(detPlotter)
release(rdr)

rdr.TargetReportFormat = "Tracks";
historyDepth = 20;
tPlotter = trackPlotter(bep,'DisplayName','Tracks', ...
    'HistoryDepth',historyDepth);

restart(scenario)
while advance(scenario)

    simTime = scenario.SimulationTime;
    targets = targetPoses(ego);
    [tracks,numTracks,isValidTime] = rdr(targets,simTime);

    helperPlotScenario(bep,rdr,ego)

    if isValidTime && numTracks > 0
        trackPos = cell2mat(arrayfun(@(t)t.State(1:2:end),tracks, ...
            'UniformOutput', false)')';
        plotTrack(tPlotter,trackPos(:,1:2))
    end

end

Close the bird's-eye plot, restart the scenario, and release the radar sensor.

close(gcf)
restart(scenario)
release(rdr)

Supporting Functions

helperPlotScenario plots the lane markings and vehicle outlines of the ego vehicle on the bird's-eye plot. It also plots the coverage area of the radar sensor.

function helperPlotScenario(bep,radar,ego)

    % Plot lane markings
    lmPlotter = findPlotter(bep,'Tag','lm');
    [lmv,lmf] = laneMarkingVertices(ego);
    plotLaneMarking(lmPlotter,lmv,lmf)

    % Plot vehicle outlines
    olPlotter = findPlotter(bep,'Tag','ol');
    [position,yaw,length,width,originOffset,color] = targetOutlines(ego);
    plotOutline(olPlotter,position,yaw,length,width, ...
                   'OriginOffset',originOffset,'Color',color)

    % Plot radar coverage area
    caPlotter = findPlotter(bep,'Tag','ca');
    plotCoverageArea(caPlotter,radar.MountingLocation(1:2), ...
        radar.RangeLimits(2),radar.MountingAngles(1), ...
        radar.FieldOfView(1))

end

Extended Capabilities

Version History

Introduced in R2021a