road

Add road to driving scenario

Description

example

road(scenario,roadcenters) adds a road to a driving scenario, scenario. You specify the road shape using a set of road centers, roadcenters, at discrete points.

road(scenario,roadcenters,roadwidth) adds a road with the specified width, roadwidth.

example

road(scenario,roadcenters,roadwidth,bankingangle) adds a road with the specified width and banking angle, bankingangle.

example

road(scenario,roadcenters,'Lanes',lspec) adds a road with the specified lanes, lspec.

road(scenario,roadcenters,bankingangle,'Lanes',lspec) adds a road with the specified banking angle and lanes.

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)
roadcenters = [400 400 0; 0 0 0];
road(scenario,roadcenters)

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,'Position',[700 0 0],'Length',3,'Width',2,'Height',1.6);

Position the bicycle farther down the road.

bicycle = actor(scenario,'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×7 struct
    ActorID
    Position
    Velocity
    Roll
    Pitch
    Yaw
    AngularVelocity

profiles = actorProfiles(scenario)
profiles=2×9 struct
    ActorID
    ClassID
    Length
    Width
    Height
    OriginOffset
    RCSPattern
    RCSAzimuthAngles
    RCSElevationAngles

Create a driving scenario containing a figure-8 road specified in the world coordinates of the scenario. Convert the world coordinates of the scenario to the coordinate system of the ego vehicle.

Create an empty driving scenario.

scenario = drivingScenario;

Add a figure-8 road to the scenario. Display the scenario.

roadCenters = [0  0  1
             20 -20  1
             20  20  1
            -20 -20  1
            -20  20  1
              0   0  1];

roadWidth = 3;
bankAngle = [0 15 15 -15 -15 0];
road(scenario,roadCenters,roadWidth,bankAngle);
plot(scenario)

Add an ego vehicle to the scenario. Position the vehicle at world coordinates (20, –20) and orient it at a –15 degree yaw angle.

ego = actor(scenario,'Position',[20 -20 0],'Yaw',-15);

Obtain the road boundaries in ego vehicle coordinates by using the roadBoundaries function. Specify the ego vehicle as the input argument.

rbEgo1 = roadBoundaries(ego);

Display the result on a bird's-eye plot.

bep = birdsEyePlot;
lbp = laneBoundaryPlotter(bep,'DisplayName','Road');
plotLaneBoundary(lbp,rbEgo1)

Obtain the road boundaries in world coordinates by using the roadBoundaries function. Specify the scenario as the input argument.

rbScenario = roadBoundaries(scenario);

Obtain the road boundaries in ego vehicle coordinates by using the driving.scenario.roadBoundariesToEgo function.

rbEgo2 = driving.scenario.roadBoundariesToEgo(rbScenario,ego);

Display the road boundaries on a bird's-eye plot.

bep = birdsEyePlot;
lbp = laneBoundaryPlotter(bep,'DisplayName','Road boundaries');
plotLaneBoundary(lbp,{rbEgo2})

Create a driving scenario containing a car and pedestrian on a straight road. Then, create and display the lane markings of the road on a bird's-eye plot.

Create an empty driving scenario.

scenario = drivingScenario;

Create a straight, 25-meter road segment with two travel lanes in one direction.

lm = [laneMarking('Solid')
      laneMarking('Dashed','Length',2,'Space',4)
      laneMarking('Solid')];
l = lanespec(2,'Marking',lm);
road(scenario,[0 0 0; 25 0 0],'Lanes',l);

Add to the driving scenario a pedestrian crossing the road at 1 meter per second and a car following the road at 10 meters per second.

ped = actor(scenario,'Length',0.2,'Width',0.4,'Height',1.7);
car = vehicle(scenario);
trajectory(ped,[15 -3 0; 15 3 0],1);
trajectory(car,[car.RearOverhang 0 0; 25-car.Length+car.RearOverhang 0 0],10);

Display the scenario and corresponding chase plot.

plot(scenario)

chasePlot(car)

Run the simulation.

  1. Create a bird's-eye plot.

  2. Create an outline plotter, lane boundary plotter, and lane marking plotter for the bird's-eye plot.

  3. Obtain the road boundaries and target outlines.

  4. Obtain the lane marking vertices and faces.

  5. Display the lane boundaries and lane markers.

  6. Run the simulation loop.

bep = birdsEyePlot('XLim',[-25 25],'YLim',[-10 10]);
olPlotter = outlinePlotter(bep);
lbPlotter = laneBoundaryPlotter(bep);
lmPlotter = laneMarkingPlotter(bep,'DisplayName','Lanes');
legend('off');
while advance(scenario)
    rb = roadBoundaries(car);
    [position,yaw,length,width,originOffset,color] = targetOutlines(car);
    [lmv,lmf] = laneMarkingVertices(car);
    plotLaneBoundary(lbPlotter,rb);
    plotLaneMarking(lmPlotter,lmv,lmf);
    plotOutline(olPlotter,position,yaw,length,width, ...
        'OriginOffset',originOffset,'Color',color);
end

Input Arguments

collapse all

Driving scenario, specified as a drivingScenario object.

Road centers used to define a road, specified as a real-valued N-by-2 or N-by-3 matrix. Road centers determine the center line of the road at discrete points.

  • If roadcenters is an N-by-2 matrix, then each matrix row represents the (x, y) coordinates of a road center. The z-coordinate of each road center is zero.

  • If roadcenters is an N-by-3 matrix, then each matrix row represents the (x, y, z) coordinates of a road center.

If the first row of the matrix is the same as the last row, the road is a loop. Units are in meters.

Data Types: double

Width of road, specified as a positive real scalar. The width is constant along the entire road. Units are in meters.

To specify the bankingangle input but not roadwidth, specify roadwidth as an empty argument, [].

If you specify roadwidth, then you cannot specify the lspec input.

Data Types: double

Banking angle of road, specified as a real-valued N-by-1 vector. N is the number of road centers. The banking angle is the roll angle of the road along the direction of the road. Units are in degrees.

Lane specification, specified as a lanespec object. Use lanespec to specify the number of lanes, the width of each lane, and the type of lane markings. To specify the lane markings within lanespec, use the laneMarking function.

If you specify lspec, then you cannot specify the roadwidth input.

Example: 'Lane',lanespec(3) specifies a three-lane road with default lane widths and lane markings.

Algorithms

The road function creates a road for an actor to follow in a driving scenario. You specify the road using N two-dimensional or three-dimensional waypoints. Each of the N – 1 segments between waypoints defines a curve whose curvature varies linearly with distance along the segment. The function fits a piecewise clothoid curve to the (x, y) coordinates of the waypoints by matching the curvature on both sides of the waypoint. For a nonclosed curve, the curvature at the first and last waypoint is zero. If the first and last waypoints coincide, then the curvatures before and after the endpoints are matched. The z-coordinates of the road are interpolated using a shape-preserving piecewise cubic curve.

Introduced in R2017a