Main Content

compositeLaneSpec

Create multiple lane specifications for road

Since R2021a

Description

The compositeLaneSpec object combines an array of lanespec objects to create a road with multiple road segments that have different lane specifications.

Creation

To define composite lane specifications, follow these steps:

  1. Create an array of lanespec objects. The number of lanespec objects defines the number of road segments in a road. Each lanespec object contains the lane specifications for one road segment.

  2. Create a composite lane specification object, compositeLaneSpec, to combine the lane specifications, using one of the syntaxes shown here. By default, the function assumes each road segment is of equal range.

  3. To vary the range for each road segment, use the SegmentRange property of the compositeLaneSpec object.

  4. To define the connection between two road segments, use the Connector property of the compositeLanespec object.

  5. Add the compositeLaneSpec object to the driving scenario using the road function.

Description

clspec = compositeLaneSpec(lsArray) creates a composite lane specification for a road using an array of lane specification objects, lsArray.

For example, create a composite lane specification object, compositeLaneSpec, to combine the lane specifications of two road segments with two and three lanes, respectively.

lsArray = [lanespec(2) lanespec(3)];
clspec = compositeLaneSpec(lsArray);
The order for numbering the lanes and segments of a road depends on the orientation of the road. For more details, see Draw Direction of Road and Numbering of Lanes and Composite Lane Specification.

example

clspec = compositeLaneSpec(lsArray,Name,Value) sets properties using one or more name-value arguments. For example, 'SegmentRange',[0.6 0.4] specifies that the normalized ranges of two road segments are 0.6 and 0.4, respectively.

example

Properties

expand all

This property is read-only.

Lane specifications of road segments, specified as a 1-by-N array of lanespec objects. N is the number of lane specifications. You must specify at least two lanespec objects to create a road with multiple lane specifications. Each lanespec object represents a distinct road segment. As such, the number of lanespec objects defines the number of road segments in a road.

You must set this property using the lsArray input argument when you create the object. To create lane specification objects, use the lanespec function.

Example: [lanespec(2) lanespec(3)] defines the lane specifications for a road with two segments. The first road segment has two lanes and the second segment has three lanes.

Range of each road segment, specified as an N-element numeric vector with normalized values in the range (0, 1). N is the number of lanespec objects in the LaneSpecification property. The sum of the elements of the vector must be equal to 1.

The default range value of each road segment is 1/N. For example, if the LaneSpecification property defines the lane specifications for two road segments, then the default range value for each road segment is 1/2, meaning that SegmentRange = [0.5 0.5].

Example: [0.4 0.3 0.3]

Data Types: single | double

Road segment connectors, specified as a laneSpecConnector object or 1-by-M array of laneSpecConnector objects. M is the number of road segment connectors. For a road with N segments, M = N – 1. When specified as only one object, the same specifications apply to all M connectors of the road.

The laneSpecConnector object specifies these properties for connecting a pair of road segments. You can specify the properties to the laneSpecConnector creation function as name-value arguments.

  • TaperShape — Specifies the shape of a taper connecting two road segments as either 'Linear' or 'None'. Specify 'None' when you want a step change while adding or dropping lanes between road segments. The default value of TaperShape is 'Linear'.

  • TaperLength — Specifies the length of a taper in meters. The default value of TaperLength is the smaller of 241 meters or 75 percent of the length of the road segment containing the taper.

  • Position — Specifies the edge of the road from which to add or drop lanes. You can specify the connector position as 'Right', 'Left', or 'Both'.

Example: [laneSpecConnector('Position','Left') laneSpecConnector('TaperLength',20)]

Note

  • The taper is part of the lower numbered road segment within the pair. For more information about the order for numbering the road segments, see Composite Lane Specification.

  • Road segment connector specifications must conform with lane specifications and segment range values. Otherwise, the function resets the connector specifications with valid values. For example, if you specify a TaperLength larger than the length of the corresponding road segment, the function resets the taper length with a value that is 75 percent of the length of the corresponding road segment.

Examples

collapse all

Create a driving scenario with merging traffic. The road in the driving scenario has two lane specifications and the traffic merges to the left as the right lane ends.

Create Road with Two Lane Specifications

Create a driving scenario. Specify the road centers with draw directions from bottom-to-top.

scenario = drivingScenario('StopTime',5);
roadCenters = [0 20; 100 20];

Define the lane specifications for a pair of two-way road segments. The first road segment has five lanes and the second road segment has four lanes. Notice that the rightmost lane drops from the second lane specification.

ls1 = lanespec([2 3],'Width',4);
ls2 = lanespec([2 2],'Width',4);
lsArray = [ls1 ls2];

Create a composite lane specification object and add the road to the driving scenario. The composite lane specification object determines the position at which the lane drops from the lsArray input argument. The object defaults to the linear taper shape and a taper length of 75% of the length of the first road segment.

clspec = compositeLaneSpec(lsArray);
road(scenario,roadCenters,'Lanes',clspec);

Plot the driving scenario. The scenario renders the road segments in the draw direction of the road, from bottom-to-top.

figMark = figure;
set(figMark,'Position',[0 0 600 600])
hPlot = axes(figMark);
plot(scenario,'Parent',hPlot)
title('Two-way Road Dropping Rightmost Lane')

Figure contains an axes object. The axes object with title Two-way Road Dropping Rightmost Lane, xlabel X (m), ylabel Y (m) contains 3 objects of type patch, line.

Simulate Vehicle Lane Change

Add an ego vehicle to the scenario. Specify waypoints and a constant speed value to set its trajectory along the middle forward lane.

egoVehicle = vehicle(scenario,'ClassID',1,'Position',[2 16 0]);
waypoints = [2 16; 20 16; 95 16];
speed = 30;
smoothTrajectory(egoVehicle,waypoints,speed)

Add another vehicle to the scenario. Set the trajectory for the vehicle such that it travels in the rightmost lane and then merges to the left before the lane ends.

car = vehicle(scenario,'ClassID',1,'Position',[2 12 0]);
waypoints = [2 12; 12 12; 30 14; 42 16; 58 16; 85 16];
speed = 20;
smoothTrajectory(car,waypoints,speed)

Create a custom figure window and plot the scenario.

close all
figScene = figure;
set(figScene,'Position',[0 0 600 600])
hPanel = uipanel(figScene);
hPlot = axes(hPanel);
plot(scenario,'Waypoints','on','Parent',hPlot)
title('Merge Left as Right Lane Ends')

while advance(scenario)
    pause(0.01)
end

Figure contains an axes object and an object of type uipanel. The axes object with title Merge Left as Right Lane Ends, xlabel X (m), ylabel Y (m) contains 9 objects of type patch, line. One or more of the lines displays its values using only markers

Create a road with multiple lane specifications and add one lane to the left of a one-way road.

Create a driving scenario. Specify the road centers for a straight, 100-meter road with draw direction from left-to-right.

scenario = drivingScenario;
roadCenters = [20 100; 20 0];

Define an array of lane specifications for two one-way road segments. The first road segment has two lanes and the second road segment has three lanes.

lsArray = [lanespec(2) lanespec(3)];

Define a road segment connector object. To add the third lane to the left side of the second road segment, specify the position property. Specify a taper length less than the length of the first road segment. Both the road segments are 50 meters long since, by default, the total road length of 100 meters is divided equally between the specified road segments.

lc = laneSpecConnector('Position','Left','TaperLength',30);

Create a composite lane specification object.

clspec = compositeLaneSpec(lsArray,'Connector',lc);

Add a road to the driving scenario and display the road. The scenario renders the road segments in the draw direction of the road, from left-to-right.

road(scenario,roadCenters,'Lanes',clspec);
plot(scenario)
title('Road with Multiple Lane Specifications')

Figure contains an axes object. The axes object with title Road with Multiple Lane Specifications, xlabel X (m), ylabel Y (m) contains 3 objects of type patch, line.

Create an empty driving scenario. Specify the road centers for a curved road.

scenario = drivingScenario;
roadCenters = [-20 22; 0 22; 18.8 15.8; 22 0; 22 -20];

Define the lane specifications for three two-way road segments. Notice that all the road segments have the same number of lanes. However, the second road segment has a greater lane width (4.6 meters) to widen the road along the curve. The other two road segments have the default lane width of 3.6 meters.

lsArray = [lanespec([1 1]) lanespec([1 1],'Width',4.6) lanespec([1 1])];

Define normalized lengths for each road segment. Notice that the sum of normalized lengths is 1, and the length of the vector matches the number of lane specification objects.

range = [0.25 0.65 0.1];

Create a road segment connector object. Since the same specifications apply to both segment connectors for the three road segments, create only one laneSpecConnector object. Since you are neither adding nor dropping lanes, do not define the position property of the road segment connector.

lc = laneSpecConnector('TaperLength',14);

Create a composite lane specification object and add the road to the driving scenario.

clspec = compositeLaneSpec(lsArray,'Connector',lc,'SegmentRange',range);
road(scenario,roadCenters,'Lanes',clspec);

Plot the driving scenario.

plot(scenario,'RoadCenters','on')
title('Lane Widening Along a Curve')

Figure contains an axes object. The axes object with title Lane Widening Along a Curve, xlabel X (m), ylabel Y (m) contains 4 objects of type patch, line. One or more of the lines displays its values using only markers

Limitations

  • Lane marking spacing is not consistent during transitions from one road segment to another.

More About

expand all

Version History

Introduced in R2021a