Skip to content

 

PID Control and Tape Following

 

 

Objectives

  • 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.

 

Notes for “Set of Instructions – APSC 203″

  • You will be submitting 1 set of instructions for 2 students.
  • Follow with all guidelines given in APSC 203 for writing and organizing instructions.
  • For this exercise, assume that your audience is one of your classmates just prior to the start of the ENPH 253 course in May.   Assume that your reader has no resources other than your specific Tape Follower, a computer with your TINAH computer program, and any other tools you specifically describe.
  • Write the Set of Instructions assuming that all of the hardware on the Tape Follower is assembled, and that any software that you have written is initially loaded onto the Tape Follower, but all software parameters used to tune the Tape Follower have been reset and need to be re-calibrated from some initial values.  Provide instructions on how the reader can tune your specific Tape Follower to follow tape.
  • Be thorough in describing all necessary steps (appropriate use of drawings and figures is highly recommended)
  • There is no page limit to this exercise.
  • Your work will be submitted either in paper format or electronically by the posted deadline, as shown on the ENPH 253 Calendar.

Red = added for clarification, 8am June 12th.

 

Pre-Lab

  1. You will need 1 complete 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-throughs, and a few other subtleties:  PID Control, from embedded.com/EETimes »
    3. Writing PID control loops for a microcontroller:  Microchip.com »
  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”:

Where:

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


 

Lab

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 value 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. alterng the weight distribution of the tape follower system.

 

Milestone

  • Demonstrate your tuned tape follower to your TA.

 

End of page.