Programming the mBot robot


9780594655602_p1_v7_s550x406My personal experiences programming the Makeblock mBot robot. I’m investigating this robot in order to use it as a tool for teaching technology and programming at an elementary school.

The mBot robot can be programmed with the Makeblock editor an application based on Scratch from MIT Media Lab. The editor and example programs can be downloaded from http://www.mblock.cc/. There are also other options such as on online web browser application and apps for Android and the iPad.

Getting started

mbotconnect
I first downloaded the editor on my laptop and installed the software. Now the robot has to be connected to your laptop with a USB cable, wifi connection or Bluetooth. The robot  needs to be connected in order to send commands, receive data and upload programs. The easiest approach when getting started is to use a USB cable.

mbotconnection1-3

You can now verify that your connection is ok. The application title on top says “Serial Port Connected” and a green light can be seen.

 

 

Programming the robot

gif-en-1Now the robot is connected we can start programming. The robot can be programmed with a set of robot programming instructions. You will find these when you click on “Robots”. My first impression is that these are designed for robot hobbyist but not for children. There are more than 50 instructions and some only work when you own the required robot sensor. Another confusing item is the “mBot Program” block. A natural response is to use this block and hope that the robot responds. But nothing happens at all.

The robot can be programmed in two modes: interactive mode and by compiling and uploading the program to the robot. The interactive mode is more suitable for children. It allows interactive trial and error interaction with the robot. You build some code, click the green start flag and the robot will execute your code. The downside is that the robot has to communicate over a relative slow connection and will require more time to react. The compile and run method allows for very advanced robot programming but it is too complicated for beginners and it takes about a minute to upload the new program. This can be frustrating for children. So my advice is to start in interactive mode.

My first robot program

IMG_1198

Blinking

Click to enlarge

I will now show you how to make a simple program. My first robot program is a blinking light. You can create this program by moving the blocks with your mouse. You turn on led lamps wait a second, turn them them off wait a second. The technicalities here are that the LED color can only be set with an RGB color code.

I would prefer some command like “turn on LEFT light with RED color”.  So my idea is to design a more compact and user friendly instruction set for the robot.

In a follow up experiment extended the previous program and created a Robocop police car. I want lights flashing red and blue and a the police siren howling:

parallel

Now something interesting happened. The program has two “When clicked” events and i expected two activities running at the same time: Light flashing and siren howling. The lights flash quickly with 0.3 second delay so every 0.6 second a new cycle and the siren is on “Double” beat speed so the pitch changes constantly at a lower pace then the lights. But when we execute this program the robot lights flash very slooowwwww. What happens is that the robot can only do only thing at the same time. Therefore the lights flash in the same pace as the slowest action. This is a limitation of the robot and there are more.

Spinning around without a tutu

IMG_1200In this experiment i wanted to see how the robot moves and how to use its line sensor. The line sensor is located under the robot and looks down to detect a black line. I wanted to find out how to make the robot turn 90 degrees. There is no command to do that, you have to program it all by yourself. The motors should run in opposite direction for some short period of time. In order to achieve that i need to know how much time it takes for the robot to make a turn. In my experiment the robot spins around and detects a black line. I bought a white plank, black tape and some paper. The computer now commands the robot to spin around and measures the time to of each turn by detecting the crossing of the black line. The results are plotted on the screen.

spinning

As you can see the graph looks a bit funny. The line should be straight but it is wobbling. This means that the time between each crossing of the line is not constant. This is cause by the robot sliding over the paper. The robot does not makes its turn in one place but it spins and slides a bit at the same time. The graph shows the results of 45 line crossings.

The robot was a bit off-line but i was too. I now realize that my original goal was to make the robot turn 90 degrees and I ended up with an advanced robot ballet dance registration program.

What i have learned

From my experiments i have learned:

  • Robot programming can be done and its fun to do
  • It requires an trial and error approach
  • The interactive programming mode has my preference
  • The instruction set of the robot is fairly large and complex
  • Programs can get quite big and hard to read (need a solution)
  • There are some technical issues with timing and executing multiple actions at the same time

botTalkI want to improve the robot instruction set and make it smaller and easy to use. For this i’m working on an extension that I call  RoboCode.

The code for this blog post can be found on github at: https://github.com/Tauvic/Technology-at-school/

And there is still more to do:

    • Basic moves
      • Determine robot velocity (how fast can it drive forward).
      • Can it drive backward?
      • How can i make a left/right turn
      • Can i make a decent 90 degrees turn
      • Turn around
      • How about a sudden stop
  • Advanced moves
    • How to follow a line
    • How to detect crossings and junctions
    • How to take a left or right turn and follow the line
  • How to detect and avoid obstacles

robot-learning

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s