Skip to content

Search the documentation

Kit
Firmware

Modes and programs

A Smart Car or a Mini does one thing at a time. What it does is its mode. Your own program runs in one mode only: Programmable.

The Smart Home has no modes. See the Smart Home at the end of this page.

The mode is one number that the robot keeps. It stays the same when you switch the robot off and on, and the robot starts in the mode it was set to.

  • Smart Car: 0 Manual (the app calls it Manual driving), 1 Line follower, 2 Obstacle avoidance, 3 Colour detection, 5 Stay in the Ring, 32 Team building, 255 Programmable.
  • Mini: 0 Manual (the app calls it Manual driving), 1 Programmable Sequence, 2 Piano (the app calls it Piano mode), 3 Police (Police mode), 4 Ambulance (Ambulance mode), 255 Programmable.

In a program, robot.mode tells you the number. 255 is Programmable. The app shows the name: its home screen says “Robot mode:” and the name of the mode. Team building has no tile in the app.

One mode can meet you under two names. The firmware uses the short names above, and so does the line the robot prints, such as “The robot is in Manual mode”. The app and the IDE use the names on the tiles, such as “Manual driving” in the question the IDE asks. They are the same mode.

In the MoBot app, only a tile changes the mode. Opening the Game Pad, the Motor Test or the Settings does not. Closing the app does not either. The IDE can also set the mode, but only after it asks you (see below).

On firmware 2.1.0 and later, the robot waits for you to tap Go in Line follower, Obstacle avoidance, Stay in the Ring and Colour detection (Smart Car), and in Programmable Sequence, Police and Ambulance (Mini). Stop stops it.

In Programmable mode the robot runs the file main.py that is stored on it. If the robot also has a file called boot.py, it runs first, just before main.py. Neither file runs in any other mode.

A new Smart Car starts in Programmable. A new Mini starts in Manual. A Mini does not run your program until it is set to Programmable. You can set it with the Programmable tile in the MoBot app, or you can let the IDE do it, as you will see next.

Your program starts when the robot is in Programmable mode and one of these happens:

  • You switch the robot on.
  • You choose the Programmable tile in the app.
  • You save main.py to the robot from the IDE.

If the robot is in another mode when you save or run from the IDE, the IDE asks a question called Robot mode. It names the mode the robot is in, with the name on the app’s tile. For a robot in Manual driving the question is: “The robot is in Manual driving. Switch it to Programmable to run your program?” The two buttons are Switch to Programmable and Keep Manual driving. Choose Switch to Programmable and the IDE sets the mode for you. Choose Keep Manual driving and your program stays on the robot but does not run.

A mode that has no tile in the app (Team building on the Smart Car), or a mode the IDE could not read, is called “another mode” in the question and on its buttons.

If you keep the mode, the IDE tells you so: “Saved. The robot stays in Manual driving. Your program will run when the robot is set to Programmable.” If Run had not saved anything, the line says “Not run. The robot stays in Manual driving.” instead.

When a robot that has a main.py starts up in another mode, it prints in the terminal: [MOBOT] The robot is in ... mode, so your program is not running. Choose Programmable in the MoBot app.

Run is different from Save. Run sends your program to the robot and starts it at once, without making it the robot’s main.py. On a robot in another mode, Run saves the file first if it is called main.py, and then asks the same question.

The app’s Programmable screen tells you what is going on: “Your program is running”, “Your program has ended”, “Your program stopped because of an error”, or “No program on the robot yet”.

On firmware 2.0.0, the robot restarts every time its mode changes. From firmware 2.1.0 it normally does not. See the firmware changelog.

A program can end in six ways.

How it ends What the robot does next
It reaches its last line The robot stays in Programmable and waits.
It stops with an error The robot prints what MicroPython prints, stays in Programmable and waits.
It calls sys.exit() The robot stays in Programmable and waits.
You press Stop in the IDE The program ends and the computer has the robot.
You choose another mode in the app The firmware interrupts the program and starts the other mode.
You switch the robot off Everything stops.

A program that ended does not start again by itself. Switch the robot off and on, or press Run or Save in the IDE.

What the wheels, lights and sound do when a program ends is on another page: Stopping and leaving outputs. It depends on the firmware version.

If you choose another mode in the app while your program runs, the firmware stops your program as if you had pressed Stop. It gives your program a short moment to finish a finally: block. After about 0.3 seconds it switches the outputs off: the wheels, the lights and the sound. If your program still runs after 1 second, the robot restarts and then goes into the new mode.

A program that swallows the interrupt, which is the stop signal, can keep going, for example one with a bare except: around a loop. A bare except: is an except line with no error name after it. It catches every error, and the stop signal too.

If your program starts a thread and leaves it running, the robot also restarts when you leave Programmable. A thread is a piece of code that runs at the same time as the rest of your program. The robot prints [MODE] the program left a thread running: restarting, because Python cannot stop a thread.

Stop in the IDE is Device ▸ Stop, and the square button next to the terminal. This is what it does.

  1. It sends Ctrl-C three times, 50 milliseconds apart. This ends your program, or takes the robot out of one of the app’s modes.
  2. It then tells the robot to stop its wheels and its buzzer. The terminal shows ■ Stopped.
  3. The robot now waits at the Python prompt. The computer has the robot, and the app can show that the robot was stopped by a computer.

What the lights and the sound do after Stop depends on how the program was started and on the firmware version. See Stopping and leaving outputs.

If the robot does not answer, the terminal says: “The robot did not stop. Press Stop again to restart it.” A second press of Stop within 30 seconds restarts the robot. Your program may have swallowed the interrupt. The restart is never automatic. It plays the robot’s start-up sound, and the phone loses its Bluetooth connection.

A robot on firmware 2.0.0 that is in one of the app’s modes cannot be stopped from the computer. The IDE says so, and it names the mode the same way: “The robot is in Manual driving and this firmware cannot be stopped from the computer. Choose Programmable in the MoBot app, or update the robot.” From firmware 2.1.0 the computer can stop the robot in any mode.

Soft Reset (Device ▸ Soft Reset) restarts the robot.

When the IDE disconnects, a robot that is in one of the app’s modes goes back to that mode. On firmware 2.1.0 and later this needs no restart, and the phone stays connected. A robot in Programmable stays stopped at the prompt, so that a program you stopped does not start again by itself.

If the phone sets a mode while a computer has the robot, the robot restarts into the new mode. The app asks first: “A computer is using this robot. Setting the mode restarts the robot.”

Set the robot to Programmable, then open the Game Pad in the app. Your program receives the stick and the buttons through robot.gamepad. The Game Pad does not change the mode. The example Name your robot, then drive it drives the Smart Car with the Game Pad.

The Smart Home has no modes and no mode runner. It starts up, joins the Wi-Fi it knows, and then runs the main.py stored on it, if there is one. A program you send from the IDE runs at start-up and after a power cut. If your program starts its own web server, it replaces the stock one.