Skip to content

Search the documentation

Kit
Firmware

robot

Smart Car

The MoBot Smart Car: every part of the robot is reached through this object, robot.

This page is for the Smart Car, on firmware 3.0. Click a class in the table to see what it can do. See also: the Smart Car kit, its examples and the names that changed from 2.x.

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.left_motor One drive motor of the robot (left_motor or right_motor); speeds are in percent. Motor (can be None)
robot.right_motor One drive motor of the robot (left_motor or right_motor); speeds are in percent. Motor (can be None)
robot.servo1 A servo motor on one of the robot’s servo plugs; angles are in degrees, 0 to 180. Servo (can be None)
robot.servo2 A servo motor on one of the robot’s servo plugs; angles are in degrees, 0 to 180. Servo (can be None)
robot.servo3 A servo motor on one of the robot’s servo plugs; angles are in degrees, 0 to 180. Servo (can be None)
robot.servo4 A servo motor on one of the robot’s servo plugs; angles are in degrees, 0 to 180. Servo (can be None)
robot.servos A list of Servo objects. Each item can be None. list of Servo (can be None, and so can each item)
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)
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.color_sensor Measures how much red, green and blue light comes back from a surface. A small white lamp lights the surface, and filters in front of the sensor sort the colours. ColorSensor (can be None)
robot.compass Tells which way the robot is facing, in degrees. It feels the Earth’s magnetic field, like a compass needle. Compass (can be None)
robot.battery Measures the battery’s voltage, which drops as the battery empties. Battery (can be None)
robot.joystick1 Reads how far the stick is pushed, left to right (x()) and forward to back (y()). Joystick (can be None)
robot.joystick2 Reads how far the stick is pushed, left to right (x()) and forward to back (y()). Joystick (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:

  1. You have to switch it on first.
  2. 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 stays None.
  3. The part is not fitted. robot.battery: the early Smart Car units that have the L298N motor driver have no battery sensor, so robot.battery stays None on them.

To be safe, check before you use a part:

if robot.led1 is not None:
robot.led1.on()

The robot’s Bluetooth name, as the MoBot app shows it.

robot.name: str

Read only.

Used in examples: Name your robot, then drive it

The robot’s mode number: 255 is Programmable (your program), the others are the app’s modes.

robot.mode: int

Read only.

Gives the robot a new Bluetooth name (text, not empty); it is kept after power-off.

robot.set_name(name)

Used in examples: Name your robot, then drive it

Switches on the four servo plugs, robot.servo1 to robot.servo4 (also the list robot.servos).

robot.enable_servos()

Used in examples: Servo arm and joystick

Switches on the two joysticks, robot.joystick1 and robot.joystick2 (they share pins with the line sensor).

robot.enable_joysticks()

Used in examples: Servo arm and joystick

These functions are not part of robot. Import them at the top of your program:

from mobot import map_range, sleep_ms

map_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) -> float

Used in examples: Name your robot, then drive it

Waits ms milliseconds; inside a built-in mode it is also where the mode can be stopped.

sleep_ms(ms)

The built-in songs for buzzer.play_song(), by name (from indicators import SONGS).

SONGS: Dict[str, str]

Used in examples: Find north, Song and lights