9. Road Sections

The road you have created in the Road section sure looks nice but still is rather basic. In this section, you are going to create a more complex world by adding further road sections.

Tip

You can create and render the following road sections yourself by creating a custom road simulation/models/env_db/example_road.py:

from simulation.utils.road.road import Road
from simulation.utils.road.sections import *

road = Road()

road.append(StraightRoad())  # Replace with other road sections

Then start the simulation:

roslaunch gazebo_simulation master.launch road:=example_road

9.1. StraightRoad

The simulation.utils.road.sections.straight_road.StraightRoad is a straight road. This is an example on how to create a StraightRoad:

1
straight_road = StraightRoad(length=2)

9.2. ParkingArea

../_images/example_parking_area.jpg

The simulation.utils.road.sections.parking_area.ParkingArea is a straight road with parking lots on the left and right side. The arguments left_lots and right_lots each define a list of simulation.utils.road.sections.parking_area.ParkingLot. Each parking lot can contain multiple simulation.utils.road.sections.parking_area.ParkingSpots.

This is an example on how to create a ParkingArea:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
parking_area = ParkingArea(
    length=4,
    start_line=True,
    left_lots=[
        ParkingLot(
            spots=[
                ParkingSpot(kind=ParkingSpot.OCCUPIED, obstacle=ParkingObstacle()),
                ParkingSpot(kind=ParkingSpot.BLOCKED),
            ],
        ),
        ParkingLot(
            start=2,
            opening_angle=math.radians(40),
            spots=[
                ParkingSpot(),
                ParkingSpot(kind=ParkingSpot.OCCUPIED, obstacle=ParkingObstacle()),
            ],
        ),
    ],
    right_lots=[
        ParkingLot(
            start=1,
            depth=0.4,
            spots=[
                ParkingSpot(kind=ParkingSpot.FREE, width=0.5),
                ParkingSpot(
                    kind=ParkingSpot.OCCUPIED, width=0.7, obstacle=ParkingObstacle()
                ),
                ParkingSpot(kind=ParkingSpot.BLOCKED),
            ],
        )
    ],
)

The ParkingArea takes three optional arguments, which are start_line, left_lots, and right_lots. In the example, start_line is set to StartLine(). This creates a StartLine at the beginning of the ParkingArea. If you do not want a StartLine, remove start_line=StartLine(). By default, start_line is None. You can also discover this if you take a closer look at simulation.utils.road.sections.parking_area. If you want to take this one step further, it is also possible to create a ParkingArea without any children; practically a StraightRoad.

The arguments left_lots and right_lots expect a list of ParkingLots. In this example two lots are created on the left and one is on the right side. In the first lot on the left side, two ParkingSpots are placed. As you already know, ParkingSpots can have three different types. The first spot in this example is occupied by a ParkingObstacle, the second is blocked, i.e. it looks like an X.

The second lot on the left looks different. You can also specify a length and an opening_angle for a ParkingLot. Here, the start is set to two meters from the beginning of the ParkingArea. If you do not specify the start argument (like in the first lot) it is set to zero. The opening angle is set to 40 degrees; the default is 60 degrees. For the first spot in this lot, no arguments are given and thus it’s kind is ParkingSpot.FREE and there’s no obstacle placed inside. This is the default behavior for a ParkingSpot.

Caution

Be careful: it is possible to place an obstacle on a free spot. The rendered road will look perfectly fine but it can cause problems in automatic driving tests because on a free spot no obstacle is expected.

Moving to the single lot on the right side, you can see the third optional argument for a ParkingLot. It is called depth and controls the depth (along the y-axis) of a lot. There is no length parameter because the length (along the x-axis) is calculated as the sum of all spots in one lot. To change the size of a spot along the x-axis, simply specify a width parameter. You can not set the depth of a spot because it is derived from the parent lot.

9.3. Intersection

../_images/example_intersection.jpg
1
intersection = Intersection(size=2, turn=Intersection.RIGHT, angle=math.radians(110))

In this example, the crossing roads intersect at a 110-degree angle. The turn parameter indicates in which direction the road continues after the intersection. The possible turn values are RIGHT, LEFT and STRAIGHT, the latter is the default. The default size is 1.8 m and represents the length of each of the crossing roads.

9.4. ZebraCrossing

../_images/example_zebra_crossing.jpg

The zebra crossing spans the entire length of this section. If no length argument is given, it defaults to 0.45 m.

1
zebra_crossing = ZebraCrossing(length=0.5)

9.5. CircularArc

../_images/example_arc.jpg

This section creates a circular arc pointing to the left (LeftCircularArc) and right (RightCircularArc). This means instead of creating an arc with a negative radius to make it turn right the radius is always positive. The two required parametes for an arc are radius and angle.

1
left_arc = LeftCircularArc(radius=2, angle=math.radians(90))

This example creates a circular arc to the left resulting in a 90-degree turn.

9.6. BlockedArea

../_images/example_blocked_area.jpg

The simulation.utils.road.sections.blocked_area.BlockedArea is a straight road, but the car is not allowed to drive on the blocked area which is marked by parallel white lines. By default the section is 1 m in length and the blocked area is 0.2 m wide, starting on the right line. This is an example on how to create a BlockedArea with a length of 1 m and a blocked area which is 0.2 m in width:

1
blocked_area = BlockedArea(length=1, width=0.2)

9.7. TrafficIsland

../_images/example_traffic_island.jpg

The simulation.utils.road.sections.traffic_island.TrafficIsland consists of a visible traffic island in the center of the road and a crosswalk or just dashed lines connecting the island with both sides of the road. B Pedestrians are coming soon! The parameters in the following example are also the default parameters:

1
2
3
4
5
6
7
traffic_island = TrafficIsland(
    island_width=0.3,
    zebra_length=0.45,
    curve_area_length=0.8,
    curvature=0.4,
    zebra_marking_type=TrafficIsland.ZEBRA,
)

9.8. Create Road

While the above introduction to the different road section is not complete and does neither explain all possible parameters which can be set nor introduces all road sections available, it is sufficient for completing the following task. If you want more information on the road sections just have all look at simulation.utils.road.sections the source code.

Your Task

Create a new road with the following sections:

  1. straight road: length 1 m

  2. parking area: length 3.5 m

    1. left lot: start after 0.5 m, depth 0.5 m, three parking spots

    2. right lot: start after 1.5 m, two spots with a width of 70 cm

  3. circular arc to the left: radius 2 m, angle 90 degrees

  4. zebra crossing

  5. intersection: turn to the left, size 3 m

  6. circular arc to the right: radius 1.5 m, angle 90 degrees

  7. circular arc to the left: radius 2.5 m, angle 60 degrees

  8. straight road: length 80 cm

  9. circular arc to the left: radius 2.5 m, angle 120 degrees

  10. intersection: size 3.2 m, angle 110 degrees, go straight

  11. straight road: length 1.66 m

  12. circular arc to the left: radius 1 m, angle 90 degrees

  13. straight road: length 1.25 m

The road should form a closed loop.

../_images/onboarding_complex_road.jpg

Hint

  • Do not forget to import necessary sections.

  • You can look at the road you have defined by starting the simulation!

  • All angles must be specified in radians!

Don’t forget to commit and push your changes after completing the task!

Note

By default, new roads are not included into git because we don’t want to have everybody’s roads in our repository! However, if you want to commit a road (like you should do here!). you can go into the roads folder (simulation/models/env_db) and execute:

git add -f <FILE_NAME>