Modelling and Control of a Two-Wheel Inverted Pendulum Using Fuzzy-PID-Modified State Feedback

Control of mechanical systems by electronic systems controlled by computer programs is one of the most active research areas in mechatronic systems engineering. Tese programs carry out control laws, which are algorithms. Tis study focuses on Segway control (a two-wheeled inverted pendulum which is a highly nonlinear and unstable open-loop system). Our research entails creating a control law to stabilize this system. We proposed using a state feedback controller, which provided us with a stable system and a lower error margin; however, to correct this error, we used a combination of the state feedback controller and the fuzzy-PID controller. Te efectiveness of the proposed method is demonstrated using simulation results.


Introduction
Te control of the wheel inverted pendulum (WIP) robot has gained popularity in both industry and research communities. WIP-based products, such as the Segway human transporter, have recently become available in the market. However, due to the inherent instability and signifcant nonlinearity of the inverted pendulum system, precise control is crucial for its successful operation. In this study, we aim to contribute to the existing body of research by proposing a novel control approach to stabilize the WIP system.
We begin by demonstrating computationally that the open-loop control is unstable. Te system's controllability and observability will also be investigated. To overcome the challenges of controlling a highly nonlinear system, we propose the use of state feedback control, which can provide high accuracy and fexible dynamic response. Furthermore, we will augment the state feedback control with a fuzzy-PID integrator to enhance stabilization.

State of the Art.
Te study of inverted pendulum systems is an area of automation research that has experienced signifcant growth in recent years. Tis is owing to their optimum instability, which makes them difcult to regulate, as well as their diverse forms and dimensions. Te simple pendulum, the double pendulum, and the Furuta pendulum can be mentioned. Diverse control strategies have been proposed to stabilize these systems, with a focus on linear systems such as proportional-integral-derivative (PID) controllers [1,2] and linear-quadratic-regulators (LQR) [3], which are simple to design and evaluate in terms of stability but require a linearized model of the system to function efectively. To overcome these difculties, other techniques, such as sliding mode control [4,5] and adaptive control [6] based on the backstepping approach [7][8][9], have been developed to overcome the limitations of these linear systems. PDC control [10] and dynamic surface control [11], which employ neural networks [12][13][14] and fuzzy logic [15][16][17][18], have also been suggested to enhance the performance of nonlinear systems.
In a recent study, the authors in [19] presented a state feedback control law for an inverted pendulum system, which demonstrated good stabilization performance in simulation. Te authors in [20] proposed a fuzzy-PID controller for a wheeled inverted pendulum, which achieved improved control accuracy and robustness compared to traditional PID controllers. Furthermore, the authors in [21] utilized a hybrid control scheme combining sliding mode control and LQR to stabilize an underactuated pendulum system.
Despite the progress made in the feld of inverted pendulum control, there is still a need for novel control techniques that can provide improved stability and robustness for more complex and underactuated systems.

Problem.
In this study, we propose a novel control approach to stabilize a nonlinear and underactuated inverted pendulum system. Te system is highly sensitive to delays, friction, and external disturbances and has unstable open-loop dynamics. To address these challenges, we combine a state feedback control law with a fuzzy-PID integrator. Our contribution is to demonstrate the efectiveness of this technique in achieving stable control of the system. Compared to traditional control strategies, our approach ofers high accuracy and a fast and fexible dynamic response.

Description and Modelling of the Inverted Pendulum
Te inverted pendulum is a test platform that poses an instability problem at the angle θ � 0; therefore, a modelling phase is necessary to allow the study in simulation. For this purpose, diferent methods can be found in the literature, such as the one based on Newtonian physics or the one based on the Lagrange-Euler formalism. In this work, we have chosen the Lagrange-Euler method which constitutes a systematic approach whose implementation is simple.

Modelling of a Segway.
A Segway can be modelled by a wheeled inverted pendulum. Tis underactuated mechanical system has been particularly studied because, despite its simplicity, it indicates a practical interest for locomotion, as proved by the commercialization of the Segway, a compact personal vehicle based on the model of the wheeled inverted pendulum. Te wheeled inverted pendulum is schematically shown in Figure 1 [22]. Te parameters of our system are presented in Table 1.

Te Dynamic Model
(1) Te dynamic model gives the nonlinear equations of the system's motion. To solve these equations, we linearize them around the equilibrium position. In this position, the system is in its quasiequilibrium state. So, we could develop the linearized model under the assumption that the variation of the inclination angle is small enough to be neglected. We then have three linearized equations of motion at the state of equilibrium as follows: (2) Once the system is linearized, we have reorganized it into the following state space: 2 Journal of Robotics where the vectors x and u are given by the following equation: Te matrices A and B can be identifed as follows:   Journal of Robotics 3 Te matrix C is defned as an identity matrix (6, 6) and the matrix D as a null matrix, which then gives Y � X.
After validating the developed model, we will present open-loop simulations.

Response of the Inverted Wheel
Pendulum. To study the system's stability, we will determine the impulse response of the system in the open-loop using MATLAB. Tis is the reference tool for numerical simulation. It ofers advanced possibilities for identifcation or control. More generally, it can be used to solve a wide variety of simulation problems.
Simulations are carried out in an environment MAT-LAB/Simulink. Te diferential equations governing the dynamics of the system are integrated using the method Runge-Kutta (function ode45 of MATLAB). Figure 2 shows the Simulink diagram. Applied to the input an amplitude, we will obtain the following results.

Figures (Figures 3-5) show that the system's kinematic parameters (x and _
x, θ and _ θ, and φ and _ φ) grow with time, indicating its instability. In this case, a control law is required to make the system stable.

Instability of the System.
According to the study, the open-loop system is unstable because one of its poles is located in the right half plane of the complex plane.  To stabilize the system, state feedback control will be used using the control gain matrix K. Before that, we need to show that the system is controllable and observable.

The Notions of Controllability and Observability
Observability and controllability are among the fundamental and essential notions in control theory. Tey have been introduced by Kalman during the 1960s in the context of fnite system dimensions. Te concepts of controllability and observability play an essential part in the study of control and fltering problems. Te concept of controllability studies the possibility of adjusting the behavior of the system under consideration in order to force the state to take the desired values during a fnite time. On the other hand, the observability of a system can be defned as the possibility of predicting the state of the system at any time within the operating time interval.

Te Controllability.
Te system is controllable if any two distinct points in the state space can be joined; in other words, let there be two points x 0 , x 1 ∈ X; there exists two instants t 0 and t 1 with t 0 < t 1 and a control u, defned on the interval [t 0 , We study the controllability of the linear system with dimension n defned in the state space by the system of equations of the following form: where x ∈ R n×1 the state vector, A ∈ R n×n the state matrix, B ∈ R n×m the control matrix, u ∈ R m×1 control vector, y ∈ R p×1 the output vector, and C ∈ R p×n the output matrix, p represents the number of outputs, and D ∈ R p×n is the direct transmission matrix. Te matrices A and B are timeindependent matrices. In such a case, the dynamics of the system is said to be time-invariant (or stationary).
It can be shown that a system is controllable only if its controllability matrix C has full rank (i.e., rank (C) � n, where n is the number of variable states).
Since 6 � 6 in our system, then the system is said to be controllable.

Te
Observability. In a nutshell, observability is a property from which the state of the system under consideration can be determined exactly or approximately. By duality with the concept of controllability, the linear invariant system is observable only if the following condition is met: Te rank Γ obs � n, Γ obs is the observability matrix, obtained by putting n matrices 1, , . . ., n C CA CA (n − 1) below each other.
For LTI (linear time-invariant) systems, the system is observable if and only if the observability matrix Γ obs , has full rank (i.e., rang (Γ obs ) � n, where n is the number of variable states).
As far as our system is concerned, we can conclude that it is observable.    Journal of Robotics Using the MATLAB software, we will make a dynamic analysis of the discretized linear model. Ten, we will study the features of this model as a function of the chosen discretization step k, and thus, of the dimension 2 (N + 1) of the system. Tis study focuses on the application of state feedback control theoretically through simulation using Simulink modelling software; the results will then be presented and their interpretation.

Feedback Control and Choice of K-Matrix
Feedback control modifes the self-dynamics (poles) of the closed-loop system to increase stability, accuracy, and speed, while maintaining a small or zero steady-state error. Te method consists of generating a control signal u from the states x1, x2. . .xn. Figure 6 provides a visual representation of the relationship between the system's states and the feedback control mechanism.
Te idea is always to drive the system with a setpoint signal and to automatically generate the control signal by comparing the setpoint value and the actual behavior of the system in performance.
Te control law that meets the above objective is called pole placement control.

Pole Placement.
Pole placement consists of determining the value of a controller's gain according to the desired position in the complex plane of certain BF poles chosen by the designer. Let be a state feedback controller; we defnite the following system of equations: where K is a matrix called the state feedback gain and v is a new input to the closed-loop system. Te closed-loop system is therefore written as follows: Te calculation of the K-matrix was carried out through a random pole change at the beginning; each time the values are changed and the curve plotted until a control point is reached: We then modifed lines 3 and 4 of our MATLAB calculation and obtained the results shown in Figure 7.
Applied to the input an amplitude, we will obtain the following results.
As shown in Figure 8, the application of the state feedback control to the system shows that the pendulum returns to the vertical position _φ (zero defection) about 1.3 seconds. It can be seen that the response is smooth and no longer aggressive.

Various Commands Available for Stabilisation
Te control of the two-wheel inverted pendulum has been realized based on diferent laws such as the following points: (1) Te extended PDC (parallel distributed compensation) control gives simulation results illustrated in Figure 9 [10] (2) Control through adaptive backstepping [8]

Discussion of the Results Obtained and
Application of the PID-Fuzzy Combination 6.1. Discussion of the Results Obtained. Te application of the extended PDC (parallel distributed compensation) control to the system, as shown in Figure 9, demonstrates that the Segway returns to its equilibrium position after a certain response time (about 7.3 seconds) and with some overshoot. Figure 10 depicts the adaptive backstepping control for the system, which shows that the Segway returns to its equilibrium position after a certain response time (about 6.2 sec) and with some overshoot.
Te comparison of the applied commands ( Figure 11) shows that the state feedback command performs better than the extended PDC (parallel distributed compensation) command and the adaptive backstepping command.
Our method has a signifcant advantage over existing ones in the literature (extended PDC control, adaptive backstepping, and so on) in that it has a much lower error margin, a faster response time (about 1.3 seconds), is generally smooth, and has a slight overshoot.
To improve the performance and stability of a Segway, we will present another proposed control based on a fuzzy-PID control loop in conjunction with a pole placement controller in the following step.

A Fuzzy-PID Controller Modifes Feedback Control.
Te state feedback control modifes the closed-loop system's poles. However, the latter does not guarantee a zero position error. A fuzzy-PID integrator is one option. Te PID uses feedback (from sensors that measure the orientation and movement of the Segway) to continuously adjust the output of a system (motor). While the fuzzy logic controller will be used to process the input variables (the orientation and motion of the Segway) and apply fuzzy rules to calculate the output variables, which will then be used to adjust the    Journal of Robotics motors to achieve the desired Segway behavior. Te control law is written as follows: where K' ∈R n and K i a scalar. Te deviation ε defned by ε � y′ − y, u is the control signal. Te vectors K' and K i can be chosen by a pole placement method. We specifed one more pole (n + 1) to take into account the presence of the integrator. We consider that y′ is a step, then y′ � 0 for about each instant of time and that the step perturbation implies: lim ε ⟶ ∞ ε(t) � 0.
Hence, the position error is zero.
After applying the Laplace transformer, the PI controller is given by the following transfer function C(s) � K' + K i /s + K d s.
In order to implement a fuzzy logic controller, we defne a set of fuzzy rules that describe how the system should respond to various inputs.
For example, if the Segway leans left and moves forward, a fuzzy rule might specify that the left motor should be set to increase speed and the right motor should be set to decrease speed to correct the lean an maintain balance.
Te optimal gains K p , K i , and K d for a PID controller were determined by several simulation tests are mentioned in Table 2.

Variables and Linguistic Values.
A linguistic variable represents a regulated state in the system or a setting variable in a fuzzy controller. In Figure 12, each value represents a fuzzy set of the universe of discourse: (i) Discourse universe: temperature from −10 to 14°C.
(iii) Linguistic values: "cold" "hot."     (iv) Membership function: We already know that fuzzy logic is not a logic that is fuzzy but a logic that is used to describe fuzziness. Tis fuzziness is best characterized by its membership function.
In other words, we can say that the membership function represents the degree of truth in fuzzy logic. Te membership functions are represented by graphical forms as follows in Figure 13.

A Fuzzy
Controller's Structure. Te most common application of fuzzy logic is the fuzzy controller. Te following diagram ( Figure 14) depicts the general structure of a fuzzy controller. Te fuzzy controller is made up of four major components. A fuzzy logic system includes a fuzzifcation block (used to convert nonfuzzy numerical variables from inputs into fuzzy linguistic variables), a rule base, an inference mechanism (used to simulate human decisions using fuzzy variables transformed by fuzzifcation and inference rules to create and determine fuzzy output variables), and a defuzzifcation block. Using the Sugeno-Takagi approach, we developed the fuzzy logic controller. Angle, angular velocity, location, and speed are the input values of the controller, which are linguistic variables. All linguistic variable values have been categorized as negative (N) or positive (P). Using the set point and the measured output, the PID controller was developed by computing the deviation between the set point and the feedback. Te error is then utilized to compute the three components of the PID controller (proportional, integral, and derivative), which are then combined to provide the control output. A fuzzy inference system is utilized to create a fuzzy logic controller employing input variables and fuzzy rules to determine output variables. Using the outputs of the PID controller and the fuzzy controller, the motors are fnally tweaked to obtain the required Segway behavior.
Te fuzzy membership functions for the inputs and outputs are shown in Figure 15. Figure 16 illustrates the control surface of the fuzzy control.
Te Simulink state feedback control diagram as modifed by the PID-fuzzy controller is shown in Figure 17.
Here, K p K i K d the controller gains used to calculate the output of the PID controller as a function of the error between the target value and the measured value. Te integral of the error and the derivative of the error are also considered in the output calculation.

. Results and Interpretation
Te pole placement controller was used to calculate the optimal actions to take based on the current system state and desired poles, and then the fuzzy-PID algorithm was used to adjust these actions based on the current error and system response. Figure 18 shows the fuzzy-PID-modifed state feedback compared to the previous controllers.
Tis study has allowed through the simulation results found, to notice a great improvement of the rapidity with the intelligent control fuzzy-PID. Conversely, the system achieves the desired stability without overshooting. Te BP neural network's robust nonlinear mapping capabilities can enhance the controller's fexibility. Table 3 shows the system's transient response characteristics are as follows.
In order to evaluate the ability of the proposed controller to compensate for external disturbances and thus test its robustness, we perturbed the pendulum to observe the behavior of the controller under these conditions. A disturbance was applied to the system for four seconds, (from 18 to 22) seconds after the start of the simulation. Te results of this evaluation are presented in Figure 19.
Te fgure shows the system response after the application of an external disturbance. It can be observed that the proposed method maintains a stable and precise response despite these disturbances, with a limited increase in oscillation amplitude. Unlike other controllers, the proposed method has a smoother profle, ascending and descending with a smaller amplitude, suggesting a faster and more precise response, as well as a better ability to adapt efectively to external disturbances.
Tese results confrm the signifcant improvement of the proposed method in terms of robustness, which is an essential feature for many control applications in perturbed environments. Te ability of the proposed method to maintain a stable and precise response in the presence of external disturbances suggests that it could be successfully used in real-world applications. In conclusion, our proposed method has signifcant advantages over other tested  controllers, and its robustness is an important advantage for many control applications.

Conclusion
Tis research has enabled us to admit that extended PDC (parallel distributed compensation) and adaptive backstepping control can produce some results, but they are still unsatisfactory in terms of stability and speed. Furthermore, the state feedback control is much better and results in a stable system with a reduced error margin and a slight overshoot; however, to improve the performance and robustness of this system, we implemented a fuzzy PID integrator, which corrected the error problem. Finally, we can conclude that the intelligent controller implementation is more complex than the classical controller because of the right combination of controller "fuzzy PID," the form and intervals of the membership functions, and the controller rules. Nonetheless, intelligent control produces signifcantly better results in terms of system stability, speed, and robustness in the face of external disruption.
It should be noted that the desired poles and the calibration of the fuzzy-PID controller parameters can have a signifcant impact on system performance and stability. Tese parameters may need to be updated in response to changing system conditions and requirements.
Other more complex mathematical models of the Segway can be tested in the future.

Data Availability
Te datasets used to support the results of this study are available from the corresponding author upon request.