carla/Docs/tuto_G_openstreetmap.md

4.5 KiB

Generate reality-based maps with OpenStreetMap

OpenStreetMap is an open license map of the world developed by contributors. Sections of these map can be exported to an XML file. CARLA can convert this file to OpenDRIVE format and ingest it as any other OpenDRIVE map using the OpenDRIVE Standalone Mode. The process is quite straightforward.


1- Obtain a map with OpenStreetMap

The first thing to do is using OpenStreetMap to generate an XML file containing the map information.

1.1. Go to openstreetmap.org.

1.2 Search for a desired location and zoom in to a specific area. openstreetmap_view

!!! Important Due to the Unreal Engine limitations, CARLA can ingest maps of a limited size (large cities like Paris pushes the limits of the engine). Additionally, the bigger the map, the longer the conversion to OpenDRIVE will take.

1.3.Click on Export in the upper left side of the window. The Export pannel will open.

1.4. Click on Manually select a different area in the Export pannel.

1.5. Select a custom area by dragging the corners of the square area in the viewport.

1.6. Click the Export button in the Export pannel, and save the map information of the selected area as a XML file.

openstreetmap_area


2- Convert to OpenDRIVE format

CARLA can read a XML file generated with OpenStreetMaps, and convert it to OpenDRIVE format that can be ingested as a CARLA map. This can be done through the PythonAPI using an script as in this example:

# load osm data
f = open(path/to/osm/file, 'r')
osm_xml = f.read()
f.close()

# convert to opendrive
settings = carla.Osm2OdrSettings()
# set desired settings
xodr_xml = carla.osm2odr.convert(osm_xml, settings)

# save opendrive file
f = open(path/to/output/file, 'w')
f.write(xodr_xml)
f.close()

The resulting file contains the road information in OpenDRIVE format. In the API documentation you can find more information regarding the settings that can be adjusted when converting the OSM file.


3- Import into CARLA

Finally, the OpenDRIVE file can be easily ingested in CARLA using the OpenDRIVE Standalone Mode.

a) Using your own script — Call for client.generate_opendrive_world() through the API. This will generate the new map, and block the simulation until it is ready. Use the carla.OpendriveGenerationParameters class to set the parameterization of the mesh generation.

vertex_distance = 2.0  # in meters
max_road_length = 500.0 # in meters
wall_height = 0.0      # in meters
extra_width = 0.6      # in meters
world = client.generate_opendrive_world(
    xodr_xml, carla.OpendriveGenerationParameters(
        vertex_distance=vertex_distance,
        max_road_length=max_road_length,
        wall_height=wall_height,
        additional_width=extra_width,
        smooth_junctions=True,
        enable_mesh_visibility=True))

We recommend to run the standalone mode with wall_height = 0.0 in the carla.OpendriveGenerationParameters settings to launch the standalone mode.

b) Using config.py — We also provide the means to load an OpenStreetMaps file directly to Carla using the config.py script provided with Carla:

config.py --osm-file=/path/to/OSM/file

!!! Warning client.generate_opendrive_world() uses content of the OpenDRIVE file parsed as string. On the contrary, config.py script needs the path to the .xodr file.

!!! Important
    The ingestion of the map allows for some parameterization. However, using the `config.py` parameters will always be the default ones.


Either way, the map should be ingested automatically in CARLA and the result should be similar to this.
![opendrive_meshissue](img/tuto_g_osm_carla.jpg)
<div style="text-align: right"><i>Outcome.</i></div>

---

That is all there is to know about how to use OpenStreetMap to generate CARLA maps.

For issues and doubts related with this topic can be posted in the CARLA forum.

<div class="build-buttons">
<p>
<a href="https://forum.carla.org/" target="_blank" class="btn btn-neutral" title="Go to the CARLA forum">
CARLA forum</a>
</p>
</div>