Numerical control program analysis method and device

By converting and optimizing CNC programs from different brands, the problem of CNC program incompatibility was solved, improving programming and simulation efficiency and accuracy, and providing a visual comparison of the optimization process.

CN121578752APending Publication Date: 2026-02-27GENERAL TECH GRP MASCH TOOL ENG RES INST CO LTD SHANGHAI BRANCH +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511723537.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-21
Publication Date
2026-02-27

AI Technical Summary

Technical Problem

CNC programs are incompatible between different brands of CNC machine tools, and existing simulation software lacks automatic optimization functions, resulting in low programming and simulation efficiency and the difference between programs before and after optimization is not intuitive.

Method used

The first CNC program is mapped to the second CNC program by converting instruction information, and simulation, parameter-level and interactive-level optimization are performed to generate the optimized simulated machining trajectory and visualize the original and optimized trajectory.

Benefits of technology

It improves compatibility with different CNC program formats, increases programming and simulation efficiency, optimizes process visualization, reduces manual adjustment time, and improves programming and simulation accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121578752A_ABST
    Figure CN121578752A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of numerical control programming, and provides a numerical control program analysis method and device. The method comprises the following steps: mapping a first numerical control program into a second numerical control program according to instruction conversion information; simulating the second numerical control program to obtain an original simulated processing track; performing parameter-level optimization and / or interaction-level optimization on the original simulation processing track to obtain an optimized simulation processing track, and visualizing the original simulation processing track and the optimized simulation processing track; wherein the instruction conversion information represents a corresponding relation between the first numerical control program and the second numerical control program; the parameter level optimization comprises at least one of arc-to-small line segment conversion, fine smoothing, coarse smoothing and local point processing; interaction level optimization includes at least one of zoom, rotation, and translation. According to the numerical control program analysis method and device provided by the invention, the numerical control program programming and simulation efficiency and accuracy can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of numerical control programming technology, and in particular to a numerical control program analysis method and apparatus. Background Technology

[0002] CNC programming is similar to computer programming, but different brands of CNC machine tools have different programming syntaxes. This lack of compatibility in CNC programs means that a CNC program written by a user for brand A must undergo a series of tedious manual re-editing processes before it can run on a machine tool for brand B.

[0003] Furthermore, current CNC programming and simulation software on the market only focuses on editing functions and the simulation of graphic trajectories. Even if users observe problems in the CNC program through graphical simulation, they can only manually re-edit the CNC program and generate a new graphic trajectory. However, the differences between the new and old CNC programs cannot be intuitively shown to the user.

[0004] Therefore, improving the efficiency and accuracy of CNC programming and simulation is of great significance. Summary of the Invention

[0005] This application provides a CNC program analysis method and apparatus to solve the problems of incompatibility between CNC programs of different brands, lack of automatic optimization function in existing simulation software, and lack of intuitive comparison between programs before and after optimization, thereby improving the efficiency and accuracy of CNC program programming and simulation.

[0006] Firstly, this application provides a numerical control program analysis method, including: Based on the instruction conversion information, the first CNC program is mapped to the second CNC program; The second CNC program is simulated to obtain the original simulated machining trajectory; The original simulated machining trajectory is optimized at the parameter level and / or interactive level to obtain the optimized simulated machining trajectory, and the original simulated machining trajectory and the optimized simulated machining trajectory are visualized. The instruction conversion information represents the correspondence between the first CNC program and the second CNC program; The parameter-level optimization includes at least one of the following: arc to small line segment conversion, fine smoothing, coarse smoothing, and local point processing; The interaction-level optimization includes at least one of scaling, rotation, and translation.

[0007] According to the CNC program analysis method provided in this application, the step of mapping a first CNC program to a second CNC program based on instruction conversion information includes: Repeat the mapping steps until all lines of code in the first CNC program have been processed to obtain the second CNC program. The mapping step includes: Generate an array of the current line of the first CNC program based on the current line of code of the first CNC program, and traverse each element in the array of the current line; If the first element in the current row array matches the preset regular expression, the first element is used as a real-time parameter variable; if the second element in the current row array does not match the preset regular expression, the second element is used as an instruction variable. Based on the instruction variable, the instruction conversion information, the real-time parameter variable, and the obsolete parameter variable, the current line of code in the first CNC program is mapped to the current line of code in the second CNC program; the obsolete parameter variable is the real-time parameter variable of the previous line of code; The deprecated parameter variables used in the first row of mappings are preset initial values.

[0008] According to a CNC program analysis method provided in this application, before performing parameter-level optimization on the original simulated machining trajectory, the method includes: A first preset point and a second preset point are determined from the original simulated processing trajectory, and the view volume coordinates of the first preset point and the second preset point are determined based on the screen coordinates of the first preset point and the screen coordinates of the second preset point. The coordinate axes of the first preset point and the second preset point are determined based on the view volume coordinates of the first preset point and the view volume coordinates of the second preset point, and the distance between the first preset point and the second preset point is determined based on the coordinate axes of the first preset point and the second preset point. Based on the distance between the first preset point and the second preset point, the rotation angle between the first preset point and the second preset point is determined, and the original simulated machining trajectory is optimized at the parameter level based on the rotation angle.

[0009] According to the CNC program analysis method provided in this application, visualizing the original simulated machining trajectory and the optimized simulated machining trajectory includes: Based on the parameter-level optimization and the coordinate axis coordinates of the original simulated machining trajectory, the original simulated machining trajectory is optimized at the parameter level to obtain the optimized coordinate axis coordinates; Based on the coordinate axes of the original simulated machining trajectory and the optimized coordinate axes, the original simulated machining trajectory and the optimized simulated machining trajectory are visualized.

[0010] According to the numerical control program analysis method provided in this application, the fine smoothing includes at least one of the following: compressing the minimum line segment length, compressing the maximum line segment length, compressing the maximum line segment included angle, compressing the position tolerance, spline segment length limit, and spline segment chord height error; The coarse smoothing includes at least one of the following: compressing the minimum line segment length and compressing the minimum line segment angle.

[0011] According to the numerical control program analysis method provided in this application, the method further includes: Delete the third preset point in the original simulated machining trajectory to determine the optimized simulated machining trajectory; Based on the coordinate axes of the original simulated machining trajectory and the coordinate axes of the optimized simulated machining trajectory, the target code line corresponding to the third preset point in the second CNC program is determined, and the target code line corresponding to the third preset point in the second CNC program is deleted.

[0012] According to a CNC program analysis method provided in this application, visualizing the original simulated machining trajectory and the optimized simulated machining trajectory further includes: Based on the original simulated machining trajectory and the optimized simulated machining trajectory, the optimization information is determined; The optimization information includes at least one of the following: the number of deleted points, the number of original points, and the number of corrected points.

[0013] Secondly, this application also provides a numerical control program analysis device, comprising: The mapping module is used to map the first CNC program to the second CNC program based on instruction conversion information; The simulation module is used to simulate the second CNC program to obtain the original simulated machining trajectory; A visualization module is used to perform parameter-level optimization and / or interactive-level optimization on the original simulated machining trajectory to obtain the optimized simulated machining trajectory, and to visualize the original simulated machining trajectory and the optimized simulated machining trajectory. The instruction conversion information represents the correspondence between the first CNC program and the second CNC program; The parameter-level optimization includes at least one of the following: arc to small line segment conversion, fine smoothing, coarse smoothing, and local point processing; The interaction-level optimization includes at least one of scaling, rotation, and translation.

[0014] Thirdly, this application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement any of the numerical control program analysis methods described above.

[0015] Fourthly, this application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the numerical control program analysis method as described above.

[0016] The CNC program analysis method and apparatus provided in this application map a first CNC program to a second CNC program through instruction conversion information, achieving compatibility between CNC programs of different formats, thereby improving flexibility and applicability. The original simulated machining trajectory is obtained through simulation calculation, and then optimized. The original and optimized simulated machining trajectories are then visualized, allowing users to intuitively compare trajectory differences, thereby shortening adjustment and verification time and improving the efficiency and accuracy of CNC program programming and simulation. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 This is a flowchart illustrating the CNC program analysis method provided in this application.

[0019] Figure 2 This is an example diagram of the CNC program analysis visualization provided in this application.

[0020] Figure 3 This is a schematic diagram of the structure of the CNC program analysis device provided in this application.

[0021] Figure 4 This is a schematic diagram of the structure of the electronic device provided in this application. Detailed Implementation

[0022] In the embodiments of this application, the term "at least one" refers to one or more items, and other quantifiers are similar.

[0023] In the embodiments of this application, the terms "first," "second," etc., are used to distinguish similar objects, and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first" and "second" are generally of the same class, and the number of objects is not limited; for example, the first object can be one or more.

[0024] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0025] Figure 1 This is one of the flowcharts illustrating the CNC program analysis method provided in this application, such as... Figure 1 As shown, the method may include: Step 110: Map the first CNC program to the second CNC program according to the instruction conversion information; Step 120: Simulate the second CNC program to obtain the original simulated machining trajectory; Step 130: Perform parameter-level optimization and / or interactive-level optimization on the original simulated machining trajectory to obtain the optimized simulated machining trajectory, and visualize the original simulated machining trajectory and the optimized simulated machining trajectory; Among them, the instruction conversion information represents the correspondence between the first CNC program and the second CNC program; Parametric optimization includes at least one of the following: arc to small line segment conversion, fine smoothing, coarse smoothing, and local point processing; Interactive-level optimizations include at least one of scaling, rotation, and translation.

[0026] It should be noted that the execution entity of the aforementioned CNC program analysis method is a general-purpose computer tool, which has the ability to perform CNC program conversion, simulate machining trajectories, optimize trajectories, and visualize the results. This computer tool can be used as an accessory to CNC machine tools, as a standalone workstation, or integrated into industrial control systems. For example, this computer tool can be deployed as an accessory on CNC machine tools such as milling machines and lathes; this application does not impose specific limitations in this regard.

[0027] Unless otherwise specified, the following embodiments use an offline analysis tool as the execution subject to illustrate the technical solution of this application.

[0028] Specifically, the first CNC program and the second CNC program refer to CNC codes of different formats, which are not specifically limited in this application.

[0029] The instruction conversion information can be a preset fixed rule table or an external file that users can customize and edit. It can convert the instructions, syntax structure, and parameter format in the first CNC program into the instructions, syntax structure, and parameter format in the second CNC program. For example, the "G43" instruction used for tool length compensation in the FANUC CNC program can correspond to the "G00" instruction in the i5 CNC program. As another example, the format of the instruction conversion information can be {Brand A instruction: its corresponding Brand B instruction}, and this application does not make specific limitations on this.

[0030] The conversion of circular arcs into smaller line segments refers to decomposing or approximating a smooth curve segment generated by a circular arc command in the original simulated machining trajectory into a series of straight line segments. For example, the "G02" and "G03" commands can be converted into the "G01" command to convert a circular arc command into a series of straight line segment commands. This application does not make specific limitations on this.

[0031] Fine smoothing refers to processing the trajectory using methods that require high precision and strict control over the deviation of the original trajectory, in order to eliminate minor jitter, improve surface smoothness, and at the same time maintain the geometric characteristics of the original trajectory as much as possible.

[0032] Coarse smoothing refers to processing a trajectory using a method that has a significant smoothing effect and a high tolerance for deviations from the original trajectory, in order to greatly reduce the number of path points and simplify the trajectory.

[0033] Local point processing refers to operations that adjust specific regions or outliers in a trajectory. For example, users may process specific regions by deleting duplicate points or merging collinear segments; this application does not specifically limit this.

[0034] Interactive-level optimizations can be achieved using the pyopengl module. For example, trajectory rotation is achieved by calling the glRotatef method of pyopengl; trajectory translation is achieved by calling the glTranslatef method of pyopengl; and trajectory scaling is achieved by the glOrthoScaled parameter of pyopengl. This application does not impose specific limitations on these aspects.

[0035] Specifically, in step 110, the offline analysis tool pre-stores instruction conversion information that maps the first CNC program to the second CNC program. This instruction conversion information defines in detail how the instructions, syntax structure, and parameter format in the first CNC program are converted into the instructions, syntax structure, and parameter format in the second CNC program. Based on the instruction conversion information, the offline analysis tool parses each line of instruction in the first CNC program and maps the first CNC program to the second CNC program.

[0036] In step 120, the offline analysis tool can use the pyopengl module to simulate the second CNC program, call the decoded Windows dynamic link library, and generate pyopengl point coordinate values. Then, the machining trajectory is drawn using the coordinate values ​​of the second CNC program, thus obtaining the original simulated machining trajectory corresponding to the second CNC program.

[0037] In step 130, if the part machining standards are not met, the original simulated machining trajectory undergoes parametric-level optimization and / or interactive-level optimization. Parametric-level optimization includes at least one of the following: arc to small line segment conversion, fine smoothing, coarse smoothing, and local point processing. For example, if the original trajectory contains large-radius arcs generated by arc commands, to obtain better surface quality in actual machining, the arcs can be decomposed into a series of straight line segments using "arc to small line segment conversion," thus making the trajectory more refined. Another example is the presence of slight jitter in the original trajectory; "fine smoothing" can make the trajectory smoother without significantly deviating from the original trajectory. Yet another example is the processing of specific areas or abnormal points in the trajectory using "local point processing." Interactive-level optimization includes at least one of scaling, rotation, and translation. For example, in the visualization interface, scaling, rotation, and translation can be used to translate the entire trajectory to a specific starting position in the coordinate system, thereby optimizing the trajectory position.

[0038] Figure 2 This is an example diagram of the CNC program analysis visualization provided in this application, such as... Figure 2 As shown, after completing parameter-level optimization and / or interactive-level optimization, an optimized simulated machining trajectory is generated. Subsequently, to facilitate user comparison and verification of the optimization effect, the offline analysis tool will visually present the original and optimized simulated machining trajectories. Typically, the original trajectory is displayed in one color, while the optimized trajectory is displayed in another color, allowing users to intuitively observe the differences between the two.

[0039] The CNC program analysis method provided in this application maps a first CNC program to a second CNC program through instruction conversion information, achieving compatibility between CNC programs of different formats, thereby improving flexibility and applicability. The original simulated machining trajectory is obtained through simulation calculation, and then optimized. The original and optimized simulated machining trajectories are then visualized, allowing users to intuitively compare trajectory differences, thereby shortening adjustment and verification time and improving the efficiency and accuracy of CNC program programming and simulation.

[0040] In one embodiment, mapping the first CNC program to the second CNC program based on instruction conversion information may include: Repeat the mapping steps until all lines of code in the first CNC program have been processed to obtain the second CNC program. The mapping step may include: Generate an array of the current line of the first CNC program based on the current line of code, and iterate through each element in the array of the current line. If the first element in the current row array matches the preset regular expression, the first element is used as a real-time parameter variable; if the second element in the current row array does not match the preset regular expression, the second element is used as an instruction variable. Based on instruction variables, instruction conversion information, real-time parameter variables, and obsolete parameter variables, the current line of code in the first CNC program is mapped to the current line of code in the second CNC program; the obsolete parameter variables are the real-time parameter variables of the previous line of code. The deprecated parameter variables used in the first row of mappings are preset initial values.

[0041] Specifically, the current line array of the first CNC program refers to the decomposition of a single line of text code in the first CNC program into a series of independent data elements through lexical analysis. For example, the current line code of the first CNC program "G00 X9.239Y3.827" can be parsed into the current line array of the first CNC program, which can be ['G00', 'X9.239', 'Y3.82'].

[0042] Predefined regular expressions refer to predefined rules used to determine the matching of real-time parameter variables and instruction variables.

[0043] Real-time parameter variables refer to parameter values ​​obtained from the first line of CNC program code currently being processed. For example, the format of a real-time parameter variable can be {parameter name (e.g., X, Y, Z): current value}, and this application does not impose any specific limitations on it.

[0044] The format of obsolete parameter variables can be {parameter name (e.g., X, Y, Z): current value}, and this application does not impose specific limitations on this.

[0045] Instruction variables refer to parameter values ​​obtained from the first line of CNC program code currently being processed, which are used to instruct the machine tool to perform specific actions or functions.

[0046] Specifically, the FANUC CNC program is used as the first CNC program and the i5 CNC program is used as the second CNC program. The offline analysis tool reads the first CNC program line by line.

[0047] When the first line of code of the first CNC program is read, the offline analysis tool generates the current line array of the first CNC program based on the current line code ";G00 X9.239 Y3.827", resulting in ['G00','X9.239','Y3.82'].

[0048] Subsequently, the offline analysis tool iterates through each element in the current row array and matches each element according to a preset regular expression. Specifically, 'X9.239' and 'Y3.827' match the preset regular expression and are stored in the real-time parameter variable {'X': 9.239, 'Y': 3.829}; 'G00' does not match the preset regular expression and is identified as an instruction variable.

[0049] Finally, based on the instruction variables, instruction conversion information, real-time parameter variables, and obsolete parameter variables, the current line code of the first CNC program is mapped to the current line code of the second CNC program, "G00 X9.239 Y3.827". The obsolete parameter variables used in the first line mapping are preset initial values.

[0050] In addition, after mapping the current line code of the first CNC program to the current line code of the second CNC program, the deprecated parameter variables are assigned the values ​​{'X': 9.239, 'Y': 3.829}.

[0051] When reading the second line of code of the first CNC program, the offline analysis tool generates the current line array of the second CNC program based on the current line code of the first CNC program ";G43 Z5. H06", resulting in ['G43','Z5.','H06'].

[0052] Subsequently, the offline analysis tool iterates through each element in the current row array and matches each element according to a preset regular expression. Specifically, 'Z5.' matches the preset regular expression, and further combined with deprecated parameter variables, the current real-time parameter variables are obtained as {'X': 9.239, 'Y': 3.829, 'Z': 5.0}; 'G43' and 'H06' do not match the preset regular expression and are identified as instruction variables. Among them, according to the instruction conversion information, the 'G43' instruction of the first CNC program is equal to 'G00' of the second CNC program, and the 'H06' instruction means deletion.

[0053] Finally, based on the instruction variables, instruction conversion information, real-time parameter variables, and obsolete parameter variables, the current line code of the first CNC program is mapped to the current line code "G00 Z5.0" of the second CNC program.

[0054] Furthermore, after mapping the current line of code of the first CNC program to the current line of code of the second CNC program, the offline analysis tool assigns the obsolete parameter variables the values ​​{'X': 9.239, 'Y': 3.829, 'Z': 5.0}.

[0055] When reading the third line of code in the first CNC program, the offline analysis tool generates the current line array of the second CNC program based on the current line code of the first CNC program: ";G98 G83 X9.239 Y3.827 Z-16. R-5. Q7.", resulting in ['G98','G83','X9.239','Y3.827','Z-16.','R-5.','Q7.'].

[0056] Subsequently, the offline analysis tool iterates through each element in the current row array and matches each element according to a preset regular expression. Specifically, 'X9.239', 'Y3.827', 'Z-16.', 'R-5.', and 'Q7.' match the preset regular expression. Further combining this with outdated parameter variables, the current real-time parameter variables are obtained as {'X': 9.239, 'Y': 3.829, 'Z': -16.0, 'R': -5, 'Q': 7.0}. 'G98' and 'G83' do not match the preset regular expression and are identified as instruction variables. Among these, the G83 instruction in the first CNC program is equivalent to CYCLE83 in the second CNC program, CYCLE83 (RTP, RFP, SFD, DEP, RDP, FDEP, FRDP, DAM, DTB, DTS, FRF, TYP). The Q parameter in G83 corresponds to the DAM parameter in CYCLE83. Since G83 lacks concepts like starting drill depth, time for chip removal at the starting point, and feed coefficient at the starting drill depth, DTB, DTS, FDEP, and FRDP can all be set to 0, and the FRF parameter to 1. The Q parameter in G83 equals the DAM parameter G83 in CYCLE83, which corresponds to TYP=1 in CYCLE83. G98 indicates a return to the initial point, therefore the RTP in CYCLE83 is assigned the deprecated Z parameter value. Furthermore, the CYCLE83 syntax does not specify XY coordinate values; the current XY parameter values ​​must be written before the CYCLE83 statement.

[0057] Finally, based on the instruction variables, instruction conversion information, real-time parameter variables, and outdated parameter variables, the current line code of the first CNC program is mapped to the current line code of the second CNC program, "X9.239 Y3.827 CYCLE83(5.0,-5.0,0,-16.0,0,0,7.0,0,0,0,1,1)".

[0058] Repeat the above mapping steps until all lines of code in the first CNC program have been processed to obtain the second CNC program.

[0059] The CNC program analysis method provided in this application identifies real-time parameter variables and instruction variables in the current line array of the first CNC program through a mapping step. Then, based on the instruction variables, instruction conversion information, real-time parameter variables, and outdated parameter variables, it maps the current line code of the first CNC program to the current line code of the second CNC program. By repeatedly executing the mapping step, all lines of code in the first CNC program are processed, avoiding incomplete or incorrect conversions caused by differences in CNC program format or logic. This reduces tedious manual correction work, thereby significantly improving the automation, accuracy, and robustness of CNC program conversion and enhancing the compatibility between different CNC machine tool programs.

[0060] In one embodiment, prior to parametric optimization of the original simulated machining trajectory, the following may be included: The first preset point and the second preset point are determined from the original simulated processing trajectory, and the view volume coordinates of the first preset point and the second preset point are determined based on the screen coordinates of the first preset point and the screen coordinates of the second preset point. The coordinate axes of the first preset point and the second preset point are determined based on the view volume coordinates of the first preset point and the view volume coordinates of the second preset point, and the distance between the first preset point and the second preset point is determined based on the coordinate axes of the first preset point and the second preset point. Based on the distance between the first preset point and the second preset point, the rotation angle between the first preset point and the second preset point is determined, and the original simulated machining trajectory is optimized at the parameter level based on the rotation angle.

[0061] Specifically, the first preset point and the second preset point can be points selected by the user by clicking with the mouse on the graphical interface; or they can be key points automatically identified by the offline analysis tool according to the preset algorithm, such as the starting point, ending point, inflection point of the trajectory, or two endpoints that constitute a specific local area. This application does not make any specific limitations on this.

[0062] Specifically, select any two points on the graphic trajectory and record them as the first preset point and the second preset point. Then, through the glutMouseFunc callback function, obtain the screen coordinates of the two points when the mouse clicks on the first preset point and the second preset point.

[0063] Subsequently, the offline analysis tool determines the view volume coordinates of the first and second preset points based on their screen coordinates. During this process, to ensure the accuracy of the coordinate transformation, before calling glGetIntegerv to obtain the current model-view matrix, projection matrix, and viewport information, the model transformation code must be reapplied in exactly the same way as used during previous drawing, and the order of translation, scaling, and rotation must also be consistent with the drawing process.

[0064] Next, the offline analysis tool, based on the view volume coordinates of the first and second preset points, further calls the OpenGL core method `gluUnProject` to convert the view volume coordinates of the first and second preset points into coordinate axes coordinates of the first and second preset points. The offline analysis tool can then determine the distance between the first and second preset points based on these coordinate axes coordinates.

[0065] Finally, the offline analysis tool determines the rotation angle between the first and second preset points based on the distance between them, and performs parametric optimization on the original simulated machining trajectory based on the rotation angle.

[0066] The CNC program analysis method provided in this application determines a first preset point and a second preset point from the original simulated machining trajectory, converts the screen coordinates of the first preset point and the second preset point into coordinate axis coordinates, and then determines the rotation angle based on the distance between the first preset point and the second preset point. The original simulated machining trajectory is then optimized at the parameter level by the rotation angle, which enables the method to accurately adjust the original simulated machining trajectory and significantly improve the efficiency and accuracy of CNC program programming and simulation.

[0067] In one embodiment, visualizing the original simulated machining trajectory and the optimized simulated machining trajectory includes: Based on the parametric optimization and the coordinate axis coordinates of the original simulated machining trajectory, the original simulated machining trajectory is optimized by parametric optimization to obtain the optimized coordinate axis coordinates; Visualize the original and optimized simulated machining trajectories based on the coordinate axes of the original and optimized machining trajectories.

[0068] Specifically, first, the user selects at least one parameter-level optimization and sets the corresponding optimization parameters. After receiving the user's optimization parameters, the offline analysis tool saves them to a Config file. Then, the offline analysis tool calls Python's `configParser` module to parse the optimization parameters in the Config file and stores the parsed parameters in float type variables. Next, the offline analysis tool uses Python's `Ctypes` module to call the interface of a pre-compiled C++ dynamic link library, passing the user-set optimization parameters and the coordinate axes of the original simulated machining trajectory to the interface to obtain the optimized coordinate axes.

[0069] Finally, the offline analysis tool visualizes the original and optimized simulated machining trajectories on a display device based on the coordinate axes of the original and optimized trajectories. Furthermore, the offline analysis tool can also save the CNC program corresponding to the optimized simulated machining trajectory.

[0070] The CNC program analysis method provided in this application obtains optimized coordinate axes by optimizing the coordinate axes of the original simulated machining trajectory through parameter-level optimization and the coordinate axes of the original simulated machining trajectory. Then, by using the coordinate axes of the original simulated machining trajectory and the optimized coordinate axes, the original simulated machining trajectory and the optimized simulated machining trajectory are visualized. This method enables intuitive and efficient comparison of the trajectory before and after optimization, and dynamically adjusts and verifies the CNC program based on the optimization comparison, thereby significantly improving the efficiency and accuracy of CNC program programming and simulation.

[0071] In one embodiment, visualizing the original simulated machining trajectory and the optimized simulated machining trajectory may further include: Based on the original simulated machining trajectory and the optimized simulated machining trajectory, the optimization information is determined; The optimization information includes at least one of the following: the number of deleted points, the original number of points, and the number of corrected points.

[0072] Specifically, the number of correction points refers to the total number of new points generated during the parametric optimization process, resulting from adjustments, modifications, or interpolations of the coordinate positions in the original simulated machining trajectory. For example, the number of correction points may include the number of corrections to the compression position tolerance parameters, which is not specifically limited in this application.

[0073] Specifically, the offline analysis tool records and statistically analyzes optimization information based on the original and optimized simulated machining trajectories. For example, optimization information may include the number of original points; the number of deleted points; and the number of correction points, such as the number of corrections to the compression position tolerance parameters.

[0074] Optionally, after determining the optimization information, the offline analysis tool can visualize the optimization information on a graphical user interface.

[0075] The CNC program analysis method provided in this application determines at least one of the following: the number of deleted points, the number of original points, and the number of corrected points, based on the original simulated machining trajectory and the optimized simulated machining trajectory. This method provides users with an intuitive and objective basis for evaluating the optimization effect, avoiding misjudgments and inaccurate evaluations that may be caused by visually observing trajectory differences, thereby significantly improving the efficiency and accuracy of CNC program programming and simulation.

[0076] In one embodiment, fine smoothing may include at least one of the following: compressing minimum segment length, compressing maximum segment length, compressing maximum segment included angle, compressing position tolerance, spline segment length limit, and spline segment chord height error; Coarse smoothing can include at least one of the following: compressing the minimum line segment length and compressing the minimum line segment angle.

[0077] Specifically, the minimum compressed line segment length refers to setting a minimum allowable line segment length. Line segments shorter than the minimum compressed line segment length will be filtered out. For example, if the minimum compressed line segment length is set too small, the "burr" phenomenon on the workpiece surface cannot be eliminated; if the minimum compressed line segment length is set too large, the actual machining trajectory will differ significantly from the original trajectory, affecting trajectory accuracy.

[0078] The maximum compression segment length refers to setting a maximum allowable straight segment length. Segments longer than this length will not be compressed. For example, if the maximum compression segment length is set too small, the compression function will not work for many micro-segments, failing to achieve the desired compression effect. Conversely, if the maximum compression segment length is set too large, the actual machining trajectory will differ significantly from the original trajectory, affecting trajectory accuracy.

[0079] The maximum compression angle refers to setting a maximum allowable angle between adjacent line segments. If the angle between line segments is greater than the maximum compression angle, the line segments before and after that angle will not be compressed into the same continuous (tangential) trajectory. For example, if the maximum compression angle is set too small, the compression function will not work for many micro-segments, failing to achieve the compression effect; if the maximum compression angle is set too large, the processed trajectory will differ significantly from the original trajectory, affecting trajectory accuracy.

[0080] Compression position tolerance is used to limit the deviation of the linear axis position between the compressed trajectory and the original trajectory. For example, if the compression position tolerance is set too small, the compressed curve will still not be smooth enough; if the compression position tolerance is set too large, the actual machining trajectory may differ significantly from the original trajectory, affecting the trajectory accuracy.

[0081] The spline segment length limit is used to restrict the maximum length of each segment. For example, if the spline segment length limit is set too small, the compressed curve will still not be smooth enough; if the spline segment length limit is set too large, the actual machining trajectory may differ significantly from the original trajectory, affecting trajectory accuracy.

[0082] The spline segment chord height error is used to limit the chord height error between each line segment and the line segment it approximates. For example, if the spline segment chord height error is set too small, it will result in a large number of spline curve segments, affecting the processing speed; if the spline segment chord height error is set too large, it will affect the compression and smoothing effect.

[0083] The CNC program analysis method provided in this application, through fine smoothing including at least one of compressing the minimum line segment length, compressing the maximum line segment length, compressing the maximum line segment angle, compressing positional tolerance, spline segment length limit, and spline segment chord height error, and coarse smoothing including at least one of compressing the minimum line segment length and compressing the minimum line segment angle, enables the method to flexibly select and adjust the parameter-level optimization of the trajectory according to different requirements of machining accuracy and efficiency. This avoids the problem that a single optimization method cannot take into account different machining scenarios, thereby significantly improving the refinement and applicability of CNC program analysis.

[0084] In one embodiment, the method may further include: Delete the third preset point in the original simulated machining trajectory and determine the optimized simulated machining trajectory; Based on the coordinate axes of the original simulated machining trajectory and the coordinate axes of the optimized simulated machining trajectory, the target code line corresponding to the third preset point in the second CNC program is determined, and the target code line corresponding to the third preset point in the second CNC program is deleted.

[0085] Specifically, the third preset point can be a point selected by the user by clicking the mouse on the graphical interface; or it can be a point automatically identified by the offline analysis tool according to the preset algorithm, such as redundant points, error points, or abnormal points caused by overcutting problems in the trajectory. This application does not make specific limitations on this.

[0086] Specifically, any point is selected in the original simulated machining trajectory and designated as the third preset point. After receiving the third preset point, the offline analysis tool deletes it from the original simulated machining trajectory, thus obtaining the optimized simulated machining trajectory.

[0087] Subsequently, the offline analysis tool will determine the target code line corresponding to the third preset point in the second CNC program based on the mapping relationship established between the coordinate axes of the original simulated machining trajectory and the coordinate axes of the optimized simulated machining trajectory.

[0088] Next, the offline analysis tool will open the second CNC program and delete the target code line corresponding to the third preset point in the second CNC program.

[0089] Finally, after deleting the target lines of code, the offline analysis tool will save the modified second CNC program.

[0090] The CNC program analysis method provided in this application determines the optimized trajectory by deleting a third preset point in the original simulated machining trajectory. Based on the coordinate axes of the original simulated machining trajectory and the coordinate axes of the optimized simulated machining trajectory, the method deletes the target code line corresponding to the third preset point in the second CNC program. This enables precise synchronization between trajectory modification and CNC program modification, avoiding human errors and extra work caused by the disconnect between traditional trajectory modification and program modification, thereby significantly improving the efficiency and accuracy of CNC program programming and simulation.

[0091] The CNC program analysis device provided in this application will be described below. The CNC program analysis device described below can be referred to in correspondence with the CNC program analysis method described above, and can achieve the same technical effect. It will not be repeated here.

[0092] Figure 3 This is a schematic diagram of the structure of the CNC program analysis device provided in this application, as shown below. Figure 3 As shown, the device may include: The mapping module 310 is used to map the first CNC program to the second CNC program according to the instruction conversion information; Simulation module 320 is used to simulate the second CNC program to obtain the original simulated machining trajectory; The visualization module 330 is used to perform parameter-level optimization and / or interactive-level optimization on the original simulated machining trajectory to obtain the optimized simulated machining trajectory, and to visualize the original simulated machining trajectory and the optimized simulated machining trajectory. The instruction conversion information represents the correspondence between the first CNC program and the second CNC program; The parameter-level optimization includes at least one of the following: arc to small line segment conversion, fine smoothing, coarse smoothing, and local point processing; The interaction-level optimization includes at least one of scaling, rotation, and translation.

[0093] In one embodiment, the mapping module 310 is specifically used for: Repeat the mapping steps until all lines of code in the first CNC program have been processed to obtain the second CNC program. The mapping step includes: Generate an array of the current line of the first CNC program based on the current line of code of the first CNC program, and traverse each element in the array of the current line; If the first element in the current row array matches the preset regular expression, the first element is used as a real-time parameter variable; if the second element in the current row array does not match the preset regular expression, the second element is used as an instruction variable. Based on the instruction variable, the instruction conversion information, the real-time parameter variable, and the obsolete parameter variable, the current line of code in the first CNC program is mapped to the current line of code in the second CNC program; the obsolete parameter variable is the real-time parameter variable of the previous line of code; The deprecated parameter variables used in the first row of mappings are preset initial values.

[0094] In one embodiment, before performing parametric-level optimization on the original simulated machining trajectory, the visualization module 330 is used to: Before performing parameter-level optimization on the original simulated machining trajectory, the following steps are included: A first preset point and a second preset point are determined from the original simulated processing trajectory, and the view volume coordinates of the first preset point and the second preset point are determined based on the screen coordinates of the first preset point and the screen coordinates of the second preset point. The coordinate axes of the first preset point and the second preset point are determined based on the view volume coordinates of the first preset point and the view volume coordinates of the second preset point, and the distance between the first preset point and the second preset point is determined based on the coordinate axes of the first preset point and the second preset point. Based on the distance between the first preset point and the second preset point, the rotation angle between the first preset point and the second preset point is determined, and the original simulated machining trajectory is optimized at the parameter level based on the rotation angle.

[0095] In one embodiment, the visualization module 330 is specifically used for: Based on the parameter-level optimization and the coordinate axis coordinates of the original simulated machining trajectory, the original simulated machining trajectory is optimized at the parameter level to obtain the optimized coordinate axis coordinates; Based on the coordinate axes of the original simulated machining trajectory and the optimized coordinate axes, the original simulated machining trajectory and the optimized simulated machining trajectory are visualized.

[0096] In one embodiment, the fine smoothing includes at least one of the following: minimum compressed line segment length, maximum compressed line segment length, maximum compressed line segment included angle, compressed position tolerance, spline segment length limit, and spline segment chord height error; The coarse smoothing includes at least one of the following: compressing the minimum line segment length and compressing the minimum line segment angle.

[0097] In one embodiment, the apparatus further includes a deletion module 340 (not shown in the figure), the deletion module 340 being used to: Delete the third preset point in the original simulated machining trajectory to determine the optimized simulated machining trajectory; Based on the coordinate axes of the original simulated machining trajectory and the coordinate axes of the optimized simulated machining trajectory, the target code line corresponding to the third preset point in the second CNC program is determined, and the target code line corresponding to the third preset point in the second CNC program is deleted.

[0098] In one embodiment, the visualization module 330 is further configured to: Based on the original simulated machining trajectory and the optimized simulated machining trajectory, the optimization information is determined; The optimization information includes at least one of the following: the number of deleted points, the number of original points, and the number of corrected points.

[0099] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4 As shown, the electronic device may include: a processor 410, a communications interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communications interface 420, and the memory 430 communicate with each other via the communication bus 440. The processor 410 can call logical instructions in the memory 430 to execute a numerical control program analysis method, which may include: Based on the instruction conversion information, the first CNC program is mapped to the second CNC program; The second CNC program is simulated to obtain the original simulated machining trajectory; The original simulated machining trajectory is optimized at the parameter level and / or interactive level to obtain the optimized simulated machining trajectory, and the original simulated machining trajectory and the optimized simulated machining trajectory are visualized. The instruction conversion information represents the correspondence between the first CNC program and the second CNC program; The parameter-level optimization includes at least one of the following: arc to small line segment conversion, fine smoothing, coarse smoothing, and local point processing; The interaction-level optimization includes at least one of scaling, rotation, and translation.

[0100] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0101] On the other hand, this application also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is implemented to perform the numerical control program analysis method described in any of the above embodiments, for example including: Based on the instruction conversion information, the first CNC program is mapped to the second CNC program; The second CNC program is simulated to obtain the original simulated machining trajectory; The original simulated machining trajectory is optimized at the parameter level and / or interactive level to obtain the optimized simulated machining trajectory, and the original simulated machining trajectory and the optimized simulated machining trajectory are visualized. The instruction conversion information represents the correspondence between the first CNC program and the second CNC program; The parameter-level optimization includes at least one of the following: arc to small line segment conversion, fine smoothing, coarse smoothing, and local point processing; The interaction-level optimization includes at least one of scaling, rotation, and translation.

[0102] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0103] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0104] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A numerical control program analysis method, characterized in that, The method includes: Based on the instruction conversion information, the first CNC program is mapped to the second CNC program; The second CNC program is simulated to obtain the original simulated machining trajectory; The original simulated machining trajectory is optimized at the parameter level and / or interactive level to obtain the optimized simulated machining trajectory, and the original simulated machining trajectory and the optimized simulated machining trajectory are visualized. The instruction conversion information represents the correspondence between the first CNC program and the second CNC program; The parameter-level optimization includes at least one of the following: arc to small line segment conversion, fine smoothing, coarse smoothing, and local point processing; The interaction-level optimization includes at least one of scaling, rotation, and translation.

2. The CNC program analysis method according to claim 1, characterized in that, The step of mapping the first CNC program to the second CNC program based on instruction conversion information includes: Repeat the mapping steps until all lines of code in the first CNC program have been processed to obtain the second CNC program. The mapping step includes: Generate an array of the current line of the first CNC program based on the current line of code of the first CNC program, and traverse each element in the array of the current line; If the first element in the current row array matches the preset regular expression, the first element is used as a real-time parameter variable; if the second element in the current row array does not match the preset regular expression, the second element is used as an instruction variable. Based on the instruction variable, the instruction conversion information, the real-time parameter variable, and the obsolete parameter variable, the current line of code in the first CNC program is mapped to the current line of code in the second CNC program; the obsolete parameter variable is the real-time parameter variable of the previous line of code; The deprecated parameter variables used in the first row of mappings are preset initial values.

3. The CNC program analysis method according to claim 1, characterized in that, Before performing parameter-level optimization on the original simulated machining trajectory, the following steps are included: A first preset point and a second preset point are determined from the original simulated processing trajectory, and the view volume coordinates of the first preset point and the second preset point are determined based on the screen coordinates of the first preset point and the screen coordinates of the second preset point. The coordinate axes of the first preset point and the second preset point are determined based on the view volume coordinates of the first preset point and the view volume coordinates of the second preset point, and the distance between the first preset point and the second preset point is determined based on the coordinate axes of the first preset point and the second preset point. Based on the distance between the first preset point and the second preset point, the rotation angle between the first preset point and the second preset point is determined, and the original simulated machining trajectory is optimized at the parameter level based on the rotation angle.

4. The CNC program analysis method according to claim 1, characterized in that, The visualization of the original simulated machining trajectory and the optimized simulated machining trajectory includes: Based on the parameter-level optimization and the coordinate axis coordinates of the original simulated machining trajectory, the original simulated machining trajectory is optimized at the parameter level to obtain the optimized coordinate axis coordinates; Based on the coordinate axes of the original simulated machining trajectory and the optimized coordinate axes, the original simulated machining trajectory and the optimized simulated machining trajectory are visualized.

5. The CNC program analysis method according to any one of claims 1-4, characterized in that, The fine smoothing includes at least one of the following: minimum compressed line segment length, maximum compressed line segment length, maximum compressed line segment included angle, compressed position tolerance, spline segment length limit, and spline segment chord height error; The coarse smoothing includes at least one of the following: compressing the minimum line segment length and compressing the minimum line segment angle.

6. The CNC program analysis method according to claim 1, characterized in that, Also includes: Delete the third preset point in the original simulated machining trajectory to determine the optimized simulated machining trajectory; Based on the coordinate axes of the original simulated machining trajectory and the coordinate axes of the optimized simulated machining trajectory, the target code line corresponding to the third preset point in the second CNC program is determined, and the target code line corresponding to the third preset point in the second CNC program is deleted.

7. The CNC program analysis method according to claim 1, characterized in that, The visualization of the original simulated machining trajectory and the optimized simulated machining trajectory also includes: Based on the original simulated machining trajectory and the optimized simulated machining trajectory, the optimization information is determined; The optimization information includes at least one of the following: the number of deleted points, the number of original points, and the number of corrected points.

8. A numerical control program analysis device, characterized in that, include: The mapping module is used to map the first CNC program to the second CNC program based on instruction conversion information; The simulation module is used to simulate the second CNC program to obtain the original simulated machining trajectory; A visualization module is used to perform parameter-level optimization and / or interactive-level optimization on the original simulated machining trajectory to obtain the optimized simulated machining trajectory, and to visualize the original simulated machining trajectory and the optimized simulated machining trajectory. The instruction conversion information represents the correspondence between the first CNC program and the second CNC program; The parameter-level optimization includes at least one of the following: arc to small line segment conversion, fine smoothing, coarse smoothing, and local point processing; The interaction-level optimization includes at least one of scaling, rotation, and translation.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the numerical control program analysis method as described in any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the numerical control program analysis method as described in any one of claims 1 to 7.