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¶
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.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.
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:
- 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.
- 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])
- 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:
- 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:
- 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:
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.
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:
- 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.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:
- 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.
- Robobo.readColorBlob(color)[source]¶
- Reads the last detected blob of the indicated color.See also:
setActiveBlobs
.
- 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)
- 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.
- 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).See also:
startFaceDetection
.
- Robobo.readFaceSensor()[source]¶
- Reads the last face detected by Robobo.See also:
startFaceDetection
.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:
- Robobo.whenAFaceIsLost(callback)[source]¶
- Configures the callback that is called when a face is lost.See also:
startFaceDetection
.- 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.See also:
startFaceDetection
.- 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.See also:
startFaceDetection
.
- 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).See also:
startObjectRecognition
.
- Robobo.readDetectedObject()[source]¶
- Reads the last object detected by Robobo.See also:
startObjectRecognition
.- Returns:
The object.
- Return type:
- Robobo.whenAnObjectIsDetected(callback)[source]¶
- Configures the callback that is called when an object is detected.See also:
startObjectRecognition
.- 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:
- 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:
- 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.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:
- 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:
- Robobo.readFlingDistance()[source]¶
Reads the length of the last fling detected by Robobo.
- Returns:
The length of the fling in pixels.
- Return type:
- Robobo.readFlingTime()[source]¶
Reads the duration of the last fling detected by Robobo.
- Returns:
The duration of the fling in milliseconds.
- Return type:
- 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:
- Robobo.readAccelerationSensor()[source]¶
Reads the acceleration sensor.
- Returns:
The acceleration read.
- Return type:
- Robobo.readTapSensor()[source]¶
Reads the data on the tap sensor.
- Returns:
The data read.
- Return type:
- 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).See also:
stopLaneDetection
,setLaneColorInversion
,readLaneBasic
,readLanePro
,whenALaneBasicDetected
,whenALaneProDetected
.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).See also:
startLaneDetection
.
- Robobo.readLaneBasic()[source]¶
- Reads the last detected basic lane (straight lines).See also:
startLaneDetection
.- Returns:
The lane read.
- Return type:
- Robobo.readLanePro()[source]¶
- Reads the last detected pro lane (Degree 2 polynomials).See also:
startLaneDetection
.- Returns:
The pro lane read.
- Return type:
- 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).See also:
startLaneDetection
.- 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.See also:
startLaneDetection
.- 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.See also:
startLaneDetection
.- 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:
- 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).See also:
startArUcoTagDetection
.- 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).See also:
startArUcoTagDetection
.
- Robobo.readArucoTags()[source]¶
- Reads the last set of ARuco tags detected by RoboboSee also:
startArUcoTagDetection
.
- Robobo.whenArucoTagIsDetected(callback)[source]¶
- Configures the callback that is called when a Tag is detected.See also:
startArUcoTagDetection
.- Parameters:
callback (fun) – The callback function to be called.
- Robobo.whenArucoTagAppears(callback)[source]¶
- Configures the callback that is called when a new Tag is detected.See also:
startArUcoTagDetection
.- Parameters:
callback (fun) – The callback function to be called.
- Robobo.whenArucoTagDisappears(callback)[source]¶
- Configures the callback that is called when a Tag is lost.See also:
startArUcoTagDetection
.- 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).See also:
startLineDetection
.
- Robobo.readLine()[source]¶
- Reads the last detected line.See also:
startLineDetection
.- Returns:
The line read.
- Return type:
- Robobo.whenALineIsDetected(callback)[source]¶
- Configures the callback that is called when a line is detected.See also:
startLineDetection
.- 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).See also:
stopSpeechDetection
.
- 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.See also:
startSpeechDetection
.- Returns:
The object.
- Return type:
Speech
- Robobo.whenSpeechDetected(callback)[source]¶
- Configures the callback that is called when speech is detected.See also:
startSpeechDetection
.- 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 falseRegistered phrases won’t get cleared if this is toggled offThis change is persistent (see: Persistent changes).See also:
startSpeechDetection
.- 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 moduleRegistered phrases can be retrieved with
readRegisteredSpeechPhrases
.This change is persistent (see: Persistent changes).See also:startSpeechDetection
.- 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 previouslyRegistered phrases can be retrieved with
readRegisteredSpeechPhrases
.This change is persistent (see: Persistent changes).See also:startSpeechDetection
.- Parameters:
phrase (string) – Phrase string to be removed.
- Robobo.readRegisteredSpeechPhrases()[source]¶
- Reads the list of registered speech phrases.See also:
startSpeechDetection
.