Research on Collision Detection Method of Contact On-line Measurement

In order to avoid collision and improve the safety of on-line measurement, a contact on-line measurement collision detection method is studied. Firstly, according to the structural characteristics of the probe and workpiece, the dynamic collision detection between the probe and workpiece is transformed into static collision detection by using the discrete method, and then the grid division of the collision detection space is carried out by using the space division method. Finally, the dynamic collision detection between the probe and workpiece is transformed into the intersection judgment between simple geometry, and according to different collision accuracy requirements, Hierarchical collision detection combining rough detection and fine detection is carried out. Experimental results show that the hierarchical collision detection algorithm has high detection speed and accuracy.


Introduction
In the process of planning the measurement path, it is necessary to carry out dynamic collision detection on the moving track of the probe to ensure the safety of the measurement path. In order to solve the problem of dynamic collision detection, it is generally necessary to transform it into static collision detection [1] . The main methods are continuous method and discrete method. Scanning volume method is widely used in continuous method [2,3] . The detection accuracy of scanning volume method is high, but the generated scanning volume is irregular geometry, which makes it difficult to achieve the subsequent geometric intersection interference test. Discrete method [4,5] can transform dynamic collision detection into static collision detection by discrete motion process and ensure detection accuracy by adjusting the spacing between discrete points. Commonly used static collision detection methods are divided into two categories: one is surround box method [6][7][8] , which is based on the shape of the object and surrounds the object with a simple polyhedron. By calculating the distance between the surround boxes, it can determine whether the object collides or not, mainly for objects with regular geometrical characteristics. One kind of [9][10][11] is space division method, which divides the space required for collision detection into homogeneous simple geometric elements in advance and determines whether an object collides according to whether it belongs to the same space element or not. In order to realize static collision detection, the interference judgment of the relevant geometry is also required. At present, the research on geometric intersection interference at home and abroad mostly focuses on the intersection of triangle pairs [12][13][14] and the intersection between polyhedrons [15][16][17] . In this paper, a collision detection method is studied. First, the probe model is simplified, the dynamic collision detection between probe and workpiece is transformed into the judgment of intersection between simple geometries by using discrete method and space division idea, and the relevant intersection detection method is put forward. According to different requirements of collision accuracy, a hierarchical collision detection algorithm combining rough detection with fine detection is designed. Increase the speed of crash detection.

Collision Detection Principle
The collision detection between the probe and the workpiece involved in this paper is dynamic collision detection. Therefore, the dynamic collision detection between the workpiece and the probe is converted into static collision detection by using the discrete method. Considering the safety of the workpiece and the probe, the speed change distance is set as discrete interval. During online measurement, collision detection is divided into rough collision detection and fine collision detection according to different collision detection accuracy required for different path planning sections. Rough collision detection is mainly used in the path where the probe moves between the characteristic surfaces. In order to ensure safety, it is necessary to maintain a certain distance between the probe and the workpiece to be measured. Therefore, only the intersection test between the probe and the spacedivided grid is required for collision detection during the path planning process of the probe moving between the characteristic surfaces to ensure the feasibility of the grid intersecting with the probe. Rough collision detection mainly carries out two kinds of intersection interference judgment: the intersection test of rectangle and cylinder and rectangle and ball. Fine collision detection is mainly used in the path of interior measuring points of probe traversal characteristics. According to the measurement requirements, when the probe moves on the path traversing the measuring point inside the characteristic, it must contact the surface of the workpiece to be measured to obtain the actual measuring point coordinates. Therefore, in the path planning process of the probe traversing the measuring point inside the characteristic, in addition to rough collision detection, it can quickly delete the parts which cannot be collided. It is also necessary to test the intersection of triangular facets and probes contained in the grid that intersect with the probe in the rough collision detection process, i.e. fine collision detection. Fine collision detection mainly carries out two kinds of intersection interference judgment: triangle and cylinder, triangle and ball. The contact online measurement path planning collision detection process is shown in figure 1.

Space and Grid Size Determination for Collision Detection
To simplify static collision detection, a grid with each side parallel to the coordinate axis is used to divide the space. Before space division, it is necessary to determine the space range and grid size of collision detection so as to calculate the number of grids and realize space division. The space range is determined by the AABB (Axis-Aligned Bounding Box) surrounding box of the workpiece to be measured. In this paper, only the direct contact between workpiece and worktable is considered. In order to reduce the calculation of collision detection, the range of probe motion is restricted above the contact surface between workpiece and worktable, so the space of collision detection only considers the upper part of the contact surface. In order to ensure the safety of measurement path, the ABB surrounding box of the workpiece to be measured is extended outwards to obtain the required pre-contact distance and the space range of collision detection. The probe moves fast in the path between the characteristic surfaces, so it is necessary to ensure that the probe has a certain distance from the surface of the part. The planned path of the probe moving between the characteristic surfaces will directly avoid the grid containing the workpiece model to be measured. Therefore, the distance between the probe moving between the characteristic surfaces and the part surface and its length planned in this paper largely depend on the size of the grid. Considering that a pre-contact distance will be set before the probe contacts the measuring point to prevent damage to the probe and the machine tool caused by excessive impact force when the probe contacts the parts, twice the pre-contact distance is selected as the grid size in this paper.

Feasibility Analysis of Grid
In order to reduce the number of subsequent intersection tests, the feasibility of grids will be analyzed in advance in this paper. The grids that are completely inside the model will be marked as 1 (infeasible), the grids on the workpiece surface will be marked as 0.5 (not fully feasible), and the grids that are not intersected with the workpiece will be marked as 0 (feasible). The steps to determine the feasibility of the grid are as follows: Step 1: Mark the grid on the surface of the part. Traverse the triangle face, and according to the number of AABB enclosure boxes of the triangle face to reduce the number of grids to be intersected for the test, the grids that intersect the triangle face enclosure box to be intersected with the triangle face are tested. As shown in figure 2, the grids that interfere with the triangle face are marked with 0.5 and the number of the triangle face is recorded.
Step 2: Divide the grids into layers. Determine the boundaries of the grid marked 0.5 in the Z-axis direction, record the boundaries in the Z-axis direction corresponding to the X and Y coordinates, and divide the grid into layers according to the Z-axis coordinates; Step 3: Mark the grid completely inside the part. Determine the boundary of each layer according to the grid marked 0.5. Mark the grid within the boundary of each layer and within the Z-axis boundary as 1. Step 4: Mark viable grids. Mark the unmarked grid as 0; Step 5: Output the feasibility analysis results.

Probe Model Simplification
As shown in figure 3(a), the probe mainly consists of a measuring base, a cyclone, a measuring pin and a measuring ball. Considering the shape and size of the relevant parts, in order to reduce the amount of calculation in the process of collision detection, a cylinder is used instead of a measuring pin. The measuring ball is modeled by a sphere. The simplified model of the probe is shown in figure  3

Intersection Test of Cuboid and Cylinders
Define a cylindrical C . The center of the bottom circle is 、 . Radius: ;Define a cuboid R whose sides are parallel to the coordinate axis. Eight vertices are When the cuboid R and cylinder C intersects, there must be a point inside the cuboid R whose distance to the cylinder axis is less than and the foot point is located between the line segments , so using the expansion method, the surface of the cuboid R is expanded outward by the distance , so that the intersection problem is transformed into judging whether the expanded round edge cuboid R interferes with the line segment .Because the intersection test between cuboid and cylinder involved in this paper is mainly used for collision detection of probe moving path planning between characteristic surfaces and rough collision detection of probe traversing feature internal measuring point path planning, the relevant detection is mainly used to ensure safety, but the detection accuracy is not high, so in order to speed up the detection, the expanded circular rectangle R is used in this paper. Simplified to a straight rectangular R as shown in figure 4.  Figure 4. Schematic diagram of expansion method for testing the intersection test between cuboid and cylinder. The steps to judge whether cuboid R and cylinder C intersect are as follows: Step 1: find the cuboid R after the expansion distance r of orientation vertex coordinates. The method is shown in Formula (1): Where x 、x 、y 、y 、z 、 is cuboid R . Maximum of vertex coordinates on X, Y and Z aixes; is the outward collision distance of the cuboid, that is, the radius of cylinder C ; Step 2: Judge the end point of line segment is in cuboid R internal. If there is an end point in the cuboid R internal, then cylinder C and cuboid R intersection, skip to step 5; Step 3: Determine the line segment and cuboid R Intersection, the main steps are as follows: first: End with endpoint of segment , the ray expression in the direction of line segment is R • (1≥ 0), the equations of six planes on the surface of cuboid R are solved together with R in turn. If none of the solutions exists, then the line segment and cuboid R do not intersect, jump to Step4, On the contrary, the solution will be recorded in the array T, the size of T is the number of solutions; second: According to the elements in the array T, substitute the expression R to calculate the coordinates of each intersection point, and judge whether the intersection point is on the surface of cuboid R , if all points of intersection are not at the cuboid R Surface, then line segment and cuboid R does not intersect, jump to Step4, On the contrary, it will be in the cuboid R Points on the surface are recorded in the array P. The size of P is the number of points. third: According to the elements in the array P, the distance to the endpoint is calculated in turn to judge whether the distance is less than or equal to the length of line segment , If all distances are greater than the length of line segment , line segment does not intersect cuboid R , On the contrary line segment intersects cuboid R ; fourth: Output judgement.
Step 4: If the line segment intersects with the cuboid R , the cylinder C intersects with the cuboid R . On the contrary, the cylinder C does not intersect with the cuboid R ; Step 5: Output judgement.

Intersection Test of Rectangles and Balls
Define a ball S . The ball center is: . Radius: ;Define a cuboid R whose sides are parallel to the coordinate axis. Eight vertices are  、  、  、  、  、  、  、  . When the cuboid R and ball S intersects, there must be a point inside the cuboid R whose distance to the ball center is less than , 6 so using the expansion method, the surface of the cuboid R is expanded outward by the distance , so that the intersection problem is transformed into judging whether the ball center is inside the expanded circular edge cuboid R . Because the intersection test between cuboid and ball involved in this paper is mainly used for collision detection of probe moving path planning between characteristic surfaces and rough collision detection of probe traversing feature internal measuring point path planning, the relevant detection is mainly used to ensure safety, but the detection accuracy is not high, so in order to speed up the detection, the expanded circular rectangle R is used in this paper. Simplified to a straight rectangular R as shown in figure 5.

Figure 5. Schematic diagram of expansion method for intersection test of cuboids and balls.
Judge whether the cuboid R and the ball S intersect, that is, judge whether the ball center v of the ball S is inside the straight side cuboid R after expansion according to formula (2). The steps to judge whether triangle T and cylinder C intersect are as follows:

Intersection Test of Triangle and Cylinder
Step 1: Find the intersection of the plane Π where the triangle T is located and the straight line where the line segment v v is located, as shown in figure 6 (a). If the intersection exists, and the intersection is located inside the triangle T and on the line segment v  v  at the same time, that is, when the shortest distance from the line segment v  v  to the triangle T is 0, the triangle T intersects with the cylinder C , jump to step 7; Step 2: Calculate the foot point and distance from the endpoint of line segment v  v  to the plane of triangle T , as shown in figure 6 (b). If there is a foot point inside triangle T and its corresponding distance is less than or equal to r, triangle T intersects cylinder C , jumps to step 7; jump to step 7; Step 3: Find the foot point (intersection) and distance from the line where the line segment v  v  is located to the line where the edge of triangle T is located, as shown in figure 6 (c). If there is a foot point (intersection) on the edge of line segment v  v  and the corresponding triangle T at the same time, and the corresponding distance is less than or equal to r, triangle T intersects cylinder C , jump to step 7; Step 4: Find the foot point and distance of the line from the endpoint of line segment v  v  to the edge of triangle T , as shown in figure 6 (d). If there is a foot point on the edge of triangle T and its corresponding distance is less than or equal to r, triangle T intersects cylinder C , jump to step 7; Step 5: Find the foot point and distance from the vertex of triangle T to the line where line segment v  v  is located, as shown in figure 6 (e). If there is a foot point on line segment v  v  and its corresponding distance is less than or equal to r, triangle T intersects cylinder C , jump to step 7; Step 6: Find the distance between the endpoint of line segment v  v  and the vertex of triangle T , as shown in figure. 6 (f). If the distance is less than or equal to r, triangle T and cylinder C intersect, On the contrary, triangle T and cylinder C do not intersect; Step 7: Output judgement.

Intersection Test of Triangle and Ball
Define a triangle T . The three vertices are: v 、v 、v . The normal vector is: n , the plane is: Π ; Define a ball S . The ball center is: v . Radius: r. When triangle T and ball S When triangle T intersects ball S , that is, the truncated circle of plane Π where ball S and triangle T are located intersects triangle T , as shown in figure 7, In this paper, the intersection test of triangle and ball is transformed into judging whether a circle on the same plane intersects with a triangle. The steps to judge whether triangle T and ballr S intersect are as follows: Step 1: Coordinate conversion. In order to quickly find the truncated circle of plane Π and ball S , the coordinates of plane Π are converted to a position parallel to XOY plane, and the same conversion is performed on ball center v , as shown in figure 8.
Step 2: Find the truncated circle C of plane Π and ball S . If z  z  r, then the triangle T does not intersect with the ball S , jump to step 5. On the contrary, find the truncated circle C of plane Π and ball S . The calculation method of relevant parameters of truncated circle C is shown in formula (3) and formula (4): Where, v represents the center coordinate of the truncated circle C ; x  , y  , z  represents the coordinates of the spherical center v of the ball S after coordinate conversion; r  represents the radius of the truncated circle C ; z  represents the z-axis coordinate value of the point on plane Π after coordinate conversion.  Figure 8. Schematic diagram of relative position relationship between plane and sphere after coordinate conversion.
Step 3: Judge whether the truncated circle C and triangle T intersect. According to the relative relationship between the center of truncated circle C and triangle T and the relative relationship between the center of truncated circle C and the three sides of triangle T , the steps to judge whether truncated circle C and triangle T intersect are as follows: first: Judge whether the center of truncated circle C is inside triangle T . If so, truncated circle C intersects triangle T , jumps to third; second: Calculate the distance from the center of the truncated circle C to the three sides of the triangle T in turn. If the distance is less than or equal to the radius  of the truncated circle C , the truncated circle C and the triangle T intersect. On the contrary, the truncated circle C and the triangle T do not intersect third: Output judgement.
Step 4: If the truncated circle C intersects the triangle T , the triangle T intersects the ball S . on the contrary, the triangle T does not intersect the ball S ; Step 5: Output judgement. Figure 9 shows the triangular mesh model of the workpiece to be tested and the number of features to be tested. According to the characteristic dimensions of the workpiece to be tested, the safety distance is 50mm, the pre contact distance is 10mm and the speed change distance is 6mm. Figure 9. Structural diagram of workpiece to be tested. In order to analyze the hierarchical collision detection method proposed in this paper, relevant collision detection tests are carried out on a computer with Intel i7-7700hq CPU and 8g memory. Under the condition of consistent model quality, the number of triangular patches constituting the sphere model varies with the sphere radius. This paper adopts the collision detection algorithm of spatial division combined with triangular patch intersection test (algorithm 1), the collision detection algorithm of bounding box combined with geometric element intersection test method in this paper (algorithm 2), and the collision detection algorithm of spatial division combined with geometric element intersection test method in this paper (algorithm in this paper), Collision detection is carried out for multiple relative position relationships between spheres with different radii and probes, and the differences in efficiency and accuracy of each method are compared. It can be seen from table 1 that algorithm 1 uses the intersection test of triangular patches directly, and the error rate is 2%. Algorithm 2 and the algorithm in this paper use the intersection test method of geometric elements, and the error rate is 0; Comparing the average processing time of algorithm 2 and the algorithm in this paper, it can be seen that the method of space division can improve the efficiency of collision detection; The average processing time of this algorithm is significantly less than that of the other two algorithms. In conclusion, the hierarchical collision detection algorithm proposed in this paper has high detection speed and accuracy.

Conclusion
In this paper, the collision detection problem in the path planning process of contact on-line detection is studied. The collision detection between probe and workpiece involved in this paper is dynamic collision detection, which is transformed into static collision detection by discrete method. For static collision detection, in order to improve the efficiency, firstly, this paper uses the method of space division to divide the space to be detected into grids with the same size, then simplifies the probe into a model composed of sphere and cylinder, and finally, with the help of the idea of hierarchical collision detection, according to the different detection accuracy required in each detection stage, The collision detection process is simplified into rough collision detection of intersection interference between cuboid and cylinder and sphere and fine collision detection of intersection interference between triangular patch and cylinder and sphere, and relevant interference judgment methods are proposed. The experimental results show that the collision detection algorithm in this paper is effective and fast.