Aseba Adapters#

class pyenki.adapters.Thymio2AsebaAdapter#

Exposes an interface that mimics the Aseba interface of the Thymio, where

  • Aseba variables x.y.z are exposed as Python properties x_y_z

  • Aseba functions x.y.z are exposed as Python methods call_x_y_z with the same number of integer arguments.

Note

This adapter does not implement Aseba events, which is the primary interface of Aseba controllers. Instead, it allows to write procedural controllers, which, although structurally different, can be functionally equivalent.

For example, we can mimic the following Aseba piece of code

call leds.top(32, 0, 0)
if prox.horizontal[2] > 2000 then
    motor.left.target = 123
else
    motor.left.target = 0
end

with

# Create a Thymio
thymio = pyenki.Thymio2()
# Wrap it in the Aseba-like interface
aseba = Thymio2AsebaAdapter(thymio)

aseba.update()

# Use a similar API
aseba.call_leds_top(32, 0, 0)
if aseba.prox_horizontal[2] > 2000:
    aseba.motor_left_target = 123
else
    aseba.motor_left_target = 0
end

aseba.actuate()

Like Aseba, it keeps the most-recent received proximity communication message in prox.comm.rx._payloads, prox.comm.rx._intensities, and prox.comm.rx. In addition, it records in prox_comm_buffer the list of messages received in the last update step.

__init__(thymio: Thymio2) None#

Constructs a new instance.

Parameters:

thymio – The robot

actuate() None#

Forwards the commands to the robots. Should be called after setting Aseba variables in a control step.

apply(control: Callback[P], *args: P.args, **kwargs: P.kwargs) None#

Applies a control, preceding with update() and postponing with actuate().

Parameters:
  • control – The control

  • args – The control arguments

  • kwargs – The control keywords arguments

call__leds_set(*args: int) None#
call_leds_bottom_left(*values: int) None#
call_leds_bottom_right(*values: int) None#
call_leds_buttons(*values: int) None#
call_leds_circle(*values: int) None#
call_leds_prox_h(*values: int) None#
call_leds_prox_v(*values: int) None#
call_leds_rc(*values: int) None#
call_leds_sound(*values: int) None#
call_leds_temperature(*values: int) None#
call_leds_top(*values: int) None#
call_prox_comm_enable(*values: int) None#
call_sound_duration(*args: int) None#
call_sound_freq(*args: int) None#
call_sound_play(*args: int) None#
call_sound_record(*args: int) None#
call_sound_replay(*args: int) None#
call_sound_system(*args: int) None#
make_controller(behavior: Behavior) Controller#

Creates a controller that applies a behavior using apply().

Parameters:

behavior – The behavior

Returns:

The controller

set_behavior(behavior: Behavior) None#

Creates a controller with make_controller() and sets the robot’s pyenki.PhysicalObject.control_step_callback to it.

Parameters:

behavior (Behavior) – The behavior

update() None#

Updates the Aseba variables. Should be called before reading them in a control step.

property prox_comm_buffer: list[tuple[int, list[int]]]#