Real-Time Embedded Controller.. (Idris E. Putro and Harry Septanto) REAL-TIME SIMULATION OF EMBEDDED CONTROLLER FOR MISSILE (SIMULASI WAKTU-NYATA PENGENDALI TERTANAM UNTUK MISIL) Idris E. Putro1, Harry Septanto2 1 Pusat Teknologi Roket - LAPAN 2Pusat Teknologi Satelit - LAPAN 1e-mail: idris.ep@lapan.go.id Diterima : 15 Juli 2019; Direvisi : 07 September 2019; Disetujui : 16 September 2019 ABSTRACT This paper focuses on the development of real-time environment for embedded system to control flight performance of missile. Real-time simulation is generated by using xPC target so that standalone target boot can be developed, and target PCs can be simulated in real-time. Two PCs and single board computers (SBCs) are required to configure the host and standalone target respectively. The host PCs are used to control the target PCs while these target PCs run simultaneously in real-time. Target PCs are divided into plant platform and controller platform. Plant platform represents missile dynamics model, while control algorithm is compiled to the other system as controller platform. Linear control synthesis will be implemented for maintaining flight stability of missile using optimal control approach based linear quadratic regulator (LQR). Simulation results show the deviation time between real-time system and non real-time under Matlab/Simulink only 0.001 second. This real-time system should resemble the environment of future flight test. Keywords: real-time simulation, xPC Target, single board computer (SBC), standalone target, LQR ABSTRAK Paper ini fokus pada pengembangan lingkungan real-time untuk sistem embedded berbiaya murah yang digunakan untuk mengendalikan prestasi terbang dari missile. Simulasi real-time dihasilkan dari metode xPC target sehingga penyalaan standalone target dapat dikembangkan, dan PC sasaran dapat disimulasikan secara real-time. Dua PC dan dua SBC masing-masing diperlukan untuk membuat host dan target mandiri. Host PC digunakan untuk mengendalikan PC sasaran dimana PC sasaran ini bekerja serentak secara real-time. PC sasaran dapat dibagi menjadi Platform model wahana dan platform kendalian. Platform model wahana mewakili model dinamika terbang missile, dan platform yang lainnya merupakan hasil proses kompilasi dari algoritma kendali (kendalian). Implementasi dari sintesa kendali linear akan digunakan untuk menjaga kestabilan terbang missile dengan menggunakan pendekatan kendali optimal berbasis linear quadratic regulator (LQR). Hasil simulasi menunjukkan bahwa perbedaan waktu antara sistem real-time dengan non real-time oleh perangkat lunak Matlab/Simulink hanya sebesar 0.001 detik. Sistem real-time ini diharapkan dapat mencerminkan lingkungan nyata dari uji terbang di masa depan. Kata kunci: simulasi real-time, xPC target, single board computer (SBC), standalone target, LQR 129 Jurnal Teknologi Dirgantara Vol.17 No.2 Desember 2019 : hal 129-140 1 INTRODUCTION Development of unmanned aerial vehicles have rapidly increased recently. Wide range applications from civil and safety purposes until military and defense missions lead this vehicle needs advanced control system. One of the most considered vehicles to support defense and military tasks is missile. The design and implementation of autonomous control system for missile is rather challenging due to higher risk in flight testing and increasing complexity in flight dynamics for high speed mode. Hence design and development of an accurate control in real-time simulation for missile become important to do before implementing it in real flight test. Designing and testing of control system needs to be verified prior to the flight test. Direct flight test without ground simulation will risk either the vehicles or environment due to an expensive onboard system, a lot of time wasted and more efforts to understand the missile behavior. Flight and control simulation are suitable to design and test the control system associated with missile dynamics. Using simulation, every flight condition can be considered, and then appropriate control algorithm designed, analyzed, and adjusted so that the precision controller can be developed more accurate. After the controller is ensured preconcerted accurate, then it can be implemented as an embedded system for the flight test. The embedded control system must be applied in real situation as similar as the flight test. The responses of the embedded controller should be able to suffice deterministic time and meet the real-time environment. There have been a lot of method to develop real-time simulation for testing flight controller. The fanciest in the last decade is using xPC target to construct real-time hardware-in-the-loop simulation (HILS). 130 For instance, Valavanis et al reveal in his book that Ates utilized xPC target to simulate various air vehicle type in realtime such as jet Fighters F-16 and F-4. (Valvalanis, 2008). Peng Lu (Lu, 2011) has constructed hardware-in-the-loop (HIL) to demonstrate real-time simulation UAV system based on xPC target under Matlab/Simuling. He has successfully validated that the responses of real-time simulation accurate enough compared to real flight. Extensive work has also been performed for autonomous flight of rotary wing UAV (Budiyono et al, 2010). Realtime HIL through xPC target is used to simulate various flight condition such as hover, cruise, climb, descent, and turning maneuver flights. Further improvement uses combined programming between xPC target and LabVIEW/SIT environment to build real-time simulation system of the orbital transfer vehicle (OTV) model (Ma et al, 2014). Optimal control has been widely used in aerospace application. Devan extend the use of lqr control to design roll autopilot of missile by cascading the algorithm (Devan, 2018). Further extensive research work has been conducted (Zheng, 2018) by using lqr to perform tracking guidance law simulation for target missile. This paper presents real-time simulation based on xPC target for embedded controller to simulate flight stability of missile. The missile model either nonlinear or linear will be run simultaneously and the controller gathers flight data and stabilize the dynamic of missile. All the real-time simulation based on xPC target are carried out under Matlab/Simulink software by using Real Time Workshop (RTW). Optimal control based linear quadratic regulator is proposed for controller target PC to keep stability of missile flight in a presence of disturbances. Real-Time Embedded Controller.. (Idris E. Putro and Harry Septanto) 2 METHODOLOGY Real-time simulation developed in this research uses methodology as the following flow chart. Picture 2-2: Missile configuration design Missile dynamic constructed from eulernewton formulation. ๐‘‘๐‘‰ =๐น ๐‘‘๐‘ก % (2-1) ๐‘‘๐œ” =๐‘€ ๐‘‘๐‘ก % (2-2) ๐‘š ๐ผ Picture 2-1: Flow chart of real-time simulation uses xPC target method Real-time system is built for target PC which will be used as embedded flight controller. Embedded flight controller must run in real-time environment thus there is no significant delayed time between inputs and responses in order to control the flight stability of missile. A real-time Operation System (OS) in this research is created based on xPC Target Kernel, since xPC gives the ability to convert a designed model in Matlab/Simulink to a real-time OS (Mohammed, 2013) Details explanation regarding host PC and target PC associated with missile dynamic, control method, and xPC target will be revealed in the next sub-chapter respectively. 2.1 Missile Dynamic Model Missile model in this research uses configuration of double stages rocket developed by LAPAN. Equation above derived from the law of conservation of linear and angular momentum, with ๐น = ๐‘‹, ๐‘Œ, ๐‘ / , and ๐‘€ = ๐ฟ, ๐‘€, ๐‘ / , are the vector of total forces and moments acting on the missile center of gravity. Total forces and moments are generated by control surfaces, i.e. elevator, aileron, rudder, and throttle. Gravitational force in three axes are also considered. Further derivation of forces and moments can be seen in (Putro et al, 2012) yields missile dynamic presented as 6 degree of freedom. Missile dynamic in translational motions of 3 axis ๐‘ฅ, ๐‘ฆ, and ๐‘ง are respectively represented as equation below. ๐‘š๐‘ข = ๐น6 โˆ’ ๐‘ž๐‘ค + ๐‘Ÿ๐‘ฃ โˆ’ ๐‘” sin ๐œƒ ๐‘š๐‘ฃ = ๐นB โˆ’ ๐‘Ÿ๐‘ข + ๐‘๐‘ค + ๐‘” cos ๐œƒ sin ๐œ™ ๐‘š๐‘ค = ๐นG โˆ’ ๐‘๐‘ฃ + ๐‘ž๐‘ข + ๐‘” cos ๐œƒ cos ๐œ™ (2-3) (2-4) (2-5) Rotational motions of missile dynamics in ๐‘ฅ, ๐‘ฆ, and ๐‘ง axis can be formulated as below. ๐ผ6 ๐‘ = ๐ฟ โˆ’ ๐‘ž๐‘Ÿ ๐ผG โˆ’ ๐ผB + ๐ผ6G ๐‘๐‘ž + ๐ผ6G ๐‘Ÿ (2-6) 131 Jurnal Teknologi Dirgantara Vol.17 No.2 Desember 2019 : hal 129-140 ๐ผB ๐‘ž = ๐‘€ โˆ’ ๐‘ž๐‘Ÿ ๐ผ6 โˆ’ ๐ผG + ๐ผ6G ๐‘ H โˆ’ ๐‘Ÿ H ๐ผB (2-7) ๐ผG ๐‘Ÿ = ๐‘ โˆ’ ๐‘ž๐‘Ÿ๐ผ6G โˆ’ ๐ผB โˆ’ ๐ผ6 ๐‘๐‘ž + ๐ผ6G ๐‘Ÿ (2-8) Completing equation (2-3) to (2-8) to govern 6 degree of freedom, kinematic equations can be arranged as the following equations for each ๐‘ฅ, ๐‘ฆ, and ๐‘ง axis. ๐œ™ = ๐‘ + ๐‘ž sin ๐œ™ tan ๐œƒ + ๐‘Ÿ cos ๐œ™ (2-9) ๐œƒ = ๐‘ž cos ๐œ™ โˆ’ ๐‘Ÿ sin ๐œ™ (2-10) ๐œ“ = ๐‘ž sin ๐œ™ + ๐‘Ÿ cos ๐œ™ sec ๐œƒ (2-11) 2.2 Optimal Control Design Optimal Control is used to improve the attitude stabilization. Optimal control approach in this research uses linear quadratic regulator (LQR). LQR controller has been known as ubiquitous controller which provides effectively fast response with minimum settling time (Devan, 2018). This paper proposes lqr approach to keep the angular angle of missile always in stable performance even small disturbances occur. This can be done by setting the angular rate errors tend to zero when disturbance applied thus the angle still can be kept after steady state. The LQR method try to find the control inputs that can minimize the chosen output by minimized ๐‘„ and ๐‘… weighting matrices (Kumar, 2016). This approach must find state-feedback law ๐‘ข = โˆ’๐‘˜๐‘ฅ as it may minimizes the quadratic cost function as the following equation in time domain. R ๐ฝ ๐‘ข = S ๐‘ฅ / ๐‘„๐‘ฅ + ๐‘ข / ๐‘…๐‘ข + 2๐‘ฅ / ๐‘๐‘ข ๐‘‘๐‘ก (2-12) The optimal gain matrix then can be found by solving the matrix differential of Riccati equation. Eventually the optimal control gain matrix can be obtained from the following equation. (2๐พY โ‰œ โˆ’๐‘… WX ๐ต / ๐พ 14) 2.3 Host PC The host PCs are developed using Matlab/Simulink software under Windows operating system. Under Matlab/Simulink, the host PC will run missile dynamic model and controller model and generate compiler files for target PCs to be controlled during simulation. This host PCs will be connected to target PCs through 100 Mbps TCP/IP connection for downloading executable files into target computer using xPC target in Matlab. This high-speed connection allows xPC target explorer in the host computer become console for monitoring and controlling the target computer during the process of the real time simulation. The host PCs also will be used to display and analyze all of the flight simulation data, covering missile dynamic model and controller model. Asus Strix ROG series notebook is used as a host computer to run the missile model, meanwhile desktop computer is used to run controller model. Communication between host PCs and target PCs are connected using UDP port. This high-speed connection will establish xPC target spy in host PC while the simulation is running. xPC target spy is target screen spy in host PC while the target PC was running. This command is commonly used to display the target PC simulation in host PC thus we can monitor the simulation of target PC on the host PC and directly controlled it from host PC. 2.4 ๐พ = ๐พ๐ด + ๐พ๐ต๐‘… 132 WX / / ๐ต ๐พโˆ’๐‘„โˆ’๐ด ๐พ (2-13) Target PC The target PCs are the computer which are running the executable files Real-Time Embedded Controller.. (Idris E. Putro and Harry Septanto) representing missile dynamic model and controller model and will be run simultaneously as a real-time kernel application on free-DOS operating system. Target PCs can be controlled through host PCs under DOS loader target boot mode and also can be run automatically under standalone target boot mode. In this research, both of those configurations have been done. The DOS loader mode is used to tune the missile model and controller parameters, and then those optimized models are used to generate compiler files for running under standalone mode. The last configuration of controller model on target computer resemble the embedded controller system that can be used for real flight test. The target PCs were using a 3.5โ€ single board computer (SBC) powered by Intel Celeron 600MHz and 512MB DDR memory (SBC: WAFER-8522). The main specifications of target PC can be seen as the following table. Tabel 2-2: SBC WAFER-8522 SPECIFICATION CPU Memory I/O Dimension Weight On-board Intelยฎ CeleronยฎM 600MHz 512K cache DDR226 512 MHz 5x RS-232 Dual Realtek RTL8110SC Ethernet 4x USB 1x IDE 1x PS/2 for KB/MS 1x TPM v.1.2 module onboard 146 mm x 102 mm GW: 700 g and NW: 175 g The SBC performance allows the process running in high-frequency as in desktop PC under a small compact and mobile package that possible to be used as flight control computer (FCC) in the future. The integrated VGA on SBC is used to display the running behavior of each model in an LCD monitor. This feature serves observation, therefore simulation process in standalone mode can be analyzed. Furthermore the host computers can be eliminated for controller model to simplify the system after all of configuration has been fixed previously by using DOS loader mode. Picture 2-3: Single board computer WAFER8522 SBC missile dynamic model is connected to SBC controller model by two channels of RS-232 at 115,200 bps, 8 data bits and 1 stop bits. Output data from missile dynamic model is sent through RS-232 com-1 port and will be received as input data by SBC controller model at com-1 port. Reversely, command data from SBC controller model is sent through RS-232 com-2 port and received as input data at com-2 port by SBC missile model. Since the SBC has six RS-232 ports, using these two channels separately can give advantages to avoid serial communication problems such as CPU overload that might be occurred when using only one serial port alternately. 3 RESULTS AND DISCUSSION Real time simulation is established for both missile dynamic model and controller model of the target PCs. These model are obtained from xPC target compiling process. 133 Jurnal Teknologi Dirgantara Vol.17 No.2 Desember 2019 : hal 129-140 Plant target pc which is represented missile dynamic model generated from equation (2-3) - (2-11) in matlab/simulink software. By inserting missile configuration data in table 2-1 into equations, thus missile dynamic can be formulated and simulated in Matlab/Simulink Plant target pc is connected to the controller target pc through serial cable connection on RS232 port. The simulink block diagram of those target PCs are shown in Figure 3-1. Plant target and Controller target PCs above are compiled using C compiler on Real Time Workshop under Matlab/Simulink Environment and generate executable files to be run on single board computer. These executable files running on SBC-target computer are called target PCs. Simulation is conducted by running missile dynamic model equipped with optimal control as defined in chapter 2.2. Optimal gain controller is obtained for Lapan double stage rocket in equation (2-14) ๐พY as the following below: 2.28 โˆ’10.32 10.24 โˆ’2.95 0.77 โˆ’0.12 โˆ’1.54 โˆ’7.98 Missile configuration (Mugia, 2012) can be seen from table 2-1. ๐พY = Tabel2-1: MISSILE CONFIGURATION. Parameters Values and Units Diameter(d) 200 mm Total length(l) 2353 mm Total mass (m) 65.26 kg CoG position(cg) 1050 mm Thrust(T) - Booster - Sustainer 500 kgf 80 kgf Wing area (S) 0.0488 m2 Wing chord (c) 0.325 m Inertial Moments (I) - ๐ผ66 - ๐ผBB - ๐ผGG Picture3-1: Simulink blocks of missile dynamic and controller models 134 0.012 kgm2 84.43 kgm2 84.43 kgm2 Real-Time Embedded Controller.. (Idris E. Putro and Harry Septanto) Roll Angle response 0.35 0.35 Simulink Realtime 0.3 0.3 0.25 0.25 0.2 0.15 Roll f (rad) Roll f (rad) 0.2 0.1 0.15 0.1 0.05 0.05 0 0 -0.05 -0.05 -0.1 0 2 4 time (sec) 6 8 0 2 4 time (sec) 6 8 Picture3-2: Comparison of simulink and target pc simulation: Roll angle response Roll rate response 1 Simulink Real time 0.8 0.8 0.6 0.6 Roll rate (rad/s) Roll rate(rad/s) 0.4 0.4 0.2 0 0 -0.2 -0.2 -0.4 0.2 0 2 4 time (sec) 6 8 -0.4 0 2 4 time (sec) 6 8 Picture3-3: Comparison of simulink and target pc simulation: Roll rate response 135 Jurnal Teknologi Dirgantara Vol.17 No.2 Desember 2019 : hal 129-140 Simulation result under real time environment can be seen from figure 3-2 until 3-7. Figure 3-2 and 3-3 show the attitude responses on lateral mode. There is a very small different response time between simulink result and realtime result. The difference value only within 0.001 sec since the plant model was very simple. From real-time simulation also can be seen that the controller is able to work properly. The controller can Pitch Angle response 0 0 -0.2 -0.2 -0.4 -0.4 -0.6 -0.6 Pitch q (rad) Pitch q (rad) maintain the roll rate close to zero ๐‘ โ‰ˆ 0 ๐‘Ÿ๐‘Ž๐‘‘/๐‘  and keep the roll angle to ฯ† = โˆ’0.074 ๐‘Ÿ๐‘Ž๐‘‘ for cruise flight. Figure 3-4 to 3-7 show the same behavior with lateral mode. The controller in real time situation can keep pitch and yaw angle near the operating points of cruise flight, ฮธ = โˆ’0.0767 ๐‘Ÿ๐‘Ž๐‘‘ and ฯˆ = 0.3077 ๐‘Ÿ๐‘Ž๐‘‘ Meanwhile the model also can maintain the rate attitude tend to zero, q = 0 rad/s and r = 0 rad/s. -0.8 -0.8 -1 -1 -1.2 -1.2 Real time Simulink -1.4 0 2 4 time (sec) 6 8 -1.4 0 2 4 time (sec) 6 Picture 3-4: Comparison of simulink and target pc simulation: Pitch angle response 136 8 Real-Time Embedded Controller.. (Idris E. Putro and Harry Septanto) Pitch rate response Real time 0.9 0.9 0.8 0.8 0.7 0.7 0.6 0.6 Pitch rate (rad/s) Pitch rate(rad/s) Simulink 0.5 0.4 0.5 0.4 0.3 0.3 0.2 0.2 0.1 0.1 0 0 -0.1 0 2 4 time (sec) 6 -0.1 8 0 2 4 time (sec) 6 8 Picture 3-5: Comparison of simulink and target pc simulation: Pitch rate response Yaw Angle response 0.4 0.4 Real time 0.35 0.35 0.3 0.3 0.25 0.25 Yaw y (rad) Yaw y (rad) Simulink 0.2 0.2 0.15 0.15 0.1 0.1 0.05 0 2 4 time (sec) 6 8 0.05 0 2 4 time (sec) 6 8 Picture 3-6: Comparison of simulink and target pc simulation: Yaw angle response 137 Jurnal Teknologi Dirgantara Vol.17 No.2 Desember 2019 : hal 129-140 Yaw rate response 0.2 0.2 Real time 0.15 0.15 0.1 0.1 Yaw rate (rad/s) Yaw rate(rad/s) Simulink 0.05 0 -0.05 0.05 0 0 2 4 time (sec) 6 8 -0.05 0 2 4 time (sec) 6 8 Picture 3-7: Comparison of simulink and target pc simulation: Yaw rate response 4 CONCLUSION Real-time Simulation of embedded control has been conducted. Missile dynamic model and controller model can simulate simultaneously in real-time based on xPC target. It was demonstrated that Plant target PC and Controller target PC were successfully run under standalone mode and maintain its operating points for stabilization flight. The small deviation time 0.001 second between real-time and non real-time simulation is reasonable since the controller has only handled the data from missile dynamic model in attitude performances. Further development can be considered by implementing this optimal control based linear quadratic regulator (LQR) for way-points tracking and navigation control in a real-time hardware prior to flight test. 138 ACKNOWLEDGMENT This paper and the research behind it would not have been possible without the exceptional support of my Professor, Kwang Joon Yoon, for the chance working together as his research assistant during master degree program. I am also grateful for the anonymous peer reviewers at Journal Teknologi Dirgantara since their insightful comments lead this manuscript greatly improved. Eventually I immensely grateful to Pustekroketโ€“ LAPAN for providing me a huge facility to support this research. REFERENCES Valavanis, K.P., et al.(eds), 2008. Unmanned Aircraft System. Springer Publisher, DOI: 10.1007/978-1-40209137-7_1. Budiyono, A., Idris E. Putro, et al., 2010. Real-time Hardware Simulation of a Real-Time Embedded Controller.. (Idris E. Putro and Harry Septanto) Small-Scale Helicopter Dynamics, International Journal of Aircraft Engineering and Aerospace Technology Vol. 82, Issue 6, pp. 360371. Peng Lu, QingboGeng, 2011. Real-time Simulation System for UAV based on Matlab/Simulink, IEEE 2nd International Conference on Computing, Control and Industrial Engineering (CCIENG),20-21 Aug 2011, ISBN 978-1-4244-9600-6. Endang Mugia GS., 2012. Pengaruh Nilai Koefisien Aerodinamika ๐ถq r dan ๐ถq s pada Kestabilan Terbang Gerak Periode Pendek (Short Period) RKX-200 LAPAN, Jurnal Teknologi Dirgantara Vol. 10, Issue 2, December, pp. 133138. Idris E. Putro, Herma Y. Irwanto, Ahmad Riyadl, 2012. Control Simulation of Fixed Wing UAV based on First Principle Approach, 6th International UAV World Conference (AIRTEC), 6 โ€“ 8 November 2012. Ma, Yehan., Ling, M., et al., 2014. Design and Implementation of Real-time Simulation System of OTV based on xPC Target and SIT, IEEE 11th World Congress on Intelligent Control and Automation (WCICA), 29 June โ€“ 4 July 2014, ISBN 978-1-4799-5825-2. E. Vinodh Kumar, J. Jerome, 2016. Algebraic Riccati equation based Q and R matrices selection algorithm for optimal LQR applied to tracking control of 3rd order magnetic levitation system, Archive of Electrical Engineering Vo.65, Issue 1, pp. 151-168. Devan, Viswanath., Chandar TS., 2018. Cascaded LQR Control for Missile Roll Autopilot, International Conference on Control, Communication, and Computing (IC4), 5-7 July 2018, Trivandrum, India Mohammed, Abdullah. A., Ali. Dia M., 2013. Creating Real-Time Operation System Based on xPC Target Kernel, International Journal of Recent Technology and Engineering (IJRTE), Volume-2, Issue-4, September 2013, ISSN: 2277-3878. Zheng, X., et al., 2018. Design and Simulation of Trajectory Tracking Guidance Law Based on LQR for Target Missile, IOP Conference Series: Materials Science and Engineering 435 (2018) 012021 DOI: 10.1088/1757-899X/435/1/012021 139 Jurnal Teknologi Dirgantara Vol.17 No.2 Desember 2019 : hal 129-140 140