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 ...
}