Skip to main content

Ozobot actor API package providing an alternative way for controling multiple bots

Project description

ozobot-actors

Library that enables to control multiple Ozobot device using a globally defined functions. It mirrors the interface of libraries implementing object oriented control of the individual robots. The library is primarily intended to be used by the Python code generated from Blockly programs, as its semantics follows the actor based use by the Ozobot Editor, but can be used even in projects written from scratch.

See the monorepo for more details.

Installation

The library requires you to list all the robots to be supported, so for example to install Evo support, run pip install ozobot-actors[evo], to install both Ari and Evo support, run pip install ozobot-actors[ari,evo].

The library currently supports:

Usage

The library defines global functions that can control any robot supporting that specific functionality. Targeting a specific robot can be done by using a context manager. When an API function is called, the context is searched for available robot and the function is executed with the first matching robot. The robot selection follows a few simple rules:

  • Actors need to be registered in the dispatcher with dispatcher.add()
  • Actors are put onto the stack as they are registered
  • Selecting an actor with dispatcher.actor() puts it on top of the current stack
  • Masking an actor with dispatcher.mask() removes it from the current stack
  • Stack is searched from the top
  • First robot having the required functionality is used, leaving the stack untouched
import asyncio

from ozobot import actors
from ozobot.actors.linefollower import move
from ozobot.actors.userio import user_io_alert
from ozobot.ari import AriHandle
from ozobot.evo import EvoHandle

dispatcher = actors.new_actor_dispatcher()

async def main() -> None:
    async with EvoHandle(name="OzoEvo-1234abcd") as e1, EvoHandle(name="Ari-ABCD") as a1:
        dispatcher.add("Evo_1", e1)
        dispatcher.add("Ari_1", a1)

        with dispatcher.actor("Ari_1"):  # this puts Ari onto the default stack
            await move(100, 50)  # moves Ari
            await user_io_alert("Hello from Ari!")  # displays message on Ari

            with dispatcher.actor("Evo_1"):  # this puts Evo on top of Ari
                await move(100, 50)  # moves Evo
                await user_io_alert("Hello again from Ari!")  # Ari shows the message, because Evo does not support `user_io_alert`
            # stepping out of the context manager block removes Evo from the top of the stack
            
            await move(-100, 50)  # moves Ari again


if __name__ == "__main__":
    asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ozobot_actors-0.3.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ozobot_actors-0.3.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file ozobot_actors-0.3.0.tar.gz.

File metadata

  • Download URL: ozobot_actors-0.3.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ozobot_actors-0.3.0.tar.gz
Algorithm Hash digest
SHA256 24c1702a6a6658432d92ed4aa3e479797c354e06869afbd80a6739c700eeb781
MD5 85b182a4fa65d24998998c7aeb71c7f7
BLAKE2b-256 7310bcc61534a077f82ec6a3d5673b970f10d98a3bab3b24f596d62bfad77998

See more details on using hashes here.

Provenance

The following attestation bundles were made for ozobot_actors-0.3.0.tar.gz:

Publisher: publish.yml on ozobot/python-libraries

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ozobot_actors-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ozobot_actors-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ozobot_actors-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cd0b0bac036ffa31e744622e19c0c606640deafec8f352d6c1c903445b0ce5a
MD5 bcc8238cbb5fed0f344a8bddb944743f
BLAKE2b-256 7aae319bb00561300cdcbeeb8373392e2b333e1950a4c633235070416741ffff

See more details on using hashes here.

Provenance

The following attestation bundles were made for ozobot_actors-0.3.0-py3-none-any.whl:

Publisher: publish.yml on ozobot/python-libraries

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page