Five-axis tool retracting method based on genetic algorithm
Patent Information
- Application Number
- CN202511372527.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-24
- Publication Date
- 2026-10-13
- Estimated Expiration
- 2045-09-24
AI Technical Summary
[0002]五轴数控机床在加工过程中,如突发停电、故障停机等事故后,在继续加工之前需要将刀具从停机时所处的位置退出,目前针对五轴退刀多数时候需要依靠人工实现,尤其依赖操作者的经验,退刀过程存在效率低、碰撞风险高、非最优路径等问题
不受限于初始刀具位姿,可在任意位置实现退刀;
Smart Images

Figure CN121480633B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of CNC machining technology, and particularly relates to a five-axis feed and retraction method based on a genetic algorithm. Background Technology
[0002] In the event of a sudden power outage or machine malfunction during machining on a five-axis CNC machine, the tool needs to be retracted from its initial position before resuming machining. Currently, tool retraction in five-axis machining often relies on manual intervention, heavily depending on the operator's experience. This process suffers from low efficiency, high risk of collisions, and suboptimal tool paths. While automatic five-axis tool advance / retract technology exists, its mainstream approach involves advancing / retracting along the tool vector. However, this method cannot guarantee the minimization of the planned path, and the feasibility of the advance / retract path depends on the initial tool pose. If the retraction exceeds the machine's travel range, the tool vector cannot be automatically adjusted. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this invention provides a five-axis tool advance and retraction method based on a genetic algorithm. This method enables tool retraction at any position and automatically selects the optimal retraction trajectory, preventing collisions during the retraction process and thus improving retraction efficiency.
[0004] In order to achieve the objective of this invention, the following solution is proposed: A five-axis tool feed / retract method based on a genetic algorithm includes the following steps: Step 1: Workpiece spatial discretization processing, including: G-code parsing, acquisition of point data and voxelization processing; The tool is defined as a cylinder, and the tool path is segmented using a linear sampling method. The number of segments is based on the three-dimensional voxel resolution. The set of voxels covered by the tool at path point P(i) is V(i) = {If V(i) ∩ {occupied voxels} ≠ ∅, then a collision occurs}. Step 2: Gene encoding processing. Each individual's chromosome is encoded as a path point sequence: Path = [P0, P1...Pn]. The starting point P0 of the path is fixed as the starting point of the forward and backward movement Ps, and the ending point Pn is fixed as the target point Pe. Step 3: Population initialization process: Randomly generate GroupSize individuals, calculate the fitness of each initial individual, and select GroupSize individuals with higher fitness to form the initial population; Step 4: Gene recombination treatment. Based on individual fitness, two different individuals are randomly selected using a roulette wheel method for gene recombination. Step 5: Gene mutation. Mutate the individual's genes with the mutation probability "P_mutation". The mutation strategy is dynamically adjusted according to the individual's status. Step 6: Natural selection, sorting the fitness of individuals in the population, and selecting individuals with good fitness from the population to form a new population; The steps 4, 5, and 6 are solved iteratively. When the fitness does not improve for M consecutive iterations or reaches the maximum number of iterations K, the iteration is terminated and the path is output.
[0005] The beneficial effects of this invention are as follows: Unrestricted by the initial tool position, tool retraction can be achieved at any position; It can automatically select the optimal retraction trajectory to prevent collisions during the retraction process, thus helping to improve retraction efficiency. Attached Figure Description
[0006] The accompanying drawings described herein are merely illustrative of selected embodiments, not all possible implementations, and are not intended to limit the scope of the invention.
[0007] Figure 1 A flowchart of the tool retraction method of this application is shown; Figure 2 This diagram illustrates the segmentation of a path using a linear sampling method. Figure 3 A schematic diagram of the dynamic search space constraints for the cutting tool is shown. Figure 4 A schematic diagram showing the tool search space, workpiece geometry, and collision elements is provided. Figure 5 A schematic diagram of random multipoint crossover in gene recombination is shown; Figure 6 A diagram illustrating mutation strategies along the gradient descent direction in gene mutations is shown. Figure 7 A schematic diagram of the roulette strategy in natural selection is shown; Figure 8 A schematic diagram illustrating the geometric description of the tool and workpiece entities in the simulation is shown; Figure 9 A schematic diagram of the workpiece solid after being pixelated from a cube mesh is shown; Figure 10 A schematic diagram of the simulation output path with a population size of 20 is shown; Figure 11 A schematic diagram of the simulation output path with a population size of 10 is shown; Figure 12 The simulation output path diagram is shown for a population size of 50. Detailed Implementation
[0008] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the implementation methods of the present invention will be described in detail below with reference to the accompanying drawings. However, the embodiments described in this invention are only some embodiments of the present invention, and not all embodiments.
[0009] Example 1: A five-axis tool feed / retract method based on a genetic algorithm, comprising the following steps: Step 1: Workpiece spatial discretization processing, including: G-code parsing, acquisition of point data and voxelization processing; Define the tool as a cylinder, with the cylinder's diameter D being a user-defined value; for example... Figure 2 As shown, the tool path is segmented using a linear sampling method. The number of segments is based on the three-dimensional voxel resolution, i.e., DxDyDz. The set of voxels covered by the tool at path point P(i) is V(i) = {If V(i)∩{occupied voxels}≠∅, then a collision occurs}.
[0010] This step discretizes the workpiece space and extracts the positioning information from the G-code program to construct a spatial model of the workpiece. The specific process is as follows: Input: G-code toolpath point set; Output: Voxel mesh parameters; The grid resolution is Dx, Dy, and Dz, which can be set by the user. The resolution must be less than or equal to the machine tool machining accuracy. The number of grid cells is set as follows: NumX=[(Xmax -Xmin) / Dx] NumY=[(Ymax-Ymin) / Dy] NumZ=[(Zmax-Zmin) / Dz]; The indexing rules are as follows: Point P(x, y, z) --> voxel index (⌊(x-Xmin) / Dx⌋, ⌊(y-Ymin)) / Dy⌋, ⌊(z-Zmin) / Dz⌋); To improve indexing speed, point data is represented by a spatial block array, SpaceArray=[Nx, Ny, Nz], where Nx, Ny, Nz are the maximum dimensions of the three axes of the spatial coordinate system, starting from 0, i.e.: X=[0Nx], Y=[0Ny], Z=[0Nz]. The block size is defined by the user, which determines the resolution of the interferometric detection. With this definition, any point in space can be directly indexed, and the point position is directly expressed according to the spatial axis vector.
[0011] Step 2: Genetic encoding processing. The chromosome of each individual (representing a candidate path) is encoded into a path point sequence: Path = [P0, P1...Pn], where P(i) = (x_i, y_i, z_i, a_i) represents the spatial coordinates (x_i, y_i, z_i) and A-axis angle a_i of the i-th path point (node) on the path, forming a 4D position point sequence, which is used as the gene sequence. The total number of path points N is preset by the user. The starting point P0 of the path is fixed as the tool advance / retreat starting point Ps, and the ending point Pn is fixed as the target point Pe. The C-axis is ignored here because, as a rotation axis, its angle change usually does not directly affect the feasibility of path planning for the linear axes (X, Y, Z) and the A-axis. Therefore, when planning the tool advance / retreat path, the C-axis angle is fixed (usually the C value of the initial or target posture). Before and after path execution, the C-axis is independently adjusted to the required angle.
[0012] Step 3: Population initialization process. Randomly generate GroupSize individuals, calculate the fitness of each initial individual, and select GroupSize individuals with higher fitness to form the initial population.
[0013] Step 4: Gene recombination treatment. Based on individual fitness, two different individuals are randomly selected for gene recombination using a roulette wheel method. To avoid local fitting, each individual needs to be allowed a certain probability of gene recombination.
[0014] Step 5: Gene mutation. Mutate the individual's genes with the mutation probability "P_mutation". The mutation strategy is dynamically adjusted according to the individual's state. The selection rules for gene mutation are: (1) Interfering individuals need to undergo mutation with a higher probability; (2) Non-interfering individuals, if their fitness is less than the median, also need to undergo mutation with a certain low probability; (3) In order to improve the convergence speed, non-collision individuals are mutated along the gradient direction.
[0015] Step 6: Natural selection. The fitness of individuals in the population is ranked, and individuals with high fitness are selected to form a new population. In practice, a roulette wheel selection strategy based on fitness ratio is used. GroupSize individuals with high fitness are selected from the current population to form the next generation. The advantage of the roulette wheel strategy is that it prioritizes retaining individuals with high fitness while ensuring that all individuals have a selection probability, thus avoiding local fitting. A diagram of the roulette wheel strategy is shown below. Figure 7 As shown: individuals are mapped onto a roulette wheel according to their fitness ratio, the roulette wheel pointer is randomized, and then the individual pointed to by the pointer is added to the new population.
[0016] The steps 4, 5, and 6 are solved iteratively. When the fitness does not improve for M consecutive iterations or reaches the maximum number of iterations K, the iteration is terminated and the path is output.
[0017] Specifically, the cylinder diameter defined for the tool is set to the maximum allowable diameter at the initial position, i.e., D=D(findmax). This setting avoids the user having to measure the tool diameter separately.
[0018] As a preferred approach, the collision detection defined in step 2 is performed using the following method: like Figure 3 As shown, the maximum axial constraint of the voxel V(i) covered by the tool at path point P(i) is used as the dynamic search space for collision detection: X ∈ [V(i)_Xmin, V(i)_Xmax] Y ∈ [V(i)_Ymin, V(i)_Ymax] Z ∈ [V(i)_Zmin, V(i)_Zmax], which minimizes the search space and time.
[0019] like Figure 4 As shown, find the distance d between all voxel points in the search space and the central axis of the cylinder. When d is less than the radius R of the cylinder, it is marked as a collision.
[0020] Preferably, in step 3, the path points P(i) = [x_i, y_i, z_i, a_i] of each individual are all within the machine tool's motion range [Xmin, Xmax], [Ymin, Ymax], [Zmin, Zmax].
[0021] Further preferably, in step 3, GroupSize is defined by the user, and it is recommended that the GroupSize be between 10 and 50, preferably 20, 30, or 40. An excessively large GroupSize will increase the iteration time of path planning.
[0022] Preferably, in step 3, the fitness calculation function is as follows: CollisionNum represents the total number of voxel elements where the tool position and workpiece interfere with each other at all path points along the path, and Length represents the total path length. ε: A very small positive number (e.g., 1e-6), to avoid division by zero. α, β: Positive weighting coefficients (α rewards shorter paths, β penalizes collision severity). These need to be adjusted so that the fitness of collision-free paths is significantly higher than that of collision-prone paths.
[0023] As a preferred approach, in step 4, gene recombination is performed using gene crossover, which does not significantly alter an individual's traits. Specifically, for example... Figure 5As shown, the crossover parent selection strategy adopts a roulette wheel selection strategy based on fitness ratio, and selects (GroupSize / 2) to perform crossover operation on the parents; the crossover method adopts a random, multi-point crossover method, exchanging gene fragments of the parents to generate a new offspring.
[0024] Preferably, the gene mutation strategy in step 5 includes: collision-individual mutation and collision-free individual mutation, specifically as follows: When CollisionNum>0, there is a collision. Then, with a high probability, "P_mutation_high" randomly changes the position (x,y,z,a) of one or more points in the path {P1 ->PN} of the individual after removing Ps (starting point) and Pe (ending point), randomly perturbing within the search space constraints. When "CollisionNum == 0", there is no collision, and the fitness of the individual is less than the median fitness of the current population, then with a low probability "P_mutation_low", the position (x, y, z, a) of one or more points in the path {P1 -> PN} of the individual after removing Ps (starting point) and Pe (ending point) is randomly changed. Individuals with fitness above the median fitness are retained. This is to preserve the good traits of the population.
[0025] Further preferred, the gene mutation strategy in step 5 also includes: gradient optimization mutation, where there is no collision when CollisionNum == 0. In order to improve the convergence speed and local optimization capability, deterministic perturbation is preferentially performed along the direction of decreasing path length, rather than completely random mutation.
[0026] Further preferred, gradient optimization mutation, for path point P(i), calculate the gradient "∇L" of the small perturbation "ΔP" with respect to the total path length "L".
[0027] like Figure 6 As shown, the gradient ∇L at point P(i) is approximately the difference between the vectors of the directions of adjacent line segments at P(i): Normalize p∇L, that is: Apply a small perturbation to P(i) along the direction of -p∇L (gradient descent). ("δ" represents the step size, which should be equal to the voxel resolution). Note that the gradient calculation for the rotation angle α is the same as above, i.e. The gradient direction vector of a has only two possibilities: 1 or -1, and can be regarded as a one-dimensional vector.
[0028] Example 2, as Figure 8 As shown, in the analysis and simulation, the tool is described by a cylinder, the black dot represents the tool tip, and the spatial point in the middle is the workpiece entity, which is obtained by parsing the machining code.
[0029] Ps: Initial tool pose; Pe: Target tool pose; Search space: [Xmin, Xmax] [Xmin, Xmax] [Xmin, Xmax] corresponds to [-100, 100] [-100,100] [-140, 60].
[0030] cube mesh voxelization Figure 9 As shown, the voxel resolution is [Dx, Dy, Dz] = [1, 1, 1]. Example
[0031] Based on the descriptions in Embodiment 1 and Embodiment 2, the input parameters are as follows: Path segment N = 5; Population size GroupSize = 20; The probability of a high mutation, P_mutation_high, is 0.1. The probability of low mutation, P_mutation_low, is 0.02. The number of iterations N = 1000; The fitness iteration count up to the final decision point is M = 10; Tool parameters: The tool diameter D = 4.0; Initial tool pose Ps = [-1.256, 6.664, -57, -120]; Target tool pose Pe = [5, -10, -65, 100].
[0032] The output is as follows: Path length: 152.16 mm; computation time: 2.3 s; number of iterations: 59; number of collision checks: 0 (final path). Analysis and simulation are as follows: Figure 10 As shown, the cylinder represents the cutting tool, the black dot represents the tool tip, and the red space point in the middle is the workpiece entity, which is obtained by parsing the machining code.
[0033] Adjusting the population size to GroupSize = 10, the output is as follows: Path length: 262.4 mm; computation time: 1.56 s; number of iterations: 37; number of collision checks: 0 (final path); analysis and simulation are as follows. Figure 11 As shown, this comparison demonstrates that a population that is too small will lead to local fitting, which is not helpful in finding the global optimal solution.
[0034] Adjusting the population size to GroupSize = 50, the output is as follows: Path length: 136.25mm; computation time: 5.61s; number of iterations: 136; number of collision checks: 0 (final path). Analysis and simulation are as follows: Figure 12 As shown in the comparison, it can be seen that increasing the population size will yield a better solution, but the iteration time and number of iterations increase exponentially.
[0035] The above description is merely a preferred embodiment of the present invention and is not intended to be the only or limiting of the invention. Those skilled in the art should understand that various changes or equivalent substitutions made to the present invention without departing from its scope are all within the protection scope of the present invention.
Claims
1. A five-axis tool feed / retract method based on a genetic algorithm, characterized in that, Includes the following steps: Step 1: Workpiece spatial discretization processing, including: G-code parsing, acquisition of point data and voxelization processing; The tool is defined as a cylinder, and the tool path is segmented using a linear sampling method. The number of segments is based on the three-dimensional voxel resolution. The set of voxels covered by the tool at path point P(i) is V(i) = {If V(i) ∩ {occupied voxels} ≠ ∅, then a collision occurs}. Step 2: Gene encoding processing. Each individual's chromosome is encoded as a path point sequence: Path = [P0, P1...Pn]. The starting point P0 of the path is fixed as the entry / exit point Ps, and the ending point Pn is fixed as the target point Pe. Step 3: Population initialization process: Randomly generate GroupSize individuals, calculate the fitness of each initial individual, and select GroupSize individuals with higher fitness to form the initial population; Step 4: Gene recombination treatment. Based on individual fitness, two different individuals are randomly selected using a roulette wheel method for gene recombination. Step 5: Gene mutation. Mutate the individual's genes with a mutation probability "P_mutation". The mutation strategy is dynamically adjusted according to the individual's status. Step 6: Natural selection, sorting the fitness of individuals in the population, and selecting individuals with good fitness from the population to form a new population; The steps 4, 5, and 6 are solved iteratively. When the fitness does not improve for M consecutive iterations or reaches the maximum number of iterations K, the iteration is terminated and the path is output.
2. The five-axis feed / retract method based on a genetic algorithm according to claim 1, characterized in that, The cylinder diameter defined by the tool is set based on the maximum allowable diameter at the initial position.
3. The five-axis feed / retract method based on a genetic algorithm according to claim 1, characterized in that, The collision detection defined in step 2 is performed using the following method: the maximum axial constraint of the voxel V(i) covered by the tool at path point P(i) is used as the dynamic search space for collision detection. X ∈ [V(i)_Xmin, V(i)_Xmax] Y ∈ [V(i)_Ymin, V(i)_Ymax] Z ∈ [V(i)_Zmin, V(i)_Zmax]; Find the distance d between all voxel points in the search space and the central axis of the cylinder. If d is less than the radius R of the cylinder, then mark it as a collision.
4. The five-axis feed / retract method based on a genetic algorithm according to claim 1, characterized in that, In step 3, the path points P(i) = [x_i, y_i, z_i, a_i] of each individual are all within the machine tool's motion range [Xmin, Xmax], [Ymin, Ymax], [Zmin, Zmax].
5. A five-axis tool feed / retract method based on a genetic algorithm according to claim 1, characterized in that, In step 3, the GroupSize size is between 10 and 50.
6. The five-axis feed / retract method based on a genetic algorithm according to claim 1, characterized in that, In step 3, the fitness calculation function is as follows: .
7. A five-axis tool feed / retract method based on a genetic algorithm according to claim 1, characterized in that, In step 4, gene recombination is performed using a gene crossover method.
8. A five-axis tool feed / retract method based on a genetic algorithm according to claim 1, characterized in that, The gene mutation strategies in step 5 include: collision-individual mutation and collision-free individual mutation; When CollisionNum>0, there is a collision. Then, with a high probability, the position (x,y,z,a) of one or more points in the path {P1->PN} of the individual after removing Ps and Pe is randomly changed. If "CollisionNum == 0", there is no collision, and the fitness of the individual is less than the median fitness of the current population, then with a low probability, the position (x, y, z, a) of one or more points in the path {P1 -> PN} of the individual after removing Ps and Pe will be randomly changed. Individuals with fitness above the median fitness will be retained.
9. A five-axis tool feed / retract method based on a genetic algorithm according to claim 1 or 8, characterized in that, The gene mutation strategy in step 5 also includes: gradient optimization mutation, where when CollisionNum == 0, there is no collision, and deterministic perturbation is preferentially performed along the direction of decreasing path length.
10. A five-axis tool feed / retract method based on a genetic algorithm according to claim 9, characterized in that, Gradient optimization of mutation: For path point P(i), calculate the gradient "∇L" of the perturbation "ΔP" with respect to the total path length "L". The gradient ∇L at point P(i) is approximately the difference between the vectors of the directions of adjacent line segments at P(i). .
Citation Information
Patent Citations
Gear cutting tool parameter control system based on bevel angle cutting
CN120286784A
Falling self-locking type remote controller
CN217588761U