pycozmo

A pure-Python communication library, alternative SDK, and application for the Cozmo robot.


Keywords
ddl, anki, cozmo, robot, robotics, anki-cozmo, cozmo-sdk, digitial-dream-labs
License
MIT
Install
pip install pycozmo==0.8.0

Documentation

PyCozmo

PyCozmo is a pure-Python Anki Cozmo communication library. It allows controlling a Cozmo robot directly, without having to go through a mobile device, running the Cozmo app.

The library is loosely based on the Anki Cozmo Python SDK and the cozmoclad ("C-Like Abstract Data") library.

This project is a tool for exploring the hardware and software of Anki Cozmo. It is unstable and heavily under development.

Usage

Basic mode:

import time
import pycozmo

def pycozmo_program(cli):
    cli.set_head_angle(angle=0.6)
    time.sleep(1)

pycozmo.run_program(pycozmo_program)

Advanced mode:

import pycozmo

cli = pycozmo.Client()
cli.start()
cli.connect()
cli.wait_for_robot()

cli.drive_wheels(lwheel_speed=50.0, rwheel_speed=50.0, duration=2.0)

cli.disconnect()
cli.stop()

Documentation

https://pycozmo.readthedocs.io/

Examples

Basic:

  • minimal.py - minimal code to communicate with Cozmo, using PyCozmo
  • go_to_pose.py - demonstrates moving to a specific pose (position and orientation)
  • extremes.py - demonstrates Cozmo lift and head control
  • backpack_lights.py - demonstrates Cozmo backpack LED control
  • display_image.py - demonstrates visualization of image files on Cozmo's display
  • events.py - demonstrates event handling
  • camera.py - demonstrates capturing a camera image
  • path.py - demonstrates following a predefined path

Advanced:

Tools

Robot Support

Sensors:

  • Camera
  • Cliff sensor
  • Accelerometers
  • Gyro
  • Battery voltage
  • Cube battery voltage
  • Cube accelerometers

Actuators:

  • Wheel motors
  • Head motor
  • Lift motor
  • Backpack LEDs
  • IR LED
  • OLED display
  • Speaker - work progress
  • Cube LEDs
  • Platform LEDs

Communication:

  • Wi-Fi AP
  • Bluetooth LE

Storage:

  • NVRAM
  • Firmware update

Functions:

  • Localization
  • Path tracking
  • Procedural faces
  • Animations from FlatBuffers .bin files

Connecting to Cozmo over Wi-Fi

A Wi-Fi connection needs to be established with Cozmo before using PyCozmo applications.

  1. Wake up Cozmo by placing it on the charging platform
  2. Make Cozmo display it's Wi-Fi PSK by rising and lowering its lift
  3. Scan for Cozmo's Wi-Fi SSID (depends on the OS)
  4. Connect using Cozmo's Wi-Fi PSK (depends on the OS)

PyCozmo vs. the Cozmo SDK

A Cozmo SDK application (aka "game") acts as a client to the Cozmo app (aka "engine") that runs on a mobile device. The low-level communication happens over USB and is handled by the cozmoclad library.

In contrast, an application using PyCozmo basically replaces the Cozmo app and acts as the "engine". PyCozmo handles the low-level UDP communication with Cozmo.

+------------------+                     +------------------+                     +------------------+
|     SDK app      |      Cozmo SDK      |    Cozmo app     |       PyCozmo       |      Cozmo       |
|      "game"      |      cozmoclad      |     "engine"     |                     |     "robot"      |
|                  | ------------------> |   Wi-Fi client   | ------------------> |     Wi-Fi AP     |
|                  |         USB         |    UDP client    |      UDP/Wi-Fi      |    UDP Server    |
+------------------+                     +------------------+                     +------------------+

Limitations

  • some high-level Cozmo SDK features are implemented in the Cozmo app and have no equivalent in PyCozmo, today:
    • personality engine
    • behaviors
    • motion detection
    • face detection
    • facial expression estimation
    • text-to-speech
    • songs
  • there is no Wi-Fi control. The library assumes a Wi-Fi connection to Cozmo, established in advance.
  • frame retransmission is not implemented
  • transmission of multiple packets in a single frame is not implemented

Requirements

  • Python 3.5.4
  • Pillow 6.0.0 - Python image library
  • FlatBuffers - serialization library
  • dpkt - TCP/IP packet parsing library

Installation

Using pip:

pip install pycozmo

From source:

git clone https://github.com/zayfod/pycozmo.git
cd pycozmo
python setup.py install

From source, for development:

git clone git@github.com:zayfod/pycozmo.git
cd pycozmo
python setup.py develop

Support

Bug reports and patches should be sent via GitHub:

https://github.com/zayfod/pycozmo

Anki Robot Discord server, channel #cozmo:

https://discord.gg/ew92haS

Disclaimer

This project is not affiliated with Anki or Digital Dream Labs.