eXperiBot Python API

Version 2.0

A Python programming interface for the eXperiBot learning robot from Cornelsen Experimenta.

Since the eXperiBot uses MicroPython as its programming language, not all Python 3 features are available.

Found a bug or missing a feature you need? Please let us know via experibot@cornelsen.de. We’re happy to help!

References

Examples

Import the experibot module.

>>> from experibot import *

Import the experibot module and create a Powerbrain instance for controlling the Powerbrain module – e.g. to play a note.

>>> from experibot import *
>>> powerbrain = Powerbrain()
>>> powerbrain.play_note()
class LedColor:

eXperiBot — Module LED color

The LedColor class contains constants for all assignable LED colors of eXperiBot modules.

Attributes
  • BLUE: Constant for referencing the module LED color blue.
  • YELLOW: Constant for referencing the module LED color yellow.
  • GREEN: Constant for referencing the module LED color green.
  • WHITE: Constant for referencing the module LED color white.
  • LIGHT_BLUE: Constant for referencing the module LED color light blue.
  • PURPLE: Constant for referencing the module LED color purple.
class Note:

Note

The Note class contains constants for all available notes the Powerbrain module can play.

Attributes
  • C6 (1047Hz): Constant for referencing the note C6.
  • B5 (988Hz): Constant for referencing the note B5 (or H5 in German notation).
  • AS5 (932Hz): Constant for referencing the note A♯5 (or Ais5 in German notation).
  • A5 (880Hz): Constant for referencing the note A5.
  • GS5 (831Hz): Constant for referencing the note G♯5 (or Gis5 in German notation).
  • G5 (784Hz): Constant for referencing the note G5.
  • FS5 (740Hz): Constant for referencing the note F♯5 (or Fis5 in German notation).
  • F5 (698Hz): Constant for referencing the note F5.
  • E5 (659Hz): Constant for referencing the note E5.
  • DS5 (622Hz): Constant for referencing the note D♯5 (or Dis5 in German notation).
  • D5 (587Hz): Constant for referencing the note D5.
  • CS5 (554Hz): Constant for referencing the note C♯5 (or Cis5 in German notation).
  • C5 (523Hz): Constant for referencing the note C5.
  • B4 (494Hz): Constant for referencing the note B4 (or H4 in German notation).
  • AS4 (466Hz): Constant for referencing the note A♯4 (or Ais4 in German notation).
  • A4 (440Hz): Constant for referencing the note A4.
  • GS4 (415Hz): Constant for referencing the note G♯4 (or Gis4 in German notation).
  • G4 (392Hz): Constant for referencing the note G4.
  • FS4 (370Hz): Constant for referencing the note F♯4 (or Fis4 in German notation).
  • F4 (349Hz): Constant for referencing the note F4.
  • E4 (330Hz): Constant for referencing the note E4.
  • DS4 (311Hz): Constant for referencing the note D♯4 (or Dis4 in German notation).
  • D4 (294Hz): Constant for referencing the note D4.
  • CS4 (277Hz): Constant for referencing the note C♯4 (or Cis4 in German notation).
  • C4 (262Hz): Constant for referencing the note C4.
class PowerbrainAxis:

Powerbrain — Axis

The PowerbrainAxis class contains constants for all available axes of the Powerbrain module.

Attributes
  • X: Constant for referencing the X axis of the Powerbrain module.
  • Y: Constant for referencing the Y axis of the Powerbrain module.
  • Z: Constant for referencing the Z axis of the Powerbrain module.
class PowerbrainButton:

Powerbrain — Button

The PowerbrainButton class contains constants for all available buttons of the Powerbrain module.

Attributes
  • A: Constant for referencing the A button of the Powerbrain module.
  • B: Constant for referencing the B button of the Powerbrain module.
  • C: Constant for referencing the C button of the Powerbrain module.
  • MINUS: Constant for referencing the minus button of the Powerbrain module. Alias for the A button.
  • ACTION: Constant for referencing the action button of the Powerbrain module. Alias for the B button.
  • PLUS: Constant for referencing the plus button of the Powerbrain module. Alias for the C button.
class Powerbrain:

Powerbrain

An instance of the Powerbrain class can be used to control the Powerbrain module.

References

You can find more information on the Powerbrain module in the knowledge base.

Examples

Create a Powerbrain instance for controlling a Powerbrain module and assign it to a variable named powerbrain.

>>> powerbrain = Powerbrain()
AXIS = <class 'PowerbrainAxis'>

The PowerbrainAxis class containing constants for all available axes of the Powerbrain module.

BUTTON = <class 'PowerbrainButton'>

The PowerbrainButton class containing constants for all available buttons of the Powerbrain module.

def wait(self, duration: int = 1000):

Powerbrain — Wait

Halts further code execution for a given duration.

Parameters
  • duration (int (optional)): The duration for which to halt further code execution, in milliseconds. Must not be lower than 0ms. Defaults to 1000ms if omitted.
Raises
  • Invalid parameter values (TypeError or ValueError): If the provided parameter value has an invalid type or is out of range.
Examples

Halt further code execution for the default duration of 1000ms.

>>> powerbrain.wait()

Halt further code execution for 500ms.

>>> powerbrain.wait(500)
def play_note(self, note: int = 1047, duration: int = 1000):

Powerbrain — Play note

Plays the given note for the given duration and halts further code execution until the time has elapsed.

Parameters
  • note (int (optional)): The note to play. See Note for available notes. Defaults to Note.C6 if omitted.
  • duration (int (optional)): The duration for which to play the note, in milliseconds. The method will halt further code execution until the time has elapsed. Must be greater than 0ms. Defaults to 1000ms if omitted.
Raises
  • Invalid parameter values (TypeError or ValueError): If the provided parameter values have an invalid type or are out of range.
Examples

Play the default note C6 for the default duration of 1000ms.

>>> powerbrain.play_note()

Play the note A4 for 500ms.

>>> powerbrain.play_note(Note.A4, 500)
def start_play_note(self, note: int = 1047, duration: None | int = None):

Powerbrain — Start playing note

Starts playing the given note indefinitely or for the given duration without halting further code execution.

Parameters
  • note (int (optional)): The note to play. See Note for available notes. Defaults to Note.C6 if omitted.
  • duration (int (optional)): The duration for which to play the note, in milliseconds. Must be greater than 0ms. If omitted, the note will be played indefinitely until another sound starts playing, it is stopped with stop_sound(), or the end of the program is reached.
Raises
  • Invalid parameter values (TypeError or ValueError): If the provided parameter values have an invalid type or are out of range.
Examples

Play the default note C6 indefinitely without halting further code execution.

>>> powerbrain.start_play_note()

Play the note A4 for 500ms without halting further code execution.

>>> powerbrain.start_play_note(Note.A4, 500)
def play_frequency(self, frequency: int = 1000, duration: int = 1000):

Powerbrain — Play frequency

Plays the given frequency for the given duration and halts further code execution until the time has elapsed.

Parameters
  • frequency (int (optional)): The frequency to play, in Hz. Must be greater than 0Hz. The recommended frequency range is 50Hz to 7000Hz. Defaults to 1000Hz if omitted.
  • duration (int (optional)): The duration for which to play the frequency, in milliseconds. The method will halt further code execution until the time has elapsed. Must be greater than 0ms. Defaults to 1000ms if omitted.
Raises
  • Invalid parameter values (TypeError or ValueError): If the provided parameter values have an invalid type or are out of range.
Examples

Play the default frequency of 1000Hz for the default duration of 1000ms.

>>> powerbrain.play_frequency()

Play a frequency of 440Hz for 500ms.

>>> powerbrain.play_frequency(440, 500)
def start_play_frequency(self, frequency: int = 1000, duration: None | int = None):

Powerbrain — Start playing frequency

Starts playing the given frequency indefinitely or for the given duration without halting further code execution.

Parameters
  • frequency (int (optional)): The frequency to play, in Hz. Must be greater than 0Hz. The recommended frequency range is 50Hz to 7000Hz. Defaults to 1000Hz if omitted.
  • duration (int (optional)): The duration for which to play the frequency, in milliseconds. Must be greater than 0ms. If omitted, the frequency will be played indefinitely until another sound starts playing, it is stopped with stop_sound(), or the end of the program is reached.
Raises
  • Invalid parameter values (TypeError or ValueError): If the provided parameter values have an invalid type or are out of range.
Examples

Play the default frequency of 1000Hz indefinitely without halting further code execution.

>>> powerbrain.start_play_frequency()

Play a frequency of 440Hz for 500ms without halting further code execution.

>>> powerbrain.start_play_frequency(440, 500)
def stop_sound(self):

Powerbrain — Stop sound

Stops any sound that is currently playing.

Examples

Stop any sound that is currently playing.

>>> powerbrain.stop_sound()
def terminate_program(self):

Powerbrain — Terminate program

Terminates the currently running program.

Notes

After this method is called, no further code will be executed.

Raises
  • System exit (SystemExit): Always raised to terminate the currently running program.
Examples

Terminate the currently running program.

>>> powerbrain.terminate_program()
def button_is_pressed(self, button: str) -> bool:

Powerbrain — Button is pressed

Returns whether a specific button of the Powerbrain module is currently pressed.

Parameters
  • button (str): The button of the Powerbrain module to check. See PowerbrainButton for available buttons.
Returns
  • bool: True if the specified button is currently pressed, False otherwise.
Raises
  • Invalid parameter value (ValueError): If the provided button is invalid.
Examples

Check whether the A button of the Powerbrain module is currently pressed.

>>> powerbrain.button_is_pressed(Powerbrain.BUTTON.A)

Check whether the action button of the Powerbrain module is currently pressed.

>>> powerbrain.button_is_pressed(Powerbrain.BUTTON.ACTION)
def get_acceleration(self, axis: None | str = None) -> list[float] | float:

Powerbrain — Get acceleration

Returns the current acceleration of the Powerbrain module’s gyroscope sensor.

Parameters
  • axis (str (optional)): The axis of the Powerbrain module to return the acceleration for. See PowerbrainAxis for available axes. If omitted, the acceleration of all axes will be returned.
Returns
  • [float, float, float] or float: The current acceleration of the Powerbrain module’s gyroscope sensor, in g (gravity), where 1g corresponds to the standard gravitational acceleration (gravity on Earth) of ≈ 9.80665m/s². If axis is omitted, a list of three values will be returned, where the first value is the acceleration of the X axis, the second value is the acceleration of the Y axis, and the third value is the acceleration of the Z axis. If axis is provided, a single value will be returned for the specified axis.
Raises
  • Invalid parameter value (ValueError): If the provided axis is invalid.
Examples

Get the current acceleration of all axes.

>>> powerbrain.get_acceleration()

Get the current acceleration of the X axis.

>>> powerbrain.get_acceleration(Powerbrain.AXIS.X)
def get_angular_velocity(self, axis: None | str = None) -> list[float] | float:

Powerbrain — Get angular velocity

Returns the current angular velocity of the Powerbrain module’s gyroscope sensor.

Parameters
  • axis (str (optional)): The axis of the Powerbrain module to return the angular velocity for. See PowerbrainAxis for available axes. If omitted, the angular velocity of all axes will be returned.
Returns
  • [float, float, float] or float: The current angular velocity of the Powerbrain module’s gyroscope sensor, in degrees per second. If axis is omitted, a list of three values will be returned, where the first value is the angular velocity of the X axis, the second value is the angular velocity of the Y axis, and the third value is the angular velocity of the Z axis. If axis is provided, a single value will be returned for the specified axis.
Raises
  • Invalid parameter value (ValueError): If the provided axis is invalid.
Examples

Get the current angular velocity of all axes.

>>> powerbrain.get_angular_velocity()

Get the current angular velocity of the Z axis.

>>> powerbrain.get_angular_velocity(Powerbrain.AXIS.Z)
def get_program_execution_time(self) -> int:

Powerbrain — Get program execution time

Returns the execution time of the currently running program.

Returns
  • int: The execution time of the currently running program, in milliseconds.
Examples

Get the execution time of the currently running program.

>>> powerbrain.get_program_execution_time()
def get_uptime(self) -> int:

Powerbrain — Get uptime

Returns the time elapsed since the eXperiBot was powered on.

Returns
  • int: The time elapsed since the eXperiBot was powered on, in milliseconds.
class MotorDrivingDirection:

Motor — Driving direction

The MotorDrivingDirection class contains constants for all available driving directions of the Motor module.

Attributes
  • FORWARD: Constant for referencing the forward driving direction of the Motor module.
  • BACKWARD: Constant for referencing the backward driving direction of the Motor module.
class MotorDrivingSpeed:

Motor — Driving speed

The MotorDrivingSpeed class contains constants for all available driving speeds of the Motor module.

Attributes
  • SLOW: Constant for referencing the slow driving speed of the Motor module.
  • AVERAGE: Constant for referencing the average driving speed of the Motor module.
  • FAST: Constant for referencing the fast driving speed of the Motor module.
class MotorAxle:

Motor — Axle

The MotorAxle class contains constants for all available axles of the Motor module.

Attributes
  • RED: Constant for referencing the red axle of the Motor module.
  • BLUE: Constant for referencing the blue axle of the Motor module.
  • RED_AND_BLUE: Constant for referencing both the red and blue axle of the Motor module.
class Motor:

Motor

An instance of the Motor class can be used to control a specific Motor module connected to the eXperiBot.

Parameters
  • led_color (str (optional)): The LED color of the Motor module to control. The first available Motor module will be used if omitted. See LedColor for available LED colors.
Raises
  • Module not found (ModuleNotFoundError): If no Motor module with the specified led_color is connected to the eXperiBot.
References

You can find more information on the Motor module in the knowledge base.

Examples

Create a Motor instance for controlling a Motor module with a blue LED connected to the eXperiBot and assign it to a variable named motor_blue.

>>> motor_blue = Motor(LedColor.BLUE)

Create a Motor instance for controlling any Motor module connected to the eXperiBot and assign it to a variable named motor.

>>> motor = Motor()
Motor(led_color: str | None = None)
DIRECTION = <class 'MotorDrivingDirection'>

The MotorDrivingDirection class containing constants for all available driving directions of the Motor module.

SPEED = <class 'MotorDrivingSpeed'>

The MotorDrivingSpeed class containing constants for all available driving speeds of the Motor module.

AXLE = <class 'MotorAxle'>

The MotorAxle class containing constants for all available axles of the Motor module.

def drive( self, direction: str = 'forward', duration: int = 2000, speed: str = 'average'):

Motor — Drive

Instructs the Motor module to drive in a specific direction at a given speed for a given duration.

Notes

The Motor module uses the Powerbrain’s gyroscope to stabilize its travel path.

Parameters
  • direction (str (optional)): The driving direction of the Motor module. See MotorDrivingDirection for available driving directions. Defaults to Motor.DIRECTION.FORWARD if omitted.
  • duration (int (optional)): The duration for which the Motor module should drive in the specified direction, in milliseconds. Must not be lower than 1ms. The method will halt further code exection until the time has elapsed. Defaults to 2000ms if omitted.
  • speed (str (optional)): The driving speed of the Motor module. See MotorDrivingSpeed for available driving speeds. Defaults to Motor.SPEED.AVERAGE if omitted.
Raises
  • Invalid parameter values (TypeError or ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Motor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Drive the Motor module motor_blue forward for 2000ms at average speed.

>>> motor_blue.drive()

Drive the Motor module motor_blue backward for 1000ms.

>>> motor_blue.drive(Motor.DIRECTION.BACKWARD, 1000)

Drive the Motor module motor_blue forward for 2000ms at fast speed.

>>> motor_blue.drive(speed = Motor.SPEED.FAST)
def drive_curve( self, angle: int = 90, radius: int = 15, direction: str = 'forward', speed: str = 'average'):

Motor — Drive curve

Instructs the Motor module to drive in a curve to a specific angle at a given speed and radius.

Notes

The Motor module uses the Powerbrain’s gyroscope to stabilize its travel path.

Parameters
  • angle (int (optional)): The target angle to drive to, in degrees. Must be between -360° and 360° (both inclusive), where positive values indicate a clockwise rotation and negative values indicate a counterclockwise rotation. Defaults to 90° if omitted.
  • radius (int (optional)): The radius of the curve to drive, in centimeters. Must be greater than 0cm. Defaults to 15cm if omitted.
  • direction (str (optional)): The driving direction of the Motor module. See MotorDrivingDirection for available driving directions. Defaults to Motor.DIRECTION.FORWARD if omitted.
  • speed (str (optional)): The driving speed of the Motor module. See MotorDrivingSpeed for available driving speeds. Defaults to Motor.SPEED.AVERAGE if omitted.
Raises
  • Invalid parameter values (TypeError or ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Motor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Drive the Motor module motor_blue forward in a clockwise curve of 90° with a radius of 15cm.

>>> motor_blue.drive_curve()

Drive the Motor module motor_blue forward in a counterclockwise curve of 180° with a radius of 30cm.

>>> motor_blue.drive_curve(-180, 30)

Drive the Motor module motor_blue backward in a clockwise curve of 45° with a radius of 20cm.

>>> motor_blue.drive_curve(45, 20, Motor.DIRECTION.BACKWARD)

Drive the Motor module motor_blue forward in a clockwise curve of 90° with a radius of 15cm at fast speed.

>>> motor_blue.drive_curve(speed = Motor.SPEED.FAST)
def turn(self, angle: int = 90, speed: str = 'average'):

Motor — Turn

Instructs the Motor module to rotate on the spot to a specific angle at a given speed.

Notes

The Motor module uses the Powerbrain’s gyroscope to stabilize its rotation.

Parameters
  • angle (int (optional)): The target angle to turn to, in degrees. Must be between -360° and 360° (both inclusive), where positive values indicate a clockwise rotation and negative values indicate a counterclockwise rotation. Defaults to 90° if omitted.
  • speed (str (optional)): The turning speed of the Motor module. See MotorDrivingSpeed for available driving speeds. Defaults to Motor.SPEED.AVERAGE if omitted.
Raises
  • Invalid parameter values (TypeError or ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Motor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Turn the Motor module motor_blue clockwise by 90° at average speed.

>>> motor_blue.turn()

Turn the Motor module motor_blue counterclockwise by 180°.

>>> motor_blue.turn(-180)

Turn the Motor module motor_blue clockwise by 45° at slow speed.

>>> motor_blue.turn(45, Motor.SPEED.SLOW)
def set_speed( self, axle_red: int | None = 50, axle_blue: int | None = 50, duration: int | None = None):

Motor — Set speed

Instructs the Motor module to set the speed of its axles to a specific value for a given duration.

Parameters
  • axle_red (int or None (optional)): The speed of the red axle, in percent. Must be between -100% and 100% (both inclusive), where negative values indicate a backward driving direction. Alternatively, None can be provided to keep the current speed of the red axle. Defaults to 50% if omitted.
  • axle_blue (int or None (optional)): The speed of the blue axle, in percent. Must be between -100% and 100% (both inclusive), where negative values indicate a backward driving direction. Alternatively, None can be provided to keep the current speed of the blue axle. Defaults to 50% if omitted.
  • duration (int (optional)): The duration for which the Motor module should drive at the specified speed, in milliseconds. If set, the method will halt further code exection until the time has elapsed. If omitted, the method will return immediately and the Motor module will keep the speed of both axles until it receives another instruction.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range, or if both axle_red and axle_blue are set to None.
  • Module not responding (ModuleNotRespondingError): If the Motor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Set the speed of both axles of the Motor module motor_blue to 50%.

>>> motor_blue.set_speed()

Let the Motor module motor_blue rotate on the spot by setting the speed of the red axle to 100% and the speed of the blue axle to -100%.

>>> motor_blue.set_speed(100, -100)

Set the speed of the red axle of the Motor module motor_blue to 75% for 1000ms and keep the current speed of the blue axle.

>>> motor_blue.set_speed(75, None, 1000)
def stop(self, axle: str = 'red_and_blue'):

Motor — Stop

Instructs the Motor module to stop any ongoing movement of the given axle(s).

Parameters
  • axle (str (optional)): The axle(s) of the Motor module to stop. See MotorAxle for available axles. Defaults to Motor.AXLE.RED_AND_BLUE if omitted.
Raises
  • Invalid parameter value (ValueError): If the provided axle is invalid.
  • Module not responding (ModuleNotRespondingError): If the Motor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Stop any movement of both axles of the Motor module motor_blue.

>>> motor_blue.stop()

Stop any movement of the red axle of the Motor module motor_blue.

>>> motor_blue.stop(Motor.AXLE.RED)
class Pivot:

Pivot

An instance of the Pivot class can be used to control a specific Pivot module connected to the eXperiBot.

Parameters
  • led_color (str (optional)): The LED color of the Pivot module to control. The first available Pivot module will be used if omitted. See LedColor for available LED colors.
Raises
  • Module not found (ModuleNotFoundError): If no Pivot module with the specified led_color is connected to the eXperiBot.
References

You can find more information on the Pivot module in the knowledge base.

Examples

Create a Pivot instance for controlling a Pivot module with a blue LED connected to the eXperiBot and assign it to a variable named pivot_blue.

>>> pivot_blue = Pivot(LedColor.BLUE)

Create a Pivot instance for controlling any Pivot module connected to the eXperiBot and assign it to a variable named pivot.

>>> pivot = Pivot()
Pivot(led_color: str | None = None)
def turn_to(self, angle: int = 0, speed: int = 50, wait: bool = True) -> None:

Pivot — Turn to

Instructs the Pivot module to turn to a specific angle at a given speed.

Parameters
  • angle (int (optional)): The target angle to turn to, in degrees. Must be between -90° and 90° (both inclusive), where 0° is the center position. Defaults to 0° if omitted.
  • speed (int (optional)): The speed at which the Pivot module should turn, in percent. Must be between 1% and 100% (both inclusive). Defaults to 50% if omitted.
  • wait (bool (optional)): If True, the method will halt further code exection until the target angle has been reached. If False, the method will return immediately and the Pivot module will hold its position on the target angle until it receives another instruction or is released with stop(). Holding the position continuously consumes energy. Defaults to True if omitted.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Pivot module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Turn the Pivot module pivot_blue to its center position of 0°.

>>> pivot_blue.turn_to()

Turn the Pivot module pivot_blue to an angle of 90°.

>>> pivot_blue.turn_to(90)

Turn the Pivot module pivot_blue to an angle of 90° with a speed of 100%.

>>> pivot_blue.turn_to(90, 100)

Turn the Pivot module pivot_blue to an angle of 90° with a speed of 100% and return immediately without waiting for the target angle to be reached.

>>> pivot_blue.turn_to(90, 100, False)
def stop(self) -> None:

Pivot — Stop

Instructs the Pivot module to stop any ongoing movement and no longer hold its position.

Raises
  • Module not responding (ModuleNotRespondingError): If the Pivot module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Stop any movement of the Pivot module pivot_blue.

>>> pivot_blue.stop()
def get_angle(self) -> int:

Pivot — Get angle

Returns the current angle of the Pivot module.

Returns
  • int: The current angle of the Pivot module, in degrees. Will be between -90° and 90° (both inclusive), where 0° is the center position.
Raises
  • Module not responding (ModuleNotRespondingError): If the Pivot module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Get the current angle of the Pivot module pivot_blue.

>>> pivot_blue.get_angle()
class Twister:

Twister

An instance of the Twister class can be used to control a specific Twister module connected to the eXperiBot.

Parameters
  • led_color (str (optional)): The LED color of the Twister module to control. The first available Twister module will be used if omitted. See LedColor for available LED colors.
Raises
  • Module not found (ModuleNotFoundError): If no Twister module with the specified led_color is connected to the eXperiBot.
References

You can find more information on the Twister module in the knowledge base.

Examples

Create a Twister instance for controlling a Twister module with a blue LED connected to the eXperiBot and assign it to a variable named twister_blue.

>>> twister_blue = Twister(LedColor.BLUE)

Create a Twister instance for controlling any Twister module connected to the eXperiBot and assign it to a variable named twister.

>>> twister = Twister()
Twister(led_color: str | None = None)
def turn_to(self, angle: int = 0, speed: int = 50, wait: bool = True) -> None:

Twister — Turn to

Instructs the Twister module to turn to a specific angle at a given speed.

Parameters
  • angle (int (optional)): The target angle to turn to, in degrees. Must be between -90° and 90° (both inclusive), where 0° is the center position. Defaults to 0° if omitted.
  • speed (int (optional)): The speed at which the Twister module should turn, in percent. Must be between 1% and 100% (both inclusive). Defaults to 50% if omitted.
  • wait (bool (optional)): If True, the method will halt further code exection until the target angle has been reached. If False, the method will return immediately and the Twister module will hold its position on the target angle until it receives another instruction or is released with stop(). Holding the position continuously consumes energy. Defaults to True if omitted.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Twister module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Turn the Twister module twister_blue to its center position of 0°.

>>> twister_blue.turn_to()

Turn the Twister module twister_blue to an angle of 90°.

>>> twister_blue.turn_to(90)

Turn the Twister module twister_blue to an angle of 90° with a speed of 100%.

>>> twister_blue.turn_to(90, 100)

Turn the Twister module twister_blue to an angle of 90° with a speed of 100% and return immediately without waiting for the target angle to be reached.

>>> twister_blue.turn_to(90, 100, False)
def stop(self) -> None:

Twister — Stop

Instructs the Twister module to stop any ongoing movement and no longer hold its position.

Raises
  • Module not responding (ModuleNotRespondingError): If the Twister module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Stop any movement of the Twister module twister_blue.

>>> twister_blue.stop()
def get_angle(self) -> int:

Twister — Get angle

Returns the current angle of the Twister module.

Returns
  • int: The current angle of the Twister module, in degrees. Will be between -90° and 90° (both inclusive), where 0° is the center position.
Raises
  • Module not responding (ModuleNotRespondingError): If the Twister module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Get the current angle of the Twister module twister_blue.

>>> twister_blue.get_angle()
class Grabber:

Grabber

An instance of the Grabber class can be used to control a specific Grabber module connected to the eXperiBot.

Parameters
  • led_color (str (optional)): The LED color of the Grabber module to control. The first available Grabber module will be used if omitted. See LedColor for available LED colors.
Raises
  • Module not found (ModuleNotFoundError): If no Grabber module with the specified led_color is connected to the eXperiBot.
References

You can find more information on the Grabber module in the knowledge base.

Examples

Create a Grabber instance for controlling a Grabber module with a blue LED connected to the eXperiBot and assign it to a variable named grabber_blue.

>>> grabber_blue = Grabber(LedColor.BLUE)

Create a Grabber instance for controlling any Grabber module connected to the eXperiBot and assign it to a variable named grabber.

>>> grabber = Grabber()
Grabber(led_color: str | None = None)
def open(self, wait: bool = True) -> None:

Grabber — Open

Instructs the Grabber module to open its arms.

Parameters
  • wait (bool (optional)): If True, the method will halt further code exection until the Grabber module’s arms have fully opened. If False, the method will return immediately. Defaults to True if omitted.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Grabber module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Open the arms of the Grabber module grabber_blue and wait until they have fully opened.

>>> grabber_blue.open()

Open the arms of the Grabber module grabber_blue and return immediately without waiting for them to fully open.

>>> grabber_blue.open(False)
def close(self, wait=True) -> None:

Grabber — Close

Instructs the Grabber module to close its arms.

Parameters
  • wait (bool (optional)): If True, the method will halt further code exection until the Grabber module’s arms have closed. If False, the method will return immediately. Defaults to True if omitted.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Grabber module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Close the arms of the Grabber module grabber_blue and wait until they have closed.

>>> grabber_blue.close()

Close the arms of the Grabber module grabber_blue and return immediately without waiting for them to close.

>>> grabber_blue.close(False)
def stop(self) -> None:

Grabber — Stop

Instructs the Grabber module to stop any ongoing movement of its arms.

Raises
  • Module not responding (ModuleNotRespondingError): If the Grabber module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Stop any movement of the arms of the Grabber module grabber_blue.

>>> grabber_blue.stop()
class MultisensorRGBChannel:

Multisensor — RGB channel

The MultisensorRGBChannel class contains constants for all available RGB channels of the Multisensor module.

Attributes
  • RED: Constant for referencing the red RGB channel of the Multisensor module.
  • GREEN: Constant for referencing the green RGB channel of the Multisensor module.
  • BLUE: Constant for referencing the blue RGB channel of the Multisensor module.
class MultisensorIRSensor:

Multisensor — IR sensor

The MultisensorIRSensor class contains constants for all available lateral infrared sensors of the Multisensor module.

Attributes
  • LEFT: Constant for referencing the left infrared sensor of the Multisensor module.
  • RIGHT: Constant for referencing the right infrared sensor of the Multisensor module.
class MultisensorPerceivedBrightness:

Multisensor — Perceived brightness

The MultisensorPerceivedBrightness class contains constants for all available perceived brightness values of the Multisensor module.

Attributes
  • BRIGHT: Constant for referencing bright light conditions in front of the Multisensor module.
  • DARK: Constant for referencing dark light conditions in front of the Multisensor module.
class MultisensorDetectableColor:

Multisensor — Detectable color

The MultisensorDetectableColor class contains constants for all available detectable colors of the Multisensor module.

Attributes
  • NONE: Constant for referencing the absence of a detectable color of the Multisensor module.
  • RED: Constant for referencing the red detectable color of the Multisensor module.
  • GREEN: Constant for referencing the green detectable color of the Multisensor module.
  • BLUE: Constant for referencing the blue detectable color of the Multisensor module.
  • YELLOW: Constant for referencing the yellow detectable color of the Multisensor module.
class Multisensor:

Multisensor

An instance of the Multisensor class can be used to control a specific Multisensor module connected to the eXperiBot.

Parameters
  • led_color (str (optional)): The LED color of the Multisensor module to control. The first available Multisensor module will be used if omitted. See LedColor for available LED colors.
Raises
  • Module not found (ModuleNotFoundError): If no Multisensor module with the specified led_color is connected to the eXperiBot.
References

You can find more information on the Multisensor module in the knowledge base.

Examples

Create a Multisensor instance for controlling a Multisensor module with a blue LED connected to the eXperiBot and assign it to a variable named multisensor_blue.

>>> multisensor_blue = Multisensor(LedColor.BLUE)

Create a Multisensor instance for controlling any Multisensor module connected to the eXperiBot and assign it to a variable named multisensor.

>>> multisensor = Multisensor()
Multisensor(led_color: str | None = None)
RGB_CHANNEL = <class 'MultisensorRGBChannel'>

The MultisensorRGBChannel class containing constants for all available RGB channels of the Multisensor module.

IR_SENSOR = <class 'MultisensorIRSensor'>

The MultisensorIRSensor class containing constants for all available infrared sensors of the Multisensor module.

BRIGHTNESS = <class 'MultisensorPerceivedBrightness'>

The MultisensorPerceivedBrightness class containing constants for all available perceived brightness values of the Multisensor module.

COLOR = <class 'MultisensorDetectableColor'>

The MultisensorDetectableColor class containing constants for all available detectable colors of the Multisensor module.

def detects_object(self, sensitivity: int = 100) -> bool:

Multisensor — Detects object

Checks whether the Multisensor module detects an object in front of it.

Parameters
  • sensitivity (int (optional)): The sensitivity value to use for object detection, in percent. Must be between 1% and 200% (both inclusive), where 1% indicates the lowest sensitivity and 200% indicates the highest sensitivity. Defaults to 100% (base sensitivity) if omitted.
Returns
  • bool: True if the Multisensor module detects an object, False if it does not.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Multisensor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Check whether the Multisensor module multisensor_blue detects an object with the base sensitivity.

>>> multisensor_blue.detects_object()

Check whether the Multisensor module multisensor_blue detects an object with the highest sensitivity.

>>> multisensor_blue.detects_object(200)
def detects_color(self, color: str, sensitivity: int = 100) -> bool:

Multisensor — Detects color

Checks whether the Multisensor module detects a specific color.

Parameters
  • color (str): The color to check for. See MultisensorDetectableColor for available detectable colors.
  • sensitivity (int (optional)): The sensitivity value to use for color detection. Must be between 1 and 200 (both inclusive), where 1 indicates the lowest sensitivity and 200 indicates the highest sensitivity. Defaults to 100 (base sensitivity) if omitted.
Returns
  • bool: True if the Multisensor module detects the specified color, False if it does not.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Multisensor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Check whether the Multisensor module multisensor_blue detects the color red.

>>> multisensor_blue.detects_color(Multisensor.COLOR.RED)

Check whether the Multisensor module multisensor_blue detects the color blue with a low sensitivity.

>>> multisensor_blue.detects_color(Multisensor.COLOR.BLUE, 50)
def detects_ambient_light(self, brightness: str = 'bright') -> bool:

Multisensor — Detects ambient light

Checks whether the Multisensor module detects bright or dark ambient light conditions.

Parameters
  • brightness (str (optional)): The brightness to check for. See MultisensorPerceivedBrightness for available brightness values. Defaults to Multisensor.BRIGHTNESS.BRIGHT if omitted.
Returns
  • bool: True if the Multisensor module detects the specified brightness, False if it does not.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Multisensor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Check whether the Multisensor module multisensor_blue detects bright ambient light conditions.

>>> multisensor_blue.detects_ambient_light()

Check whether the Multisensor module multisensor_blue detects dark ambient light conditions.

>>> multisensor_blue.detects_ambient_light(Multisensor.BRIGHTNESS.DARK)
def detects_surface_brightness( self, brightness: str = 'bright', sensor: str | None = None) -> bool | list[bool]:

Multisensor — Detects surface brightness

Checks whether the Multisensor module detects a bright or dark surface with its lateral infrared sensors.

Parameters
  • brightness (str (optional)): The brightness to check for. See MultisensorPerceivedBrightness for available values. Defaults to Multisensor.BRIGHTNESS.BRIGHT if omitted.
  • sensor (str (optional)): The lateral infrared sensor to check for the specified brightness. See MultisensorIRSensor for available sensors. If omitted, results for both sensors will be returned.
Returns
  • bool or [bool, bool]: True if the Multisensor module detects the specified brightness with the specified sensor, False if it does not. If no sensor is specified, a list of two booleans will be returned, where the first boolean indicates whether the left infrared sensor detects the specified brightness and the second boolean indicates whether the right infrared sensor detects the specified brightness.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Multisensor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Check whether both lateral infrared sensors of the Multisensor module multisensor_blue detect a bright surface.

>>> multisensor_blue.detects_surface_brightness()

Check whether both lateral infrared sensors of the Multisensor module multisensor_blue detect a dark surface.

>>> multisensor_blue.detects_surface_brightness(Multisensor.BRIGHTNESS.DARK)

Check whether the left infrared sensor of the Multisensor module multisensor_blue detects a bright surface.

>>> multisensor_blue.detects_surface_brightness(
...   Multisensor.BRIGHTNESS.BRIGHT, Multisensor.IR_SENSOR.LEFT
... )
def get_distance_to_object(self) -> int:

Multisensor — Get distance to object

Returns
  • int: The distance to the an object detected by the Multisensor module’s middle infrared sensor, in percent. Will be between 0% and 100% (both inclusive), where 0% indicates a very close object (approx. 10cm) and 100% indicates a very far object (approx. 30cm or higher).

Is also 100% if no object is detected.

Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Multisensor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Notes

The sensor can detect changes in distance between approximately 10cm and 30cm. Unfortunately, it is not possible to measure the exact distance to objects that are closer than this. However, you can use the get_surface_brightness() function to measure the brightness or reflectivity of very close objects and thereby determine their approximate distance.

Examples

Get the distance to an object detected by the Multisensor module multisensor_blue.

>>> multisensor_blue.get_distance_to_object()
def get_color(self) -> str:

Multisensor — Get color

Returns the color detected by the Multisensor module’s color sensor.

Returns
  • str: The color detected by the Multisensor module’s color sensor. See MultisensorDetectableColor for available detectable colors.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Multisensor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Get the color detected by the Multisensor module multisensor_blue.

>>> multisensor_blue.get_color()
def get_color_intensity(self, rgb_channel: None | str = None) -> list[int] | int:

Multisensor — Get color intensity

Returns the color intensity for the specified RGB channel detected by the Multisensor module’s color sensor.

Parameters
  • rgb_channel (str (optional)): The RGB channel to get the color intensity from. See MultisensorRGBChannel for available RGB channels. If omitted, the color intensity for all RGB channels will be returned.
Returns
  • int or [int, int, int]: The color intensity for the specified RGB channel.. Will be between 0 and 6150 (both inclusive), where 0 indicates no color intensity and 6150 indicates maximum color intensity. If no rgb_channel is specified, a list of three integers will be returned, where the first integer is the color intensity for the red channel, the second integer is the color intensity for the green channel and the third integer is the color intensity for the blue channel.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Multisensor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Get the color intensity of all RGB channels detected by the Multisensor module multisensor_blue.

>>> multisensor_blue.get_color_intensity()

Get the color intensity of the red RGB channel detected by the Multisensor module multisensor_blue.

>>> multisensor_blue.get_color_intensity(Multisensor.RGB_CHANNEL.RED)
def get_ambient_light_intensity(self) -> int:

Multisensor — Get ambient light intensity

Returns the ambient light intensity detected by the Multisensor module.

Returns
  • int: The ambient light intensity detected by the Multisensor module, in percent. Will be between 0% and 100% (both inclusive), where 0% indicates maximum darkness and 100% indicates maximum brightness.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Multisensor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Examples

Get the ambient light intensity detected by the Multisensor module multisensor_blue.

>>> multisensor_blue.get_ambient_light_intensity()
def get_surface_brightness(self, sensor: str | None = None) -> list[int] | int:

Multisensor — Get surface brightness

Returns the surface brightness detected by the Multisensor module’s lateral infrared sensors.

Parameters
  • sensor (str (optional)): The lateral infrared sensor to get the surface brightness from. See MultisensorIRSensor for available sensors. If omitted, the surface brightness for both lateral infrared sensors will be returned.
Returns
  • int or [int, int]: The surface brightness detected by the specified sensor, in percent. Will be between 0% and 100% (both inclusive), where 0% indicates maximum darkness and 100% indicates maximum brightness. If no sensor is specified, a list of two integers will be returned, where the first integer is the surface brightness detected by the left infrared sensor and the second integer is the surface brightness detected by the right infrared sensor.

If the Multisensor module does not detect any surface, the returned value will be 0% for the specified sensor(s).

Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
  • Module not responding (ModuleNotRespondingError): If the Multisensor module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.
Notes

Since infrared sensors measure the reflectivity of surfaces, highly reflective surfaces are detected as particularly bright.

Examples

Get the surface brightness detected by both lateral infrared sensors of the Multisensor module multisensor_blue.

>>> multisensor_blue.get_surface_brightness()

Get the surface brightness detected by the right infrared sensor of the Multisensor module multisensor_blue.

>>> multisensor_blue.get_surface_brightness(Multisensor.IR_SENSOR.RIGHT)
class ModuleNotFoundError(builtins.Exception):

Error — Module not found

Raised when a specific eXperiBot module could not be found.

class ModuleNotRespondingError(builtins.Exception):

Error — Module not responding

Raised when a specific eXperiBot module is not responding, e.g. because it was disconnected from the eXperiBot during program execution.

def map( value: int | float, in_min: int | float, in_max: int | float, out_min: int | float, out_max: int | float) -> int | float:

Map

Maps a value from one range to another.

Parameters
  • value (int or float): The value to map.
  • in_min (int or float): The minimum value of the input range.
  • in_max (int or float): The maximum value of the input range.
  • out_min (int or float): The minimum value of the output range.
  • out_max (int or float): The maximum value of the output range.
Returns
  • int or float: The mapped value.
Raises
  • Invalid parameter values (ValueError): If the provided parameter values have an invalid type or are out of range.
Examples

Map a value of 50 from the range 0 to 100 to the range 0 to 255.

>>> map(50, 0, 100, 0, 255)