Journal of Undergraduate Research
Volume 7, Issue 6 - July/August 2006

Development and Application of the Proportional-Integral-Derivative Control Algorithm

Sara C. Keen, Eric M. Schwartz, Member, IEEE

ABSTRACT

The three-term proportional-integral-derivative (PID) controller is one of the most effective methods for achieving motor control. This control method is preferred to other, less complex methods because it is able to account for accumulated past error as well as prevent future error. The PID controller is particularly suited for steering control, as it is more efficient at eliminating steady-state error and oscillations than other controllers. By properly tuning a controller it is possible to achieve a linear output of a non-linear system. Most control systems can be represented mathematically using discrete equations, facilitating the design of a controller entirely in software. This method of control was applied for a large autonomous robot to provide with accurate steering capabilities. The controller was tuned to smoothly adjust both motors to a predetermined set point. Simulation and further testing was used to demonstrate the efficacy of the controller.

Index Terms— Laplace transform, PID control, Set point

INTRODUCTION

The purpose of a proportional-integral-derivative (PID) controller is to create a system output that matches a predetermined set point, or trajectory that is input to the system. The PID controller is capable of eliminating transient as well as steady-state error, making it one of the most popular controllers used in industry. System feedback is used to calculate the proportional, integral and derivative terms that adjust the current controller output. The goal of the control system is to find a combination of these three terms that yields a small rise time and settling time and the lowest possible overshoot and steady-state error.

This paper will discuss the theory of PID control and the process of designing and tuning an actual PID system.

CONTROL THEORY

A Model Control System

The most basic closed-loop control system consists of an input, a controller, a plant, and an output. For the purposes of this paper, a simple model of such a control system is provided in Fig 1.

Fig. 1. Model of a closed-loop control system

Fig. 1. Model of a closed-loop control system. X, Y, e and u represent the input, output, error and control signal, respectively.

The controller signal, u, is calculated using the tracking error, e, that is found from the closed-loop feedback. The feedback is actually the data from some sensor monitoring the plant output. A system performing optimally will have the input and output matched, yielding a zero error. This is achieved by calculating the control signal from the correct combination of the proportional, integral, and derivative terms.

Using the Laplace transform, the transfer function of the three-term PID control system can be represented in the as

Keen Figure (1)
Keen Figure (2)

where (1) is known as the “parallel form” and (2) is known as the “ideal form” of the PID transfer function [1]. Kp, Ki and Kd are the proportional, integral and derivative gains, and TI and TD are the integral and derivative time constants, respectively.

Functionality of Terms

A PID controller attempts to minimize past, present and future error with the three terms that affect the control signal. Each term is multiplied by a gain, K, which is set between 0 and 1 during tuning of the system. By altering these coefficients it is possible to control which has the greatest influence and find a balance of the terms that is suitable for the system.

Proportional Term. The proportional term accounts only for the present error. This term is simply the error, or difference between the output and the set point, multiplied by the gain Kp. As shown in Fig. 1, the system feedback is negative. Thus, if the output is greater than the set point, the proportional term is negative and decreases the controller output. The proportional term has an immediate and drastic effect on the system output. This term decreases the rise time and steady-state error of the response but also increases the overshoot.

A proportional controller (with only the P-term) is able to reduce the amount of error but cannot eliminate it entirely. There will always be some offset between the system output and desired value [2].

Integral Term.  The integral term compensates for past error, or error accumulated over time. This term is most effective at reducing steady-state error or oscillations from a system. The integral term also typically increases overshoot and settling time, undesirable traits in a controller.

It should be noted, however, that over time the integral term might lead to system instability. After receiving an error signal for significant periods of time the plant output will increase at a steady rate determined by TI. Eventually the controller output will be at its maximum or minimum limit [2]. This occurrence is known as integral wind-up and can be counteracted by using negative feedback from the excess amount of the integral term within the integrator. This will effectively remove the saturation [1].

Derivative Term.  The derivative term reduces the error that will occur in the future as well as the transient response of the system. This is done by anticipating what the plant output will be by examining the rate of change, or derivative, of the error. Unlike the other terms, the derivative term will have no effect if the error is constant. One undesirable quality of the derivative term is that it may magnify the effects of electrical noise within the system. When noise is differentiated, the controller output will change dramatically [2]. Furthermore, adjustments may need to be made to the control equation to prevent derivative kick. This is when a step change in the set point causes a large change in the D term. Methods for preventing derivative kick will be discussed in detail later.

Analog and Discrete Control

An ideal PID controller operates continuously, meaning that is it functionally an analog controller. The control signal can be represented mathematically in the continuous time domain as shown in (3).

Keen Figure (3)

In (3) Ki can also be represented as Kp/TI and Kd by Kp*TD. The term u0 represents the base level of the plant output. In order for a computer to perform PID control it is necessary to convert the system into the discrete domain [3]. This requires approximating the integral and derivative terms as in (4).

Keen Figure (4)

This equation can easily be represented in programming language, which greatly simplifies the application of the PID algorithm.

Positional vs. Velocity Control

A PID controller can operate in two ways.  The first is known as the positional form and can be represented by (4).  In this format the control signal is calculated with reference to a base level.  Thus, the controller output is not summed with the previous outputs.  This command is proportional to the exact position at which the system should be operating [1].  The controller measures the error associated with the output and calculates what the new output must be in order to match the set point.

The second method is the velocity PID algorithm.  This form can be derived directly from the Laplace representation shown in (1).  If this equation is discretised using the backwards difference technique, (5) is found.

Keen Figure (5)

This can be simplified to

Keen Figure (6)

This time-domain representation is known as the velocity PID control form.  Using this method the controller output is the amount that is added to the current plant output in order for it to match the set point.  Only the change in controller output is calculated.  Therefore, if there is zero error there controller output will be zero. 

The Three Types of PID Equations

The velocity control form can be divided into three types of PID equations [4].  Equation (2) is the basis for the three types.  The first step is to differentiate (2) as shown below.

Keen Figure (7)

In this equation the error e(t) is the plant output, or plant variable SV, subtracted from the set point, SP.  The differential of the error can then be approximated using the difference over time.  When simplified, (7) becomes identical to (6).  This representation is known as the Type A PID equation.  In (6) T represents the sampling period, or loop update time.  Type A is also known as textbook PID [4].  It can be seen that the D term contains the set point, which can lead to undesirable changes in the controller output if the set point changes, the previously mentioned derivative kick.  The set point can be removed from the D term to give the Type B equation shown below.

Keen Figure (8)

This completely resolves the issue of a derivative kick, although the presence of the error could still affect the other terms.  Type B controllers are those most commonly used in industry.  By also removing the set point from the P term the Type C equation is found.

Keen Figure (9)

Type C controllers are most commonly preferred because they act upon the plant variable rather than the error signal [1].  Type C has been proven to provide the most stable system with the least overshoot.

SIMULATION

Using a program such as Matlab, it is possible to simulate the response of a control system and predict what coefficients will be most effective.  This can be done by creating a transfer function representative of the system and observing the system response to various inputs.  One common simulation technique is to individually adjust the coefficients of each term and measure the system response to a step input.  Simulation can save the control system designer time and prevents the system from being damaged by rigorous testing.

APPLICATION

The algorithm was tested by applying PID control to a large mobile robot created in the Machine Intelligence Laboratory at the University of Florida.  The robot, known as Koolio, is essentially a refrigerator on wheels that delivers refreshments to different offices in the mechanical engineering building.  This robot was a qualified candidate for receiving a motor control system because it is driven by two motors with very different characteristics. 

It is important that the robot motors are controlled such that they rotate at the same speed for the robot to travel in a straight line.  Even the slightest differences in motor speed could cause the robot to be entirely off course by the end of one delivery. 

Integrated System

The two motors receive commands from separate motor controllers.  The motor controllers are sent one byte of data from the main processor that corresponds to the desired motor speed.  Using one byte the data range is 0 –255, with 0 being stopped and 255 being full speed.  This number is not signed, as desired direction of rotation is sent in a separate byte. 
The motor control calculations are performed by an Atmega128, an 8-bit, 16 MHz microprocessor.  The Atmega128 uses encoder readings to compute the three controller terms, and then asserts the correct motor driver command.  The program for the controller was written in the C language and programmed into the Atmega128 flash memory.  A larger processor that is used to control the robot’s behavior sends instructions to the Atmega128 that specify the desired motor speeds.

A smaller processor was used for the sole purpose of measuring motor feedback and reporting readings to the main processor.  This task was assigned to a separate processor because taking continuous measurements requires too many operations for the processor to do anything else.  A block diagram of both motor control systems is shown in Fig. 2.

Fig. 2.  Model of closed-loop control system for the two motors used in Koolio

Figure 2.  Model of closed-loop control system for the two motors used in Koolio

In both control systems the Atmega128 uses the feedback and an external input to calculate the controller input, e(t).  The controller, which is within the Atmega128, uses that input to produce the plant input u(t).  The plants are of the two motor driver-motor pairs.  Each plant output is measured by an encoder that reports data to the main processor, providing feedback for the closed-loop systems.  It should be noted that the main processor contains two separate, but related control systems.  This is because each motor requires different coefficients for optimal performance.

Feedback

It is essential that both motors rotate at the same speed for the robot to drive straight.  Clearly, this cannot be achieved by simply sending the motors identical commands.  Additionally, because the motors are not matched, it is impossible to know their speed based on the commands sent by the motor drivers.  Some form of feedback is required.  Two optical encoders were used to create a closed-loop system for both motors.  An encoder was connected to the gear train of both motors.

The optical encoders use two photoreflectors to continuously take readings from a colordisk that they are positioned above.  This colordisk is attached to the protruding bar of the encoder, which is turned by the wheel.  The colordisk consists of alternating black and white lines directed radially outward.  The photoreflectors are spaced such that they may fit side-by-side over one line on the disk.  Each reflector gives a digital output to signal what color is it above.  When the wheel turns it is possible to know the direction of rotation by monitoring the order in which these outputs change.  This method is referred to as quadrature encoding.

Mobile Platform

The robots wheels are mounted on a single axis that crosses the center of the circular base.  A comparison of the left and right motor can be seen in the graph below.

Figure 3.  Model of closed-loop control system for the two motors used in Koolio.

Figure 3.  Model of closed-loop control system for the two motors used in Koolio.

Method of Control

The robot was programmed to use the ‘velocity’ PID control method.  This method was preferred above positional control because it was of more importance that the robot traveled straight rather than at a particular speed.  One disadvantage to this method was that it was necessary to perform calculations based on encoder readings to determine what speed the robot was traveling at.  Using the positional method, the robots current speed would be known and added into the controller output.  However, for the purposes of this robot, maintaining a precise, known speed was not essential.
To travel in a straight line using the velocity control method, both motor drivers would first send identical commands to the motors that were representative of the desired speed.   The motors would then begin rotating, although at different speeds, because they were not matched.  From the encoder readings the processor found the speed of both motors.  The processor then established the set point as the average of these speeds.  After both motors were rotating at the same speed, a digital compass was used to ensure that the robot was traveling in the correct direction.  If the robot had strayed off course during alignment, one motor speed was increased until the compass readings were correct, and the alignment process began anew.

TUNING

The tuning of a PID controller is the process of adjusting the control parameters, or coefficients, until the system demonstrates the desired response [5].  For this robot it was permissible to have high overshoot and an overall response time of several minutes during tuning.  The motors would not go faster than the motor drivers’ limit, which eliminated the possibility of destroying the motors or harming the robot.  Furthermore, a slow response time made it possible to observe each change in motor speed and better predict what values needed to be altered.  By changing the coefficient K of each term, it is possible to change the value of every term and its effect on the system.  A summary of the effects of increasing each term can be seen in Table I.

Table 1
Effects of Increasing Parameters
Term Rise Time Overshoot Settling Time Steady-state Error
P Decrease Increase Small Change Decrease
I Decrease Increase Increase Eliminate
D Small Change Decrease Decrease Small Change

To tune the motors, the I and D terms were first set to zero for both motors.  The P values were increased until the motors both oscillated about the set point with equal steady-state error.  It was possible to monitor the speeds of the motors by using a liquid crystal display updated by the main controller.  Next, the I term was increased for both motors until the oscillations disappeared.  This step was somewhat tedious because the control loop was set to update approximately once per second in order to observe changes on the LCD.  Finally, the D terms were increased in order to decrease the time it took both systems to reach the set point.  When the settling time for a motor could not be made any shorter, the D term was set. 

RESULTS

After tuning both motors the robot was tested by making numerous trips up and down a long hallway.  The robot was programmed to continuously monitor its direction and the speed of both wheels, meaning that it stayed in an infinite control loop.  When the robot steered in the correct direction with both motors rotating at the desired speed, the error and the controller input were both zero.  If at any point the robot turned in the wrong direction or the motors became mismatched, the control system would take command and align the robot once again.  The control system was found to be quite effective.  The robot motors were successfully controlled using the PID algorithm.  The differences between motors were entirely compensated for by the controller. 


ACKNOWLEDGMENTS

Our thanks to Brian Pietrodangelo and Kevin Phillipson for their work on the original Koolio design and the University of Florida Machine Intelligence Laboratory. 


REFERENCES

  1. K. H. Ang, G. Chong, and Y. Li, “PID Control System Analysis, Design, and Technology,” IEEE Trans. Control Systems and Technology, vol. 13, pp. 559-576, July 2005.
  2. M. J. Willis, “Proportional-Integral-Derivtive Control,” 1999 [Online].  Available: http://lorien.ncl.ac.uk/ming/pid/PID.pdf.
  3. M. Tham, “Discretised PID Comtrollers,” 1998 [Online]. Available: http://lorien.ncl.ac.uk/ming/digicont/digimath/dpid1.htm
  4. “Three Types of PID Equations,” 2001 [Online]. Available: http://bestune.50megs.com/typeABC.htm
  5. Wikipedia, “PID Controller,” 2006  [Online]. Available: http://en.wikipedia.org/wiki/PID_controller
  6. I. Kaya, N. Tan, and D. P. Atherton, “ A Simple Procedure for Improving Performance of PID Controllers,” in Proc. 2003 IEEE Conf. on Control Applications, California, 2003, pp.882-885.
  7. G. W. Lucas, “Using a PID-based Technique for Competitive Odometry and Dead Reckoning,”  2001 [Online]. Available: http://www.seattlerobotics.org/encoder/200108/using_a_pid.html

--top--

Back to the Journal of Undergraduate Research