actor

Add actor to driving scenario

Description

ac = actor(scenario) adds an Actor object, ac, to the driving scenario, scenario. The actor has default property values.

Actors are cuboids (box shapes) that represent objects in motion, such as cars, pedestrians, and bicycles. Actors can also represent stationary obstacles that can influence the motion of other actors, such as barriers. For more details about how actors are defined, see Actor and Vehicle Positions and Dimensions.

example

ac = actor(scenario,Name,Value) sets actor properties using one or more name-value pair arguments. For example, you can set the position, velocity, dimensions, and orientation of the actor. You can also set a time for the actor to spawn or despawn in the scenario.

Note

You can configure the actors in a driving scenario to spawn and despawn, and then import the associated drivingScenario object into the Driving Scenario Designer app. The app considers the first actor created in the driving scenario to be the ego actor and does not allow the ego actor to either spawn or despawn in the scenario.

Examples

collapse all

Create a driving scenario containing a curved road, two straight roads, and two actors: a car and a bicycle. Both actors move along the road for 60 seconds.

Create the driving scenario object.

scenario = drivingScenario('SampleTime',0.1','StopTime',60);

Create the curved road using road center points following the arc of a circle with an 800-meter radius. The arc starts at 0°, ends at 90°, and is sampled at 5° increments.

angs = [0:5:90]';
R = 800;
roadcenters = R*[cosd(angs) sind(angs) zeros(size(angs))];
roadwidth = 10;
road(scenario,roadcenters,roadwidth);

Add two straight roads with the default width, using road center points at each end.

roadcenters = [700 0 0; 100 0 0];
road(scenario,roadcenters)
ans = 
  Road with properties:

           Name: ""
         RoadID: 2
    RoadCenters: [2x3 double]
      RoadWidth: 6
      BankAngle: [2x1 double]

roadcenters = [400 400 0; 0 0 0];
road(scenario,roadcenters)
ans = 
  Road with properties:

           Name: ""
         RoadID: 3
    RoadCenters: [2x3 double]
      RoadWidth: 6
      BankAngle: [2x1 double]

Get the road boundaries.

rbdry = roadBoundaries(scenario);

Add a car and a bicycle to the scenario. Position the car at the beginning of the first straight road.

car = vehicle(scenario,'ClassID',1,'Position',[700 0 0], ...
    'Length',3,'Width',2,'Height',1.6);

Position the bicycle farther down the road.

bicycle = actor(scenario,'ClassID',3,'Position',[706 376 0]', ...
    'Length',2,'Width',0.45,'Height',1.5);

Plot the scenario.

plot(scenario,'Centerline','on','RoadCenters','on');
title('Scenario');

Display the actor poses and profiles.

poses = actorPoses(scenario)
poses=2×1 struct array with fields:
    ActorID
    Position
    Velocity
    Roll
    Pitch
    Yaw
    AngularVelocity

profiles = actorProfiles(scenario)
profiles=2×1 struct array with fields:
    ActorID
    ClassID
    Length
    Width
    Height
    OriginOffset
    MeshVertices
    MeshFaces
    RCSPattern
    RCSAzimuthAngles
    RCSElevationAngles

Create a driving scenario. Set the stop time for the scenario to 3 seconds.

scenario = drivingScenario('StopTime',3);

Add a two-lane road to the scenario.

roadCenters = [0 1 0; 53 1 0];
laneSpecification = lanespec([1 1]);
road(scenario,roadCenters,'Lanes',laneSpecification);

Add another road that intersects the first road at a right angle to form a T-shape.

roadCenters = [20.3 33.4 0; 20 3 0];
laneSpecification = lanespec(2);
road(scenario,roadCenters,'Lanes',laneSpecification)
ans = 
  Road with properties:

           Name: ""
         RoadID: 2
    RoadCenters: [2x3 double]
      RoadWidth: 7.3500
      BankAngle: [2x1 double]

Add the ego vehicle to the scenario and define its waypoints. Set the ego vehicle speed to 20 m/s and generate the trajectories for the ego vehicle.

egoVehicle = vehicle(scenario,'ClassID',1, ...
                    'Position',[1.5 2.5 0]);
waypoints = [2 3 0; 13 3 0;
            21 3 0; 31 3 0;
            43 3 0; 47 3 0];
speed = 15;
trajectory(egoVehicle,waypoints,speed)

Add a non-ego actor to the scenario. Set the non-ego actor to spawn and despawn during the simulation by specifying an entry time and an exit time.

nonEgoactor1 = actor(scenario,'ClassID',1, ...
                'Position',[22 30 0],'EntryTime',0.8,'ExitTime',2);

Define the waypoints for the non-ego actor. Set the non-ego actor speed to 35 m/s and generate its trajectories.

waypoints = [22 30 0; 22 23 0;
            22 13 0; 22 7 0;
            18 -0.3 0; 12 -0.8 0; 3 -0.8 0];
speed = 35;
trajectory(nonEgoactor1,waypoints,speed)

Add another non-ego actor to the scenario. Set the second non-ego actor to spawn during the simulation by specifying an entry time. Since you do not specify an exit time, this actor will remain in the scenario until the scenario ends.

nonEgoactor2 = actor(scenario,'ClassID',1, ...
                'Position',[48 -1 0],'EntryTime',2);

Define the waypoints for the second non-ego actor. Set the actor speed to 60 m/s and generate its trajectories.

waypoints = [48 -1 0; 42 -1 0; 28 -1 0;
            16 -1 0; 6 -1 0];
speed = 60;
trajectory(nonEgoactor2,waypoints,speed)

Create a custom figure window to plot the scenario.

fig = figure;
set(fig,'Position',[0 0 600 600])
movegui(fig,'center')
hViewPnl = uipanel(fig,'Position',[0 0 1 1],'Title','Actor Spawn and Despawn');
hPlt = axes(hViewPnl);

Plot the scenario and run the simulation. Observe how the non-ego actors spawn and despawn in the scenario while simulation is running.

plot(scenario,'Waypoints','on','Parent',hPlt)
while advance(scenario)
    pause(0.1)
end

Input Arguments

collapse all

Driving scenario, specified as a drivingScenario object.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Height',1.7 sets the height of the actor to 1.7 meters upon creation.

Classification identifier of actor, specified as the comma-separated pair consisting of 'ClassID' and a nonnegative integer.

Specify ClassID values to group together actors that have similar dimensions, radar cross-section (RCS) patterns, or other properties. As a best practice, before adding actors to a drivingScenario object, determine the actor classification scheme you want to use. Then, when creating the actors, specify the ClassID name-value pair to set classification identifiers according to the actor classification scheme.

Suppose you want to create a scenario containing these actors:

  • Two cars, one of which is the ego vehicle

  • A truck

  • A bicycle

The code shows a sample classification scheme for this scenario, where 1 refers to cars, 2 refers to trucks, and 3 refers to bicycles. The cars have default vehicle properties. The truck and bicycle have the dimensions of a typical truck and bicycle, respectively.

scenario = drivingScenario;
ego = vehicle(scenario,'ClassID',1);
car = vehicle(scenario,'ClassID',1);
truck = vehicle(scenario,'ClassID',2,'Length',8.2,'Width',2.5,'Height',3.5);
bicycle = actor(scenario,'ClassID',3,'Length',1.7,'Width',0.45,'Height',1.7);

The default ClassID of 0 is reserved for an object of an unknown or unassigned class. If you plan to import drivingScenario objects into the Driving Scenario Designer app, do not leave the ClassID property of actors set to 0. The app does not recognize a ClassID of 0 for actors and returns an error. Instead, set ClassID values of actors according to the actor classification scheme used in the app.

ClassIDClass Name
1Car
2Truck
3Bicycle
4Pedestrian
5Barrier

Name of the actor, specified as the comma-separated pair consisting of 'Name' and a character vector or string scalar.

Example: 'Name','Actor1'

Example: "Name","Actor1"

Data Types: char | string

Entry time for an actor to spawn in the driving scenario, specified as the comma-separated pair consisting of 'EntryTime' and a positive scalar. Units are in seconds, measured from the start time of the scenario.

Specify this name-value pair argument to add or make an actor appear in the driving scenario at the specified time, while the simulation is running.

  • If the actor has an associated exit time, then the entry time must be less than the specified exit time.

  • If the actor does not have an associated exit time, then the entry time must be less than or equal to the stop time of the scenario. You can set the stop time for the scenario by specifying a value for the 'StopTime' property of the drivingScenario object.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Exit time for an actor to despawn from the driving scenario, specified as the comma-separated pair consisting of 'ExitTime' and a positive scalar. Units are in seconds, measured from the start time of the scenario.

Specify this name-value pair argument to remove or make an actor disappear from the scenario at a specified time while the simulation is running.

  • If the actor has an associated entry time, then the exit time must be greater than the specified entry time.

  • If the actor does not have an associated entry time, then the exit time must be less than or equal to the stop time of the scenario. You can set the stop time for the scenario by specifying a value for the 'StopTime' property of the drivingScenario object.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Display color of actor, specified as the comma-separated pair consisting of 'PlotColor' and an RGB triplet, hexadecimal color code, color name, or short color name.

The actor appears in the specified color in all programmatic scenario visualizations, including the plot function, chasePlot function, and plotting functions of birdsEyePlot objects. If you import the scenario into the Driving Scenario Designer app, then the actor appears in this color in all app visualizations. If you import the scenario into Simulink®, then the actor appears in this color in the Bird's-Eye Scope.

If you do not specify a color for the actor, the function assigns one based on the default color order of Axes objects. For more details, see the ColorOrder property for Axes objects.

For a custom color, specify an RGB triplet or a hexadecimal color code.

  • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]; for example, [0.4 0.6 0.7].

  • A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Thus, the color codes '#FF8800', '#ff8800', '#F80', and '#f80' are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
'red''r'[1 0 0]'#FF0000'

'green''g'[0 1 0]'#00FF00'

'blue''b'[0 0 1]'#0000FF'

'cyan' 'c'[0 1 1]'#00FFFF'

'magenta''m'[1 0 1]'#FF00FF'

'yellow''y'[1 1 0]'#FFFF00'

'black''k'[0 0 0]'#000000'

'white''w'[1 1 1]'#FFFFFF'

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]'#0072BD'

[0.8500 0.3250 0.0980]'#D95319'

[0.9290 0.6940 0.1250]'#EDB120'

[0.4940 0.1840 0.5560]'#7E2F8E'

[0.4660 0.6740 0.1880]'#77AC30'

[0.3010 0.7450 0.9330]'#4DBEEE'

[0.6350 0.0780 0.1840]'#A2142F'

Position of the actor center, specified as the comma-separated pair consisting of 'Position' and an [x y z] real-valued vector.

The center of the actor is [L/2 W/2 b], where:

  • L/2 is the midpoint of actor length L.

  • W/2 is the midpoint of actor width W.

  • b is the bottom of the cuboid.

Units are in meters.

Example: [10;50;0]

Velocity (v) of the actor center in the x-, y- and z-directions, specified as the comma-separated pair consisting of 'Velocity' and a [vx vy vz] real-valued vector. The 'Position' name-value pair specifies the actor center. Units are in meters per second.

Example: [-4;7;10]

Yaw angle of the actor, specified as the comma-separated pair consisting of 'Yaw' and a real scalar. Yaw is the angle of rotation of the actor around the z-axis. Yaw is clockwise-positive when looking in the forward direction of the axis, which points up from the ground. Therefore, when viewing actors from the top down, such as on a bird's-eye plot, yaw is counterclockwise-positive. Angle values are wrapped to the range [–180, 180]. Units are in degrees.

Example: -0.4

Pitch angle of the actor, specified as the comma-separated pair consisting of 'Pitch' and a real scalar. Pitch is the angle of rotation of the actor around the y-axis and is clockwise-positive when looking in the forward direction of the axis. Angle values are wrapped to the range [–180, 180]. Units are in degrees.

Example: 5.8

Roll angle of the actor, specified as the comma-separated pair consisting of 'Roll' and a real scalar. Roll is the angle of rotation of the actor around the x-axis and is clockwise-positive when looking in the forward direction of the axis. Angle values are wrapped to the range [–180, 180]. Units are in degrees.

Example: -10

Angular velocity (ω) of the actor, in world coordinates, specified as the comma-separated pair consisting of 'AngularVelocity' and a [ωx ωy ωz] real-valued vector. Units are in degrees per second.

Example: [20 40 20]

Length of the actor, specified as the comma-separated pair consisting of 'Length' and a positive real scalar. Units are in meters.

Example: 5.5

Width of the actor, specified as the comma-separated pair consisting of 'Width' and a positive real scalar. Units are in meters.

Example: 3.0

Height of the actor, specified as the comma-separated pair consisting of 'Height' and a positive real scalar. Units are meters.

Example: 2.1

Extended object mesh, specified as an extendedObjectMesh object.

Radar cross-section (RCS) pattern of actor, specified as the comma-separated pair consisting of 'RCSPattern' and a Q-by-P real-valued matrix. RCS is a function of the azimuth and elevation angles, where:

  • Q is the number of elevation angles specified by the 'RCSElevationAngles' name-value pair.

  • P is the number of azimuth angles specified by the 'RCSAzimuthAngles' name-value pair.

Units are in decibels per square meter (dBsm).

Example: 5.8

Azimuth angles of the actor's RCS pattern, specified as the comma-separated pair consisting of 'RCSAzimuthAngles' and a P-element real-valued vector. P is the number of azimuth angles. Values are in the range [–180°, 180°].

Each element of RCSAzimuthAngles defines the azimuth angle of the corresponding column of the 'RCSPattern' name-value pair. Units are in degrees.

Example: [-90:90]

Elevation angles of the actor's RCS pattern, specified as the comma-separated pair consisting of 'RCSElevationAngles' and a Q-element real-valued vector. Q is the number of elevation angles. Values are in the range [–90°, 90°].

Each element of RCSElevationAngles defines the elevation angle of the corresponding row of the RCSPattern property. Units are in degrees.

Example: [0:90]

Output Arguments

collapse all

Driving scenario actor, returned as an Actor object belonging to the driving scenario specified by scenario.

You can modify the Actor object by changing its property values. The property names correspond to the name-value pair arguments used to create the object. The only property that you cannot modify is ActorID, which is a positive integer indicating the unique, scenario-defined ID of the actor.

To specify or visualize actor motion, use these functions:

trajectory

Create actor or vehicle trajectory in driving scenario

chasePlot

Ego-centric projective perspective plot

To get information about actor characteristics, use these functions:

actorPoses

Positions, velocities, and orientations of actors in driving scenario

actorProfiles

Physical and radar characteristics of actors in driving scenario

targetOutlines

Outlines of targets viewed by actor

targetPoses

Target positions and orientations relative to ego vehicle

driving.scenario.targetsToEgo

Convert actor poses to ego vehicle coordinates

driving.scenario.targetsToScenario

Convert target actor poses from ego vehicle coordinates to world coordinates of scenario

To get information about the roads and lanes that the actor is on, use these functions:

roadBoundaries

Get road boundaries

driving.scenario.roadBoundariesToEgo

Convert road boundaries to ego vehicle coordinates

currentLane

Get current lane of actor

laneBoundaries

Get lane boundaries of actor lane

laneMarkingVertices

Lane marking vertices and faces in driving scenario

roadMesh

Mesh representation of an actor's nearest roads in driving scenario.

More About

collapse all

Actor and Vehicle Positions and Dimensions

In driving scenarios, an actor is a cuboid (box-shaped) object with a specific length, width, and height. Actors also have a radar cross-section (RCS) pattern, specified in dBsm, which you can refine by setting angular azimuth and elevation coordinates. The position of an actor is defined as the center of its bottom face. This center point is used as the actor's rotational center, its point of contact with the ground, and its origin in its local coordinate system. In this coordinate system:

  • The X-axis points forward from the actor.

  • The Y-axis points left from the actor.

  • The Z-axis points up from the ground.

Roll, pitch, and yaw are clockwise-positive when looking in the forward direction of the X-, Y-, and Z-axes, respectively.

A vehicle is an actor that moves on wheels. Vehicles have three extra properties that govern the placement of their front and rear axle.

  • Wheelbase — Distance between the front and rear axles

  • Front overhang — Distance between the front of the vehicle and the front axle

  • Rear overhang — Distance between the rear axle and the rear of the vehicle

Unlike other types of actors, the position of a vehicle is defined by the point on the ground that is below the center of its rear axle. This point corresponds to the natural center of rotation of the vehicle. As with nonvehicle actors, this point is the origin in the local coordinate system of the vehicle, where:

  • The X-axis points forward from the vehicle.

  • The Y-axis points left from the vehicle.

  • The Z-axis points up from the ground.

Roll, pitch, and yaw are clockwise-positive when looking in the forward direction of the X-, Y-, and Z-axes, respectively.

This table shows a list of common actors and their dimensions. To specify these values in Actor and Vehicle objects, set the corresponding properties shown.

Actor ClassificationActor ObjectActor Properties
LengthWidthHeightFrontOverhangRearOverhangWheelbaseRCSPattern
PedestrianActor0.24 m0.45 m1.7 mN/AN/AN/A–8 dBsm
CarVehicle4.7 m1.8 m1.4 m0.9 m1.0 m2.8 m10 dBsm
MotorcycleVehicle2.2 m0.6 m1.5 m0.37 m0.32 m1.51 m0 dBsm

Introduced in R2017a