## 3 Controller Design
### Bpnn-Pid  
The neural network has a strong self-adaptive ability and can be combined well with other control methods [18]. On the basis of PID control, in order to optimize the performance of the controller, the online learning type BP neural network ANN1 was applied.  
The BPNN-PID controller consisted of two parts: the PID controller and the BP network ANN1. The PID controller directly controlled the controlled object in the closed loop, and the BPNN adjusted the three parameters of the PID controller in real time according to the error function J.  
The structure of the neural network ANN1 is shown in Figure 7.  
The input and output of the network are  
\[\left\{\begin{array}{cc}\mathcal{O}_{i}(t)=\left[\begin{array}{cc}R(t)&E(t) &F(t)\end{array}\right]^{T}\\ net_{k}(t)=\left[\begin{array}{cc}k_{p}&k_{i}&k_{d}\end{array}\right]^{T} \end{array}\right. \tag{15}\]  
where \(t\) is the discrete time series (\(t=1,2,3...\)); \(R(t)\) is the set force at time \(t\); \(E(t)\) is the error at time \(t\); \(F(t)\) is the actual output force at time \(t\); and \(k_{p},\ k_{i},k_{d}\) indicate the proportional, integral and differential parameters of the PID controller, respectively.  
The activation function of the hidden layer was the tanh function. Since PID parameters cannot be negative, the activation function of the output layer was taken as a sigmoid function. Based on the previous paper [30], other parameters of the neural network were determined, as shown in Table 1.  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Type** & **Value** \\ \hline Learning type & Online \\ Learning rate (\(\eta\)) & 0.3 \\ Inertia index (\(\alpha\)) & 0.15 \\ Number of hidden layer neurons & 8 \\ Hidden layer activation function & Tanh \\ Output layer activation function & Sigmoid \\ Initialization weight method & 0.03 rands(n, 1) 1  \\ \hline \hline \end{tabular}
\end{table}
Table 1: Parameters of neural network ANN1.  
Figure 7: Schematic diagram of the neural network ANN1’s structure, part of the BPNN-PID controller depicted in Figure 6.  
The incremental PID control algorithm is used for calculating the control voltage _Uc(t)_:  
\[U_{c}(t)=U_{c}(t-1)+\left[\begin{array}{cc}E(t)-E(t-1)&E(t)&E(t)-2E(t-1)+E(t-2) \end{array}\right]\cdot net_{k}(t) \tag{16}\]  
The error function / [18; 19] is expressed as  
\[J=\frac{1}{2}(R(t)-F(t))^{2} \tag{17}\]  
According to the gradient descent method, the weights of the output layer and hidden layer of the network are adjusted in turn, and an inertia term \(\alpha\Delta\omega(t-1)\) is added to avoid falling into the local minimum:  
\[\Delta\omega(t)=-\eta\frac{\partial J(t)}{\partial\omega}+\alpha\Delta\omega (t-1) \tag{18}\]  
In Equation (18), \(\Delta\omega(t)\) is the weights adjusting value; \(\eta\) is the learning rate; and \(\alpha\) is the coefficient of inertia.  
In application, this BPNN-PID control algorithm could be roughly divided into the following steps, as shown in Figure 8:  
1. Determine the structure of the BP neural network. The parameters of the neural network are listed in Table 1;
2. Give the initial value of each layer's weights;
3. The input data _R(t)_, _F(t)_ is sampled, and the error _E(t)_ is calculated;
4. Calculate the input and output values of each layer of neurons, and the output values of the output layer are PID parameters \(k_{p},\ k_{i},k_{d}\);
5. Calculate the control voltage _Uc(t)_ based on the incremental PID control algorithm;
6. Perform online learning of neural networks, and adjust the weights of the hidden layers and the output layer;
7. Return to Step 3 for the next round of training.  
Figure 8: ANN1 training flowchart.