Control Engineering Practice 6 (1998) 1287—1293
An integrated software environment for the design and real-time implementation of control systems Masanobu Koga*, Hiroaki Toriumi, Mitsuji Sampei Department of Mechanical and Environmental Informatics, Tokyo Institute of Technology, 2-12-1, Oh-okayama, Meguro-ku, Tokyo 152-8552, Japan Received 10 February 1998; accepted 31 July 1998
Abstract This paper introduces the development of a CAD environment for control systems, which supports not only the analysis of control systems, and the design of controllers, but also the real-time implementation of controllers. By utilizing this software, the control engineer is able to repeat the procedure for the modification of both controllers and experiments, without recompiling, to attain better performance. The software also offers a facility to update the parameters of controllers without interrupting the real-time control, which helps in the on-line tuning of controllers. Otherwise, if some of the parameters of a controller are changed on-line, the control input may change in a discontinuous fashion. This would have a serious effect on the control systems. A method for the on-line tuning of a state feedback controller with a state observer is proposed and verified through an experiment with an inverted pendulum. 1998 Elsevier Science ¸td. All rights reserved. Keywords: Computer-aided control system design; real-time control; simulation; on-line tuning
1. Introduction In this paper, an integrated software environment for the design and real-time implementation of control systems is introduced. It supports not only off-line design, but also on-line design. In other words, it is possible to undertake an analysis of a plant, synthesis of a controller, modeling of the plant, and real-time implementation for experimental use, all in one software environment. By utilizing this software, it is possible to repeat the design of control-system cycle efficiently, to achieve good performance of the closed-loop system. This paper considers the procedure for designing control systems from the software environment point of view in Section 2. The software also offers the facility to update the parameters of controllers without interrupting the realtime control, which helps in the on-line tuning of controllers. If some parameters of the controller are changed on-line, the control input may change in a discontinuous way. This may have serious effect on the control systems, but this effect was not considered in an earlier paper on
* Corresponding author. Tel: #81 3 5734 2328; fax: #81 3 5734 2328; e-mail:
[email protected].
the topic (Koga et al. 1996). A method for the on-line tuning of controllers is considered in Section 3. The system has been used in research and education, and has considerably reduced the implementation time, e.g. when developing new laboratory exercises, or when a control algorithm is being tested in a laboratory experiment. A few examples are described in Section 4.
2. Design of control systems 2.1. Control-system design cycle Many computer-aided control system-design (CACSD) software packages have been developed in various universities and companies. The typical procedure for the design of control systems supported by such software is shown in Fig. 1. First, the plant, whose mathematical model has been determined by input—output data or a physical formula, is analysed. Then, the synthesis of the controller, simulations, and experiments are repeated until the design specification is satisfied. After the performance of the closed-loop system has been verified by simulation, the program for the experiment is implemented in another
0967-0661/98/$ — see front matter 1998 Elsevier Science Ltd. All rights reserved PII: S 0 9 6 7 - 0 6 6 1 ( 9 8 ) 0 0 1 2 3 - 3
1288
M. Koga et al. /Control Engineering Practice 6 (1998) 1287—1293
Fig. 2. New design cycle of control systems. Fig. 1. Conventional design cycle of control systems.
software environment. It is apparent that the design of the control system and the real-time implementation are separated in this procedure. This paper deals with a procedure for the design of control systems, in which the design specification is satisfied by iterating the analysis of the plant, the synthesis of the controller, simulations, experiments, and the modeling of the plant. For this purpose, a new software environment has been developed, which comprehensively supports the whole proposed design cycle. Fig. 2 shows the proposed design cycle for control systems. There are many methods for the modeling (identification) of a plant. Among these, the modeling based on the input—output data is indispensable to treat the robustness of the plant to parameter variation and uncertainty. This leads to the requirement for a real-time implementation facility. Therefore, a real-time implementation facility was integrated with the MATX CACSD software to develop a new software environment RTMATX. This paper deals with some problems encountered in the integration of a real-time implementation facility with CACSD software, and gives solutions to them. 2.2. Man—machine interface MATX provides not only a command-line interpreter (matx) whose interfaces are similar to the use of MATLAB [The Math Works, 1992a] but also a compiler (matc) that accepts the same syntax as that of matx, and outputs portable C language code. The user can extend the functionality of a program by realizing algorithms as functions in ‘mm-files’. The interpreter enables the
mm-files to be tested interactively, file-by-file or line-byline. If the mm-file implementation of an algorithm is not efficient enough, the mm-files being examined are compiled into portable C language files, using the compiler. Then those C files are compiled and linked up with the run-time library, using a C compiler, to generate the desired executable program. It is possible to call user C functions from MATX functions by linking C language routines to the executable program. No graphical user interface is available for MATX at the moment.
3. Real-time implementation issue In this section, some issues concerning the integration of a real-time implementation facility with CACSD software are considered, and it is shown that RTMATX produces a solution to them. 3.1. Speed of computation The speed of computation is a crucial point in realtime implementation. Therefore, the program should be compiled rather than be executed by the interpreter. RTMATX programs can be compiled to be as fast as C programs. An example is shown in Section 4. 3.2. Tuning of controller without recompiling There are some commercially available CACSD software packages that support real-time implementation, such as AutoCode for Matrixx [Integrated Systems,
M. Koga et al. /Control Engineering Practice 6 (1998) 1287—1293
1991] and the C-code generation toolbox for Simulink [The Math Works, 1992b]. When people use such software, they have to recompile the generated code for the experiment if they change the parameters of the controller, or at least the structure of the controller. This makes the iteration of the procedure for control-system design inefficient. Compared with the method above, which generates C code from block diagrams, it is possible to repeat the tuning of controllers and experiments without recompiling in RTMATX, since this package allows the inclusion of routines for the design of control systems in the implemented programs. 3.3. Memory management for real-time implementation If people write a program with a matrix notation like Matlab, the program is easy to read. However, the size of memory required for the calculations is not determined until the execution time. This is why functions like malloc( ) are necessary. These functions are slow, since they are general-purpose memory-management functions. Therefore, methods to improve the speed of computation should be considered. MATX has its own memory-management mechanism to reduce the number of calls to the memory-allocation function [Koga et al., 1996]. In particular, no memoryallocation function is called when real-time control is executed. 3.3.1. Memory management in MATX When a block of memory is required, the memorymanagement list in MATX is referred. If there exists a memory block of suitable size in the list, this is used. Otherwise, malloc( ) is used to get the memory from the operating system. When a block of memory is no longer needed, it is registered in the memory-management list instead of being returned to the OS. Therefore, the exact size of the memory required for a series of calculations is registered in the memory-management list. When the same calculation is executed again, no further malloc( ) is necessary. This strategy for memory management is extremely efficient for programs like simulation, which repeat the same calculations, because the memory-allocation function is called only once. 3.3.2. Memory management in RTMATX The memory management in RTMATX is almost the same as in MATX. RTMATX calls the function for realtime control once, in advance, before starting the realtime control. At this stage, the amount of memory needed for the calculation of real-time control is registered in the list. No further memory-allocation function is called when the function of real-time control is executed at every sampling period.
1289
3.4 On-line parameter changes In most cases, designers have to interrupt the process of real-time control in order to change the parameters of the controller. If the real-time control is not halted, the incorrect control input may be calculated, since some parameters are updated at that moment, and others are not. RTMATX allows for the changing of the parameters of the controller without stopping the real-time control. This facility makes it possible to iterate efficiently through the procedure for control-system design. 3.4.1. How to update parameters in real time Two tables of parameters are utilized in order to share the parameters of control systems between a non-realtime function and a real-time function. As shown in Fig. 3, ‘real-time function’ refers here to the parameters held in one table, used for calculation, while a non-realtime function changes the parameters in the other table. After all the parameters in the table have been changed, the two parameter tables are exchanged. Accordingly, it is possible to change the parameters that are shared between a real-time function and a non-real-time function, while maintaining the consistency of all the parameters. 3.4.2. Real-time variables If the variables that are to be shared are declared as real-time variables, two parameter tables, including these variables, are prepared automatically. Therefore users do not have to take care of updating the table of shared parameters. An example program for real-time implementation is given in Section 4.
Fig. 3. Exchange of parameter tables.
1290
M. Koga et al. /Control Engineering Practice 6 (1998) 1287—1293
3.5. On-line tuning of controllers
is consistent with x' (t ), the estimated state of the old observer
If some of the parameters of the controller are changed on-line, the control input may change discontinuously. Since this could have a serious effect on the control systems, an appropriate method for changing parameters on-line should be considered.
zR (t)"A< z (t)#B< y(t)#J< u(t) x' (t)"C< z (t)#D< y(t). System (1)—(2) is transformed using the state transformation x"¹xN to the equivalent system
3.5.1. On-line tuning of state feedback and observer The effect of changing the parameters of the controller without stopping the real-time control is considered here. The state equation and the output equation of the plant are described as xR "Ax#Bu
(1)
y"Cx
(2)
where x3RL, u3RK and y3RN. The system is assumed to be controllable and observable. The controller consists of state feedback
xNQ (t)"AM xN (t)#BM u(t) y(t)"CM xN (t), CM "[0 I ] N Let the minimum-order state observer for the equivalent system be described as zNQ (t)"AM K zN (t)#BM K y(t)#JM K u(t)
(6)
xNK (t)"CM K zN (t)#DM K y(t)
(7)
where
I
(3)
¸ L\N (8) 0 I N and ¸ is a constant matrix which determines the poles of the observer. Eqs. (7) and (8) give the state of the observer zN :
zR "AK z#BK y#JK u
(4)
zN (t)"[I 0] xNK (t)!¸y(t) L\N Let the initial state of the new observer be chosen as
x' "C< z#D< y
(5)
u"!Fx and minimum-order state observer (Ogata, 1990)
Assume that the parameters are changed around the equilibrium point, i.e., (x"0, u"0), at t"t . 3.5.2. State feedback It was found through some simulations and experiments that the effect of changing the state feedback on-line is small, since the state is changed around the equilibrium point, x&0. 3.5.3. State observer When the parameters of the observer are changed, the estimated state x' may change discontinuously, and the control input u may change dramatically. Now, consider a method to determine z (t ), the initial state of the updated observer, so that x' (t ), the estimated state of the new observer zR (t)"AK z (t)#B< y(t)#J< u(t) x' (t)"C< z (t)#D< y(t)
[CM K DM K ]"
zN (t )"[I 0] xNK (t )!¸ y(t ) L\N then the estimated state of the new observer is consistent with that of the old observer as follows: xNK (t )"CM K zN (t )#DM K y(t ) I ¸ (t )# y(t ) " L\N zN 0 I N "xNK (t )
4. Example 4.1. Inverted pendulum This section deals with some examples to illustrate the facility of RTMATX for simulation and real-time implementation. The first plant is the well-known inverted pendulum, shown in Fig. 4. When the state of the system is chosen as x2"[x x x x ]"[r h rR hQ ] then the state equation is described as
x x dx " dt (1#a sin x )\+a sin x cos x #a x #a cos x x #a sin x x#b u, (1#a sin x )\+a sin x #a cos x x #a x #a sin x cos x x#b cos x u,
M. Koga et al. /Control Engineering Practice 6 (1998) 1287—1293
1291
Fig. 5. Function for state equation.
Fig. 4. Inverted pendulum.
where a , b , and a are parameters of the plant. Next, GH G design an LQ state feedback control law (3) and an observer (4)—(5) for the linearized model of the plant (1)—(2). The observer is discretized for digital control such that z[k#1]"A< z[k]#B< y[k]#J< u[k] B B B u[k]"!Fx' [k] x' [k]"C< z[k]#D< y[k]
Fig. 6. Function for control input.
4.1.1. Simulation The simulation program consists of three functions, main( ), diff —eqs( ), and link —eqs( ). Function diff—eqs( ) is a function that calculates the derivative of state vector xR , and link —eqs( ) is a function that calculates the control inputs u. In main( ) the differential equation is integrated according to the RKF45 algorithm, automatically changing the step size to guarantee the specified computational error. The listing of diff—eqs( ) and link—eqs( ) are shown in Figs. 5 and 6. Note that the program can be written in almost the same way as the mathematical notation. See Koga (1995) for the detailed description. Fig. 7. Function for real-time control.
4.1.2. Real-time implementation The real-time implementation program consists of three functions, the main function, main( ), the on-line function, on—task( ), and the off-line function, off—task( ). The function on—task( ) is a function for the calculation of control inputs, and off—task( ) is the user-interface function for showing and changing parameters. Once the
real-time control starts, on—task( ) is called every sampling period. The listing of on—task( ) is shown in Fig. 7. The function sensor( ) returns the output of the plant, as measured by the sensors, and actuator( ) operates the actuator. Since the variables, Ah, Bh, Ch, Dh, Jh, F are
1292
M. Koga et al. /Control Engineering Practice 6 (1998) 1287—1293
Fig. 8. The initial state of observer is unchanged.
Fig. 10. Double-cart system.
Fig. 9. The initial state of observer is changed according to the proposed method.
declared as real-time variables, they can be changed while the real-time control is running. Note that the difference between the functions on—task( ) and link—eqs( ) in the simulation program consists of two lines. Therefore, it is possible to obtain the on-line function for the real-time experiment from the simulation program with a two-line change. This is one of the most useful features of RTMATX. 4.1.3. On-line tuning Figs. 8 and 9 show the experimental results with the inverted pendulum. The poles of the observer were changed from multiple double root !70 to multiple double root !20 at 3 s. In the first case, the initial state of the new observer was not changed, while in the second case, the initial state of the new observer was reset according to the proposed method. It was found that the proposed method works very well. 4.2. Double-cart system The second plant is the double-cart system shown in Fig. 10, where y1 is the absolute position of the big cart
Fig. 11. On-line function for double-cart system.
(cart-1) and y2 is the relative position of the small one (cart-2) to cart-1. A linear controller of order 8 was designed so that the absolute position of cart-2 follows the reference signal r. The control inputs are the torques sent to the two carts. The on-line function for the doublecart system is shown in Fig. 11. The execution speeds of the real-time control programs written in MATX and C (see Fig. 12) were compared. Two-dimensional arrays are used for matrix calculation in C. An IBM-PC/AT computer with 60 MHz pentium was used for the experiment. The shortest sampling intervals for the two programs are shown in Table 1. It is clear that the MATX program is faster than the C program. There are several for-loops in the C program, and two-dimensional arrays which require some extra time for index calculation are used in those loops. On the other hand, the matrix calculation in MATX does not use two-dimensional arrays, but employs pointers to memory, with some optimization techniques. Also, the memory needed for matrix calculations is registered in
M. Koga et al. /Control Engineering Practice 6 (1998) 1287—1293 Table 1 The shortest sampling intervals C program
MATX program
1.6 (ms)
1.1 (ms)
1293
it is possible to modify the C program using the same techniques as those used in MATX, but this would take considerable time, and makes the program messy.
5. Summary In this paper, an integrated software environment for the design and real-time implementation of control systems is introduced. The software comprehensively supports the design procedure, including the analysis of the plant, the synthesis of the controller, simulations, and experiments. The paper deals with some problems related to the integration of a real-time implementation facility with CACSD software, and gives solutions to them. The software offers a facility to update the parameters of controllers without halting real-time control, which helps in the on-line tuning of the controllers. A method for the on-line tuning of state observers was proposed and verified through experiments.
References
Fig. 12. On-line function written in C.
advance, as mentioned in Section 3. That is why the MATX program is faster than the C program. Of course,
Integrated Systems, Inc. (1991). MATRIXx Core. 8 ed. 3260 Jay Street Santa Clara, CA 95054, USA. Koga, M. (1995). An interactive environment for simulation and realtime implementation of control systems. Proc. KACC’95, Seoul, Korea (pp. 336—339). Koga, M., Toriumi, H., Sampei, M. (1996). Real-time cad of control systems achieving cooperation of modeling and design of controllers. Proc. CACSD’96, Dearborn, Michigan, U.S.A. (pp. 457—462). Ogata, K. (1990). Modern control engineering. Englewood Cliffs, NJ: Prentice-Hall. The Math Works, Inc. (1992a). MATLAB User’s Guide. The Math Works, Inc. 24 Prime Park Way, Natick, Mass. 01760-1500, USA. The Math Works, Inc. (1992b). SIMULINK User’s Guide. (1st ed.). 24 Prime Park Way, Natick, MA. 01760-1500, USA.