# A Neural Network Based Approach to Inverse Kinematics Problem for General Six-Axis Robots
## 4 Implementation
### IKP Simplification and NN Training  
As mentioned above, the performance of the trained neural network will be unimaginably poor if we fit the IKP of Xarm6 with a single NN directly. In this study, the strategies, joint space segmentation, are employed to simplify the problem and improve the performance. On the one hand, although the IK function is extremely complicated in the whole joint space, if we only focus on a small subspace of IKP, we will obtain a relatively simple IK function and the NN would give reliable results. Based on this idea and experiments, we divide the joint space of Xarm6, as listed in Table 3. As a result, from the first joint to the last one, the allowed joint ranges of motion are separated into the following parts: 2, 2, 2, 3, 4, and 2, with 192 subspaces being generated in total. It is noteworthy that, the amount of subspaces for joint space division is a hyperparameter for the problem which requires tuning by experiments. An advice is applying an even division step, such as \(60^{\circ}\), for each joint at first, randomly picking one divided subspace then, and fitting it with a simple MLP, such as our 3-layer MLP. This can help to figure out the complexity of IKP for a specific case, and also strategies for further adjustment. Furthermore, after selecting the basic category of neural networks, there are also two kinds of configurations available for application, namely, single joint model and all joint model. The difference is vividly depicted by Figure 2, of which NNs can be regarded as all joint model for 5-DoF robots and single joint model for 6-DoF robots, respectively. Since the single joint model approximates the solution with six sets of weights, the precision is expected to be improved, as proved in [16]. However, for six NNs in need, the overall training cost of the single joint model is several times higher than its all joint model's counterpart. In a previous study, both NN models were investigated on Xarm6 for the optimal performance and the results coincide with aforementioned hypothesis. In addition, one interesting phenomenon was that the well-trained NN from all joint model can make reliable predictions for the first five joints. However, the result for the last joint was less accurate. Thus, instead of using the single or all joint model solely, as shown in \begin{table}
\begin{tabular}{c c c} \hline \hline
**Joint Number** & **Goal Range** & **After Dividing** \\ \hline
1 & (0, 360\({}^{\circ}\)) & (0, 180\({}^{\circ}\)) (180, 360\({}^{\circ}\)) \\
2 & (0, 90\({}^{\circ}\)) & (0, 60\({}^{\circ}\)) (60, 90\({}^{\circ}\)) \\
3 & (\(-\)180, \(-\)90\({}^{\circ}\)) & (\(-\)180, \(-\)120\({}^{\circ}\)) (\(-\)120, \(-\)90\({}^{\circ}\)) \\
4 & (0, 180\({}^{\circ}\)) & (0, 60\({}^{\circ}\)) (60, 120\({}^{\circ}\)) (120, 180\({}^{\circ}\)) \\
5 & (0, 180\({}^{\circ}\)) & (0, 45\({}^{\circ}\)) (45, 90\({}^{\circ}\)) (90, 120\({}^{\circ}\)) (120, 180\({}^{\circ}\)) \\
6 & (0, 360\({}^{\circ}\)) & (0, 180\({}^{\circ}\)) (180, 360\({}^{\circ}\)) \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Joint space division of Xarm6. Figure 2, a five output MLP was trained to predict the inverse kinematics solutions of the first five joints while the last joint was handled separately. Additionally, the complexities of IK function also vary from different subspaces in Table 3. Hence, apart from the amount of neurons per layer being kept as a constant, the number of hidden layers and the training set is not fixed during the learning process. As a default setting, three hidden layers, 600 maximum epochs, and 80,000 sets of training data are configured during the learning process. If a subspace turned out to be challenging, the default configurations will be adjusted according to the performance with an upper bound as:  
* The maximum iteration epochs: 2000;
* The maximum amount of hidden layers: 5;
* The maximum amount of training data: 200,000.