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
  • Actors are put onto the stack as they are registered
  • Selecting an actor puts it on top of the current stack
  • Masking an actor 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.ActorDispatcher()
actors.set_actor_dispatcher(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.2.0.tar.gz (5.2 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.2.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ozobot_actors-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b7a66a0c1ec4ca31d7465dc0bc3ebac06a7f24abfb26ddf049a3bfbf8301244e
MD5 98c34ddac034ba81887253929c79bff8
BLAKE2b-256 bdc0db9292e74f55170c4599401735a009f8254c5000b708626d228eab7a572c

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for ozobot_actors-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5ff4fee2d4e0f0911fb2759fb019a0db8803eec8a1fa21f0e19eb3bbba18d19
MD5 4ce3adcd8fc2f79a43c476176fdb929e
BLAKE2b-256 d471500b1259a2ab09e94961f3d0cf6e8e17c88708255b9b29ab1a3eed027cd0

See more details on using hashes here.

Provenance

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