# Inverse Kinematics of Large Hydraulic Manipulator Arm Based on ASWO Optimized BP Neural Network
## 4 ASWO-BP Inverse Solution Study  
In order to address the shortcomings of the BP algorithm, such as its tendency to fall into local optima and its weak generalization ability, the ASWO algorithm is used to optimize the weights and biases of the BP neural network. This optimization improves the network's generalization ability and output accuracy. The flow of the algorithm is shown in Figure 6.  
In the ASWO optimization BP neural network algorithm, the data set is first processed to determine the neural network topology, and random positions are generated to represent the search agents, i.e., individual spider bees, in the ASWO algorithm. The initial position of each agent represents a potential solution to the weights and biases in the neural network. Following the ASWO algorithm strategy, the search agents explore and update their positions in the solution space, and each population iteration performs fitness calculations and updates the algorithm parameters, which helps to guide the search agents to evolve towards a better solution and to find the optimal search agent through continuous iterations. Finally, the optimal weights and biases obtained by the ASWO algorithm are used as the initial weights and biases of the BP neural network for training.  
To construct the complete data set that covers the working range of the robotic arm, the complete spatial range reachable by the end of the drilling arm is first determined using the Monte Carlo pseudo-random number method within the range of each joint. During the data set establishment process, the straight-line distance between the rock drill dolly and the boring face is continuously adjusted, and the position points are planned within the coverage of the boring face so that they are evenly spread across it. The total station is used to collect and store the actual position data of the end of the robotic arm, while the control unit of the rock drill cart synchronizes and records the joint values of the robotic arm and the attitude of the end-effector.  
The data set needs to be further processed by converting the attitude data into the 9 elements of the rotation matrix \(\frac{0}{7}R_{3\times 3}\). The theoretical position of the end-effector is obtained by solving the forward kinematics of each set of joint values, and the spatial position error is obtained by subtracting the theoretical position from the actual position for use in the subsequent simulation process.  
A total of 3095 sets of data were collected in this study, covering the entire working space of the robotic arm. Each group contains 7 joint values of the robotic arm, 3 actual position values of the end-effector, 3 theoretical positions, 3 spatial position errors, and 9 data units of the rotation matrix R. Eighty-five percent of the data set was used for training, and the remaining 15% (i.e., 464 data sets) was used for network prediction.  
According to the analysis of multiple rounds of experiments, the optimal hidden layer structure is determined to be 2 layers, the number of nodes is 22 and 18, respectively, the hidden layer adopts the tansig function as the activation function, the number of training iterations is 1500, and the learning rate is set to 0.001, and the topology of the BP neural network is shown in Figure 7.  
Figure 6: Flowchart of the BP neural network algorithm optimized by ASWO.  
In order to find the global optimal solution, the mean square error (MSE) is used as the fitness value. MSE is the average of the squared errors between the predicted and actual values.  
\[\text{MSE}=\frac{1}{n}\sum_{i=1}^{n}\left(\theta_{i}-\hat{\theta}_{i}\right)^{2} \tag{11}\]  
A smaller MSE value means a smaller gap between the predicted and true values, thus indicating a more accurate and better solution. In order to balance the influence of the telescopic and rotational joints on the overall fitness value when calculating the MSE, the two telescopic joints are unified in decimeters, ensuring equal importance of each joint parameter in the optimization process.