Control Method for Flexible Joints in Manipulator Based on BP Neural Network Tuning PI Controller

With the development of robot technology, integrated joints with small volume and convenient installation have been widely used. Based on the double inertia system, an integrated joint motor servo system model considering gear angle error and friction interference is established, and a joint control strategy based on BP neural network and pole assignment method is designed to suppress the vibration of the system. Firstly, the dynamic equation of a planetary gear system is derived based on the Lagrange method, and the gear vibration of angular displacement is calculated. Secondly, the vibration displacement of the sun gear is introduced into the motor servo system in the form of the gear angle error, and the double inertia system model including angle error and friction torque is established. Then, the PI controller parameters are determined by pole assignment method, and the PI parameters are adjusted in real time based on the BP neural network, which effectively suppresses the vibration of the system. Finally, the effects of friction torque, pole damping coefficient and control strategy on the system response and the effectiveness of vibration suppression are analyzed.


Introduction
With the development of robot technology, the integrated joint has been widely used in robots. Compared with the traditional robot joint transmission system, the integrated joint is smaller in structure and lighter in mass. Harmonic gear is often used as a reducer in the integrated joint, and the flexible element and transmission shaft system in the harmonic reducer have torsional stiffness. The servo system with the integrated joint has certain torsional stiffness [1]. In reference [2], the joint considering torsional stiffness is called the flexible joint. The existence of joint flexibility will cause the fluctuation of output speed of the servo system. Suppress the fluctuation of output speed and improve the control accuracy of the flexible joint has become a hot issue [3,4].
To achieve accurate control of the servo system, it is necessary to establish an accurate dynamic model. A large number of scholars have discussed the dynamic modeling of flexible joint. References [5,6] believe that the flexible joint model can be equivalent to a double inertia system, and the double inertia system relies on the motor to drive the load to rotate. During load operation, the system is affected by friction torque. References [7,8] consider the influence of friction factors on the basis of the double inertia system. In addition, gears are often used in the transmission of the double inertia system. Reference [9] considers the gear reduction ratio based on the double inertia model but does not consider the dynamic performance of the gear system. Li et al. [10] established a planetary gear torsional dynamics model considering time-varying stiffness, backlash and transmission error. Li et al. [11,12] established the planetary gear system and the gear-bearing system model, respectively, and studied the influence of load and wear on the response of the system. In order to construct a more accurate dynamic model, reference [13] considers

Dynamic Modeling of Flexible Joint Considering Gear Angle Error and Friction Torque
The robot joint servo system is composed of servo motor, deceleration components, transmission shafts, loads, etc. Gears are widely used in servo systems, which play a role in changing the transmission direction and adjusting the output speed of the motor. Due to the existence of factors such as backlash and time-varying meshing stiffness, a certain vibration of gear system will be generated when the gear is running, resulting in vibration displacement and affecting the operation of the motor and the load end. There is a certain torsional stiffness in the transmission shaft system and deceleration components, so there is a certain torsional deformation in the robot joint servo system as well. The joint considering torsional deformation is called the flexible joint, and it can be equivalent to a double inertia system. One end of the double inertia system is called the motor end and the other end is called the load end. The motor end and the load end are connected by a torsion spring. The model diagram of the flexible joint servo system is shown in Figure 1. The flow chart of dynamic model analysis is shown in Figure 2.

Torque
The robot joint servo system is composed of servo motor, deceleration components, transmission shafts, loads, etc. Gears are widely used in servo systems, which play a role in changing the transmission direction and adjusting the output speed of the motor. Due to the existence of factors such as backlash and time-varying meshing stiffness, a certain vibration of gear system will be generated when the gear is running, resulting in vibration displacement and affecting the operation of the motor and the load end. There is a certain torsional stiffness in the transmission shaft system and deceleration components, so there is a certain torsional deformation in the robot joint servo system as well. The joint considering torsional deformation is called the flexible joint, and it can be equivalent to a double inertia system. One end of the double inertia system is called the motor end and the other end is called the load end. The motor end and the load end are connected by a torsion spring. The model diagram of the flexible joint servo system is shown in Figure 1. The flow chart of dynamic model analysis is shown in Figure 2. In Figure 1, a T represents the driving torque, m  represents the motor end angle,  In Figure 1, T a represents the driving torque, θ m represents the motor end angle, θ l represents the load end angle, F represents the friction torque, K s represents the torsional stiffness, J m represents the moment of inertia at the motor end, and J l represents the moment of inertia at the load end.
In addition, the load is subjected to friction torque during rotation. The models describing the friction torque in the servo system mainly include the LuGre model, the Coulomb model, and the Stribeck model. According to reference [24], different friction models are introduced. It can be seen that an approach for modeling systems with lubrication is the Stribeck friction model. In this paper, friction comes from the transmission system or coupling, etc., which contains lubrication. Therefore, the Stribeck model is adopted. The Stribeck model considers friction torque as a function of speed. The expression of the Stribeck model is shown in Equation (1). by Equation (4). The planetary gear reducer is input from the planet carrier, and the sun gear is output, that is, ∆θ = θ ss . Considering the meshing stiffness, damping, and backlash of the gear system, the dynamic model of the planetary gear system is established by Lagrange method [25,26] as shown in Equation (4). θ ss , J s and r bs are the vibration angular displacement, the moment of inertia and the base circle radius of the sun gear, respectively. θ pi , J pi , m pi and r bpi are the vibration angular displacement, the moment of inertia, the mass and the base circle radius of the planetary gear, respectively. θ c , J c and r bc are the vibration angular displacement, the moment of inertia and the radius of the planet carrier, respectively. e spi , b spi , c spi and k spi are the transmission error, the backlash, the damping and the stiffness of the meshing position of the sun gear and the planet gear, respectively. e rpi , b rpi , c rpi and k rpi are the transmission error, the gear backlash, the damping and the stiffness of the meshing part of the ring gear and the planetary gear, respectively.
where k s , k p , and k c are the supporting stiffnesses of the sun gear, the planetary gear, and the ring gear, respectively, and c s , c p and c c are the supporting damping of the sun gear, the planetary gear, and the ring gear, respectively. In order to eliminate the influence of rigid body displacement and indefinite solution on the planetary gear system as shown in Figure 3, the Equation (4) is rewritten, and the dynamic transmission error is introduced as shown in Equation (5).
where the stiffness and the static transmission error are in the form of finite harmonics, and the backlash is in the form of a piecewise function proposed by Kahraman [27], as shown in Equations (6)- (8). k spi (t) = k hsp + k asp cos(ωt + ϕ) k rpi (t) = k hrp + k arp cos(ωt + ϕ) (6) e spi (t) = e asp + e rsp cos(ωt + ϕ e ) e rpi (t) = e arp + e rrp cos(ωt + ϕ e ) Mathematics 2021, 9,3146 5 of 18 where the meshing of the sun gear and the planetary gear is called the internal meshing, the meshing of the planetary gear and the ring gear is called the external meshing, k hsp and k hrp are the mean stiffnesses of internal and external meshing, respectively, k asp and k arp are the stiffness amplitudes of internal and external meshing, respectively, e asp and e arp are the mean static transmission errors of internal and external meshing, respectively, and e rsp and e rrp are the static transmission error amplitudes of internal and external meshing, respectively. In Equation (8), j (j = spi and rpi) represents the backlash of internal and external meshing, respectively.   According to Equation (3), the dynamic equation considering gear angle error and friction model is a nonlinear equation, which brings difficulties to the design of servo system controller parameters. The influence of gear system and system friction torque is introduced into the double inertia system as the interference term of the system, which also belongs to the modeling error of the system. It is relatively smaller than load feedback and has no effect on the determination of PI parameters. In order to determine the controller  According to Equation (3), the dynamic equation considering gear angle error and friction model is a nonlinear equation, which brings difficulties to the design of servo system controller parameters. The influence of gear system and system friction torque is introduced into the double inertia system as the interference term of the system, which also belongs to the modeling error of the system. It is relatively smaller than load feedback and has no effect on the determination of PI parameters. In order to determine the controller parameters for the subsequent application of the pole assignment strategy, the influence of the gear angle error and the friction torque are ignored. After ignoring the nonlinear factors such as gear angle error and friction torque, the dynamic equation of the flexible joint servo system can be obtained as shown in Equation (9).
According to Equation (9), the state space equation of the flexible joint can be obtained as shown in Equation (10).
According to Equation (10), the transfer function from the output speed of the motor to the driving torque can be obtained as shown in Equation (11).
We can represent Equation (11) in the form as shown in Equation (12).
where ω a represents the anti-resonant frequency and ω n represents the resonant frequency, and their expressions are shown in Equations (13) and (14).
In Equation (14), R represents the ratio of inertia between the load end and the motor end, and its expression is shown in Equation (15).

Joint Control Strategy Based on BP Neural Network and Pole Placement Method
The control strategy of the flexible joint servo system mostly adopts a three-loop control strategy, which contains current loop, speed loop and displacement loop. It can be known that the current loop and the speed loop have a larger bandwidth. The influence of the current loop can be ignored during the speed loop control strategy. This paper mainly studies the speed control of the flexible joint, so the influence of position loop is not considered. The output speed of the motor is easy to measure, so the speed of the motor is used as the feedback signal. Through the closed-loop control of the motor speed, the control of the output speed of the load is indirectly realized.
The PI control strategy is widely used in the speed control strategy of the servo system. Therefore, this paper uses PI control strategy to control the speed loop of the servo system. The control block diagram of the flexible joint servo system is shown in Figure 5. The controller parameters play a key role in whether the flexible joint servo system can obtain stable speed output. Therefore, it is necessary to design the controller parameters according to the controlled object. In this paper, the pole assignment strategy is used to design controller parameters.
The moment of inertia of the load of the servo system in the mechanical arm flexible joint has obvious time-varying characteristics. It is difficult to obtain a stable control effect if the controller parameters are fixed. With the development of intelligent control, fuzzy logic systems and neural networks provide theoretical possibilities for changing controller parameters in real time. Compared with the PI controller with fixed parameters, the PI controller that can change parameters in real time can obtain more accurate control effects. Therefore, this paper uses the BP neural network to adjust the controller parameters in real time according to the error and the change rate of error. It is necessary to roughly determine the control parameters before using the BP neural network. In this paper, the pole assignment strategy is used to roughly determine the control parameters, and then the BP neural network is used to fine tune the controller parameters. The specific control flow is shown in Figure 6.

Controller Parameters Tuning Based on Pole Assignment
According to reference [15], the appropriate controller parameters are roughly determined by using the pole assignment strategy, which is ready for the next step of using the BP neural network. According to Equation (12), the closed-loop transfer function of the flexible joint servo system can be obtained as shown in Equation (16).
where θ * represents the rated input angle, K p represents the proportional parameter of the controller, K I represents the integral parameter of the controller. We can represent the denominator of Equation (16) in the form of Equation (17).
where ω a1 and ω b1 represent the natural frequencies of the pole; ξ a1 and ξ b1 represent the pole damping coefficient.
According to the equivalence of corresponding terms, Equation (18) holds.
According to references [15,23], there are three different pole assignment strategies, which are the same amplitude, the same real part and the same damping coefficient. In this paper, the pole assignment method with the same amplitude is selected to design the controller parameters. The so-called pole assignment strategy with the same amplitude means that the poles have the same radius. Therefore, substituting ω a1 = ω b1 into Equation (18), Equation (19) can be obtained.
According to Equation (19), the expression of controller parameters can be obtained. Therefore, the controller parameters can be adjusted by changing the pole damping coefficient.

Controller Parameters Tuning Based on BP Neural Network
Neural network has the ability to approximate any nonlinear function and can realize the PI control strategy of the optimal controller parameter combination by learning the system performance. The BP neural network adjusts the PI controller parameters according to the operating state, and then achieves the optimization of a certain performance index. The PI controller using BP neural network is shown in Figure 7.
According to Figure 7, the output state of the neurons in the output layer corresponds to the proportional and integral parameters of the PI controller. Through the self-learning of the neural network and the adjustment of the weighting coefficient, its stable state corresponds to a certain optimal controller parameter. The BP neural network in Figure 7 adopts a three-layer structure, one input layer, one hidden layer and one output layer. The structure of the BP neural network is shown in Figure 8.  In Figure 8, j represents an input layer node, i represents a hidden layer node, and l represents an output layer node. The input layer has m input nodes, the hidden layer has q hidden nodes, and the output layer has two output nodes.
The input node corresponds to the selected system operating state quantity, such as rated input, system output, error, etc. The output nodes correspond to the proportional parameter and integral parameter in the PI controller. Since the controller parameters cannot be negative, the neuron activation function of the output layer takes a non-negative Sigmoid function.
It can be seen from Figure 8 that the output of the input layer of the BP neural network is shown in Equation (20).
The input of the hidden layer is shown in Equation (21).
where ω (2) ij represents the weighting coefficient from the input layer to the hidden layer. The output of the hidden layer is shown in Equation (22).
where g(x) represents the positive and negative symmetric Sigmoid function, and its expression is shown in Equation (23).
The input of the two nodes in the output layer of the neural network is shown in Equation (24).
where ω (3) li represents the weighting coefficient from the hidden layer to the output layer. Thus, two outputs of the output layer can be obtained as shown in Equation (25).
where f (x) represents the neuron activation function of the output layer, and its expression is shown in Equation (26).
The two outputs of the output layer of the BP neural network are the PI controller parameters as shown in Equation (27).
The performance index function selected in this paper is shown in Equation (28).
where, r(k) represents the input node, which is the state quantity of system operation, and y(k) is the output node. The difference of them represents the error. In this paper, r(k) is the expected value of motor speed, and y(k) is the actual motor speed. The gradient descent algorithm is used to modify the weight coefficient of the BP neural network, and its expression is shown in Equation (29).
where η represents the learning rate, ∂ represents the inertia coefficient, which is used to make the contraction converge to the global minimum quickly. According to Equation (29), Equation (30) can be obtained.
Due to the non-linear factors of the flexible joint servo system model, it is difficult to obtain ∂y(k)/∂u(k). We can use Equation (31) as an approximation of ∂y(k)/∂u(k).
Since u(k) and u(k − 1) are very close, it is easy to cause the infinite phenomenon in Equation (31). Therefore, this paper uses Equation (32) instead of Equation (31).
According to the classical incremental numerical PID control algorithm, the expression u(k) can be obtained as shown in Equation (33).
According to Equation (27), Equation (33) can be written in the form of Equation (34).
According to Equations (33) and (35), the weight calculation formula of the output layer of the BP neural network can be obtained as shown in Equation (36).
According to Equation (38), the weight calculation formula of the output layer of the BP neural network can be obtained as shown in Equation (39).
Similarly, the formula for calculating the weight coefficient of the hidden layer can be obtained as shown in Equation (40).
The algorithm of PI controller based on BP neural network is shown below.
(1) Determine the structure of the BP neural network, that is, the number of input nodes m, the number of hidden layer nodes q, and the initial values of the weight coefficients of each layer of the neural network are ω (2) li (0) and ω (3) li (0), and the learning rate η and the inertia coefficient ∂ are selected.
(2) r(k) and y(k) are obtained by sampling, and the time error e(k) is calculated. (3) Calculate the input and output values of each layer of the neural network, and adjust the controller parameters.
(5) Carry out neural network learning and adjust the weighting coefficients online according to Equations (39) and (40) to realize the adaptive adjustment of PID parameters.
In summary, this paper adopts a control strategy based on BP neural network and pole assignment method to control the flexible joint servo system. The control block diagram is shown in Figure 9.

Numerical Simulation Analysis
In order to verify the effectiveness of the proposed control strategy, the simulation analysis of the flexible joint servo system is carried out based on Matlab and Simulink in this paper. Firstly, the influence of friction torque on the flexible joint servo system is illustrated through simulation analysis. Then the influence of different pole damping coefficient on the output of the servo system is analyzed, and the reasonable interval of the pole damping coefficient is given. Finally, the effectiveness of the proposed control strategy is verified by comparing the output errors of different control strategies.

The Effect of Friction on the System
In the robotic arm flexible joint servo system, the servo motor drives the load to rotate. In the process of load rotation, it is affected by friction. In this paper, the Stribeck model shown in Equation (1) is used to describe the friction torque of the load. In order to analyze the influence of friction torque on the flexible joint servo system, the moment of inertia of the motor end is set to 0.05, the moment of inertia of the load end is set to 0.15, and the torsional stiffness of the joint is set to 300. In the simulation process, a sinusoidal signal is selected as the rated input signal of the motor end. Thus, the law of friction torque changing with time can be obtained as shown in Figure 10a. The influence of friction torque on the input torque required by the servo system is obtained as shown in Figure 10b. The influence of friction torque on the servo system is not only reflected in the required input torque. The friction torque also affects the output of the system speed. The influence of friction torque on the load end speed and rotation angle is shown in Figure 10c,d.
According to Figure 10a, it can be seen that when the friction torque changes in the direction of the speed, a sudden change will occur. This sudden change of friction torque is due to the static friction effect. According to Figure 10b, we can see that the sudden change of the friction torque will cause the sudden change of the required input torque, but the controller cannot provide the required driving torque within a short period of time, which will cause fluctuations in the output speed of the servo system. According to Figure 10c, we can clearly see this speed fluctuation. The speed fluctuation will have a certain effect on the angle of rotation, but according to Figure 10d, it can be seen that this effect is relatively weak. In summary, the friction torque received by the flexible joint servo system will affect the input torque and load speed. Therefore, the influence of friction torque cannot be ignored for robots with high accuracy.

The Influence of Pole Damping Coefficient on System Output
The selection of the controller parameters plays a crucial role in the control effect of the flexible joint servo system. In this paper, the pole assignment strategy of the same amplitude is used to roughly design the controller parameters. According to Equation (19), it can be seen that the design of the controller parameters can be transformed into the selection of the pole damping coefficient. Different pole damping coefficient will affect the output of the system. In order to clarify the influence of the value of the pole damping coefficient on the output of the system. Within this paper, the moment of inertia at the motor end is set to 0.05, the moment of inertia at the load end is set to 0.15, and the torsional stiffness of the flexible joint is set to 500. In order to illustrate the influence of the pole damping coefficient, the rated signals of the motor speed are set as a step signal and a sinusoidal signal, respectively. Therefore, the output results of different pole damping coefficients at the motor end and load end can be obtained as shown in Figures 11 and 12. Among them, Figure 11 shows the output results under the step signal and Figure 12 shows the output results of the sinusoidal signal.
According to Figures 11 and 12, the value of the pole damping coefficient will affect the fluctuation of the output speed. This phenomenon is especially obvious under the step signal input. However, the value of the pole damping coefficient has a weaker effect on the angle of rotation. According to Figure 11, the value of the pole damping coefficient, whether too large or too small, will aggravate the fluctuation of the output speed. Based on this, it can be obtained that the ideal value range of the pole damping coefficient is 0.3-0.5 through numerical different simulation experiments. In this interval, the design of the PI controller parameters of the flexible joint servo system can obtain a relatively stable output. (19), it can be seen that the design of the controller parameters can be transformed into the selection of the pole damping coefficient. Different pole damping coefficient will affect the output of the system. In order to clarify the influence of the value of the pole damping coefficient on the output of the system. Within this paper, the moment of inertia at the motor end is set to 0.05, the moment of inertia at the load end is set to 0.15, and the torsional stiffness of the flexible joint is set to 500. In order to illustrate the influence of the pole damping coefficient, the rated signals of the motor speed are set as a step signal and a sinusoidal signal, respectively. Therefore, the output results of different pole damping coefficients at the motor end and load end can be obtained as shown in Figures 11 and 12. According to Figures 11 and 12, the value of the pole damping coefficient will affect the fluctuation of the output speed. This phenomenon is especially obvious under the step signal input. However, the value of the pole damping coefficient has a weaker effect on the angle of rotation. According to Figure 11, the value of the pole damping coefficient, whether too large or too small, will aggravate the fluctuation of the output speed. Based

Joint Control Strategy of BP Neural Network and Pole Assignment
During the movement of the robot, the moment of inertia at the load end of the flexible joint will change. In order to make the robot obtain good output under different working conditions, this paper chooses three different working conditions to carry out simulation experiments. The parameters of the three different working conditions are shown in Table 1. In order to verify the effectiveness of the control strategy proposed in this paper, the joint control strategy of BP neural network and pole assignment, the pole assignment control strategy, and the common PI control strategy are respectively selected to control the flexible joint. The three working conditions in Table 1 are selected for simulation, and the simulation results of different control strategies are obtained as shown in Figures 13 and 14. Figure 13a shows the speed output at the motor end, Figure 13b shows the error of the speed output at the motor end. Figure 14a shows the speed output at the load end, Figure 14b shows the speed error at the load end. During the movement of the robot, the moment of inertia at the load end of the flexible joint will change. In order to make the robot obtain good output under different working conditions, this paper chooses three different working conditions to carry out simulation experiments. The parameters of the three different working conditions are shown in Table 1. In order to verify the effectiveness of the control strategy proposed in this paper, the joint control strategy of BP neural network and pole assignment, the pole assignment control strategy, and the common PI control strategy are respectively selected to control the flexible joint. The three working conditions in Table 1 are selected for simulation, and the simulation results of different control strategies are obtained as shown in Figures 13  and 14. Figure 13a shows the speed output at the motor end, Figure 13b shows the error of the speed output at the motor end. Figure 14a shows the speed output at the load end, Figure 14b shows the speed error at the load end.  According to Figure 13b, taking the maximum error of PI method as the benchmark, the percentage of other methods' maximum errors to it is obtained.
The method of the joint control strategy of BP neural network and pole assignment in different working conditions: 30% (Working condition 1), 32% (Working condition 2) and 38% (Working condition 3).
The method of the joint control strategy of pole assignment in different working conditions: 40% (Working condition 1), 44% (Working condition 2) and 44% (Working condition 3).
According to Figures 13 and 14, the control strategy proposed in this paper has small error under any working conditions, which shows that the control strategy proposed in this paper can effectively reduce the error and improve the control accuracy.

Conclusions
Based on the double inertia system, an integrated joint motor servo system model considering gear angle error and friction interference is established, and a joint control strategy based on BP neural network and pole assignment method is designed to suppress the vibration of the system. The following conclusions can be obtained through simulation analysis: (1) When the friction torque changes in the direction of the speed, a sudden change will occur. This sudden change of friction torque will affect the input torque, and cause fluctuations in the output speed and the output rotation angle of the servo system.
(2) The pole damping coefficient will affect the fluctuation of the output speed. This phenomenon is especially obvious under the step signal input. In the range 0.3-0.5 of the pole damping coefficient, the design of the PI controller parameters of the flexible joint servo system can obtain a relatively stable output.
(3) The control strategy proposed in this paper has small error under different working conditions, which shows that the control strategy proposed in this paper can effectively reduce the error and improve the control accuracy.  According to Figure 13b, taking the maximum error of PI method as the benchmark, the percentage of other methods' maximum errors to it is obtained.
The method of the joint control strategy of BP neural network and pole assignment in different working conditions: 30% (Working condition 1), 32% (Working condition 2) and 38% (Working condition 3).
The method of the joint control strategy of pole assignment in different working conditions: 40% (Working condition 1), 44% (Working condition 2) and 44% (Working condition 3).
According to Figures 13 and 14, the control strategy proposed in this paper has small error under any working conditions, which shows that the control strategy proposed in this paper can effectively reduce the error and improve the control accuracy.

Conclusions
Based on the double inertia system, an integrated joint motor servo system model considering gear angle error and friction interference is established, and a joint control strategy based on BP neural network and pole assignment method is designed to suppress the vibration of the system. The following conclusions can be obtained through simulation analysis: (1) When the friction torque changes in the direction of the speed, a sudden change will occur. This sudden change of friction torque will affect the input torque, and cause fluctuations in the output speed and the output rotation angle of the servo system.
(2) The pole damping coefficient will affect the fluctuation of the output speed. This phenomenon is especially obvious under the step signal input. In the range 0.3-0.5 of the pole damping coefficient, the design of the PI controller parameters of the flexible joint servo system can obtain a relatively stable output.
(3) The control strategy proposed in this paper has small error under different working conditions, which shows that the control strategy proposed in this paper can effectively reduce the error and improve the control accuracy. Data Availability Statement: Some data, models, or code generated or used during the study are available from the corresponding author by request.

Conflicts of Interest:
The authors declare no conflict of interest.