robot
MiniThe MoBot Mini: every part of the robot is reached through this object, robot.
This page is for the Mini, on firmware 3.0. Click a class in the table to see what it can do. See also: the Mini kit, its examples and the names that changed from 2.x.
Attributes
Section titled “Attributes”Every part of the robot is an attribute of robot. The class tells you what the part can do. Read Attributes that can be None to see what “can be None” means.
| Attribute | What it is | Class |
|---|---|---|
robot.bluetooth |
The robot’s Bluetooth link to the MoBot app on your phone. | BLEController |
robot.gamepad |
The Game Pad in the MoBot app on your phone, received over Bluetooth. | Gamepad |
robot.led1 |
One of the robot’s lights (led1 or led2); brightness is in percent, 0 to 100. | Led (can be None) |
robot.led2 |
One of the robot’s lights (led1 or led2); brightness is in percent, 0 to 100. | Led (can be None) |
robot.buzzer |
The robot’s buzzer: it plays songs in the background while your program goes on. | Buzzer (can be None) |
robot.rgb_led |
The robot’s colour light; colours are red, green and blue from 0 to 255, brightness in percent. | RGBLed (can be None) |
robot.left_motor |
One drive motor of the robot (left_motor or right_motor); speeds are in percent. | DRV8833Motor (can be None) |
robot.right_motor |
One drive motor of the robot (left_motor or right_motor); speeds are in percent. | DRV8833Motor (can be None) |
robot.distance_sensor |
Measures how far away something is. It sends out a short burst of ultrasound, a sound too high for us to hear, and times how long the echo takes to come back, like a bat. | DistanceSensor (can be None) |
robot.line_sensor |
Sees a dark line on a light floor. Each eye shines infrared light at the ground and measures how much bounces back: dark surfaces send back less. | LineSensor (can be None) |
Attributes that can be None
Section titled “Attributes that can be None”In the table, a class followed by (can be None) means that the attribute holds either an object of that class or None, which is Python’s word for “nothing”. Written as a type, such an attribute is Optional[...], for example Optional[Led]. If your program uses a part that is None, it stops with an AttributeError. The attributes with no such mark are always there.
A part of the robot is None when:
- You have to switch it on first.
robot.distance_sensor: callrobot.enable_distance_sensor()first.robot.line_sensor: callrobot.enable_line_sensor()first.
- The part did not start. When the robot starts, it sets up its parts one at a time. If a part cannot start, the robot prints a message such as
LED1 init error:and carries on. The attribute staysNone.
To be safe, check before you use a part:
if robot.led1 is not None: robot.led1.on()Properties
Section titled “Properties”robot.name
Section titled “robot.name”The robot’s Bluetooth name, as the MoBot app shows it.
robot.name: strRead only.
robot.mode
Section titled “robot.mode”The robot’s mode number: 255 is Programmable (your program), the others are the app’s modes.
robot.mode: intRead only.
Methods
Section titled “Methods”robot.set_name(name)
Section titled “robot.set_name(name)”Gives the robot a new Bluetooth name (text, not empty); it is kept after power-off.
robot.set_name(name)robot.enable_distance_sensor()
Section titled “robot.enable_distance_sensor()”Switches on the distance sensor, robot.distance_sensor (it shares its two pins with the line sensor).
robot.enable_distance_sensor()Used in examples: Mini eyes
robot.enable_line_sensor()
Section titled “robot.enable_line_sensor()”Switches on the line sensor’s two eyes, robot.line_sensor (they share their pins with the distance sensor).
robot.enable_line_sensor()Used in examples: Mini eyes
Helpers
Section titled “Helpers”These functions are not part of robot. Import them at the top of your program:
from mobot import map_range, sleep_msmap_range(value, in_min, in_max, out_min, out_max)
Section titled “map_range(value, in_min, in_max, out_min, out_max)”Converts a value from one range to another, for example 0-1023 to 0-100; the result is a float.
map_range(value, in_min, in_max, out_min, out_max) -> floatsleep_ms(ms)
Section titled “sleep_ms(ms)”Waits ms milliseconds; inside a built-in mode it is also where the mode can be stopped.
sleep_ms(ms)Constants
Section titled “Constants”The built-in songs for buzzer.play_song(), by name (from indicators import SONGS).
SONGS: Dict[str, str]Used in examples: Jukebox