Challenge 102 - Following the line using two light sensors – Is it worthwhile?

So far, you have added a light sensor to our robot, and successfully programmed it to follow a line – good work! This would enable you to enter your robot in the Tasmanian RoboCup Junior Rescue Championships that are held about August each year in Hobart. This is good fun, and you meet lots of other people from other schools who like robots too – you might even make some new friends.

The runs in the Rescue event are timed, with robots that are faster having an advantage over slower robots. it will be interesting to see if your robot could follow a line more quickly if you equipped your robots with two light sensors – would two allow your robots to go twice as fast, or would they just be a nuisance and make your runs even slower?

Let us experiment and find out!

102.1 Line following with one light sensor.

When your robot had one light sensor, your robot was programmed so that the light sensor moved towards, and then away, from the line edge, (and then again towards, and then away, and so on…) as shown in the two photos below.

 

If you used a program similar to that in the LEGO NXT-G Robot Educator, (17. Follow a Line), your program probably looked like this:-

The Robot Educator does not contain a sample program for using two light sensors to follow a line. Could we usefully modify the “one light sensor  program” shown above for use with two light sensors?

102.2 Add a second light sensor to your robot

The next step will be to add a second light sensor to your robot.  There are many ways to do this – one way would be to add a second 4 hole by 2 hole angle bracket to the front of your robot, moving the brackets a bit further apart. Another would be to add a horizontal bar to the front of your robot and mount two light sensors on the bar about five LEGO holes apart. There are lots of other ways you can mount two light sensors – experiment and try your very own way to see if your way works and if your way is better than the suggestions above!

102.3 Programming your robot when it has two light sensors available.

When you have added a second light sensor, your robot may look something like the robots shown below.

 

1: LEFT and RIGHT sensors both on WHITE   2: LEFT sensor on BLACK, RIGHT on WHITE

 

3: LEFT sensor on WHITE, RIGHT on BLACK  4: LEFT and RIGHT sensors both on BLACK

102.3.1 Programming Method 1

It has been suggested that we could program the robot so that each of the light sensors work to keep the robot away from the line by just using the one-light sensor program twice in a row, with the motors reversed, as shown below:-

Does this follow a line more quickly than our previous robot using just one light sensor? If it is better, how much faster is it? If it does not work, why is this not a useful program?

HINT: To work out why it is behaving in the way it is behaving, follow through the program to see what happens in the cases of photos 1:, 2: and 3: on the previous page; (we can ignore photo 4: for a while). If you are having trouble understanding what happens in this program, call your mentor. When you feel you understand how this program works, try Programming Method 2 method to see if Programming Method 2 is better or worse than Programming Method 1.

102.3.2 Programming method 2

In this case we should think carefully what we want our robot to do when it comes across the circumstances shown in photos 1:, 2: and 3: (ignore photo 4: at this stage).

One possible way of programming this is shown below – SEE IF YOU CAN PROGRAM THIS YOURSELF BEFORE YOU LOOK AT THE DIAGRAM BELOW YOU WILL LEARN MORE THIS WAY!

 

Can you work out what the program above does if both sensors see black (photo 4)? Also, this program is not the only way to represent the diagram on the previous page – can you think of a different way? How would your program be different to the program above?

102.4 Extension tasks:-

 

To go back to the list of Challenges - Click here.

Mentor notes: This Challenge is also available as a four page Microsoft Word 2003 document; click here. Information regarding the arena used in the Tasmanian RoboCup Junior Rescue and Premier Rescue competitions can be found by clicking here.

LEGO MindStorms NXT Robot Tutorial Challenge 102 - Line following with two light sensors - www.DrGraeme.net