backwoods control theory

Upload: akozy

Post on 04-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Backwoods Control Theory

    1/18

    Backwoods Control Theory Page 1

    Backwoods Control Theory

    1 IntroductionThe usual university courses on control theory dig deep into the mathematics of control, but do not govery far in explaining how to apply the theory to real life. Also, these courses tend to be to analog circuitfolk, not to folk who are destined to become software engineers. Until recently in real life most controlproblems were solved by circuit designers who had forgotten their university training and had learned afew techniques that work reliably to solve most of the control problems that one encounters. It is thesefew techniques, applied wisely, that constitute backwoods control theory.

    Backwoods control theory works well in most cases (there are still times when you need an expert).Unfortunately, most good practitioners of backwoods control are analog circuit folks, but these days thesolution of choice for most control problems is the embedded microcontroller. This paper is aboutbackwoods control for digital systems, and specifically for embedded applications.

    This paper talks about closed-loop (or feedback) control systems. This is the case when you are

    implementing a system like the one in Figure 1. The control software combines the feedback with thecommand to create the drive signal. The drive signal is amplified and applied to the plant, which changesits behavior. The plant behavior is measured and read by the control software as feedback. Since this allgoes in one big circle it is called "closed loop".

    Control

    Software

    drive

    feedback

    plant

    behavior

    command

    DAC

    Filter/

    ADC

    Digital Controller

    PlantAmplifier

    Measurement

    Figure 1: A generic computerized control system.

    Even though we're in the backwoods we still need to coversome theory. We'll be using differenceequations to model the plant and controller, and the z transform to analyze the difference equations andto describe the signals that go into and out of them. Then we'll use the z transform to tell us how thesystem will behave in closed loop.

    As you'll see, the z transform is a handy thing, but it only works on certain types of problems. If you candescribe your plant and your controller using linear difference equations, and if the coefficients of theequations don't change from sample to sample, then your controller and plant are linear and shift-invariant, and you can use the z transform. If the problem at hand won't allow you to model the plant andcontroller as linear shift invariant, and you won't be able to use the z transform.

    While all real-world plants are nonlinear in some sense, and have parameters that vary with time to somedegree, the majority of plants can be usefully modeled with linear time invariant differential equations.Once this is done the effects of sampling the input and updating the output at discrete intervals can betaken into account and a difference equation that describes the plant behavior from the software's point ofview can be produced.

    Let's say that you've reduced the behavior of the plant to a difference equation that looks like

    ( ) ( )LL +++++= 22112211 nnnnn ububxaxax ( 1 )

    RETURN

  • 7/29/2019 Backwoods Control Theory

    2/18

    Backwoods Control Theory Page 2

    wherexn is the output of the plant at sample time n, un is the command to the DAC at sample time n, andthe various a and b are constants set by the design of the plant, driver and ADC circuits.

    You can solve ( 1 ) forxn over time if you are given a specific sequence ofun using techniques verysimilar to those used to solve differential equations, but the process is just as tedious and obscure assolving differential equations, and just as error prone and frustrating. Furthermore if you want toinvestigate what happens when you add feedback to the system you would need to solve many equations

    like ( 1 ) over and over again.

    2 The z Transform

    One can use the Laplace transform to solve linear time-invariant differential equations, and to deal withmany common feedback control problems using continuous-time control. With a sampled-time systemyou deal with linear shift-invariant difference equations, and the tool for analysis is the z transform.

    Officially, the z transform takes a sequence of numbersxn and transforms it into an expressionX(z) thatdepends on the variable zbut not n. That's the transform part: the problem is transformed from one in thesampled time domain (n), and put it into the z domain. The z transform of x is denoted as Z(x) anddefined as:

    =

    == 0)()( nn

    nzxxZzX ( 2 )

    For example, if you have a signalxn = an

    you can plug it into ( 2 ) and get:

    az

    zzazX

    n

    nn

    ==

    =

    0

    )( . ( 3 )

    Officially ( 3 ) is valid for any value ofa, real or complex, that has a magnitude less than 1; in reality itturns out that all the math works even for |a| greater than 1.

    The most commonly used and most important property of the z transformation is that the z transform of asignal that is delayed by one sample time is the z transform of the original signal times z

    -1:

    =

    =

    = ===

    0

    1

    0

    1

    1

    1)(n

    nn

    n

    nn

    n

    nn zxzzxzxzX ( 4 )

    This seems pretty simplistic, but we'll get a lot of mileage out of it -- in fact, it's probably the only propertyof the z transform that you'll need to remember. Just for completeness, though, Table 1 lists some otherproperties of the z transform. If you feel inclined, it's good practice to use ( 2 ) or ( 4 ) to verify each one ofthese.

  • 7/29/2019 Backwoods Control Theory

    3/18

    Backwoods Control Theory Page 3

    Comments

    )(][ zkXkxZ n = kmust be a constant. ( 5 )

    )()(][ 2121 zXzXxxZ nn +=+ ( 5 ) and ( 6 ) togetherimply that the z transform is

    a linear operation.

    ( 6 )

    [ ] )(1

    1 zXz

    zxxZ nn=

    This is called a "firstdifference" -- its thediscrete time equivalent toa differential

    ( 7 )

    )(10

    zXz

    zxZ

    n

    m

    m =

    =

    A summation is thediscrete time equivalent toan integral.

    ( 8 )

    z

    zXxZ n

    )(][ 1 =

    This is the unit delay -- it'sthe fundamental operationin discrete-time analysis.

    ( 9 )

    [ ]

    = nznn

    xZzx11limlim

    1 This is called the "FinalValue Theorem" and is only

    valid if all the poles ofX(z)are stable.

    ( 10 )

    Table 1: z Transform Properties.

    2.1 An Example

    Figure 2 shows a motor and geartrain that we might use in a servo system. We're driving it with a voltage,and reading the position of the output gear with a potentiometer. Let's say that we're going to use it as ourplant. If we ignore all the nonlinearities in the system, and any difficulties with the motor performancechanging over time, and if we setx = vp and u = vi, then the difference equation that describes it mightlook like ( 11 ):

    +

    -

    Vi

    + -

    Vp

    Motor

    Pot

    m

    Figure 2: A voltage driven motor and gear train.

    121)1( ++= nnnn buaxxax ( 11 )

    You can take the ztransform of ( 11 ) without knowing whatxn orun are by applying ( 4 ) as appropriate(remember thatxn transforms toX(z) and un transforms to U(z)). If you do this you get:

    121 )()()1)(()( ++= bzzUazzXzazXzX ( 12 )

  • 7/29/2019 Backwoods Control Theory

    4/18

    Backwoods Control Theory Page 4

    Notice a cool thing: We've turned the difference equation into an algebraic equation! Turns out it'sperfectly fair to treat zas an algebraic variable. If we do, we can solve ( 12 ) pretty easily:

    ( ) 121 )()1(1)( =++ bzzUazzazX , ( 13 )

    ( )( )azz

    zbzU

    azaz

    zbzUzX

    =

    ++

    =1

    )(

    )1(

    )()(2

    . ( 14 )

    With ( 14 ) if we know the z transform ofu we can find the z transform ofxvery easily by plugging it intothe right-hand side of the equation. Then we could find the inverse z transform of the result to find outwhatxis in the time domain.

    If this was all that we could do with the z transform it would be a useful tool to have around, but probablynot something you'd want in your toolkit for everyday use. Fortunately, the z transform goes beyondallowing easy solutions to specific difference equations.

    2.2 Transfer Functions

    We can take the idea of plugging in signals one step further and express the relationship betweenXandUas a ratio:

    azaz

    zb

    zU

    zXzH

    ++==

    )1()(

    )()(

    2 ( 15 )

    The function H(z) is called the "transfer function" of the system -- it shows how the input signal istransformed into the output signal. In pure z domain terms the transfer function of a system is alwaysconstant: it isn't affected by the nature of the input signal, nor does it vary with time.

    The easy thing that I can do with the transfer function is to predict the behavior of the motor. Let's say Iwant to see what the motor will do ifxgoes from 0 to 1 at time n = 0, and stays there forever. This iscalled the "unit step function", and a system's response to it is very informative. The z transform of theunit step response is z/(z-1). To simplify the math, lets also say that a = 0.8 and that b = 0.2. In that case Ihave:

    1)( = zzzU

    ( 16 )

    ( ) ( )8.01

    2.0

    18.08.1

    2.0)(

    )(

    )()(

    2

    2

    2 =+

    ==zz

    z

    z

    z

    zz

    zzU

    zU

    zXzX ( 17 )

    There's two ways I can go with ( 17 ). First, I can solve it by polynomial division. This is a good way to goif I want to graph the response vs. time, and it is simple to do. The result looks like this:

    L

    321

    3

    2

    048.156.02.08.06.28.2

    2.0)( ++=

    += zzz

    zzz

    zzX ( 18 )

    The system response is now expressed as a polynomial in z-1

    . It is trivial to apply ( 4 ) in reverse to get

    L048.1,56.0,2.0,0=x ( 19 )

    This gives the response, but it doesn't tell you if the system will ever settle out, or what it will settle out to.The second method that you can use is partial fraction expansion to break things down into easy bits,followed by doing the reverse transform by inspection. The partial fraction expansion ofX(z) is

    ( ) ( ) ( ) 8.04

    1

    4

    18.01

    2.0)(

    22

    2

    +=

    =

    z

    z

    z

    z

    z

    z

    zz

    zzX ( 20 )

  • 7/29/2019 Backwoods Control Theory

    5/18

    Backwoods Control Theory Page 5

    You can use ( 20 ) with the transforms in Table 2 to get

    n

    n nx 8.01+= ( 21 )

    When you do this it becomes immediately clear that the motor position and velocity start at zero, then themotor velocity increases with its velocity increasing asymptotically to one count per step. This is exactlywhat you'd expect from a motor with a constant voltage on it.

    In fact, for all but a few special cases there will always be certain elements of the system response (in thiscase the 1 and the 0.8

    n) that will be there because of the nature of that system's transfer function. Even

    these special cases happen because the input signal happens to mask portions of the system output; ingeneral this will not be the case.

    )(kf )(zF Comments

    )(kd 1

    ==

    otherwise

    kkd

    0

    01)( 1

    ( 22 )

    )(ku

    1zz