CFHBA-PID Algorithm: Dual-Loop PID Balancing Robot Attitude Control Algorithm Based on Complementary Factor and Honey Badger Algorithm

The PID control algorithm for balancing robot attitude control suffers from the problem of difficult parameter tuning. Previous studies have proposed using metaheuristic algorithms to tune the PID parameters. However, traditional metaheuristic algorithms are subject to the criticism of premature convergence and the possibility of falling into local optimum solutions. Therefore, the present paper proposes a CFHBA-PID algorithm for balancing robot Dual-loop PID attitude control based on Honey Badger Algorithm (HBA) and CF-ITAE. On the one hand, HBA maintains a sufficiently large population diversity throughout the search process and employs a dynamic search strategy for balanced exploration and exploitation, effectively avoiding the problems of classical intelligent optimization algorithms and serving as a global search. On the other hand, a novel complementary factor (CF) is proposed to complement integrated time absolute error (ITAE) with the overshoot amount, resulting in a new rectification indicator CF-ITAE, which balances the overshoot amount and the response time during parameter tuning. Using balancing robot as the experimental object, HBA-PID is compared with AOA-PID, WOA-PID, and PSO-PID, and the results demonstrate that HBA-PID outperforms the other three algorithms in terms of overshoot amount, stabilization time, ITAE, and convergence speed, proving that the algorithm combining HBA with PID is better than the existing mainstream algorithms. The comparative experiments using CF prove that CFHBA-PID is able to effectively control the overshoot amount in attitude control. In conclusion, the CFHBA-PID algorithm has great control and significant results when applied to the balancing robot.


Introduction
PID control algorithms are the most prevailing and widely used control algorithms in the industry, agriculture, and new technology industries such as with drones and unmanned vehicles. In recent years, balancing robots have been developed rapidly [1,2], and wheeled balancing robots are more widely used in production because they are simpler and more stable to control than legged balancing robots, as well as being cheaper and easier to manufacture [3]. For a balancing robot, the most important thing is the stability and robustness of its attitude control, which depends on the control algorithm. The Dual-loop PID control algorithm [4] is often used in the control of balancing robots [5], while it is difficult to tune the PID parameters simply by manual. Many studies [6][7][8][9][10][11][12][13][14][15][16][17][18] have proposed different methods to optimize the PID algorithm, which enable the PID algorithm to have better performance and to be applied to various scenarios. The merit of the PID parameters determines the effectiveness of the control algorithm as well as the accuracy and stability of balancing robot control. Therefore, the present study aims at presenting a Dual-loop PID control algorithm for balancing robots capable of automatically tuning parameters.
With the continuous development of the methods for tuning PID parameter, they include manual PID parameter tuning methods and intelligent PID parameter tuning methods. Among them, using metaheuristic algorithms for PID parameter tuning has important research significance and development prospects. Metaheuristic algorithms [19] are optimization algorithms that use multiple agents and multiple iterations to obtain the optimal solution to a specific problem. Exploration and exploitation are indispensable components of metaheuristics that contradict each other, but both determine the merits of metaheuristics. In chronological order, metaheuristics can be divided into traditional metaheuristics and novel metaheuristics.
The classical traditional metaheuristics are the particle swarm optimization algorithm (PSO) [20], ant colony optimization algorithm (ACO) [21], and genetic algorithms (GAs) [22], which have been frequently used in the PID control algorithm in recent years. In [8], the PSO-PID control algorithm is proposed to achieve freeway ramp control regulation. The results show that the convergence speed of the PSO-PID control algorithm is faster than that of the BP neural network in the process of ramp control, thus obtaining the best ramp control. However, the PSO-PID control algorithm is not accurate in the search process and easily falls into the local optimum. In [9], the PSO algorithm is used for the parameter optimization of a chaotic synchronous PID controller, and the algorithm is applied to chaotic synchronous control with better results than the evolutionary programming (EP) algorithm. In [10], the PSO algorithm is used to tune the quantization and proportionality factors in the fuzzy PID, resulting in a self-tuning particle swarm fuzzy PID control algorithm for the control of the robotic arm. The optimized controller has higher control precision and better control input torque on the control of the robotic arm. In [11], a weighted cooperative PID and LQR control algorithm using the PSO algorithm and the FCPC control algorithm are presented to control the robotic arm. The FCPC control algorithm converges faster in the position control of the robotic arm compared to the single PID control algorithm and the LQR control algorithm. In [12], the NSGA-II-PID control algorithm is obtained by using the evolutionary algorithm NSGA-II to tune the PID parameters of the PID controller of the greenhouse climate control system, which achieved good control performance. The schemes of optimizing the PID control algorithm through the traditional metaheuristic algorithm solve the problem that the parameters of the traditional PID control algorithm are difficult to tune. However, due to the limitations of traditional metaheuristic algorithms, it may lead to premature convergence and local optimal solutions obtained during parameter tuning, which may produce invalid loops [23].
In recent years, more and more metaheuristics have been proposed that outperform traditional metaheuristics in terms of their ability to search for globally optimal solutions, like the Archimedes Optimization Algorithm (AOA) [24], Whale Optimization Algorithm (WOA) [25], Harris−Hawkes Optimization (HHO) [26], Atom Search Algorithm (ASO) [27]. In [13], a combination of atomic search algorithm (ASO) and logistic chaotic sequences is applied for fractional order PID (FOPID) control. The FOPID algorithm achieves a better step response of the control output and has a better suppression effect on disturbances. In [14], the Crow search algorithm is proposed for the combination of DC motor PID control algorithm, and the obtained transient response is superior to the PSO-PID control algorithm. In [15], an artificial bee colony (ABC) algorithm is used to optimize the PID/PI control algorithm in the automatic generation control of interconnected reheat thermal power systems, which has a stronger global search capability than the PSO-PID/PI control algorithm. In [16], a hybrid algorithm (D2AOFAT) combining the dynamic differential annealing optimization (DDAO) and feedback artificial tree (FAT) algorithm is proposed to tune the parameters of a high-order fractional-order PID control algorithm. The timedomain metrics of the responses obtained by this algorithm are better than the conventional algorithm. In [17], the Whale Optimization Algorithm (WOA) is applied to the PID con-troller which achieved the effective trajectory tracking control of the robot manipulator. In [18], the chaotic whale algorithm (CWOA) is proposed to optimize the parameter tuning of the FOPID control algorithm. The CWOA-FOPID control algorithm obtains better ITAE and ISE values during the optimization search process, and the time-domain metrics of the output response are better than those obtained by other existing controllers in the reverse osmosis desalination process. Optimizing the PID control algorithm through metaheuristic algorithms with better search capability avoids the problem of premature convergence to some extent. However, given that the global optimal solution is extremely complicated, the search capability and search speed of metaheuristic algorithms still need to be improved, and there is still much room for improvement in the performance of these control algorithms.
Due to the increasing complexity of real-life problems and the highly multimodal nature of the problems, many existing metaheuristic algorithms present local optimal solutions rather than global optimal solutions during the search process. Therefore, developing a metaheuristic algorithm that well balances exploitation and exploration has become the focus of metaheuristic algorithm research. In [28], the Honey Badger Algorithm (HBA) is proposed, which is inspired by the hunting process of honey badgers. HBA maintains a large enough population diversity during the search process and possesses a dynamic search strategy to simultaneously balance the exploration. These two properties of HBA play a very effective role in avoiding the effect of local optimum, which is conducive to better avoiding the problems of early convergence and local optimal solutions in the process of PID parameter tuning.
In the process of balancing robot attitude control, the merit of the Dual-loop PID parameters determines the accuracy and stability of balancing robot attitude control. From the comparative experimental results, it can be seen that for the complex PID control algorithm, the controller obtained by the metaheuristic algorithm with ITAE as fitness was not effective and has the problem of short adjustment time but large overshoot. Therefore, it is necessary to explore an optimization method for the Dual-loop PID parameter tuning that can balance the overshoot and response speed.
In this paper, an HBA Dual-loop PID control algorithm (CFHBA-PID algorithm) based on CF-ITAE for balancing robot attitude control is proposed. To verify the superiority of the HBA-PID algorithm, the AOA-PID, WOA-PID, and PSO-PID algorithms are applied to the attitude control of the balancing robot for comparison experiments. In addition, a new indicator CF-ITAE is proposed to be compared with ITAE. The CFHBA-PID algorithm, CFAOA-PID algorithm, CFWOA-PID algorithm, and CFPSO-PID algorithm are compared with the original control algorithm, so as to verify the superiority of CF-ITAE.
The main contributions of this paper are the following: 1.
The HBA (Honey Badger Algorithm) is utilized in the Dual-loop PID algorithm parameter tuning for the first time, and the HBA-PID control algorithm is proposed to achieve stable and robust balancing robot attitude control.

2.
A complementary factor (CF) is proposed and implemented as a hyperparameter in the new proposed CFHBA-PID algorithm, which can be adjusted according to the actual requirements to achieve the balance of overshoot and response speed during the process of searching the optimal parameters. 3.
The CFHBA-PID algorithm is applied to the Dual-loop PID attitude control of the balancing robot, and achieves the best control compared to the existing mainstream algorithms.

Materials and Methods
2.1. PID 2.1.1. PID Control Algorithm Figure 1 presents the basic model of the PID control algorithm. The PID control algorithm is a series compensation control algorithm consisting of the proportional session, integral session, and differential session. In the PID controller, the error quantity e(t) is the difference between the system feedback quantity c(t) and the input quantity r(t). The output control quantity m(t) is obtained by scaling up or down as well as integrating and differentiating the error quantity e(t). The output control quantity m(t) calculation equation is given as Equation (1): where t is the current time of the PID controller, K p is the proportional factor, K i is the integral factor, and K d is the differential factor. According to the PID control algorithm, K p plays a role in making the control timely, whereas too much K p will cause a loss of stability and too little K p will result in a loss of regulation, as well as inappropriate K p will cause static errors. K i plays a role in eliminating static errors, but it results in system oscillations, and the larger the K i , the larger the integral effect. K d plays a role in overcoming the hysteresis of a controlled object, and the larger the K d , the more potent the differential effect. Therefore, K p , K i , and K d play a decisive role in the performance of the control algorithm, and appropriate parameters can ensure a stable system with small errors.
integral session, and differential session. In the PID controller, the error quantity the difference between the system feedback quantity ( ) and the input quantit The output control quantity ( ) is obtained by scaling up or down as well as inte and differentiating the error quantity ( ). The output control quantity ( ) calc equation is given as Equation (1): where is the current time of the PID controller, is the proportional factor, integral factor, and is the differential factor. According to the PID control algo plays a role in making the control timely, whereas too much will cause a stability and too little will result in a loss of regulation, as well as inappropr will cause static errors. plays a role in eliminating static errors, but it results in oscillations, and the larger the , the larger the integral effect.
plays a role i coming the hysteresis of a controlled object, and the larger the , the more pot differential effect. Therefore, , , and play a decisive role in the perform the control algorithm, and appropriate parameters can ensure a stable system wit errors.    Figure 2 illustrates the basic model of the Dual-loop PID control algorithm. The Dualloop PID control algorithm is a dual closed-loop control system by combining two PID controllers, one of which acts as the outside loop of the system and the other acts as the inside loop of the system. The output of the outside loop PID controller affects the desired value of the inside loop PID controller, while the output of the inside loop PID controller affects the actual value of the outside loop, thus achieving Dual-loop control of the inside and outside loops. Compared with single-loop PID control, the Dual-loop PID algorithm increases the frequency of the control system operation and reduces the oscillation period and regulation time, resulting in enhanced system rapidity.

Dual-Loop PID Algorithm for Attitude Control of Balancing Robots
A balancing robot's control relies on attitude control. The mechanical model of the balancing robot is shown in Figure 3, while the cross-section is shown in Figure 4. The outside loop of attitude control is the angular loop, which is obtained by using the angular error ( ) as the input quantity and the output quantity ( ) as the desired value of the inside loop. The equations of the outside loop control are given as Equations (2) and (3): where _ is the desired angle, and is the actual angle.

Dual-Loop PID Algorithm for Attitude Control of Balancing Robots
A balancing robot's control relies on attitude control. The mechanical model of the balancing robot is shown in Figure 3, while the cross-section is shown in Figure 4. The outside loop of attitude control is the angular loop, which is obtained by using the angular error e outside (t) as the input quantity and the output quantity C outside (t) as the desired value of the inside loop. The equations of the outside loop control are given as Equations (2) and (3): where Angle_expect is the desired angle, and Angle is the actual angle. K p_outside , K i_outside , and K d_outside are parameters of the outside-loop PID controller.

Dual-Loop PID Algorithm for Attitude Control of Balancing Robots
A balancing robot's control relies on attitude control. The mechanical model of th balancing robot is shown in Figure 3, while the cross-section is shown in Figure 4. Th outside loop of attitude control is the angular loop, which is obtained by using the angula error ( ) as the input quantity and the output quantity ( ) as the desired value of the inside loop. The equations of the outside loop control are given as Equation (2) and (3): where _ is the desired angle, and is the actual angle.   The inside loop of the attitude control is the angle loop, which take locity error ( ) as the input quantity and the output quantity force to balance the robot. The equations of the outside loop control are gi (4) and (5): where is the actual angular velocity. _ , _ , _ ters of the inside-loop PID controller. Figure 5 shows the state diagram of the balancing robot in attitude c is the initial state of the balancing robot. State Four is the upright state robot. The balancing robot starts from State One and aims to achieve Sta to reach State Four, the outer loop output ( ) is obtained throug Equations (2) and (3). Then, ( ) is used as the desired angular vel inner-loop Equations (4) and (5) to calculate the output of the inner-lo nally, ( ) is used as the input of the balancing robot motor to ge sponding control force F to change the attitude of the balancing robot. The inside loop of the attitude control is the angle loop, which takes the angular velocity error e inside (t) as the input quantity and the output quantity C outside (t) as the force to balance the robot. The equations of the outside loop control are given as Equations (4) and (5): where Palstance is the actual angular velocity. K p_inside , K i_inside , K d_inside are parameters of the inside-loop PID controller. Figure 5 shows the state diagram of the balancing robot in attitude control. State One is the initial state of the balancing robot. State Four is the upright state of the balancing robot. The balancing robot starts from State One and aims to achieve State Four. In order to reach State Four, the outer loop output C outside (t) is obtained through the outer loop Equations (2) and (3). Then, C outside (t) is used as the desired angular velocity value in the inner-loop Equations (4) and (5) to calculate the output of the inner-loop C inside (t). Finally, C inside (t) is used as the input of the balancing robot motor to generate the corresponding control force F to change the attitude of the balancing robot.

PID Control Performance Indicators
In the present paper, the dynamic performance of the control system is evaluated from two aspects. In terms of time-domain metrics, the rise time t r , transition process time t s , and overshoot σ p are used to determine the superiority of the step response of the output. The rise time t r is the time it takes for the step response curve to rise from zero to the steady-state value for the first time. The settling time t s is the time when the step response enters and stays within the error range. The overshoot σ p is the ratio of the instantaneous maximum deviation value of the step response to the steady-state value. In addition, error integration metrics IAE, ISE, ITSE, ITAE are widely used. Among four error integration metrics, ITAE is measured by multiplying the time by the absolute value of the error integral [29], which is seen as one of the best performance metrics in single-parameter optimal control and adaptive control [30].

PID Control Performance Indicators
In the present paper, the dynamic performance of the control system is evaluated from two aspects. In terms of time-domain metrics, the rise time , transition process time , and overshoot are used to determine the superiority of the step response of the output. The rise time is the time it takes for the step response curve to rise from zero to the steady-state value for the first time. The settling time is the time when the step response enters and stays within the error range. The overshoot is the ratio of the instantaneous maximum deviation value of the step response to the steady-state value. In addition, error integration metrics IAE, ISE, ITSE, ITAE are widely used. Among four error integration metrics, ITAE is measured by multiplying the time by the absolute value of the error integral [29], which is seen as one of the best performance metrics in singleparameter optimal control and adaptive control [30].
ITAE is selected as the objective function and a set of optimal (minimum ITAE value) PID parameters are tuned by metaheuristic algorithms. The ITAE calculation equation is given as Equation (6): where _ is the time for the PID controller to reach stability.

Honey Badger Algorithm (HBA)
The Honey Badger Algorithm (HBA) is inspired by the intelligent hunting behavior of honey badgers. HBA achieves the balance between exploration and exploitation [31] by setting appropriate randomness. In the HBA algorithm, the smell intensity of the prey is related to the concentration strength of the prey and the distance between the prey and the honey badger , which enables search agents to transfer from exploration to exploitation and avoids falling into local optimum. The density factor is a randomization control factor that decreases with time to reduce population diversity throughout iterations. This achieves the required trade-off balance between exploration and exploitation.
can provide population diversity in the search process by changing the search direction. HBA has two modes of locating food sources, which are digging mode and honey mode: 1. Digging mode: Honey badgers use their rat sniffing skills to slowly approach the prey and dig the prey in a cardioid way. In digging mode, the HBA position update process ( ) is given as Equation (7): ITAE is selected as the objective function and a set of optimal (minimum ITAE value) PID parameters are tuned by metaheuristic algorithms. The ITAE calculation equation is given as Equation (6): where Time_s is the time for the PID controller to reach stability. The Honey Badger Algorithm (HBA) is inspired by the intelligent hunting behavior of honey badgers. HBA achieves the balance between exploration and exploitation [31] by setting appropriate randomness. In the HBA algorithm, the smell intensity of the prey I is related to the concentration strength of the prey S and the distance between the prey and the honey badger d i , which enables search agents to transfer from exploration to exploitation and avoids falling into local optimum. The density factor α is a randomization control factor that decreases with time to reduce population diversity throughout iterations. This achieves the required trade-off balance between exploration and exploitation. F can provide population diversity in the search process by changing the search direction. HBA has two modes of locating food sources, which are digging mode and honey mode: Digging mode: Honey badgers use their rat sniffing skills to slowly approach the prey and dig the prey in a cardioid way. In digging mode, the HBA position update process (x new ) is given as Equation (7): where x prey is the global best position of the prey so far. I is the smell intensity of the prey. α is the update density factor. β is the ability of the honey badger to get food (default = 6). r 3 , r 4 , and r 5 are three different random numbers between 0 and 1. F is a flag to change the search direction, which is given as Equation (8): I is the smell intensity of the prey that is related to the concentration strength of the prey S and the distance between the prey and the honey badger d i . The smell intensity of the prey I is strong when the concentration strength of the prey is high and the distance between the prey and the honey badger is close. Honey Badgers will search faster when the smell intensity of the prey is strong. I, S, and d i are given respectively using Equations (9)- (11): where r 2 is a random number between 0 and 1. The density update factor α is a random variable that controls time-varying randomness, which can be used to achieve smooth transitions during exploration and development. It is given as Equation (12): where C is greater than or equal to 1 (default = 2). t is the current number of iterations and t max is the maximum number of iterations.

2.
Honey mode: The honey badger likes eating bee larvae and pupae, and they cooperate with a honey-guide (a bird) to find bee larvae. It is difficult for the honey badger to find the hive, but its claws can easily break open the hive, while the honey-guide can quickly find the hive but cannot break it. Therefore, the honey-guide guides the honey badger toward the hive and finally shares the bee larvae. In honey mode, the HBA position update process (x new ) is given as Equation (7): where r 7 is a random number between 0 and 1.

Complementary Factor (CF)
For a complex PID control system, simply using ITAE as the fitness of the metaheuristic algorithms may make the rise time shorter, but the overshoot is not well controlled, which is reflected in Equation (6); furthermore, a large overshoot is fatal to the attitude control of the balancing robot, which causes serious impact and interference. Therefore, the complementary factor (CF) is proposed to achieve the fusion of ITAE and overshoot quantity, which leads to a new indicator, CF-ITAE. The CF-ITAE calculation equation and overshoot calculation equation are given as Equations (14) and (15): where CF is a constant between 0 and 1. Equation (15) shows that when c(∞) is a constant, the relationship between the overshoot σ p and the maximum value of the response c(t) max can be given as Equation (16): Therefore, we replace the overshoot σ p with c(t) max . The improved CF-ITAE calculation equation is given as Equation (17): CF determines the direction of CF-ITAE rectification. A larger CF indicates that the CF-ITAE has less confidence in the overshoot amount, while a smaller CF indicates that the CF-ITAE has more confidence in the overshoot amount. The complementary factor CF is implemented as a hyperparameter in this algorithm so that the metrics can be changed according to the actual requirements, and it achieves a balance between overshoot and rise time while retaining the original performance of ITAE.
Using CF-ITAE as the fitness, the value of the CF has an important influence on the search of the metaheuristic algorithm. If the weight of the algorithm for the overshoot is too small, and the algorithm may obtain a PID system with too much overshoot and very short rise time, we can change the search direction of the algorithm by reducing the value of the CF to obtain the desired solution. On the contrary, if the overshoot is small but the rise time is too long, the value of CF should be increased to increase the weight of the ITAE in the CF-ITAE in order to achieve the purpose of shortening the rise time of the tuning result.
Therefore, due to the simplicity and understandability of the CF-ITAE calculation in Equation (17), the user can easily understand the impact of CF and adjust it according to their requirements. If the user has high requirements for overshoot, the CF value can be reduced until the desired solution is obtained. It can be seen that compared with the ITAE, CF-ITAE can not only solve the problem of large overshoot, but also can be adjusted according to user needs.

CFHBA-PID Algorithm
The CFHBA-PID algorithm combined the HBA algorithm with the Dual-loop PID algorithm by setting K p_inside , K i_inside , K d_inside , K p_outside , K i_outside , and K d_outside of the Dual-loop PID algorithm as the search space of HBA algorithm. Two sets of PID parameters are obtained for each search, and the parameters obtained from the search are imported into the balanced robot model implemented by Simulink to calculate the ITAE value and the overshoot amount. Then the CF-ITAE can be calculated by Equation (17). The CF-ITAE metric is used as the fitness of the metaheuristic algorithm HBA to constrain the search direction to obtain the optimal solution.
The CFHBA-PID control algorithm steps described by Figure 6 are: Step 1: Initialize PID parameters. The six parameters K p_inside , K i_inside , K d_inside , K p_outside , K i_outside , and K d_outside are used as the solution space, and the relevant parameters of HBA are initialized.
Step 2: The Dual-loop PID control algorithm calculates the fitness value (CF-ITAE) as the initial fitness, and the best fitness value and the corresponding PID parameters are recorded for subsequent updates.
Step 3: Start iterations and update the PID parameters by HBA for each iteration, and the new fitness (CF-ITAE) is calculated by the Dual-loop PID control algorithm.
Step 4: The calculated fitness value is compared with the previously recorded best fitness, and if the new fitness obtained is smaller, the fitness and its corresponding PID parameters will be updated.
Step 5: When the iteration is complete, the best fitness is output along with its corresponding PID parameters.

Experiments and Results
To verify the performance of the proposed algorithm, a series of experiments an comparisons are conducted, including comparing the HBA-PID algorithm with existin mainstream algorithms, and verifying the importance of complementary factors as we

Experiments and Results
To verify the performance of the proposed algorithm, a series of experiments and comparisons are conducted, including comparing the HBA-PID algorithm with existing mainstream algorithms, and verifying the importance of complementary factors as well as testing the superiority of the CFHBA-PID algorithm. The Dual-loop PID attitude control of the balancing robot is used as the experimental object. The simulation experiments of the balancing robot were implemented by Simulink, and the Simulink model of the Dual-loop PID control algorithm for the attitude control of the balancing robot is shown in Figure 7. The relevant parameter values and ranges for the balancing robot are shown in Table 1, and the parameters related to the metaheuristic algorithm are set in Table 2.  Table 1, and the parameters related to the metaheuristic algorithm are set in Table 2.       Figures 8-11. In addition, to test the robustness of the algorithm when subjected to external disturbance, we apply an external force to break the balance of the balancing robot at a population size of 50, when time t = 1, and compare the robustness of the algorithm by observing the recovery speed and the magnitude of overshoot of the balancing robot. The actual angle of the balancing robot under HBA-PID, AOA-PID, WOA-PID, and PSO-PID algorithms after applying the external force is shown in Figure 12. The fitness value curves are shown in Figure 13. Table 2. Parameters related to metaheuristic algorithm.

Algorithms Parameters
a variable decreases linearly from 2 to 0 (Default) a 2 linearly decreases from −1 to −2 (Default) PSO Inertia weight decreases linearly from 0.9 to 0.4 (Default) C 1 (individual-best acceleration factor) increases linearly from 0.5 to 2.5 (Default) C 2 (global-best acceleration factor) decreases linearly from 2.5 to 0.5 (Default)    The overshoots obtained by the HBA-PID algorithm, AOA-PID algorithm, WOA-PID algorithm, and PSO-PID algorithm with a population size of 50 are 0.168%, 7.9185%, 14.6905%, and 25.3665%, respectively, while the rise times are kept short. It can be seen that using ITAE as the fitness, the rise time is preferred between the balance of overshoot and rise time. Since the amount of overshoot has a large impact on the attitude control of the balancing robot, the CF-ITAE indicator is proposed to achieve the fusion between ITAE and overshoot by using the CF. CF-ITAE enables the metaheuristic algorithm to obtain parameters that balance overshoot and rise time in the search for the optimal parameters. To verify the effectiveness of CF-ITAE, we compare the PID parameters and the time-domain metrics of the attitude control of the balancing robot obtained by combining HBA-PID, AOA-PID, WOA-PID, and PSO-PID algorithms with CF-ITAE. The CF is 0.05, the number of populations is 50, and other parameters are set as before. The data are shown in Table 7, and the step response of the actual angle of the balancing robot is shown in Figure 14. In order to test the robustness of the algorithm when subjected to external disturbance, we apply an external force to break the balance of the balancing robot at a population size of 50, when time t = 1, and compare the robustness of the algorithm by observing the recovery speed and the magnitude of overshoot of the balancing robot. The actual angle of the balancing robot under CFHBA-PID, CFAOA-PID, CFWOA-PID, and CFPSO-PID algorithms after applying the external force is shown in Figure 15, and the corresponding fitness curve is shown in Figure 16.           The overshoots obtained by the HBA-PID algorithm, AOA-PID algorithm, WOA-PID algorithm, and PSO-PID algorithm with a population size of 50 are 0.168%, 7.9185%, 14.6905%, and 25.3665%, respectively, while the rise times are kept short. It can be seen that using ITAE as the fitness, the rise time is preferred between the balance of overshoot     In addition, to investigate the effect of the value of the CF on the performance of the CFHBA-PID algorithm, CF is set to 0.05, 0.20, 0.50, 0.80, 0.95, and 1 for the experiments to obtain the PID parameters as well as the time-domain indicators of the attitude control of the balancing robot. The obtained data are shown in Table 8, and the step responses of the actual angle of the balancing robot are shown in Figure 17.      obtain the PID parameters as well as the time-domain indicators of the attitude control of the balancing robot. The obtained data are shown in Table 8, and the step responses of the actual angle of the balancing robot are shown in Figure 17.

Discussion
As is indicated in Tables 3-6 and Figures 8-11, the most effective algorithms in balancing robot attitude control are expected to be a combination of the HBA-PID algorithm with a population size of 50, the AOA-PID algorithm with a population size of 20, the WOA-PID control algorithm with a population size of 40, and the PSO-PID control algorithm with a population size of 40. By comparing the optimal results obtained by the four algorithms (the bolded data in each table), we can easily find that the data obtained by the HBA-PID algorithm with a population size of 50 have the smallest stability time and ITAE value in balancing robot attitude control. From the above data, it can be seen that the ITAE values obtained by the HBA-PID algorithm are all less than 10, which means the results obtained by the HBA-PID are closer to the global optimal solution. Figure 12 shows that the HBA-PID algorithm produces the smallest angular change when disturbed by external force and also has the shortest stabilization time to recover to an error value of 2%, which shows that the HBA-PID algorithm has the best robustness for balancing robot attitude control among the four algorithms. The fitness curves obtained by the four metaheuristic algorithms are presented in Figure 13, indicating that the HBA-PID algorithm converges fastest in the search for the optimal PID parameters and obtains the smallest adaptation value, which also indicates that the HBA-PID algorithm outperforms other metaheuristic algorithms in balancing robot attitude control. Therefore, the proposed HBA-PID algorithm is better than other control algorithms in balancing robot attitude control.
Comparing the results of Table 7 and Figure 14 with the time-domain metrics obtained with ITAE as the fitness, it is found that the overshoot is effectively reduced by introducing the CF. The CFHBA-PID algorithm, CFAOA-PID algorithm, CFWOA-PID algorithm, and CFPSO-PID algorithm had 0.0035%, 0.0015%, 4.1095%, and 5.8615% overshoots, respectively, which were 0.1645%, 7.917%, 10.581%, and 19.505% less compared to the original algorithm, respectively. Figure 15 shows that CFHBA-PID algorithm, CFWOA-PID algorithm, and CFPSO-PID algorithm have good robustness and stability after introducing the CF. Considering the attitude control of the balancing robot by the three algorithms at 0-0.5 s, it is seen that the CFHBA-PID algorithm is the optimal algorithm in terms of robustness and stability. Figure 16 shows that with the introduction of complementary factors, although the CFHBA-PID algorithm converges slightly less quickly than the CFPSO-PID algorithm in the search for the optimal parameters, the CFHBA-PID algorithm obtains the smallest fitness value and outperforms the other three algorithms overall. Therefore, the proposed CFHBA-PID algorithm could be considered as the most effective in balancing the robot's attitude control and is superior to other algorithms.
The new rectification indicator CF-ITAE is obtained by using CF for the fusion of ITAE and overshoot. CF is used as a hyperparameter to play a role in the parameter tuning of the system to balance the relationship between the overshoot amount and the rise time, and the CF value can be adjusted according to the demand of the system, so that the system can achieve better results. Table 8 and Figure 17 show that when the CFs are 0.80 or 0.95, the CFHBA-PID algorithm does not have enough weight on the overshoot amount and does not achieve a significant effect, and when the CF is 0.5, the CFHBA-PID algorithm increases the weight on the overshoot amount, so that the algorithm can effectively reduce the overshoot amount in the attitude control of the balancing robot. The overshoots are less than 0.01% for the CFs of 0.05, 0.2, and 0.5, indicating that the CFHBA-PID algorithm has effectively controlled the overshoot. It can be seen that when the CF is less than or equal to 0.5 as a hyperparameter, the overshoot in balancing robot attitude control is negligible, and the effect is significant for balancing robot attitude control at this time. Therefore, when the CFHBA-PID control algorithm is applied in the attitude control of the balancing robot, the best effect is achieved when the CF is less than 0.5.

Conclusions
In the present paper, the CFHBA-PID algorithm is proposed and implemented to the balancing robot attitude control. The HBA-PID algorithm is compared with the AOA-PID algorithm, WOA-PID algorithm, and PSO-PID algorithm through experimental simulation. The experimental results show that the HBA-PID algorithm outperforms the other three algorithms in terms of overshoot, stabilization time, ITAE value, and convergence speed of fitness value, which proves that the HBA-PID algorithm has the best control effect in the attitude control of the balancing robot. In addition, the complementary factor (CF) is introduced to the algorithm, and CF-ITAE is proposed to perform the fusion between the overshoot and ITAE to achieve the balance between the overshoot and rise time. Compared with the CFHBA-PID algorithm, CFAOA-PID algorithm, CFWOA-PID algorithm, and CFPSO-PID algorithm, the overshoot of the CFHBA-PID algorithm is very close to that of the CFAOA-PID algorithm; meanwhile, the CFHBA-PID algorithm is better than the other three algorithms in terms of rise time, stability time, and CF-ITAE value.
HBA is applied to PID parameter tuning in balancing robot attitude Dual-loop control for the first time, and the complementary factors are introduced to propose the CFHBA-PID algorithm, which is the most effective in balancing robot attitude control when compared with other existing algorithms. Therefore, the CFHBA-PID algorithm is suggested to be applied into other complex control systems in future work.