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()
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.
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.
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.
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 theAbutton.ACTION: Constant for referencing the action button of the Powerbrain module. Alias for theBbutton.PLUS: Constant for referencing the plus button of the Powerbrain module. Alias for theCbutton.
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()
The PowerbrainAxis class containing constants for all available axes of the Powerbrain module.
The PowerbrainButton class containing constants for all available buttons of the Powerbrain module.
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 (
TypeErrororValueError): 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)
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. SeeNotefor available notes. Defaults toNote.C6if 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 (
TypeErrororValueError): 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)
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. SeeNotefor available notes. Defaults toNote.C6if 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 withstop_sound(), or the end of the program is reached.
Raises
- Invalid parameter values (
TypeErrororValueError): 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)
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 (
TypeErrororValueError): 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)
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 withstop_sound(), or the end of the program is reached.
Raises
- Invalid parameter values (
TypeErrororValueError): 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)
Powerbrain — Stop sound
Stops any sound that is currently playing.
Examples
Stop any sound that is currently playing.
>>> powerbrain.stop_sound()
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()
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. SeePowerbrainAxisfor available axes. If omitted, the acceleration of all axes will be returned.
Returns
[float, float, float]orfloat: 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². Ifaxisis 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. Ifaxisis 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)
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. SeePowerbrainAxisfor available axes. If omitted, the angular velocity of all axes will be returned.
Returns
[float, float, float]orfloat: The current angular velocity of the Powerbrain module’s gyroscope sensor, in degrees per second. Ifaxisis 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. Ifaxisis 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)
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()
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.
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.
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.
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. SeeLedColorfor available LED colors.
Raises
- Module not found (
ModuleNotFoundError): If no Motor module with the specifiedled_coloris 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()
The MotorDrivingDirection class containing constants for all available driving directions of the Motor module.
The MotorDrivingSpeed class containing constants for all available driving speeds of the Motor module.
The MotorAxle class containing constants for all available axles of the Motor module.
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. SeeMotorDrivingDirectionfor available driving directions. Defaults toMotor.DIRECTION.FORWARDif 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. SeeMotorDrivingSpeedfor available driving speeds. Defaults toMotor.SPEED.AVERAGEif omitted.
Raises
- Invalid parameter values (
TypeErrororValueError): 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)
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. SeeMotorDrivingDirectionfor available driving directions. Defaults toMotor.DIRECTION.FORWARDif omitted. - speed (
str(optional)): The driving speed of the Motor module. SeeMotorDrivingSpeedfor available driving speeds. Defaults toMotor.SPEED.AVERAGEif omitted.
Raises
- Invalid parameter values (
TypeErrororValueError): 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)
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. SeeMotorDrivingSpeedfor available driving speeds. Defaults toMotor.SPEED.AVERAGEif omitted.
Raises
- Invalid parameter values (
TypeErrororValueError): 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)
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 (
intorNone(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,Nonecan be provided to keep the current speed of the red axle. Defaults to 50% if omitted. - axle_blue (
intorNone(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,Nonecan 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 bothaxle_redandaxle_blueare set toNone. - 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)
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. SeeMotorAxlefor available axles. Defaults toMotor.AXLE.RED_AND_BLUEif 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)
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. SeeLedColorfor available LED colors.
Raises
- Module not found (
ModuleNotFoundError): If no Pivot module with the specifiedled_coloris 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 — 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)): IfTrue, the method will halt further code exection until the target angle has been reached. IfFalse, 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 withstop(). Holding the position continuously consumes energy. Defaults toTrueif 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)
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()
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()
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. SeeLedColorfor available LED colors.
Raises
- Module not found (
ModuleNotFoundError): If no Twister module with the specifiedled_coloris 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 — 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)): IfTrue, the method will halt further code exection until the target angle has been reached. IfFalse, 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 withstop(). Holding the position continuously consumes energy. Defaults toTrueif 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)
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()
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()
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. SeeLedColorfor available LED colors.
Raises
- Module not found (
ModuleNotFoundError): If no Grabber module with the specifiedled_coloris 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 — Open
Instructs the Grabber module to open its arms.
Parameters
- wait (
bool(optional)): IfTrue, the method will halt further code exection until the Grabber module’s arms have fully opened. IfFalse, the method will return immediately. Defaults toTrueif 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)
Grabber — Close
Instructs the Grabber module to close its arms.
Parameters
- wait (
bool(optional)): IfTrue, the method will halt further code exection until the Grabber module’s arms have closed. IfFalse, the method will return immediately. Defaults toTrueif 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)
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()
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.
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.
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.
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.
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. SeeLedColorfor available LED colors.
Raises
- Module not found (
ModuleNotFoundError): If no Multisensor module with the specifiedled_coloris 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()
The MultisensorRGBChannel class containing constants for all available RGB channels of the Multisensor module.
The MultisensorIRSensor class containing constants for all available infrared sensors of the Multisensor module.
The MultisensorPerceivedBrightness class containing constants for all available perceived brightness values of the Multisensor module.
The MultisensorDetectableColor class containing constants for all available detectable colors of the Multisensor module.
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:Trueif the Multisensor module detects an object,Falseif 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)
Multisensor — Detects color
Checks whether the Multisensor module detects a specific color.
Parameters
- color (
str): The color to check for. SeeMultisensorDetectableColorfor 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:Trueif the Multisensor module detects the specified color,Falseif 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)
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. SeeMultisensorPerceivedBrightnessfor available brightness values. Defaults toMultisensor.BRIGHTNESS.BRIGHTif omitted.
Returns
bool:Trueif the Multisensor module detects the specified brightness,Falseif 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)
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. SeeMultisensorPerceivedBrightnessfor available values. Defaults toMultisensor.BRIGHTNESS.BRIGHTif omitted. - sensor (
str(optional)): The lateral infrared sensor to check for the specified brightness. SeeMultisensorIRSensorfor available sensors. If omitted, results for both sensors will be returned.
Returns
boolor[bool, bool]:Trueif the Multisensor module detects the specified brightness with the specified sensor,Falseif it does not. If nosensoris 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
... )
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()
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. SeeMultisensorDetectableColorfor 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()
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. SeeMultisensorRGBChannelfor available RGB channels. If omitted, the color intensity for all RGB channels will be returned.
Returns
intor[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 norgb_channelis 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)
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()
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. SeeMultisensorIRSensorfor available sensors. If omitted, the surface brightness for both lateral infrared sensors will be returned.
Returns
intor[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 nosensoris 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)
Error — Module not found
Raised when a specific eXperiBot module could not be found.
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.
Map
Maps a value from one range to another.
Parameters
- value (
intorfloat): The value to map. - in_min (
intorfloat): The minimum value of the input range. - in_max (
intorfloat): The maximum value of the input range. - out_min (
intorfloat): The minimum value of the output range. - out_max (
intorfloat): The maximum value of the output range.
Returns
intorfloat: 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)