Roads

Whenever the car’s behavior is simulated, a road is necessary.

Important

Roads are python scripts within simulation/models/env_db. The name of the file is the road’s name.

The repositories already comes with a few predefined roads.

/bin/sh: 1: cd: can't cd to /workspaces/kitcar-gazebo-simulation/

The renderer expects to find py:attr:road of type simulation.utils.road.road.Road within the road script.

This implies that:

Note

A new road can be any script which defines a global road variable of type simulation.utils.road.road.Road within simulation/models/env_db.

E.g. the file simulation/models/env_db/custom_road.py with content:

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

road = Road()

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

creates a very simple straight road, called custom_road.

There are a number of different types of road sections which are explained in Road Sections.

default_road

When the simulation is launched without any additional road parameter:

roslaunch gazebo_simulation master.launch

the default_road is used. It consists of multiple simulation.utils.road.generator.road_sections concatenated using a simulation.utils.road.road.Road:

default_road
"""The default road when launching this simulation."""

import math

from simulation.utils.road.road import Road  # Definition of the road class
from simulation.utils.road.sections import (
    Intersection,
    LeftCircularArc,
    ParkingArea,
    ParkingLot,
    ParkingObstacle,
    ParkingSpot,
    Pedestrian,
    StaticObstacle,
    StraightRoad,
    ZebraCrossing,
)
from simulation.utils.road.sections.road_section import RoadSection

road = Road(start_box=True)
road.append(StraightRoad(length=1))

# Create a parking area with different kinds of parking spots
road.append(
    ParkingArea(
        length=4,
        start_line=True,
        left_lots=[
            ParkingLot(
                start=1, spots=[ParkingSpot(), ParkingSpot(kind=ParkingSpot.BLOCKED)]
            )
        ],
        right_lots=[
            ParkingLot(
                start=0.2,
                spots=[
                    ParkingSpot(
                        kind=ParkingSpot.OCCUPIED,
                        width=0.7,
                        obstacle=ParkingObstacle(x=0.15, y=-0.2, width=0.3, depth=0.25),
                    ),
                    ParkingSpot(kind=ParkingSpot.BLOCKED),
                ],
            )
        ],
    )
)
road.append(
    LeftCircularArc(
        radius=2, angle=math.pi / 2, right_line_marking=RoadSection.MISSING_LINE_MARKING
    )
)
road.append(StraightRoad(length=0.45))
road.append(LeftCircularArc(radius=2, angle=math.pi / 2))
road.append(Intersection(size=3, turn=Intersection.RIGHT))
road.append(LeftCircularArc(radius=1.5, angle=math.pi, obstacles=[StaticObstacle()]))
road.append(Intersection(size=3, turn=Intersection.RIGHT))

left_arc = LeftCircularArc(
    radius=1.5,
    angle=math.pi / 2,
    left_line_marking=RoadSection.MISSING_LINE_MARKING,
)
left_arc.add_speed_limit(arc_length=0, speed=30)
road.append(left_arc)

road.append(ZebraCrossing(obstacles=[Pedestrian()]))
road.append(StraightRoad(length=1))

left_arc = LeftCircularArc(radius=1.5, angle=math.pi / 2)
left_arc.add_speed_limit(0, -30)
road.append(left_arc)

road.append(StraightRoad(length=0.95))