Robobo.py

Robobo.py is the library used to create programs for the Robobo educational robot in the Python language.

To create a Robobo instance:

from Robobo import Robobo

rob = Robobo ('10.113.36.150')

Parameters:

  • ip: (string) The IP address of the Robobo robot.

Connection methods

Robobo.connect()[source]

Establishes a remote connection with the Robobo indicated by the IP address associated to this instance.

Robobo.disconnect()[source]

Disconnects the library from the Robobo robot.

Base actuation methods

Robobo.moveWheels(rSpeed, lSpeed)[source]

Moves Robobo wheels, each one at the specified speed.

Parameters:
  • rSpeed (int) – Speed factor for the right wheel [-100..100]. Absolute value 100 is the maximum speed reachable, while 0 means no movement. Positive values mean the wheel moves forwards and negative values mean it moves backwards.

  • lSpeed (int) – Speed factor for the left wheel [-100..100]. Absolute value 100 is the maximum speed reachable, while 0 means no movement. Positive values mean the wheel moves forwards and negative values mean it moves backwards.

Robobo.moveWheelsByTime(rSpeed, lSpeed, duration, wait=True)[source]

Moves Robobo wheels during the specified time, each one at the specified speed.

Parameters:
  • rSpeed (int) – Speed factor for the right wheel [-100..100]. Absolute value 100 is the maximum speed reachable, while 0 means no movement. Positive values mean the wheel moves forwards and negative values mean it moves backwards.

  • lSpeed (int) – Speed factor for the left wheel [-100..100]. Absolute value 100 is the maximum speed reachable, while 0 means no movement. Positive values mean the wheel moves forwards and negative values mean it moves backwards.

  • duration (float) – Duration of the movement in seconds (>0). Decimals like 0.2 are allowed.

  • wait (bool) – If true, the instruction is executed in blocking mode. If false, it’s executed in non-blocking mode. For more information, see: Blocking instructions.

Robobo.moveWheelsByDegrees(wheel, degrees, speed)[source]

Moves Robobo wheels by some degrees at the specified speed.

Parameters:
  • wheel (Wheels) – Wheel or wheels to move.

  • degrees (int) – Degrees to move the wheel or wheels (>0).

  • speed (int) – Speed factor for the movement [-100..100]. Absolute value 100 is the maximum speed reachable, while 0 means no movement. Positive values mean the wheel moves forwards and negative values mean it moves backwards.

Robobo.stopMotors()[source]

Stops the movement of the wheels.

Robobo.movePanTo(degrees, speed, wait=True)[source]

Moves the PAN of the base to the specified position at the specified speed.

Parameters:
  • degrees (int) – Position in degress of the PAN [-160..160]. See: Pan positions.

  • speed (int) – Speed factor for the movement [0..100]. 100 is the maximum speed reachable, while 0 means no movement.

  • wait (bool) – If true, the instruction is executed in blocking mode. If false, it’s executed in non-blocking mode. For more information, see: Blocking instructions.

Robobo.moveTiltTo(degrees, speed, wait=True)[source]

Moves the TILT of the base to the specified position at the specified speed.

Parameters:
  • degrees (int) – Position in degrees of the TILT [5..105]. See: Tilt positions.

  • speed (int) – Speed factor for the movement [0..100]. 100 is the maximum speed reachable, while 0 means no movement.

  • wait (bool) – If true, the instruction is executed in blocking mode. If false, it’s executed in non-blocking mode. For more information, see: Blocking instructions.

Robobo.setLedColorTo(led, color)[source]

Set the color of a LED of the base.

Parameters:
  • led (LED) – LED to set the color of.

  • color (Color) – New color of the LED.

Base sensing methods

Robobo.readBatteryLevel(device)[source]

Reads the battery level of the base or the smartphone.

Parameters:

device (string) – One of ‘base’ or ‘phone’.

Returns:

The battery level of the specified device.

Return type:

int

Robobo.readIRSensor(id)[source]

Reads the current value sensed by the specified IR. This value depends on the distance to nearby objects, being larger for shorter distances. This value also depends on ambient conditions, such as the lighting.

Parameters:

id (IR) – The IR to read the value sensed from.

Returns:

The value of the IR read.

Return type:

int

Robobo.readAllIRSensor()[source]

Reads the values of all the IR sensors.

Example of use:

irs = rob.readAllIRSensor()
if irs != []:
    print (irs[IR.FrontR.value])
    print (irs[IR.FrontRR.value])
Returns:

A dictionary returning the values of all the IR sensors of the base. Dictionary keys (string): IR ids (see IR). Dictionary values (float): The value of the IR.

Return type:

dict

Robobo.readWheelPosition(wheel)[source]

Reads the current position of the specified wheel.

Parameters:

wheel (Wheels) – The wheel to read the position of. One of Wheels.L or Wheels.R.

Returns:

The position of the wheel in degrees.

Return type:

int

Robobo.readWheelSpeed(wheel)[source]

Returns the current speed of the specified wheel.

Parameters:

wheel (Wheels) – The wheel to read the position of. One of Wheels.L or Wheels.R

Returns:

The current speed of the wheel [-100..100]. Absolute value 100 is the maximum speed reachable, while 0 means no movement. Positive values mean the wheel moves forwards and negative values mean it moves backwards.

Return type:

int

Robobo.readPanPosition()[source]

Reads the current position of the PAN.

Returns:

The position in degrees, taking values in range [-160..160]. See: Pan positions.

Return type:

int

Robobo.readTiltPosition()[source]

Reads the current position of the TILT.

Returns:

The position in degrees, taking values in range [5..105]. See: Tilt positions.

Return type:

int

Robobo.resetWheelEncoders()[source]

Resets the encoders of the wheels.

Smartphone actuation methods

Robobo.playNote(note, duration, wait=True)[source]

Makes Robobo play a musical note.

Parameters:

note – Note to play index following the Anglo-Saxon notation, allowing 133 possible notes. The following scheme shows the equivalency in the range 48 to 59:

DO

DO#

RE

RE#

MI

FA

FA#

SOL

SOL#

LA

LA#

SI

C

Cs

D

Ds

E

F

Fs

G

Gs

A

As

B

48

49

50

51

52

53

54

55

56

57

58

59

Parameters:
  • duration (float) – Duration of the note in seconds (>0). Decimals like 0.2 are allowed.

  • wait (bool) – If true, the instruction is executed in blocking mode. If false, it’s executed in non-blocking mode. For more information, see: Blocking instructions.

Robobo.playSound(sound)[source]

Makes Robobo play the specified emotion sound.

Parameters:

sound (Sounds) – The emotion sound to play.

Robobo.sayText(speech, wait=True)[source]

Makes Robobo say the specified text.

Parameters:
  • speech (string) – The text to say.

  • wait (bool) – If true, the instruction is executed in blocking mode. If false, it’s executed in non-blocking mode. For more information, see: Blocking instructions.

Robobo.setEmotionTo(emotion)[source]

Changes the emotion showed by the face of Robobo.

Parameters:

emotion (Emotions) – New emotion to show.

Smartphone sensing methods

Robobo.readBatteryLevel(device)[source]

Reads the battery level of the base or the smartphone.

Parameters:

device (string) – One of ‘base’ or ‘phone’.

Returns:

The battery level of the specified device.

Return type:

int

Robobo.setStatusFrequency(frequency)[source]
Sets the frequency of the status messages coming from Robobo. Status messages are filtered by default in order to reduce network bandwidth. A higher frequency reduces the filters, so more status messages are sent and more network bandwidth is used.
This change is persistent (see: Persistent changes).
Parameters:

frequency (StatusFrequency) – New frequency of the status messages.

Robobo.setStreamFps(fps)[source]
Sets the stream fps. These are the number of frames per second sent from the smartphone to the computer. Default value is 60, buf effective value is usually lower (around 20), depending on the smartphone.
This change is persistent (see: Persistent changes).
Parameters:

fps (int) – New upper limit of the stream fps. Takes positive values.

Robobo.setCameraFps(fps)[source]
Sets the camera fps. These are the number of frames per second read by the smartphone camera. Default value is 60, buf effective value is usually lower (around 20), depending on the smartphone.
This change is persistent (see: Persistent changes).
Parameters:

fps (int) – New upper limit of the camera fps. Takes positive values.

Robobo.setFrontCamera()[source]
Makes Robobo use the frontal camera.
This change is persistent (see: Persistent changes).
Robobo.setBackCamera()[source]
Makes Robobo use the back camera.
This change is persistent (see: Persistent changes).
Robobo.startStream()[source]
Starts the camera streaming.
Camera streaming is stopped by default.
This change is persistent (see: Persistent changes).
In order to use this function, it’s neccesary to download the project and follow the instructions from the stream repository.
Robobo.stopStream()[source]
Stops the camera streaming.
Camera streaming is stopped by default.
This change is persistent (see: Persistent changes).
Robobo.startCamera()[source]

Starts the camera.

Robobo.stopCamera()[source]
Stops the camera.
Warning: Other modules depend on the camera, so it’s necessary to start it again to make use of them.
Robobo.readBrightnessSensor()[source]
Reads the ambient light level detected by the smartphone.
Warning: The light sensor may not be available on all the devices.
Returns:

The brightness value in lux. It’s a positive value.

Return type:

int

Robobo.setActiveBlobs(red, green, blue, custom)[source]
Note: Before tracking blobs, it is highly recommended to follow the camera calibration tutorial.
Enables or disables the individual tracking of each color.
By default, green tracking is enabled and the rest are disabled.
Warning: Color tracking is a computationally intensive task, activating all the colors may impact performance.
Parameters:
  • red (bool) – If true, enables red blob tracking.

  • green (bool) – If true, enables green blob tracking.

  • blue (bool) – If true, enables blue blob tracking.

  • custom (bool) – If true, enables custom blob tracking.

Robobo.readColorBlob(color)[source]
Reads the last detected blob of the indicated color.
See also: setActiveBlobs.
Parameters:

color (BlobColor) – Color of the blob.

Returns:

The blob read.

Return type:

Blob

Robobo.readAllColorBlobs()[source]
Reads all the color blob data.
See also: setActiveBlobs.

Example of use:

blobs = rob.readAllColorBlobs()
for key in blobs:
    blob = blobs[key]
    print(blob.color)
    print(blob.posx)
    print(blob.posy)
    print(blob.size)
Returns:

A dictionary returning the individual blob information. Dictionary keys (BlobColor): the possible colors. Dictionary values (Blob): the blobs.

Return type:

dict

Robobo.resetColorBlobs()[source]
Resets the color blob detector. This sets to 0 the attributes of the last color blobs detected, but keeps the enabled and disabled colors the same.
See also: setActiveBlobs.
Robobo.whenANewColorBlobIsDetected(callback)[source]
Configures the callback that is called when a new color blob is detected.
See also: setActiveBlobs.
Parameters:

callback (fun) – The callback function to be called.

Robobo.setAdvancedLostBlobParameters(frames=5, minarea=1000, max_count=1, epsilon=0)[source]
Sets advanced parameters for the blob tracker.
Warning: Only use this function if you know what you are doing. A bad configuration might have unexpected consecuences.
Parameters:
  • frames (int) – Number of frames passed to consider a blob lost.

  • minarea (int) – Minimum area to consdider a Blob as a Blob.

  • max_count (int) – max_count parameter of the termcriteria.

  • epsilon (int) – epsilon parameter of the termcriteria.

Robobo.startFaceDetection()[source]
Starts the face detection.
Face detection is started by default.
This change is persistent (see: Persistent changes).
Robobo.stopFaceDetection()[source]
Stops the face detection.
Face detection is started by default.
This change is persistent (see: Persistent changes).
Robobo.readFaceSensor()[source]
Reads the last face detected by Robobo.

Example of use:

face = robobo.readFaceSensor()
print(face.distance)  #the distance to the person
print(face.posX) # the position of the face in X axis
print(fase.posY) # the position of the face in Y axis
Returns:

The information of the face detected.

Return type:

Face

Robobo.whenAFaceIsLost(callback)[source]
Configures the callback that is called when a face is lost.
Parameters:

callback (fun) – The callback function to be called.

Robobo.whenANewFaceIsDetected(callback)[source]
Configures the callback that is called when a new face is detected.
Parameters:

callback (fun) – The callback function to be called.

Robobo.resetFaceSensor()[source]
Resets the face sensor. After this function, and until a new face is detected, the face sensor will return 0 for each attribute of the face object.
Robobo.startObjectRecognition()[source]
Starts the object recognition.
Object recognition is stopped by default.
This change is persistent (see: Persistent changes).
For more information, check the Object Recognition Wiki.
Robobo.stopObjectRecognition()[source]
Stops the object recognition.
Object recognition is stopped by default.
This change is persistent (see: Persistent changes).
Robobo.readDetectedObject()[source]
Reads the last object detected by Robobo.
Returns:

The object.

Return type:

DetectedObject

Robobo.whenAnObjectIsDetected(callback)[source]
Configures the callback that is called when an object is detected.
Parameters:

callback (fun) – The callback function to be called.

Robobo.readLastNote()[source]

Reads the last note detected by the note sensor.

Returns:

The note read.

Return type:

Note

Robobo.whenANoteIsDetected(callback)[source]

Configures the callback that is called when a new note is detected.

Parameters:

callback (fun) – The callback function to be called.

Robobo.readClapCounter()[source]

Reads the number of claps registered since last reset.

Returns:

The number of claps.

Return type:

int

Robobo.whenClapIsDetected(callback)[source]

Configures the callback that is called when a new clap is detected.

Parameters:

callback (fun) – The callback function to be called.

Robobo.resetClapCounter()[source]

Resets the clap counter.

Robobo.readNoiseLevel()[source]

Reads the SPL (Sound Pressure Level) value, which is a measurement of the ambient noise.

Returns:

The SPL value in decibels.

Return type:

float

Robobo.readFlingAngle()[source]

Reads the last angle detected on the fling sensor. This angle is formed by a horizontal line and the first and last points where the finger touched the screen.

Returns:

The angle detected in degrees.

Return type:

int

Robobo.readFlingDistance()[source]

Reads the length of the last fling detected by Robobo.

Returns:

The length of the fling in pixels.

Return type:

float

Robobo.readFlingTime()[source]

Reads the duration of the last fling detected by Robobo.

Returns:

The duration of the fling in milliseconds.

Return type:

float

Robobo.resetFlingSensor()[source]

Resets the state of the Fling sensor.

Robobo.whenAFlingIsDetected(callback)[source]

Configures the callback that is called when a new fling is detected.

Parameters:

callback (fun) – The callback function to be called.

Robobo.readOrientationSensor()[source]
Reads the orientation sensor.
Warning: This sensor may not be available on all the devices.
Returns:

The orientation read.

Return type:

Orientation

Robobo.readAccelerationSensor()[source]

Reads the acceleration sensor.

Returns:

The acceleration read.

Return type:

Acceleration

Robobo.readTapSensor()[source]

Reads the data on the tap sensor.

Returns:

The data read.

Return type:

Tap

Robobo.resetTapSensor()[source]

Resets the tap sensor value.

Robobo.whenATapIsDetected(callback)[source]

Configures the callback that is called when a new tap is detected.

Parameters:

callback (fun) – The callback function to be called.

Robobo.startLaneDetection()[source]
Starts the lane detection.
Lane detection is stopped by default.
This change is persistent (see: Persistent changes).
For more information, check the Lane Detection Wiki.
Robobo.stopLaneDetection()[source]
Stops the lane detection.
Lane detection is stopped by default.
This change is persistent (see: Persistent changes).
Robobo.readLaneBasic()[source]
Reads the last detected basic lane (straight lines).
Returns:

The lane read.

Return type:

LaneBasic

Robobo.readLanePro()[source]
Reads the last detected pro lane (Degree 2 polynomials).
Returns:

The pro lane read.

Return type:

LanePro

Robobo.setLaneColorInversion(set_on)[source]
Toggles the color inversion for the advanced lane module. Usually, light lanes are detected against a dark background, but it is also possible to detect dark lanes against light backgrounds.
This change is persistent (see: Persistent changes).
Parameters:

set_on (bool) – Boolean to choose if turn it on or off.

Robobo.whenALaneProDetected(callback)[source]
Configures the callback that is called when a pro lane is detected.
Parameters:

callback (fun) – The callback function to be called.

Robobo.whenALaneBasicDetected(callback)[source]
Configures the callback that is called when a basic lane is detected.
Parameters:

callback (fun) – The callback function to be called.

Robobo.startQrTracking()[source]
Starts the QR tracking.
QR tracking is started by default.
This change is persistent (see: Persistent changes).
Robobo.stopQrTracking()[source]
Stops the QR tracking.
QR tracking is started by default.
This change is persistent (see: Persistent changes).
See also: startQrTracking.
Robobo.readQR()[source]
Reads the last detected QR code.
See also: startQrTracking.
Returns:

The QR code read.

Return type:

QRCode

Robobo.whenAQRCodeIsDetected(callback)[source]
Configures the callback that is called when a QR is detected.
See also: startQrTracking.
Parameters:

callback (fun) – The callback function to be called.

Robobo.whenANewQRCodeIsDetected(callback)[source]
Configures the callback that is called when a new QR is detected. A QR is considered to be new if it’s different to the last one detected.
See also: startQrTracking.
Parameters:

callback (fun) – The callback function to be called.

Robobo.whenAQRCodeIsLost(callback)[source]
Configures the callback that is called when a QR is lost.
See also: startQrTracking.
Parameters:

callback (fun) – The callback function to be called.

Robobo.startArUcoTagDetection()[source]
Starts the ArUcoTag detection.
This change is persistent (see: Persistent changes).
For more information, check the ArUco Tag Detection Wiki.
Robobo.setArucoTagSize(size)[source]
Sets the length of the side of the ArUco tag to be detected. It is important that this value fits the real tag size used, because it is used to calculate the distance from Robobo to the tag.
This change is persistent (see: Persistent changes).
Parameters:

size (int) – Size of the side of the ArUco tag in milimiters.

Robobo.stopArUcoTagDetection()[source]
Stops the ArUco tag detection.
This change is persistent (see: Persistent changes).
Robobo.readArucoTag()[source]
Reads the last ArUco Tag detected by Robobo.
Returns:

The Tag.

Return type:

Tag

Robobo.whenArucoTagIsDetected(callback)[source]
Configures the callback that is called when a Tag is detected.
Parameters:

callback (fun) – The callback function to be called.

Robobo.startLineDetection()[source]
Starts the line detection.
Line detection is stopped by default.
This change is persistent (see: Persistent changes).
Robobo.stopLineDetection()[source]
Stops the line detection.
Line detection is stopped by default.
This change is persistent (see: Persistent changes).
Robobo.readLine()[source]
Reads the last detected line.
Returns:

The line read.

Return type:

Lines

Robobo.whenALineIsDetected(callback)[source]
Configures the callback that is called when a line is detected.
Parameters:

callback (fun) – The callback function to be called.

Robobo.startAudioStream()[source]
Starts the microphone streaming.
Microphone streaming is stopped by default.
This change is persistent (see: Persistent changes).
In order to use this function, it’s neccesary to download the project and follow the instructions from the stream repository.
Robobo.stopAudioStream()[source]
Stops the microphone streaming.
Audio streaming is stopped by default.
This change is persistent (see: Persistent changes).
Robobo.startSpeechDetection()[source]
Starts the speech detection.
Speech detection is stopped by default.
This change is persistent (see: Persistent changes).
Robobo.stopSpeechDetection()[source]
Stops the speech detection.
Speech detection is stopped by default.
This change is persistent (see: Persistent changes).
Robobo.readDetectedSpeech()[source]
Reads the last speech message detected by Robobo.
This includes the detected message and the matched registered phrases if any, also indicates if the detected message is final or is still going.
Returns:

The object.

Return type:

Speech

Robobo.whenSpeechDetected(callback)[source]
Configures the callback that is called when speech is detected.
Parameters:

callback (fun) – The callback function to be called.

Robobo.setSpeechDetectionPhraseOnly(set_on)[source]
Toggles the Speech Detection mode to only detect the registered phrases if true or anything if false
Registered phrases won’t get cleared if this is toggled off
This change is persistent (see: Persistent changes).
Parameters:

set_on (bool) – Boolean to choose if turn it on or off.

Robobo.registerSpeechDetectionPhrase(phrase)[source]
Registers a new phrase to be detected by the speech detection module
Registered phrases can be retrieved with readRegisteredSpeechPhrases.
This change is persistent (see: Persistent changes).
Parameters:

phrase (string) – Phrase string to be registered.

Robobo.removeSpeechDetectionPhrase(phrase)[source]
Removes a a phrase from the registered on the speech detection module. Has no effect if the phrase wasn’t registered previously
Registered phrases can be retrieved with readRegisteredSpeechPhrases.
This change is persistent (see: Persistent changes).
Parameters:

phrase (string) – Phrase string to be removed.

Robobo.readRegisteredSpeechPhrases()[source]
Reads the list of registered speech phrases.
Returns:

A list of registered string phrases.

Return type:

list of str

Other methods

Robobo.wait(seconds)[source]

Pauses the program for the specified time. After that time, next instruction is executed.

Parameters:

seconds (float) – Time to wait in seconds (>0). Decimals like 0.2 are allowed.