The package duckietown_world
implements the map representation for the
Duckeietown World.
import duckietown_world as dw
import logging
dw.logger.setLevel(logging.CRITICAL)
dw.list_maps()
Use load_map
to load a map:
m = dw.load_map('4way')
print(m)
Later, we will see what is inside a map.
We define this utility function to draw the map:
import os
def draw_static_map(m, outdir=None):
if outdir is None:
outdir = 'out-draw_static_map/%s' % id(m)
dw.draw_static(m, outdir);
from IPython.core.display import SVG
return SVG(os.path.join(outdir, 'drawing.svg'))
draw_static_map(m)
import IPython;
for map_name in dw.list_maps():
m1 = dw.load_map(map_name)
image = draw_static_map(m1, map_name)
print(map_name)
IPython.display.display_svg(image)
Look for the '*.yaml' files in duckietown_world
to get examples of data format.
You can also define a new map "inline":
map_data_yaml = """
# 3x3 tiles with left turns at the corners going in a counter-clockwise loop
tiles:
- [curve_left/W , straight/W, curve_left/N]
- [straight/S , asphalt , straight/N]
- [curve_left/S , straight/E, curve_left/E]
"""
import yaml
map_data = yaml.load(map_data_yaml)
m = dw.construct_map(map_data, tile_size=0.61)
draw_static_map(m, 'mymap')
map_data_yaml = """
# 3x3 tiles with left turns at the corners going in a counter-clockwise loop
tiles:
- [straight/N, straight/W, straight/N, straight/E]
- [curve_left/N, curve_left/W, curve_left/N, curve_left/E]
- [curve_right/N, curve_right/W, curve_right/N, curve_right/E]
- [4way/N, 4way/W, 4way/N, 4way/E]
- [3way_left/N, 3way_left/W, 3way_left/N, 3way_left/E]
- [3way_right/N, 3way_right/W, 3way_right/N, 3way_right/E]
"""
import yaml
map_data = yaml.load(map_data_yaml)
m = dw.construct_map(map_data, tile_size=0.61)
draw_static_map(m, 'mymap')