Journal of Fuzzy Systems and Control. Vol. No 2, 2025 ISSN: 2986-6537. DOI: 10. 59247/jfsc. A Study of Optimized-LQR Control for Rotary Inverted Pendulum by Particle Swarm Optimization Thanh-Tri-Dai Le 1. Thanh-Cong Pham 2,*. Duc-Thanh-Long Bui 3. Quang-Truong Nguyen 4. Van-Nhat-Truong Vo 5. Quoc-Lap Dinh 6. Le-Hieu Tran 7. Thien-Bao Truong 8. Tan-Loc Nguyen 9. Duy-Tan Nguyen 10. Tuan-Anh Nguyen 11. Viet-Anh Nguyen 12. Thi-Thanh-Hoang Le 13 Faculty of International Training. Ho Chi Minh City University of Technology and Education (HCMUTE). Ho Chi Minh City (HCMC). Vietnam 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 Faculty of Electrical and Electronics Engineering (F. Ho Chi Minh City University of Technology and Education (HCMUTE). Ho Chi Minh City (HCMC). Vietnam 8, 9 Faculty of Mechanical Engineering. Ho Chi Minh City University of Technology and Education (HCMUTE). Ho Chi Minh City (HCMC). Vietnam Email: 1 19151051@student. vn, 2 17151175@student. vn, 3 20161222@student. 20161286@student. vn, 5 20161029@student. vn, 6 20161025@stuednt. 20161193@student. vn, 8 21146428@student. vn, 9 21146125@student. 20161257@student. vn, 11 21143326@student. vn, 12 20161156@student. hoangltt@hcmute. *Corresponding Author AbstractAiRotary Inverted Pendulum (RIP) is a classical but effective model in testing control algorithms. Besides designing controllers, it can also be a model for testing the evolution algorithms (EA. in optimizing control parameters. In this paper, we apply particle swarm optimization (PSO), which is an EA, to optimize the parameters of the LQR controller for this In the study, an experimental model in which system parameters are already measured and identified in former studies is used. The LQR control method is inherited from former results, and the weighing matrices (Q and R) are optimized by the PSO method. In each case, the control matrix K is obtained from Q and R to apply for RIP. Through both simulation and experiment. LQR control parameters are found better through generations by using PSO. The responses of RIP, in which controllers are designed under optimized Q and R in later generations, are better in quality, and values of the fitness function also supports that opinion. Thence, through this study, beside genetic algorithm (GA), this study proves that PSO is a suitable searching algorithm that can be applied for balancing this single input- multi output (SIMO) system. Also, the experimental platform of RIP in this research confirms its ability to control tests. KeywordsAiPSO. Genetic Pendulum. SIMO System Algorithm. Rotary Inverted INTRODUCTION SIMO system . is a class of systems controlled by one control signal when controlling more than one variable. Those models are usually balanced robots. Among them. RIP . is a popular SIMO model in control engineering. It has a simple structure but a highly nonlinear feature. Thence, it becomes a classical model in training and research activities in a control laboratory. Due to its popularity, it has become a standard model that is industrially produced by Quanser for laboratories . Some other similar kinds of inverted pendulum (IP) developed from RIP are: cart and pole . , double-linked RIP, which is created by adding one more parallel link . or serial link . Thence, any study from standard RIP can be developed for those similar models. Based on this model. PID . , pole-placement . , sliding control . methods are tested well. The control methods are examined in many papers, with control parameters chosen through trial-and-error. To automatically search these parameters, evolution algorithms (EA. are developed . GA is the most popular algorithm in EAs. It was proved to optimize well controllers for the heating oven . DC motor . In . GA is proved to be effective for finding PID control parameters for an antenna system. It is also applied well in parameter searching for nonlinear algorithms, such as back-stepping . However, proving the ability to optimize control parameters for a linear controller is still necessary. PSO is also regarded to be more effective than GA in However. Experimental results are still necessary. In . , we created an experimental RIP in which backstepping control is tested well in both simulation and Thence, it becomes our main model for In this paper, we apply LQR control again for this model and use PSO to examine the effectiveness of PSO on optimizing LQR control. II. MATHEMATICAL MODEL From . , mathematical model of RIP is described in Fig. Also, the features of the experimental model are shown in Table 1, . , . Fig. Mathematical model of RIP This work is licensed under a Creative Commons Attribution 4. 0 License. For more information, see https://creativecommons. org/licenses/by/4. Journal of Fuzzy Systems and Control. Vol. No 2, 2025 Table 1. System parameters Symbols yu yu ycoycy yaycy yaycy ycoyc yayc yayc ycAyceycu ycIyco yayco yayca yayc yayco yayco ycNyce Description Angle of pendulum. Angle of arm . Mass of pendulum . Length of pendulum . Inertia moment of pendulum . Mass of arm . Length of arm . Inertia moment of arm . Gravitational acceleration . /sec. Mass of encoder measuring . Voltage on DC motor (V) Resistor of motor . Inductance of motor (H) Counter electromotive constant (V/rad/se. Moment constant (Nm/A) Moment of inertia of DC motor rotor . coyciyco2 ) Viscous coefficient of friction (Nm/rad/se. Frictional torque (N. Fig. Structure of LQR for RIP Linear model of . at the equilibrium point is The values of system parameters are yayc = 0. ycAyceycu = 0. ycAycy = 0. ycAyc = 0. yaycy = 0. yayc = 0. yayco = 0. %6. 74 O . Oe5 ). yayca = 0. ycIyco = 11. yayco = 5. 98 O . Oe5 ). yci = 9. cu, yc. = yce = . ce1 yce2 ycu = . cu1 ycu2 ycu3 yce3 yce4 ]ycN . ycu4 ]ycN yayc ya ya2 = yayco yc yayca . ya3 = yayco ycIyco ycIyco 6 K3 gsinx1 -6K2 yaycyuN ycaosx1 6K1 yayc ecosx1 3( 6Lyc ycAyceycu gsinx1 6Lyc ycAycy gsinx1 2Lyc ycAyc gsinx1 ) yce1 = ycu2 . yce3 = ycu4 . ya1 = yce2 = -3Lycy ya2yc ycAycy ycu22 ycaycuyc ycu1 ycycnycu ycu1 yaycy ( 12K3 12L2 yc ycAen 12Lyc ycAycy 4L2 yc ycAyc -9Lyc ycAycy cos ycu1 yuiyce1 yuiyce1 yuiyce1 yuiycu2 yuiyce2 yuiycu3 yuiyce2 yuiycu4 yuiyce2 | where ya = yuiyce1 yuiycu yuiycu2 yuiyce3 yuiycu3 yuiyce3 yuiycu4 yuiyce3 yuiycu1 yuiyce4 yuiycu2 yuiyce4 yuiycu3 yuiyce4 yuiycu4 | yuiyce4 yuiycu2 yuiycu3 . uiycu1 yuiycu4 ] ycu=0 yc=0 yuiyce1 yuiyc yuiyce2 | yuiyc yaA = yuiyce yuiyc | yuiyce4 [ yuiyc ] ycu=0 yc=0 ya=[ Oe0. yaA = . Oe0. Thence, matrix K in . is calculated by solving the Riccati However, we can use the command ycoycyc() in MATLAB to easily obtain this matrix as ya = ycoycyc. a, yaA, ycE, ycI) . Q and R are weighing matrices that should be chosen. PSO Position change model of the PSO algorithm in space is shown in Fig. 4yaycy yayc ycAycy sinx1 ycu22 4K2 yuN - 4K1 e - 3Lyc ycAycy gcosx1 sinx1 yce4 = 12ya3 12ya2yc ycAyceycu 12ya2yc ycAycy 4ya2yc ycAyc Oe 9ya2yc ycAycy ycaycuyc 2 ycu1 i. yuiyce1 yuiycu1 yuiyce2 With system parameters in . , matrices A. B are The dynamic equations of RIP are: ycuN = yce. cu, yc. ycuN = yaycu yaAyc ALGORITHM LQR control Voltage on DC motor Ae control signal- under the LQR method is calculated as yce = yc = Oeyaycu where ya is the control matrix. The structure of control is shown in Fig. Fig. The principle of changing the position of an individual in a 2dimensional space Fundamentals of PSO technique are stated and defined as Individual ycU. : Is a candidate solution represented by a ycodimensional real-valued vector, where yco is the number of Thanh-Tri-Dai Le. A Study of Optimized-LQR Control for Rotary Inverted Pendulum by Particle Swarm Optimization Journal of Fuzzy Systems and Control. Vol. No 2, 2025 optimized parameters. At iteration ycn, the position of the ycycEa individual ycU. cn, y. can be described as follows: ycUyc . = . cuyc,1 . ycuyc,2 . ycuyc,yco . ycuyc,ycc . ] . where ycuyco. cn, y. is kth optimal parameter in jth candidate d represents the control variables. Population: is set of n individuals at ith iteration ycyycuycy. = . cUycn . , ycU2 . , . , ycUycu . ]ycN . where n stands for the number of candidate solutions. A swarm is an unorganized population of mobile individuals that tend to gather together while each individual tends to move in a random direction. Individual velocity ycO. : is the velocity of the moving individual, represented by a d-dimensional real-valued At iteration ith, the velocity of the jth individual is ycOyc. , which can be described as follows: ycOyc . = . cyc,1 . ycyc,2 . ycyc,yco . ycyc,ycc . ] . With ycyc, . being the velocity component of the jth individual in the kth dimensional space. Best Individual ycU O . : During the movement of an individual through the search space, it compares the fitness values at its current position with the fitness values it has achieved previously at any iteration up to the current The best position that is associated with the best fitness value achieved is called the best individual ycU O . For each individual in the swarm, ycU O . can be determined and updated during the search. The jth individual, the best individual, can be expressed as follows: ycUycO . = . cuyc,1O . , ycuyc,2O . , . ycuyc,yccO . ]ycN . In a minimization problem with a single objective function f, the jth best individual ycUyc O . is updated whenever . cUyc O . ) < . cUyc O . cn Oe . ) Iteration Stopping Criteria: The search process will terminate when one of the following criteria is satisfied: - The number of iterations since the last change of the best solution is greater than a previously specified number. - The number of iterations reaches the maximum allowed The velocity of the individual in the kth dimension is limited by some maximum value ycycoycoycaycu . This limit extends the local exploration of the problem space, and it effectively simulates the larger variation of human learning. The maximum velocity in the kth dimension is described by a sequence of kth optimal parameters and is given by: ycyco yco The diagram of applying PSO in optimizing the controller is shown in Fig. Fig. PSO optimizing diagram IV. RESULTS AND DISCUSSION Real Model The real model is shown in Fig. It is re-utilized, and the system parameters are maintained as in . The description of components in Fig. 5 is: Information of Fig. 5 is: 1-pendulum, 2-arm, 3-encoder that measures the angle of the pendulum . , 4-DC motor, 5encoder that measures the angle of the arm . , 6-STM32 control chip, 7-L298 H-bridge board, 8-DC source. Simulation and Experiment Program The simulation program is described in Fig. 6 and Fig. Description of blocks in Fig. 6 is: 1-Block calculating control signal . ), 2-Block imitating RIP. This block is explained in detail in Fig. 7, 3-State of variables, 4-Parts that calculate the mean square of errors. Description of blocks in Fig. 7 is: 1-Control signal of RIP . oltage on DC moto. , 2-Blocks that describe the dynamic equations of RIP in . , 3-Systems Fig. Real model . Thanh-Tri-Dai Le. A Study of Optimized-LQR Control for Rotary Inverted Pendulum by Particle Swarm Optimization Journal of Fuzzy Systems and Control. Vol. No 2, 2025 Fig. Blocks describing the RIP model The embedded program for the experimental model is described in Fig. 8 and Fig. Description of blocks in Fig. is: 1-Block calculating the pulse from the encoder of the arm, 2-Block calculating pulse from encoder of pendulum, 3Value of the angle of the arm, 4-Value of the angle of the Description of blocks in Fig. 9 is:1-Value of the angle of the arm, 2-Value of the angle of the pendulum, 3Block that calculates the control signal through the LQR method, 4-Signal that controls the direction of the motor, 5Signal that controls the velocity of the motor. Fig. Simulation program of LQR control for RIP Fig. Blocks describing input signals from sensors Fig. Blocks describing the controller and the control signal Standard LQR algorithm In the simulation, the initial values of RIP are chosen as yu= yuU . yuN = 0. yu = 0. yuN = 0. A trial-and-error test is used to choose matrices Q and R as ycE=[ ycI = 1 Thanh-Tri-Dai Le. A Study of Optimized-LQR Control for Rotary Inverted Pendulum by Particle Swarm Optimization . Journal of Fuzzy Systems and Control. Vol. No 2, 2025 Thence, from . , . , . , we obtain K to get the simulation result in Fig. yaycIya = O. ce1 2 yce3 2 ) = 32663. Optimized-LQR algorithm with no weighting constant The cost function is chosen as yaycIya = O. ce1 2 yce3 2 ) . Limitation of components in matrices Q and R as ycE = . , 5. ycI = . , . Fig. Response . of RIP under standard LQR control By PSO, we obtain matrices Q and R as In Fig. 10, pendulum moves from the initial position . to the equilibrium point after 4sec. Then, it is balanced. Also, the arm moves from the initial value (-0. 1 ra. to position (-0. 5 ra. and it is stabilized at 0 position after 6 sec. Using the ISE method to evaluate the fitness of the system, considering yce1 as the error of yu and yce3 as the error of yu, we yaycIya = O. ce1 2 yce3 2 ) = 445. ycE=[ ycI = 1 From . , . , . , we obtain the LQR controller, and the simulation and experiment are shown in Fig. 13 to Fig. The experimental result is shown in Fig. 11 and Fig. In Fig. 11, the angle of the pendulum is stable. However, the vibration is 0. 04 rad around the equilibrium point. In Fig. the arm vibrates from 0. 15 rad to 0. 42 rad from the zero Fig. Simulation results . ad and rad/. Fig. Experimental angle pendulum In Fig. 13, the settling time of angle is about 0. 8 sec, and that of angle yu is about 4 sec. The cost function of the simulation results is yaycIya = O yce1 2 yce3 2 = 54. In Fig. 14, the pendulum oscillates around the equilibrium Pendulum oscillates around 0. The settling value is around 0. In Fig. 15, arm oscillates from 0. The cost function in the experiment is yaycIya = O yce1 2 yce3 2 = 18301 Fig. Experimental angle of arm From Fig. 11 and Fig. 12, using the ISE method to evaluate the fitness of the system, we obtain. From . (ISE of simulatio. , from . , the cost function in the case using PSO is smaller than Thanh-Tri-Dai Le. A Study of Optimized-LQR Control for Rotary Inverted Pendulum by Particle Swarm Optimization Journal of Fuzzy Systems and Control. Vol. No 2, 2025 the non-PSO results. Thence. PSO successfully optimizes LQR control in simulation and experiment Fig. Angle of pendulum Fig. Simulation response . ad and rad/. Fig. Angle of arm Optimized-LQR algorithm with weighting constant The Cost function is chosen as yaycIya = O. cuyce1 2 yce3 2 ) . Fig. Angle of pendulum where x is a weighing constant Limitation of components in ycE and ycI, the value of ycu is chosen as ycE = . , 5. ycI = . , . ycaycuycc ycu = 640 Thence. PSO give us the values of Q and R as ycE=[ ycI Fig. Angle of arm Thence, the control results are shown in Fig 16 to Fig. In Fig. 17, pendulum oscillates around the equilibrium The pendulum oscillates around 0. , and the average value is around 0. When adding a weighing constant ycu to yce1 in the cost function, the vibration of the pendulum is smaller . n Fig. 14 and Fig. And, the quality control of the arm is not considered . n Fig. 15 and Fig. The cost function is chosen as yaycIya = O. ce1 2 ycuyce3 2 ) . Limitation of components in Q and R, the value of x is chosen ycE = . , 5. ycI = . , . ycaycuycc ycu = 640 Thence. PSO gives us the values of ycE and ycI as Thanh-Tri-Dai Le. A Study of Optimized-LQR Control for Rotary Inverted Pendulum by Particle Swarm Optimization . Journal of Fuzzy Systems and Control. Vol. No 2, 2025 ycE=[ ycI = 1 Thence, the control results are shown in Fig. In Fig. the pendulum oscillates around the equilibrium position. The pendulum oscillates around 0. , and the average value of the oscillation is around 0. In Fig. 21, the arm ranges from 0. In Fig. and Fig. 21, when adding the weighing constant x in . , quality control of the arm is smaller . ess vibratio. Thence, weighing constant helps to optimize the main component that we care about . n this case, it is y. CONCLUSION Through the paper, optimized-LQR controllers based on PSO make the response of a RIP better than a normal LQR controller: shorter settling time, smaller oscillation in simulation and experiment. These criteria can be described more easily by the smaller fitness function. Also, the later generations of the finding matrices Q and R give smaller fitness functions. Thence. PSO is proved to be a successful method in optimizing control parameters. In this case, they are matrices Q and R. The results are described randomly due to the uncertainty of the searching methods. PSO is proven to successfully optimize the control parameters and give better quality control . hrough values of cost function compariso. Thence, a constant x is added to adjust the optimization to a variable that we care. And, the study shows the method to calibrate this constant to obtain a better quality for the expected variable. ACKNOWLEDGMENT