## 4 Software System
### Pose Calculation Based on Normal Vectors  
Each point on the spraying path has an associated normal vector \(\mathbf{N}_{W}\) that defines the spraying direction in the external work coordinate system. The robotic arm performs the spraying operation along the path defined on the surface of the lasted upper, while the fixed spray tool must remain aligned with the surface normals to ensure uniform adhesive coverage. The pose of the robotic arm at each path point is typically represented by a combination of position and orientation, where the position is already defined by the transformed path points. The orientation is computed based on the local surface normal vector and the tangent vector along the path. To achieve this, the normal vector and tangent vector are combined to construct a local orthonormal frame, which is then converted into ZYX Euler angles to represent the desired orientation. These Euler angles are used as inputs to the robot controller to achieve accurate pose execution. The computational steps for determining the Euler angles are as follows:  
Let \(\mathbf{P}_{i}\) represent one of the path points in \(\mathbf{P}_{W}(\mathcal{X},\mathcal{Y},\mathcal{Z})\) with the associated normal vector \(\mathbf{\mathcal{N}}_{i}\), and \(\mathbf{P}_{i+1}\) is its next path point. 1. Calculation of the tangent vector \(\mathbf{T}\): it represents the direction of the robotic arm's motion path: \[\mathbf{T}=\frac{\mathbf{P}_{i}-\mathbf{P}_{i+1}}{\|\mathbf{P}_{i}-\mathbf{P}_{i+1}\|}\] (9)
2. Vector \(\mathbf{T}\) must satisfy the condition of being perpendicular to the normal vector \(\mathbf{T}\cdot\mathbf{\mathcal{N}}_{i}=0\). To ensure that the system meets this orthogonality condition, we apply the Gram-Schmidt orthogonalization method to adjust the normal vector as follows: \[\mathbf{\mathcal{N}}_{i}^{\prime}=\frac{\mathbf{\mathcal{N}}_{i}-(\mathbf{\mathcal{N}}_{ i}\cdot\mathbf{T})\mathbf{T}}{\|\mathbf{\mathcal{N}}_{i}-(\mathbf{\mathcal{N}}_{i}\cdot\mathbf{T}) \mathbf{T}\|}\] (10) Then, the orthogonality condition \(\mathbf{T}\cdot\mathbf{\mathcal{N}}_{i}^{\prime}=0\) can now always be satisfied. 3. Calculation of the binormal vector \(\mathbf{B}\): \[\mathbf{B}=\mathbf{T}\times\mathbf{\mathcal{N}}_{i}^{\prime}\] (11)  
Figure 21: Coordinate frame transformation chain from the tool to the external work coordinate. Formulation of the rotation matrix \(\mathbf{\mathcal{R}}\): the orthogonal vectors \(\mathbf{T},\mathbf{B}\), and \(\mathbf{\mathcal{N}}_{i}^{\prime}\) serve as the basis for describing the robotic arm's rotational orientation. \[\mathbf{\mathcal{R}}= \begin{bmatrix}T_{\mathbf{\hat{s}}}&B_{\mathbf{\hat{s}}}&\mathcal{N}_{ i\mathbf{\hat{s}}}^{\prime}\\ T_{\mathbf{\hat{\tau}}}&B_{\mathbf{\hat{\tau}}}&\mathcal{N}_{i\mathbf{\hat{\tau}}}^{\prime}\\ T_{\mathbf{\hat{\tau}}}&B_{\mathbf{\hat{\tau}}}&\mathcal{N}_{i\mathbf{\hat{\tau}}}^{\prime} \end{bmatrix} \] (12)
5. Derive the ZYX-sequence Euler angles from the rotation matrix \(\mathbf{\mathcal{R}}\): \[roll=arctan2\big{(}T_{\mathbf{\hat{\tau}}}\,\ T_{\mathbf{\hat{s}}}\big{)}\] (13) \[pitch=arctan2\Big{(}-T_{\mathbf{\hat{\tau}}}\,\ \sqrt{B_{\mathbf{\hat{\tau}}} ^{2}+\mathcal{N}_{i\mathbf{\hat{\tau}}}^{\prime 2}}\Big{)}\] (14) \[yaw=arctan2\Big{(}B_{\mathbf{\hat{\tau}}}\,\mathcal{N}_{i\mathbf{\hat{\tau}}}^{ \prime}\Big{)}\] (15)  
After converting the surface normal vector at each point on the spraying path into ZYX Euler angles, the resulting position \(\mathbf{P}_{W}\) and orientation can be transmitted to the robotic arm for execution. Each computed spraying point is formatted into the KUKA robot's E6 POS structure, which encapsulates a complete six-dimensional pose comprising both position and orientation. The ZYX Euler angles (_roll_, _pitch_, _yaw_), derived from the local surface frame, are directly mapped to the A, B, and C components of the E6 POS structure, respectively.