# Machine Learning Sequential Methodology for Robot Inverse Kinematic Modelling
## 2 Methodology Structure
### Dataset Generation  
This phase consists of the robot selection and the D-H parameters estimation for the FK dataset creation with a pseudo-random generator. The FK equations compute the Cartesian coordinates from the joints' values using the D-H parameters. The axes X, Y, and Z are defined from the origin of each joint, positioned at the actuator centre: Z is the direction of the joint axis; X is the axis perpendicular to both Z\({}_{i}\) and Z\({}_{i-1}\), from the latter; Y is derived from Z and X axes. The D-H parameters based on the presented axes definition are [37]:  
* **Joint angle \(\theta_{i}\):** rotation angle about the Z\({}_{i-1}\) axis, determined from X\({}_{i-1}\) to X\({}_{i}\). The angle corresponds to the joint value if the joint has a rotary actuator. * 1)th frame to the intersection of the Z\({}_{i-1}\) with X\({}_{i}\). * **Link length \(a_{i}\):** distance along the X\({}_{i}\) axis, from the intersection between the Z\({}_{i}\) and the Z\({}_{i-1}\) axis to the origin of the ith coordinate frame. * **Link twist \(\alpha_{i}\):** rotation about X\({}_{i}\), defined from Z\({}_{i-1}\) to the Z\({}_{i}\) axis. The D-H (\(R^{n\times 4}\)) transformation matrices are obtained in the Equations (1) and (2), where \(k\) is the joint number of the robotic manipulator. The transformation matrices are computed to obtain the relative modeling between consequent joints, since the multiplication of the complete set of matrices generates the model between the base frame and the final joint frame. The homogeneous transformation matrix A is defined based on the D-H parameters as follows:  
\[A_{k}^{k-1}=R(z,\theta_{k})\ T(z,d_{k})T(x,a_{k})R(x,\alpha_{k}) \tag{1}\]  
\[= \begin{bmatrix}c\theta_{k}&-s\theta_{k}\cdot c\alpha_{k}&s\theta_{k}\cdot s \alpha_{k}&a_{k}\cdot c\theta_{k}\\ s\theta_{k}&c\theta_{k}\cdot c\alpha_{k}&-c\theta_{k}\cdot s\alpha_{k}&a_{k} \cdot s\theta_{k}\\ 0&s\alpha_{k}&c\alpha_{k}&d_{k}\\ 0&0&0&1\end{bmatrix}  \tag{2}\]  
where \(c\theta_{k}\) and \(s\theta_{k}\) correspond to the cosine and sine functions of \(\theta_{k}\); \(c\alpha_{k}\) and \(s\alpha_{k}\) correspond to the cosine and sine functions of \(\alpha_{k}\). As stated, the transformation matrix from the end-effector to the base frame may be obtained as a product of matrix multiplication, as:  
\[T_{n}^{0}= \begin{bmatrix}n_{x}&s_{x}&a_{x}&p_{x}\\ n_{y}&s_{y}&a_{y}&p_{y}\\ n_{z}&s_{z}&a_{z}&p_{z}\\ 0&0&0&1\end{bmatrix}  \tag{3}\]  
\[T_{n}^{0}=\prod_{k=1}^{n}A_{k}^{k-1} \tag{4}\]  
where vectors \(n\), \(s\), and \(a\) define the manipulator orientation and vector \(p\) represents the position in Cartesian coordinates. The produced matrix corresponds to the FK equations. Nevertheless, the manual definition of these parameters is a time-consuming activity; considering the novel methodology, an automatic procedure is implemented, as presented in [38]. This is an alternative method for the user, however, a manual approach may also be pursuable if the user aims to insert the D-H parameters or the FK equations, directly. The FK model validation is a critical point in the proposed methodology, due to the data-driven nature of the IK model. The employed dataset needs to be coherent with the reality to prevent misleading results. In fact, the FK validation is carried out with a set of four different trajectories, as shown in Figure 2a-d, with the base reference frame fixed at Zero-World [0; 0; 0; 0; 0; 0]. Furthermore, the robustness of the direct model is assessed by varying the main trajectory parameter on two different levels: reducing (low level) and expanding (high level) by 20% the initial path. This perturbation, arbitrarily selected, permits to evaluate the effectiveness of the direct model in multi-conditions, recreating a set of trajectories in the workspace.