The Implementation of PC-Based Real-Time Control Systems Using Quadratic Optimal Control

PC-Based 二次式最佳控制之即時控制系統 The Implementation of PC-Based Real-Time Control Systems Using Quadratic Optimal Control

柯德祥 張曉維 Dershyang Ker Hsiao-Wei Chang 中華技術學院電機工程系副教授及講師

摘要

本文以 VisSim 為系統發展環境,以數學方塊圖模式設計開發現代控制演 算法,以 PC 為主控制器配合資料擷取介面卡整合伺服控制系統,實現現代控制 演算法於 PC-Based 即時控制系統。首先以一簡單控制系統為例,推導二次式最 佳控制理論並符合性能指標之最小化,求得最佳控制器理論值;另外以 VisSim 為系統發展環境,無需理論推導,即可得到二次式最佳控制器模擬值,並與理 論值作比對,驗證其正確性。 然後將此法應用於實際 FB-33 伺服控制系統,建 立數學模式於 VisSim,即可輕鬆得到二次式最佳控制器。最後,再配合商用資 料擷取介面卡與動態連結函數庫整合 FB-33 控制系統,完成 PC-Based 即時控制 系統,實現二次式最佳控制演算法於伺服控制系統。 關鍵詞:PC-Based 即時控制系統、二次式最佳控制、資料擷取介面卡。

ABSTRACT The goal of this paper is to implement the quadratic optimal control algorithm in PC-Based real time control systems by using mathematic model blocks in VisSim software package environment. We use PC as a controller to apply quadratic optimal control algorithm in PC-Based real time control systems using plug-in PCI interface card. First, a design example based on the quadratic optimal control algorithm is given. The theoretical state feedback controller can be obtained. An alternative approach using VisSim’s OptimizePro to automatically calculate optimal state feedback controller has been verified to be a very powerful method to avoid tedious theoretical design. Second, the model of the real control system, FB-33 control system, can be up in VisSim. The quadratic optimal controller can be

- 439 - The Implementation of PC-Based Real-Time Control Systems Using Quadratic Optimal Control

easily obtained without the theoretical design. Finally, the PC controller uses the quadratic optimal controller and data acquisition system to control the FB-33 servo control system. The satisfied results are shown in this paper. Keywords:PC-Based Real Time Control System, Quadratic Optimal Control, Data Acquisition Interface Card.

1. Introduction Depending on the popularity and development of PC-Based controller, the demand of market is rapidly growing [1]. The IPC, I/O interface card, motion control card and the related peripheral hardware in Taiwan that have the competitive ability of the market [2]. We also find the data acquisition system of popularity use that is lack of the effective modern control method and mathematical calculation functions, so that it is only used as virtual instruments [3][4]. This makes modern & constant progress control algorithms to be unable to really apply in industrial control. The related fields of domestic and abroad, implementing modern control algorithms in PC-Based real time control systems, still have many problems to be needed to overcome. This paper uses VisSim as a system developing environment to design and develop advance modern control algorithms by mathematic model blocks. VisSim is a Windows-based program for the modeling, design and simulation of complex control systems without writing a line of code [5]. It combines an intuitive drag-and-drop block diagram interface with a powerful mathematical engine. The visual block diagram interface offers a simple method for constructing, modifying and maintaining complex control system models. Furthermore, VisSim offers unprecedented ease-of-use and consequently a shorter learning curve than competitive systems. In designing optimal control systems, we are often interested in selecting a control vector such that a given performance index is minimized [6][7]. It can be proved that a quadratic performance index will yield linear control law. Setting up a simulation in VisSim is simple. Connect the controller to the mathematical model and to a plot block. VisSim/Optimize can determine optimal values for design variables subject to the given performance indexes starting from initial guess values [8]. VisSim/Optimize can automatically calculate optimal control vector that give minimal performance indexes. It allows user-specified cost functions that can

- 440 - The Implementation of PC-Based Real-Time Control Systems Using Quadratic Optimal Control

consider controller behavior, such as steady-state error, overshoot and rise and settling times. Finally, We use the optimal control vector built up in PC to work with the FB-33 control system [9] when coupled with VisSim’s Real-Time through data acquisition interface card [10][11].

2. Quadratic Optimal Control

The control system is shown in Figure 1. We consider the optimal control problem based on quadratic performance indexes that, given the system equations

• x = Ax + Bu (1) In designing control systems, we are interested in determining the optimal feedback gain matrix K of the optimal control vector

u(t) = −Kx(t) (2) so as to minimize the performance index

∞ ∞ ∞ J = ∫ L(x,u)dt =∫ (xT Qx + u T Ru)dt = ∫ xT (Q + K T RK)xdt (3) 0 0 0 where Q is a positive-definite Hermitian or real symmetric matrix and is a positive-definite Hermitian or real symmetric matrix. From Figure 2, we find that the state equation for the plant is ⎡0 1⎤ ⎡0⎤ ⎡1 0⎤ A = ⎢ ⎥ B = ⎢ ⎥ Q = ⎢ ⎥ (4) ⎣0 0⎦ ⎣1⎦ ⎣0 µ⎦

Figure 1 Optimal control system

- 441 - The Implementation of PC-Based Real-Time Control Systems Using Quadratic Optimal Control

Let us assumed that d xT (Q + K T RK)x = − (xT Px) (5) dt where P is a positive-definite Hermitian or symmetric matrix. Therefore xT (Q + K T RK)x = −xT [(A − BK)T P + P(A − BK)]x (6) Comparing both sides of this last equation, we obtain (Q + K T RK) = −[(A − BK)T P + P(A − BK)] (7) Using the second method of Liapunov, if A-BK is a stable matrix, there exists P that satisfies Equation (7). Hence we can evaluate the performance index J as

∞ ∞ J = xT (Q + K T RK)xdt = −xT Px = −xT (∞)Px(∞) + xT (0)Px(0) (8) ∫0 0 It can be obtained that X (∞) tends to zero because all eigenvalues of A-BK have negative real parts. Then, the value of J can be given by J = xT (0+)Px(0+) (9) Since R has been assumed to be a positive-definite Hermitian or real symmetric matrix, we can write R = T T T . The Equation (7) will become (AT − K T BT )P + P(A − BK) = −(Q + K T T T TK) (10) which can be rewritten as AT P + PA + [TK − (T T ) −1 BT P]T [TK − (T T ) −1 BT P] − PBR −1BT P + Q = 0 (11) To minimize J with respect to K. This yields K = T −1 (T T ) −1 BT P = R −1BT P (12) Equation (12) gives the optimal matrix K. The P matrix in Equation (12) must satisfy the reduced matrix Ricatti equation as AT P + PA − PBR −1BT P + Q = 0 (13) Noting that the matrix A is real and matrix Q is real symmetric, matrix P is real symmetric matrix in Equation (4). Solving Equation (13) for the pij , we obtain

⎡ p11 p12 ⎤ ⎡ µ + 2 1 ⎤ P = ⎢ ⎥ = ⎢ ⎥ (14) ⎣ p21 p22 ⎦ ⎣⎢ 1 µ + 2⎦⎥ Substituting Equation (14) to Equation (12), the optimal feedback gain matrix K can be written as

- 442 - The Implementation of PC-Based Real-Time Control Systems Using Quadratic Optimal Control

−1 T ⎡ p11 p12 ⎤ K = R B P = [1][[]0 1 ⎢ ⎥ ⎣ p21 p22 ⎦

= [1 µ +1] (15)

Then, the optimal control signal is

u(t) = −Kx(t) = −x1 − µ + 2x2 (16) Therefore, the block diagram of this optimal control system is shown in Figure 3.

Figure 3 Optimal control of the plant shown in Figure 2

3. Verifying Quadratic Optimal Control with VisSim/Optimize To verify the quadratic optimal control law described above, it can be easily done using VisSim/OptimizePro. It is convenient to use VisSim/OptimizePro for optimization problems on VisSim simulations and models because VisSim/Optimize was designed and implemented to take advantage of the VisSim environment. We can use all of the features of VisSim to create the cost function. VisSim dialog box make it easy to set upper and lower bounds on design variables. The Optimization Properties dialog box is used to select an optimization run. The control system shown in Figure 2 has a feedback gain matrix with two parameters. Following the quadratic optimal control law, this feedback gain matrix K can be also optimized using VisSim/OptimizePro shown in Figure4. The state feedback controller has two variables k1 and k2 . The cost function shown in Figure 5 is computed by integrating the quadratic function L(x,u) in Equation (3). The plant is produced with two integrator blocks.

Once the initial conditions of the plant and initial values of k1 and k2 are set, a simulation run produces the results in Figure 4. The final value of the cost function is

- 443 - The Implementation of PC-Based Real-Time Control Systems Using Quadratic Optimal Control

1.73212. The final values of k1 and k2 are 0.999955 and 1.73203, respectively. It can be seen that the errors between the simulation results and the theoretical values in Equation (15) are less than 0.0001%.

x2 x1 Tuned Plant Controller 2.0 u 1/S 1/S Measured output

Plant 1.5

1.0

objectiveFunction cost .5 173.212 0 0 2 4 6 8 10 1 parameterUnknown k2 1.73203 Time (sec) 1 parameterUnknown k1 .999955 $runCount 70 Starting values Optimized state feedback controller gains

Feedback k2 * x2p x2

k1 - * u x1 x1p - Figure 4 The optimal state feedback controller tuning diagram with VisSim/Optimize

x2 pow + x1 pow + 1/S 100 Error u pow + Figure 5 The block diagram of the cost function in Equation (3)

4. Quadratic Optimal Control in Real Systems

Implementing Quadratic Optimal Control algorithm to the mathematical model of FB-33 system using VisSim/OptimizePro

The FB-33 Feedback control system, the apparatus of automatic control laboratory, is a typical second-order system [6]. The objective of this system is to control the position of the mechanical load in accordance with the reference position. The open-loop transfer function of the FB-33 control system obtained by the author [13] can be written as 8.546 G (s) = (17) p (1+ 0.3114s)s After the mathematical model is obtained. It is easy to build the mathematical mode

- 444 - The Implementation of PC-Based Real-Time Control Systems Using Quadratic Optimal Control

of the FB-33 control system by simply selecting and connecting predefined function blocks in VisSim. It is convenient to use VisSim/OptimizePro for optimization problems on VisSim simulations. The quadratic optimal control simulation can be set up in VisSim shown in Figure 6. After 26 simulations runs, the final value of the cost function is 1.04286. The final values of k1 and k2 are 0.999533 and 0.926224, respectively.

Tuned Plant Controller 2.0 Measured output

u Plant Measurement Measured output 1.5

8.546 1 1.0 2 .3114s +s .5 objectiveFunction cost 104.286 0 0 2 4 6 8 10 Time (sec) 1 parameterUnknown k2 .926224 1 parameterUnknown k1 .999533 $runCount 26

Starting values Optimized state feedback controller gains

Feedback

k2 * x2p x2 - k1 u * x1p - x1 Figure 6 The quadratic optimal controller tuning diagram of the FB-33 control system

Real-Time Hardware-in-the -loop Once the quadratic optimal control design is complete, we can test controller performance with the FB-33 control system. VisSim/Real-Time is a VisSim option that provides the capability to couple a VisSim system model directly with a real-world hardware. Hardware-in-the-loop (HIL) systems can be configured and executed by interfacing VisSim controller mode with the FB-33 control system. With VisSim/Real-Time, the PC can be used as on-line servo controller for the FB-33 control system through a high-speed data acquisition card (NI-DAQ-6024E). The NI-DAQ-6024E interface card plugged in the PC offers a 200 kHz sampling rate for A/D and D/A channels larger than the bandwidth of the FB-33 servomotor. Figure 7 shows a PC-based real-time control diagram and the actual step response of the FB-33 control system with quadratic optimal controller.

- 445 - The Implementation of PC-Based Real-Time Control Systems Using Quadratic Optimal Control

Analog ch 1 NIDaq dev1

in + NIDaq dev1Analog ch 1 x1 out out 0.999533 - 1 - NIDaq dev1Analog ch 2 x2 x2 0.926224

Plot out 3.0

2.5

2.0

1.5 in 1.0

.5

0

-.5

-1.0 0 1 2 3 4 5 6 7 8 9 10 Time (sec) Figure 7. PC-based real-time control diagram and the actual step response

5. Concluding Remarks

1. This paper has presented an approach using VisSim to estimate the quadratic optimal controller is a very powerful method to avoid tedious theoretical design. 2. The PC-based real-time control system using the quadratic optimal control algorithm and data acquisition system to control the real world has been developed in this paper. 3. VisSim is a Windows-based software package for the modeling, design and simulation of complex control systems without writing a line of code. It offers unprecedented ease-of-use and consequently a short learning curve. 4. Directions for future work include studying time-optimal controller, dead-beat controller, fuzzy controller, and adaptive control algorithm, and designing various interfacing capabilities for the design of control systems in VisSim.

Acknowledgment The work reported in this paper was supported by Cho Chieh Tech. Enterprise Ltd. and National Science Council under grant NSC-91-2622-E-157-005-CC3.

- 446 - The Implementation of PC-Based Real-Time Control Systems Using Quadratic Optimal Control

References

[1] 蘇興川、楊文瑩, PC-Based 控制器先期投資可行性分析,工研院機械所. [2] eAutomation Solution Guide, Advantech Automation Corporation, 2002. [3] LabVIEW User Manual, Corporation, July 2000. [4] D.J. Parish and P. R. Hardcastle, “Rapid Prototyping Using the LabVIEW Environment,” IEEE AUTOTESTCON, 1996, pp.235-238. [5] VisSim User's Guide, Visual Solutions, Inc., Westford. Massachusetts, 1995. [6] K. Ogata, Modern Control Engineering, Prentice Hall, Inc., 2002, Fourth Edition. [7] A. E. Bryson and Y. . Ho, Applied Optimal Control, Hemisphere Publishing Corporation, New York, 1975. [8] VisSim/OptimizePRO User's Guide - Version 4.5,Visual Solutions Inc., 2000. [9] Analogue Servo Fundamentals Trainer 33-002, Feedback Instruments Ltd. [10] VisSim/Real-TimePRO User's Guide - Version 4.5,Visual Solutions Inc., 2000. [11] NI-DAQ-6024E User Manual, National Instruments Corporation, January 1999. [12] B. C. Kuo and F. Golnaraghi, Automatic Control Systems, John Wiley & Sons, Inc., 2002, 8th Edition. [13] D. Ker, “The Implementation of PC-Based Real-Time Control Systems Using Gain-Optimization Algorithm” Accepted by Journal of China Institute of Technology, March. 2003.

- 447 -