linetracking_20080702 vhdl

download linetracking_20080702 vhdl

of 5

Transcript of linetracking_20080702 vhdl

  • 8/6/2019 linetracking_20080702 vhdl

    1/5

    2008/04/17 PLAB Robot Project Kaichouhi, A.

    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 controlthe motor directions. The reflective photosensors are placed in close proximity to a black line on alight surface and as a result the robot will follow the path of the black line (i.e., line tracking). Figure1 shows a simplified drawing of the robot with the line tracking sensor PCB you assembled in theprevious sessions.

    Figure 1: Top-view of the robot platform with the line tracking sensor PCB.

    1

    Elektronische Schakelingen Exercise 8

    ET1505-D2, 2008-2009

    VHDL Programming for Line Tracking

  • 8/6/2019 linetracking_20080702 vhdl

    2/5

    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/Opins. You will first write a simple VHDL program that performs the basic movements required totrack a black line. Figure 2 shows a state diagram of the line tracking function. See Appendix A forthe pseudocode of the basic line tracking program.

    Figure 2: State diagram of the robot line tracking controller.

    From this pseudocode, a VHDL program must first be written and downloaded to the Spartan IIIFPGA board. Test your code using the robot to attempt tracking a straight line (see Fig. 3a). You willprobably observe that the robot doesn't follow the line smoothly, but rather that it meanders back andforth in a shaky manner while attempting to track the line. You must fine tune your VHDL programso that the robot moves smoothly along the line. As you refine your program and the robot is able totrack the straight line smoothly, attempt to track the shallow curve of Fig. 3b. Again you will likelyobserve that the robot doesn't move smoothly along the line, and it may even lose its way along thetrack. This problem has to be solved by (again) fine tuning your VHDL program. The final objectiveis 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.

    Figure 3: Test tracks for testing line tracking.

    2

  • 8/6/2019 linetracking_20080702 vhdl

    3/5

    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.

    Exercise 1: VHDL Line Tracking Programming

    1. Start a new VHDL project. Write a VHDL program to implement the pseudocode shown inAppendix A. Check the syntax and make sure that it's error free. If you wish, simulate theprogram. To decrease the simulation time, set the operation of your VHDL program to themicrosecond range instead of the millisecond range. This allows you to observe the linetracking 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 theSpartan III FPGA board.

    3. After programming has succeeded, disconnect the 5 V DC adapter and JTAG programmingcable 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 trackall 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 thestudent assistant and what features allow it to smoothly track all 3 lines.

    3

  • 8/6/2019 linetracking_20080702 vhdl

    4/5

    ** Signal declarations of the pseudocode for 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];

    ** Servomotor control signals.out lmotor;out rmotor;

    ** input clock signal.in clock;

    ** 20 ms timer signal.

    ** Q is a bit vector signal [Q n ....Q0 ]. In this pseudo code it is denoted as a single variable.out Q;

    4

    Appendix A Pseudo code of the Line Tracking program

  • 8/6/2019 linetracking_20080702 vhdl

    5/5

    ** Pseudo code Line Tracking Program.

    ProcessBegin

    WAIT UNTIL clock event AND clock is highIN CASE sensor IS

    WHEN 011: IF Q is smaller then or equal to one millisecond THENrmotor is set high;

    ELSE rmotor is set low;END IF;

    WHEN 110: IF Q is smaller then or equal to two milliseconds THENlmotor 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 THENrmotor is set high;

    ELSE rmotor is set low;END IF;

    WHEN OTHERS: nothing happens;END IN CASE;

    END PROCESS;

    5