1 Introduction

Inverted pendulum on cart is widely used in many nonlinear control applications and testing several control algorithms due to its nonlinear and unstable dynamics. The system consists of a rigid pendulum mounted on a movable cart, and the aim is to stabilize all the three pendulums at vertically upright position [1]. Increasing the number of pendulums makes the dynamics of the system all the more complex and challenging [2]. The system consists of three pendulums hinged together and capable of rotating in vertical plane. Triple inverted pendulum system can be modeled as a human standing on one leg. Due to its inherent multivariability and instability, these systems are widely used for simulating performances and validation of various control techniques [3]. It has been a keen source of interest for the researchers in the past few decades. Medrano-cerda [4] designed a robust controller for control of double and triple inverted pendulum system. A DC motor was mounted on the upper and middle hinge to balance double and triple inverted pendulums, respectively. A state feedback controller was utilized, and system stability was evaluated via Nyquist plots.

A control technique which combined different control methods like stipulations, optimal control combined with knowledge-based control was proposed by Ruisen and Liang [5]. The results were obtained using nonlinear programming technique combining with experts experience for the proposed system. A swing-up control of three-link inverted pendulum was proposed by Gluck et al. [6]. The controller was designed combining a nonlinear feedforward controller with an optimal feedback controller. Real-time experiments were performed for successful implementation of the proposed system. Ananyevskiy and Anokhin [7] considered control of multi-link inverted pendulum having a fixed suspension. A control torque was applied to the first link of proposed system, and a control feedback law was developed for steering of the pendulums in equilibrium position. Prasad et al. [8] considered a Linear quadratic regulator (LQR) and PID techniques for stabilization of one link inverted pendulum system. State-space model of the system was developed, and simulations were performed using both with and without disturbance input.

Zhang et al. [9] proposed control of triple inverted pendulum via Genetic algorithm (GA)-PID Neural network (PIDNN). A nonlinear model of the system was developed which combines the merits of both GA and PIDNN control. Simulations showed that GA technique was better compared to PIDNN. Anan’evskii [10] obtained control of three-link inverted pendulum system by applying torques at the ball joints. The system has got around eight different equilibrium positions, and a control feedback module was developed to bring the system in equilibrium. In a study by Huang et al. [11], Swinging motion of three-link inverted pendulum was recorded via CCD camera and motion was further optimized with the help of Harris algorithm. The author effectively utilized the motion vision technique for stabilizing the complete system. Stabilization of triple inverted pendulum in vertical position through parametric excitation of the support has been demonstrated by Arkhipora [12]. The author applied multiple scale method and Floquet theory for controlling the system at different frequency ranges.

In this study, closed-loop feedback control strategies have been adopted for solving nonlinearity associated with the problem of balancing triple-stage inverted pendulum system at upward unstable position. This inherent unstable position gives rise to nonlinearity which needs to be linearized. The study considers a feedback linearization to compensate the nonlinearities associated with the system. A nonlinear model of the system has been derived using Newton’s second law. The transient response of the system is controlled using PID controller which is further used for training of ANFIS and neural controllers. Finally, the study compares the results of the study to results of an ANFIS controller developed by Jun-wei et al. [21]. It has been clearly observed from the results that the settling time has been significantly improved using PID controller, whereas there is still a scope for improving the results of ANFIS and neural controller.

2 Mathematical Model of Triple-Stage Inverted Pendulum

The generalized equations of motion for the system were developed using a study by Eltohamy and Kuo [13]. These equations were further used for developing a Simulink model of proposed system. The equations of motion for the system were derived considering free body diagram analysis of individual sub-systems. The final nonlinear differential equations for the individual sub-systems are as follows.

2.1 Equations of Motion for Cart

The free body diagram of cart sub-system highlighting all the forces acting on it is illustrated in Fig. 1. In the figure, \( N_{1} \) and \( P_{1} \) represent the interaction forces between bottom pendulum and cart acting along horizontal and vertical directions, respectively. In the figure b, \( \dot{x} \) represents frictional force acting between cart and surface during motion.

Fig. 1
figure 1

Free body diagram of cart sub-system

Summing forces acting on the cart in horizontal direction gives the following equation of motion,

$$ \ddot{x} = \frac{1}{M}\left( {F - N_{1} - b\dot{x}} \right) $$
(1)

In the above equation, \( \dot{x} \) and \( \ddot{x} \) denote velocity and linear acceleration of the cart, respectively.

2.2 Equations of Motion for Bottom Pendulum

The free body diagram of bottom pendulum highlighting all the forces acting on it is highlighted in Fig. 2. In the figure, \( N_{2} \) and \( P_{2} \) represent the interface forces amid lower and middle pendulum acting along horizontal and vertical directions, respectively. In the figure, \( m_{1} g \) represents the gravitational force acting on the system due to its weight.

Fig. 2
figure 2

Free body diagram of bottom pendulum

An expression for angular acceleration (\( \ddot{\theta }_{1} \)) of the bottom pendulum is given below,

$$ \ddot{\theta }_{1} = \frac{1}{{I_{1} }}\left( {N_{1} l_{1} \cos \theta_{1} + P_{1} l_{1} \sin \theta_{1} - b_{1} \dot{\theta }_{1} + N_{2} l_{1} \cos \theta_{1} + P_{2} l_{1} \sin \theta_{1} } \right) $$
(2)

where \( \dot{\theta }_{1} \) and \( I_{1} \) are angular velocity and moment of inertia for bottom pendulum.

2.3 Equation’s of Motion for Middle Pendulum

The free body diagram of middle pendulum highlighting all the forces acting on it is shown in Fig. 3. In the figure, \( N_{3} \) and \( P_{3} \) represent interaction forces between middle and top pendulum acting along horizontal and vertical directions, respectively. The gravitational force acting on the system due to its weight is given by \( m_{2} g \), where g is acceleration due to gravity.

Fig. 3
figure 3

Free body diagram of middle pendulum

An expression for angular acceleration (\( \ddot{\theta }_{2} \)) of the middle pendulum is given below,

$$ \ddot{\theta }_{2} = \frac{1}{{I_{2} }}\left( {N_{2} l_{2} \cos \theta_{2} + P_{2} l_{2} \sin \theta_{2} - b_{2} \dot{\theta }_{2} + N_{3} l_{2} \cos \theta_{2} + P_{3} l_{2} \sin \theta_{2} } \right) $$
(3)

where \( \dot{\theta }_{2} \) and \( I_{2} \) are angular velocity and moment of inertia for middle pendulum.

2.4 Equations of Motion for Top Pendulum

The free body diagram of top pendulum highlighting all the forces acting on it is illustrated in Fig. 4. In the figure, \( N_{3} \) and \( P_{3} \) represent interaction forces between middle and top pendulum acting along horizontal and vertical directions, respectively. The gravitational force acting on the system due to its weight is given by \( m_{3} g \).

Fig. 4
figure 4

Free body diagram of top pendulum

An expression for angular acceleration (\( \ddot{\theta }_{3} \)) of the top pendulum is given below,

$$ \ddot{\theta }_{3} = \frac{1}{{I_{3} }}\left( {N_{3} l_{3} \cos \theta_{3} + P_{3} l_{3} \sin \theta_{3} - b_{3} \dot{\theta }_{3} } \right) $$
(4)

where \( \dot{\theta }_{3} \) and \( I_{3} \) are angular velocity and moment of inertia for top pendulum.

Equations (1)–(4) were utilized to create a Simulink of above system as given in Fig. 5.

Fig. 5
figure 5

Simulink of three-stage cart and pole system

3 PID Control of Triple-Stage Inverted Pendulum

A proportional–integral–derivative (PID) controller is a closed-loop feedback control mechanism widely used for various control applications [14]. The controller computes an error signal which is the difference between the desired output and measured value. The error signal is computed until the error becomes zero or minimal value is obtained. The reduction of error is performed with the help of proportional, integral, and derivative gains [15]. All the three gains were added together to calculate the output of PID controller as shown with the help of equation [16]. The gains of PID controller for triple-stage cart and pendulum have been tuned using trial and error method. The tuning procedure for gains is continued until suitable responses were obtained. The PID gains obtained after tuning diverse sub-systems of three-stage cart and pendulum system are given in Table 1. It is clear from the table that negative gains were obtained for differential gain constant, whereas proportional gain values were kept to zero for all the controllers.

Table 1 PID gains obtained after tuning for sub-systems

4 Neural Control of Triple-Stage Inverted Pendulum

Neural networks are artificial learning tools based on human ability of learning. These networks are designed on the basis of learning ability of neurons of human brain. In this paper, a PID-based neural controller is designed for control of triple-link inverted pendulum. A total of 147 data samples were stored from results of PID controller and applied for training of neural controller. These data samples were further at random divided into training, testing, and validation samples in the ratio 70:15:15 in order to solve the problem of overfitting [17]. The sample size of randomly divided data samples is given in Table 2.

Table 2 Random division of data samples for training of neural controllers

The neural design was constructed considering 20 neurons in the hidden layer and single neuron in output layer as shown in Fig. 6. Levenberg–Marquardt algorithm was used for training of neural controllers. The tuning was done till a regression rate of unity which was achieved for the entire samples. The actual MSE and regression values attained for each controller is given in Table 3.

Fig. 6
figure 6

Neural network architecture considered for triple-link cart and pendulum

Table 3 MSE and regression values obtained for different controllers

5 ANFIS Control of Triple-Stage Inverted Pendulum

The term ‘ANFIS’ stands for adaptive neuro-fuzzy inference systems which belongs to a class of adaptive networks and is widely used for various learning and training operations [18]. These systems combine the features of both fuzzy logic controllers and artificial neural networks. ANFIS has the learning ability of artificial neural networks and logic-based reasoning of fuzzy controllers which makes them powerful learning tool [19]. The system consists of a set of nodes whose weights are adjusted during the learning process. A schematic view of ANFIS architecture is shown in Fig. 7 [21]. The results obtained from PID controller were utilized for teaching of ANFIS controller. This section further highlights the consequence of type of memberships on learning of both linear- and constant-type membership functions. Five different shape memberships, namely triangular, trapezoidal, gbell, gauss, and gauss2mf were considered and varied from 3 to 8 in number. The errors achieved incorporating these memberships for bottom pendulum controller are depicted in Table 4 which proved that the minimum training error was given by triangular memberships of constant type.

Fig. 7
figure 7

Cart position response using different controllers

Table 4 Training errors obtained for bottom pendulum controller

The simulation responses obtained for different sub-systems of triple inverted pendulum using above-mentioned techniques are revealed via following figures and tables. The time considered for simulation was 6 s.

6 Simulation Results

See Figs. 7, 8, 9, 10, 11, 12, and 13.

Fig. 8
figure 8

Bottom pendulum angle response using different controllers

Fig. 9
figure 9

Bottom pendulum angular velocity response using different controllers

Fig. 10
figure 10

Middle pendulum angle response using different controllers

Fig. 11
figure 11

Middle pendulum angular velocity response using different controllers

Fig. 12
figure 12

Top pendulum angle response using different controllers

Fig. 13
figure 13

Top pendulum angular velocity response using different controllers

  1. (a)

    Simulation response: cart position

  2. (b)

    Simulation response: bottom pendulum angle

  3. (c)

    Simulation response: bottom pendulum angular velocity

  4. (d)

    Simulation response: middle pendulum angle

  5. (e)

    Simulation response: middle pendulum angular velocity

  6. (f)

    Simulation responses for top pendulum angle

  7. (g)

    Simulation response: top pendulum angular velocity.

The simulation results obtained for sub-systems by Jun-wei et al. [21] are shown in Table 5.

Table 5 Simulation results obtained using ANFIS controller in study by Jun-wei et al.

The simulation results obtained for sub-systems of three-stage cart and pole system by means of various techniques are given in Table 6.

Table 6 Simulation results of three-link cart and pendulum system using different controllers

7 Conclusion

This chapter considered different controllers based on results of fuzzy and PID control techniques for control of three-link cart and pendulum system. The outcomes of fuzzy controller were adopted to teach and train ANFIS, whereas the results of PID controller were used for training of both ANFIS and neural controllers. The results clearly proved superior response of PID-based control compared to fuzzy-based control. The fuzzy control rules can be further tuned to get better results. The simulation results for fuzzy-based ANFIS controller can be further improved by reducing the value of error tolerances either by increasing the total memberships or by changing its shape. The time required to stabilize complete system using ANFIS and neural control was 3.4 s and 4.0 s, respectively. The maximum overshoot responses for both the controllers were comparatively similar as can be inferred from the results. It is also conceived from the responses that both fuzzy and PID-based control showed excellent response toward steady-state error. The simulation results obtained for triple inverted pendulum system using PID-based ANFIS, and neural controllers were further compared to the results of ANFIS controller developed by Jun-wei et al. [20]. The comparison of results showed that the settling time taken by cart and pendulum sub-systems were significantly reduced using PID-based ANFIS and neural controllers. The maximum improvement in settling time of top, middle, bottom pendulums and cart position was obtained using PID controller and was 72%, 72%, 70% and 70%, respectively.