roadpack
Turn-by-turn routing on a microcontroller, offline, for a whole country.
roadpack compiles an OpenStreetMap extract into a .gmap: a compact binary road graph with a precomputed
contraction hierarchy, laid out so that a device with a few MB of RAM routes straight from a microSD card,
without ever loading the map. All of Colombia is 256 MB, turn restrictions included, and an ESP32-S3 finds the 963 km
route from Bogotá to Cartagena in under 3 seconds, with a cold cache (on the device).
Why
Routing engines like OSRM, Valhalla or GraphHopper are built for servers and phones, with an operating system, a file system and plenty of memory. A microcontroller has a few MB of RAM, a FAT-formatted SD card that reads a few MB per second, and no operating system. roadpack is not a routing engine: it is the build step that produces a map such a device can route on.
- Only what routing needs. Drivable roads for a vehicle profile; graph nodes only at intersections and dead ends (13 to 47 % of the OSM road nodes); shapes simplified to 2 m.
- Few nodes per route. The contraction hierarchy settles a few hundred nodes for a route across a country, where A* settles hundreds of thousands (Colombia: 275 against 458,000, median of 200 random routes).
- Read in place. Fixed-size little-endian records, nodes in Z-order so that nearby roads sit in the same SD card pages, a sparse spatial grid to snap a GPS fix, and the file split into 4 MiB chunks because FAT without fast seek is slow on large files.
- Verified. The hierarchy matches A* on 2,200 random routes across 22 regions, and the builder's output is checked against the original reference implementation (how).
It was built for, and runs on, an offline motorcycle navigator: a Waveshare ESP32-S3 with a 466×466 round AMOLED display, reading the map from a microSD card.
Quick start
pip install git+https://github.com/NicolasDevel/roadpack.git
# Any extract from https://download.geofabrik.de or https://extract.bbbike.org
roadpack build colombia-latest.osm.pbf -o out/colombia.gmap # the whole extract
roadpack build colombia-latest.osm.pbf --region bogota -o out/bogota.gmap # or --bbox minlat,minlon,maxlat,maxlon
roadpack info out/bogota.gmap
roadpack route out/bogota.gmap --from 4.5981,-74.0760 --to 4.6766,-74.0482 --check --images out/preview
roadpack stats out/bogota.gmap --routes 200
Route: 13.9 km, ~19 min, 155 edges, 11 maneuvers
contraction hierarchy settled 293 nodes in 1 ms (Python)
A* on the full graph settled 19,263 nodes in 30 ms: same cost
0.00 km (+ 0 m) Head out onto Calle 11
0.55 km (+ 550 m) Turn left onto Avenida Calle 7
0.67 km (+ 120 m) Turn left onto Carrera 5
...
buildwrites the.gmapand the same file split into chunks for the SD card (out/bogota/0000.bin, …).--profile carapplies car access and one-way rules instead of motorcycle ones.routeroutes like a device would and prints the maneuvers;--checkcompares with A* on the full graph,--imagesrenders the route and each maneuver screen.statsroutes between random pairs of nodes and reports the nodes settled and the KB of the file each route reads, which is what the SD card has to deliver.
The first build fetches RoutingKit and compiles a small helper into
~/.cache/roadpack: it needs git and a C++17 compiler.
How it works
flowchart LR
pbf[".osm.pbf"] --> load["Load<br/>highway ways, then their nodes<br/>(two passes, filtered in C++)"]
load --> graph["Graph<br/>split at intersections<br/>simplify shapes · Z-order<br/>spatial grid<br/>turn restrictions"]
graph --> ch["Contraction hierarchy<br/>(RoutingKit)"]
ch --> gmap[".gmap<br/>+ 4 MiB chunks"]
gmap --> sd["microSD"] --> mcu["Microcontroller<br/>bidirectional upward Dijkstra<br/>through a small page cache"]
┌────────┬────────────┬──────────┬──────────────┬──────────┬───────┬────────────┬─────────────┐
│ header │ nodes │ edges │ spatial grid │ geometry │ names │ CH forward │ CH backward │ copies │
│ 80 B │ 12 B × N+1 │ 28 B × E │ sparse │ variable │ UTF-8 │ │ │ 8 B × K │
└────────┴────────────┴──────────┴──────────────┴──────────┴───────┴────────────┴─────────────┴──────────┘
A device answers a query by running Dijkstra from both ends, only ever going up in the hierarchy, then unpacking
the shortcuts into real edges. The format, byte by byte, and the query are in FORMAT.md; the Python
reader in roadpack.format and the router in roadpack.routing are the reference implementation.
Results
From the benchmarks: motorcycle profile, 200 random routes per region, on a 16 GB laptop.
| Region | Graph nodes | .gmap |
Build | Median route | Nodes settled (median) | A* settles | KB read per query |
|---|---|---|---|---|---|---|---|
| Bogotá | 91 k | 15 MB | 5 s | 15 km | 272 | 29 k | 1,072 |
| London | 419 k | 62 MB | 11 s | 31 km | 389 | 83 k | 2,040 |
| Tokyo | 236 k | 42 MB | 7 s | 17 km | 462 | 81 k | 2,112 |
| Colombia | 1.27 M | 263 MB | 54 s | 610 km | 294 | 439 k | 2,972 |
| Spain | 3.41 M | 603 MB | 2 min | 563 km | 420 | 545 k | 3,560 |
| California | 2.94 M | 505 MB | 95 s | 408 km | 566 | 1.09 M | 4,496 |
| Brazil | 10.2 M | 2.2 GB | 8 min | 1,674 km | 693 | 3.59 M | 8,020 |
The benchmarks also cover Mexico City, Lima, Buenos Aires, Santiago, Washington DC, Ottawa, Toronto, New York, Madrid, Barcelona, Paris, Berlin, Canada, Texas, New York State and Colombia by department. How large countries fit in a laptop, and the evidence that they are exact.
On the device
Measured on the navigator this was built for: an ESP32-S3 with a 2 MB page cache in PSRAM (4 KiB pages), reading the Colombia map (v3, with turn restrictions; OSM data of 2026-10-27) from a microSD card in 1-bit mode at 40 MHz, with the cache empty before each route. Median of 10 runs.
| Route | Distance | Route found | Ready to navigate | SD card reads |
|---|---|---|---|---|
| Across Bogotá | 15 km | 0.9 s | 1.4 s | 423 |
| Bogotá – San Francisco | 62 km | 1.0 s | 1.4 s | 464 |
| Bogotá – Medellín | 427 km | 2.0 s | 2.5 s | 839 |
| Bogotá – Cartagena | 963 km | 2.9 s | 3.4 s | 1,139 |
Route found is the hierarchy query plus unpacking the shortcuts into edges. Ready to navigate adds the shapes and maneuvers of the first 15 km.
What made the difference:
- The time is spent waiting for the card. Each random 4 KiB read costs about 2.8 ms and the computation is
negligible, so the number to watch is reads per route (what
roadpack statsreports). Larger pages were slower: the cost grows with the bytes read. - Build the shapes as you go. Reading the shapes and checking every intersection of a 963 km route costs more than finding it (1,352 reads), so the navigator only builds 15 km ahead of the rider. Bogotá–Cartagena went from 8.2 to 4.4 s. Adding up the length of the rest of the route while riding, instead of before showing it, saved another ~400 reads: until then the remaining distance is estimated from the travel time of the edges.
- Use a genuine card. A counterfeit one (sold as a known brand, but its CID reports manufacturer 0x6F) stalled for about 9 s in one route out of three and sometimes failed a read even after retries. A failed read silently leaves zeros where the data should be, so the device counts them and computes the route again. The same card once stored a copy of the map with 16 KB of one chunk replaced by other data, without any error: compare the files after copying them to the card.
Limits
- The
.gmapformat addresses 4 GiB and about 164° of longitude: Brazil fits (2.2 GB); the whole United States does not, so it is built per state. - Building needs at least about 1.5 GB of RAM, and about 9 GB for Brazil.
- Turn restrictions with a via node or via ways are applied (in Colombia, 6,826 of 6,940 in the October 2026
extract); time-dependent ones are not. Speeds come from
maxspeedor a default per road class (no traffic). - The microcontroller side is specified in FORMAT.md, with two implementations: the Python reference here and a portable C99 reader and router in reader/ (no allocation, checked against the Python one). Maneuvers are only in Python for now.
Project layout
| Module | Layer |
|---|---|
roadpack.osm |
Loading: drivable ways of an OSM extract for a vehicle profile (motorcycle, car) |
roadpack.graph |
Graph: segments between intersections, simplified geometry, Z-order, spatial grid (numpy) |
roadpack.ch |
Contraction hierarchy (RoutingKit, build_ch.cpp) |
roadpack.format |
The .gmap format: writer, reader, SD card chunks |
roadpack.routing |
Reference routing: CH query, A*, turn-by-turn maneuvers |
roadpack.stats, roadpack.preview |
Route sampling; PNG of a route and of each maneuver screen |
benchmarks/ |
Benchmark, validation and reference-comparison scripts, with their results |
reader/ |
C99 reader and router for microcontrollers (reader/README.md) |
pip install -e '.[test]' && pytest
The tests build small synthetic OpenStreetMap files (a hand-made town that exercises every rule, and random street grids) and check, among other things, that the contraction hierarchy matches Dijkstra on every pair of nodes.
Licenses
- This repository's code: MIT.
- Generated maps are a database derived from OpenStreetMap, © OpenStreetMap contributors, under the ODbL: if you distribute them, give that attribution and share them under the same license.
- RoutingKit (BSD 2-Clause) is downloaded and compiled on use; it is not included in this repository.
- Python dependencies: pyosmium (BSD 2-Clause), NumPy (BSD 3-Clause), Pillow (MIT-CMU).
Metadata
Release files for roadpack 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| roadpack-0.1.0.tar.gz | 489.2 kB | With provenance | Details for roadpack-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| roadpack-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for roadpack-0.1.0-py3-none-any.whl |
Total release size: 540.9 kB
Release files / roadpack-0.1.0.tar.gz
| Download URL | roadpack-0.1.0.tar.gz |
|---|---|
| Size | 489.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0457cf56009e495242b5e84373f144c0ca45547e4332f163c56145663c21bc2
|
|
BLAKE2b-256 checksum How to use checksums |
ca96e29d34591e0e9e2440b29095981e4efee5e1ffdd36652d236d87b3b21bf1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logRelease files / roadpack-0.1.0-py3-none-any.whl
| Download URL | roadpack-0.1.0-py3-none-any.whl |
|---|---|
| Size | 51.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
448f9d7d5d73a8fb5d65134f0a1a8c01385d81fbc9c65d5cc5e11a2deed8b745
|
|
BLAKE2b-256 checksum How to use checksums |
eb518b6a216cdd708c57c7c1401a6ef4226a28125ea4743de07dd68b06ffa111
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logSecurity for roadpack 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for roadpack-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.