The Quester follows a line marked on the floor or other surface. For this task, it needs the pair of infrared sensors. The ultra-bright LEDs on the front panel are not essential, but they add to the visual appeal of the robot, especially when it is operating in low light. It can, of course, operate in darkness or in bright room lighting. There is also the practical point that when the robot is spinning left or right to keep on a curving line, the LED on the side to which it is spinning comes on. This helps you to check that the line following is working correctly.
The line is either made from adhesive black strip, from black card, or is painted on the running surface. Before preparing the line, confirm that the line really does absorb infrared. Some black papers and card reflect it, so the black line is indistinguishable from the white or light coloured surface. We found that painting a line on thin white card using Payne's Grey acrylic paint, gave good results. Presumably, Lamp Black acrylic would be just as good.
The line should be about 20 mm wide. Prepare a loop line with straight sections and curves. The radius of each curve should be 70 mm or more. With sharper bends the robot finds itself attempting to cross the line, and stops.
The flowchart and diagram opposite explain how the robot reads the left and right sensors to find out if they are detecting reflected IR. Normally, when the robot is running along a straight line, the sensors are positioned on either side of the line. The situation is as at (a) the top of the diagram. The robot moves forward for 0.2 s and reads the sensors again.
If only one of the sensors sees white, it is veering. The reaction varies according to which sensor sees white and which sees black. If the left sees black and the right white (as at b), it is veering right. To stay on the line it must spin left. The program jumps to the spinl label: the left LED comes on and the working register is set to H'90', the motor contol code for spinning left. The opposite happens if the robot veers off to the left, as at (c).
If both sensors see no white, the robot must be crossing the line (as at d). It stops and the program ends. This is where you might program it to do something more exciting, as suggested later.
What the sensors see, in the four possible cases.
In cases (b) or (c) program jumps to spinl or spinr, depending on which direction it needs to spin. The working register (w) is loaded with the appropriate code and the program goes to spinnit. There, it uses the value in w to spin the robot in the required direction.
The program repeats and the robot runs round and round the loop indefinitely, or until it is blocked when attempting to cross the line.
The listing is:
btfsc porta, 2 goto rorcross btfsc porta, 1
;Left IR sensor.
;Is veering right or crossing.
;Right IR sensor. ; Is veering left.. ;Forward.
goto spinr movlw a0h movwf portb call delay clrf portb goto mode3
rorcross btfsc porta, 1 goto blocked goto spinl
;Right sensor. ; Is crossing. ;Is veering right spinr bsf portc, 3 movlw 60h goto spinnit
spinl bsf portc, 4 movlw 90h
spinnit movwf portb call delay clrf portb clrf portc goto mode3
;Make it spin.
blocked goto $
;Wait (or further action)
Many amendments and extensions can be made to this program. For example, a simple amendment is to program it to follow a white line on a dark surface.
You can experiment with the lines. If the robot comes to an end of a line, it will continue more or less straight ahead for a short distance. Then it can detect the beginning of another line and follow it. Use this behaviour to make the robot follow a figure-of-eight loop.
The robot can also run a maze of branching lines. At each branch there is a strip across the junction to make it stop. Then it makes a random selection to go either left or right. and arrives at one of several endings. Only one of these is 'home'. Program it to remember which selection it made at each branch and, eventually, to learn to run directly home every time. Quest05.asm, a maze runner program on this theme, is available for downloading from the companion website (p. vi).
Was this article helpful?