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
creates lane specifications for a road having lnspec
= lanespec(numlanes
)numlanes
lanes. numLanes
sets the NumLanes
property of the lanespec
object. The order for numbering the lanes on a road depend on the orientation of
the road. For more details, see Draw Direction of Road and Numbering of Lanes.
sets properties using one or more name-value pairs. For example,
lnspec
= lanespec(numlanes
,Name,Value
)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. For more information on the geometrical properties of a lane, see
Lane Specifications.
Properties
NumLanes
— Number of lanes in road
positive integer | two-element vector of positive integers
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.
Width
— Lane widths
3.6
(default) | positive real scalar | 1-by-N vector of positive real scalars
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
Marking
— Lane markings
LaneMarking
object (default) | SolidMarking
object | DashedMarking
object | CompoundMarking
object | 1-by-M array of lane marking objects
Lane markings of road, specified as one of these values:
LaneMarking
object. This is the default.SolidMarking
objectDashedMarking
objectCompoundMarking
object1-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.
Type
— Lane types
DrivingLaneType
object (default) | RestrictedLaneType
object | ShoulderLaneType
object | ParkingLaneType
object | 1-by-M array of lane type objects
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
Create Straight Four-Lane Road
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 Car Traveling on S-Curve
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 waypoints. By default, the car travels at a speed of 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]; smoothTrajectory(car,waypoints);
Plot the scenario and corresponding chase plot.
plot(scenario)
chasePlot(car)
Run the simulation loop.
Initialize a bird's-eye plot and create an outline plotter, left-lane and right-lane boundary plotters, and a road boundary plotter.
Obtain the road boundaries and rectangular outlines.
Obtain the lane boundaries to the left and right of the vehicle.
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.
More About
Draw Direction of Road and Numbering of Lanes
To create a road by using the road
function, specify the road centers as a
matrix input. The function creates a directed line that traverses the road centers, starting
from the coordinates in the first row of the matrix and ending at the coordinates in the last
row of the matrix. The coordinates in the first two rows of the matrix specify the
draw direction of the road. These coordinates correspond to the first
two consecutive road centers. The draw direction is the direction in which the roads render in
the scenario plot.
To create a road by using the Driving Scenario Designer app, you can either specify the Road Centers parameter or interactively draw on the Scenario Canvas. For a detailed example, see Create a Driving Scenario. In this case, the draw direction is the direction in which roads render in the Scenario Canvas.
For a road with a top-to-bottom draw direction, the difference between the x-coordinates of the first two consecutive road centers is positive.
For a road with a bottom-to-top draw direction, the difference between the x-coordinates of the first two consecutive road centers is negative.
|
|
For a road with a left-to-right draw direction, the difference between the y-coordinates of the first two consecutive road centers is positive.
For a road with a right-to-left draw direction, the difference between the y-coordinates of the first two consecutive road centers is negative.
|
|
Lanes must be numbered from left to right, with the left edge of the road defined relative to the draw direction of the road. For a one-way road, by default, the left edge of the road is a solid yellow marking which indicates the end of the road in transverse direction (direction perpendicular to draw direction). For a two-way road, by default, both edges are marked with solid white lines.
For example, these diagrams show how the lanes are numbered in a one-way and two-way road with a draw direction from top-to-bottom.
Numbering Lanes in a One-Way Road | Numbering Lanes in a Two-Way Road |
Specify the number of lanes as a positive integer for a one-way road. If
you set the integer value as 1, 2, 3 denote the first, second, and third lanes of the road, respectively. | Specify the number of lanes as a two-element vector of positive integer
for a two-way road. If you set the vector as [ 1L denote the only left lane of the road. 1R and 2R denote the first and second right lanes of the road, respectively. |
The lane specifications apply by the order in which the lanes are numbered.
Lane Specifications
The diagram shows the components and geometric properties of roads, lanes, and lane markings.
The lane specification object, lanespec
, defines the road lanes.
The
NumLanes
property specifies the number of lanes. You must specify the number of lanes when you create this object.The
Width
property specifies the width of each lane.The
Marking
property contains the specifications of each lane marking in the road.Marking
is an array of lane marking objects, with one object per lane. To create these objects, use thelaneMarking
function. Lane marking specifications include:Type
— Type of lane marking (solid, dashed, and so on)Width
— Lane marking widthColor
— Lane marking colorStrength
— Saturation value for lane marking colorLength
— For dashed lanes, the length of each dashed lineSpace
— For dashed lanes, the spacing between dashesSegmentRange
— For composite lane marking, the normalized length of each marker segment
The
Type
property contains the lane type specifications of each lane in the road.Type
can be a homogeneous lane type object or a heterogeneous lane type array.Homogeneous lane type object contains the lane type specifications of all the lanes in the road.
Heterogeneous lane type array contains an array of lane type objects, with one object per lane.
To create these objects, use the
laneType
function. Lane type specifications include:Type
— Type of lane (driving, border, and so on)Color
— Lane colorStrength
— Strength of the lane color
Version History
Introduced in R2018a
See Also
Objects
Functions
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)