Skip to content

Python+node wrapper to read/send message from/to Anki Overdrive bluetooth vehicles.

Notifications You must be signed in to change notification settings

jacopotagliabue/anki-drive-python-sdk

Repository files navigation

anki-drive-python-sdk

This is a Python wrapper to read/send message from/to Anki Overdrive bluetooth vehicles.

The project was designed for the A.I. blog series Self-driving (very small) cars: please refer to the Medium post for a full explanation on the code structure and the philosophy behind it.

TL;DR

We share a cross-platform Python+node setup that allows for quick experimentation and prototyping of interesting ideas in the toy universe of bluetooth cars.

overview

In particular:

  • a node server leverages noble to establish communication with Anki cars;
  • a Python app leverages sockets to reliably read/send messages from/to the node gateway, which abstracts away all the complexity of the bluetooth channel.

Setup

To use py-overdrive-sdk you'll need:

We run our code from a 2017 MacBook Pro and a Rasp Pi 3B+. We did not test with other hardware setups but in theory the wrapper should be pretty flexible.

Deployment

After cloning the repo, proceed to install node and python dependencies (we suggest using virtualenv but it's not necessary of course) as usual:

npm install
pip install -r requirements.txt

Prepare the bluetooth id for the car you want to drive (if you don't know it, you can just start-up the node server with a fake id and write down the id that gets printed to the console in the format SCAN|{BLUETOOTH-CAR-ID}|{BLUETOOTH-CAR-ADDRESS}).

Start-up the node gateway:

node node_server.js {YOUR-SERVER-PORT} {YOUR-BLUETOOTH-CAR-ID}

and wait for the console to notify that SCAN has been completed (you should see the id of the Anki cars as they are discovered by noble).

Finally run your python script. To start with a simple example, run:

python constant_speed_example.py --car={YOUR-BLUETOOTH-CAR-ID} --port={GATEWAY-PORT}

and see your car moving around (make sure to specify the same port for both node and Python). This is a one-minute video going from git to a running car: please refer to the Medium post for more details.

Current release and next steps

Please note that the current master (as of Sep. 2018) is released as alpha as it just contains the bare minimum the get things going: no unit tests, no fancy stuff, almost no protections from errors, etc. We'll hope to make several improvements to the code base as we progress with our experiments: feedback and contributions are most welcomed! Even without considering A.I. stuff (i.e. making the car learning how to optimally drive), there are several engineering improvements to be considered, such as for example (non-exhaustive list in no particular order):

  • set up unit and integration tests;
  • re-use node gateway for multiple cars at the same time;
  • a better abstraction for "driving policies", so that it becomes easier to instantiate custom policies while keeping the rest of the code (i.e. communication layer) pretty much intact and re-usable;
  • a "car-level" abstraction on top of the current Overdrive class, so that we could easily simulate different hardware abilities and constrain car learning in dynamic ways;
  • data ingestion/persisting mechanism, so that we can log in a reliable and consistent way everything that happens within a run

Some experimental code will be published in the develop branch and hopefully merged later on into a beta release.

Acknowledgments

It would have been a month project, not a weekend one, without Internet and the fantastic people on it sharing their code and ideas: as far as copy+paste-ing goes, this project is indeed second to none. In particular:

License

All the code in this repo is provided "AS IS" and it is freely available under the Apache License Version 2.0.

About

Python+node wrapper to read/send message from/to Anki Overdrive bluetooth vehicles.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published