lanespec

Create road lane specifications

Description

The lanespec object defines the lane specifications of a road that was added to a drivingScenario object using the road function. For more details, see Lane Specifications.

Creation

Description

lnspec = lanespec(numlanes) creates lane specifications for a road having numlanes lanes. numLanes sets the NumLanes property of the lanespec object.

example

lnspec = lanespec(numlanes,Name,Value) sets properties using one or more name-value pairs. For example, lanespec(3,'Width',[2.25 3.5 2.25]) specifies a three-lane road with widths from left to right of 2.25 meters, 3.5 meters, and 2.25 meters.

Properties

expand all

This property is read-only.

Number of lanes in the road, specified as a positive integer or two-element vector of positive integers, [NL, NR]. When NumLanes is a positive integer, all lanes flow in the same direction. When NumLanes is a vector:

  • NL is the number of left lanes, all flowing in one direction.

  • NR is the number of right lanes, all flowing in the opposite direction.

The total number of lanes in the road is the sum of these vector values: N = NL + NR.

You can set this property when you create the object. After you create the object, this property is read-only.

Example: [2 2] specifies two left lanes and two right lanes.

Lane widths, specified as a positive real scalar or 1-by-N vector of positive real scalars, where N is the number of lanes in the road. N must be equal to numlanes and the corresponding value set in the NumLanes property.

When Width is a scalar, the same value is applied to all lanes. When Width is a vector, the vector elements apply to lanes from left to right. Units are in meters.

Example: [3.5 3.7 3.7 3.5]

Data Types: double

Lane markings of road, specified as a lane marking object or a 1-by-M array of lane marking objects. M is the number of lane markings. For a road with N lanes, M = N + 1.

To create lane marking objects, use the laneMarking function and specify the type of lane marking.

'Unmarked' 'Solid''Dashed''DoubleSolid''DoubleDashed''SolidDashed''DashedSolid'

No lane marking

Solid line

Dashed line

Two solid lines

Two dashed lines

Solid line on left, dashed line on right

Dashed line on left, solid line on right

By default, for a one-way road, the rightmost and center lane markings are white and the leftmost lane marking is yellow. For two-way roads, the color of the dividing lane marking is yellow.

Example: [laneMarking('Solid') laneMarking('DoubleDashed') laneMarking('Solid')] specifies lane markings for a two-lane road. The leftmost and rightmost lane markings are solid lines, and the dividing lane marking is a double-dashed line.

Lane types of road, specified as a homogeneous lane type object or a 1-by-M array of lane type objects. M is the number of lane types.

To create lane type objects, use the laneType function and specify the type of lane.

'Driving''Border''Restricted''Shoulder''Parking'

Example: [laneType('Shoulder') laneType('Driving')] specifies the lane types for a two-lane road. The leftmost lane is the shoulder lane and the rightmost lane is the driving lane.

Examples

collapse all

Create a driving scenario and the road centers for a straight, 80-meter road.

scenario = drivingScenario;
roadCenters = [0 0; 80 0];

Create a lanespec object for a four-lane road. Use the laneMarking function to specify its five lane markings. The center line is double-solid and double yellow. The outermost lines are solid and white. The inner lines are dashed and white.

solidW = laneMarking('Solid','Width',0.3);
dashW = laneMarking('Dashed','Space',5);
doubleY = laneMarking('DoubleSolid','Color','yellow');
lspec = lanespec([2 2],'Width',[5 5 5 5], ...
    'Marking',[solidW dashW doubleY dashW solidW]);

Add the road to the driving scenario. Display the road.

road(scenario,roadCenters,'Lanes',lspec);
plot(scenario)

Simulate a driving scenario with one car traveling on an S-curve. Create and plot the lane boundaries.

Create the driving scenario with one road having an S-curve.

scenario = drivingScenario('StopTime',3);
roadcenters = [-35 20 0; -20 -20 0; 0 0 0; 20 20 0; 35 -20 0];

Create the lanes and add them to the road.

lm = [laneMarking('Solid','Color','w'); ...
    laneMarking('Dashed','Color','y'); ...
    laneMarking('Dashed','Color','y'); ...
    laneMarking('Solid','Color','w')];
ls = lanespec(3,'Marking',lm);
road(scenario,roadcenters,'Lanes',ls);

Add an ego vehicle and specify its trajectory from its speed and waypoints. The car travels at 30 meters per second.

car = vehicle(scenario, ...
    'ClassID',1, ...
    'Position',[-35 20 0]);
waypoints = [-35 20 0; -20 -20 0; 0 0 0; 20 20 0; 35 -20 0];
speed = 30;
trajectory(car,waypoints,speed);

Plot the scenario and corresponding chase plot.

plot(scenario)

chasePlot(car)

Run the simulation loop.

  1. Initialize a bird's-eye plot and create an outline plotter, left-lane and right-lane boundary plotters, and a road boundary plotter.

  2. Obtain the road boundaries and rectangular outlines.

  3. Obtain the lane boundaries to the left and right of the vehicle.

  4. Advance the simulation and update the plotters.

bep = birdsEyePlot('XLim',[-40 40],'YLim',[-30 30]);
olPlotter = outlinePlotter(bep);
lblPlotter = laneBoundaryPlotter(bep,'Color','r','LineStyle','-');
lbrPlotter = laneBoundaryPlotter(bep,'Color','g','LineStyle','-');
rbsEdgePlotter = laneBoundaryPlotter(bep);
legend('off');
while advance(scenario)
    rbs = roadBoundaries(car);
    [position,yaw,length,width,originOffset,color] = targetOutlines(car);
    lb = laneBoundaries(car,'XDistance',0:5:30,'LocationType','Center', ...
        'AllBoundaries',false);
    plotLaneBoundary(rbsEdgePlotter,rbs)
    plotLaneBoundary(lblPlotter,{lb(1).Coordinates})
    plotLaneBoundary(lbrPlotter,{lb(2).Coordinates})
    plotOutline(olPlotter,position,yaw,length,width, ...
        'OriginOffset',originOffset,'Color',color)
end

Limitations

  • Lane markings in intersections are not supported.

  • The number of lanes for a road is fixed. You cannot change lane specifications for a road during a simulation.

  • A road can have only one lane specification.

More About

expand all

Introduced in R2018a