Modeling and Optimal Controller Based on Disturbance Detector for the Stabilization of a Three-link Inverted Pendulum Mobile Robot

: This work presents the realization of a complicated stabilization problem for a three inverted pendulum links-based mobile robot. The actuators of the mobile robot are direct current motors that have tachometer couplings to measure both the position and speed of the wheels and links. Using direct measurements under load and analyzing the deceleration curve, the motor parameters are determined experimentally. A mathematical model of the robot is obtained via the Euler–Lagrange equations. Next, the nonlinear model is linearized and discretized. Based on this discrete LTI model, an optimal controller is designed. The states and disturbances are estimated using a robust detector. Both the controller and detector are implemented in the robot processor. Numerical simulations and experimental tests show a good performance of the controller despite the presence of disturbances. Writing—Review and Editing, M.G.F.-G. and J.H.P.-C.; Visualization, L.A.J.-M.; Supervision, M.G.F.-G.; Project Administration, M.G.F.-G.; Acquisition, M.G.F.-G. All


Introduction
Inverted pendulum mobile robots are an excellent testbed for implementing different classical control strategies and advanced controllers. The most common are the inverted pendulum on a cart [1], the double inverted pendulum on a cart [2], the double inverted pendulum with an actuator at the first joint (Pendubot) [3], and the double inverted pendulum with an actuator only in the second joint (acrobot) [4].
The wide application of this type of mobile robots has attracted the interest of many researchers in automatic control and robotics. Some examples of these applications are the personal transportation systems [5], walking design for humanoid robots [6], robotic wheelchairs [7], and educational purposes [8][9][10]. From the point of view of automatic control theory, the inverted pendulum mobile robot presents a complex stabilization problem, since it has only two wheels as a supporting point. One of the first researchers to tackle the stabilization control problem of two degrees of freedom inverted pendulum mobile robot was Yamamoto [11], who proposed a mathematical model with one input and two outputs. In the work presented by S.W. Nawawi [12], a sliding mode controller was used to balance an inverted pendulum-type mobile robot, also with two degrees of freedom.
Concerning to recent advancements about this kind of robots, in [13], the modified DAYANI method supported by a five-layered back-propagation neural network is used for the path control of a two-wheeled self-balancing robot. Using this method, the robot is able to find the optimal path from the starting point to the target point in a short time without hitting obstacles. In [14], a fuzzy controller and a PID controller are optimized using the particle swarm optimization algorithm. Both controllers are used for the stabilization of an under-actuated mobile robot. The optimized fuzzy controller shows a better suppression of system oscillations and current peaks than the optimized PID controller. In [15], the problem of the stabilization of a two-wheeled self-balanced vehicle is solved by using a nonlinear H ∞ . Despite external disturbances, un-modeled dynamics and extreme initial conditions, the system is able to work satisfactorily. In [16], a nonlinear proportional-derivative and a sliding mode controller using two reaction wheels are designed and implemented for an inverted pendulum. Both controllers overcome the performance of a previously presented PID controller. In [17], a self-balancing two-wheeled robot with two manipulator arms is considered. This robot is able to pick up objects. A dual-loop fuzzy control system is proposed to control the movement, rotation, and reach the desired position while keeping the robot in balance. In [18], the most common approaches for the modeling and control of such kind of systems are studied. To solve the stabilization problem, different kinds of controllers such as PD, LQR, H ∞ , backstepping, non-linear control, feedback linearization, model-based control, and model-based disturbance rejection control are studied. For the case of wheeled inverted pendulum systems subject to disturbances, a disturbance observer as feedforward compensation is proposed. Likewise, the design of a robust adaptive controller for the stabilization and trajectory tracking of such systems is considered. This control can work satisfactorily despite un-modeled dynamics and parametric uncertainties. Finally, advanced approaches based on soft computing such as neural networks, least squares support vector machine, and fuzzy logic are discussed. The performance of all the aforementioned controllers is tested by numerical simulations. On the other hand, regarding the use of inverted pendulum-type systems in education, in [19], a cheap portable arduino-based self-balancing robot is used to implement different strategies of control. All the different stages in the design and implementation process such as modeling, parameter estimation, programming, etc., are considered. In [20], a low-tech self-balancing human transportation vehicle is presented as a pedagogical tool for teaching feedback control concepts.
In this work, we have designed and assembled a mobile robot with five degrees of freedom and four inputs. It is a mobile robot whose supporting point is on its two wheels and whose links are three inverted pendulums. We have also done a complete theoretical analysis with sufficient mathematical foundations of the relationship between control systems and robotics. For the stabilization under disturbance of our mobile robot, we have designed an optimal controller based on two fundamental structural concepts for the compensation of dynamic systems: observability and controllability.
This article is organized as follows: Section 2 describes the development of the dynamic model of the mobile robot. Section 3 describes the design and assembly of the mobile robot, as well as its electronic characteristics. Section 4 presents the values of the parameters acquired from each motor of the mobile robot and the real-time response of each motor. In Section 5, we describe the mathematical model of the control law for the optimal stabilization for disturbed systems, while in Section 6, we synthesized, from an observer of state variables, a robust detector to estimate state variables and disturbances. In Section 7, we present the development of the optimal controller based on a robust detector for the stabilization of the mobile robot, and the closed-loop system diagram and numerical simulations that indicate a good performance of the controller. In Section 8, we can see the description and results of the implementation of the robust controller in the mobile robot, the movement of the wheels, and the stabilization of the mobile robot. Section 9 is dedicated to the discussion and conclusions about the results and experience obtained in this work. In Appendix A the general description of a discrete-time state-space model has been placed. Appendix B shows the matrices of the mobile robot's non-linear model, while Appendix C contains the numerical matrices of the mobile robot, and finally Appendix D shows the efficient performance of the optimal controller based on the disturbance detector versus PD controller. Figure 1 shows the free-body diagram of the inverted pendulum mobile robot with five degrees of freedom. The masses of the links are defined as m 1 , m 2 , and m 3 , and the mass of the wheel as m w . It is assumed that the center of gravity coincides with the geometric center of the links that are at a distance of l 1 , l 2 , and l 3 (l i is the distance from joint i to the center of mass of the i − th link, i = 1, . . . , 3). The angle of link 1 relative to the vertical is defined as θ 1 , the angle of link 2 relative to link 1 as θ 2 and the angle of link 3 relative to link2 as θ 3 . Four torques act on the robot, τ 1 , τ 2 , τ 3 , and τ 4 , has five degrees of freedom δ r , δ l , θ 1 , θ 2 , and θ 3 . The mobile robot parameters are defined in Table 1. The links are considered as uniform rods of mass M and length l. The moment of a rod's inertia calculated about an axis of rotation, which is perpendicular to the rod and touches one end of the rod, is J = 1 3 Ml 2 . The wheels are considered as uniform discs of mass M y radius R. The moment of inertia of a uniform disc about an axis through its center is given by J = 1 2 MR 2 . The mobile robot's mathematical model is obtained from the equations of Euler-Lagrange. The Euler-Lagrange equation is defined as [21]:

Dynamic Model of the Mobile Robot
where τ i is the vector of generalized forces, q i is the vector of generalized coordinates,q i is the vector of joint velocities, Λ = T − V is the Lagrangian, T is the kinetic energy of the system, and V is the potential energy of the system. Equation (1) can be written in its compact form: where M(q) is the inertia matrix, V(q,q) is the Coriolis and centrifugal matrix, g(q) is the vector of gravitational forces, q is the position vector, andq is the velocity vector. The appropriate state variables to describe the dynamic model of the robot are the position q and the velocityq. Then Equation (2) can be expressed in terms of the state vector: qq T as: From the free body diagram of the robot (see Figure 1) it is determined that the generalized coordinate vector of the mobile robot is q = q 1 q 2 q 3 q 4 q 5 The displacement of the right wheel is δ r , and δ l is the displacement of the left wheel, and θ 1 , θ 2 , and θ 3 , are the angular position of the first, second, and third links respectively.
Denotingq andq asq = δ rδrθ1θ2θ3 The kinetic and potential energy of the system are calculated. The robot model represented by the Euler-Lagrange equations is obtained: In Appendix A, we can see the matrix representation of the system (4), where the matrix M(q) ∈ R 5×5 is the positive symmetric and definite inertia matrix, V(q,q)q ∈ R 5 contains the terms of centripetal and Coriolis forces, G(q) ∈ R 5 is the vector of gravitational forces, and the vector of applied is produced by two actuators on the wheels, an actuator in the second link, and an actuator in the third link.

Design and Assembly of the Mobile Robot with Five Degrees of Freedom
For the construction of the mobile robot, five pieces were designed using SolidWorks software and manufactured in a 3D printer with PLA material, 5 Lego motors EV3 and two wheels of 3.4 cm radius each were used (see Figure 2). A motor with a tachometer is coupled to each wheel. The accuracy of the tachometer is one degree [22]. The maximum speed of each motor is 160-170 RPM with 20 Ncm torque. In the third and fourth joints, two motors with the same characteristics are coupled, and in the fifth joint a motor with a maximum speed of 240-250 RPM with 8 Ncm torque is coupled. The robot has a rotation sensor EV3 implemented to measure the angular position of the first link with respect to the vertical axis. This is an EV3 gyroscopic sensor with an accuracy of ±3 degrees and a sample rate of 1 KHz. For the control of the mobile robot, a 300 MHz ARM9 Lego EV3 processor with a Linux-based operating system and a 64 MB RAM memory was acquired, which makes it suitable for the implementation of the optimal control law designed for the stabilization of the mobile robot. The power source is a lithium-ion EV3 rechargeable DC battery with a capacity of 2200 mAh. Communication with the computer and robot is via Wi-Fi.

Motors Control of the Mobile Robot
The motor parameters are shown in Table 2. These were obtained experimentally by direct measurements under load and analyzing the deceleration curve. The parameters β, K m , K e , R a , and J m are the viscous friction coefficient, torque constant, back electromotive force constant, resistance, and moment of inertia of the motor, respectively. The transfer function that relates the voltage V(s) to the angular velocity Ω(s) of a DC motor is: The real-time response for each motor is obtained by running the motor at full power and recording its angular velocity. Next, it is compared with the response of the system G i (s) obtained from the estimated parameters, as shown in Figure 3. Observing that the responses have the same behavior, validating the parameters obtained.

Torque Equation
Starting from the equation of the electrical subsystem of a DC motor: where R and L a represent the resistance and inductance of the motor, u represents the input voltage, and u e the back electromotive force (back EMF). The torque equation is obtained in terms of the voltage input and motor speed: Using Equation (6) the torques of the mobile robot are determined, obtaining:

State Variables Model of Mobile Robot
Let the vector of states T . Linearizing the system around the operating point δ r = δ l = θ 1 = θ 2 = θ 3 =δ r =δ l =θ 1 =θ 2 =θ 3 = 0 and u 1 = u 2 = u 3 = u 4 = 0 and discretizing the system with a sampling period of t s = 0.005 s, the numerical matrices A y B of the mobile robot are obtained (see these matrices in Appendix C).
The eigenvalues of matrix Since not all eigenvalues are within the unit circle, the system is unstable.

Optimal Control for Systems with Disturbances
The objective is to find an optimal control law u k that minimizes the performance index J i in the interval [k, N]. The performance index is given by [23][24][25]: where Q is a positive definite symmetric matrix (or positive semi-defined), R is a positive definite symmetric matrix, and Q f is a positive definite (or positive semi-defined) symmetric matrix. The term u T k Ru k is related to the energy expenditure of the u k control, the term x T k Qx k is related to the intermediate states, and the term x T N Q f x N is related to the final states. The control law has the form: where K k is the feedback gain matrix, K v k is the gain matrix that depends on the disturbance input w k , and h k+1 is obtained by solving the differential equation: where P k+1 is the positive symmetric and definite solution matrix of the Riccati equation.

Robust Detector for Systems with Disturbances
The equations for the linear system with disturbance w k are: Considering the state observer: where φ is the gain matrix of the observer. Let e k =x k − x k , then the error dynamics of the system is: In Equation (11), it can be observed that even when the eigenvalues of the matrix (A − φC) are stable, the presence of the disturbance w k does not guarantee that lim k→∞ e k+1 tends to zero, so that from the observer (10) we proceed to synthesize a robust detector of disturbance that guarantees the zero convergence of the error e k+1 .

Synthesis of a Robust Detector for Disturbances
For the synthesis [26] of a disturbance detector, a new output built as Y = y k y k+1 . As y k = Cx k , then y k+1 = Cx k+1 = CAx k + CBu k + CEw k . Therefore, the new output Y has the form: Then the expression Cx k+1 has the form: where L is the gain matrix of the disturbance detector. Performing the corresponding calculations, we obtain that: The detector for the disturbed system is defined by the dynamics: The dynamics of the detection error has the form: Let L = L 1 L 2 and by rewriting, we have: Then, if the pair (Ā, C) is detectable, a matrix L 1 can be found such that the matrix (Ā − L 1 C) is asymptotically stable. To avoid the effect of disturbances on the estimation error, an L 2 matrix must be found such that: E ∈ Ker (L 2 C − I) .

Optimal Control Design Based on a Disturbance Detector to Stabilize the Mobile Robot
In order to stabilize the mobile robot around the equilibrium point, an optimal controller based on a disturbance detector is designed.
Using the controllability and observability matrices, it is verified that the mobile robot is a fully controllable and observable system: Appendix C shows the numerical gain matrix L = L 1 L 2 of the robust detector, such that (L 2 C − I)E = 0 and (Ā − L 1 C) is asymptotically stable, with eigenvalues: {0.1999 multiplicity 5; 0.1997 multiplicity 5}. Subsequently, the matrices A and B of the robot system are replaced in the Riccati equation and finding the positive defined symmetric solution, the numerical feedback matrix K k (see Appendix C) that stabilizes the system is obtained. Let: Q = diag 20 20 1 × 10 7 1 1 1 1 1 1 1 R = diag 50 50 50 5000 5000 .
The weight matrices Q and R were selected by observing the behavior of the system in numerical simulations. A higher weighting factor was given to the stabilization of the pendulum angle on the vertical axis. The goal is to obtain a fast stabilization process without reaching the input saturation of the motors.

Simulations
The Matlab-Simulink software was used to verify the performance of the controller, according to the diagram in Figure 4, with a simulation time of 4 s, implementing a disturbance w k that adds to the control signal u 1 and u 2 in 1 Volt during the period of 1.5 s to 2 s, under the initial conditions:

Real-Time Experimentation
Using the Matlab Simulink platform, the optimal detector-based control is implemented using the feedback gains calculated above. By using the Simulink Lego mindstorms EV3 library it is possible to access the sensors and generate the robot states from them, calculate the control input, and implement it to the motors. The position and speed signals obtained by the encoder and gyroscope, respectively, are conveniently conditioned using a low pass filter. The driver implementation is performed for a period of 50 s, using the diagram in Figure 7. As well as the disturbance:  In Figure 10a,b the control inputs to the right and left wheel motor are shown. In Figure 10c,d the control inputs of the second and third link motors are presented, having values between [−2.5, 1] V and ±1 V . It is important to mention that, as can be verified, the control signals for the motors are within the operating range ±7.6 V. That is, there is no saturation. The differences between simulated and experimental responses may be mainly due to un-modeled dynamics, sensor, and actuator noises. Nonetheless, in general, as can be appreciated, such differences are not significant for the achievement of the main goal of the controller, that is, to keep the system in balance. In fact, from Figure 10, it is interesting to observe the ability of the control signal to compensate for the deleterious effect of noises, disturbances, and un-modeled dynamics. Thus, it can be considered that the experimental performance of the controller is good, particularly considering the difficulty of the stabilization problem. Figure 11 shows the robot's behavior during the experiment, maintaining a tilt angle close to zero with respect to the vertical axis and remaining at the same point with respect to the horizontal axis throughout the time of the experiment. Appendix D describes the comparison with another control technique known as PD (Proportional-Derivative).

Conclusions
The proposed inverted pendulum mobile robot is an excellent reference problem for studies of advanced control techniques, due to the complex task of keeping its structure in balance. We decided to develop an optimal disturbance detector-based controller for our mobile robot. The controller was implemented using the Matlab-Simulink algorithm via a Wi-Fi connection with the robot. Stabilization in the vertical position of the robot was successfully achieved. The oscillations that occurred when there were no disturbances were approximately ±0.017 rad, measured by the gyroscope coupled to the first link. When a slight force is applied contrary to the movement of the robot (disturbance), the oscillations that occurred were ±0.035 rad with ±5 V requirement for the two-wheel motors, while the behavior of links 2 and 3 presented values between [0, 0.5] rad and [0, −0.05] rad with a requirement of [1, −2.5] V and ±1 V.
For future work, an extension of the current controller will be used to cope with the tracking trajectory problem. Likewise, the Coefficient of Friction between the robot body and motors, as well as the Coefficient of Friction between the robot wheels and bearing surface will be studied. Besides, the uncertainty associated with some robot parameters, and a variable load in the last link could be considered. Finally, the problem of ascending and descending ramps will be addressed. Funding: This work was supported by CONACYT (Consejo Nacional de Ciencia y Tecnología México), and by COFAA (Comisión de Operación y Fomento de Actividades Académicas).

Conflicts of Interest:
The authors declare no conflict of interest.

Appendix A. Control Systems
For a discrete linear time-invariant system, the state equation and the output equation are written as [27,28]: where x k is the state vector n × 1, u k is the control signal m × 1, y k is the output vector p × 1, A is the state matrix n × n, B is the input matrix n × m, and C is the output matrix p × n. The (A, B, C) system represented by Equation (A1), is completely controllable if and only if the controllability matrix M C = B AB · · · A n−1 B has rank n, and it is completely observable if and only if the observability matrix M O = C CA · · · CA n−1 T has rank n.
If the system (A, B, C) is completely controllable [29,30], then there exists a feedback gain matrix K of the control law u k = −Kx k . Substituting the control law u in the first system equation (A, B, C), the closed-loop system matrix (A − BK) is obtained, which is stable if its eigenvalues λ i are all inside the unit circle of the complex plane, that is, |λ i | < 1 for i = 1, . . . , n. Equivalently, we could say that a discrete-time linear system is asymptotically stable if and only if all the eigenvalues of its corresponding state matrix are inside the unit circle [30]. If the system (A, B, C) is completely observable, then the state observer is given by the equation: where φ is the observer gain matrix n × p. Let e k =x k − x k , then the error dynamics of the system is: If all the eigenvalues of the (A − φC) matrix are stable then the observer (A2) is stable and lim k→∞ e k = 0.
When not all state variables are available for feedback, then u control law feeds the estimated states, that is, u = −Kx.

Appendix D. Optimal Controller Based on Disturbance Detector vs. PD Controller
To test the performance of the robust detector based optimal controller and the PD controller, a disturbance signal of 1 V is added in the input u 1 and u 2 in t = 5. This signal is applied only during 2 s. According to Figure A1, it can be appreciated how the optimal controller can significantly reduce the negative effect of the disturbance. However, when the PD controller is used, important deviations from the equilibrium are presented. For example, for the case of the wheels displacements δ r and δ l , the deviations from the equilibrium reach 2 cm and 1 cm, respectively, during the presence of the disturbance. Likewise, the deviations for the angular positions θ 1 , θ 2 , and θ 3 are 0.7 rad, −0.65 rad, and −1.47 rad, respectively. In contrast, the deviations are barely perceptible if the optimal controller is used. For the right and left wheel speeds, that is,δ r andδ l , the deviations reach ±14 rad/s during the disturbance when the PD controller is utilized. Nevertheless, the deviations only reach ±4 rad/s using the optimal controller. Finally, with the PD controller, for angular speedsθ 1 ,θ 2 , andθ 3 , the maximum deviations are ±1.1 rad/s, ±3 rad/s and ±14 rad/s, respectively. With the optimal controller, the effect of the disturbance is practically negligible for all the aforementioned angular speeds.

Abbreviations
The following abbreviations are used in this manuscript: