Optimized Hierarchical Sliding Mode Control for the Swing-Up and Stabilization of a Rotary Inverted Pendulum

: This paper presents a study on controlling a rotary inverted pendulum (RIP) system using a hierarchical sliding mode control (HSMC) approach. The objective is to swing up and stabilize the pendulum at a desired position. The proposed HSMC controller addresses the underactuation challenge through a hierarchical structure of sliding surfaces. The particle swarm optimization (PSO) algorithm is used to optimize the controller parameters. Simulations were performed to evaluate the performance of the HSMC controller at different initial pendulum angles, demonstrating its effectiveness in achieving swing-up and stabilization. The integration of the PSO algorithm enhances the controller’s adaptability and robustness, emphasizing the benefits of combining optimization algorithms with controller parameter tuning for underactuated systems like the RIP


Introduction
Inverted pendulum systems have long captivated researchers and engineers in the field of control theory due to their inherent complexity and practical significance.These systems serve as valuable testbeds for developing and evaluating control strategies, offering insights into the fundamental challenges of stabilizing unstable systems.The dynamics of inverted pendulums make them particularly intriguing, as they require continuous adjustments to counteract the effects of gravity and external disturbances.The concept of an inverted pendulum can be visualized as a pendulum that is placed in an upsidedown position, with its pivot point above the center of mass.This configuration inherently leads to an inherently unstable system, as even the slightest disturbance can cause the pendulum to fall and diverge from its upright position.Consequently, controlling the inverted pendulum becomes a challenging task that necessitates sophisticated control algorithms and strategies [1,2].
Control methods for rotary inverted pendulum (RIP) systems have been extensively studied to address their inherent instability.Conventional methods such as proportionalintegral-derivative (PID) control [3][4][5] offer simplicity but struggle with nonlinear dynamics and uncertainties, leading to limited stability and robustness in controlling RIP systems.Sliding mode control (SMC) [6][7][8][9][10] ensures robustness by driving the system onto a predefined sliding surface, effectively minimizing disturbances and uncertainties.However, SMC can introduce chattering phenomena, which can degrade control performance and affect system dynamics.Fuzzy logic control (FLC) incorporates linguistic rules and fuzzy sets to handle nonlinearities and uncertainties, providing a flexible approach to RIP control [11,12].However, FLC requires an extensive rule base and parameter tuning, which can be timeconsuming and complex.While the above control approaches have been investigated in terms of the performance, robustness, and stability of RIP systems, their drawbacks should be considered when selecting an appropriate control strategy for practical applications.In addition to the mentioned drawbacks, the above studies either did not specifically present the method for adjusting controller parameters or did not select optimal parameters.
To address the limitations and disadvantages of the preceding controllers, the selection of the hierarchical sliding mode control (HSMC) approach emerges as a promising remedy.The effectiveness of HSMC in controlling underactuated systems has been extensively demonstrated in numerous studies [13][14][15][16].Hierarchical sliding mode control is an advanced control method that combines the benefits of sliding mode control with a hierarchical control structure.Sliding mode control is a robust control technique that aims to drive the system's states onto a predefined sliding surface, minimizing the effects of disturbances and uncertainties.This is achieved by designing a discontinuous control law that forces the system's trajectory to track the sliding surface.However, in underactuated systems, where the number of control inputs is less than its degrees of freedom, sliding mode control alone may not be sufficient to achieve satisfactory control performance.HSMC addresses this limitation by introducing a hierarchical control structure.The control structure consists of two levels of the controller: the upper level and the lower level.The upper-level controller is responsible for generating the desired sliding surface and supervising the lower-level controller.It ensures that the lower-level controller tracks the desired sliding surface, effectively controlling the system's states.The lower-level controller, also known as the sliding mode controller, implements the discontinuous control law to drive the system onto the sliding surface.This paper aims to leverage the advantages of the HSMC controller to address two critical tasks of the pendulum system: swing-up and stabilization.By employing the HSMC controller in this research, the objective is to showcase its effectiveness in both swing-up and stabilization tasks, ultimately providing insights into the applicability of the HSMC approach for controlling complex and underactuated systems like the pendulum.
Particle swarm optimization (PSO) is a powerful optimization algorithm inspired by the social behavior of birds and fish.It involves a population of particles that move through the search space to find the optimal solution based on the best-performing particles.This algorithm has found applications in various control methods, demonstrating its versatility.In the realm of control systems, PSO has been successfully integrated into methodologies such as fuzzy logic [17,18], PID [19,20], and more.In this study, we leverage the capabilities of PSO by incorporating it into the parameter-tuning process of hierarchical sliding mode control.This integration aims to optimize the HSMC controller's parameters, enhancing its overall performance.The decision to employ PSO in this research underscores the importance of intelligent optimization techniques in improving control systems.It emphasizes PSO's potential as a valuable tool in the parameter optimization process, offering efficiency and effectiveness in achieving optimal controller configurations.
This paper makes the following contributions: • Our research introduces a pioneering hierarchical sliding mode controller that streamlines control efforts and outperforms dual-controller methods in both the swing-up and stability control of the rotary inverted pendulum.

•
In addition, our paper leverages particle swarm optimization (PSO) to fine-tune the controller's parameters, resulting in enhanced control performance for the rotary inverted pendulum.

Hierarchical Sliding Mode Control
Having scrutinized the structure and merits of the HSMC controller in the Introduction, this section delves into the controller design.Consider a single-input multi-output system comprising n subsystems, each representing a specific component or aspect of the overall system.By dividing the system into these subsystems, we can derive the state-space equations that describe the dynamics of the entire system: where {x 1 , x 2 , . . ., x 2n } are state variables; F i (x) and G i (x), with i = {1, 2, . . ., n}, are nonlinear functions; and the control input signal is represented by u.Considering the state space associated with the i th subsystem, the sliding surface of this subsystem can be defined as follows: where λ i is an arbitrary positive constant.The derivation of the equivalent control signal for the i th subsystem, responsible for maintaining the subsystem on its designated sliding surface, can be achieved by setting ṡi = 0: and then Figure 1 illustrates the hierarchical structure of the sliding surfaces, providing a visual representation of the stepwise construction process [21].Consider the ith-layer sliding surface with a constant γ i−1 (i = 1, 2, . . ., n) and γ 0 = S 0 = 0: The determination of the control signal for the ith-layer sliding surface involves a combination of the control signal from the previous layer's sliding surface and two components: the equivalent control signal (u eq i ) and the switching control signal (u sw i ): where u 0 = 0.The calculation of the control signal u i in the aforementioned equation can be performed utilizing Lyapunov stability theory as a foundation.Let us consider the Lyapunov function associated with the sliding surface of the ith layer, denoted by The time derivative of the above function is where γ p = 1 if p = i.The following equation is derived by substituting (3), ( 4), and ( 6) into (8): An exponential reaching law with the arbitrary positive constants k i and η i is chosen and defined as follows: The ith layer has the following switching control law: The control signal for the entire system can be calculated when i = n [21]: Figure 1.Hierarchical structure of sliding surfaces.
Theorem 1.For the underactuated system represented by Equation ( 1), the sliding surface S i of the ith layer, as defined in (5), is asymptotically stable, with the control law determined by the following expression: Proof.By selecting the Lyapunov function stated in Equation ( 7), we can compute its time derivative and subsequently apply the control signal defined in Equation ( 13): Integrating both sides of the aforementioned equation, we obtain Then, Based on Barbalat's lemma, we have Then, the ith-layer sliding surface has been proven to be asymptotically stable.
Theorem 2. For the underactuated system represented by Equation ( 1), the ith-subsystem sliding surface s i , as defined in (2), is asymptotically stable, with the control law determined by (13).
Proof.From Theorem 1, the ith-layer sliding surface S i → 0 when t → ∞.Then, The sliding surface s i of the ith subsystem is demonstrated to be asymptotically stable.

Particle Swarm Optimization
Particle swarm optimization (PSO) is an optimization strategy derived from the foraging behavior of living organisms, i.e., fish schools and bird flocks, initially proposed by J.Kennedy and R.Eberhart [22].This method simulates a swarm of particles, where the particle's position stands for a potential solution within a multidimensional search space.By iteratively adjusting each member's positions and velocities in response to both their individual experiences and the best solution encountered by the swarm of n particles, PSO efficiently explores the solution space to locate optimal or near-optimal solutions.The updating formula for the velocity and position of the ith particle (i = 1, 2, . . ., n) after the k th iteration is described as follows: where w is the inertia weight, while the terms r 1 and r 2 refer to uniformly distributed random variables in the range of (0, 1).−−→ pbest and −−→ gbest are the best-known solution of each individual (personal) and the overall best solution achieved within the entire swarm (global), respectively.The relative influences of the personal and global optimal positions on the movement of individual particles are governed by c 1 and c 2 .
The velocity in the next iteration consists of three parts.The first component serves as the inertial part, driving the agent to continue following the previous direction.The second element is considered the cognitive component, directing the particles toward their individual optimal positions.The third component is considered the social factor, representing the collective effect of globally optimal solutions on individuals searching.This social component attracts individuals toward the swarm's optimal solution.Afterward, the agent's position in the next iteration is computed as in (20).
The personal best position −−→ pbest is determined by evaluating the fitness function for a particle's position.The fitness function is problem-specific, based on whether the problem is a maximization or minimization problem.For a maximization problem, a higher fitness value indicates a better solution, so the personal best is updated if the new fitness is greater than the current value.In contrast, within the context of minimization problems, a lower fitness value signifies a superior solution.For each iteration, after evaluating the fitness function for all particles, if there exists a position that yields the best-known fitness value among the entire population, that position will be updated as the new global best position −−→ gbest.
The PSO algorithm's effective management of exploration and exploitation is a crucial concern.Typically, in the initial search stages, utilizing a substantial inertia weight results in a comprehensive exploration of the search space.Subsequently, by gradually reducing the inertia weight, the algorithm is able to converge toward more ideal solutions in the final stages of the search process.The fundamental aim of this adjustment is to mitigate premature convergence during the initial search phases and facilitate the algorithm's convergence toward the global optimal solution during the later stages.According to [23], the gradual reduction in inertia weight in each iteration is defined as where w max and w min represent the initial and final values of the inertia weight, respectively; iter is the current iteration number; and iter max is the maximum number of iterations specified for the algorithm.In this paper, the parameters w max and w min are set to 0.9 and 0.4, respectively, resulting in a wide exploration of the search space during the initial stages and a quick approach to the swarm's optimal solution in the later process.Building upon the general theories of PSO discussed earlier, this optimization algorithm is applied to determine the parameters for the proposed hierarchical sliding mode controller.The control design process reveals that numerous controller parameters require careful selection.Without the assistance of intelligent algorithms like PSO, it would be challenging to choose these parameters optimally based solely on experience.The specific parameters to be optimized using PSO will be detailed later in the article.

Application to Rotary Inverted Pendulum
To illustrate the application of the presented theories to a specific system, we utilize a rotary inverted pendulum, as depicted in Figure 2.This system is a classic example of a nonlinear dynamic system characterized by a single input and multiple outputs.Consider the mathematical model of the RIP [24] and its parameters shown in Table 1, where α is the deviation angle of the pendulum from verticality and θ is the position of the rotary arm: The state-space expression of the rotary inverted pendulum system is derived as follows: The sliding surfaces of these two subsystems can be defined as From ( 4) and ( 24), the equivalent control signals can be calculated as follows: With the presence of two subsystems in this RIP model, the hierarchical structure comprises two layers.The sliding surface of the last layer, as well as the sliding surface of the entire system, is given by where γ 1 is an arbitrary constant.The hierarchical sliding mode control law for the RIP can be inferred: By choosing the Lyapunov function and the reaching law Ṡ2 = −kS 2 − ηsgn(S 2 ), the control signal of the entire system can be determined according to ( 13) and ( 27): The stability of the sliding surfaces S 2 , S 1 , and s 2 has been guaranteed and proven through Theorems 1 and 2. From Equations ( 24) and (29), it can be observed that the performance of the system is determined by the selection of the parameters λ 1 , λ 2 , γ 1 , k, and η.In this context, the PSO algorithm will be employed to search for the optimal values of these parameters.To evaluate the potential solutions, the design fitness function employed is the integral absolute error (IAE) of the pendulum angle error, expressed as where α(t) is the actual signal of the pendulum angle at time t, α d (t) denotes the desired value of the signal, and J represents the final value of the fitness function.The IAE fitness function takes into account both the magnitude and duration of the error in the pendulum angle.It quantifies the cumulative absolute difference between the desired and actual angles over a specific time interval.Through the minimization of the fitness value, the control system's accuracy and stability can be improved, demonstrating superior performance in control.

Parameter-Tuning Process
In order to evaluate the performance of the proposed hierarchical sliding mode control approach applied to the rotary inverted pendulum system, extensive simulations were conducted via Matlab Simulink.The simulations aimed to analyze the behavior of the control system under various scenarios and assess its effectiveness in achieving the swingup and stabilization of the pendulum.
The parameters of the RIP system were selected, as indicated in Table 1.Furthermore, to demonstrate the efficacy of utilizing PSO to choose the parameters of the HSMC con-troller, a series of iterations were performed, and the results are presented in Table 2.These iterations serve as evidence of the effectiveness of PSO in optimizing the cost function via tuning the controller's parameters, contributing to improved control system performance and stability.The angle and angular velocity of the pendulum for each parameter set specified in Table 2 are visualized in the subsequent figures.In Figure 3a,b, the results of the initial iteration of PSO are presented.During this iteration, the parameters for the controller were randomly selected from the search space.The corresponding performance of the controller can be observed, indicating that with these randomly chosen parameters, the control system failed to swing up the pendulum and stabilize it at the desired position.In Figure 4a,b, the performance of the 10th iteration is displayed, revealing notable improvements in the angular response and angular velocity of the pendulum.The swing-up maneuver has been successfully accomplished, and the pendulum is observed to be stable.However, a small steady-state error of approximately 3 degrees is still present.Despite this minor deviation, the overall performance of the system has significantly improved compared to earlier iterations, demonstrating the efficiency of PSO in tuning parameters for the HSMC controller.
In the 15th iteration, the issue of steady-state error persisted without complete resolution.Nevertheless, an improvement in swing-up performance can be observed in Figure 5a compared to Figure 4a.The angular velocity depicted in Figure 5b exhibits a significant increase during the swing-up phase and gradually approaches zero as the pendulum stabilizes.This observation suggests that the controller is effectively driving the pendulum toward the desired position and achieving stability, although some steady-state error remains.Continued iterations and fine-tuning of the control parameters may be necessary to further mitigate the steady-state error and optimize the swing-up and stabilization process.In the 30th iteration, as illustrated in Figure 6a,b, the issues encountered in previous iterations were successfully resolved.Notably, the steady-state error was completely eliminated, and the swing-up and stabilization processes were noticeably faster compared to earlier iterations.The improved angular response resulted in a slightly higher angular velocity, as depicted in Figure 6b.Overall, with the control parameters obtained in the 30th iteration, the HSMC controller exhibited excellent performance in both swing-up and stability control tasks.These results demonstrate the effectiveness of the proposed approach in achieving the precise control and robust stabilization of the RIP system.

Simulation Cases and Evaluations
To validate the efficacy of the controller using the parameters obtained in the final iteration, a series of simulations were conducted with three scenarios, including changing the initial angle of the pendulum and adding an external disturbance, and the proposed controller was compared with other controllers.In the first scenario, the initial deflection angle of the pendulum was gradually changed from −30 degrees to −180 degrees.The outcomes displayed in Figures 7 and 8 not only confirm the effectiveness of the HSMC controller under varying initial angle conditions but also underscore the significance of the PSO algorithm in parameter selection.By employing PSO during the optimization process, the controller's parameters were fine-tuned to achieve optimal performance.As a result, the HSMC controller, equipped with the parameter set obtained from the last iteration, demonstrated remarkable performance in swiftly and accurately stabilizing the pendulum, irrespective of the initial angle.The correlation between the initial angle and the corresponding angular velocity showcased the controller's ability to adapt dynamically, leveraging the chosen parameters to expedite the pendulum's convergence to the desired position.This robust performance solidifies the effectiveness of the PSO-driven parameter selection approach in enhancing the control system's overall performance.To assess the robustness of the controller in the presence of external disturbances, let us consider a scenario where a white noise disturbance is added to the control signal.The characteristics, including the shape and magnitude of the disturbance, are depicted in Figure 9.
The responses of the pendulum angle, under both disturbed and undisturbed conditions, are illustrated in Figure 10.Starting with an initial angle of α = −60 degrees, the proposed controller adeptly brings the pendulum to its equilibrium position even in the presence of a disturbance.A closer examination of the graph's magnified section reveals minimal oscillations in the pendulum bar.While it is not feasible to entirely eliminate the influence of the disturbance, the pendulum's oscillation toward the equilibrium position is minimal, measuring only approximately 0.5 degrees.Consequently, the proposed controller demonstrates notable resistance to interference, establishing its viability for practical experimental applications.The congruence between the HSMC controller and the RIP system is further substantiated through a comparative analysis with other controllers operating under identical conditions.Specifically, two controllers chosen for this comparative study are the LQR controller and the conventional SMC controller, representing the linear and nonlinear controller categories, respectively.In the LQR approach [11], the control signal is computed using the following equation: where K is the control matrix.With the value of the matrix Q = diag(10, 1, 1, 1) and R = 1, the matrix K is determined: K = 40.34875.8822 −1.0000 −1.3263 The control signal of the SMC controller is given by [24] in which the controller parameters are selected as follows:  Upon comparison with two alternative controllers at the same initial angle of −45 degrees, the proposed controller distinctly exhibits a superior convergence time for the deviation angle.The LQR controller requires approximately 1 s to guide the pendulum to a stable state and over 2 s to completely stabilize it at 0 degrees.In contrast, the SMC controller yields a slightly swifter response, stabilizing the pendulum in about 1 s.Remarkably, the HSMC controller outshines both, accomplishing equilibrium in a mere 0.2 s, signifying a significantly faster convergence.Similar to the SMC controller, negligible steady-state error is observed when the pendulum bar attains a stable position.To validate the supremacy of the proposed controller in the face of disturbances, all three controllers underwent testing while the pendulum bar oscillated due to an external disturbance.
In this case, a white noise disturbance, similar to the one depicted in Figure 9, is introduced into the control signals.The deflection angles of the pendulum bar, as depicted in Figure 12, exhibit noticeable variations compared to the scenario without a disturbance.Specifically, the pendulum angle under the sliding mode controller displays the least fluctuation in the steady region, albeit with a relatively small steady-state error.In contrast, both the LQR and HSMC controllers exhibit slightly larger fluctuations in their responses.Notably, only the proposed controller manages to maintain the pendulum at around the 0-degree position, whereas the other two controllers still exhibit steady-state errors.The remarkable characteristic of the HSMC controller, its swift settling time, persists in this context.However, for a more nuanced evaluation of the responsiveness in the presence of a disturbance, the integral absolute error (IAE) for the aforementioned three responses is considered.The computed integral absolute error values in Table 3 corroborate the earlier analysis.The SMC controller exhibits the highest IAE value due to the extended rise time observed in its response.The LQR controller follows with the second-largest error, having an IAE of 5.739, while the proposed controller demonstrates the smallest error, with an IAE of 1.976.This reinforces the conclusion regarding the effectiveness and superiority of the proposed controller.

Conclusions and Discussion
In addressing the inherent challenges posed by the RIP system, characterized by underactuation, high nonlinearity, and instability, an optimized hierarchical sliding mode controller was developed.This approach integrates the HSMC controller with the particle swarm optimization algorithm.The HSMC controller is formulated to fulfill the dual objectives of swinging up and stabilizing the pendulum, while PSO is employed to meticulously adjust the parameters of the proposed controller, thereby elevating the overall efficacy of the control system.Through diverse simulation scenarios, the effectiveness and robustness of the proposed controller are substantiated.Comparative analyses with two alternative controllers, namely, LQR and SMC, highlight the superior performance of the proposed approach under varying conditions, encompassing scenarios with and without disturbances.While the results are promising in many instances, the theoretical foundation requires further refinement to better adapt to practical conditions.Utilizing observers, as demonstrated in reference [25], can aid in detecting disturbances and enhance the control design to mitigate these disturbances.Prospective research endeavors will be centered around implementing the proposed controller within an experimental model and augmenting its disturbance rejection capabilities.

Figure 3 .
Figure 3.The angle and angular velocity of the pendulum in iteration 1.(a) The angle of the pendulum.(b) The angular velocity of the pendulum.

Figure 4 .Figure 5 .
Figure 4.The angle and angular velocity of the pendulum in iteration 10.(a) The angle of the pendulum.(b) The angular velocity of the pendulum.

Figure 6 .
Figure 6.The angle and angular velocity of the pendulum in iteration 30.(a) The angle of the pendulum.(b) The angular velocity of the pendulum.

Figure 7 .
Figure 7.The angle of the pendulum at different initial angles.

Figure 8 .
Figure 8.The angular velocity of the pendulum at different initial angles.

Figure 10 .
Figure 10.The angle of the pendulum with and without a disturbance.
1, and ∆ = 0.1.The deflection angle responses of the pendulum bar using different controllers are shown in Figure 11.

Figure 11 .
Figure 11.The angle of the pendulum when comparing controllers.

Figure 12 .
Figure 12.The pendulum's angle when comparing controllers in the presence of a disturbance.

Table 1 .
The parameters of the RIP.

Table 2 .
The parameters of the controller in different iterations.

Table 3 .
The integral absolute error and settling time of the pendulum angle.