Thymio#

class pyenki.Thymio2.IRCommEvent#

This event is created each time a message is received by at least one proximity sensor. The sensors that do not receive the message, have the corresponding payloads and intensities set to zero.

rx_value#

The received message payload (readonly)

Type:

int

payloads#

An array of 7 integer payloads, one for each sensors (readonly). The first 5 entries are from frontal sensors ordered from left to right. The last two entries are from rear sensors ordered from left to right.

Type:

IntArray1D

intensities#

An array of 7 integer intensities, one for each sensors (readonly). The first 5 entries are from frontal sensors ordered from left to right. The last two entries are from rear sensors ordered from left to right.

Type:

IntArray1D

enum pyenki.Thymio2.Button(value)#

Identify one of the five touch button of the Thymio2.

Valid values are as follows:

CENTER = <Button.CENTER: 0>#
FORWARD = <Button.FORWARD: 1>#
BACKWARD = <Button.BACKWARD: 2>#
LEFT = <Button.LEFT: 3>#
RIGHT = <Button.RIGHT: 4>#
class pyenki.Thymio2#

Bases: DifferentialWheeled, PhysicalObject

A DifferentialWheeled Thymio2 robot.

Example:

>>> import pyenki
>>> thymio = pyenki.Thymio2()
>>> thymio.position = (3.2, 5.6)
>>> thymio.angle = 1.3
>>> # Spin the robot on itself
>>> thymio.motor_left_target = 10.2
>>> thymio.motor_right_target = -10.2
>>> # Switch the top LED yellow
>>> thymio.set_led_top(0.5, 0.5, 0.0)
>>> thymio.prox_values
array([   0.        ,    0., ...
prox_values#

An array of 7 proximity sensor readings, one for each sensors (readonly). The first 5 entries are from frontal sensors ordered from left to right. The last two entries are from rear sensors ordered from left to right.

Type:

Array1D

prox_distances#

A list of 7 distances between proximity sensor and nearest obstancle, one for each sensors; please note that this value would not directly be accessible by a real robot (readonly). The first 5 entries are from frontal sensors ordered from left to right. The last two entries are from rear sensors ordered from left to right.

Type:

Array1D

prox_comm_tx#

The integer payload to be sent. The real robot can only send 11 bits, therefore to be compliant we should limit the value between 0 and 2047.

Type:

int

prox_comm_enabled#

Enable/disable proximity communication.

Type:

bool

prox_comm_events#

A list of events, one for every received message during the last control step (readonly).

Type:

list[IRCommEvent]

ground_values#

An array of 2 ground sensor readings, one for each sensors (readonly)

Type:

Array1D

button_touch_callback#

An optional function called when button touch events happen with the same arguments as pyenki.Thymio2.on_button_touch().

Type:

Callable[[Thymio2, Thymio2.Button], None] | None

leds_buttons#

list[float]: The intensities of the 4 buttons LEDs.

leds_circle#

list[float]: The intensities of the 8 circle LEDs.

leds_prox#

list[float]: The intensities of the 8 proximity LEDs.

led_left_red#

float: The intensity of the left red LED.

led_left_blue#

float: The intensity of the left blue LED.

led_right_red#

float: The intensity of the right red LED.

led_right_blue#

float: The intensity of the right blue LED.

buttons#

list[bool]: Whether the buttons are being pressed.

__init__() None#

Constructs an instance

get_led_bottom_left() Annotated[list[float], 'FixedSize(3)']#

Reads the bottom left RGB LED color

Returns:

the value of the [red, blue, green] channels

Return type:

list[float]

get_led_bottom_right() Annotated[list[float], 'FixedSize(3)']#

Reads the bottom left RGB LED color

Returns:

the value of the [red, blue, green] channels

Return type:

list[float]

get_led_buttons(index: SupportsInt) float#

Reads one of four button LEDs

Parameters:

index (int) – the index of the LED (between 0 and 3)

Returns:

the intensity between 0 and 1.

Return type:

float

get_led_circle(index: SupportsInt) float#

Reads one of 8 circle LEDs

Parameters:

index (int) – the index of the LED (between 0 and 7)

Returns:

the intensity between 0 and 1.

Return type:

float

get_led_prox(index: SupportsInt) float#

Reads one of 8 proximity LEDs

Parameters:

index (int) – the index of the LED (between 0 and 7)

Returns:

the intensity between 0 and 1.

Return type:

float

get_led_top() Annotated[list[float], 'FixedSize(3)']#

Reads the top RGB LED color

Returns:

the value of the [red, blue, green] channels

Return type:

list[float]

on_button_touch(index: pyenki.Thymio2.Button) None#

Called after a button is touched.

Can be overridden by sub-classes to react to button touch events. Alternatively, users can assign a callback as button_touch_callback.

Parameters:

index (int) – The button being touched.

set_led_bottom_left(red: SupportsFloat = 0, green: SupportsFloat = 0, blue: SupportsFloat = 0) None#

Control the bottom left RGB LED color

Parameters:
  • red (float) – the value of the red channel

  • green (float) – the value of the green channel

  • blue (float) – the value of the blue channel

set_led_bottom_right(red: SupportsFloat = 0, green: SupportsFloat = 0, blue: SupportsFloat = 0) None#

Control the bottom right RGB LED color

Parameters:
  • red (float) – the value of the red channel

  • green (float) – the value of the green channel

  • blue (float) – the value of the blue channel

set_led_buttons(index: SupportsInt, value: SupportsFloat) None#

Control the four button LEDs

Parameters:
  • index (int) – the index of the LED. Set to -1 to control all LEDs.

  • value (float) – the desired intensity between 0 and 1.

set_led_circle(index: SupportsInt, value: SupportsFloat) None#

Control the 8 circle LEDs

Parameters:
  • index (int) – the index of the LED. Set to -1 to control all LEDs.

  • value (float) – the desired intensity between 0 and 1.

set_led_prox(index: SupportsInt, value: SupportsFloat) None#

Control the 8 proximity LEDs

Parameters:
  • index (int) – the index of the LED. Set to -1 to control all LEDs.

  • value (float) – the desired intensity between 0 and 1.

set_led_top(red: SupportsFloat = 0, green: SupportsFloat = 0, blue: SupportsFloat = 0) None#

Control the top RGB LED color

Parameters:
  • red (float) – the value of the red channel

  • green (float) – the value of the green channel

  • blue (float) – the value of the blue channel

touch_button(button: pyenki.Thymio2.Button) None#

Touches one of the buttons on top of the robot.

Parameters:

index (int) – the index of the button