HBM005: An introduction to Robotics with LEGO® MINDSTORMS™ (II)

An introduction to Robotics with LEGO® MINDSTORMS™ (II)

LEGO Mindstorms


So I've got an NXT, but now...

Text and images by Koldo


So I've got an NXT, but now that I've opened the box, where do I start? That is quite a common sensation for those who have no prior experience with robotics: will I be able to make the most of all of this?

The easiest starting point is building and programming the models that come with the set, following all the building and programming steps, and playing with them. When I say playing I mean modify the original programs and observing how the robot reacts to those changes in its behaviour. That is a great way to learn. You can also change the hardware, that is to say, any element of the structure of the robot or of its motor and sensor systems.

If things don't works as expected... don't worry. It's normal. Often things work quite well on the computer, but in real life things don't always work as expected.

And then what?

It isn't always easy to decide on one idea or another and often we can't think up anything. That happens to all of us. We'd love to come up with a brilliant idea no one has had before, something we'd feel really satisfied about. But that doesn't happen every day, so in the meanwhile you may want to do something more conventional or get some ideas from books or the Internet.

One type of robot that provides a lot of opportunities for learning programming is a mobile robot with wheels (or tracks - these are not included with the NXT, but can be found in some other sets and with the RCX). This kind of robot is easy to build and can be used together with several different sensors. One of the simplest could be the one in figure 1[1] instructions for which you can find at Lrobotikas.net.

Before you start building you'll have to take some decisions, the most important of which is deciding what kind of steering mechanism you'll give it. With mobile robots on wheels different systems can be used, like differential steering, the kind of steering used in a tricycle or the steering of a car. Without a doubt you best option is differential steering because of it's simplicity: to motors control two wheels, one on each side; if both turn in the same direction and with the same speed the robot will go forwards or backwards, if the speeds are different the robot will turn (this system is used in the Tribot, one of the original LEGO® models).

LEGO Mindstorms

It's always a good idea to have some basic ideas to develop with the NXT and the basic set and in the following lines some ideas will be proposed. These ideas don't require any complex mechanical design as there is no point in starting out with a very complex construction - you can always do that later on. In the article about LEGO MINDSTORMS™ in the previous edition of HISPABRICK Magazine I pointed out that before writing any code in NXT-G (or any other programming language), it's a good idea to write down what the robot is supposed to do in normal language, using the same words we use normally. To this end we only need to put ourselves in the place of the robot and make an ordered list of the steps we would take to solve the problem. A basic algorithm accompanies each one of the ideas, although you need to develop them in more detail to put them in practise.

• A robot that starts and stops when you clap your hands: This is a very simple robot. It needs to wait until the sensor detects sound above the level you determine and then start moving (motors on without limit) and wait to detect the sound again. It should repeat all of this endlessly. Attention: don't place the sound sensor too near the motors as the noise they produce might interfere with its proper functioning.

• A robot that drives around a space, avoiding obstacles without touching them: this moving robots needs to use the ultrasound sensor to detect any obstacles that may get in its way. It goes forward until the sensor detects an obstacle at a distance that is inferior to what has been set as a safe distance. It then stops and turns until it finds a direction in which it can advance without running into an obstacle and starts over again.

• A robot that moves around avoiding obstacles using a touch sensor: basically it is no different from the previous idea, although in this case first it has to move forwards and wait until it hits something (sensor is activated) after which it stops, avoids the obstacle (by moving backwards and turning) and then starts over again.

• A robot that tells you the distance travelled when you push it forwards manually: this involves some basic maths since we need the formula to convert the rotation of the wheel into distance. The robot will read how much the motor has turned, use the programming locks that allow you to do maths and show the result on the screen of your NXT in the unit of your choice.

• A robot that looks for light: when you are faced with a challenge, the best thing to do is how you would solve the problem, and in most cases there is more than one way of solving the problem. What do you do when you want to go towards a brighter area? Well, the first thing would be to have a look around, take note of the level of light you can see and then move towards the lightest area. The robot will have to do the same thing: make a full turn on the spot, checking light levels, memorize the direction in which it saw the most light and what value it noted there and then turn back and look for that spot in its second turn. But you are sure to come up with another way of doing it.

• A shy robot that runs away from the light: this one is similar to the previous one, but in this case it needs to find a dark pace to hide.

• A robot that follows a line: for thi robot you can use the pad that comes with the MINDSTORMS set. You can use a number of different strategies and since the LEGO® MINDSTORMS™ set comes with only one light sensor you will have to think of a way of doing it with only one sensor. One way is trying to make the robot move along the outside edge of the black line , following it in the clockwise direction (which means the robot will have a white space to its left and will follow the black line keeping it to its right). When the robot detects that the sensor is over the white space (which means it moving to the outside) it will have to correct its course towards the right and when the reading shows its over the black line (the robot is moving towards the inside) it will have to correct towards the left.

In each of the above mentioned cases you can design a robot that is 100% predictable in its behaviour or give it some margin to take its own decisions. How can you do that? That is easy: in each case where it doesn't have any specific instructions you can let it throw the dice to decide whether to turn left or right when avoiding an obstacle or whether to go backwards during one second or three...

LEGO Mindstorms

Books and the Internet

These are two sources of very interesting ideas. I will dedicate another article to giving more information, but I want to mention one at this time which can be very interesting because of its structure and content, "LEGO® MINDSTORMS™ Zoo!”. This book takes the zoo as its central point and develops free reproductions of several animals. Although the book is written in English, this is no obstacle for anyone not fluent in that language as it contains lots of graphical information including step by step building and programming instructions.

On the Internet you can also find many ideas and websites with models that include step by step instructions. A very interesting website in this regard is NXT programs[2], which offers more than 60 models you can build with only the elements contained in a single NXT set without any additional parts, together with step by step building instructions and the corresponding programs in NXT-G.

Exploring new ideas

Where can you find new ideas? The first place to look for them is in your immediate surroundings, our routines, in a problem that arises, in a visit to a museum or a fair..

One example of this is a project my son did a couple of years ago with the RCX. It started when we had a problem with our electrical installation and the main fuse blew while we were on holiday. When we arrived home the freezer had defrosted and all the food had gone bad. While we were cleaning up the mess his mother said "why don't you invent something to prevent this from happening again!". A week later he presented a construction that sent a message to my cellphone when the mains supply was disconnected[3].

The idea in the figure was inspired by a visit to an industrial tools fair[4].

Final remarks

Two weeks after the publication of this magazine a thread will be opened at the forum Lrobotikas[5] to discuss the first proposal and after that each 2 weeks another thread for the remaining proposals in order to collectively solve any doubts, problems, etc. that may arise.


[1] Download area at http://lrobotikas.net

[2] http://nxtprograms.com

[3] See http://lrobotikas.net/es/modelos/rcx/51- alarmasistema

[4] See http://lrobotikas.net/es/modelos/rcx/61- manipulador

[5] Forum Lrobotikas at http://foro.lrobotikas.net