280_fa4-3

Upload: abdallah-omar-al-ayoubi

Post on 04-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 280_FA4-3

    1/5

    Application of predictive control to a toy helicopter

    Jonas Balderud and David I. Wilson

    Department of Electrical Engineering

    Karlstad University, Sweden

    [email protected]

    Keywords: Matlab/Simulink, optimal control, heli-copter, MPC

    Abstract

    A toy helicopter makes for an impressive classroomcontrol demonstration. However the challenge to ob-tain a robust, stable, multivariable controller is non-

    trivial given the nonlinear nature of the helicopter, thestochastic nature of the disturbances, and the perfor-mance limitations of PCs. This paper applies a modelpredictive controller using the Mathworks xPC tar-get to obtain significantly improved results over thatachievable using classical control algorithms.

    1 Predictive control in an education context

    In 1997, Karlstad University purchased, at not incon-siderable expense, a toy helicopter with two degrees offreedom and with three inputs as shown in Fig. 1. The

    intention was to use this bench-scale model in our au-tomatic control education to supplement our existingcollection of laboratory equipment. Our wish was for amulti-input/multi-output (possibly non-square) inter-acting laboratory plant that exhibited both stable andunstable modes, possessing time constants in the or-der of seconds, and most importantly, to be visuallyarresting. This latter feature in particular is due tothe simple fact that the helicopter is practically un-controllable under manual operation. The helicopterfrom Humusoft1 satisfied most of these demands andwe demonstrated it successfully in introductory controlcourses and during university open days.

    However some debilitating drawbacks for this labora-tory plant quickly became apparent such as severe stic-tion nonlinearities, and the difficulty in developing awhite, or even grey-box model of the plant. Thesedrawbacks are such that apart from the initial demon-stration, we found that we could not use the helicopterproductively until late in our advanced control course.This is, of course, poor utilisation of an expensive re-

    1www.humusoft.cz

    Figure 1: The bench-scale 2DOF helicopter from Humu-soft.

    source. Some of these issues are independent of thehelicopter and are further discussed in [1].

    The helicopter challenged us in the Mat-

    lab/Simulink environment using a modest 266MHzcomputer. While the Real-time Toolbox (also fromHumusoft) performed adequately at modest samplingrates (0.1s and upwards), this was inadequate for thehelicopter.

    The remainder of the paper is as follows. Section 2reviews state-space model predictive control with con-straints and section 3 outlines the model developmentand identification of key parameters and the rationalbehind the implementation of MPC on a PC running adedicated real-time operating system. Section 4 showsthe performance of the MPC control scheme and sec-

    tion 5 finishes with some conclusions.

    2 Model predictive control

    Model Predictive Control (MPC) refers to a family ofcontrollers that use a model to compute an input tra-jectory in order to optimize the future behaviour of theplant. The optimization is repeated each sample, asonly the first future manipulated variable adjustment

    Proceedings of the 2002 IEEE InternationalConference on Control ApplicationsSeptember 18-20, 2002 Glasgow, Scotland, U.K.

    0-7803-7386-3/02/$17.00 2002 IEEE 1225

  • 7/30/2019 280_FA4-3

    2/5

    is actually implemented on the plant. MPC while per-haps an odd choice for an aerospace application, is verypopular in the chemical processing industry due to itsability to handle saturation constraints, [24]. Thispaper also explores the possibility to apply MPC ona high-speed plant which would traditionally be con-trolled by a much simpler algorithm implemented inan embedded system.

    The MPC algorithm is well known and is reviewed in[5]. For this application we use a state-space approach,[6], with a differenced input

    x(k + 1) = Ax(k) + Bu(k) (1)

    y(k) = Cx(k) (2)

    where is the difference operator defined as 1 q1,and q1 denotes the backward shift operator. In thelinear SISO case, the predicted output j samples in thefuture is given by,

    yp(k + j) = yf(k + j) +

    j1i=0

    CAji1Bu(k + i) (3)

    where yf(k + j) is the so-called free response, whichaccounts for the initial conditions, at time k, and theinput adjustments done in the past.

    Over a prediction horizon, Np, using a control horizon,Nc, the stacked predicted output vector, yp = [yp(k +1), , yp(k + Np)]

    T is given by

    yp = yf + Hu (4)

    where the dynamic matrix H is defined as,

    H =

    h1,1 h1,Nc...

    . . ....

    hNp,1 hNp,Nc

    (5)

    with the scalar elements hj,i given by,

    hj,i =

    CAjiB, j i0, j < i

    (6)

    The unconstrained cost function to be minimized is aweighted sum of output deviations from a desired tra-jectory, r, and input trajectory,

    J = (ryfHu)T(ryfHu) + u

    Tu (7)

    with solution

    u =

    HTH + 1

    HT(r yf) (8)

    Since the current state appears implicitly in the termyf of Eqn. 8, a state observer is needed to completethe control algorithm. The state observer, such as a

    Kalman Filter, provides direct feedback into the con-trol law, which is different from the somewhat ad-hocsolution used by the DMC, [7], algorithm.

    This SISO control law is extended to the multivariablecase by stacking the input and output vectors,

    u = [u1, , un]

    T

    , yp =

    yp1, , ypnT

    (9)

    so now dynamic matrix becomes,

    H =

    H1,1 H1,n...

    . . ....

    Hn,1 Hn,n

    (10)

    where each block matrix Hi,j predicts the effect of in-put j on the output i.

    Owing to the significant nonlinearities of the helicopter,

    (refer Fig. 1), the accepted approach in such cases is touse a full nonlinear model to predict the free response,while using a linearised plant model to compute thecontrol moves, [8]. The alternative of solving the fulloptimisation problem while avoiding the explicit lin-earisation step, is extremely computationally demand-ing, and rarely used, [9].

    In addition to nonlinear dynamics, the helicopter isconstrained in motor power (input), and unlike somecompetitors products, it is constrained in both out-puts rotations. Since adding constraints to the optimi-sation problem precludes the possibility of an analyt-

    ical solution, most commercial MPC formulations usea quadratic programming approach. However in ourcase, we could not afford the computation time to solvea QP, so we simply saturated the inputs if the optimisedsolution violated the hard constraints. A minor algo-rithmic improvement could be to remove those inputsthat violated the constraints from the decision vector,and repeat the now smaller optimisation problem. Inpractice, as shown in section 4, constraint violation wasnot a problem under typical operation.

    3 Implementation of MPC on the helicopter

    3.1 Helicopter model

    The helicopter has two degrees of freedom, (elevation,azimuth), and three inputs (main and side rotors, anda moveable counter weight). Four states are needed tomodel the position and velocity of the body in the twoaxes,(1, 1, 2, 2), and two further states, (1, 2), areneeded to model the two motor dynamics giving a to-tal of six, coupled, highly-nonlinear states. A semi-

    1226

  • 7/30/2019 280_FA4-3

    3/5

    rigorous model incorporating stiction,

    Im1 =K121 (11|1| + 21)1

    Tc1sign(1)

    1 e(|1|/10 )

    Tg sin(1 + 1) KG21 cos(1)

    + KC22

    cos(1)

    Ir1 1 =u1 a121 b11

    sin(1)Is0 2 =sin(1)K2|2|2

    (12|2| + 22)2

    Tc2sign(2)

    1 e(|2|/20 )

    sin(1 + 2)

    Kr1

    u1 Kr2

    a121 + b11

    Ir2 2 =u2 a2|2|2 b22

    was developed in [10] which also details the identifica-tion of the 23 plant parameters. The two outputs arethe axis rotations 1 and 2. The 95% settling time for

    the elevation dynamics is around 36s while the mo-tor dynamics are an order of magnitude faster, so asuitable sampling time is 0.05s giving prediction andcontrol horizons of Np = 60 and Nc = 30 respectively.

    3.2 Implementation using the target hardware

    As is typical in these undertakings, the simulationsin Matlab worked perfectly. However the controllercomputation time on a 1GHz machine was in the orderof 0.08s, which clearly indicated that running under amore modest 266MHz machine, with the added load ofservicing the real-time components in a timely mannerwas unlikely to suffice. Table 1 lists our implementation

    alternatives for an MPC controller in increasing orderof development complexity. The Humusoft real-timeenvironment (options 13) has both the disadvantageof requiring an excessive sample time, and an enforcedone-step delay. In addition, the at times sporadic sam-pling timings played havoc with the model-predictivecontrollers whereas the PI type are relatively immune.

    33 66 200 266 333 450 650 1000

    10

    50100200

    unacceptable

    acceptable

    Machine clock speed [MHz]

    Samplingrate[Hz]

    Figure 2: Maximum sampling rate using xPC as a func-tion of clockspeed.

    Implementing the controller on a dedicated PC run-ning the xPC target real-time kernel solves the timingproblems that plague real-time windows applications,but also considerably increases the development com-

    plexity and cost. This is partly offset by the minimalhardware demands as illustrated in Fig. 2 which givesthe achievable sampling rate for the MPC controllergiven machine clock speed measured on a variety of PChardware. The maximum achievable sampling rate isboth a function of clock-speed and processor architec-ture which is why the value for the 200MHz machine islower than expected. Of the next three options listed in

    Table 1, only the last is feasible given the limitationsof the xPC development environment (e.g. Matlabm s-functions and Matlab matrix library routines areunsupported, limitations on the size of variables used,the computational overhead ofSimulink passing largematrices between blocks etc).

    The main algorithmic stumbling blocks for the MPCcalculations are the re-linearisation of the nonlinearsystem, and the nonlinear integration step requiredfor the prediction. These operations are not suitedfor the block diagram nature of Simulink, and evenif attempted, are comparatively slow compared to C

    code. The disadvantage of C code is that it blurs thetransparency of the application, an important consid-eration in an education environment. The streamliningof the computation required the following three steps:(1) employing simple explicit integrators (as proposedin [11]), (2) using analytical Jacobians and a Pade ap-proximation method for the linearisation and discreti-sation steps, and (3) only partially computing the least-squares solution to the optimisation using a Choleskydecomposition. In all these cases, we could not use theinternal Matlab routines since substantial modifica-tions to the C source code was required. At large sam-pling times, the optimisation problem becomes illcondi-tioned where a singular value, rather than a Cholesky,

    decomposition is more appropriate. However this dras-tically increases the already demanding computationalload, and was not deemed necessary in this application.

    Table 1: Hardware implementation alternatives

    Environment Max. sampling rate [Hz]266MHz 1GHz

    Matlab/RT 3 12Simulink/RT & Chol N/A 143Simulink/RT sfunc. N/A 146

    xPC/C sfunc. & Chol 63 234

    xPC/C sfunc. (own) 65 274

    Since the MPC algorithm uses only the first of the com-puted control moves for the control horizon (in our case30), it makes sense only to compute that one. Sav-ings can be made by re-ordering the system matricesand terminating the back-substitution step after u(1)is computed.

    A further issue characteristic of receding horizon con-

    1227

  • 7/30/2019 280_FA4-3

    4/5

    trollers is that if we increased the sampling rate, per-haps to better capture some of the nonlinearities in thelinearised model, we also increase the computationalload of the control law. This is because the horizonlength, which is governed by the open-loop time con-stants remains the same. Fig. 3 shows the breakdownof the computational load of the MPC algorithm. Theexpensive operations are the Cholesky decomposition,

    and particularly the 2Nc 2Np matrix multiplicationHTH which have order at least O(NpN2c ). The nonlin-ear prediction step, the linearisation, and the creationof the dynamic matrix dominate only at the shortercontrol horizons.

    10 20 30 40 50 60 70

    0.0001

    0.001

    0.01

    0.1

    HTH

    chol Ax=blin & predictCreate DMC

    ryp,+ etc.

    Control Horizon, Nc

    Time[s]

    Figure 3: Execution time for key numerical operations asa function of control horizon, Nc with a predic-tion horizon ofNp = 60.

    4 Results

    Fig. 4 shows the controlled response of the helicopterusing two PID controllers. This control is only barely

    acceptable, and exhibits excessive stiction and, attimes, excessive oscillation.

    0.2

    0

    0.2

    Elevation

    0.2

    0

    0.2

    0.4

    Azimuth

    0 50 100 150

    1

    0.5

    0

    0.5

    1

    Time (sec)

    Inputs

    Figure 4: Closed-loop response of the helicopter using 2PID controllers with a t = 10ms.

    Fig. 5 shows the improved closed-loop response of thehelicopter under MPC following a command signal andsubjected to manual disturbances. While the PID el-evation control is comparable to the predictive con-troller, the azimuth response, which is considerablymore challenging, is substantially worse. The figurestarts with prediction horizon of Np = 60, and controlhorizons Nc = 30, then increasing to Np = 120, Nc =

    40, and finally Np = 60, Nc = 20. Control horizons ofabout 50 is an upper limit.

    It is interesting to note that integration of the full non-linear model is required for the prediction step in theestimator (as well as for the computation of the freeresponse in the MPC algorithm). If we relaxed any ofthe model demands (such as using a linearised model,or skip over the hard discontinuities), the estimatedstates from the Kalman filter rapidly diverged, and con-sequently the controller went unstable.

    4.1 Model robustnessThe model fidelity of the MPC can easily be compro-mised by moving the small counter weight on the he-licopter as an unmeasured disturbance. Fig. 6 showsthat the plant model does play a vital role in the con-troller. The controlled performance is noticeably dete-riorated when moving the weight from the design po-sition (100%) to 90% and 75% of the full-scale range,while a 50% change is on the brink of instability. Inthis disturbance however, the weight position is knownand could be incorporated in the model.

    0.2

    0

    0.2

    0.4

    0.6

    Elevation

    0.1

    0

    0.1

    0.2

    0.3 100% 90% 75% 50%

    Azimuth

    0 50 100 150

    1

    0.5

    0

    0.5

    1

    Time (sec)

    Inputs

    Figure 6: Closed-loop response of the helicopter usingMPC with a significant model/plant mis-matchintroduced by moving the counter-weight.

    1228

  • 7/30/2019 280_FA4-3

    5/5

    0.4

    0.2

    0

    0.2

    0.4

    Elevation

    Np=60, N

    c=30. N

    p=120, N

    c=40. N

    p=60, N

    c=20.

    0.05

    0

    0.05

    0.10.15

    Azimuth

    0 20 40 60 80 100 120 140 160 180

    1

    0.5

    0

    0.5

    1

    Time (sec)

    Inputs

    Figure 5: Closed-loop response of the helicopter using MPC with different prediction and control horizons

    5 Conclusions

    The bench-scale helicopter supplied by Humusoftmakes for a marvellous and impressive control demon-stration. Model predictive control is popular in theprocess industries, but does require substantial inter-sample computation. Due to the nonlinear model, thedemand for relatively short sampling times, coupledwith long prediction, and in particular, control hori-

    zons, Simulink or even raw Matlab with the real-time toolbox did not suffice. In order for the demon-stration to be sufficiently robust, we found that thecontroller must be implemented primarily in C withmany algorithmic shortcuts and streamlined optimisa-tions, and for it to be implemented on a stand-alone PCrunning xPC target. While the development and costfar outweighs what we had originally expected, the con-trolled performance is significantly improved over thatachievable using classical control algorithms.

    References

    [1] David Wilson. Optimal control teaching using Mat-lab: Have we reached the turning point yet? In ToreBjrnara, editor, Nordic Matlab Conference, pages II246 II251, Oslo, Norway, 1718 October 2001. ISBN82-995995-0-9.

    [2] David Clarke. Advances in Model-Based PredictiveControl. Oxford University Press, 1994.

    [3] S.J. Qin and T.A. Badgwell. An overview of industrialmodel predictive control technology. In J.C. Kantor,C.E. Garcia, and B. Carnahan, editors, Proc. Fifth In-

    ternational Conference on Chemical Process Control,number 316 in AIChE Symposium Series, pages 232256, Tahoe City, January 1996. AIChE.

    [4] J. M. Maciejowski. Predictive Control with Con-straints. PrenticeHall, 2002.

    [5] M. Morari and J.H. Lee. Model predictive control:Past, present and future. Computers and ChemicalEngineering, 23:667682, 1999.

    [6] P. Krauss, K. Dass, and H. Rake. Model-based pre-dictive controller with Kalman filtering for state es-timation. In D. Clarke, editor, Advances in Model-Based Predictive Control, pages 6983. Oxford Univer-sity Press, New York, 1994.

    [7] C. R. Cutler and B.L. Ramaker. Dynamic matrix con-trol - a computer control algorithm. In Proc. 1980Joint automatic Control Conference, San Fransisco,1980. American Institute of Chemical engineers.

    [8] J.H. Lee and N.L. Ricker. Extended Kalman FilterBased Nonlinear Model Predictive Control. Ind. Eng.Chem. Res., 33(6):15301541, 1994.

    [9] M.A. Henson. Nonlinear Model Predictive Control:current status and the future directions. Computersand Chemical Engineering, 23:187202, 1998.

    [10] Jonas Balderud. Modelling and Control of a Toy Heli-copter. Masters thesis, Karlstad University, ElectricalEngineering Department, December 2001.

    [11] David Wilson. End-UseOriented Discretisation ofTypical Chemical-Process Models. In Proceedings ofthe IASTED Modelling, Identification and Control,Innsbruck, Austria, Feb 1821 2002.

    1229