Skip to content

This page is archived material from a previous course. Please check for updated material.

    Lab 5 (2015)


    PID Control and Tape Following




    • Build and characterize a tape-following system based on PID control.
    • Learn to tune PID parameters to obtain optimum vehicle performance for both speed and precision.
    • Write and submit a Set of Instructions describing how to tune your system.   This is to be submitted as part of your APSC 203 mark.



    1. You will need 1 complete working chassis for every 2 people.
    2. Read a few primers on PID control:
      1. Wikipedia entry – focus on explanation of terms, manual tuning.  PID Control, Wikipedia »
      2. Articles on PID control including walk
      3. Writing PID control loops for a microcontroller: »
    3. Attempt to write software to implement the PID control loop as described in the lab below.



    Additional Readings


    PID control is an algorithm to provide a control signal based on an error signal, the integral of the error signal over time, and the time derivative of the error signal. The resulting equation is:

    This can be implemented in an analog circuit by using Op-amps and filters to perform the integration and differentiation functions. For this lab, you will be implementing PID in software.  In that case you will execute a loop (loop index i) where

    (i) = sensor voltage(i) – setpoint voltage

    (i) = ((i) – (i-1)) / T

    where T = the number of seconds spent in each loop (this can be omitted and lumped into the gain constant D)

    where error_sum is incremented each loop:

    error_sum = error_sum + T *(i);

    The gain variable T allows you to slow the rate at which the integral accumulates should it be desirable to do so (this is usually the case if your algorithm executes much faster than the rate at which you can perform the control).

    To avoid integral “wind-up” (where the value of the integral term becomes too large following a sustained error), software limits are applied to error_sum:

    if (error_sum > high_limit)

    error_sum = high_limit;

    if (error_sum < low_limit)

    error_sum = low_limit;

    this prevents error_sum from reaching absurdly high or low values which the P gain will not be able to overcome should the error suddenly decrease.

    Tuning P, I, and D gain variables is often done by trial and error.    Some more precise tuning methods are shown in the primer.


    Alternate algorithm


    An alternate form of the digital PID algorithm can be found in “Microprocessors in Instruments and Control” by R.J. Bibbero.    This algorithm is inherently “anti wind-up”:


    dOm =amount to be added to the output voltage each loop (Vout += dOm)

    Verror(i)= error voltage during ith iteration

    G = total loop gain

    I = Integral gain

    D = Derivative gain

    T = Time interval between each loop execution



    The goal is to control your tape follower from the hand tool exercise with a PID algorithm you write.

    1. Write your PID software.     Write a control algorithm.   For easy tuning during testing you may choose to use the TINAH Board’s knobs to adjust the main parameters in your code.   If that is not sufficient, you may also want to use additional trimpots soldered to short leads and connected to other analog inputs to help tune your values.
    2. Warnings:
      1. Maximum values of +/- 700 to the motors.      Note that the motors are rated for 6V maximum, but the TINAH board motor outputs have a maximum effective value of 9V   (outputs are regulated to 9V through the two 7809 regulators with the heat sinks next to the on-board H-bridge chips).   Using motor values greater than +/- 700 to the motors puts the motor windings at risk and may burn out the coils inside the small DC motors.
      2. Sunlight affects QRD1114 Sensors   Be careful if you are running your system in the hallway or near windows, as the infrared background from the sun tends to swamp the IR phototransistors on the QRD1114.   Use some kind of physical shilelding, or (even better) stay away from the sun!
    3. Tune your PID control.      As described in the lecture and in the pre-lab readings, tune your PID loop to provide zero steady state error, and optimum response time with minimum overshoot when following the tape.    Initially you will want to set I=D=0 and use only proportional gain for tuning the system.   Qualitatively explore the response time and steady state error of your servo system, then increase gain, and add I,D gain to see what happens.
    4. Optional:    Change the physical setup of your tape follower.     You are free to make small changes to your vehicle to see the effects of the system, with the overall goal of ending up with a tape following vehicle that can both move quickly while still precisely following tape.     This might include:
      1. stiffening the entire chassis
      2. placing the sensors in different positions in the sensor holder (closer/further away from each other, on the same side of the sensor holder)
      3. placing the sensor holder closer/further away from the centre of rotation.
      4. altering the weight distribution of the tape follower system.



    • Demonstrate your tuned tape follower to your TA.



    End of page.