A fine-grained error detection and repair method for NC code based on 2-gram and mutual information model

By combining lexical, grammatical and logical detection technologies and using 2-gram and mutual information models to analyze the functional instructions and trajectory data of NC codes, the problem of detecting and repairing NC code errors in CNC systems is solved, thereby improving the safety and efficiency of the production process.

CN119356209BActive Publication Date: 2025-09-09HARBIN INST OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411461383.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-18
Publication Date
2025-09-09
Estimated Expiration
2044-10-18

AI Technical Summary

Technical Problem

The NC codes in existing CNC systems are prone to errors and anomalies, which affect production safety and efficiency, and there is a lack of effective real-time detection and repair methods.

Method used

A method based on 2-gram and mutual information model is used, combined with lexical, grammatical and logical detection technologies, to analyze the functional instructions and trajectory data of NC codes. Linear interpolation and spline interpolation technologies are used to repair abnormal points and ensure code integrity.

Benefits of technology

It realizes fine-grained error detection and repair of NC code, improves the safety and efficiency of the production process, and ensures the reliability and accuracy of CNC machining.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119356209B_ABST
    Figure CN119356209B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for fine-grained error detection and repair of NC code based on 2-gram and mutual information model. The method is as follows: Step 1: A local operator identifies key instructions and potential abnormal feature areas by analyzing the functional instructions and trajectory data of the NC code; Step 2: A preliminary check of the instructions is performed using lexical, grammatical, and logical detection techniques to identify possible lexical and grammatical errors; Step 3: If no errors are detected, the relationship between the instructions is deeply analyzed using 2-gram and mutual information model to find possible abnormal instruction combinations; Step 4: For abnormal points in the trajectory data, interpolation technology is used to repair the abnormal points to ensure that the code passes integrity detection. By analyzing the functional instructions and trajectory data of the NC code and combining lexical, grammatical, and logical detection techniques, this method can accurately locate and repair NC code anomalies, thereby improving the safety and efficiency of the production process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of numerical control technology and relates to a method for detecting and repairing NC code errors, and in particular to a method for detecting and repairing NC code fine-grained errors based on a 2-gram and mutual information model. Background Art

[0002] With the continuous development of industrial automation and intelligent manufacturing, CNC technology plays an increasingly important role in the manufacturing industry. However, in the actual application of CNC machine tools, NC code may be subject to interference from various factors, causing errors and anomalies, which pose a potential threat to production safety and product quality. Therefore, the research and development of effective NC code error detection and repair methods has become a technical challenge that needs to be addressed urgently.

[0003] In current CNC systems, many devices rely on specialized software for operation. However, this software often lacks open application programming interfaces (APIs) and file access capabilities, making real-time monitoring and management difficult. This complicates the identification and repair of NC code errors during production, impacting production efficiency and product reliability. Therefore, developing a method that can detect and repair NC code errors in real time is crucial. Summary of the Invention

[0004] To address the potential for errors and anomalies in NC code used in numerical control systems, which can impact production safety and efficiency, this paper presents a fine-grained NC code error detection and repair method based on 2-gram and mutual information models. This method analyzes the functional instructions and trajectory data of NC code, combining lexical, grammatical, and logical detection techniques to accurately locate and repair NC code anomalies, thereby improving production safety and efficiency.

[0005] The purpose of the present invention is achieved through the following technical solutions:

[0006] A method for detecting and repairing fine-grained errors in NC codes based on 2-gram and mutual information models includes the following steps:

[0007] Step 1: The local operator identifies key instructions and potential abnormal feature areas by analyzing the functional instructions and trajectory data of the NC code;

[0008] Step 2: Use lexical, grammatical, and logical detection techniques to perform a preliminary check on the instructions to identify possible lexical and grammatical errors;

[0009] Step 3: If no error is detected, use 2-gram and mutual information models to deeply analyze the relationship between instructions and find possible abnormal instruction combinations;

[0010] Step 4: For abnormal points in the trajectory data, use linear interpolation and spline interpolation techniques to repair the abnormal points to ensure that the code passes the integrity test.

[0011] Compared with the prior art, the present invention has the following advantages:

[0012] The present invention provides a method for error detection and repair of functional instructions and trajectory data in the NC code of numerically controlled (NC) machine tools. After detecting NC code integrity anomalies using a reversible fragile watermark, the method performs fine-grained error checking on the functional instructions and trajectory data. For the functional instruction portion, the method categorizes errors into three categories: lexical, syntactic, and logical. First, a lexical detection method based on finite automata is used to detect errors. If this detection fails to detect anomalies, a combination of 2-gram and mutual information models is used to analyze the probability of occurrence of instruction combinations to identify potential hidden errors. This method effectively locates and repairs anomalous code by leveraging the high similarity of NC code instructions on the same NC machine tool. For the trajectory data portion, the method uses linear interpolation and spline interpolation to fit the tampered tool trajectory points and estimate the locations of normal points. By traversing the interpolation points, the method gradually restores the tampered trajectory data until the watermark verification passes, ensuring code integrity is restored. This fine-grained error detection and repair method combines the detection and repair of functional instructions and trajectory data to accurately locate anomalies in NC code, improving the efficiency and accuracy of code error correction. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] Figure 1 This is a flowchart of the NC code fine-grained error detection and repair method based on 2-gram and mutual information model;

[0014] Figure 2 This is a detailed flow chart of the NC code fine-grained error detection and repair method based on 2-gram and mutual information model;

[0015] Figure 3 It is NC code preprocessing. DETAILED DESCRIPTION

[0016] The technical solution of the present invention is further described below with reference to the accompanying drawings, but is not limited thereto. Any modification or equivalent replacement of the technical solution of the present invention that does not depart from the spirit and scope of the technical solution of the present invention should be included in the scope of protection of the present invention.

[0017] The present invention provides a method for fine-grained error detection and repair of NC code based on 2-gram and mutual information model, such as Figure 1 As shown, the method includes the following steps:

[0018] Step 1: The local operator (i.e., the CNC machine operator) analyzes the functional instructions and trajectory data of the NC code to identify key instructions and potential abnormal feature areas. This analysis provides basic data for subsequent fine-grained detection. The specific steps are as follows:

[0019] Step 1-1: Analyze the execution process of the NC code, including its functional instructions and trajectory data;

[0020] Step 1-2: By studying the operation steps of the CNC machine tool, identify the key instruction segments and data segments that may be prone to errors. Among them, the characteristic instruction segments usually include commonly used G codes and M codes, while the abnormal trajectory data involves the coordinate points of the tool path;

[0021] Step 1-3: If certain code segments repeatedly fail during program execution or cause the tool path to deviate from the expected path, these code segments will be marked as segments to be monitored.

[0022] Step 2: Use lexical, grammatical, and logical detection techniques to perform a preliminary check on the instructions to identify possible lexical and grammatical errors. The specific steps are as follows:

[0023] Step 2-1: Use finite automaton (FA) to perform lexical detection, conduct preliminary inspection of feature instruction segments, and identify possible lexical errors.

[0024] After recording the characteristic instruction segments, the NC code is lexically analyzed using a finite automaton. Based on the NC code's grammatical rules, the finite automaton scans each character in the code to determine whether any lexical structures are illegal. Lexical errors in NC code typically include non-standard instruction formats, illegal characters, or non-compliant parameters. By converting the NC code format into a finite automaton model using regular expressions, low-level errors such as missing parameters and misspelled symbols can be quickly detected. The results of the finite automaton analysis are used to determine whether syntax checking is necessary.

[0025] Step 2-2: After lexical detection, LR analysis is applied to perform syntax detection to check the syntax structure of the instruction segment and determine whether there are any syntax errors.

[0026] During syntax checking, the input symbol is started and the syntax tree is reduced upwards to the root of the syntax tree, which is the start symbol. In its implementation, the LR parsing method sets up a symbol stack to store symbols and guide subsequent actions based on historical push data.

[0027] Syntax errors are common in complex CNC programs, especially those containing macros and program structures. LR parsing reduces instructions layer by layer from the bottom up, generating a syntax tree and checking whether the code segment conforms to the rules of a context-free grammar. By constructing a syntax tree, problems such as incorrect instruction order and incorrect nesting can be detected.

[0028] Steps 2-3: Following syntax checking, logic checking is a necessary follow-up step to identify underlying issues within the code. Logic checking is primarily performed using a predefined rule base. Due to the flexible and changeable semantics of NC code, logic checking often requires specialized development based on specific application scenarios and experience. Specifically, the logic checking method includes the following steps:

[0029] (1) Rule-based logic detection: A rule-based detection system was built to identify common logic errors in NC code. This system summarizes the operating rules and experience of actual CNC machine tool processing and matches the code by writing corresponding logic detection rules. For example, during the processing process, certain instructions must appear in pairs or in a specific order. If these rules are not met, the logic detection will be judged as an error.

[0030] (2) Checking the dependency and rationality of instructions: The system will check the dependency between different functional instructions. For example, whether the preconditions are met before the execution of the instructions, whether the execution order of the instructions is reasonable, etc. If a code segment contains a position setting instruction (such as the coordinate setting of the G code), the subsequent tool movement instruction must comply with the position setting, otherwise a logic error will be triggered.

[0031] (3) Logic Verification of Parameter Ranges: Logic testing also ensures that the parameter values ​​in each instruction are within a reasonable range. For example, parameters such as feed rate and spindle speed must be within the operating range of the CNC machine tool. If a parameter exceeds the range allowed by the equipment, the system will determine it as a logic error and prompt for correction.

[0032] (4) Checking the complexity of macro instructions and program structures: Macro instructions are often used in NC code to implement complex conditional judgments and loop structures. Logic testing further checks whether the execution paths of these macro instructions are reasonable to avoid dead loops or invalid operations. For example, during program execution, if the jump conditions of a macro instruction are not set correctly, the program may not exit correctly or may be repeatedly executed. Logic testing will identify this error in advance and prompt an error.

[0033] (5) Checking the physical rationality of the machining trajectory: In addition to functional instructions, logic testing also verifies the rationality of the tool trajectory. Abnormal trajectory data may cause the tool to deviate from the planned path or even lead to dangerous operations. The system will predict the trajectory by comparing it with known trajectory models or using interpolation methods to ensure that the tool path meets expectations. If the trajectory changes too drastically or there are unforeseen corners and path jumps, the logic test will mark it as an abnormality.

[0034] (6) Checking the legality of specific command combinations: In some cases, certain commands in a CNC program require a specific combination or sequence to ensure safety. For example, the combination of coolant on (M08) and high-speed cutting is a typical rule. If the coolant is not turned on before high-speed cutting, the system will detect this logical error and prompt the operator to make corrections.

[0035] Through this logic-checking method, the system can identify instruction errors that fail lexical and grammatical checks but could potentially cause failures or hazards during actual processing. If the logic check fails to identify an issue, the code segment is marked as passed. If a logic error is detected, the system displays an error message and interrupts program execution, pending further manual repair or automatic error correction. Thus, by combining a multi-layered approach of lexical, grammatical, and logic checking, the present invention ensures the security and accuracy of NC code, effectively improving the reliability of CNC machining.

[0036] Step 3: If no error is detected, use the 2-gram and mutual information models to further analyze the relationship between instructions and find possible abnormal instruction combinations. The specific steps are as follows:

[0037] Step 3-1: If no lexical and syntactic errors are detected, apply the mutual information model to analyze the relationship between instructions and identify abnormal instruction combinations.

[0038] The mutual information model is used to quantify the correlation between two instruction keywords, primarily based on historical data from code segments. A single NC code instruction keyword is considered a word, w, while a collection of NC code instruction keywords can be considered a sentence, S. Since NC codes represent the operating sequence of CNC machine tools, many instruction keywords are not independent of each other but follow a specific process. Instructions have a sequential relationship, and the appearance of the nth instruction is related to the previous n-1 instructions. The probability of occurrence of a string of NC code segments is P(S). This NC code segment consists of n instruction keywords, and the string representation of this NC code segment is:

[0039] S=w1w2w3...w n-1 w n (1)

[0040] The probability of this code segment appearing is calculated as follows:

[0041] P(S)=P(w1)P(w2|w1)P(w3|w1w2)...P(w n |w1w2...w n-1 ) (2)

[0042] Among them, P(w n |w1w2...w n-1 ) means that the first n-1 instructions of the program segment S are w1w2...w n-1 In the case of n The probability of occurrence, which reflects w n The instruction is the correlation strength of the previous n-1 instructions. Since the length of a code segment is variable, when n is large, the computational effort required to calculate the probability of occurrence of that NC code segment, P(S), will increase exponentially. The G-code program instruction portion of an NC code is also relatively short. Most G-code combinations consist of two instructions, and the syntax and logic are not complex. Therefore, long-distance error correction is unnecessary, and the 2-gram method can be used, saving computational resources. The formula for calculating P(S) for the 2-gram-based NC code model is as follows:

[0043]

[0044] Among them, w i-1 represents the probability of the i-1th instruction appearing, w i represents the probability of the i-th instruction occurring.

[0045] Because some instructions in the NC code corpus appear less frequently, for example, the 2-gram value for the collocation of "G68.1" and "G19" is too low, resulting in model recognition errors. However, "G19 G68.1" has a high co-occurrence frequency and is a legal fixed collocation. In NC code, mutual information quantifies the degree of connection between two instruction keywords. The greater the mutual information, the greater the degree of connection between the two instruction keywords. Therefore, mutual information can supplement 2-gram defects and jointly analyze the two during error detection. The mutual information between two instruction keywords (X, Y) is defined as I(X, Y), as shown in the following formula:

[0046]

[0047] Where: P(X,Y) is the joint probability distribution of (X,Y); P(X) is the probability of instruction X appearing in the NC code corpus; P(Y) is the probability of instruction Y appearing in the NC code corpus.

[0048] By analyzing common instruction combinations on machine tools and calculating the joint probability of their occurrence, we can determine that abnormal instructions often exhibit unusual or inconsistent pairing characteristics. If the mutual information values ​​for certain instruction combinations are low, this indicates an anomaly.

[0049] Step 3-2: For the abnormal instruction combination initially located, calculate the 2-gram score of the abnormal instruction and determine the probability of occurrence of the instruction to determine the potential abnormality.

[0050] The 2-gram model measures the rationality of instruction combinations by analyzing the frequency of binary combinations of instruction keywords. The model is trained on historically validated NC code to generate a probability distribution for binary combinations. Instruction combinations with a low probability of occurrence often represent anomalies, potentially the result of malicious tampering or programming errors. Calculating the 2-gram score further identifies potentially anomalous instructions.

[0051] Step 3-3: Based on the mutual information value, possible repair suggestions are given and alternative instruction combinations are listed.

[0052] Based on the analysis results of the mutual information model and the 2-gram model, the system generates repair suggestions. When the 2-gram score of the binary adjacent phrases before and after a command keyword is high but the mutual information score is low, an anomaly is very likely to occur at that command keyword. However, when the 2-gram score is low but the mutual information score is high, the probability of an anomaly is relatively low. Furthermore, when the 2-gram score of two command keywords in a pair is high but the mutual information score is low, and if the 2-gram score of the commands before and after is low but the mutual information score is high, a command deletion attack is possible.

[0053] For detected abnormal instructions, the CNC system provides multiple possible replacement command combinations and prioritizes high-probability replacement solutions based on historically reasonable instruction combinations. These repair suggestions are ranked by mutual information value and provided to the operator for reference, allowing them to make repairs.

[0054] Step 4: Use linear interpolation and spline interpolation techniques to repair abnormal points in the trajectory data to ensure that the code passes the integrity test. The specific steps are as follows:

[0055] Step 4-1: For abnormal points in the trajectory data, use linear interpolation and spline interpolation techniques to estimate and determine the range of normal points.

[0056] The abnormality of trajectory data is usually caused by the deviation of the tool trajectory from the predetermined path. Through linear interpolation and cubic spline interpolation technology, the known normal trajectory data can be curve fitted to estimate the reasonable position range of the abnormal trajectory points. When the tool trajectory angle is small, or when the tampering point may be a watermark point, the use of linear interpolation can locate the normal data more quickly. The idea of ​​the linear interpolation method in the present invention is to predict the normal point based on the straight line relationship between the two tool trajectory points, which is particularly suitable for situations where the tool trajectory points are dense and the change trend is approximately linear. The equation of the straight line contained in the normal point priority search domain is shown as follows:

[0057]

[0058] Where (x1, y1) represents the coordinates of the first known point, (x2, y2) represents the coordinates of the second known point, x represents the x-coordinate of the point to be interpolated, which is between x1 and x2, and y represents the y-coordinate obtained after interpolation, which corresponds to the result of inserting the x-value into the equation of the line.

[0059] Linear interpolation is suitable for cases with small trajectory curvature, while spline interpolation is suitable for complex trajectories with strong nonlinearity. Through these techniques, the possible repair range of the outlier point can be determined, providing a basis for subsequent repair.

[0060] Step 4-2: Traverse the interpolation points and repeatedly search and replace abnormal points according to the requirements of the integrity test until the test passes.

[0061] After determining the possible range of the abnormal point, the system will repair it by traversing the interpolation points. A fine-grained error checking experiment of an NC code with an instruction abnormality is used to explain the method flow in detail. Figure 3 As shown, after testing, no lexical, grammatical or logical errors were found in the code and it can be processed by machine tools.

[0062] Traversing the binary adjacent instruction group of the preprocessed NC code, the result is:

[0063] [(O0001,G91), (G91,G28), (G28,Z), (Z,G90), (G90,G40), (G40,G49), (G49,G80), (G80 ,G98), (G98,G21), (G21,G0), (G0,G54), (G54,G17), (G17,T1), (T1,M6), (M6,G90), (G9 0,G40), (G40,G49), (G49,G54), (G54,G17), (G17,S1000), (S1000,M03), (M03,M08), (M 08,G00), (G00,XY), (XY,G43), (G43,Z), (Z,H1), (H1,Z), (Z,G01), (G01,Z), (Z,F600)].

[0064] The binary neighboring instruction groups are extracted and the scores of each binary neighboring instruction in the code are calculated according to the trained 2-gram model and the scores are arranged from high to low. 10 groups of data are selected, as shown in Table 1.

[0065] Table 1 2-gram scores of binary neighboring instruction groups

[0066]

[0067] Among them, higher instruction group scores indicate lower 2-gram values, indicating a high likelihood of anomalies. High-scoring binary neighbor instruction groups include "F600," "S1000," "Z," "G17," and "M03." However, other binary neighbor instruction groups including "Z," "G17," and "M03" have low 2-gram scores, suggesting that "F600" and "S1000" may be anomalies. For further analysis, we need to calculate the mutual information values ​​of binary neighbor instruction groups, as shown in Table 2.

[0068] Table 2 Mutual information scores of binary neighboring instruction groups

[0069]

[0070] Among them, the mutual information value of the binary neighboring instruction group containing "F600" and "S1000" is 0, which indicates that the binary neighboring instruction group "(Z,F600)" paired with "F600" and the two binary neighboring instruction groups paired with "S1000" have never appeared in the historically processed NC code corpus. "F600" and "S1000" are likely to be illegal, that is, the feed speed and rotation speed may have been tampered with by the attacker, but it cannot be completely determined that only these two places have been tampered with.

[0071] For further judgment, it is necessary to provide repair suggestions based on the matching items in the mutual information table. The mutual information scores between "Z" and possible context phrases, the mutual information scores between "G17" and possible context phrases, and the mutual information scores between "M03" and possible context phrases are queried respectively, and then sorted, as shown in Tables 3, 4, and 5.

[0072] Table 3 Mutual information scores between “Z” and possible following phrases

[0073]

[0074] Table 4 Mutual information scores between “G17” and possible following phrases

[0075]

[0076] Table 5 Mutual information scores between “M03” and possible preceding phrases

[0077]

[0078] As can be seen from Tables 3, 4, and 5, the instruction keywords "S5000" and "S1500" can be selected to replace the position of "S1000"; the instruction keywords "F100", "F60", "G1", and "G90" can be selected to replace the position of "F600". There are a total of 8 combinations. These 8 combinations are replaced in the abnormal positions in turn and the watermark is re-matched. As a result, only the combination of "S5000" and "F100" can make the watermark match, successfully repairing the special code segment above the first group. Therefore, it can be completely determined that tampering anomalies have occurred at "F600" and "S1000", and there are no anomalies at other positions.

[0079] After each outlier point is replaced, the system re-runs an integrity check to determine whether the repair was successful. If the replaced trajectory data passes the integrity check, the repair is successful. Otherwise, the system will continue to traverse other interpolation points until a suitable replacement point is found to ensure the integrity of the trajectory data.

[0080] Step 4-3: Record key steps in the repair process and output the detection and repair results.

[0081] During the detection and repair process, the system records information for each key step, including the initial detection results, repair suggestions, replacement process, and final detection results. Specifically, the initial detection results will point out the abnormal instruction segments in the NC code and mark the abnormal locations through lexical, grammatical, and logical detection. Repair suggestions will provide potential alternative instruction combinations or parameter values ​​based on 2-gram and mutual information model analysis, and list reasonable repair options by priority. During the replacement process, the system will gradually replace abnormal instructions or trajectory points, and perform integrity checks after each replacement until the watermark match verification is passed. Finally, the system will output a post-repair detection report, comparing the code before and after the repair in detail, and confirming that all abnormal points have been successfully repaired. This detection report not only summarizes the specific repair operations, but also provides subsequent optimization suggestions to ensure that similar problems are effectively prevented in the future.

[0082] Step 4-4: End the detection and repair process to ensure the integrity and accuracy of the NC code.

[0083] Once all instructions and trajectory data pass integrity checks, the system concludes the detection and repair process. The final NC code is guaranteed to be free of lexical, syntactic, and logical errors, while trajectory data is accurate, ensuring the normal operation of the CNC machine tool and the safety and efficiency of production.

Claims

1. A fine-grained error detection and repair method for NC code based on 2-gram and mutual information model, characterized by The method comprises the following steps: Step 1: The local operator identifies key instructions and potential abnormal feature areas by analyzing the functional instructions and trajectory data of the NC code; Step 2: Use lexical, grammatical, and logical detection techniques to perform a preliminary check on the instructions to identify possible lexical and grammatical errors; Step 3: If no error is detected, use the 2-gram and mutual information models to further analyze the relationship between instructions and find possible abnormal instruction combinations. The specific steps are as follows: Step 3-1: If no lexical or syntactic errors are detected, apply the mutual information model to analyze the relationship between instructions and identify abnormal instruction combinations. The specific steps are as follows: Treat a single NC code instruction keyword as a word, set , and a set of NC code instruction keywords can be regarded as a sentence, set as , the probability of a string of NC code segments appearing is set to , this NC code segment consists of The string representation of the NC code segment is: NC code model correspondence based on 2-gram The calculation formula is as follows: in, Indicates the The probability of an instruction appearing, Indicates the The probability of an instruction appearing; In NC code, mutual information is used to supplement 2-gram defects. When checking errors, the two are analyzed jointly. The mutual information is defined as , as shown below: Where: for The joint probability distribution of instruction Probability of occurrence in the NC code corpus; --instruction Probability of occurrence in the NC code corpus; By analyzing the common instruction combinations on machine tools, the joint probability of the instructions is calculated. If the mutual information value of some instruction combinations is low, there may be anomalies. Step 3-2: For the abnormal instruction combination initially located, calculate the 2-gram score of the abnormal instruction and determine the probability of occurrence of the instruction to determine the potential abnormality; Step 3-3: Based on the mutual information value, give possible repair suggestions and list alternative instruction combinations. The specific steps are as follows: Based on the analysis results of the mutual information model and the 2-gram model, the system generates repair suggestions. If the 2-gram score of the binary adjacent phrases before and after a certain instruction keyword is high but the mutual information score is low, an anomaly is very likely to occur at that instruction keyword. If the 2-gram score is low but the mutual information score is high, the probability of an anomaly is relatively low. If the 2-gram score of two instruction keywords in a pair is high but the mutual information score is low, and if the 2-gram score of the instructions before and after is low but the mutual information score is high, an instruction deletion attack is likely to have occurred. For detected abnormal instructions, the CNC system will provide multiple possible alternative instruction combinations and prioritize high-probability instruction replacement solutions based on historically reasonable instruction combinations. These repair suggestions are sorted by mutual information value and provided to the operator for reference so that the operator can make repairs. Step 4: For abnormal points in the trajectory data, use linear interpolation and spline interpolation techniques to repair the abnormal points to ensure that the code passes the integrity test.

2. The NC code fine-grained error detection and repair method based on 2-gram and mutual information model according to claim 1 is characterized in that The specific steps of step 1 are as follows: Step 1-1: Analyze the execution process of the NC code, including its functional instructions and trajectory data; Step 1-2: By studying the operation steps of CNC machine tools, identify the key instruction segments and data segments that may be prone to errors; Step 1-3: If certain code segments repeatedly fail during program execution or cause the tool path to deviate from the expected path, these code segments will be marked as segments to be monitored.

3. The NC code fine-grained error detection and repair method based on 2-gram and mutual information model according to claim 1 is characterized in that The specific steps of step 2 are as follows: Step 2-1: Use finite automata to perform lexical detection, conduct preliminary inspection of the characteristic instruction segment, and identify possible lexical errors; Step 2-2: After lexical detection, LR analysis is applied to perform syntax detection to check the grammatical structure of the instruction segment and determine whether there are any grammatical errors; Step 2-3: After the syntax check, a logic check is performed to check for deep-seated problems in the code. If the logic check fails to find any problems, the code segment will be marked as passed. If a logical error is detected, the system will prompt an error message and interrupt program execution, waiting for further manual repair or automatic error correction.

4. The NC code fine-grained error detection and repair method based on 2-gram and mutual information model according to claim 3 is characterized in that The specific steps of step 2-1 are as follows: After recording the characteristic instruction segments, the NC code is lexically analyzed using a finite automaton. Based on the grammatical rules of the NC code, the finite automaton scans each character in the NC code to determine whether there is an illegal lexical structure.

5. The NC code fine-grained error detection and repair method based on 2-gram and mutual information model according to claim 1 is characterized in that The specific steps of step 4 are as follows: Step 4-1: For abnormal points in the trajectory data, use linear interpolation and spline interpolation techniques to estimate and determine the range of normal points; Step 4-2: Traverse the interpolation points and repeatedly search and replace abnormal points according to the requirements of the integrity test until the test passes; Step 4-3: Record key steps in the repair process and output the detection and repair results; Step 4-4: End the detection and repair process to ensure the integrity and accuracy of the NC code.

6. The NC code fine-grained error detection and repair method based on 2-gram and mutual information model according to claim 5 is characterized in that In step 4-2, each time an abnormal point is replaced, the system will re-perform an integrity check and determine whether the repair is successful. If the replaced trajectory data passes the integrity check, it means that the repair is successful; otherwise, the system will continue to traverse other interpolation points until a suitable replacement point is found to ensure the integrity of the trajectory data.

Citation Information

Patent Citations

  • Webpage new word discovery and analysis method based on word vector representation

    CN114169325A

  • Spacecraft test script automatic generation method based on deep learning

    CN115964273A