The package duckietown_world
implements the map representation for the
Duckeietown World.
# disabling contracts for speed
import contracts
contracts.disable_all()
import duckietown_world as dw
# reducing the verbosity to critical
dw.logger.setLevel(50)
Function list_maps
returns the list of maps:
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:
from duckietown_world.svg_drawing.ipython_utils import ipython_draw_svg
ipython_draw_svg(m)
for map_name in dw.list_maps():
m1 = dw.load_map(map_name)
image = ipython_draw_svg(m1, 'out/' + map_name)
print(map_name)
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/N, 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)
ipython_draw_svg(m);
map_data_yaml = """
# 3x3 tiles with left turns at the corners going in a counter-clockwise loop
tiles:
- [straight/N, straight/W, straight/S, straight/E]
- [curve_left/N, curve_left/W, curve_left/S, curve_left/E]
- [curve_right/N, curve_right/W, curve_right/S, curve_right/E]
- [4way/N, 4way/W, 4way/S, 4way/E]
- [3way_left/N, 3way_left/W, 3way_left/S, 3way_left/E]
- [3way_right/N, 3way_right/W, 3way_right/S, 3way_right/E]
"""
import yaml
map_data = yaml.load(map_data_yaml)
m = dw.construct_map(map_data, tile_size=0.61)
ipython_draw_svg(m);