Online Adaptation of a Compensatory Neuro-Fuzzy Controller Parameters Using the Extended Kalman Filter: Application on an Inverted Pendulum

: This paper presents the implementation of a Compensatory Adaptive Neuro-Fuzzy Inference System (CANFIS) controller to control an inverted pendulum. This controller is developed in order to readjust the parameters relating to the membership functions and the fuzzy rules used as well as to optimize the dynamics of the latter, using a learning algorithm based on the extended Kalman ﬁlter. The CANFIS controller is developed on the Simulink environment of the MATLAB software and is implemented on a Raspberry Pi 3 board, with a view to analyzing its real behavior, and testing its speed as well as its robustness through the use of the “Processor-In-the-Loop” (PIL) technique. The results obtained through PIL tests showed the effectiveness of the neuro-fuzzy controller equipped with a compensator.


Introduction
The control of non-linear systems is always a rather complex task in the field of automation, because several control techniques require a perfect knowledge of the behavior of the system in order to be able to achieve good performance. The description of a system equipped with its actuators and sensors and the various physical phenomena that appear during operation show the high complexity due to numerous non-linearities as well as the difficulty in perfectly modeling the dynamics of the mechanical sensors-actuators-system. Controlling the system for performing tasks requiring good performance becomes difficult, as knowledge of the system is incomplete and imperfect.
Adaptive control using artificial intelligence techniques has been the subject of several research works in the control of nonlinear systems [1][2][3][4]. The combination of fuzzy logic with neural networks has been recognized as a promising solution to compensate for the non-structural uncertainties of nonlinear systems. Therefore, combining fuzzy logic with neural networks in the form of a single network structure allows building more efficient neuro-fuzzy controllers, and this by taking advantage of the inference capacity of fuzzy reasoning and computational parallelism of neural networks. Among the most efficient adaptive neuro-fuzzy systems, we cite the CANFIS (Compensatory Adaptive Neuro-Fuzzy Inference System) structure, which consists of using a fuzzy compensator which compensates for the bad choice of membership functions, and which uses techniques which allow us to adjust the dynamics of fuzzy rules, so as to adapt to the environment [5]. However, the use of such an adaptive structure requires a high computation time and its implementation in practice then requires powerful control boards in order to minimize the computational time of the algorithm in order to converge on the desired performance.
Due to the computational complexity of these algorithms, several processes are generally necessary so that the controllers are suitable for implementations, because on the one hand, many development boards do not support the double-precision floating-point data type on the MATLAB-Simulink software, and on the other hand, designs based on this floating-point data type consume a significant number of hardware resources compared to designs based on the fixed-point data type [6]. However, in this design methodology, the adaptation of the controller is limited by the fixed point encoding. Several research works have been carried out in this area [7][8][9][10]. In this article, we will use MATLAB-Simulink software to implement the CANFIS controller on a Raspberry Pi 3 board to control an inverted pendulum. These control boards are known by their powerful processors, namely the ARM Cortex processors, and support both fixed and floating point data types. The MATLAB software therefore allows us to considerably reduce the design time of the algorithm, and to implement it on the Raspberry board. The use of the Processor-In-the-Loop (PIL) technique makes it possible to test the behavior of the CANFIS controller on the hardware, while the rest of the control loop is on the Simulink. This document is organized as follows: in the second part, we present the structure of the fuzzy neuro network with a fuzzy compensator as well as the mathematical formalism, then, we study the learning algorithm. In the third part, we present the control scheme based on the Raspberry Pi 3 board, suitable for dynamic control of the inverted pendulum using the CANFIS controller. In the fourth part, we present the results of the PIL tests obtained by applying this synthesized strategy to the command in tracking of a reference trajectory of the inverted pendulum. Finally, we end our work with a general conclusion and some perspectives.

Description of the Adaptive Neuro-Fuzzy Network with a Compensator
CANFIS is a fuzzy inference system based on a multi-layered adaptive network, where the learning algorithm not only adjusts the membership functions, but also optimizes the dynamics of fuzzy reasoning by adjusting the degree of compensation. In this section, we develop an ANFIS controller equipped with a fuzzy compensator, where the adaptation of its parameters is ensured by a learning algorithm based on the extended Kalman filter. To simplify understanding and without loss of generality, we consider a system with two inputs x 1 , x 2 and one output u (Figure 1), modeled by a fuzzy system of the Takagi-Sugeno type, composed of the following four fuzzy rules: The degree of activation of a rule is defined by w i . We consider the pessimistic and optimistic operations, given respectively as follows: The fuzzy compensator expressed by this relation: where γ i ∈ [0, 1] is the compensatory degree. Therefore, the net value of the fuzzy neuralnetwork equipped with a fuzzy compensator is given as follows: Eng. Proc. 2022, 14, 11 where is the compensatory degree. Therefore, the net value of the fuzzy neural-network equipped with a fuzzy compensator is given as follows: ( ) Consider that 1 x and 2 x are the position error e and its derivative e Δ . We associate two fuzzy sets for each of the inputs, namely ( ) and ( ). x with respect to fuzzy subsets i A and i B , defined by the following member functions: Consider that x 1 and x 2 are the position error e and its derivative ∆e. We associate two fuzzy sets for each of the inputs, namely N (Negative) and P(Positive). µ N et µ P represent the appropriate membership degrees of the variables x i with respect to fuzzy subsets A i and B i , defined by the following member functions: with: (ρ i , σ i ) and (β i , δ i ) being the (mean, variance) of the fuzzy set of the membership functions respectively of x 1 and x 2 .

Learning Algorithm
The controller is characterized by a vector of parameters Φ. Our objective is to find the values of the vectorΦ by minimizing the following criterion [11]: where: y(k) is the real output of the system and y d (k) is its desired output. The extended Kalman filter approach consists of linearizing the output regulator u d at each step k around the estimated vector Φ d (k). This is equivalent to writing: With: where n is the dimension of the vector Ψ T . Consequently, the parameters are adjusted according to the following relation [12]: where Ψ(k) is the Jacobian matrix (the observation matrix of the system), P(k) is the estimation matrix of the error covariance and B(k) is the measurement covariance matrix. In order to approximate the variation e u , we linearize the inverse model of the system around y(k) according to the following relation: where y(k) is the system output and u(k) its input. For this linearized model, the value u d (k) can be expressed as follows: Therefore, we have: Then: We also have: ∂e(k) = ∂y d (k) − ∂y(k). We assume that y d (k) is constant in the neighborhood of y(k). Then: Therefore: The relation (17) can be written as follows: In order to eliminate the constraint γ i ∈ 0 1 defined in Equation (7), we define: Consequently, the parameters vector to be readjusted is given by: With: We have: Then: With: ∂h ∂e where j is the integer part of (i − 1)/2.

Implementation of the CANFIS Controller Equipped with a Compensator on the Raspberry Pi 3 Board: Application on the Inverted Pendulum
In this section, we use the "Processor-In-the-Loop" technique in MATLAB-Simulink, which allows us to test the behavior of the CANFIS controller on the Raspberry Pi 3 board [13]. In this mode of execution, the CANFIS controller runs in the hardware while the Eng. Proc. 2022, 14, 11 6 of 8 rest of the closed loop runs on the Simulink environment. In order to test the performances of the controller, we considered the stabilization problem of an inverted pendulum on a cart. The dynamic equations of the nonlinear system are given by [14]: .
where x 1 is the position of the vertical rod (in radian), x 2 is the angular velocity and τ(t) the torque applied to the rod. Its parameters are given in the Table 1. The implementation of the CANFIS controller was done with a frequency of 10 KHz. The execution diagram of the regulation chain (CANIFIS controller, System and disturbance) in PIL mode under the MATLAB Simulink environment is presented in Figure 2. where 1 x is the position of the vertical rod (in radian), 2 x is the angular velocity and ( ) t τ the torque applied to the rod. Its parameters are given in the Table 1.

Results of the PIL Tests
In this section, we present the simulation results of the PIL mode. In order to test the robustness of the two proposed controllers, we added a disturbance on the input of the system at the instant 20s t = , given as follows: (43) Figures 3a,b, 4a,b and 5a,b represent the results of the position tracking, the position tracking errors as well as the control signals delivered by the CANFIS controller. From these figures, we can see that the proposed controller has good performance (tracking, response time and robustness) with a low precision error, in both test cases (with and without disturbances). This is due to the use of a compensator which compensates for errors in the choice of membership functions, even readjusting the dynamics of fuzzy rules, using a learning algorithm based on the extended Kalman filter. The implementation of the proposed controller allowed us to obtain good performances thanks to the sampling frequency of the Raspberry Pi 3 board.

R aspberry Pi 3
Reference Output Reference Output

Results of the PIL Tests
In this section, we present the simulation results of the PIL mode. In order to test the robustness of the two proposed controllers, we added a disturbance on the input of the system at the instant t = 20 s, given as follows: (43) Figure 3a,b, Figure 4a,b and Figure 5a,b represent the results of the position tracking, the position tracking errors as well as the control signals delivered by the CANFIS controller. From these figures, we can see that the proposed controller has good performance (tracking, response time and robustness) with a low precision error, in both test cases (with and without disturbances). This is due to the use of a compensator which compensates for errors in the choice of membership functions, even readjusting the dynamics of fuzzy rules, using a learning algorithm based on the extended Kalman filter. The implementation of the proposed controller allowed us to obtain good performances thanks to the sampling frequency of the Raspberry Pi 3 board. response time and robustness) with a low precision error, in both test cases (with and without disturbances). This is due to the use of a compensator which compensates for errors in the choice of membership functions, even readjusting the dynamics of fuzzy rules, using a learning algorithm based on the extended Kalman filter. The implementation of the proposed controller allowed us to obtain good performances thanks to the sampling frequency of the Raspberry Pi 3 board.

Conclusions
In this article, we have proposed the implementation on a Raspberry Pi 3 board of a neuro-fuzzy controller CANFIS, in order to control an inverted pendulum. The CANFIS controller presents good results because it uses a learning algorithm based on the extended Kalman filter, which converges very quickly, and which readjusts the membership functions and optimizes at the same time the dynamics of fuzzy reasoning by adjusting the degree of compensation. The development and implementation of the controller was done through MATLAB's Simulink environment, which simplified the study and implementation of the code on the Raspberry Pi 3 board.
In conclusion, we have tried through this article to show the efficiency of the CANFIS controller on real hardware (Raspberry Pi 3) in the control of non-linear systems. The implementation of such a controller using the PIL technique has demonstrated its speed and robustness to disturbance rejection.

Conclusions
In this article, we have proposed the implementation on a Raspberry Pi 3 board of a neuro-fuzzy controller CANFIS, in order to control an inverted pendulum. The CANFIS controller presents good results because it uses a learning algorithm based on the extended Kalman filter, which converges very quickly, and which readjusts the membership functions and optimizes at the same time the dynamics of fuzzy reasoning by adjusting the degree of compensation. The development and implementation of the controller was done through MATLAB's Simulink environment, which simplified the study and implementation of the code on the Raspberry Pi 3 board.
In conclusion, we have tried through this article to show the efficiency of the CANFIS controller on real hardware (Raspberry Pi 3) in the control of non-linear systems. The implementation of such a controller using the PIL technique has demonstrated its speed and robustness to disturbance rejection.

Conclusions
In this article, we have proposed the implementation on a Raspberry Pi 3 board of a neuro-fuzzy controller CANFIS, in order to control an inverted pendulum. The CANFIS controller presents good results because it uses a learning algorithm based on the extended Kalman filter, which converges very quickly, and which readjusts the membership functions and optimizes at the same time the dynamics of fuzzy reasoning by adjusting the degree of compensation. The development and implementation of the controller was done through MATLAB's Simulink environment, which simplified the study and implementation of the code on the Raspberry Pi 3 board.
In conclusion, we have tried through this article to show the efficiency of the CANFIS controller on real hardware (Raspberry Pi 3) in the control of non-linear systems. The implementation of such a controller using the PIL technique has demonstrated its speed and robustness to disturbance rejection.