Numerical control machine tool space error prediction compensation method based on digital twinning and data driving

By constructing a digital twin model and using a data-driven approach, real-time accurate prediction and dynamic feedforward compensation of spatial errors in CNC machine tools were achieved. This solved the problems of unsuitability of error compensation and insufficient prediction in traditional methods, and improved machining accuracy and intelligence level.

CN122172724APending Publication Date: 2026-06-09GUANGDONG MECHANICAL TECHNICIAN COLLEGE
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GUANGDONG MECHANICAL TECHNICIAN COLLEGE
Filing Date
2026-03-16
Publication Date
2026-06-09

Smart Images

  • Figure CN122172724A_ABST
    Figure CN122172724A_ABST
Patent Text Reader

Abstract

This invention discloses a spatial error prediction and compensation method for CNC machine tools based on digital twins and data-driven approaches, belonging to the field of CNC machine tool control technology. This invention addresses the problems of existing CNC machine tool spatial error compensation methods, which generally rely on offline, fixed mechanistic models, making it difficult to accurately describe and adapt to the dynamic, time-varying, and nonlinear coupling characteristics of errors in actual machining, and lacking the ability to predict and actively suppress future errors. This invention constructs a digital twin of the CNC machine tool that integrates a data-driven prediction model, trains the error model based on multi-source industrial big data, and achieves synchronous virtual-real simulation. This enables accurate real-time prediction of complex dynamic errors and converts them into feedforward compensation quantities to proactively correct CNC machine tool motion commands, thereby realizing a shift from passive lag correction to proactive prediction and prevention. This significantly improves the machining accuracy and adaptability of CNC machine tools under high dynamic and multi-condition conditions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of CNC machine tool control technology, specifically to a method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches. Background Technology

[0002] As core equipment in modern manufacturing, CNC machine tools directly determine the quality and performance of products through their machining accuracy. However, in actual operation, CNC machine tools are affected by a combination of complex factors, including mechanical structural defects, thermal deformation, servo tracking errors, load disturbances, and geometric / kinematic errors. These factors generate spatial position errors (referred to as spatial errors) in their end effectors (such as spindles or cutting tools), severely restricting their ability to achieve high-precision machining. These errors are characterized by time-varying, nonlinear, and strongly coupled properties, making it difficult for traditional error compensation methods based on mechanistic models or offline calibration to achieve dynamic, accurate, and adaptive error suppression.

[0003] However, traditional error compensation methods mainly rely on model-based theoretical analysis or offline calibration, which makes it difficult to comprehensively and accurately describe the dynamic error changes of machine tools under actual multi-condition operation. Moreover, the compensation effect is limited by the accuracy of the model and its adaptability to real-time changes in operating conditions. In addition, most existing technologies focus on measuring and correcting historical or current errors, lacking the ability to predict errors in the future, and thus cannot meet the needs of proactively suppressing and preventing errors in high-speed and high-precision machining.

[0004] Therefore, it does not meet the existing requirements. In response, we propose a spatial error prediction and compensation method for CNC machine tools based on digital twins and data-driven approaches. Summary of the Invention

[0005] The purpose of this invention is to provide a method for predicting and compensating spatial errors of CNC machine tools based on digital twins and data-driven approaches. By constructing a digital twin that integrates geometric, kinematic, and data-driven error models, and combining industrial big data covering multiple working conditions for model training and online synchronous simulation, the invention achieves real-time accurate prediction and advanced feedforward compensation of complex dynamic spatial errors of CNC machine tools, thus solving the problems mentioned in the background art.

[0006] To achieve the above objectives, the present invention provides the following technical solution: a method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches, comprising the following steps: Construct a digital twin model corresponding to a CNC machine tool. The digital twin model shall include at least the geometric structure model, kinematic model, and error mapping model for characterizing spatial errors of the CNC machine tool. For CNC machine tools, we will carry out industrial big data collection covering multiple working conditions, multiple motion trajectories, and multiple load states. The collected industrial big data includes at least the real-time position information of each motion axis of the CNC machine tool, drive current, temperature field distribution information, and actual spatial position error information obtained by laser interferometer. The collected raw industrial big data is processed by big data, including data cleaning, spatiotemporal synchronization and alignment of multi-source heterogeneous data, and construction of sample datasets for model training. The constructed sample datasets include training datasets, validation datasets, and test datasets. Big data analysis is performed on the processed sample dataset, and machine learning algorithms are used to train and optimize the error mapping model of the digital twin model to form a data-driven error prediction model. During the real-time operation of the CNC machine tool, the digital twin model is synchronously driven to perform virtual simulation, and based on the data-driven error prediction model, the spatial error of the current and several future interpolation cycles is predicted in advance. The predicted spatial error value is converted into a real-time compensation amount for the motion commands of each CNC axis and sent to the controller of the CNC machine tool to realize dynamic feedforward compensation for spatial error.

[0007] Furthermore, for CNC machine tools, we will conduct industrial big data collection covering multiple working conditions, multiple motion trajectories, and multiple load states, specifically including: In the digital twin simulation environment of CNC machine tools, based on the machining capabilities of CNC machine tools, a comprehensive calibration motion program set covering the entire stroke, multiple feed rates, multiple accelerations, and including complex spatial trajectories is automatically planned and generated; While executing the comprehensive calibration motion program set on the CNC machine tool, the digital twin model is synchronously driven to run virtually, and the actual position encoder feedback, servo drive current and temperature sensor array data deployed on the key heat source and structural components of the machine tool are collected and time-synchronized in real time. A laser interferometer synchronized with the clock of the CNC machine tool's CNC system is used to dynamically measure and record the actual spatial position error of the CNC machine tool when executing the comprehensive calibration motion program set at predetermined grid points within the CNC machine tool's workspace. The collected CNC machine tool status data stream and the collected spatial error measurement data stream are spatiotemporally aligned and fused with the global clock and motion command sequence number of the CNC system as a reference to form a pairing data record of multi-source operating status of CNC machine tool and corresponding spatial error. Repeat the aforementioned steps, and before each repetition, manually change the load state, spindle speed, and environmental conditions of the CNC machine tool to collect a complete set of industrial big data covering the multiple working conditions and multiple loads.

[0008] Furthermore, spatiotemporal synchronization alignment specifically includes: Using the interpolation cycle clock of the CNC machine tool's CNC system as the reference time axis, a unified timestamp is applied to all the collected raw industrial big data streams. Among them, the data streams from inside the CNC system are directly marked using the internal clock of the CNC system, while the data streams from external sensor networks are marked through a hardware clock module synchronized with the CNC system. For a data stream that has a fixed offset from the reference time axis, the system time deviation of the data stream is calculated and compensated by comparing the time stamps of the same physical event in different data streams. A virtual data bus indexed by the reference time axis is constructed. After time deviation compensation, each data stream is resampled to a unified high-frequency time series consistent with the interpolation cycle of the CNC system, based on the sampling frequency of each data stream and using a combination of forward filling and linear interpolation. For each time-aligned data record, the machine tool motion command code corresponding to the time the data record occurred, the theoretical position coordinates calculated by the digital twin model simulation, and the CNC machine tool motion status identifier are associated to form spatiotemporally aligned structured data with complete contextual information.

[0009] Furthermore, the construction of the sample dataset used for model training specifically includes: From the data sequence that has been unified with timestamps and resampled, determine the measurement time corresponding to the actual spatial position error point measured by each laser interferometer; For each measurement moment, a data segment is extracted based on a continuous CNC machine tool operation data prior to that measurement moment. The start time of the data segment is dynamically determined by backtracking according to the CNC machine tool's motion state at that measurement moment. Specifically, when the CNC machine tool is in continuous motion during measurement, the start time is backtracked to the start time of the current motion command segment. When the CNC machine tool undergoes a switch from stationary to moving during measurement, the start time is backtracked to the time point that includes the complete preheating process. For each data segment obtained, a model training sample is generated. The input features of the sample are a set of time-series parameters extracted from the data segment, including the difference sequence between the command position and the feedback position of each motion axis, the absolute value sequence of the drive current of each axis, and the reading sequence of the temperature sensor at the spindle bearing and the lead screw nut seat. The label of the sample is the actual spatial position error value corresponding to the end time of the data segment. After normalizing all generated samples, they are classified according to the spindle speed range, load weight range, and ambient temperature range of the CNC machine tool when the samples were collected. Samples are then randomly selected from each category in proportion to form training datasets, validation datasets, and test datasets.

[0010] Furthermore, based on the processed sample dataset, big data analysis is performed, and machine learning algorithms are used to train and optimize the error mapping model of the digital twin model to form a data-driven error prediction model, specifically including: The training dataset is input into the error mapping model to be trained. A machine learning algorithm is used to iteratively train the error mapping model by taking the input features of the sample as input and the label of the sample as the expected output. The accuracy of the error mapping model during the iterative training process is verified and hyperparameters are tuned using the validation dataset. The prediction accuracy of the error mapping model is evaluated by comparing the spatial error values ​​predicted by the error mapping model with the actual measured spatial error values. Based on the evaluation results of the validation dataset, the structural parameters and learning parameters of the error mapping model are optimized and adjusted. The optimization and adjustment include, but are not limited to, adjusting the network depth, number of nodes, and regularization parameters of the model. The optimized final error mapping model is independently tested using the test dataset. After confirming that the prediction accuracy and generalization ability of the error mapping model meet the preset requirements, the error mapping model that passes the test is used as the data-driven error prediction model and integrated into the digital twin model.

[0011] Furthermore, during the real-time operation of the CNC machine tool, the digital twin model is synchronously driven to perform virtual simulation, specifically including: While the CNC system of the CNC machine tool is executing the machining program, it simultaneously sends the same sequence of CNC machine tool motion control commands, spindle status commands and load status information to the digital twin model that integrates the data-driven error prediction model. The digital twin model drives the geometric structure model and kinematic model to perform synchronous simulation in virtual space based on the received instructions and status information, and calculates the theoretical position, velocity and acceleration of each motion axis of the machine tool in real time. During the synchronous simulation, the theoretical position, velocity, and acceleration of each axis in the digital twin model, as well as the virtual temperature field data output by the sensors integrated within the digital twin model, are collected in real time with the same interpolation cycle as the CNC system. These data are used as the real-time input feature stream of the data-driven error prediction model.

[0012] Furthermore, based on the data-driven error prediction model, the spatial error of the current and several future interpolation periods is predicted in advance, specifically including: At the beginning of each interpolation cycle, the actual feedback position and drive current of each motion axis in the current and several past cycles are read from the CNC machine tool, and feature fusion is performed with the synchronous theoretical motion data and virtual temperature data output by the digital twin model to form the complete state feature vector at the current moment. The complete state feature vector at the current moment is input into the data-driven error prediction model, and the data-driven error prediction model outputs the spatial error prediction value of the CNC machine tool end effector at the end of the current interpolation cycle. Based on the known future motion command queue of the CNC system and the future motion state pre-calculated by the digital twin model, combined with the data-driven error prediction model to model the error evolution law, the spatial error value at the end of multiple interpolation cycles is recursively predicted, forming an advanced prediction error sequence.

[0013] Furthermore, the predicted spatial error values ​​are converted into real-time compensation values ​​for the motion commands of each CNC axis and sent to the controller of the CNC machine tool to achieve dynamic feedforward compensation for spatial errors. Specifically, this includes: The spatial error values ​​of the current and several future interpolation cycles output by the data-driven error prediction model are decomposed into individual position compensation amounts corresponding to each linear motion axis based on the real-time motion axis linkage relationship of the CNC machine tool. Based on the interpolation cycle and command issuance sequence of the CNC system, the position compensation amount of each axis obtained by decomposition is vector-superimposed with the theoretical motion command position of each axis in the future interpolation cycles currently being planned by the CNC system, to generate the motion command sequence after compensation for each axis; The compensated sequence of motion commands for each axis is sent to the physical controller of the CNC machine tool through the CNC machine tool communication interface at a frequency not less than the interpolation cycle of the CNC system. The physical controller drives the servo actuator, so that the actual motion trajectory of the CNC machine tool cancels out the predicted spatial error, thus realizing dynamic feedforward compensation for spatial error.

[0014] Furthermore, the spatial error values ​​of the current and several future interpolation cycles output by the data-driven error prediction model are decomposed into individual position compensation amounts corresponding to each linear motion axis based on the real-time motion axis linkage relationship of the CNC machine tool, including: The basic data is input into the data-driven error prediction model, which outputs the spatial error values ​​of the current and several future interpolation cycles. Based on the real-time motion axis linkage relationship of the CNC machine tool, the spatial error values ​​are initially decomposed to obtain the candidate compensation amount of each axis. The candidate compensation amount of each axis is input into the digital twin model for simulation. Based on the simulation results, the effective compensation amount that meets the preset requirements is selected, and the effective compensation amount is used as the initial individual. Spatial error compensation accuracy, motion command smoothness, and response delay are used as three evaluation indicators. Based on the mechanical characteristics of CNC machine tools, constraints are established. Based on the constraints, objective functions for the three evaluation indicators are established respectively, and the index function values ​​corresponding to the initial individual under the objective functions are calculated. If the index function values ​​of the three evaluation indicators of the first individual are not greater than the index function values ​​of the second individual, and at least one index function value of the first individual is less than the index function value of the second individual, then the way in which the first individual dominates the second individual is determined, and the dominance relationship of the initial individuals is determined. Based on the dominance relationship, the initial individuals are recursively divided into layers according to the rule that the first layer is dominated by no initial individual and the second layer is dominated by only one initial individual. Genetic operations are performed on the initial individuals in each layer of the initial individual stratification result to obtain the target individuals. The target individuals are then iteratively screened to obtain the next generation of individuals until the next generation of individuals meets the iteration termination condition, thus obtaining the target individual stratification result. The target individuals in the first layer of the target individual stratification result are selected as the optimal solution set. The individual position compensation amount corresponding to each linear motion axis is obtained based on the optimal solution set.

[0015] Furthermore, genetic operations are performed on the initial individuals in each layer of the initial individual stratification result to obtain the target individuals, including: Based on the working condition feature vector of the initial individuals, the working condition similarity between the initial individuals is determined, and the initial individuals with a working condition similarity greater than the preset similarity are selected as the parent population. Perform crossover and mutation operations on the parent population to obtain the offspring compensation amount, and obtain the offspring population based on the offspring compensation amount; The parent population is perturbed and mutated to obtain the mutation compensation amount, and the mutated parent population is obtained based on the mutation compensation amount. The target individual is obtained by merging the parent population, offspring population, and mutated parent population.

[0016] Compared with the prior art, the beneficial effects of the present invention are: This invention utilizes machine learning algorithms to directly learn the complex nonlinear mapping relationship between errors and multi-source states of machine tools from real-world operational big data. This enables more accurate characterization and prediction of time-varying and strongly coupled spatial errors generated during actual dynamic machining. By performing synchronous virtual simulation in a digital twin environment and based on real-time states and future motion commands, it can recursively predict spatial errors for several interpolation cycles in advance. This transforms the error compensation mode from traditional lag correction to active suppression, thus meeting the need for feedforward error prevention in high-speed and high-precision machining. By acquiring data online in real time, driving the digital twin model, and executing prediction and compensation, a closed adaptive optimization loop is formed. This loop can automatically adapt to changes in machining conditions, load, and environmental conditions, continuously improving compensation accuracy and robustness. This fundamentally solves the problems of poor model adaptability and inability to respond to dynamic changes in real time in traditional methods, significantly improving the machining accuracy and intelligence level of CNC machine tools. Attached Figure Description

[0017] Figure 1 This is a flowchart of the spatial error prediction and compensation method for CNC machine tools based on digital twins and data-driven methods according to the present invention. Detailed Implementation

[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0019] To address the shortcomings of existing CNC machine tool spatial error compensation methods, which generally rely on offline, fixed mechanistic models, making it difficult to accurately describe and adapt to the dynamic, time-varying, and nonlinear coupling characteristics of errors in actual machining, and lacking the ability to proactively predict and suppress future errors, please refer to [the relevant documentation / reference]. Figure 1 This embodiment provides the following technical solution: A method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches includes the following steps: Construct a digital twin model corresponding to a CNC machine tool. The digital twin model shall include at least the geometric structure model, kinematic model, and error mapping model for characterizing spatial errors of the CNC machine tool. For CNC machine tools, we will carry out industrial big data collection covering multiple working conditions, multiple motion trajectories, and multiple load states. The collected industrial big data includes at least the real-time position information of each motion axis of the CNC machine tool, drive current, temperature field distribution information, and actual spatial position error information obtained by laser interferometer. The collected raw industrial big data is processed by big data, including data cleaning, spatiotemporal synchronization and alignment of multi-source heterogeneous data, and construction of sample datasets for model training. The constructed sample datasets include training datasets, validation datasets, and test datasets. Big data analysis is performed on the processed sample dataset, and machine learning algorithms are used to train and optimize the error mapping model of the digital twin model to form a data-driven error prediction model. During the real-time operation of the CNC machine tool, the digital twin model is synchronously driven to perform virtual simulation, and based on the data-driven error prediction model, the spatial error of the current and several future interpolation cycles is predicted in advance. The predicted spatial error value is converted into a real-time compensation amount for the motion commands of each CNC axis and sent to the controller of the CNC machine tool to realize dynamic feedforward compensation for spatial error.

[0020] The technical effects of the above solution are as follows: By constructing a digital twin model that integrates geometry, kinematics, and error mapping models, and combining it with industrial big data collection under multiple working conditions, multiple trajectories, and multiple loads, high-precision modeling and dynamic representation of spatial errors of CNC machine tools can be achieved. By using big data processing methods such as data cleaning and spatiotemporal synchronization to construct a high-quality sample set, and by using machine learning algorithms to optimize the error mapping relationship, a data-driven error prediction model is formed. This model can synchronously simulate and predict the spatial error of future interpolation cycles during machine tool operation. On this basis, by converting the predicted error into motion axis compensation commands in real time, dynamic feedforward compensation is achieved, which significantly improves the machining accuracy and stability of CNC machine tools, while reducing the traditional compensation cost that relies on physical trial and error.

[0021] For CNC machine tools, we will conduct industrial big data collection covering multiple working conditions, multiple motion trajectories, and multiple load states, specifically including: In the digital twin simulation environment of CNC machine tools, based on the machining capabilities of CNC machine tools, a comprehensive calibration motion program set is automatically planned and generated, covering the entire stroke, multiple feed rates, multiple accelerations, and including complex spatial trajectories (such as three-dimensional figure-eight, diagonal and circular motions). While executing the comprehensive calibration motion program set on the CNC machine tool, the digital twin model is synchronously driven to run virtually, and the actual position encoder feedback, servo drive current and temperature sensor array data deployed on the key heat source and structural components of the machine tool are collected and time-synchronized in real time. A laser interferometer synchronized with the clock of the CNC system of the CNC machine tool is used to dynamically measure and record the actual spatial position error of the CNC machine tool when executing the comprehensive calibration motion program set at predetermined grid points in the workspace of the CNC machine tool. The measurement optical path of the laser interferometer is automatically positioned and switched by an automatic guidance device based on the measurement point coordinates pre-calculated according to the digital twin model. The collected CNC machine tool status data stream and the collected spatial error measurement data stream are spatiotemporally aligned and fused with the global clock and motion command sequence number of the CNC system as a reference to form a pairing data record of multi-source operating status of CNC machine tool and corresponding spatial error. Repeat the aforementioned steps, and before each repetition, artificially change the load state, spindle speed, and environmental conditions of the CNC machine tool to collect a complete set of industrial big data covering the multiple working conditions and multiple loads, so as to facilitate subsequent model training.

[0022] The technical effects of the above solution are as follows: By integrating digital twin simulation planning with multi-sensor synchronous acquisition, a comprehensive calibration program covering the entire workspace, multiple speeds, and multiple trajectories can be automatically generated and executed. This efficiently acquires a strictly paired dataset of multi-dimensional operating status data and high-precision spatial errors. By utilizing clock synchronization and sequence number alignment mechanisms, the spatiotemporal consistency of multi-source data streams such as actual axis position, current, and temperature with the dynamic measurement errors of the laser interferometer can be ensured. This lays a high-quality data foundation for building a high-fidelity error prediction model. Furthermore, by artificially changing the load and environmental conditions and repeatedly acquiring data, the operating condition coverage and generalization ability of the dataset can be further expanded, enabling the subsequently trained model to accurately characterize the comprehensive impact of complex dynamic factors on spatial errors.

[0023] Spatiotemporal synchronization alignment specifically includes: Using the interpolation cycle clock of the CNC machine tool's CNC system as the reference time axis, a unified timestamp is applied to all the collected raw industrial big data streams. Among them, the data streams from inside the CNC system are directly marked using the internal clock of the CNC system, while the data streams from external sensor networks are marked through a hardware clock module synchronized with the CNC system. For a data stream that has a fixed offset from the reference time axis, the system time deviation of the data stream is calculated and compensated by comparing the time stamps of the same physical event in different data streams. A virtual data bus indexed by the reference time axis is constructed. After time deviation compensation, each data stream is resampled to a unified high-frequency time series consistent with the interpolation cycle of the CNC system, based on the sampling frequency of each data stream and using a combination of forward filling and linear interpolation. For each time-aligned data record, the machine tool motion command code corresponding to the time the data record occurred, the theoretical position coordinates calculated by the digital twin model simulation, and the CNC machine tool motion status identifier are associated to form spatiotemporally aligned structured data with complete contextual information.

[0024] The technical effects of the above solution are as follows: using the CNC system interpolation cycle as a unified time reference, hardware synchronization and time deviation compensation ensure accurate alignment of multi-source heterogeneous data in the time dimension. By utilizing a virtual data bus combined with forward padding and linear interpolation techniques, all data streams are resampled to a high-frequency time series consistent with the actual control cycle of the CNC machine tool, thus solving the problem of data asynchrony caused by different sensor sampling frequencies and transmission delays. On this basis, by associating and fusing the time-aligned data with the corresponding motion commands, theoretical positions, and machine tool status indicators, a spatiotemporally aligned structured data with both accurate time synchronization and complete motion context is formed. This provides a strictly consistent and complete data foundation for the subsequent construction of a data-driven error prediction model, thereby improving the efficiency of model training and the accuracy of prediction results.

[0025] The construction of the sample dataset for model training specifically includes: From the data sequence that has been unified with timestamps and resampled, determine the measurement time corresponding to the actual spatial position error point measured by each laser interferometer; For each measurement moment, a data segment is extracted based on a continuous CNC machine tool operation data prior to that measurement moment. The start time of the data segment is dynamically determined by backtracking according to the CNC machine tool's motion state at that measurement moment. Specifically, when the CNC machine tool is in continuous motion during measurement, the start time is backtracked to the start time of the current motion command segment. When the CNC machine tool undergoes a switch from stationary to moving during measurement, the start time is backtracked to the time point that includes the complete preheating process. For each data segment obtained, a model training sample is generated. The input features of the sample are a set of time-series parameters extracted from the data segment, including the difference sequence between the command position and the feedback position of each motion axis, the absolute value sequence of the drive current of each axis, and the reading sequence of the temperature sensor at the spindle bearing and the lead screw nut seat. The label of the sample is the actual spatial position error value corresponding to the end time of the data segment. After normalizing all the generated samples, they are classified according to the spindle speed range, load weight range and ambient temperature range of the CNC machine tool when the sample was collected. Samples are randomly selected from each category in proportion to form training dataset, validation dataset and test dataset respectively. In this embodiment, the dynamic backtracking determination of the start time of the data segment specifically involves: based on the history of machine tool motion commands within a preset time period before the measurement time, identifying the start time point when the machine tool continuously executes the same set of interpolation commands, and using this time point as the start time of the data segment.

[0026] In this embodiment, the input features of the sample are constructed by extracting a set of timing parameters from the data segment in chronological order. Specifically, the set of parameters includes a sequence of the difference between the command position and the actual feedback position of each motion axis, a sequence of absolute values ​​of the servo drive current of each axis, and a sequence of temperature values ​​read from temperature sensors deployed on key heat sources and structural components such as spindle bearings and lead screw nut seats.

[0027] In this embodiment, the label of the sample directly corresponds to the end time of the data segment, that is, the spatial position error vector value actually measured and recorded by the laser interferometer at the end effector of the CNC machine tool. In this way, the multi-source state time series data of the machine tool within a specific time window is accurately associated with the final spatial error result, forming a complete sample pair for training the error prediction model.

[0028] The technical effects of the above solution are as follows: by tracing back the time-series data segment containing the complete motion state and preheating process before the measurement time, it is possible to construct a high-quality training sample that comprehensively reflects the dynamic error generation process of CNC machine tools. Furthermore, by classifying the samples according to spindle speed, load, and ambient temperature and randomly dividing the dataset in layers, it is ensured that the training set, validation set, and test set are evenly distributed under various working conditions, thus laying a solid and reliable data foundation for training a model that can accurately predict spatial errors under different operating conditions.

[0029] Based on the processed sample dataset, big data analysis is performed. Machine learning algorithms are used to train and optimize the error mapping model of the digital twin model, forming a data-driven error prediction model, specifically including: The training dataset is input into the error mapping model to be trained. A machine learning algorithm is used to iteratively train the error mapping model by taking the input features of the sample as input and the label of the sample as the expected output. The accuracy of the error mapping model during the iterative training process is verified and hyperparameters are tuned using the validation dataset. The prediction accuracy of the error mapping model is evaluated by comparing the spatial error values ​​predicted by the error mapping model with the actual measured spatial error values. Based on the evaluation results of the validation dataset, the structural parameters and learning parameters of the error mapping model are optimized and adjusted. The optimization and adjustment include, but are not limited to, adjusting the network depth, number of nodes, and regularization parameters of the model. The optimized final error mapping model is independently tested using the test dataset. After confirming that the prediction accuracy and generalization ability of the error mapping model meet the preset requirements, the error mapping model that passes the test is used as the data-driven error prediction model and integrated into the digital twin model.

[0030] The technical effects of the above solution are as follows: by using the training dataset for iterative training and combining it with the validation dataset for accuracy verification and hyperparameter tuning, not only is the structure and parameters of the error mapping model optimized, but the accuracy of the model in predicting the spatial error of CNC machine tools is also improved. The final evaluation of the optimized model through the independent test dataset ensures that the model not only has high accuracy but also good generalization ability and can be reliably applied to unseen working conditions. On this basis, the model that has passed the test is integrated into the digital twin system as a data-driven error prediction model, realizing dynamic and accurate prediction of machine tool spatial errors.

[0031] During the real-time operation of the CNC machine tool, the digital twin model is synchronously driven to perform virtual simulation, specifically including: While the CNC system of the CNC machine tool is executing the machining program, it simultaneously sends the same sequence of CNC machine tool motion control commands, spindle status commands and load status information to the digital twin model that integrates the data-driven error prediction model. The digital twin model drives the geometric structure model and kinematic model to perform synchronous simulation in virtual space based on the received instructions and status information, and calculates the theoretical position, velocity and acceleration of each motion axis of the machine tool in real time. During the synchronous simulation, the theoretical position, velocity, and acceleration of each axis in the digital twin model, as well as the virtual temperature field data output by the sensors integrated within the digital twin model, are collected in real time with the same interpolation cycle as the CNC system. These data are used as the real-time input feature stream of the data-driven error prediction model. In this embodiment, the process by which the digital twin model calculates the theoretical position, velocity, and acceleration of each motion axis of the machine tool in virtual space based on the received instructions and status information is as follows: The digital twin model parses the received CNC machine tool motion control instructions and, in conjunction with the spindle status and load information, performs inverse kinematics calculations based on the integrated machine tool kinematics model, decomposing the theoretical motion instructions of the end effector into a sequence of theoretical position instructions for each independent motion axis (such as the X, Y, and Z axes); the digital twin model uses the same interpolation cycle as the physical CNC system as the step size, and, based on this sequence of theoretical position instructions, calculates the theoretical instantaneous velocity and acceleration of each axis in each interpolation cycle through differential calculations; simultaneously, the geometric structure model is updated synchronously based on these calculated axis positions to ensure that the pose of the virtual CNC machine tool is strictly consistent with the theoretical instructions; the entire process is executed in real-time loops in the virtual simulation environment, thereby continuously outputting a data stream of theoretical motion states of each axis that is synchronized with and strictly corresponds to the instructions of the physical CNC machine tool.

[0032] The technical effect of the above solution is as follows: by synchronizing the control commands and status information between the CNC and the digital twin model in real time, the virtual CNC machine tool is driven to perform high-fidelity collaborative simulation, realizing the millisecond-level real-time calculation and extraction of the theoretical motion state and thermal characteristics of the CNC machine tool. This provides the error prediction model with a real-time input feature stream that is strictly synchronized with the physical machine tool, structurally consistent, and contains rich dynamic information, thereby ensuring the timeliness and accuracy of spatial error prediction.

[0033] Based on the data-driven error prediction model, the spatial error of the current and several future interpolation periods is predicted in advance, specifically including: At the beginning of each interpolation cycle, the actual feedback position and drive current of each motion axis in the current and several past cycles are read from the CNC machine tool, and feature fusion is performed with the synchronous theoretical motion data and virtual temperature data output by the digital twin model to form the complete state feature vector at the current moment. The complete state feature vector at the current moment is input into the data-driven error prediction model, and the data-driven error prediction model outputs the spatial error prediction value of the CNC machine tool end effector at the end of the current interpolation cycle. Based on the known future motion command queue of the CNC system and the future motion state pre-calculated by the digital twin model, combined with the data-driven error prediction model to model the error evolution law, the spatial error value at the end of multiple interpolation cycles in the future is recursively predicted, forming an advanced prediction error sequence. In this embodiment, at the beginning of each interpolation cycle, the actual feedback position and drive current of each motion axis within the current and several past cycles are read from the CNC machine tool, and feature fusion is performed with the synchronous theoretical motion data and virtual temperature data output by the digital twin model to form the complete state feature vector at the current moment. The process is as follows: Using a unified reference time axis (i.e., the CNC system interpolation cycle clock) as an index, the actual encoder feedback position sequence and servo drive current sequence of each axis within the current cycle and the predefined historical window length are synchronously read from the cache of the physical machine tool CNC system; at the same time, the same time window sequence is obtained from the simulation output cache of the digital twin model. The theoretical position sequence, theoretical velocity sequence, and theoretical acceleration sequence of each axis calculated by the model, as well as the virtual temperature sequence of key points (such as spindle bearings and lead screw nut seats) generated by simulation, are used to splice and arrange these multi-source data streams from both physical and virtual sources, which have been ensured to be time-consistent through the aforementioned spatiotemporal synchronization alignment method, according to a predefined characteristic order (e.g., organized by time step). The spliced ​​multidimensional time series data is flattened or structured to form a complete state feature vector that can comprehensively characterize the comparison between the actual and theoretical states of the CNC machine tool at that moment and the historical evolution process, so as to provide a data-driven error prediction model for real-time processing and prediction.

[0034] The technical effects of the above solution are as follows: By integrating physical machine tool feedback data with theoretical and virtual sensing data from the digital twin model in real time, a feature vector comprehensively reflecting the dynamic operating state of the machine tool is formed and input into the trained error prediction model, achieving high-precision real-time estimation of spatial error at the current moment. Furthermore, by combining known future motion commands with the future state pre-simulated by the digital twin, and utilizing the model's ability to capture the error evolution law, it is possible to recursively predict the spatial error of multiple interpolation cycles in the future, thereby generating a predicted error sequence. This provides predictive information for the CNC system, enabling dynamic feedforward compensation to respond in advance and offset impending errors, thereby improving the timeliness of error compensation and overall control accuracy.

[0035] The predicted spatial error values ​​are converted into real-time compensation values ​​for the motion commands of each CNC axis and sent to the controller of the CNC machine tool to achieve dynamic feedforward compensation for spatial errors. Specifically, this includes: The spatial error values ​​of the current and several future interpolation cycles output by the data-driven error prediction model are decomposed into individual position compensation amounts corresponding to each linear motion axis based on the real-time motion axis linkage relationship of the CNC machine tool. Based on the interpolation cycle and command issuance sequence of the CNC system, the position compensation amount of each axis obtained by decomposition is vector-superimposed with the theoretical motion command position of each axis in the future interpolation cycles currently being planned by the CNC system, to generate the motion command sequence after compensation for each axis; The compensated sequence of motion commands for each axis is sent to the physical controller of the CNC machine tool in real time and ahead of time through the CNC machine tool communication interface at a frequency no less than the interpolation cycle of the CNC system. The physical controller drives the servo actuator, so that the actual motion trajectory of the CNC machine tool cancels out the predicted spatial error, thereby realizing dynamic feedforward compensation for spatial error. In this embodiment, the process of decomposing the spatial error value output by the data-driven error prediction model into the single position compensation amount of each linear motion axis is as follows: The spatial error vector of the end effector in the current and several future interpolation cycles output by the prediction model is received. This vector is typically represented as the three-dimensional position deviation in the machine tool coordinate system (such as the workpiece coordinate system). Based on the real-time motion axis linkage relationship and configuration of the CNC machine tool at the current and corresponding future moments, i.e., the theoretical motion state determined by the kinematic model in the digital twin model, the spatial error vector is decomposed and projected onto the direction of each linear motion axis (e.g., X, Y, Z axes) using the inverse kinematic transformation of the machine tool or according to the cosine of the theoretical motion direction of each axis in the current interpolation cycle. For the error prediction value of the future cycle, the decomposition process requires the use of the theoretical pose of the corresponding future moment, pre-simulated and calculated by the digital twin model, as the inverse solution input. Finally, a sequence of position compensation amounts for each linear motion axis corresponding to the prediction time series is output.

[0036] The technical effects of the above solution are as follows: by decomposing the predicted spatial error into position compensation amounts for each motion axis in real time and accurately, and superimposing it with the future instructions preset by the CNC system in advance, a directly executable sequence of compensated instructions is formed. This achieves efficient and low-latency conversion of error prediction information into physical control actions. Furthermore, by sending the compensation instructions to the physical controller in real time at a frequency no less than the interpolation cycle, it ensures that the servo system can synchronously execute the corrected trajectory, enabling the actual movement of the machine tool to actively offset the predicted error. Ultimately, dynamic and accurate feedforward compensation of spatial errors is achieved at the root, thereby improving the static and dynamic machining accuracy of the CNC machine tool.

[0037] Working Principle: By constructing a digital twin integrating geometry, kinematics, and data-driven error models, big data on machine tool operation and errors under multiple working conditions is collected in advance. A predictive model that can accurately map the relationship between complex working conditions and spatial errors is trained. During actual machining, the digital twin model runs synchronously with the CNC machine tool, acquiring the CNC machine tool's status data in real time and inputting it into the predictive model. This allows for the advance calculation of spatial error values ​​at current and future moments. The predicted error is then decomposed and converted into real-time compensation for the motion commands of each CNC axis. Through the controller, the actual motion trajectory of the CNC machine tool actively cancels the predicted error. This invention overcomes the bottlenecks of traditional methods, such as inaccurate modeling and poor adaptability of dynamic time-varying errors, by transforming traditional post-measurement compensation into advance prediction and dynamic feedforward compensation based on twin simulation. This significantly improves machining accuracy and the machine tool's intelligent adaptive capability.

[0038] In one embodiment, the spatial error values ​​of the current and several future interpolation cycles output by the data-driven error prediction model are decomposed into individual position compensation amounts corresponding to each linear motion axis based on the real-time motion axis linkage relationship of the CNC machine tool, including: The basic data is input into the data-driven error prediction model, which outputs the spatial error values ​​of the current and several future interpolation cycles. Based on the real-time motion axis linkage relationship of the CNC machine tool, the spatial error values ​​are initially decomposed to obtain the candidate compensation amount of each axis. The candidate compensation amount of each axis is input into the digital twin model for simulation. Based on the simulation results, the effective compensation amount that meets the preset requirements is selected, and the effective compensation amount is used as the initial individual. Spatial error compensation accuracy, motion command smoothness, and response delay are used as three evaluation indicators. Based on the mechanical characteristics of CNC machine tools, constraints are established. Based on the constraints, objective functions for the three evaluation indicators are established respectively, and the index function values ​​corresponding to the initial individual under the objective functions are calculated. If the index function values ​​of the three evaluation indicators of the first individual are not greater than the index function values ​​of the second individual, and at least one index function value of the first individual is less than the index function value of the second individual, then the way in which the first individual dominates the second individual is determined, and the dominance relationship of the initial individuals is determined. Based on the dominance relationship, the initial individuals are recursively divided into layers according to the rule that the first layer is dominated by no initial individual and the second layer is dominated by only one initial individual. Genetic operations are performed on the initial individuals in each layer of the initial individual stratification result to obtain the target individuals. The target individuals are then iteratively screened to obtain the next generation of individuals until the next generation of individuals meets the iteration termination condition, thus obtaining the target individual stratification result. The target individuals in the first layer of the target individual stratification result are selected as the optimal solution set. The individual position compensation amount corresponding to each linear motion axis is obtained based on the optimal solution set.

[0039] In this embodiment, after each iteration, the obtained individuals are stratified and genetically processed to obtain new individuals before the next round of iteration is performed.

[0040] In this embodiment, effective compensation quantities that meet preset requirements are selected based on simulation results. For example, the preset requirements are servo current ≤ 0.8Irated and acceleration change rate ≤ 5000mm / s³.

[0041] The beneficial effects of the above design scheme are as follows: Initial individuals are generated through preliminary error decomposition and digital twin simulation screening. Spatial errors are first converted into candidate compensation quantities based on axis linkage relationships. Then, digital twin simulation verifies whether these quantities meet the physical constraints of the machine tool, ensuring that all initial individuals possess practical application potential. This avoids wasting resources on ineffective calculations during subsequent optimization processes and provides a high-quality starting point for multi-objective optimization, improving overall optimization efficiency. By using spatial error compensation accuracy, motion command smoothness, and response delay as core evaluation indicators, combined with the mechanical characteristics of CNC machine tools (such as servo limits and structural stiffness), constraints and objective functions are established. Simultaneously, machining accuracy, operational stability, and real-time performance are considered, avoiding problems such as pursuing accuracy while ignoring vibration or sacrificing compensation effects for speed. This fully matches the actual needs of high-speed and high-precision machining on CNC machine tools. The use of dominance relationship rules allows for the objective quantification of multi-objective performance differences among initial individuals. This judgment method is logically rigorous, clearly selecting individuals with superior comprehensive performance, avoiding optimization direction deviations caused by fuzzy evaluations, and providing a clear basis for subsequent hierarchical and evolutionary operations, ensuring that the optimization process does not deviate from the core objectives. The algorithm is recursively layered according to dominance relationships. The best individuals without dominance are assigned to the first layer, while those dominated by only a few individuals are assigned to subsequent layers. This prioritizes the initial individuals with the best overall performance, reducing the interference of inferior solutions on the optimization process. This allows subsequent genetic operations to focus on iteratively upgrading high-quality solutions, significantly improving the algorithm's convergence speed and optimization focus. Genetic operations (selection, crossover, mutation) enrich the diversity of target individuals, preventing the algorithm from getting trapped in local optima. After multiple rounds of iterative screening, the algorithm gradually approaches the global optimum, preserving the core advantages of high-quality individuals while exploring new optimization spaces through mutation operations. At the same time, the iterative mechanism can dynamically adapt to changes in machine tool operating conditions (such as load fluctuations and speed adjustments), ensuring the robustness of the final solution. Selecting individuals with different objectives in the first layer to form the optimal solution set allows for flexible matching of the optimal compensation amount based on the priorities of different processing scenarios (such as prioritizing accuracy in high-precision machining and smoothness in high-speed machining). This approach breaks the limitations of a single optimal solution, enabling the compensation strategy to adapt to different scenarios. The final output of the single-axis position compensation can achieve optimal synergy between accuracy, smoothness, and real-time performance in actual machining, significantly improving the machining accuracy and operational stability of CNC machine tools.

[0042] In one embodiment, genetic operations are performed on the initial individuals in each layer of the initial individual stratification result to obtain the target individual, including: Based on the working condition feature vector of the initial individuals, the working condition similarity between the initial individuals is determined, and the initial individuals with a working condition similarity greater than the preset similarity are selected as the parent population. Perform crossover and mutation operations on the parent population to obtain the offspring compensation amount, and obtain the offspring population based on the offspring compensation amount; Offspring compensation amount The calculation formula is as follows: ;in, Represents the iterative dynamic correction factor. Indicates the working condition fit weight of the parent population. Indicates the cross factor for operating condition adaptation. Indicates the first The constraint compliance coefficient of each parent individual. Indicates the first The constraint compliance coefficient of each parent individual. Indicates the first The amount of compensation for each parent individual. Indicates the first The amount of compensation for each parent individual. Indicates the baseline compensation amount; The parent population is perturbed and mutated to obtain the mutation compensation amount, and the mutated parent population is obtained based on the mutation compensation amount. Variation compensation The calculation formula is as follows: ;in, This represents the amount of compensation provided by the parent individual. This indicates the maximum permissible rate of change of compensation amount between adjacent interpolation cycles. Represents uniformly distributed random numbers. Indicates the current iteration number. Indicates the maximum number of iterations. Indicates the distribution index of variation; The target individual is obtained by merging the parent population, offspring population, and mutated parent population.

[0043] In this embodiment, the iterative dynamic correction factor dynamically adjusts the fusion ratio between the inheritance strength of the offspring's features from the parent and the baseline compensation amount based on the current iteration number, balancing the exploratory nature of the algorithm in the early stage and the convergence stability in the later stage. It is a key parameter to adapt to the real-time requirements of the interpolation cycle.

[0044] In this embodiment, the parent population working condition adaptation weight represents the adaptation priority of the parent individual participating in the crossover with the current processing working condition. The higher the weight, the more likely the offspring are to inherit the advantages of the parent under the current working condition.

[0045] In this embodiment, the working condition adaptation cross factor controls the fusion ratio of the parent compensation amount, and its value range is dynamically adjusted according to the load conditions to ensure the stability and exploratory balance of the offspring under different loads.

[0046] In this embodiment, the constraint compliance coefficient of the parent individual is used to evaluate the degree to which the compensation amount satisfies the servo constraints (current, motion continuity). The higher the compliance, the closer the coefficient is to 1, ensuring that the offspring inherits the constraint satisfaction characteristics of the parent.

[0047] In this embodiment, the baseline compensation amount is based on the inverse kinematics solution and error decomposition of the digital twin model. It is the baseline value that ensures the offspring compensation amount does not deviate from the core objective of error cancellation.

[0048] In this embodiment, the maximum allowable rate of change of compensation amount between adjacent interpolation cycles characterizes the maximum response capability of the CNC machine tool servo system to dynamic adjustments of compensation amount, limits the upper limit of the amplitude of variation disturbance, and avoids servo shock and motion trajectory jitter caused by sudden changes in compensation amount. It is a core constraint parameter to ensure the engineering effectiveness of the compensation amount after variation.

[0049] In this embodiment, uniformly distributed random numbers are used to introduce random perturbation characteristics, making the mutation operation exploratory and avoiding the algorithm from getting trapped in local optima.

[0050] In this embodiment, the variation distribution index represents the distribution characteristics of the control perturbation amplitude, so that the variation perturbation is locally concentrated, that is, most perturbations are small-scale fine-tuning, and a few are larger-scale explorations, which not only ensures the inheritance of the high-quality features of the parent generation, but also avoids excessive perturbation that leads to a decrease in the effectiveness of the solution.

[0051] The beneficial effects of the above design scheme are as follows: By calculating the similarity of the initial individuals' working condition feature vectors, individuals with similarity higher than a preset value are selected as the parent population. This ensures that all parent individuals are adapted to the current machining conditions (such as spindle speed, load, and ambient temperature), avoiding performance degradation in offspring caused by ineffective cross-condition crossover. Furthermore, parents with similar working conditions exhibit greater consistency in error compensation characteristics (such as error coupling patterns and constraint adaptation requirements). Subsequent genetic operations can focus on optimizing high-quality solutions under the current working conditions, reducing irrelevant exploration, improving evolutionary efficiency and the engineering adaptability of offspring. The crossover and mutation formula integrates multi-dimensional parameters, and the working condition adaptation weights of the parent population match the working condition priorities, ensuring optimal working condition adaptation. The cross-factor balance of the parent generation fusion ratio and the constraint compliance coefficient ensure that the offspring inherits the constraint compliance characteristics of the parent (such as servo current and motion continuity). The iterative dynamic correction factor dynamically adjusts the inheritance strength with each iteration, realizing the synergy of working condition adaptation, constraint compliance and iterative convergence. The benchmark compensation amount avoids the offspring compensation amount from deviating from the core objective due to cross operations, prevents mathematical optimization from deviating from engineering reality, and ensures the effectiveness of the core function of the offspring compensation amount. By fusion of the advantages of the parent compensation amount through parameter weighting, the generated offspring compensation amount not only inherits the multi-objective performance (accuracy, smoothness, delay) of the high-quality parent, but also avoids constraint violations through parameter adjustment, greatly improving the efficiency of the offspring.

[0052] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0053] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention.

Claims

1. A method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches, characterized in that, Includes the following steps: Construct a digital twin model corresponding to a CNC machine tool. The digital twin model shall include at least the geometric structure model, kinematic model, and error mapping model for characterizing spatial errors of the CNC machine tool. For CNC machine tools, we will carry out industrial big data collection covering multiple working conditions, multiple motion trajectories, and multiple load states. The collected industrial big data includes at least the real-time position information of each motion axis of the CNC machine tool, drive current, temperature field distribution information, and actual spatial position error information obtained by laser interferometer. The collected raw industrial big data is processed by big data, including data cleaning, spatiotemporal synchronization and alignment of multi-source heterogeneous data, and construction of sample datasets for model training. The constructed sample datasets include training datasets, validation datasets, and test datasets. Big data analysis is performed on the processed sample dataset, and machine learning algorithms are used to train and optimize the error mapping model of the digital twin model to form a data-driven error prediction model. During the real-time operation of the CNC machine tool, the digital twin model is synchronously driven to perform virtual simulation, and based on the data-driven error prediction model, the spatial error of the current and several future interpolation cycles is predicted in advance. The predicted spatial error value is converted into a real-time compensation amount for the motion commands of each CNC axis and sent to the controller of the CNC machine tool to realize dynamic feedforward compensation for spatial error.

2. The method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches according to claim 1, characterized in that, For CNC machine tools, we will conduct industrial big data collection covering multiple working conditions, multiple motion trajectories, and multiple load states, specifically including: In the digital twin simulation environment of CNC machine tools, based on the machining capabilities of CNC machine tools, a comprehensive calibration motion program set covering the entire stroke, multiple feed rates, multiple accelerations, and including complex spatial trajectories is automatically planned and generated; While executing the comprehensive calibration motion program set on the CNC machine tool, the digital twin model is synchronously driven to run virtually, and the actual position encoder feedback, servo drive current and temperature sensor array data deployed on the key heat source and structural components of the machine tool are collected and time-synchronized in real time. A laser interferometer synchronized with the clock of the CNC machine tool's CNC system is used to dynamically measure and record the actual spatial position error of the CNC machine tool when executing the comprehensive calibration motion program set at predetermined grid points within the CNC machine tool's workspace. The collected CNC machine tool status data stream and the collected spatial error measurement data stream are spatiotemporally aligned and fused with the global clock and motion command sequence number of the CNC system as a reference to form a pairing data record of multi-source operating status of CNC machine tool and corresponding spatial error. Repeat the aforementioned steps, and before each repetition, manually change the load state, spindle speed, and environmental conditions of the CNC machine tool to collect a complete set of industrial big data covering the multiple working conditions and multiple loads.

3. The method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches according to claim 1, characterized in that, Spatiotemporal synchronization alignment specifically includes: Using the interpolation cycle clock of the CNC machine tool's CNC system as the reference time axis, a unified timestamp is applied to all the collected raw industrial big data streams. Among them, the data streams from inside the CNC system are directly marked using the internal clock of the CNC system, while the data streams from external sensor networks are marked through a hardware clock module synchronized with the CNC system. For a data stream that has a fixed offset from the reference time axis, the system time deviation of the data stream is calculated and compensated by comparing the time stamps of the same physical event in different data streams. A virtual data bus indexed by the reference time axis is constructed. After time deviation compensation, each data stream is resampled to a unified high-frequency time series consistent with the interpolation cycle of the CNC system, based on the sampling frequency of each data stream and using a combination of forward filling and linear interpolation. For each time-aligned data record, the machine tool motion command code corresponding to the time the data record occurred, the theoretical position coordinates calculated by the digital twin model simulation, and the CNC machine tool motion status identifier are associated to form spatiotemporally aligned structured data with complete contextual information.

4. The method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches according to claim 1, characterized in that, The construction of the sample dataset for model training specifically includes: From the data sequence that has been unified with timestamps and resampled, determine the measurement time corresponding to the actual spatial position error point measured by each laser interferometer; For each measurement moment, a data segment is extracted based on a continuous CNC machine tool operation data prior to that measurement moment. The start time of the data segment is dynamically determined by backtracking according to the CNC machine tool's motion state at that measurement moment. Specifically, when the CNC machine tool is in continuous motion during measurement, the start time is backtracked to the start time of the current motion command segment. When the CNC machine tool undergoes a switch from stationary to moving during measurement, the start time is backtracked to the time point that includes the complete preheating process. For each data segment obtained, a model training sample is generated. The input features of the sample are a set of time-series parameters extracted from the data segment, including the difference sequence between the command position and the feedback position of each motion axis, the absolute value sequence of the drive current of each axis, and the reading sequence of the temperature sensor at the spindle bearing and the lead screw nut seat. The label of the sample is the actual spatial position error value corresponding to the end time of the data segment. After normalizing all generated samples, they are classified according to the spindle speed range, load weight range, and ambient temperature range of the CNC machine tool when the samples were collected. Samples are then randomly selected from each category in proportion to form training datasets, validation datasets, and test datasets.

5. The method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches according to claim 1, characterized in that, Based on the processed sample dataset, big data analysis is performed. Machine learning algorithms are used to train and optimize the error mapping model of the digital twin model, forming a data-driven error prediction model, specifically including: The training dataset is input into the error mapping model to be trained. A machine learning algorithm is used to iteratively train the error mapping model by taking the input features of the sample as input and the label of the sample as the expected output. The accuracy of the error mapping model during the iterative training process is verified and hyperparameters are tuned using the validation dataset. The prediction accuracy of the error mapping model is evaluated by comparing the spatial error values ​​predicted by the error mapping model with the actual measured spatial error values. Based on the evaluation results of the validation dataset, the structural parameters and learning parameters of the error mapping model are optimized and adjusted. The optimization and adjustment include, but are not limited to, adjusting the network depth, number of nodes, and regularization parameters of the model. The optimized final error mapping model is independently tested using the test dataset. After confirming that the prediction accuracy and generalization ability of the error mapping model meet the preset requirements, the error mapping model that passes the test is used as the data-driven error prediction model and integrated into the digital twin model.

6. The method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches according to claim 1, characterized in that, During the real-time operation of the CNC machine tool, the digital twin model is synchronously driven to perform virtual simulation, specifically including: While the CNC system of the CNC machine tool is executing the machining program, it simultaneously sends the same sequence of CNC machine tool motion control commands, spindle status commands and load status information to the digital twin model that integrates the data-driven error prediction model. The digital twin model drives the geometric structure model and kinematic model to perform synchronous simulation in virtual space based on the received instructions and status information, and calculates the theoretical position, velocity and acceleration of each motion axis of the machine tool in real time. During the synchronous simulation, the theoretical position, velocity, and acceleration of each axis in the digital twin model, as well as the virtual temperature field data output by the sensors integrated within the digital twin model, are collected in real time with the same interpolation cycle as the CNC system. These data are used as the real-time input feature stream of the data-driven error prediction model.

7. The method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches according to claim 1, characterized in that, Based on the data-driven error prediction model, the spatial error of the current and several future interpolation periods is predicted in advance, specifically including: At the beginning of each interpolation cycle, the actual feedback position and drive current of each motion axis in the current and several past cycles are read from the CNC machine tool, and feature fusion is performed with the synchronous theoretical motion data and virtual temperature data output by the digital twin model to form the complete state feature vector at the current moment. The complete state feature vector at the current moment is input into the data-driven error prediction model, and the data-driven error prediction model outputs the spatial error prediction value of the CNC machine tool end effector at the end of the current interpolation cycle. Based on the known future motion command queue of the CNC system and the future motion state pre-calculated by the digital twin model, combined with the data-driven error prediction model to model the error evolution law, the spatial error value at the end of multiple interpolation cycles is recursively predicted, forming an advanced prediction error sequence.

8. The method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches according to claim 1, characterized in that, The predicted spatial error values ​​are converted into real-time compensation values ​​for the motion commands of each CNC axis and sent to the controller of the CNC machine tool to achieve dynamic feedforward compensation for spatial errors. Specifically, this includes: The spatial error values ​​of the current and several future interpolation cycles output by the data-driven error prediction model are decomposed into individual position compensation amounts corresponding to each linear motion axis based on the real-time motion axis linkage relationship of the CNC machine tool. Based on the interpolation cycle and command issuance sequence of the CNC system, the position compensation amount of each axis obtained by decomposition is vector-superimposed with the theoretical motion command position of each axis in the future interpolation cycles currently being planned by the CNC system, to generate the motion command sequence after compensation for each axis; The compensated sequence of motion commands for each axis is sent to the physical controller of the CNC machine tool through the CNC machine tool communication interface at a frequency not less than the interpolation cycle of the CNC system. The physical controller drives the servo actuator, so that the actual motion trajectory of the CNC machine tool cancels out the predicted spatial error, thus realizing dynamic feedforward compensation for spatial error.

9. The method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches according to claim 8, characterized in that, The spatial error values ​​of the current and several future interpolation cycles output by the data-driven error prediction model are decomposed into individual position compensation amounts corresponding to each linear motion axis based on the real-time motion axis linkage relationship of the CNC machine tool, including: The basic data is input into the data-driven error prediction model, which outputs the spatial error values ​​of the current and several future interpolation cycles. Based on the real-time motion axis linkage relationship of the CNC machine tool, the spatial error values ​​are initially decomposed to obtain the candidate compensation amount of each axis. The candidate compensation amount of each axis is input into the digital twin model for simulation. Based on the simulation results, the effective compensation amount that meets the preset requirements is selected, and the effective compensation amount is used as the initial individual. Spatial error compensation accuracy, motion command smoothness, and response delay are used as three evaluation indicators. Based on the mechanical characteristics of CNC machine tools, constraints are established. Based on the constraints, objective functions for the three evaluation indicators are established respectively, and the index function values ​​corresponding to the initial individual under the objective functions are calculated. If the index function values ​​of the three evaluation indicators of the first individual are not greater than the index function values ​​of the second individual, and at least one index function value of the first individual is less than the index function value of the second individual, then the way in which the first individual dominates the second individual is determined, and the dominance relationship of the initial individuals is determined. Based on the dominance relationship, the initial individuals are recursively divided into layers according to the rule that the first layer is dominated by no initial individual and the second layer is dominated by only one initial individual. Genetic operations are performed on the initial individuals in each layer of the initial individual stratification result to obtain the target individuals. The target individuals are then iteratively screened to obtain the next generation of individuals until the next generation of individuals meets the iteration termination condition, thus obtaining the target individual stratification result. The target individuals in the first layer of the target individual stratification result are selected as the optimal solution set. The individual position compensation amount corresponding to each linear motion axis is obtained based on the optimal solution set.

10. The method for predicting and compensating spatial errors in CNC machine tools based on digital twins and data-driven approaches according to claim 9, characterized in that, Genetic operations are performed on the initial individuals in each layer of the initial individual stratification result to obtain the target individuals, including: Based on the working condition feature vector of the initial individuals, the working condition similarity between the initial individuals is determined, and the initial individuals with a working condition similarity greater than the preset similarity are selected as the parent population. Perform crossover and mutation operations on the parent population to obtain the offspring compensation amount, and obtain the offspring population based on the offspring compensation amount; The parent population is perturbed and mutated to obtain the mutation compensation amount, and the mutated parent population is obtained based on the mutation compensation amount. The target individual is obtained by merging the parent population, offspring population, and mutated parent population.