cozmo

Functions

verify_min_clad_version()
cozmo.logger = <Logger cozmo.general (WARNING)>

The general purpose logger logs high level information about Cozmo events.

cozmo.logger_protocol = <Logger cozmo.protocol (WARNING)>

The protocol logger logs low level messages that are sent back and forth to Cozmo.

class cozmo.DeviceConnector(cozmo_port=5106, enable_env_vars=True)

Base class for objects that setup the physical connection to a device.

connect(loop, protocol_factory, conn_check)

Connect attempts to open a connection transport to the Cozmo app on a device.

On opening a transport it will create a protocol from the supplied factory and connect it to the transport, returning a (transport, protocol) tuple. See asyncio.BaseEventLoop.create_connection()

class cozmo.IOSConnector(serial=None, **kw)

Connects to an attached iOS device over USB.

Opens a connection to the first iOS device that’s found to be running the Cozmo app in SDK mode.

iTunes (or another service providing usbmuxd) must be installed in order for this connector to be able to open a connection to a device.

An instance of this class can be passed to the connect_ prefixed functions in this module.

Parameters:serial (string) – Serial number of the device to connect to. If None, then connect to the first available iOS device running the Cozmo app in SDK mode.
connect(loop, protocol_factory, conn_check)

Connect attempts to open a connection transport to the Cozmo app on a device.

On opening a transport it will create a protocol from the supplied factory and connect it to the transport, returning a (transport, protocol) tuple. See asyncio.BaseEventLoop.create_connection()

class cozmo.AndroidConnector(adb_cmd=None, serial=None, **kw)

Connects to an attached Android device over USB.

This requires the Android Studio command line tools to be installed, specifically adb.

By default the connector will attempt to locate adb (or adb.exe on Windows) in common locations, but it may also be supplied by setting the ANDROID_ADB_PATH environment variable, or by passing it to the constructor.

An instance of this class can be passed to the connect_ prefixed functions in this module.

Parameters:serial (string) – Serial number of the device to connect to. If None, then connect to the first available Android device running the Cozmo app in SDK mode.
connect(loop, protocol_factory, conn_check)

Connect attempts to open a connection transport to the Cozmo app on a device.

On opening a transport it will create a protocol from the supplied factory and connect it to the transport, returning a (transport, protocol) tuple. See asyncio.BaseEventLoop.create_connection()

class cozmo.TCPConnector(tcp_port=None, ip_addr='127.0.0.1', **kw)

Connects to the Cozmo app directly via TCP.

Generally only used for testing and debugging.

Requires that a SDK_TCP_PORT environment variable be set to the port number to connect to.

connect(loop, protocol_factory, conn_check)

Connect attempts to open a connection transport to the Cozmo app on a device.

On opening a transport it will create a protocol from the supplied factory and connect it to the transport, returning a (transport, protocol) tuple. See asyncio.BaseEventLoop.create_connection()

cozmo.connect(f, conn_factory=<class 'cozmo.conn.CozmoConnection'>, connector=None)

Connects to the Cozmo Engine on the mobile device and supplies the connection to a function.

Accepts a function, f, that is given a cozmo.conn.CozmoConnection object as a parameter.

The supplied function may be either an asynchronous coroutine function (normally defined using async def) or a regular synchronous function.

If an asynchronous function is supplied it will be run on the same thread as the Cozmo event loop and must use the await keyword to yield control back to the loop.

If a synchronous function is supplied then it will run on the main thread and Cozmo’s event loop will run on a separate thread. Calls to asynchronous methods returned from CozmoConnection will automatically be translated to synchronous ones.

The connect function will return once the supplied function has completed, as which time it will terminate the connection to the robot.

Parameters:
  • f (callable) – The function to execute
  • conn_factory (callable) – Override the factory function to generate a cozmo.conn.CozmoConnection (or subclass) instance.
  • connector (DeviceConnector) – Optional instance of a DeviceConnector subclass that handles opening the USB connection to a device. By default it will connect to the first Android or iOS device that has the Cozmo app running in SDK mode.
cozmo.connect_with_3dviewer(f, conn_factory=<class 'cozmo.conn.CozmoConnection'>, connector=None, enable_camera_view=False, show_viewer_controls=True)

Setup a connection to a device and run a user function while displaying Cozmo’s 3d world.

This displays an OpenGL window on the screen with a 3D view of Cozmo’s understanding of the world. Optionally, if use_viewer is True, a 2nd OpenGL window will also display showing a view of Cozmo’s camera. It will return an error if the current system does not support PyOpenGL.

The function may be either synchronous or asynchronous (defined used async def).

The function must accept a cozmo.CozmoConnection object as its only argument. This call will block until the supplied function completes.

Parameters:
  • f (callable) – The function to execute
  • conn_factory (callable) – Override the factory function to generate a cozmo.conn.CozmoConnection (or subclass) instance.
  • connector (DeviceConnector) – Optional instance of a DeviceConnector subclass that handles opening the USB connection to a device. By default it will connect to the first Android or iOS device that has the Cozmo app running in SDK mode.
  • enable_camera_view (bool) – Specifies whether to also open a 2D camera view in a second OpenGL window.
  • show_viewer_controls (bool) – Specifies whether to draw controls on the view.
cozmo.connect_with_tkviewer(f, conn_factory=<class 'cozmo.conn.CozmoConnection'>, connector=None, force_on_top=False)

Setup a connection to a device and run a user function while displaying Cozmo’s camera.

This displays a Tk window on the screen showing a view of Cozmo’s camera. It will return an error if the current system does not support Tk.

The function may be either synchronous or asynchronous (defined used async def).

The function must accept a cozmo.CozmoConnection object as its only argument. This call will block until the supplied function completes.

Parameters:
  • f (callable) – The function to execute
  • conn_factory (callable) – Override the factory function to generate a cozmo.conn.CozmoConnection (or subclass) instance.
  • connector (DeviceConnector) – Optional instance of a DeviceConnector subclass that handles opening the USB connection to a device. By default it will connect to the first Android or iOS device that has the Cozmo app running in SDK mode.
  • force_on_top (bool) – Specifies whether the window should be forced on top of all others
cozmo.connect_on_loop(loop, conn_factory=<class 'cozmo.conn.CozmoConnection'>, connector=None)

Uses the supplied event loop to connect to a device.

Will run the event loop in the current thread until the connection succeeds or fails.

If you do not want/need to manage your own loop, then use the connect() function to handle setup/teardown and execute a user-supplied function.

Parameters:
  • loop (asyncio.BaseEventLoop) – The event loop to use to connect to Cozmo.
  • conn_factory (callable) – Override the factory function to generate a cozmo.conn.CozmoConnection (or subclass) instance.
  • connector (DeviceConnector) – Optional instance of a DeviceConnector subclass that handles opening the USB connection to a device. By default, it will connect to the first Android or iOS device that has the Cozmo app running in SDK mode.
Returns:

A cozmo.conn.CozmoConnection instance.

cozmo.run_program(f, use_viewer=False, conn_factory=<class 'cozmo.conn.CozmoConnection'>, connector=None, force_viewer_on_top=False, deprecated_filter='default', use_3d_viewer=False, show_viewer_controls=True, exit_on_connection_error=True)

Connect to Cozmo and run the provided program/function f.

Parameters:
  • f (callable) – The function to execute, accepts a connected cozmo.robot.Robot as the parameter.
  • use_viewer (bool) – Specifies whether to display a view of Cozmo’s camera in a window.
  • conn_factory (callable) – Override the factory function to generate a cozmo.conn.CozmoConnection (or subclass) instance.
  • connector (DeviceConnector) – Optional instance of a DeviceConnector subclass that handles opening the USB connection to a device. By default it will connect to the first Android or iOS device that has the Cozmo app running in SDK mode.
  • force_viewer_on_top (bool) – Specifies whether the window should be forced on top of all others (only relevant if use_viewer is True). Note that this is ignored if use_3d_viewer is True (as it’s not currently supported on that windowing system).
  • deprecated_filter (str) – The filter for any DeprecationWarning messages. This is defaulted to “default” which shows the warning once per location. You can hide all deprecated warnings by passing in “ignore”, see https://docs.python.org/3/library/warnings.html#warning-filter for more information.
  • use_3d_viewer (bool) – Specifies whether to display a 3D view of Cozmo’s understanding of the world in a window. Note that if both this and use_viewer are set then the 2D camera view will render in an OpenGL window instead of a TkView window.
  • show_viewer_controls (bool) – Specifies whether to draw controls on the view.
  • exit_on_connection_error (bool) – Specify whether the program should exit on connection error or should an error be raised. Default to true.
cozmo.setup_basic_logging(general_log_level=None, protocol_log_level=None, protocol_log_messages='all', target=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>, deprecated_filter='default')

Helper to perform basic setup of the Python logging machinery.

The SDK defines two loggers:

  • logger (“cozmo.general”) - For general purpose information about events within the SDK; and
  • logger_protocol (“cozmo.protocol”) - For low level communication messages between the device and the SDK.

Generally only logger is interesting.

Parameters:
  • general_log_level (str) – ‘DEBUG’, ‘INFO’, ‘WARN’, ‘ERROR’ or an equivalent constant from the logging module. If None then a value will be read from the COZMO_LOG_LEVEL environment variable.
  • protocol_log_level (str) – as general_log_level. If None then a value will be read from the COZMO_PROTOCOL_LOG_LEVEL environment variable.
  • protocol_log_messages (list) – The low level messages that should be logged to the protocol log. Defaults to all. Will read from the COMZO_PROTOCOL_LOG_MESSAGES if available which should be a comma separated list of message names (case sensitive).
  • target (object) – The stream to send the log data to; defaults to stderr
  • deprecated_filter (str) – The filter for any DeprecationWarning messages. This is defaulted to “default” which shows the warning once per location. You can hide all deprecated warnings by passing in “ignore”, see https://docs.python.org/3/library/warnings.html#warning-filter for more information.
exception cozmo.CozmoSDKException

Base class of all Cozmo SDK exceptions.

exception cozmo.SDKShutdown

Raised when the SDK is being shut down

exception cozmo.StopPropogation

Raised by event handlers to prevent further handlers from being triggered.

exception cozmo.AnimationsNotLoaded

Raised if an attempt is made to play a named animation before animations have been received.

exception cozmo.ActionError

Base class for errors that occur with robot actions.

exception cozmo.ConnectionError

Base class for errors regarding connection to the device.

exception cozmo.ConnectionAborted

Raised if the connection to the device is unexpectedly lost.

exception cozmo.ConnectionCheckFailed

Raised if the connection check has failed.

exception cozmo.NoDevicesFound

Raised if no devices connected running Cozmo in SDK mode

exception cozmo.SDKVersionMismatch(message, sdk_version, sdk_app_version, app_version, *args)

Raised if the Cozmo SDK version is not compatible with the software running on the device.

app_version = None

The version of the App that was detected, and is incompatible, in Major.Minor.Patch format.

Type:str
sdk_app_version = None

The version of the App that this SDK is compatible with in Major.Minor.Patch format.

Type:str
sdk_version = None

The SDK version number in Major.Minor.Patch format. See SDK vs. App Versions for which App version is compatible with each SDK version.

Type:str
exception cozmo.NotPickupable

Raised if an attempt is made to pick up or place an object that can’t be picked up by Cozmo

exception cozmo.CannotPlaceObjectsOnThis

Raised if an attempt is made to place an object on top of an invalid object

exception cozmo.RobotBusy

Raised if an attempt is made to perform an action while another action is still running.

exception cozmo.InvalidOpenGLGlutImplementation

Raised by opengl viewer if no valid GLUT implementation available.