Trajectory Planning for Spray Painting Robot Based on Point Cloud Slicing Technique

: In this paper, aiming at the problem of poor quality and low spraying e ﬃ ciency of irregular for complex freeform surfaces, a new spray painting robot trajectory planning method based on point cloud slicing technology is proposed. Firstly, the point cloud data of the workpiece to be sprayed is obtained by laser scanning. The point cloud data is processed to obtain the point cloud model of the sprayed workpiece. Then the section polysemy line is obtained after slice acquisition and section data processing of the point cloud model. The section polysemy line is sampled on average, and the normal vector of all sampling points is estimated. Finally, interpolation algorithm is used to connect the data points to obtain the space trajectory of spraying robot. In addition, the droplet trajectory model for electrostatic spray painting is established. The experimental results show that the method fully meets the requirements of coating thickness and improves the spraying e ﬃ ciency and uniformity of coating.


Introduction
Automatic painting is an important process in the manufacture of many products, such as automobiles, furniture, and airplanes [1].With the development of various science and technology, spraying robots have been widely used, such as in agricultural production [2], pest control [3], art creation [4,5], art restoration [6], etc.People have higher requirements for the spraying quality of the product surface, but the original spraying robot spraying model and the trajectory optimization theory have been unable to adapt to these higher and higher production requirements.To achieve a new spray painting standard and to realize the production target with high efficiency and low cost, research on the new spray modeling and the optimization algorithm and control strategy of the spraying robot with high performance have become focused issues both at home and abroad.
The surface modeling of spraying workpiece is the key of spraying trajectory planning.Because of the diversity and complexity of spraying workpiece, it is not easy to find a complete set of practical surface modeling methods for spraying workpieces [7][8][9].At present, the modeling method based on parametric surface and the surface modeling method based on CAD model are used in spraying robots [10].The modeling method based on parametric surface is based on approximation, and polygons are used to generate curves or surfaces, so as to complete the surface modeling of the workpiece.The parametric surface expression obtained by this method has high precision, but the expression form is very complex, which is difficult to be applied to the surface modeling of complex workpiece with large curvature [11].The surface modeling method based on a CAD model refers to the fact that the CAD model data of the workpiece was obtained before the surface modeling, and the triangular mesh surface is used to approximate the surface of the spraying workpiece, so as to plan the spraying trajectory of the spraying robot [12].Alessandro et al. proposed a practical CAD model-based trajectory optimization method for spraying robot [13].However, how to carry out trajectory planning on free surface without CAD data model is a difficult problem.Therefore, the current surface modeling method is not suitable for surface modeling and trajectory planning of spraying workpiece with large curvature and no CAD model data, which seriously affects the spraying efficiency and effectiveness.After the surface modeling of painting workpiece is completed, the next step is to plan the space trajectory of painting robot, and finding the appropriate space trajectory of painting robot is very important to improve the spraying efficiency and quality [14].In recent years, scholars have made a lot of achievements in the research of spraying robots [15][16][17][18][19][20].Professor Chen Heping's team from the United States optimized the key parameters, thus improving the trajectory optimization method [21].Pal et al. proposed a multi-objective optimization algorithm with spraying time and uniformity of coating thickness as the optimization objectives, but the trajectory optimization method is too complex and has poor practicability [22].In reference [23], a method is presented for lowering the energy consumption and/or increasing the speed of a standard manipulator spray painting a surface.Anurag et al. applied spraying robots to different industries and proposed a new trajectory optimization method adapted to this application field [24].To sum up, most of the current international studies focus on trajectory optimization methods, and there are few studies on the generation of complex surface spray trajectory without CAD data model or large curvature change.Moreover, trajectory optimization methods are too complex and less practical.To obtain better spraying effect, it is necessary to study the surface modeling method of spraying workpiece and the space trajectory planning method of spraying robot.The development of bionic robot technology provides inspiration for the control scheme of spraying robot.For example, apply neuroscience to spray robots, using goal-directed neural circuits to improve spray robots [25].Similarly, the study of the compensation relationship between biological cognition and movement can enhance the cooperative relationship between the joints of the spraying mechanical arm, so as to achieve accurate control of the spray gun position and improve the spraying efficiency [26,27].Living organisms are far superior to state-of-the-art robots as they have evolved a wide number of capabilities that far encompass our most advanced technologies [28].We can get inspiration from the biological principle and combine the biological model with spraying robot control technology.This is a complex process, but it provides a new direction for the improvement and development of spraying robot.
The surface modeling method based on point cloud patchation technology is a surface modeling method based on workpiece scanning system, which is suitable for small batch and many kinds of workpiece surface spraying.The innovation of spraying trajectory planning based on point cloud slicing technology lies in the use of point cloud data as the data format of surface modeling and trajectory generation of spraying robot.The idea of trajectory planning for spray painting robot based on point cloud slicing technique is: first, the point cloud data is obtained by laser scanning the workpiece to be sprayed, and then the point cloud data is reconstructed in three dimensions to complete the surface modeling of the sprayed workpiece.According to the point cloud slicing technique mentioned, the cross-section data of patches can be simplified, smoothed, and segmented, and the effective data points of the workpiece surface can be obtained.We can get the projection point of the end effector on the workpiece surface after these data points are average sampled.These offset data points contain the position and direction information of the end effector in the spraying process.Through the bias algorithm, the offset of the sampling point in the normal direction can be calculated.Finally, the interpolation algorithm is used to connect the logarithmic points to form a continuous spatial trajectory of the robot.When there are more kinds of spraying workpiece or the curvature of spraying workpiece changes greatly, the point cloud technology is suitable for the surface modeling and trajectory planning of the spraying robot.This technique not only reduces the complexity of the spraying process but also controls the position of the spraying gun, thus improving the quality and efficiency of spraying.

Spray Workpiece Surface Modeling
The surface modeling method of spraying workpiece based on point cloud slicing technology is a surface modeling method based on the workpiece scanning system, which can be applied to the surface modeling of spraying workpiece with large curvature changes.By slicing the pre-processed point cloud with the help of data acquisition and data processing technology in reverse engineering, the section profile can be extracted as the initial spraying path of the spraying robot.

Data Acquisition and Processing of Point Cloud Slice of Spraying Workpiece
To reduce the modeling time of complex surface and improve the spraying efficiency, the point cloud data on the surface of complex spraying workpiece can be obtained through the scanning system, and the section data can be directly generated from the point cloud data, and then the section data can be processed.As shown in Figure 1, The steps are as follows: (1) determine the number of slice layers; (2) Separate and calculate the slice data; (3) Polysemy line reconstruction.The specific section modeling process of three-dimensional entity can be referred to the reference [29].

Spray Workpiece Surface Modeling
The surface modeling method of spraying workpiece based on point cloud slicing technology is a surface modeling method based on the workpiece scanning system, which can be applied to the surface modeling of spraying workpiece with large curvature changes.By slicing the pre-processed point cloud with the help of data acquisition and data processing technology in reverse engineering, the section profile can be extracted as the initial spraying path of the spraying robot.

Data Acquisition and Processing of Point Cloud Slice of Spraying Workpiece
To reduce the modeling time of complex surface and improve the spraying efficiency, the point cloud data on the surface of complex spraying workpiece can be obtained through the scanning system, and the section data can be directly generated from the point cloud data, and then the section data can be processed.As shown in Figure 1, The steps are as follows: (1) determine the number of slice layers; (2) Separate and calculate the slice data; (3) Polysemy line reconstruction.The specific section modeling process of three-dimensional entity can be referred to the reference [29].

Determine the number of slice layers
Separate and calculate the slice data The section data obtained after slicing the spraying workpiece usually have problems such as redundancy, noise, and connection errors, which makes it difficult to meet the needs of subsequent spraying trajectory planning.Therefore, it is necessary to process the section data.This process has two main purposes: First, reduce the error of cross-section data and improve the accuracy of trajectory planning.The second is to facilitate the subsequent matching and pose generation, reduce the trajectory generation time, and improve the spraying efficiency.Cross-section data processing mainly includes three steps: point cloud data streamlining, discrete curvature estimation and section data segmentation based on feature points.

Data Streamlining
Point cloud data set of surface shape characteristics of spraying workpiece can be expressed by mathematical expression as: Ω = { ( ,  ,  ) = 1,2 ⋅⋅⋅ }.In the expression, Ω represents a point cloud,  ( ,  ,  ) represents an arbitrary point in the point cloud,  represents the total number of point clouds.We can use the angle method to streamline the cloud data.Figure 2 is a schematic illustration of the angle method.The specific steps are as follows: a) Set the angle threshold as  , . Calculate the corresponding cosine value.As  and  are generally obtuse, so 0 > ( ) > ( ).The section data obtained after slicing the spraying workpiece usually have problems such as redundancy, noise, and connection errors, which makes it difficult to meet the needs of subsequent spraying trajectory planning.Therefore, it is necessary to process the section data.This process has two main purposes: First, reduce the error of cross-section data and improve the accuracy of trajectory planning.The second is to facilitate the subsequent matching and pose generation, reduce the trajectory generation time, and improve the spraying efficiency.Cross-section data processing mainly includes three steps: point cloud data streamlining, discrete curvature estimation and section data segmentation based on feature points.

Data Streamlining
Point cloud data set of surface shape characteristics of spraying workpiece can be expressed by mathematical expression as: Ω = P i (x i , y i , z i )i = 1, 2 • • • n .In the expression, Ω represents a point cloud, P i (x i , y i , z i ) represents an arbitrary point in the point cloud, n represents the total number of point clouds.We can use the angle method to streamline the cloud data.Figure 2 is a schematic illustration of the angle method.The specific steps are as follows: (a) Set the angle threshold as [a min , a max ].Calculate the corresponding cosine value.As α min and α max are generally obtuse, so 0 > cos(α min ) > cos(α max ).
(b) Calculate the cosine of the angle cosα of the adjacent three points P i−1 , P i , P i+1 in the cross section data: cos α = P i−1 P i 2 + P i P i+1 2 − P i−1 P i+1 2 2 P i−1 P i P i P i+1 If P i−1 P i or P i P i+1 is 0, then let cosα = cos(α max ) in order to solve the key issues existing in the patch data.If the cross-section polyline is closed, it is necessary to calculate the cosine of the angle at the starting point P 0 (or terminal point P n ).Then we have i = (1, . . ., n − 1).When i = 0, let P i−1 = P n−1 in order to solve the problem.If the cross-section polyline is not closed, there is no angle at the starting point and the terminal point.Then we have i = (1, . . ., n − 1).

Discrete Curvature Estimation
Discrete curvature estimation is mainly used for denoising, feature extraction and data segmentation for cross-section data.The circular curvature method is used to obtain the discrete curvature of the cross-section data.To facilitate the description, the curvature of the cross-section data is divided into center point and endpoint two cases to discuss.

a) Curvature estimation of the center point
The curvature  of a point  among the middle point array  , . . .,  is determined by the circle obtained by the three adjacent points  ,  ,  , As shown in Figure 3, the formula is as follows: where  is the area of a signed triangle.When  ,  ,  is counterclockwise, the sign is positive.On the contrary, the sign is negative.The sign can be determined by the vector fork.The area of signed triangular can be calculated as follows:

Discrete Curvature Estimation
Discrete curvature estimation is mainly used for denoising, feature extraction and data segmentation for cross-section data.The circular curvature method is used to obtain the discrete curvature of the cross-section data.To facilitate the description, the curvature of the cross-section data is divided into center point and endpoint two cases to discuss.

(a) Curvature estimation of the center point
The curvature C i of a point P i among the middle point array P 1 , . . ., P n−1 is determined by the circle obtained by the three adjacent points P i−1 , P i , P i+1 , As shown in Figure 3, the formula is as follows: where S ∆P i−1 P i P i+1 is the area of a signed triangle.When P i−1 , P i , P i+1 is counterclockwise, the sign is positive.On the contrary, the sign is negative.The sign can be determined by the vector fork.The area of signed triangular can be calculated as follows: b) The curvature estimation of endpoints  and  If the cross-section polyline is closed, then the endpoints  and  are the same point.When  = 0，let  =  so that the curvature of  can be obtained with the Equation ( 3).If the crosssection polyline is not closed, the calculation method for the curvatures of endpoints  and  is: Add a point  and  in the opposite direction of the cut vectors of two endpoints.The curvatures of  and  can be calculated by  ,  ,  and  ,  ,  respectively.Figure 4 shows the curvature estimation for endpoint  , and the unit tangent vector  ⃑ is: Here, ⃑ =   ⃑   ⃑ ,  ⃑ =   ⃑ .Suppose the center coordinate of circle  is ( ,  )，then we have: Solve the equation set above, then we can get: Add a point  in the opposite direction of  ⃑ and make it satisfy ‖  ‖ ‖  ‖.The Equation ( 2) can be used to solve the curvature after three adjacent points  ,  ,  are obtained.Similarly, the curvature of  can be calculated by adding point  .If the cross-section polyline is closed, then the endpoints P 0 and P n are the same point.When i = 0, let P i−1 = P n−1 so that the curvature of P 0 can be obtained with the Equation ( 3).If the cross-section polyline is not closed, the calculation method for the curvatures of endpoints P 0 and P n is: Add a point P 0 − and P n + in the opposite direction of the cut vectors of two endpoints.The curvatures of P 0 and P n can be calculated by P 0 − , P 0 , P 1 and P n−1 , P n , P n + respectively.Figure 4 shows the curvature estimation for endpoint P 0 , and the unit tangent vector t 0 is:  The cross-section characteristic curve is generally the point whose position or tangential vector is continuous.Therefore, the extraction of the feature points on the cross-section curve is dominated by these two types of points.Find the feature points in the section data, then the curve can be divided into multiple segments by referring to these points.The first order difference can be used to calculate the derivative of the discrete curve C at point  :   Here, v 0 = P 2 P 0 × P 1 P 0 , r 0 = O 1 P 0 .Suppose the center coordinate of circle O 1 is (x c , y c ), then we have: Electronics 2020, 9, 908 6 of 18 Solve the equation set above, then we can get: where Add a point P 0 − in the opposite direction of t 0 and make it satisfy ||P 0 − P 0 || < ||P 0 P 1 ||.The Equation ( 2) can be used to solve the curvature after three adjacent points P 0 − , P 0 , P 1 are obtained.Similarly, the curvature of P n can be calculated by adding point P n + .

Cross-section Data Segmentation Based on Feature Points
The cross-section characteristic curve is generally the point whose position or tangential vector is continuous.Therefore, the extraction of the feature points on the cross-section curve is dominated by these two types of points.Find the feature points in the section data, then the curve can be divided into multiple segments by referring to these points.The first order difference can be used to calculate the derivative of the discrete curve C at point P j : C (P j +) = (P j+2 − P j+1 ) + (P j+2 − P j ) P j+1 − P j + P j+2 − P j+1 /2 If the expressions above satisfies C i P j − − C i P j + > L and θ = angle C i P j − , C i P j + > α, then the data point P j is a sharp point, where L and α are the set length and angle threshold respectively.
Similarly, if they satisfy V i P j − ||−||V i P j + ≥ N (N is the set threshold), P j is considered to be the first order continuous point on C.

Experiment on Surface Modeling of Spraying Workpiece
With VC++ 6.0 as the development platform, the trajectory optimization software system based on point cloud slicing technology is designed.The main functions of the surface modeling subsystem in the system include input and output of point cloud data, data acquisition of point cloud patches, and cross-section data processing.
The main functions of the surface modeling subsystem of spraying workpiece are described as follows: 1.
Input and output of point cloud data.For *.txt file format, we use C++ input and output stream function to achieve read and storage of arbitrary point cloud data.

2.
Data acquisition of point cloud patches.Include patch thickness calculation, patching direction definition, plane and point cloud intersection, polyline construction and other functions, which can achieve the slicing of the point cloud model.Polyline construction includes patch data sorting and polyline orientation adjustment.

3.
Cross-section data preprocessing.Include cross-section data streamlining, discrete curvature estimation, cross-section data segmentation and other functions.
The spraying workpiece is shown in Figure 5.The ATOSII three-dimensional optical scanner manufactured by GOM company in German is used as measurement equipment, Point Cloud Model of the Workpiece as shown in Figure 6.The workpiece surface is labeled with black background and white dots.When a scanner scans an artifact in blocks, scan at least three labels at a time.Point cloud data preprocessing is implemented in Imageware.It mainly includes the following four steps:

Data Streamlining
Uniform sampling method, string error method and spatial sampling method can be select to perform data streamlining.The corresponding command is Modify → Data Reduction → Sample Uniform, Modify → Data Reduction → Chordal Error and Modify → Data Reduction → Space Sampling.Among them, the space sampling method can delete the data by setting a distance tolerance, which has a better streamlining effect on the overlapping area of the point cloud.The streamlining effect is also the best.To ensure the quality of follow-up point cloud patches, we usually take space sampling method (distance tolerance is 0.4 mm) for data streamlining.While preserving the shape features, the data of the overlapping area is effectively deleted.The shape of point cloud data after pre-processing is shown in Figure 7.After the pre-processing of point cloud data, point cloud slice acquisition and section data processing are carried out.Taking the z-axis as an example, the slice direction was selected as the z-axis and the slice layer number is 20.The slices of the resulting plastic basin are shown in Figure 8.Because the curvature of the workpiece changes greatly, there are some blind areas in the directions of X, Y and Z slices, but the three slices are complementary.From the experimental results, since most of the painting paths are parallel to each other, the patch can be arranged in a parallel plane which is uniformly distributed along the patching direction.The patching direction is perpendicular to the painting path, which determines the direction of the patch curve.For the same sprayed area, the position and number of patches will change along different directions, so that different sections are obtained.The direction of the generated painting path based on the contour lines of these sections is also different.The number of layers should be determined by factors such as the curvature of the workpiece surface, the diameter of spray painting

Data Interpolation
There will be lost points which need to be interpolated in the groove, hole, and the occluded area of the surface.For scanning line point cloud or section data, we can use Modify → Scan Line → Fill Gap to perform linear or non-linear interpolation.For scattered cloud data, we can use Construct → Cross Section → Cloud Parallel to generate cross-section data.Then we can use Modify → Scan Line → Fill Gap to fill the data.We can also use Construct → Points → Sample Curve or Construct → Points → Sample Surface to discrete fitting curves or surfaces so as to generate missing points.

Data Smooth
To reduce or eliminate noise, we can use Modify → Smooth → Scan to perform smoothing process.If the point cloud has changes in corners, we can also use Modify → Smooth → Scan Between Corners to smooth the data at the transition.

Data Streamlining
Uniform sampling method, string error method and spatial sampling method can be select to perform data streamlining.The corresponding command is Modify → Data Reduction → Sample Uniform, Modify → Data Reduction → Chordal Error and Modify → Data Reduction → Space Sampling.Among them, the space sampling method can delete the data by setting a distance tolerance, which has a better streamlining effect on the overlapping area of the point cloud.The streamlining effect is also the best.To ensure the quality of follow-up point cloud patches, we usually take space sampling method (distance tolerance is 0.4 mm) for data streamlining.While preserving the shape features, the data of the overlapping area is effectively deleted.
The shape of point cloud data after pre-processing is shown in Figure 7.After the pre-processing of point cloud data, point cloud slice acquisition and section data processing are carried out.Taking the z-axis as an example, the slice direction was selected as the z-axis and the slice layer number is 20.The slices of the resulting plastic basin are shown in Figure 8.Because the curvature of the workpiece changes greatly, there are some blind areas in the directions of X, Y and Z slices, but the three slices are complementary.The shape of point cloud data after pre-processing is shown in Figure 7.After the pre-processing of point cloud data, point cloud slice acquisition and section data processing are carried out.Taking the z-axis as an example, the slice direction was selected as the z-axis and the slice layer number is 20.The slices of the resulting plastic basin are shown in Figure 8.Because the curvature of the workpiece changes greatly, there are some blind areas in the directions of X, Y and Z slices, but the three slices are complementary.From the experimental results, since most of the painting paths are parallel to each other, the patch can be arranged in a parallel plane which is uniformly distributed along the patching direction.The patching direction is perpendicular to the painting path, which determines the direction of the patch curve.For the same sprayed area, the position and number of patches will change along different directions, so that different sections are obtained.The direction of the generated painting path based on the contour lines of these sections is also different.The number of layers should be determined by factors such as the curvature of the workpiece surface, the diameter of spray painting and the size of the workpiece.For the workpieces with large curvature changes, the minimum values of all patch thickness can be obtained by adaptive patching techniques.The minimum patch thickness can be used as the patch thickness for uniform slice.

Spatial Trajectory Planning for Spray Painting Robot Based on Point Cloud Slicing Technique
According to the point cloud slicing technique mentioned, the cross-section data of patches can be simplified, smoothed, and segmented, and the effective data points of the workpiece surface can be obtained.We can get the projection point of the end effector on the workpiece surface after these  The shape of point cloud data after pre-processing is shown in Figure 7.After the pre-processing of point cloud data, point cloud slice acquisition and section data processing are carried out.Taking the z-axis as an example, the slice direction was selected as the z-axis and the slice layer number is 20.The slices of the resulting plastic basin are shown in Figure 8.Because the curvature of the workpiece changes greatly, there are some blind areas in the directions of X, Y and Z slices, but the three slices are complementary.From the experimental results, since most of the painting paths are parallel to each other, the patch can be arranged in a parallel plane which is uniformly distributed along the patching direction.The patching direction is perpendicular to the painting path, which determines the direction of the patch curve.For the same sprayed area, the position and number of patches will change along different directions, so that different sections are obtained.The direction of the generated painting path based on the contour lines of these sections is also different.The number of layers should be determined by factors such as the curvature of the workpiece surface, the diameter of spray painting and the size of the workpiece.For the workpieces with large curvature changes, the minimum values of all patch thickness can be obtained by adaptive patching techniques.The minimum patch thickness can be used as the patch thickness for uniform slice.

Spatial Trajectory Planning for Spray Painting Robot Based on Point Cloud Slicing Technique
According to the point cloud slicing technique mentioned, the cross-section data of patches can be simplified, smoothed, and segmented, and the effective data points of the workpiece surface can be obtained.We can get the projection point of the end effector on the workpiece surface after these From the experimental results, since most of the painting paths are parallel to each other, the patch can be arranged in a parallel plane which is uniformly distributed along the patching direction.The patching direction is perpendicular to the painting path, which determines the direction of the patch curve.For the same sprayed area, the position and number of patches will change along different directions, so that different sections are obtained.The direction of the generated painting path based on the contour lines of these sections is also different.The number of layers should be determined by factors such as the curvature of the workpiece surface, the diameter of spray painting and the size of the workpiece.For the workpieces with large curvature changes, the minimum values of all patch thickness can be obtained by adaptive patching techniques.The minimum patch thickness can be used as the patch thickness for uniform slice.

Spatial Trajectory Planning for Spray Painting Robot Based on Point Cloud Slicing Technique
According to the point cloud slicing technique mentioned, the cross-section data of patches can be simplified, smoothed, and segmented, and the effective data points of the workpiece surface can be obtained.We can get the projection point of the end effector on the workpiece surface after these data points are average sampled.Since the position and orientation of the end effector includes both position and attitude parameters, and the slicing data only includes position information, so these data points cannot be used as the position and orientation of the end effector directly.During the operation of the spray painting robot, it is necessary to keep the axis of the end effector perpendicular to the workpiece surface and the distance from the workpiece surface constant.To ensure the uniform painting distribution, a corresponding algorithm has been designed to calculate the offset of sampling point in the normal line direction.These offset data points contain information about the position and orientation of the end effector during the spray painting process.Finally, the interpolating algorithm is used to connect the data points in order to form a continuous spatial path of the robot.

Mathematical Model of the Position and Orientation of End Effector
Suppose the workpiece is stationary in the Cartesian coordinate system XYZ, we can directly get the function expression of the surface as z = h (x, y).Here, the projection is h: D → R (real number field), the domain is D ⊂ R 2 .By the general concept of the set, function expression of the surface can be defined as: S = (x, y, z) z = h(x, y), (x, y) ∈ D} (9) Assuming that the position of the end effector Tool Center Point (TCP) relative to the fixed Cartesian coordinate system XYZ is represented by a three-dimensional vector function P(t).The orientation of the end effector relative to the fixed Cartesian coordinate system XYZ is represented by another three-dimensional vector function O(t).The relationship between these two vectors and time can be expressed as: The vectors P x (t), P y (t), P z (t) represent the position of the end effector in the XYZ coordinate system at time t.The vectors O x (t), O y (t), O z (t) represent the rotation angles of the end effectors around the X, Y and Z axis at time t.This rotation system relative to a fixed coordinate system is generally referred to as a 'rolling, pitching, yawing' system.It is easy to define a rotation matrix based on these angle values, so that the fixed coordinate system can be converted into the rotating coordinate system of the end effector by premultiplying or postmultiplying the matrix.For convenience, a vector function a(t) is defined to generally represent the position and orientation of the end effector.

Spatial Trajectory Acquisition of Spray Painting Robots
The spatial trajectory acquisition of spray painting robots can be divided into three steps: setting the number of sampling points, estimating the normal vector of sampling points, and generating spatial trajectories.

Setting the Number of Sampling Points
We can obtain the projection of the painting trajectory on the workpiece surface after the average sampling of the patches which have already been processed.The number of sampling points (recorded as num) is set by the artificial interaction method.Equation ( 13) is used to calculate the interval distance dm of the sampling points on each patch, and the coordinate data of the trajectory points can be obtained.
where N denotes the number of points on the polyline of the patch, P i and P i+1 denote the i-th and (i+1)-th sampling points on the polyline.

Estimating the Normal Vector of Sampling Points
According to the start point for operation and the moving direction of the end effector on the first painting trajectory, the sorting direction of patch data on the first layer should be determined first.In addition, the sorting direction of patch data on adjacent layer is set in reverse order, so that the Electronics 2020, 9, 908 10 of 18 painting trajectory of the end effector on the workpiece surface can be determined.Painting trajectory is a set of data points formed by a set of patches, known as the sampling point set Q: where x j is the X-coordinate of the j-th patch, i is the number of sampling points on the patch of the i-th layer, y i , z i are the Y-coordinate and Z-coordinate of the sampling point on the i-th layer.There are two main methods for estimating the normal vector of each data point Q i in the sampling point set of the microcutting plane: One is to make use of the neighborhood information of the points.By computing the k-neighborhood of the points, the best approximation plane of the k neighboring points can be constructed by the least squares method.The plane can be regarded as the microcutting plane at this point.The normal vector of the plane is the normal vector of the desired sampling point [30][31][32].
The microcutting plane in this method has ambiguity.To make the plane of the normal vector point to the outside of the surface, we need to adjust the direction of the normal vector.Another method is to use the triangular topology of scattered data, which can be obtained by the normal vector of the relevant triangles of the points.Then the direction of the normal vector can be determined by the direction of the directed triangles directly [33,34].Here, we use this method to estimate the normal vector of sampling point.
As is shown in Figure 9, there are m point P j (j = 1, 2, . . ., m) around the sampling point Q i , which are adjacent to each other.Thus, m related triangles are formed by these points.The unit normal vector of the triangle formed by Q i , P j , P j+1 is Electronics 2019, 8, x FOR PEER REVIEW 11 of 19

Generating Spatial Trajectory
According to the requirements of the spray painting robot, the perpendicular distance from the end effector to the sprayed workpiece surface is set as the parameter Offset Distance, which is denoted as H, while the position and orientation of the end effector can be obtained by the algorithm above.The bias point  of point  can be obtained by setting offset distance H of point  in the direction of normal vector n   . The mathematical expression is as follows: Point  contains the coordinate values and the unit normal vectors, which gives the position (coordinate) and direction (opposite to the direction  ⃗) of the end effector.We can get a set of offset points O by using the same method to traverse all the points in the sampling point set Q.The information contained in the entire point set O represents the position and orientation parameters of the end effector during the spray painting process.Finally, the points are connected to form a continuous trajectory of the spray painting robot by using the spatial line or arc interpolation algorithm.In this expression, (j = 1, 2, . . ., m, and P m+1 = P 1 ).If the area of the triangle is S j , by weighting combination and using σ j = 1/s j as the weighting factor, the normal vector

Generating Spatial Trajectory
According to the requirements of the spray painting robot, the perpendicular distance from the end effector to the sprayed workpiece surface is set as the parameter Offset Distance, which is denoted as H, while the position and orientation of the end effector can be obtained by the algorithm above.
The bias point Q i of point Q i can be obtained by setting offset distance H of point Q i in the direction of normal vector → n .The mathematical expression is as follows: Point O i contains the coordinate values and the unit normal vectors, which gives the position (coordinate) and direction (opposite to the direction → n ) of the end effector.We can get a set of offset points O by using the same method to traverse all the points in the sampling point set Q.The information contained in the entire point set O represents the position and orientation parameters of the end effector during the spray painting process.Finally, the points are connected to form a continuous trajectory of the spray painting robot by using the spatial line or arc interpolation algorithm.
For the point cloud slice shown in Figure 8, the number of data points to be extracted is 20 and the offset distance is 0. The resulting painting trajectory is shown in Figure 10.

Generating Spatial Trajectory
According to the requirements of the spray painting robot, the perpendicular distance from the end effector to the sprayed workpiece surface is set as the parameter Offset Distance, which is denoted as H, while the position and orientation of the end effector can be obtained by the algorithm above.The bias point  of point  can be obtained by setting offset distance H of point  in the direction of normal vector n   . The mathematical expression is as follows: Point  contains the coordinate values and the unit normal vectors, which gives the position (coordinate) and direction (opposite to the direction ⃗) of the end effector.We can get a set of offset points O by using the same method to traverse all the points in the sampling point set Q.The information contained in the entire point set O represents the position and orientation parameters of the end effector during the spray painting process.Finally, the points are connected to form a continuous trajectory of the spray painting robot by using the spatial line or arc interpolation algorithm.

Droplet Trajectory Model for Electrostatic Spray Painting
In modern automobile spraying, in order to improve the use rate of coating, electrostatic spraying method is adopted.There are many electrostatic spraying parameters, compared with air spraying, robot trajectory planning is more difficult [35][36][37].The following is a practical electrostatic spraying trajectory planning method based on the above spraying trajectory planning method.The Lagrangian method is used to simulate the droplet movement trajectory of electrostatic spray painting.Here, we use the improved formation of the Basset-Boussinesq-Oseen (BBO) equation of the well-known particle motion equation in fluid mechanics to describe the trajectory of the electrostatic droplet [38].The improvement is mainly reflected in the BBO equation by taking the

Droplet Trajectory Model for Electrostatic Spray Painting
In modern automobile spraying, in order to improve the use rate of coating, electrostatic spraying method is adopted.There are many electrostatic spraying parameters, compared with air spraying, robot trajectory planning is more difficult [35][36][37].The following is a practical electrostatic spraying trajectory planning method based on the above spraying trajectory planning method.The Lagrangian method is used to simulate the droplet movement trajectory of electrostatic spray painting.Here, we use the improved formation of the Basset-Boussinesq-Oseen (BBO) equation of the well-known particle motion equation in fluid mechanics to describe the trajectory of the electrostatic droplet [38].The improvement is mainly reflected in the BBO equation by taking the influence of the electrostatic field into account.The BBO equation is a form of Newton's second law of motion that contains all the forces acting on the particles, which are steady-state air thrusts F D , buoyancy, virtual inertial forces, Basset forces, gravity F g and electrostatic force F E/S .The improved BBO equation is as follows: In the equation above, u, D g , ρ g , q are the droplet instantaneous velocity, droplet diameter, droplet density, droplet charge respectively.v, D, ρ, t are the particle instantaneous velocity, particle diameter, particle density, particle movement time respectively.µ is the viscosity of the paint.E is the electrostatic potential field.The simplified model of the electrostatic droplet trajectory can be expressed as: Only two major forces will affect the momentum of the droplet, i.e., the thrust of the surrounding turbulent air and the electrostatic force of the charged droplet in the electrostatic field.In addition, turbulent air thrust can be introduced by Stokes law: µ g , D p , f, u − v are the air viscosity, droplet diameter, resistance factor and the relative velocity of ambient air u and droplet v respectively.The resistance factor is defined as follows: Equations ( 21) and ( 22) are based on the instantaneous velocity of the gas, and the instantaneous velocity is shown as (23): u, u are the average gas velocity and the turbulent velocity respectively.The electrostatic force is the product of the droplet charge q and the electrostatic field E, which is the divergence of the electrostatic potential.Therefore, the droplet trajectory equation can be written as: Equation ( 24) is a vector equation, which can be solved by the fixed-step ∆t Euler time integral.

Spraying Experiment
The plastic basin is replaced with a certain brand of car body as the spraying experiment object.Firstly, the three-dimensional optical scanner is used to measure the point cloud data of the experimental vehicle, and then the workpiece point cloud model is obtained by using the automatic point cloud assembly technology of the scanner.The pre-processing of automobile body point cloud data is realized in reverse engineering software Imageware.The car body shape obtained after pre-processing of point cloud data is shown in the prototype system as shown in Figure 11.data is realized in reverse engineering software Imageware.The car body shape obtained after preprocessing of point cloud data is shown in the prototype system as shown in Figure 11.We use ABB electrostatic painting robot to conduct painting experiments on the body, as shown in Figure 12.Multiple ABB spraying robots are used to spray the body in different areas on the same automobile spraying line, as shown in Figure 13.Spraying experiment adopts the droplet trajectory model of electrostatic spraying, and combined with the installation location distribution of ABB robot, the body is divided into three parts: the roof and rear, the left side of the body, and the right side of the body.Trajectory planning is carried out on the three parts by using the trajectory planning method of spraying robot based on point cloud slicing technology.The point cloud model is patched by setting the slicing direction (relative to painting path direction) and patch number (relative to the number of reciprocating strokes).After the polyline of patch is obtained, the average sampling is We use ABB electrostatic painting robot to conduct painting experiments on the body, as shown in Figure 12.Multiple ABB spraying robots are used to spray the body in different areas on the same automobile spraying line, as shown in Figure 13.Spraying experiment adopts the droplet trajectory model of electrostatic spraying, and combined with the installation location distribution of ABB robot, the body is divided into three parts: the roof and rear, the left side of the body, and the right side of the body.Trajectory planning is carried out on the three parts by using the trajectory planning method of spraying robot based on point cloud slicing technology.The point cloud model is patched by setting the slicing direction (relative to painting path direction) and patch number (relative to the number of reciprocating strokes).After the polyline of patch is obtained, the average sampling is performed.Then the normal vectors of all sampling points are estimated.Finally, the spatial path of the spray painting robot is obtained by the interpolation algorithm.In the process of trajectory planning, according to the curvature of different body surfaces, different trajectory spacing is adopted according to the characteristics of the experimental platform.The painting effect is better when the robot end moves at a uniform speed.We use ABB electrostatic painting robot to conduct painting experiments on the body, as shown in Figure 12.Multiple ABB spraying robots are used to spray the body in different areas on the same automobile spraying line, as shown in Figure 13.Spraying experiment adopts the droplet trajectory model of electrostatic spraying, and combined with the installation location distribution of ABB robot, the body is divided into three parts: the roof and rear, the left side of the body, and the right side of the body.Trajectory planning is carried out on the three parts by using the trajectory planning method of spraying robot based on point cloud slicing technology.The point cloud model is patched by setting the slicing direction (relative to painting path direction) and patch number (relative to the number of reciprocating strokes).After the polyline of patch is obtained, the average sampling is performed.Then the normal vectors of all sampling points are estimated.Finally, the spatial path of the spray painting robot is obtained by the interpolation algorithm.In the process of trajectory planning, according to the curvature of different body surfaces, different trajectory spacing is adopted according to the characteristics of the experimental platform.The painting effect is better when the robot end moves at a uniform speed.The spray tracks generated on the right side of the left side of the car roof are shown in Figures 14-16 respectively.Among them, the roof and rear of the vehicle are divided into three tracks, the left part of the vehicle is divided into eight tracks, and the right part of the vehicle is divided into eight tracks.The tracks of different segments are displayed in different colors in the off-line programming system of the spraying robot.The spray parameters corresponding to the track of each part of the body are shown in Table 1, Table 2 and Table 3, respectively.The parameters Del, AM, SA1, SA2, and HV represent the paint flow rate, rotating speed of rotary bell, flow of air 1, flow of air 2, and electrostatic voltage of rotary bell respectively.Air 1 is used to drive the turbine and drive the rotary bell to rotate, air 2 is the shaping air.The paint flow of the yellow track is 0, and there is no spraying at this time, just the position transfer of ABB spraying robot spraying.The tracks of different segments are displayed in different colors in the off-line programming system of the spraying robot.The spray parameters corresponding to the track of each part of the body are shown in Tables 1-3, respectively.The parameters Del, AM, SA1, SA2, and HV represent the paint flow rate, rotating speed of rotary bell, flow of air 1, flow of air 2, and electrostatic voltage of rotary bell respectively.Air 1 is used to drive the turbine and drive the rotary bell to rotate, air 2 is the shaping air.The paint flow of the yellow track is 0, and there is no spraying at this time, just the position transfer of ABB spraying robot spraying.
minimum thickness of the coating is about 10μm.In the actual production process of this brand of cars, the ideal coating thickness is 50 μm, and the maximum allowable deviation thickness is ± 5 μm.
It can be seen from the figure that a few measuring points exceed the upper limit of coating thickness, because these points are at the junction of the complicated surface.In general, the coating thickness basically meets the requirements, and the experimental results verify the effectiveness of the proposed method.In this section, the trajectory optimization method of electrostatic spraying based on the surface modeling of point cloud slices is adopted in the spraying experiment, while the method of trajectory optimization based on CAD surface modeling is adopted in the reference [15][16][17] and [21][22][23][24].In this section, the trajectory optimization method of electrostatic spraying based on the surface modeling of point cloud slices is adopted in the spraying experiment, while the method of trajectory optimization based on CAD surface modeling is adopted in the reference [15][16][17] and [21][22][23][24].Compared the two methods, the approach described in this section has two advantages: (1) In terms of spray efficiency, when spraying a large area of complex curved surface workpiece, since it is not necessary to triangulate the complicated surface, the point cloud section modeling method has high accuracy and speed, which can save about 15% of the system operation time for the same spraying workpiece; (2) In terms of spray effectiveness, after the spraying workpiece surface is segmented, if the spraying trajectory optimization method based on CAD curved surface modeling is adopted, the cumulative thickness uniformity of the coating at the junction between the pieces is poor, and some concave and convex points may even appear on the coating surface of the workpiece, which will affect the appearance of the automobile and other spraying workpiece; By using the trajectory optimization technology of electrostatic spraying based on point cloud slice, the overall coating thickness uniformity of the workpiece is relatively good, which can save about 20% of the coating for the same spraying workpiece.

Conclusions
At present, there are more and more complex spraying parts in industrial production, and traditional modeling and trajectory planning methods are gradually limited.With the upgrade of technology and process, consumers not only have high requirements for product quality, but also have higher pursuit for product appearance.When the product has the same quality, the appearance determines the competitiveness of the product.Aiming at the spraying problem of the workpiece with complicated shape in the process of industrial production, this paper first proposed a surface modeling method based on point cloud slice, and completed the surface modeling through data acquisition and data processing.Then the spraying trajectory planning method was proposed, which adopted the bias algorithm and interpolation algorithm to obtain the spraying robot's spatial trajectory.Finally, the spraying trajectory planning method based on point cloud slice technology and the trajectory model of electrostatic spraying fog drops are combined to carry out the spraying experiment on the automobile.The experimental results show that the method completely meet the requirements of coating thickness, the advantage of this method is to improve the coating uniformity and provide a solution for the modeling of large curvature workpiece or CAD free model.The disadvantage is
‖  ‖ or ‖  ‖is 0，then let   = ( ) in order to solve the key issues existing in the patch data.If the cross-section polyline is closed, it is necessary to calculate the cosine of the angle at the starting point  (or terminal point  ).Then we have  = (1, … ,  − 1).When i = 0，let  =  in order to solve the problem.If the cross-section polyline is not closed, there is no angle at the starting point and the terminal point.Then we have  = (1, … ,  − 1).c) If  ∈ ( ), cos ( ) ,then delete the center point ,that is  =  , . . .,  =  ,  =  − 1.If   ∉ ( ), cos ( ) , let  =  1. d) If i satisfies the termination condition, end the loop.Otherwise, turn to (b) to continue calculation.

Figure 3 .
Figure 3. Curvature estimation of the center point.

Figure 3 .
Figure 3. Curvature estimation of the center point.(b) The curvature estimation of endpoints P 0 and P n

Figure 8 .
Figure 8. Point cloud slice along the Z-axis.

Figure 6 .
Figure 6.Point cloud model of the workpiece.

Figure 6 .
Figure 6.Point cloud model of the workpiece.

Figure 8 .
Figure 8. Point cloud slice along the Z-axis.

Figure 6 .
Figure 6.Point cloud model of the workpiece.

Figure 8 .
Figure 8. Point cloud slice along the Z-axis.

Figure 8 .
Figure 8. Point cloud slice along the Z-axis.

Figure 9 .
Figure 9. Estimation of normal vector of point .

Figure 9 .
Figure 9. Estimation of normal vector of point Qi.

Figure 9 .
Figure 9. Estimation of normal vector of point .

Figure 10 .
Figure 10.Spray trajectory of point cloud patch in Z-axis direction.

Figure 10 .
Figure 10.Spray trajectory of point cloud patch in Z-axis direction.

Figure 11 .
Figure 11.Car body shape after pre-processing of point cloud data.

Figure 11 .
Figure 11.Car body shape after pre-processing of point cloud data.

Figure 11 .
Figure 11.Car body shape after pre-processing of point cloud data.

Figure 14 .
Figure 14.Spray Painting trajectory on the roof and rear part of the automobile.

Figure 15 .
Figure 15.Spray Painting trajectory on the left part of the automobile.

Figure 14 .
Figure 14.Spray Painting trajectory on the roof and rear part of the automobile.

Figure 13 .
Figure 13.Automobile spraying line.The spray tracks generated on the right side of the left side of the car roof are shown in Figures14-16respectively.Among them, the roof and rear of the vehicle are divided into three tracks, the left part of the vehicle is divided into eight tracks, and the right part of the vehicle is divided into eight tracks.

Figure 14 .
Figure 14.Spray Painting trajectory on the roof and rear part of the automobile.

Figure 15 .
Figure 15.Spray Painting trajectory on the left part of the automobile.Figure 15.Spray Painting trajectory on the left part of the automobile.

Figure 15 . 19 Figure 16 .
Figure 15.Spray Painting trajectory on the left part of the automobile.Figure 15.Spray Painting trajectory on the left part of the automobile.Electronics 2019, 8, x FOR PEER REVIEW 15 of 19

Table 1 .
Operating parameters of the spray painting trajectory on the roof and tail.TrajectoryOperating Parameters of Spray Trajectory on the Roof and Tail Parts of the

Figure 16 .
Figure 16.Spray Painting trajectory on the right part of the automobile.