Main Content

barrier

Add a barrier to a driving scenario

Since R2021a

Description

barrier(scenario,rd) adds a barrier along the entire length of the road object rd. By default, the barrier is placed along the right edge and each segment lies on the surface of road.

example

barrier(scenario,rd,'RoadEdge','left') adds a barrier along the left edge of the road object rd.

example

barrier(scenario,barrierCenters) adds a barrier along a piecewise, clothoid curve that smoothly connects the specified barrier centers. This approach is useful when adding barriers to edges of roads that intersect or overlap.

example

barrier(scenario,barrierCenters,bankAngle) specifies the angle by which the barrier tilts when traversing the barrier centers.

barrier(___,Name,Value) sets barrier properties using one or more name-value pair arguments, in addition to any combination of input arguments from previous syntaxes.

Barriers are composed of individual elements called barrier segments. Use name-value pair arguments such as 'SegmentLength', 'SegmentGap', 'Width' and 'Height' to tune the properties of individual barrier segments. Jersey barriers and guardrails are the two types of barriers that you can add to a scenario. Specify the appropriate 'Mesh' and 'ClassID' arguments to represent the barrier as a guardrail or a jersey barrier.

example

Examples

collapse all

Create a driving scenario and add a curved road.

scenario = drivingScenario;
roadCenters = [-14.1 -4.3; 9 -10; 37 -8; 60 3.9; 81.2 29.4; 83.4 57.9];
road1 = road(scenario,roadCenters);

Add a barrier along the right edge of the road.

barrier(scenario,road1)

Add another barrier along the left edge of the road with a lateral offset of 1 m from the edge. Specify a gap of 1 m between individual barrier segments.

barrier(scenario,road1,'RoadEdge',"left",'SegmentGap',1,'RoadEdgeOffset',1)

Plot the scenario.

plot(scenario)

Figure contains an axes object. The axes object with xlabel X (m), ylabel Y (m) contains 4 objects of type patch, line.

Create a driving scenario and add a straight road.

scenario2 = drivingScenario;
roadCenters = [0 0; 20 0];
rr = road(scenario2,roadCenters);

Specify appropriate barrier centers and add a barrier on the road, covering the entire width of the road.

barrierCenters = [20 3; 20 0; 20 -3];
barrier(scenario2,barrierCenters,'SegmentGap',0.2)

Add two barriers on the road, each covering half the width of the road.

barrierCenters1 = [12 3; 12 0];
barrierCenters2 = [6 -3; 6 0];
barrier(scenario2,barrierCenters1,'SegmentGap',0.2)
barrier(scenario2,barrierCenters2,'SegmentGap',0.2)

Plot the scenario.

plot(scenario2)

Figure contains an axes object. The axes object with xlabel X (m), ylabel Y (m) contains 5 objects of type patch, line.

Input Arguments

collapse all

Driving scenario, specified as a drivingScenario object.

Road to add a barrier along, specified as a road object.

Barrier center coordinates, specified as an N-by-3 or N-by-2 matrix.

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

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

The function connects the coordinates along a smooth, piecewise, clothoid curve, and adds a barrier with the curve as its center line. Units are in meters.

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

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'RoadEdge','left' adds a barrier along the left edge of the road.

Edge of the road along which to place a barrier, specified as the comma-separated pair consisting of 'RoadEdge' and 'right' or 'left'. Use 'RoadEdge' only when you specify a road object to add a barrier along.

Lateral offset from road edge, specified as the comma-separated pair consisting of 'RoadEdgeOffset' and a scalar or real-valued N-by-1 vector. N is the number of barrier centers. A positive offset value moves the barrier away from the road and a negative offset value moves the barrier into the road. Units are in meters. 'RoadEdgeOffset' is valid only when you specify a road object and 'RoadEdge' argument.

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

Distance between consecutive barrier segments, specified as the comma-separated pair consisting of 'SegmentGap' and a positive real scalar. Units are in meters.

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

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

Mesh representation of the barrier, specified as the comma-separated pair consisting of 'Mesh' and a valid extendedObjectMesh object. The available meshes for barrier are driving.scenario.jerseyBarrierMesh, representing a Jersey barrier and driving.scenario.guardrailMesh, representing a guardrail. The lidarPointCloudGenerator system object uses this mesh to generate detections.

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

The barrier 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 barrier appears in this color in all app visualizations. If you import the scenario into Simulink®, then the barrier appears in this color in the Bird's-Eye Scope.

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 string scalar or character vector 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. Therefore, 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"

Sample of the color red

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

Sample of the color green

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

Sample of the color blue

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

Sample of the color cyan

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

Sample of the color magenta

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

Sample of the color yellow

"black""k"[0 0 0]"#000000"

Sample of the color black

"white""w"[1 1 1]"#FFFFFF"

Sample of the color white

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"

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980]"#D95319"

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

[0.9290 0.6940 0.1250]"#EDB120"

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

[0.4940 0.1840 0.5560]"#7E2F8E"

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

[0.4660 0.6740 0.1880]"#77AC30"

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

[0.3010 0.7450 0.9330]"#4DBEEE"

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840]"#A2142F"

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

Radar cross-section (RCS) pattern of the barrier, specified as the comma-separated pair consisting of 'RCSPattern' and a Q-by-P real-valued matrix. The 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 argument.

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

Units are in decibels per square meter (dBsm).

Example: 5.8

Azimuth angles of RCS pattern of barrier, 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 argument. Units are in degrees.

Example: [-90:90]

Elevation angles of RCS pattern of barrier, 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' name-value pair argument. Units are in degrees.

Example: [0:90]

Classification identifier of the barrier, specified as the comma-separated pair consisting of 'ClassID' and a nonnegative integer value of 5 or 6. The values 5 and 6 correspond to Jersey barriers and guardrails, respectively. Specify the appropriate Class ID for each barrier before importing the scenario into the Driving Scenario Designer app. For more information about the Class ID values for different actors, refer to the description of the 'ClassID' name-value pair argument.

Limitations

  • Road networks added using the roadNetwork function do not support barriers.

Tips

  • For faster simulations, specify the input argument range for the targetPoses function in the scenario advance loop.

Version History

Introduced in R2021a