# An Algorithm for Solving Robot Inverse Kinematics Based on FOA Optimized BP Neural Network
## 4 Simulation and Discussion  
In the simulation experiment, based on the Monte Carlo method, 2000 sets of samples are generated in the robot workspace, of which 1950 sets are used as training samples and 50 sets are used as test samples. The robot end position coordinates and fixed angle samples in the training samples are used as the input of the BP neural network, and the joint angle samples of the robot are used as the output of the BP neural network. Then, theFOA algorithm is used to optimize the convergence of the network, and the weights and thresholds of the BP neural network are returned. The training samples are brought into the FOA optimized BP algorithm to train the network. Finally, the test samples are brought into the trained network for testing, and the joint variables of the robot outputted by the test samples are obtained.  
The FOA optimized BP algorithm contains two hidden layers. The first hidden layer has 24 neurons and the second hidden layer has 43 neurons. The number of fruit flies is set to 30, and the number of iterations is set to 50. In order to intuitively reflect the effect of the algorithm proposed in this article, the FOA optimized BP algorithm is compared with the ordinary BP algorithm and the PSO optimized BP algorithm. In the PSO optimized BP algorithm, the number of particles is set to 30, and 50 iterations are set. The learning factor \(c_{1}=c_{2}=2\), and the inertia factor \(w=0.95\), are used.  
After the simulation, the robot joint variables output by the three algorithms are compared with the expected values in the test samples. Table 2 shows the maximum error range and the overall mean square error (MSE) range of each joint in the 50 groups of samples.  
From the results in Table 2, it can be seen that the maximum error range of the joint variables output by the ordinary BP algorithm is [\(-0.2723\), \(0.2977\)], and the range of MSE is [\(6.400\times 10^{-6}\), \(1.983\times 10^{-3}\)]. The maximum error range of the joint variables output by the PSO optimized BP algorithm is [\(-0.1570\), \(0.2022\)], and the range of MSE is [\(6.390\times 10^{-6}\), \(1.116\times 10^{-3}\)]. The maximum error range of the joint variables output by the FOA optimized BP algorithm is [\(-0.04686\), \(0.1271\)], and the range of MSE is [\(2.870\times 10^{-7}\), \(3.258\times 10^{-4}\)].  
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Joint Error** & **BP** & **PSO-BP** & **FOA-BP** \\
**and MSE** & & & \\ \hline \(\Delta\theta_{1}(^{\circ})\) & \(-0.1530\)-\(0.1775\) & \(-0.07472\)-\(0.07594\) & \(-0.02583\)–\(0.03612\) \\ \(\Delta\theta_{2}(^{\circ})\) & \(-0.2723\)–\(0.2977\) & \(-0.1570\)–\(0.2022\) & \(-0.04686\)–\(0.1271\) \\ \(\Delta\theta_{3}(^{\circ})\) & \(-0.11206\)–\(0.2087\) & \(-0.0727\)–\(0.1599\) & \(-0.02986\)–\(0.03678\) \\ MSE & \(6.400\times 10^{-6}\)–\(1.983\times 10^{-3}\) & \(6.390\times 10^{-6}\)–\(1.116\times 10^{-3}\) & \(2.870\times 10^{-7}\)-\(3.258\times 10^{-4}\) \\ \hline \hline \end{tabular}
\end{table}
Table 2: The range of joint error and the range of MSE.  
It can be seen from Figures 7-9 that the output error of the ordinary BP algorithm is the largest, and the output error of the FOA optimized BP algorithm is the smallest. The error distribution of the FOA optimized BP algorithm is relatively uniform. From Figure 10, it can be seen that the MSE output by the FOA optimized BP algorithm is much smaller than the MSE output by the other two algorithms.  
It can be seen that when solving the robot inverse kinematics, the error of the FOA optimized BP algorithm is smaller than that of the ordinary BP algorithm and PSO optimized BP algorithm, and the MSE is also significantly reduced. The FOA optimized BP algorithm can improve the accuracy of solving inverse kinematics. The effectiveness of the FOA optimized BP algorithm in solving the inverse kinematics of the robot is verified.