## 4 Weld Seam Tracking  
### Extraction and Preprocessing of Discrete Weld Seam Data Points  
Discrete 3D data points extracted from the weld seam surface often contain noise and significant errors due to measurement inaccuracies and environmental interference. When the robot and sensor are stationary, these errors can be represented by an error sphere. However, during tracking, as the robot and sensor move, the error distribution approximates an error cylinder along the motion direction, with this direction serving as the cylinder's axis. To address this, we propose a cylindrical filtering method to remove these errors. The implementation process of this method is illustrated in Figure 9.  
When the system detects a new data point, \(P_{n}\), principal component analysis (PCA) is employed to linearly fit the previous \(m\) data points, \(P_{n-m}\), \(P_{n-m+1},\ldots,P_{n-1}\), resulting in a spatial line \(l\) that minimizes the fitting error. The direction of the spatial line \(l\) is defined as the cylinder's axis, and the point \(P_{n-m}\) is selected as the center of the cylinder's base. A cylindrical space with a base radius \(r_{0}\) and height \(h_{0}\) is then constructed to determine whether the new data point \(P_{n}\) falls within this cylinder. If \(P_{n}\) is inside the cylinder, it is retained, and the cylinder's radius and height remain unchanged. If \(P_{n}\) is outside  
Figure 8: Results of the V-shaped weld seam feature extraction method. (**a**) Original V-shaped weld seam image, (**b**) rough results obtained by maximum distance search method, and (**c**) optimized results obtained by least-squares fitting.  
the cylinder, both the radius and height are increased by preset increments \(r_{\Delta}\) and h\({}_{\Delta}\), respectively. This process is repeated for subsequent data points.  
After obtaining the principal component direction \(v_{dir}=\left(v_{x},v_{y},v_{z}\right)\) from the mm data points preceding point \(P_{n}\), a cylindrical space is established to eliminate gross error points. This cylinder has point \(P_{n-1}\) as its base center, \(v_{dir}\) as the axis direction, a radius \(r=r_{0}\), and a height \(h=h_{0}\). It is used to determine whether point \(P_{n}\) should be retained for trajectory planning, as shown in Figure 10.  
To assess if \(P_{n}\) lies within the cylindrical space, \(v_{dir}\) is first normalized as follows:  
\[\mathbf{v_{dir}}=\frac{\mathbf{v_{dir}}}{\parallel\mathbf{v_{dir}}\parallel} \tag{19}\]  
where \(\parallel\mathbf{v_{dir}}\parallel\) is the Euclidean norm (magnitude) of the vector \(\mathbf{v_{dir}}\).  
Next, the distances between point \(P_{n}\) and point \(P_{n-1}\) in both the radial and axial directions of the cylinder are calculated as follows:  
Calculate radial distance \(d_{r}\) (perpendicular distance to the cylinder axis)  
\[d_{r}=\frac{\parallel\mathbf{v_{{n}}}\times\mathbf{v_{{dir}}}\parallel}{ \parallel\mathbf{v_{{dir}}}\parallel} \tag{20}\]  
where \(v_{{n}}\) is the vector from point \(P_{n-1}\) to point \(P_{n}\).  
Calculate axial distance \(d_{a}\) (distance along the cylinder axis)  
\[d_{a}=\mathbf{v}_{n}\cdot\mathbf{v_{{dir}}} \tag{21}\]  
By comparing \(d_{r}\) with \(r_{0}\) and \(d_{a}\) with \(h_{0}\), we determine if point \(P_{n}\) is inside the cylinder. If \(d_{r}<r_{0}\) and \(d_{a}<h_{0}\), as shown in Figure 10a, \(P_{n}\) is retained for further trajectory planning. Conversely, if \(d_{r}\geq r_{0}\) or \(d_{a}\geq h_{0}\), as shown in Figure 10b, point \(P_{n}\) is discarded. The cylinder's radius and height are then increased by preset increments \(r_{\Delta}\) and \(h_{\Delta}\), respectively,  
Figure 9: Cylindrical filtering flowchart.  
to update its dimensions. This process is applied to each new data point as it is detected, using the same criteria for evaluation and processing.  
Finally, a mean filtering process is applied to the collected data points to further reduce noise.