Duckietown World tutorial

The package duckietown_world implements the map representation for the Duckeietown World.

In [1]:
# disabling contracts for speed
import contracts
contracts.disable_all()
In [2]:
import duckietown_world as dw
INFO:dt-world:duckietown-world 1.0.15
In [3]:
# reducing the verbosity to critical
dw.logger.setLevel(50)

Listing available maps

Function list_maps returns the list of maps:

In [4]:
dw.list_maps()
Out[4]:
['4way',
 'loop_dyn_duckiebots',
 'loop_empty',
 'loop_obstacles',
 'loop_pedestrians',
 'regress_4way_adam',
 'regress_4way_drivable',
 'robotarium1',
 'small_loop',
 'small_loop_cw',
 'straight_road',
 'udem1',
 'zigzag_dists']

Loading a map

Use load_map to load a map:

In [5]:
m = dw.load_map('4way')
print(m)
DuckietownMap(tile_size=0.585)

Later, we will see what is inside a map.

Drawing a map

We define this utility function to draw the map:

In [6]:
from duckietown_world.svg_drawing.ipython_utils import ipython_draw_svg
In [7]:
ipython_draw_svg(m)
Out[7]:

Display all the maps available

In [8]:
for map_name in dw.list_maps():
    m1 = dw.load_map(map_name)
    image = ipython_draw_svg(m1, 'out/' + map_name)
    print(map_name)
4way
loop_dyn_duckiebots
loop_empty
loop_obstacles
loop_pedestrians
regress_4way_adam
regress_4way_drivable
robotarium1
small_loop
small_loop_cw
straight_road
udem1
zigzag_dists

Creating new maps

Look for the '*.yaml' files in duckietown_world to get examples of data format.

You can also define a new map "inline":

In [9]:
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);

Available tiles

In [10]:
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);