Adaptive Particle Swarm Optimization of PID Gain Tuning for Lower-Limb Human Exoskeleton in Virtual Environment

: Tuning of a proportional-integral-derivative (PID) controller for a complex multi-joint structure, such as an exoskeleton, using conventional methods is difﬁcult and imprecise. In this paper, an optimal PID tuning method for a 3-dimensional model of a lower-limb human exoskeleton in gait training condition is presented. The dynamic equation of the human-exoskeleton is determined using a Lagrangian approach, and its transfer function is established in a closed-loop control system. PID controller gains, initialized by the Ziegler–Nichols (Z-N) method, are used as the input to an adaptive particle swarm optimization (APSO) algorithm for minimizing the multi-joint trajectory error. The optimized controller is tested in the Gazebo virtual environment and compared with the Z-N and conventional optimization methods. The numerical analysis shows that the PID controller tuned by a combination of Z-N and APSO improves the performance of a lower-limb human exoskeleton in gait training.


Introduction
Stroke and spinal cord injury are the main causes of disability in the elderly [1,2], creating problems in daily life. For many years, rehabilitation therapies have been concentrated on recovering their motion function using various manual methods. In recent years, the lower-limb exoskeleton, which is a wearable robot, has been used to aid patients with mobility problems [3][4][5].
For the exoskeleton wearer to walk properly, the desired trajectory of the joints requires a robust control system to minimize steady-state errors to reduce disturbances. Huo et al. [6] proposed an active impedance control strategy for controlling a lower-limb exoskeleton for the sit-to-stand motion. Many researchers focused on adaptive-based control approaches to design a controller with uncertainties and non-linear systems. For instance, Daachi et al. [7] controlled one degree of freedom (DoF) lower-limb knee joint orthosis using a neural network based on adaptive control using the Lyapunov approach for rehabilitation reasons. Chen et al. [8] studied an adaptive robust cascade force control for a one DoF exoskeleton with a hydraulic actuator to minimize the effect of uncertainties.
Lu et al. [9] described an adaptive learning control system with unknown parameters using the Lyapunov approach for stability. In another study, Yang et al. [10] designed a robust learning controller with hybrid electro-hydraulic actuators, and verified their exoskeleton using a periodic reference.
For many years, proportional-integral-derivative (PID) controllers have been commonly used because of their reliable performance, and convenient and robust operation [11][12][13]. In our approach, we used particle swarm optimization (PSO) to tune the PID controller's gains. PSO has a simple concept and is easy to implement in different optimization problems. Hence, it has been used to control the robustness of PID parameters [14]. PSO has few parameters that need to be adjusted, and it has high probability and efficiency in finding the global optima, but initializing its parameters can be difficult. Although PSO has fast error convergence, it can converge prematurely and be trapped in the local optima [15]. Therefore, researchers have combined different tuning methods to optimize its gains. For example, Belkadi et al. [16] developed an optimal method to obtain the parameters of the PID controller and verified the performance in a simulation using PSO with random initialization. Similarly, Durgadevi et al. [17] used PSO for tuning the parameters of proportional-integral (PI) and PID controllers of the temperature of a continuous stirred tank reactor.
As an alternative to PSO, other optimization methods have been used for tuning controller parameters [18]. Qianhao et al. [19] developed the whale optimization algorithm, which is a type of swarm intelligence optimization algorithm, to improve the performance of a linear-quadratic regulator controller. Pan et al. [20] presented the fuzzy-PID algorithm for the nonlinear dynamics and uncertainties of the human exoskeleton robot. Their method was verified in a co-simulation technique combining ADAMS and MATLAB/Simulink. Moharam et al. [21] used a hybrid differential evolution and PSO algorithm for tuning a PID controller and compared it with the genetic algorithm (GA) and the Ziegler-Nichols (Z-N) method to prove the hybrid method is robust to disturbances. Lal et al. [22] implemented the grasshopper optimization algorithm (GOA) to obtain the PID and fuzzy-PID controller parameters for a multi-area interconnected microgrid power system. They compared two different PID controllers and concluded that fuzzy-PID produced better dynamic responses compared to a PID controller tuned by GOA.
This paper presents the tuning of PID controller gains by combining Z-N and adaptive particle swarm optimization (APSO). A simulation and the dynamic equation of the human exoskeleton model walking with the aid of a parallel bar in a virtual environment are described. The transfer functions of each joint based on the dynamic equation of human exoskeleton model are established in a closed-loop control system. An objective function formulated by the error of the control system is defined. Our main objective was to optimize a PID controller using initialization with Z-N and optimized by APSO. The tuned PID was verified in the 3-dimensional virtual simulation environment and compared with the conventional method.

Human Exoskeleton Simulation in a Virtual Environment
The lower-limb exoskeleton model consists of a waist, left and right femurs, left and right tibias, and left and right feet. The human exoskeleton simulated model was created and controlled in a robot operating system (ROS) with average human anthropometric height. The waist functions as a base link to which the left and right femurs are connected. Consequently, other links are assembled to each other as parent and child links [23]. Figure 1a  To simulate the interaction between the exoskeleton and patient, a 3D human model was added in the Gazebo simulation environment. The foot, tibia, and femur of human are coupled to its related links. The configurations of coupling between human and exoskeleton model are shown in Figure 2. To ensure the simulation accurately mimicked to the gait training task, parallel bars were added to avoid the human model from falling down by providing stability. Both hands of the human model are constrained to the parallel bars using a slide joint to allow forward and backward motion. Figure 3 demonstrates the gait training simulation of the human exoskeleton model walking with both hands holding the parallel bars.  are the center position of hip, knee, and ankle joint, respectively; θ 1 , θ 2 , and θ 3 represent angles of hip, knee, and ankle, respectively; l 1 , l 2 , and l 3 are length of the femur, tibia, and foot, respectively; and l Gi is the center of gravity (CoG) of links 1, 2, and 3. In this paper, each link of the exoskeleton and human is modeled as one DoF pendulum model, which replicates one joint of the exoskeleton and human, as shown in Figure 5. The summation of the physical effect of each lower link such as mass and inertia is considered to be M i [24]. In this study, the Lagrangian formulation of dynamic equation of the pendulum model is expressed as follows:

Human Exoskeleton Dynamic Modeling
where i represents number of the links; L i is the Lagrangian function; θ i andθ i are the angular position and velocity, respectively; T i is the torque that applies to each joint; and E ki and E pi represent kinetic and potential energy [25], respectively, which are given as follows: where m i and I i are the mass and inertia of the link, respectively; M i is the mass of lower links; g represents gravitational acceleration; x Gi , y Gi , x i , y iẋ Gi ,ẏ Giẋi , andẏ i ,represent the position of the CoG, end point of the link, and their velocity, respectively, as follows: where l Gi and l i are the length of the CoG and the link i, respectively. The total kinetic and potential energies are determined as follows: The dynamic equation of the pendulum model is determined as follows: where b is the friction coefficient and sinθ i is approximated as θ i . The transfer function G(s) is represented in Laplace as follows: Table 1 lists the physical features of the exoskeleton based on computer-automated design (CAD). The human model's features were obtained from References [26][27][28]. The mass and inertia of the human model were for a subject that weighed 74.2 kg and was 175.5 cm tall. Based on the features, the transfer function of the exoskeleton (G L (s)) and human (G H (s)) can be determined as shown in Table 2.

Control System
The plant of the system G(s) is defined as a combination of transfer functions of the human G H (s) and exoskeleton G L (s) in parallel. Figure 6 shows the control system with the feedback loop for the joint angle for each joint. Since the human model and exoskeleton are coupled together, it is assumed they are parallel to each other and the joints' angles are equal. The PID controller employs the input as the error between yhe actual and desired trajectories, and the output is the torque as a plant [29]. The error is defined as follows: Figure 6. Control system.
The PID controller and plant model are represented as follows: where C(s) is the PID controller; K P , K i , and K d are the proportional, integral, and derivative gains to be tuned to reduce the error, respectively [30]; and G L (s) and G H (s) are the transfer function of the exoskeleton and lower limb of the human, respectively.

Optimization of the Controller's Gains
The PID controller is tuned using an algorithm by a combination of the Z-N method and APSO. The PID parameters are obtained from Z-N, which is the classical observation method of tuning [31]. The output is set as the initial value, which provides the searching space to avoid local optima [32]. APSO increases the speed of convergence and the chance of finding the global optimum. PSO is based on population, inspired from observation of biological social phenomena such as a flock of birds, swarms of bees, and schools of birds [33].
An objective function f obj of the optimization problem is defined as the integral time absolute error (ITAE), which is the summation of the absolute error weighted by the elapsed time [34,35], as follows: where the error of control system is given as follows: where t is the elapsed time; e obj (t) and e obj (s) represent the error of the control system in the time and frequency domains, respectively. The tuning algorithm starts with Z-N, where K i and K d are set to zero while the K p value is established as K u . The value of K u is added until the first oscillation is observed, then its frequency is calculated as T u . The gains of the PID are determined as follows: where x zn is the output that is input into APSO, which contains particles as design variables for minimizing the objective function. Initialization is created by randomizing x zn as follows: where x 1j represents the particles in the first iteration; is a positive value, which is selected as a random value between 0 and 1. = rand(0, 1) The particles of the next iteration are a summation of the positions of previous particles with their velocities: where k and j represent the numbers of iterations and particles, respectively; x k,j and x k−1,j are the position of the current particle and the particle of the previous iteration, respectively; and v k,j is the velocity and direction of each particle toward the next iteration as follows: where rand 1 and rand 2 are random values between 0 and 1; ω i is a positive coefficient, called inertia weight, which reduces linearly with iteration, and is determined as follows: where ω max is the maximum value for inertia weight; b is a gain that starts from 1 in the first iteration and end to 0, which allows ω i starts from the maximum value to have wider searching space and decrease to be narrowed toward the global optima [36]; and b is a positive descending coefficient, starting from 1 in the first iteration. b is represented as follows: where a is a positive ascending coefficient, which starts from 0 and increases to 1 at the last iteration, as follows: where k and k max are the maximum number of iterations; C 1 and C 2 are non-negative coefficients of self and social recognition, defined as follows: The value of C 1 is greater than C 2 , and their summation remains at 4 in all iterations [36]. In each iteration, the objective function is determined for each particle, and the smallest objective function is selected as p best . The value of g best will be the lowest value of p best when the algorithm ends. ASPO stops when the number of iterations meets the maximum number of iterations k max . In this paper, the numbers of iterations and particles are 150 and 30, respectively, which were determined by experimentation to obtain the convergence of the objective function values to zero. Algorithm 1 and Figure 7 illustrate the pseudo code and flow chart of the APSO algorithm, respectively, where K step is a constant value for a step of K u . Create new iteration ; 34: 35: Select the p best ; 36: 37: if p best less than the previous g best then; The changes in C 1 and C 2 for 150 iterations are shown in Figure 9 and the ω in each iteration.
iteration amplitude C 1 ω C 2 Figure 9. Changes in adaptive particle swarm optimization (APSO) gains. Table 3 demonstrates the optimal gains of the PID controller.

Results and Discussion
The desired trajectory of each joint is based on gait training to move the joints simultaneously. The trajectories of each joint are driven by two different functions, repeated periodically. Table 4 shows the desired trajectory. t represents the elapsed time and t is the time of one walking cycle. Figure 10 provides the frame-by-frame pictures of gait training with parallel bars.
The APSO algorithm was coded in Python programming language, and the virtual environment was Gazebo, integrated with ROS. All tests were performed using a PC with a Ubuntu 18.04 LTS operation system with 16 GB RAM and an Intel core-i3 Xeon processor. Figure 11 exhibits the performance of the simulated model in Gazebo. The graphs compare the trajectories of Z-N, PSO, and APSO with the desired trajectory. The Z-N measured the initial values for PSO and APSO. The difference between PSO and APSO is the method of setting the parameters. In PSO, ω, C 1 , and C 2 are adjusted to 1.2, 2, and 2, respectively. Figure 12 shows the angular error trajectory for the hip, knee, and ankle. For all joints, the APSO error was the lowest, followed by PSO and Z-N. For example, the average error determined by APSO for the hip was 24% and 48% is less than PSO and Z-N, respectively. APSO showed less overshoot than the other methods because of its smaller peak, whereas PSO and Z-N experienced more shock when the trajectory changed. Figure 13 demonstrates the output torque of each link. The maximum torques of the knee and ankle were less than 3 and 0.05 Nm, respectively. The maximum amplitude of torque for the hip was 7 Nm, which is the highest because the actuator of the hip tolerates a heavier mass compared to the knee and ankle.     Table 5 provides the numerical analysis of Z-N and APSO performance. ME, AE, RMSE, and R 2 represent the maximum error, average error, root mean square error, and coefficient of determination, respectively. The maxima of ME and AE were less than 0.03 m, which are within the acceptable zone [37]. The maximum of RMSE was 0.0130, while the R 2 values of all joints were greater than 99%, indicating the close fitted of all variability in the actual trajectories.

Conclusions
In this study, a PID controller was optimally tuned using an optimization algorithm that combines of Z-N and APSO. Parameter changes in each iteration enabled the finding of the optimal solution and avoided the local optima. Furthermore, the PID gains were established by Z-N and used for initializing the APSO. The proposed method was compared and tested in a virtual environment on a human exoskeleton model. The results demonstrated the acceptable performance of the APSO controller by statistical analysis.
The optimal PID controller minimized the trajectory error of a multi-joint human exoskeleton structure for gait training. For a new trajectory and different training conditions, the optimization process should be repeated, which is the limitation of this study. In future work, the model can be applied in different situations such as climbing stairs and the stand-to-sit movement.