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.2.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.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ozobot_actors-0.3.2.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.2.tar.gz
Algorithm Hash digest
SHA256 5eabb62bd9ab393463c149de055f0bd4e716e8c98a3c575d8c9283375a1553de
MD5 3c3c1dcfdc4f4267e3a7969a23a0627d
BLAKE2b-256 51ce8349ee6971993b8d45980e6192cbf61aae792beb8658f088f4d05179cd6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ozobot_actors-0.3.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: ozobot_actors-0.3.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 83d66213b259a94154766300c491189738265beb23a9069028adc3115bbbbba5
MD5 bf3a3d44230a26f1a66fd7c904d36910
BLAKE2b-256 f7bf0219e19e0a296732f718cfb624146fa5f7ddf2fcedd8b0bf7c9f1880389d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ozobot_actors-0.3.2-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