Linetracking - 20080702 VHDL
Linetracking - 20080702 VHDL
Objective:
– Programming the robot to respond to the reflective photosensors that are placed in close
proximity to a black line on a light surface in order to control motor direction.
– Further programming the robot to track a line and to turn as smoothly as possible, as well as
searching for the line when the robot is *lost*.
In this exercise you will program your robot to respond to reflective photosensors in order to control
the motor directions. The reflective photosensors are placed in close proximity to a black line on a
light surface and as a result the robot will follow the path of the black line (i.e., line tracking). Figure
1 shows a simplified drawing of the robot with the line tracking sensor PCB you assembled in the
previous sessions.
Figure 1: Top-view of the robot platform with the line tracking sensor PCB.
1
To control the robot, a VHDL program will be written and is downloaded to the Spartan III FPGA.
The output control signals are connected to the control inputs of the servomotors via the FPGA I/O
pins. You will first write a simple VHDL program that performs the basic movements required to
track a black line. Figure 2 shows a state diagram of the line tracking function. See Appendix A for
the pseudocode of the basic line tracking program.
From this pseudocode, a VHDL program must first be written and downloaded to the Spartan III
FPGA board. Test your code using the robot to attempt tracking a straight line (see Fig. 3a). You will
probably observe that the robot doesn't follow the line smoothly, but rather that it meanders back and
forth in a shaky manner while attempting to track the line. You must fine tune your VHDL program
so that the robot moves smoothly along the line. As you refine your program and the robot is able to
track the straight line smoothly, attempt to track the shallow curve of Fig. 3b. Again you will likely
observe that the robot doesn't move smoothly along the line, and it may even lose its way along the
track. This problem has to be solved by (again) fine tuning your VHDL program. The final objective
is to program the robot so that it is able to tracking a line with tight or sharp turns, as shown in Fig.
3c.
(a) Straight line. (b) Line with large turns. (c) Line with sharp turns.
2
For this exercise you need:
• A complete assembled robotplatform.
• A PC with the Xilinx 6.3.03i software.
• A US/European AC power adapter.
• A parallel port to JTAG programming cable.
• 15 mm wide black tape.
• A clean, light colored and flat surface for testing.
1. Start a new VHDL project. Write a VHDL program to implement the pseudocode shown in
Appendix A. Check the syntax and make sure that it's error free. If you wish, simulate the
program. To decrease the simulation time, set the operation of your VHDL program to the
microsecond range instead of the millisecond range. This allows you to observe the line
tracking action in a shorter simulation time period.
2. Disconnect the battery pack from the FPGA board and connect it instead to the 5V DC
adapter. Connect the JTAG programming cable and download your VHDL code to the
Spartan III FPGA board.
3. After programming has succeeded, disconnect the 5 V DC adapter and JTAG programming
cable from the robot and reconnect the battery pack.
4. Attach a 40-50 cm long strip of 15 mm wide black tape onto a light colored, flat surface.
5. Place the robot with the reflective photosensor centred on the black strip and power on the
robot.
6. Observe the behaviour of the robot by looking at the movements of the reflective photosensors
as it tracks the black tape.
7. Correct the movements by modifying the VHDL line tracking program, and repeat steps 2-3,
and 5-7 until the robot tracks the line as smoothly as possible.
8. Repeat this for the other 2 test tracks shown in Figure 3b and 3c. The robot should now track
all 3 lines smoothly.
9. Implement a strategy to search for the line when the robot is lost.
Note:
• Show your tutor the line tracking action of the robot. He will judge how well the robot tracks
the line. Explain the operation of your VHDL line tracking program to your tutor and the
student assistant and what features allow it to smoothly track all 3 lines.
3
Appendix A Pseudo code of the Line Tracking program
** Note: These shown signal declarations do not show declarations as in a real VHDL program.
** You have to define these signals yourself.
** Sensor Signals.
** This is a bitvector signal of 3 bits.
** Sensor[2] Sensor[1] Sensor[0]
** Left sensor Center sensor Right sensor
in Sensor[3];
** 20 ms timer signal.
** Q is a bit vector signal [ Q n .... Q 0 ]. In this pseudo code it is denoted as a single variable.
out Q;
4
** Pseudo code Line Tracking Program.
Process
Begin
WAIT UNTIL clock event AND clock is high
IN CASE sensor IS
WHEN 011: IF Q is smaller then or equal to one millisecond THEN
rmotor is set high;
ELSE rmotor is set low;
END IF;
WHEN 110: IF Q is smaller then or equal to two milliseconds THEN
lmotor is set high;
ELSE lmotor is set low;
WHEN 101: IF Q is smaller then or equal to two milliseconds THEN
lmotor is set high;
ELSE lmotor is set low;
END IF;
IF Q is smaller then or equal to one millisecond THEN
rmotor is set high;
ELSE rmotor is set low;
END IF;
WHEN OTHERS: nothing happens;
END IN CASE;
END PROCESS;