3. Road

This section is an introduction to the construction of routes for our simulation environment. The routes for our simulation, which we call roads, consist of different sections. A single road is made up of different road sections which are placed consecutively. All length specifications are in meters.

3.1. Road sections

Available road sections are:

StaticObstacles can be placed on every RoadSection. Every road section has a middle, right, and left line. Lines can be dashed, solid or missing. The width of a single lane is 0.4 m thus making the road 0.8 m in width. The origin of every road is at the beginning of the first middle line. The x-Axis points in the driving direction (along the middle line), the y-Axis is defined pointing towards the left line. These axes are also shown in gazebo (x-axis: red, y-axis: green).

3.2. Road directory

Roads are defined in a single python file. All of these road files are located in simulation/models/env_db/. After rendering a road file called road_name.py a .road_name folder is created in the same directory. Amongst other things, this hidden folder contains pictures of the rendered road which are later used in the simulation.

Tip

Hidden files or directories can be recognized by the dot (.) before their file or directory name. By default, they are not shown to the user. In most file managers, you can use the Ctrl+H keyboard shortcut to toggle between displaying or hiding hidden files. In a terminal you can use the ls command to display all files, including the hidden ones:

ls -a

3.3. Simple road

Inside the road directory, there is a road file called onboarding_simple.py. It is a very simple road only containing StraightRoads and a basic right-angle intersection. Let’s take a look at onboarding_simple.py:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
"""A simple road for the onboarding task."""

from simulation.utils.road.road import Road  # Definition of the road class
from simulation.utils.road.sections import Intersection, StraightRoad

road = Road()
road.append(StraightRoad())
road.append(StraightRoad(length=2))
road.append(Intersection())
road.append(StraightRoad())

Lines 3 to 5 are imports for the abstract road class and the used road sections. In line 8 a Road called road is constructed and in the following lines different road sections are added to this road:

>>> straight_road = road.append(road_section)

A StraightRoad with the default length of 1 m can be added by calling:

>>> StraightRoad()
StraightRoad(_Transformable__transform=Transform(translation=Vector(0.0, 0.0, 0.0),rotation=Quaternion(1.0, 0.0, 0.0, 0.0)), id=0, is_start=False, left_line_marking='solid', middle_line_marking='dashed', right_line_marking='solid', obstacles=[], traffic_signs=[], surface_markings=[], _speed_limits=[], prev_length=0, length=1)

If you want to pass a different length add the argument length in the constructor. For example a 2 m long StraightRoad:

>>> StraightRoad(length=2)
StraightRoad(_Transformable__transform=Transform(translation=Vector(0.0, 0.0, 0.0),rotation=Quaternion(1.0, 0.0, 0.0, 0.0)), id=0, is_start=False, left_line_marking='solid', middle_line_marking='dashed', right_line_marking='solid', obstacles=[], traffic_signs=[], surface_markings=[], _speed_limits=[], prev_length=0, length=2)

In the next section you are going to learn how to start the simulation with a custom road.