9
24/11/11 CTM: PID Tutorial 1/9 ZZZ.engin.umich.edu/group/ctm/PID/PID.html PID TXWoUial InWUodXcWion The WhUee-WeUm conWUolleU The chaUacWeUiVWicV of P, I, and D conWUolleUV E[ample PUoblem Open-loop VWep UeVponVe PUopoUWional conWUol PUopoUWional-DeUiYaWiYe conWUol PUopoUWional-InWegUal conWUol PUopoUWional-InWegUal-DeUiYaWiYe conWUol GeneUal WipV foU deVigning a PID conWUolleU Ke\ MaWlab CommandV XVed in WhiV WXWoUial aUe: VWep cloop NoWe : MaWlab commandV fUom Whe conWUol V\VWem Woolbo[ aUe highlighWed in Ued. InWrodXcWion ThiV WXWoUial Zill VhoZ \oX Whe chaUacWeUiVWicV of Whe each of pUopoUWional (P), Whe inWegUal (I), and Whe deUiYaWiYe (D) conWUolV, and hoZ Wo XVe Whem Wo obWain a deViUed UeVponVe. In WhiV WXWoUial, Ze Zill conVideU Whe folloZing XniW\ feedback V\VWem: PlanW: A V\VWem Wo be conWUolled ConWUolleU: PUoYideV Whe e[ciWaWion foU Whe planW; DeVigned Wo conWUol Whe oYeUall V\VWem behaYioU The Whree-Werm conWroller The WUanVfeU fXncWion of Whe PID conWUolleU lookV like Whe folloZing:

CTM_ PID Tutorial

Embed Size (px)

Citation preview

Page 1: CTM_ PID Tutorial

24/11/11 CTM: PID Tutorial

1/9www.engin.umich.edu/group/ctm/PID/PID.html

PID Tutorial

IntroductionThe three-term controllerThe characteristics of P, I, and D controllersExample Problem

Open-loop step responseProportional controlProportional-Derivative controlProportional-Integral controlProportional-Integral-Derivative control

General tips for designing a PID controller

Key Matlab Commands used in this tutorial are: step cloop

Note: Matlab commands from the control system toolbox are highlighted in red.

Introduction

This tutorial will show you the characteristics of the each of proportional (P), the integral (I), and the

derivative (D) controls, and how to use them to obtain a desired response. In this tutorial, we will consider

the following unity feedback system:

Plant: A system to be controlled

Controller: Provides the excitation for the plant; Designed to control the overall system behavior

The three-term controller

The transfer function of the PID controller looks like the following:

Page 2: CTM_ PID Tutorial

24/11/11 CTM: PID Tutorial

2/9www.engin.umich.edu/group/ctm/PID/PID.html

Kp = Proportional gain

KI = Integral gain

Kd = Derivative gain

First, let's take a look at how the PID controller works in a closed-loop system using the schematic shown

above. The variable (e) represents the tracking error, the difference between the desired input value (R) and

the actual output (Y). This error signal (e) will be sent to the PID controller, and the controller computes boththe derivative and the integral of this error signal. The signal (u) just past the controller is now equal to the

proportional gain (Kp) times the magnitude of the error plus the integral gain (Ki) times the integral of the

error plus the derivative gain (Kd) times the derivative of the error.

This signal (u) will be sent to the plant, and the new output (Y) will be obtained. This new output (Y) will besent back to the sensor again to find the new error signal (e). The controller takes this new error signal and

computes its derivative and its integral again. This process goes on and on.

The characteristics of P, I, and D controllers

A proportional controller (Kp) will have the effect of reducing the rise time and will reduce ,but never

eliminate, the steady-state error. An integral control (Ki) will have the effect of eliminating the steady-stateerror, but it may make the transient response worse. A derivative control (Kd) will have the effect of

increasing the stability of the system, reducing the overshoot, and improving the transient response. Effects ofeach of controllers Kp, Kd, and Ki on a closed-loop system are summarized in the table shown below.

CL RESPONSE RISE TIME OVERSHOOT SETTLING TIME S-S ERROR

Kp Decrease Increase Small Change Decrease

Ki Decrease Increase Increase Eliminate

Kd Small Change Decrease Decrease Small Change

Note that these correlations may not be exactly accurate, because Kp, Ki, and Kd are dependent of eachother. In fact, changing one of these variables can change the effect of the other two. For this reason, the

table should only be used as a reference when you are determining the values for Ki, Kp and Kd.

Example Problem

Suppose we have a simple mass, spring, and damper problem.

Page 3: CTM_ PID Tutorial

24/11/11 CTM: PID Tutorial

3/9www.engin.umich.edu/group/ctm/PID/PID.html

The modeling equation of this system is

(1)

Taking the Laplace transform of the modeling equation (1)

The transfer function between the displacement X(s) and the input F(s) then becomes

Let

M = 1kg

b = 10 N.s/mk = 20 N/m

F(s) = 1

Plug these values into the above transfer function

The goal of this problem is to show you how each of Kp, Ki and Kd contributes to obtain

Fast rise time

Minimum overshoot

No steady-state error

Open-loop step response

Let's first view the open-loop step response. Create a new m-file and add in the following code:

n u m = 1 ;d e n = [ 1 1 0 2 0 ] ;s t e p ( n u m , d e n )

Page 4: CTM_ PID Tutorial

24/11/11 CTM: PID Tutorial

4/9www.engin.umich.edu/group/ctm/PID/PID.html

Running this m-file in the Matlab command window should give you the plot shown below.

The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of the output to an unit step input.This corresponds to the steady-state error of 0.95, quite large indeed. Furthermore, the rise time is about one

second, and the settling time is about 1.5 seconds. Let's design a controller that will reduce the rise time,

reduce the settling time, and eliminates the steady-state error.

Proportional control

From the table shown above, we see that the proportional controller (Kp) reduces the rise time, increases the

overshoot, and reduces the steady-state error. The closed-loop transfer function of the above system with aproportional controller is:

Let the proportional gain (Kp) equals 300 and change the m-file to the following:

K p = 3 0 0 ; n u m = [ K p ] ; d e n = [ 1 1 0 2 0 + K p ] ; t = 0 : 0 . 0 1 : 2 ; s t e p ( n u m , d e n , t )

Running this m-file in the Matlab command window should gives you the following plot.

Page 5: CTM_ PID Tutorial

24/11/11 CTM: PID Tutorial

5/9www.engin.umich.edu/group/ctm/PID/PID.html

Note: The Matlab function called c l o o p can be used to obtain a closed-loop transfer function directly fromthe open-loop transfer function (instead of obtaining closed-loop transfer function by hand). The following m-

file uses the c l o o p c o m m a n d t h a t s h o u l d g i v e y o u t h e i d e n t i c a l p l o t a s t h e o n e s h o w n

a b o v e .

n u m = 1 ;d e n = [ 1 1 0 2 0 ] ;K p = 3 0 0 ;

[ n u m C L , d e n C L ] = c l o o p ( K p * n u m , d e n ) ;t = 0 : 0 . 0 1 : 2 ;s t e p ( n u m C L , d e n C L , t )

T h e a b o v e p l o t s h o w s t h a t t h e p r o p o r t i o n a l c o n t r o l l e r r e d u c e d b o t h t h e r i s e t i m ea n d t h e s t e a d y - s t a t e e r r o r , i n c r e a s e d t h e o v e r s h o o t , a n d d e c r e a s e d t h e s e t t l i n gt i m e b y s m a l l a m o u n t .

P r o p o r t i o n a l - D e r i v a t i v e c o n t r o l

N o w , l e t ' s t a k e a l o o k a t a P D c o n t r o l . F r o m t h e t a b l e s h o w n a b o v e , w e s e e t h a tt h e d e r i v a t i v e c o n t r o l l e r ( K d ) r e d u c e s b o t h t h e o v e r s h o o t a n d t h e s e t t l i n g t i m e .T h e c l o s e d - l o o p t r a n s f e r f u n c t i o n o f t h e g i v e n s y s t e m w i t h a P D c o n t r o l l e r i s :

L e t K p e q u a l s t o 3 0 0 a s b e f o r e a n d l e t K d e q u a l s 1 0 . E n t e r t h e f o l l o w i n g c o m m a n d si n t o a n m - f i l e a n d r u n i t i n t h e M a t l a b c o m m a n d w i n d o w .

K p = 3 0 0 ;K d = 1 0 ;n u m = [ K d K p ] ;d e n = [ 1 1 0 + K d 2 0 + K p ] ; t = 0 : 0 . 0 1 : 2 ;s t e p ( n u m , d e n , t )

Page 6: CTM_ PID Tutorial

24/11/11 CTM: PID Tutorial

6/9www.engin.umich.edu/group/ctm/PID/PID.html

T h i s p l o t s h o w s t h a t t h e d e r i v a t i v e c o n t r o l l e r r e d u c e d b o t h t h e o v e r s h o o t a n d t h es e t t l i n g t i m e , a n d h a d s m a l l e f f e c t o n t h e r i s e t i m e a n d t h e s t e a d y - s t a t e e r r o r .

P r o p o r t i o n a l - I n t e g r a l c o n t r o l

B e f o r e g o i n g i n t o a P I D c o n t r o l , l e t ' s t a k e a l o o k a t a P I c o n t r o l . F r o m t h et a b l e , w e s e e t h a t a n i n t e g r a l c o n t r o l l e r ( K i ) d e c r e a s e s t h e r i s e t i m e , i n c r e a s e sb o t h t h e o v e r s h o o t a n d t h e s e t t l i n g t i m e , a n d e l i m i n a t e s t h e s t e a d y - s t a t e e r r o r .F o r t h e g i v e n s y s t e m , t h e c l o s e d - l o o p t r a n s f e r f u n c t i o n w i t h a P I c o n t r o l i s :

L e t ' s r e d u c e t h e K p t o 3 0 , a n d l e t K i e q u a l s t o 7 0 . C r e a t e a n n e w m - f i l e a n d e n t e rt h e f o l l o w i n g c o m m a n d s .

K p = 3 0 ;K i = 7 0 ;n u m = [ K p K i ] ;d e n = [ 1 1 0 2 0 + K p K i ] ;

t = 0 : 0 . 0 1 : 2 ;s t e p ( n u m , d e n , t )

R u n t h i s m - f i l e i n t h e M a t l a b c o m m a n d w i n d o w , a n d y o u s h o u l d g e t t h e f o l l o w i n gp l o t .

Page 7: CTM_ PID Tutorial

24/11/11 CTM: PID Tutorial

7/9www.engin.umich.edu/group/ctm/PID/PID.html

W e h a v e r e d u c e d t h e p r o p o r t i o n a l g a i n ( K p ) b e c a u s e t h e i n t e g r a l c o n t r o l l e r a l s or e d u c e s t h e r i s e t i m e a n d i n c r e a s e s t h e o v e r s h o o t a s t h e p r o p o r t i o n a l c o n t r o l l e rd o e s ( d o u b l e e f f e c t ) . T h e a b o v e r e s p o n s e s h o w s t h a t t h e i n t e g r a l c o n t r o l l e re l i m i n a t e d t h e s t e a d y - s t a t e e r r o r .

P r o p o r t i o n a l - I n t e g r a l - D e r i v a t i v e c o n t r o l

N o w , l e t ' s t a k e a l o o k a t a P I D c o n t r o l l e r . T h e c l o s e d - l o o p t r a n s f e r f u n c t i o n o ft h e g i v e n s y s t e m w i t h a P I D c o n t r o l l e r i s :

A f t e r s e v e r a l t r i a l a n d e r r o r r u n s , t h e g a i n s K p = 3 5 0 , K i = 3 0 0 , a n d K d = 5 0 p r o v i d e dt h e d e s i r e d r e s p o n s e . T o c o n f i r m , e n t e r t h e f o l l o w i n g c o m m a n d s t o a n m - f i l e a n dr u n i t i n t h e c o m m a n d w i n d o w . Y o u s h o u l d g e t t h e f o l l o w i n g s t e p r e s p o n s e .

K p = 3 5 0 ;K i = 3 0 0 ;K d = 5 0 ;

n u m = [ K d K p K i ] ;d e n = [ 1 1 0 + K d 2 0 + K p K i ] ;

t = 0 : 0 . 0 1 : 2 ;s t e p ( n u m , d e n , t )

Page 8: CTM_ PID Tutorial

24/11/11 CTM: PID Tutorial

8/9www.engin.umich.edu/group/ctm/PID/PID.html

N o w , w e h a v e o b t a i n e d t h e s y s t e m w i t h n o o v e r s h o o t , f a s t r i s e t i m e , a n d n o s t e a d y -s t a t e e r r o r .

G e n e r a l t i p s f o r d e s i g n i n g a P I D c o n t r o l l e r

W h e n y o u a r e d e s i g n i n g a P I D c o n t r o l l e r f o r a g i v e n s y s t e m , f o l l o w t h e s t e p s s h o w nb e l o w t o o b t a i n a d e s i r e d r e s p o n s e .

1 . O b t a i n a n o p e n - l o o p r e s p o n s e a n d d e t e r m i n e w h a t n e e d s t o b e i m p r o v e d2 . A d d a p r o p o r t i o n a l c o n t r o l t o i m p r o v e t h e r i s e t i m e3 . A d d a d e r i v a t i v e c o n t r o l t o i m p r o v e t h e o v e r s h o o t4 . A d d a n i n t e g r a l c o n t r o l t o e l i m i n a t e t h e s t e a d y - s t a t e e r r o r5 . A d j u s t e a c h o f K p , K i , a n d K d u n t i l y o u o b t a i n a d e s i r e d o v e r a l l r e s p o n s e .

Y o u c a n a l w a y s r e f e r t o t h e t a b l e s h o w n i n t h i s " P I D T u t o r i a l " p a g e t o f i n do u t w h i c h c o n t r o l l e r c o n t r o l s w h a t c h a r a c t e r i s t i c s .

L a s t l y , p l e a s e k e e p i n m i n d t h a t y o u d o n o t n e e d t o i m p l e m e n t a l l t h r e ec o n t r o l l e r s ( p r o p o r t i o n a l , d e r i v a t i v e , a n d i n t e g r a l ) i n t o a s i n g l e s y s t e m , i f n o tn e c e s s a r y . F o r e x a m p l e , i f a P I c o n t r o l l e r g i v e s a g o o d e n o u g h r e s p o n s e ( l i k e t h ea b o v e e x a m p l e ) , t h e n y o u d o n ' t n e e d t o i m p l e m e n t d e r i v a t i v e c o n t r o l l e r t o t h es y s t e m . K e e p t h e c o n t r o l l e r a s s i m p l e a s p o s s i b l e .

U s e r F e e d b a c k

W e w o u l d l i k e t o h e a r a b o u t d i f f i c u l t i e s y o u h a d w i t h t h e t u t o r i a l s , s u g g e s t i o n sy o u h a v e f o r i m p r o v e m e n t , e r r o r s t h a t y o u f o u n d , o r a n y o t h e r c o m m e n t s t h a t y o uh a v e . T h i s f e e d b a c k i s a n o n y m o u s ; i n c l u d e y o u r e m a i l a d d r e s s i f y o u w a n t a r e p l y .

Submit Feedback Reset

P I D E x a m p l e sC r u i s e C o n t r o l | M o t o r S p e e d | M o t o r P o s i t i o n | B u s S u s p e n s i o n | I n v e r t e dP e n d u l u m | P i t c h C o n t r o l l e r | B a l l a n d B e a m

T u t o r i a l s

Page 9: CTM_ PID Tutorial

24/11/11 CTM: PID Tutorial

9/9www.engin.umich.edu/group/ctm/PID/PID.html

B a s i c s | M o d e l i n g | P I D | R o o t L o c u s | F r e q u e n c y R e s p o n s e | S t a t e S p a c e |D i g i t a l C o n t r o l | E x a m p l e s

8 / 2 6 / 9 7 D K