Trajectory Planning of Spray Gun With Variable Posture for Irregular Plane Based on Boundary Constraint

In order to solve the problem of low spraying efficiency and excessive paint waste caused by overspray when the robot automatically sprays irregular plane, a method of spray trajectory planning with boundary-constrained considering spray gun changing posture is proposed. The static spraying model of the spray gun with variable posture, and the dynamic spraying model of the spray gun along the arc path are established separately, an optimization method for the symmetry of coating distribution based on the variable spray angle when the gun spraying along the arc path is proposed. Orthogonal experiment method based on numerical simulation is used to clarify the influence of boundary curve shape and spray gun posture on boundary constraint distance, the prediction of the value range of the boundary constraint distance at the boundary of different curvature radius is realized. Within the range of the value of the boundary constraint, combined with the equal division method of the plane intercept line and the distance search method, a boundary constraint spray path generation algorithm is established by setting a uniform boundary constraint distance value. Finally, a multivariable spraying parameter optimization algorithm based on PSO is established, the spraying velocity, spraying height and spraying angle in the dynamic spraying process are solved, and the coating uniformity is optimized. The effectiveness and feasibility of the proposed spray trajectory planning method is verified by robot spraying experiment for any irregular plane.


I. INTRODUCTION
As an advanced automation equipment, spraying robot is widely used in painting process of automobile, ship, aerospace and thermal spraying process of surface strengthening technology [1]- [3]. Although the manual teaching of spraying robot is still the commonly used programming method, due to the insuperable defects such as long teaching cycle, coating thickness uniformity, spraying efficiency and paint utilization depending on the technical level of teaching workers, the research on off-line programming technology of spraying robot has become a hot spot for scholars at home and abroad [4]- [7]. The planning of spraying path and the optimization of spraying parameters in offline programming technology directly have an important impact on the The associate editor coordinating the review of this manuscript and approving it for publication was Pedro Neto . coating thickness uniformity, spraying efficiency and paint utilization [8].
Hong and Li [9] developed a spiral spray path planning method for the revolving surface, and realized uniform spraying of the revolving surface by optimizing the spacing distance between adjacent paths. Zhao et al. [10], [11] used the plane cutting method based on bounding box to generate the spraying path on each approximate plane patch for the complex surface after topological segmentation, and optimized the spacing distance between adjacent paths and spraying velocity on each patches, so as to effectively improve the coating thickness uniformity. Considering the adverse effect of the geodesic curvature of the spray path on the symmetry of the coating film distribution on both sides of the spray path, Atkar et al. [12] developed a offset spray path generation method based on surface geodesic for the freeform surface, and improved the coating thickness uniformity by optimizing the spacing distance between adjacent paths and the spraying velocity. The above research is to plan a full coverage spraying path for the surface, and start to optimize the spacing distance between adjacent paths and the spraying velocity. Although the method they proposed achieves the goal of improving the coating thickness uniformity, the planned spray path does not consider the boundary constraints and causes the overspray phenomenon to be more serious, which adversely affects the spraying efficiency and paint utilization. In order to solve this problem, the author proposes a spray path planning method based on boundary constraints for workpieces with irregular boundary shapes such as car fenders [13], which reduces spraying time and paint waste by shortening the spray path. Since the boundary shape of the spraying surface and the posture of the spray gun (spraying height and spraying angle) have an important influence on the value of the boundary constraint distance, however, the author did not study the method of setting its value, and because it is easy to generate non-geodetic spray paths, the author similarly, the uneven distribution of the coating film caused by the non-zero geodesic curvature of the spray path has not been studied. The solution of the above problems is very important to ensure the accuracy of film thickness at the boundary of the sprayed surface and the thickness uniformity of the coating inside the surface.
In order to achieve high efficient, high quality and green spraying trajectory planning of irregular plane, based on the concept of boundary-constrained spraying path planning, this paper establishes a static spraying model of the spray gun with variable posture on the plane, and the optimization method of coating distribution symmetry based on variable spraying angle is proposed in this paper. According to the quality requirements of the coating thickness, a method for setting the uniform boundary constraint distance value is established by analyzing the influence of the radius of curvature of the boundary curve and the posture of the spray gun on the boundary constraint distance, and a method to generate spraying path with boundary constraints is further proposed, the coating thickness uniformity is optimized by establishing an optimization algorithm for the spraying height, spraying angle and spraying velocity in the dynamic spraying process with boundary constraints. Finally, taking arbitrary irregular plane as the object, spraying experiments are carried out on the spray trajectory planning methods with and without boundary constraints to verify the effectiveness and feasibility of the method proposed in this paper.

II. STATIC SPRAY MODEL OF SPRAY GUN WITH VARIABLE POSTURE
The static spraying model of the spray gun is the basis of the spray trajectory optimization. At present, β distribution model, elliptical double-β distribution model and Gaussian sum model [14]- [17] and other mathematical model are mainly used to describe coating deposition distribution for various types of spray gun after static spraying, but these models consider fewer controllable parameters of the spray gun, the existing problem can no longer meet the current needs of multi-variable spraying of complex surface. This paper is based on a parabolic model whose torch space shape is a cone, and its expression is: f (x, y) = A[H 2 tan 2 (ϕ/2) − (x 2 + y 2 )]. Under the assumption that the paint flow rate q v and the torch cone opening angle ϕ are constant during spraying, considering the posture of the spray gun relative to the sprayed surface as controllable parameters, namely the spraying height H and the spraying angle α, as shown in Figure. 1(a). After the spray gun sprays the plane statically, the paint deposition model at any point (x, y) within the spray range can be expressed as [18]: where A is constant, the paint deposition model is shown in Figure. 1(b). When the spray gun is spraying at an angle relative to the plane, the paint covering shape formed on the plane is an ellipse, where the major axis a and minor axis b of the ellipse are: In order to simplify the modeling difficulty of the dynamic spraying of the spray gun along the free curve path, linear and circular interpolation methods can be used to approximate the free curve path as a combination of line and circular arc segments. The modeling of the dynamic spraying of the spray gun along the linear path trajectory is relatively mature, so this paper will not go into details, only the modeling method of the dynamic spraying of the spray gun along the arc path trajectory will be discussed. In Figure. 2, suppose the radius of the arc path is r and the center of curvature is O . When the spray gun is spraying dynamically along the arc path, the direction of spray gun velocity v is the tangent direction of the arc path, the radius of curvature of the arc at the point S is r S . Take the direction of the radius of curvature of the arc path as the X axis and the direction of the spray velocity as the Y axis to establish a rectangular coordinate system, where l CD represents the arc length swept by the spray gun at the point S in the spray range. When the spray gun is spraying dynamically along the arc path, the spraying velocity on the same arc is constant, so here can be assumed that the spray gun is fixed, and the spraying process can be regarded as a uniform circular motion of the point S in the spray range around point O . Therefore, the time t for the point S to pass through the elliptical spray range is l CD v S . By integrating (1), the coating thickness model of the point S within the spray range after the spray gun is dynamically sprayed along the arc path is established as: In the above formula, the spraying velocity at the point S and its Y-axis coordinate value are: The arc length swept by the spray gun at the point S is: rs , l CD and p in (7), (8) and (9) are: q and j in (12) are: Substituting (8) into (6), the specific coating thickness expression at the point S in the spray range can be obtained.

B. OPTIMIZATION OF COATING THICKNESS DISTRIBUTION SYMMETRY
When the spray gun sprays vertically along a linear path, the thickness distribution of the coating film on both sides of the path is theoretically symmetrical, and the best coating thickness uniformity effect can be obtained by superimposing the coating film between adjacent spray paths. When the spray gun sprays vertically along a curved path, the thickness distribution of the coating film on both sides of the path is no longer symmetrical because the geodesic curvature of the path is not zero, where thickness of the coating film on the concave side of the path is thicker than that on the convex side, and as the curvature of the path increases, the deviation of the coating film thickness on both sides of the path is also greater [12]. For this reason, if the spray angle is used to adjust the symmetry of the coating film distribution, it may be an effective method to solve the problem of uneven coating film distribution caused by spraying along the curved path.
For this reason, by adjusting the size and direction of the spraying angle α, the coating film thickness peak is in the normal direction of the spraying path to improve the uneven distribution of the coating film caused by the bending of the spraying path. Suppose the target value of the coating film thickness is T d , the coordinate value x 0 of the X axis where the coating thickness peak is obtained by deriving the x in (6), and set x 0 = 0, that is, the coating thickness peak is fixed in the normal direction of spray path and then substitute x 0 = 0 into (6), which is expressed as follows: It can be seen from the above formula that spraying velocity v, spraying angle α and spraying height H satisfy a specific functional relationship. If one of the parameters is known, the other two parameters can be obtained by solving (15). Assuming that the target value of the coating thickness T d = 50µm and the spraying height H = 200mm, the spraying velocity v and the spraying angle α under different curvature radii of the spraying path are obtained by solving (15), and the coating thickness distribution at various path curvature radii are obtained, as shown in Figure. 3. In Figure. 3, the black solid line is the coating thickness distribution curve after optimizing the spraying angle α, and the red dotted line is the coating thickness distribution curve when vertical spraying. It can be seen from Figure. 3 that the asymmetry of the coating thickness distribution on both sides of the arc spray path can be effectively improved by optimizing the spraying angle α, and as the path curvature radius is smaller, the improvement effect is more significant.

IV. SPRAY PATH GENERATION METHOD BASED ON BOUNDARY CONSTRAINTS FOR IRREGULAR PLANE A. THE INFLUENCE OF THE SPRAY GUN POSTURE AND THE CURVATURE RADIUS OF THE BOUNDARY CURVE ON THE BOUNDARY CONSTRAINT DISTANCE
The boundary-constrained spray path is generated based on the boundary curve of the sprayed surface shrinking a certain constraint distance d inside the sprayed surface, therefore, the distance d from the spraying path point at the boundary to the boundary curve in the direction of the radius of curvature of the boundary curve that just meets the minimum coating thickness requirement is defined as the boundary constraint distance. According to the positional relationship of the boundary constraint distance relative to the spraying path, the boundary constraint distance is divided into left and right, they are d 1 and d 2 respectively, the value of which is affected by the spray gun posture and the radius of curvature of the spray path, as shown in Figure. 4. The reasonable value of the boundary constraint distance directly affects whether the quality of the coating thickness at the boundary meets the requirements, numerical simulation method is adopted to clarify its influence law in this paper.
Taking the target coating thickness T d = 50µm and the spray torch cone opening angle ϕ = 28 • as an example, within the variable range of the spray gun parameters H and α, different parameter values of H , α and r are respectively substituted into the above formula of (15), different coating thickness distribution states can be obtained. According to the definition of boundary constraint distance, the boundary constraint distance values of different coating thickness distribution states are measured. According to the principle of orthogonal experiment, two of the three parameters H , r and α are fixed respectively, the third parameter is used as the VOLUME 9, 2021 independent variable, and the boundary constraint distance is a function, the influence law of parameters H , r and α on the boundary constraint distance are analyzed respectively. Since the spraying path at the boundary is generated by shrinking a boundary constraint distance on the basis of the boundary curve, set the radius of curvature of the boundary curve as r d , which satisfies r d = r + d, therefore, by analyzing the influence law of the radius of curvature of the spraying path on the boundary constraint distance, the influence of the radius of curvature of the boundary curve on the boundary constraint distance can be obtained. Figure. 5, Figure. 6 and Figure. 7 respectively show the influence of parameters r d , α and H on the boundary constraint distance.
It can be seen from Figure. 5, Figure. 6 and Figure. 7 that under the premise that α and H are fixed, the boundary constraint distance varies with r d as a power function, when r d is greater than 400mm, the boundary constraint distance changes almost linearly with r d . On the premise that H and r d are fixed, the boundary constraint distance changes linearly with α. On the premise that α and r d are fixed, the boundary constraint distance also changes linearly with H . According to Figure 5, Figure 6 and Figure 7, the influence law of H and α on d with different boundary curve curvature radius r d can be clarified, as shown in Figure 8. Within the variable    the coating thickness effect that meets the spraying quality requirements by optimizing H and α can be obtained.

B. ALGORITHM OF SPRAYING PATH GENERATION BASED ON BOUNDARY CONSTRAINTS
The boundary curve of any irregular plane can be approximately regarded as a combination of several straight line segments and circular arc segments. According to the above analysis, it can be seen that if there are N boundary segments with different r d in the boundary curve, on the premise that H and α are unchanged, there are theoretically N boundary constraint distance values. In order to generate a smooth and continuous spraying path at the boundary, a uniform boundary constraint distance value can be taken at the boundary.
In order to ensure that the coating thickness at any position on the boundary can meet the quality requirements, on the basis of obtaining the boundary constraint distance range of all boundary sections, the smallest value can be taken as the unified boundary constraint distance value d 0 , as shown in the following formula: In the direction of the curvature radius of the boundary curve, based on the boundary curve of the patch, a closed boundary constraint range curve can be obtained to generate the boundary constraint spray path by translating a boundary constraint distance d 0 into the patch, and then the boundary bounding box method is used to determine the length L of the patch, and N planes are used to cut the patch evenly and vertically along the length of the patch to obtain a series of cutting lines, set the cutting density as ρ, and then ρ = L/N . The intersection formed by the cutting line and the boundary curve is the boundary point, and the intersection formed by the cutting line and the boundary constraint range curve is spray path point at the boundary of the patch, let the distance between the two spray path points at the boundary on the ith cutting line be l i (i = 1, 2, . . . , N ), the spacing distance δ between two adjacent spraying paths meets δ ∈ [δ min , δ max ]. In this paper, the equal division method of the intersecting line is used to generate the spray path points inside the patch, and the distance search algorithm is used to generate the spray path. The algorithm flow chart is shown in Figure 9 and the specific algorithm steps are as follows: step.1 Take a corner of the bounding box as the origin O, the length direction of the patch as the X axis, and the width direction as the Y axis to establish a rectangular coordinate system, and set the N cutting lines along the positive direction of the X axis as g 1 , g 2 , . . . , g N , as shown in Figure 10(a).
step.2 N cutting line segments are processed equally, where the equal fraction of the j-th cutting line F j = l j /δ max (j = 1, 2, . . . , N ), the formed bisecting points and boundary path points are spraying path points, the number k j of which satisfies k j = F j +1, finally, the total number K of path points on the patch satisfies K = N j=1 k j as shown in Figure. 10(b).
step.3 Set p = 1, calculate the distances between point O and K path points respectively, take the path point with the shortest distance from point O as the starting point of the spraying path, and number it as S p , the cutting line at the starting point is g j .
step.4 j = j + 1, if j > N , go to step.7, otherwise go to the next step.
step.5 Using point S p as the search center, calculate the distances between point S p and each path point on the cutting line g j , and take the path point with the shortest distance from point S p and not yet numbered in the cutting line g j and number it as S p+1 , p = p + 1, if K = p, then the next step, otherwise go to step.4.
step.8 Using point S p as the search center, calculate the distances between point S p and each path point on the j-th cutting line, and take the path point with the shortest distance from point S p and not yet numbered in the cutting line g j and number it as S p+1 , p = p + 1, if K = p, then turn to step 6, otherwise turn to step.4.
step.9 Regarding the corner connection of two adjacent spraying paths at the boundary of the patch, in order to ensure that the spraying robot maintains good dynamic characteristics and the coating thickness quality at the boundary, the boundary constraint distance at the corner can be set to 0, at the same time, the intersection point of the midperpendicular line connecting the two path points at the boundary and the boundary curve is regarded as the transition path point, connect this point with the two corner path points with a circular arc to realize the arc corner transition of two adjacent spraying paths, as shown in Figure. 10(d).

V. MULTI-VARIABLE SPRAYING PARAMETER OPTIMIZATION ALGORITHM BASED ON PSO
On the basis of planning an irregular plane spraying path based on boundary constraints, in order to achieve the best coating thickness uniformity quality after the spray gun is dynamically sprayed along the path trajectory, it is necessary to optimize the spraying velocity, spraying height and spraying angle during the dynamic spraying process of the spray gun. Since the improved particle swarm algorithm has the advantages of fast convergence speed, strong global search ability, and effectively avoiding premature convergence, here the particle swarm algorithm based on natural selection is used to optimize the spraying parameters, the algorithm flow chart is shown in Figure. 11.
The particle swarm algorithm is to continuously update and iterate the speed and position of the particles, so as to continuously approach the optimal solution. The formula for velocity ζ and position x are as follows: Among them, c 1 and c 2 are learning factors, and λ 1 and λ 2 are uniform random numbers in [0, 1]. The coating thickness uniformity of the sprayed surface is an important indicator to measure the spraying quality. Here, the mean square deviation between the actual coating thickness T i of M discrete points on the patch and the target coating thickness T d is selected to establish the evaluation function, namely: In order to obtain the thickness of the coating film at any point on the patch, it is possible to set a total of N intersecting lines to generate the spraying path, and the surface of the workpiece is divided into m coating thickness overlap intervals, as shown in Figure. 12, according to the principle of coating thickness superposition between adjacent paths, the coating film thickness of any point S in the j-th superposition interval on the i-th intersection line can be expressed as: In order to make the coating thickness in the spraying area meet the quality requirements, an optimization model needs to be established. In this paper, the selected particle swarm algorithm is used to optimize spraying height H , spraying angle α and spraying velocity v, and based on (16), the penalty function term is constructed using Jonies and Houck Method [20] as follows: where τ (k) is the penalty factor.

VI. EXPERIMENT AND ANALYSIS
Set the target coating thickness value T d = 50µm, allowable coating thickness error T = 10µm, spray height H ∈ Taking a boundary irregular plane of a known CAD model as an example, the length and width of the plane are measured by the bounding box method to be 366.5mm and 225.8mm, respectively. The boundary-constrained and non-boundaryconstrained spray trajectory planning methods are used to conduct spraying experiments on the plane respectively. After the experiment, the mean square deviation of coating thickness uniformity, spraying path length and spraying time under the two spraying trajectory planning methods are compared. The spraying path is generated by secondary development using C# language in the offline programming software RobotStudio 6.08, as shown in Figure. 14.
Parameters such as spraying velocity v and spray gun posture (H and α) are calculated by programming the optimization algorithm in Matlab2016. According to the prediction method of the boundary constraint distance range described in this paper and its value setting method, the uniform  boundary constraint distance value of the irregular plane is 13.3mm, and then according to the boundary constraint spraying path generation algorithm described in this paper, the boundary constraint spraying path is obtained, as shown in Figure. 15(a). In this paper, the spacing distance δ = 56.5mm is used to generate non-boundary-constrained spraying path for the irregular plane, and the overspray distance at the corner of the path is 28.3mm, as shown in Figure. 15(b).
Using the robot spraying experiment platform, and based on the above two spraying path planning methods, spraying experiments were carried out with the optimized spraying parameters of vertical spraying and variable posture spraying, as shown in Figure 16. After the experiment, the coating thickness distribution on the sprayed surface was measured by a coating film thickness gauge. Figure 17 shows the coating thickness distribution effects after boundary-constrained variable posture spraying, boundaryconstrained vertical spraying, and non-boundary-constrained vertical spraying. Table 1 shows the results of coating thickness mean square error, spraying path length and spraying time under different spraying path planning methods.  From Figure. 17 and Table. 1, it can be seen that the maximum error of the coating thickness after non-boundaryconstrained vertical spraying is 3.6µm, the mean square error is 1.9µm 2 , the maximum error of the coating thickness after boundary-constrained variable posture spraying is 7.5µm, the mean square error is 3.8µm 2 , the maximum error of the coating thickness after boundary-constrained vertical spraying is 9.3µm, the mean square error is 4.1µm 2 . It can be seen that the thickness uniformity effect of the coating film after the non-boundary-constrained spraying trajectory planning is the best. In the boundary-constrained spraying path planning method, the thickness uniformity effect of the coating film after variable posture spraying is better than the thickness uniformity effect of the coating film after vertical spraying.
In addition, the spraying path length of boundary constraint planning is shortened by 24.6% compared with that of no boundary constraint, the time spent for boundary-constrained variable posture spraying and vertical spraying were reduced by 55.6% and 46.9%, respectively, compared with the time spent for non-boundary-constrained vertical spraying. It can be seen that the spraying efficiency of boundaryconstrained spraying trajectory planning is higher than that of non-boundary-constrained spraying trajectory planning. When the spray gun is continuously spraying along the boundary constraint path, if the flow rate Q of the spray gun is considered to be constant, the shortening of the spraying time means the reduction of the paint waste.

VII. CONCLUSION
(1) Compared with the boundary-constrained vertical spraying trajectory planning for the irregular plane, the boundaryconstrained variable posture spraying trajectory planning method can effectively improve the spraying efficiency and reduce the paint waste caused by overspray.
(2) The spray gun variable posture spraying can obtain better coating uniformity effect than vertical spraying for the boundary-constrained spraying path planning method.
(3) The method proposed in this paper has important guiding significance and reference value for further realization of high-efficiency, high-quality and green painting and cold-hot spraying processes for complex curved surfaces.

APPENDIX
Appendixes, if needed, appear before the acknowledgment. From 2011 to 2015, he was a Lecturer with the Yancheng Institute of Technology, Yancheng, China, where he has been an Associate Professor, since 2016. He is the author of more than 20 articles and more than ten inventions. His research interests include robot integrated manufacturing technology and spray trajectory planning technology.
He received the Third Prize of Jiangsu Science and Technology Progress Award in 2018.
YONGQING YU was born in Shangdong, China, in 1994. He received the bachelor's degree in agricultural mechanization and automation from Shandong Agricultural University, Tai'an, China, in 2018. He is currently pursuing the master's degree in mechanical engineering with Jiangsu University, Zhenjiang, China. He is the author of more than three articles and more than three inventions.
XUEYA ZHAO was born in Jiangsu, China, in 1989. She received the bachelor's degree in electronic information engineering from Sanjiang University, Nanjing, China, in 2013, and the master's degree in mechanical engineering from the Nanjing Institute of Technology, China, in 2016. From 2016 to 2019, she served as an Assistant Teacher with the Yancheng Institute of Technology, China. Since 2020, she has been a Lecturer with the Yancheng Institute of Technology. Her research interests include robotics programming and design and electrical control and PLC applications.
YI LIU was born in Anhui, China, in 1996. He received the bachelor's degree in mechanical design manufacture and automation from Anhui Xinhua University, Hefei, China, in 2019. He is currently pursuing the master's degree in mechanical engineering with the Yancheng Institute of Technology, Yancheng, China. His research interests include spray trajectory planning technology and spray simulation technology.
JIUXUAN LIU was born in Henan, China, in 1997. He received the bachelor's degree in mechanical design, manufacturing and automation from Liaocheng University, in 2020. He is currently pursuing the master's degree in mechanical engineering with the Yancheng Institute of Technology, Yancheng, China. His research interest includes robot spraying trajectory planning technology.
DEZHI LIU was born in Jiangsu, China, in 1996. He received the bachelor's degree in industrial engineering from the Yancheng Institute of Technology, Yancheng, China, in 2018, where he is currently pursuing the master's degree in mechanical engineering. His research interest includes machine vision.