Stabilising a cart inverted pendulum with an augmented PID control scheme

A cart inverted pendulum is an under actuated system that highly unstable and nonlinear. Therefore, it makes a good problem example which attracts control engineers to validate the developed control algorithms. In this paper, an augmented PID control algorithm is proposed to stabilise a cart inverted pendulum at the desired state. The derivation of a mathematical model of the cart inverted pendulum using Lagrange’s equation is discussed in detail. The system dynamics is illustrated to understand better the behaviour of the system. A simulation program has been developed to verify the performance of the proposed control algorithm. The system dynamic behaviours with respect to the variation of the controller parameters are analysed and discussed. Controllers parameters are expressed into two PID gain sets which associated with 2 dynamic states: the cart position (xx) and the pendulum angle (θθ). It can be concluded from the simulation result that the proposed control algorithm can perform well where acceptable steady errors can be achieved. The best response from the cart inverted pendulum system has been obtained with the value of kkPPxx 190, kkDDxx 50, kkIIxx 5, kkPPθθ 140, kkDDθθ 5, and kkIIθθ 25.


Introduction
The Cart Inverted Pendulum is an example of a nonlinear [1], unstable [2] and under actuated system [3].The nonlinear system means the system has many possible responses although the same input is given.A normal pendulum or a pendulum that facing downwards is a stable system, but an inverted pendulum is an unstable system.In the cart-inverted pendulum, the output variables are expressed by its position of the cart and the rod angle, and a horizontal force [4] expresses the input variable.The cart-inverted pendulum is a system that usually used for testing many control algorithms [5].There are some control algorithms that can be used for stabilising a cart-inverted pendulum such as Linear Quadratic Regulator (LQR) [6], neural network [7], genetic algorithm [8], fuzzy control [9], and PID [10] which have been studied by many researchers.The studies about the stability of a cart-inverted pendulum is very useful for developing real world application systems, for instances: a segway, an earthquake resistant building design, a human walking, etc.
An augmented PID control scheme is proposed for stabilising a cart inverted pendulum in this work.The system modelling is discussed in Section 2. In this section, the mathematical model for cart and pendulum is derived by Lagrange Equation.The open and closed loop control are discussed in Section 3. The modelling of cart inverted pendulum with PID is derived in Section 4.
The simulation results are shown in Section 5. Finally, Section 6 presents the conclusion of the work.

Lagrange's equation
A complex system dynamic can be described in efficient way using Lagrange's equation.The complicated vector analysis that needed for describing forces applied on a mechanical system can be reduced by Langrange's equation.
A set of generalised coordinate  = { 1 , … ,   , … ,   } is a representation of the fundamental principle of Lagrange's equation, where   is an independent degree of freedom of the system which combines the constraints unique to the system, i.e., the communication between parts of the system.The total generalised coordinates is do noted by .
The Lagrange's equation is expressed by the system's kinetic  and potential energy  which described as follows Where the function of kinetic energy in terms of the generalised coordinate  and its derivative ̇.The function of potential energy is described in terms of only the generalised coordinate .
The equations of desired motion are derived using Where   shows the external force that applied in term of   coordinate.The development of the Lagrange's equation of the cart-inverted pendulum is presented in the following section.In Fig. 1, the motion of the cart is only in  ̂ direction, thus the total kinetic energy of the cart can be expressed as

Lagrange's equation of the system
The motion of pendulum are expressed in  ̂ and  ̂ directions, hence, the total kinetic energy can be formulated as Fig. 1 shows that Where  is the position of the cart,   is the projected pendulum position on the horizontal axis, and ℎ is the projected pendulum position on the vertical axis.The first derivatives of Eq. ( 5) and Eq. ( 6), are determined as Hence, the kinetic energy of pendulum in Eq. ( 4) can be rewritten as Combining the kinetic energy formulations in Eq. ( 10) and Eq. ( 3), one can verify that the total kinetic energy of the system can be expressed as The pendulum mass  is only the potential energy involved in the system  = ℎ (13) Then, the Lagrangian equation Eq. ( 15) can be fully determined using Eq. ( 12) and Eq. ( 14), as follows The angle of the pendulum with respect to the  ̂ direction and the displacement of the cart in the  ̂ direction with respect to the origin specifically defined the motion of the inverted pendulum on a cart.Therefore, the system only has two degrees of freedom represented by  and , the system dynamics must be expressed in terms of  and .Thus,  and  can be selected as the elements of the generalised coordinate vector .The Lagrange's equation Eq. ( 2) can be expressed using this selection for each generalised coordinate: The external forces that applied to the system is assumed that there is no external torque applied to the pendulum and the external force only applied on a cart in  ̂ direction.Deriving for each term in the differential equation in Eq. ( 16) and Eq.(17), we have  It can be seen that Eq. ( 24) and Eq. ( 25) have terms () and ().Hence, terms  2 and  ̇ can be neglected.Stabilising the pendulum vertically with small deflection of  is the aim of the controller that will be designed.It is assumed that the pendulum will be initialised near to the reference angle (upright), thus it can be approximated that sin  ≈  and cos  ≈ 1.Using assumptions that mentioned before, the linearised Lagrange's equation can be derived as follows

Open and closed loop control
In a cart inverted pendulum system, the motion dynamic of the cart can be controlled using an external force or torque.The motions dynamic state is measured with position, velocity, and possibly acceleration sensors.In the case of a cart inverted pendulum system, two motions dynamic states are measured: the motion of the cart and the motion of the pendulum.These two motion states are coupled.In order, to stabilise the pendulum at the equilibrium position, the desired external force applied to the system should be computed.We denoted by .The position, the velocity and the acceleration of the system are denoted by , ̇, ̈, respectively.The motion dynamics is then described by:   = (  )  ̈+ (  ,   ̇) + (  ) Where the subscripts c in   means a controlled force and d in   expresses the desired states.The desired position   can be reached by giving the external force   .The external force that described in Eq.( 28) is an  In the open loop system, there is no mechanism to compensate any possible error.A feedback control algorithm is needed to resolve this problem.
Linear control technique is a simple technique for controlling robots.Linear control technique is a method based on linearization of the system model equations with a combination of proportional, integral, derivative gain, or any combination of them.The control law for a proportional control () is: Where   is the desired control command and  is an error.The control law for a proportional integral control () is: At this point, the differential equation of the pendulum of cart inverted pendulum motion have been developed.

Simulation and result
In order to simulate the linear control technique PID, the cart inverted pendulum parameters defined in Table 1.

No Parameter
Value Units The simulation is done by using the differential equation of pendulum and cart from cart inverted pendulum system which has been obtained.The simulation is done by augmented PID control scheme.The selection of controller parameters   ,   and   are by trial and error.Finally, the best response from cart inverted pendulum system has been obtained with the value of    190,    50,    5,    140,    5, and    25.It can be seen in Fig. 4 that the best response are shown by the cart inverted pendulum system with the pendulum response reaches the desired position within 2 seconds and the cart response reaches the desired position in less than 4 seconds.Furthermore, the simulation is done by changing the parameter of the PID controller.This is done to determine the pendulum and cart response to the system in case of PID parameter change.The first simulation is done by changing    .   20 and 50 applied to the simulation.From Fig. 5, it can be concluded that the greater    make the system responses can achieve the desired position quickly.If    is too small, the system becomes unstable.   changes are made with    10 and    140.The results from simulations are shown in Fig. 6.It is known that small    can stabilize the system, but higher    can make the system unstable.The next step is change the value of    .The small    does not affect system response at all.But if the    that given to the system is too large, makes the system unstable.Fig. 7 shows the pendulum and cart response on a cart inverted pendulum system with a value of    0 and    50.The next simulation is replacing the parameter PID on .The first thing to do is replacing the    .Fig. 8 shows the    10 and 600.From Fig. 8, it can be seen that the change in    does not significantly affect the system response.The    changes are done with 0 and 20.It can be seen in Fig. 9 that the small    does not affect the system response.But if the given    is slightly higher, the system becomes unstable.The last one is the change of    with the gain 5 and 50.From Fig. 10, it can be seen that the higher value of the    makes the system reach the desired point faster.It can be concluded that the selection of PID parameters on    ,    ,    ,    ,    , and    greatly affects the system response.

Conclusions
The mathematical model of a cart inverted pendulum has been successfully conducted using Lagrange equation.The control command for cart and pendulum in a cart inverted pendulum successfully made the system reach the desired point.Linear control technique is a simple control technique based on the linearisations of the equation of motion.The parameter of proportional gain   , the integral gain   , and derivative gain   have been successfully selected to satisfy the system stability conditions.

Fig. 1 .
Fig. 1.The inverted pendulum on a cart system.

Fig. 3
Fig. 3 illustrate the feedback control algoritm with a new motion dynamics that described by: An integral controller is usually used with a proportional controller.The integral controller usually MATEC Web of Conferences 197, 11013 (2018) https://doi.org/10.1051/matecconf/201819711013AASEC 2018 The second differential equation of degree pendulum expressed as  ̈= −    −   ̇−   ∫   − ̈−

Fig. 5 .
Fig. 5. Pendulum angle and cart response trajectories with variation of    .

Fig. 6
Fig. 6 Pendulum angle and cart response trajectories with variation of    .

Fig. 7 .
Fig. 7. Pendulum angle and cart response trajectories with variation of    .

Fig. 8 .
Fig. 8. Pendulum angle and cart response trajectories with variation of    .

Fig. 9 .
Fig. 9. Pendulum angle and cart response trajectories with variation of    .

Fig. 10 .
Fig. 10.Pendulum angle and cart response trajectories with variation of    .

Table 1 .
The Cart Inverted Pendulum System Parameter.