On Wednesday 2nd July Loreto High School had its second 'Open Evening' this year and Computer.lab went down to work with the Young Engineers in the Technology Department.  The aim was to combine some mechanical engineering activities with computer programming through the medium of robotics.


The pupils used Lego Mindstorms kits to make some tracked robotic vehicles out which were later programmed to move in different ways using the NQC language. This mechanical engineering part of the work involved assembling Lego Technic parts including gears, motors and sensors by following a set of construction diagrams.


Once the robots were built their behaviour needed to be programmed. The large yellow Lego RCX brick in the above photograph is actually a microcomputer.  A program is written on a laptop or desktop computer and then downloaded to the RCX brick to control the robot's behaviour. Simple programs were used to introduce the Young Engineers to the NQC programming environment and simply made the robots move forwards, backwards and turn.  Here is some of the code they used:

task main()
{
     OnFwd(OUT_A + OUT_C);
     Wait(200);
     OnRev(OUT_A + OUT_C);
     Wait(200);
     OnFwd(OUT_A);
     OnRev(OUT_C);
     Wait(200);
     Off(OUT_A + OUT_C);
}

This program works by switching on two motors on the robot attached to outputs A and C first forwards, then in reverse and finally one motor going in each direction which makes the robot turn or spin round.


The next activity was to add a light sensor to the front of the robot so that it could follow a line.  The light sensor can detect whether it is over a light coloured surface or a dark coloured service by measuring the reflection of a red beam of light off it. 

 
This program works by checking how much light is reflected from the surface.  If a lot of light is reflected in a light-coloured area the robot is programmed to turn right until it detects the line.  Once the line has been found the robot moves forward until the sensor detects that the robot has moved off the line, when it turns right again and repeats the process.  Here is the code that was used to do this:

# define THRESHOLD 45

task main()
{
     code to follow soon ...
}



 

Welcome to Mind.lab

Mind.lab is the Lego Mindstorms branch of Computer.lab.  In this microsite we'll be writing about our experiences in creating small robots and programming their behaviours.  Sometimes we will be using laptops to write the programs, but more often than not we'll be using Raspberry Pi computers as the programming source.

We'll be mainly using the original Lego Mindstorms sets which were released in the mid 90's.  Despite their age, these kits still have a lot to offer when learning about programming and robotics. However, we won't be using the graphical programming language which was supplied with these sets - instead we'll be using NQC (Not Quite C) which was developed independently of Lego by Dave Baum and which is much closer to being a traditional text-based programming language.

When programming on a Raspberry Pi, the NQC compiler will be compiled and downloaded by commands typed into a Linux terminal window and the programs will be developed using the simple Nano text editor.  On a laptop the Bricxcc IDE (Integrated Development Environment) will be used to both develop, compile and download NQC programs to the RCX brick.

The Lego Mindstorms sets we'll be using are no longer available as retail products but they are still readily available on eBay, although they can sometimes command quite high prices.  Care should be taken in making sure that the sets are more or less complete with the yellow RCX brick, sensors, wheels and most importantly the IR Tower which is used to download programs from the computer.