Glossary

Bluetooth

Wireless technology used to communicate with Ozobot directly from PC, phone or tablet.

Look here for more detailed info.

Cooperative scheduling

Type of scheduling without preemption. Look here for more detailed info. If you would like to see how this scheduling is implemented in Ozobot, you can have a look at ozobot.asyncio module.

Coroutines

Routine which is capable of remembering its internal state. It does not need a call stack to carry its internal state (Stack-less coroutines). It can be terminated at one point and continues at the same point with the next call.

Cooperative scheduling is usually based on Python coroutines with asyncio module used for scheduling orchestration.

Garbage Collector

As Python does not have a deallocation function unlike languages such as C or C++, there is a system called garbage collector. This system is responsible for finding Python objects which are not in use and releasing them to free memory. The influence of this functionality is very important especially for Python running directly inside the robot, as collection and deallocation of memory may take some time. Sometimes, it is beneficial to tweak this process from outside by Python module gc.

Look here for more detailed info.

OzoBlockly

One of the possible languages which may be used to program ozobot. Language comes from Google blockly project and is modified to be able to generate code for ozobot. See OzoBlockly web page for more info.

Ozobot

Everyone already knows this nice guy ;-)

Python

Python is a popular programming language aimed at ability to solve algorithmic tasks in an efficient and simple way. This programming language may be present on your PC, can be running in your web browser or can even run in tiny embedded devices such as some Ozobot models.

Look here for more detailed info.

Pyodide

Pyodide is a web variant of Python. This variant of python runs directly inside a web browser and communicates with the robot over Bluetooth.

Documentation legend

This part of documentation makes only links with brief explanation of some tags used inside documentation.

Any type

As Python resolves types in runtime, it may happen that a function returns or accepts any argument type. In this case it does not matter if the argument is int, str or something else … it can be anything.

Optional type

Python also supports the possibility to define some arguments just optionally. Argument can be used, or some default value is used, or it may even happen that there is no default value defined.

def my_generator(cnt = 8):  # cnt argument is optional.
    a = 1                   # When it is omitted, then value 8 is used
    for i in range(cnt):
        yield a
        a *= 2

Type type

This looks like a typo in this chapter name, however, it’s true that type definition in python is also an object and can be accessed in runtime.

>>> def my_new_iterable(tp):
...     return tp(i for i in range(6))
...
>>> print(my_new_iterable(list))
[0, 1, 2, 3, 4, 5]
>>> print(my_new_iterable(tuple))
(0, 1, 2, 3, 4, 5)

Iterable type

Iterable type in Python is a type which can be used as an iterator in a for cycle. Iterable type is e.g. returned by function range(). Also, some basic types such as list or tuple are iterators. A special kind of iterable types are python generators.

for i in ( 1, 2, 4, 8, 16 ):                    # Tuple is iterable type.
    print('iteration of tuple', i)

for i in range(6):                              # Function range returns generator
    print('iteration of range generator', i)    # which can be used in a for cycle.

def my_generator(cnt):
    a = 1
    for i in range(cnt):
        yield a
        a *= 2

for i in  my_generator(5):                      # Generator is iterable as well
    print('iteration of my generator', i)       # This generator allows to get the same numbers
                                                # in a for cycle as does my_iterable1

When an iterable type appears in documentation, its argument is the type of expected elements obtained during iteration. For example iterable ( int | float ) means that the tuple may contain integers or floats (or both).

Sequence type

Sequence type is an iterable type which also knows its length. Typical sequence types are e.g. list, tuple, bytes or str.

List type

List in documentation means basic Python list, like in the following example:

my_list_1 = [ 1, 2, 'hello', 'list' ]   # Creates list containing values 1, 2, 'hello', 'list'
my_list_2 = [ a for a in range(6)   ]   # Creates list containing values 0, 1, 2, 3, 4, 5

Just note that list is a type of sequence, so it means that it is iterable with defined length.

Where list type appears in documentation, its argument is the type of expected list elements. For example list ( int | float ) means that the list may contain integers or floats (or both), e.g. like [ 1, 2, 3.5, 8.2 ].

Tuple type

Tuple is a type similar to list, but it’s more simple and more efficient to use. However unlike list it also hs its own limitations, the most visible being the fact that tuple is like a “constant” list. This means that once it is created, you can not change its items and its size.

my_tuple_1 = ( 1, 2, 'hello', 'list' )    # Creates list containing values 1, 2, 'hello', 'list'
my_tuple_2 = tuple( a for a in range(6) ) # Creates list containing values 0, 1, 2, 3, 4, 5

Just note that tuple is a type of sequence, so it means that it is iterable with defined length.

When tuple type appears in documentation, its argument is the type of expected tuple elements. For example, tuple ( int | float ) means that the tuple may contain integers or floats (or both), e.g. like ( 1, 2, 3.5, 8.2 ).

Named tuple type

Named tuple is a type similar to tuple (we can even say that it’s derived from it), but it has the additional feature that each member can be accessed also by its name.

>>> from ozobot.collections import namedtuple
>>> MyTuple = namedtuple('MyTuple', ('member_1', 'member_2'))
>>> my_tuple = MyTuple( 1, 2 )
>>> print('{} == {}'.format(my_tuple[0], my_tuple.member_1))
1 == 1
>>> print('{} == {}'.format(my_tuple[1], my_tuple.member_2))
2 == 2

Function type

In Python everything is represented by objects. Functions and class methods are not an exception.

def my_callback(num):
    print('My number is', num)


def my_caller(function):
    for i in range(10):
        function(i)


# We can use function as an argument of other function
my_caller(my_callback)

When you see a function tag in documentation, you can see it either without any arguments (arguments or return are not specified), or you can see which arguments are expected and what the function shall return. For example, a function expecting one int and one float and returning str will be shown like function (int, float) → str.

Coroutine type

Coroutines as functions are also represented by a custom type which is often used by Cooperative scheduling in Python. Such routine may represent some task or subtask in scheduler:

from ozobot import get_robot, asyncio, Lights, SurfaceColor

# This is a coroutine representing a task to be running in scheduler
async def task(delay_ms):
    bot    = get_robot(coro = True)
    lights = ((Lights.FRONT_1, 0),
              (Lights.FRONT_2, 1),
              (Lights.FRONT_3, 2),
              (Lights.FRONT_4, 3),
              (Lights.FRONT_5, 4))
    colors = (ozobot.SurfaceColor.BLACK,
              ozobot.SurfaceColor.BLACK,
              ozobot.SurfaceColor.BLACK,
              ozobot.SurfaceColor.BLACK,
              ozobot.SurfaceColor.BLACK,
              ozobot.SurfaceColor.RED,
              ozobot.SurfaceColor.YELLOW,
              ozobot.SurfaceColor.GREEN,
              ozobot.SurfaceColor.BLUE,
              ozobot.SurfaceColor.MAGENTA)
    cnt    = len(colors)

    for i in range(cnt * 4):
        for l in lights:
            await bot.light_effects.aset_light_color(colors[(l[1] + i) % cnt], l[0])

        await asyncio.sleep_ms(delay_ms)

    await bot.light_effects.aset_light_color(ozobot.SurfaceColor.BLACK)


# Here we get the coroutine itself and give it to scheduler for running
my_task = task(300)

asyncio.run(my_task)