A high-frequency sampling error compensation method and system for a numerical control system software layer
By performing timestamp calibration and high-frequency reconstruction of multi-source state variables at the CNC system software layer, the problem of difficulty in obtaining high-frequency state variables for upper-level applications is solved, realizing real-time error compensation and forward-looking calculation, which is suitable for high-frequency processing of servo axes, spindles, turrets and temperature signals.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ZHEJIANG ADVANCED CNC MASCH TOOL TECH INNOVATION CENT CO LTD
- Filing Date
- 2026-04-29
- Publication Date
- 2026-06-19
Smart Images

Figure CN122239587A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of numerical control technology, industrial automation control, servo status acquisition and precision machining error compensation technology, and particularly relates to a method and system for high-frequency sampling error compensation in the software layer of a numerical control system. Background Technology
[0002] In high-precision CNC machining, the state variables of machine tool motion axes, spindles, turrets, and related actuators, such as position, angle, speed, temperature, current, switching status, and error, have a significant impact on machining accuracy, contour consistency, surface quality, and equipment stability. To achieve high-quality control of the machining process, it is usually necessary to acquire these state variables in real time and use them for error monitoring, dynamic compensation, status identification, and fault early warning.
[0003] However, in existing CNC systems, the data update cycle that upper-level applications can directly access is typically constrained by factors such as the CNC kernel task scheduling cycle, PLC scanning cycle, bus communication refresh cycle, servo feedback open interface refresh cycle, and peripheral acquisition module access cycle. Although there may be higher-frequency data updates in servo drives, encoder feedback links, or some internal control modules, this data cannot be directly provided to upper-level applications at the same high frequency, with a unified time base, and in a stable manner. Therefore, upper-level software can usually only observe the machine tool status at a lower frequency, making it difficult to capture transient fluctuations, local impacts, short-term disturbances, and error mutations during high-speed motion in a timely manner.
[0004] When upper-layer applications directly perform machining error compensation based on low-frequency or asynchronous sampling data, problems such as untimely error estimation, delayed compensation amount, inability to identify local anomalies, and unstable compensation effect are likely to occur. These problems are particularly prominent in high-precision turning, milling, turret tool changing, and composite machining scenarios.
[0005] In existing technologies, common improvement approaches include increasing the sampling frequency of the underlying hardware, adding external high-speed acquisition hardware, or using a single interpolation algorithm to supplement low-frequency data. However, the first two approaches usually require modifications to the original CNC system hardware structure, increasing system costs or affecting the stability of the original system; the latter approach often lacks unified time calibration and timing alignment for multi-source asynchronous data, making it difficult to directly meet the application requirements of high-precision error compensation.
[0006] Therefore, there is an urgent need for a method, system, and storage medium that can achieve high time resolution reconstruction of multi-source state variables at the software layer without modifying the underlying hardware structure of the CNC system, and further be used for machining error compensation. Summary of the Invention
[0007] The purpose of this invention is to address the aforementioned problems in the prior art by providing a high-frequency sampling error compensation method for the software layer of a numerical control system.
[0008] The objective of this invention can be achieved through the following technical solution: 1. A method for high-frequency sampling error compensation in the software layer of a numerical control system, characterized by comprising the following steps: S1: Collect raw sampling source data from multiple sampling frequencies, wherein the raw sampling source includes at least two of the following: servo or spindle feedback source, analog sampling source, temperature sampling source, and digital sampling source; S2: Append an absolute timestamp to the original sampled source data, and map the time information corresponding to each sampled source to a unified time base, wherein the first... Class sampling source absolute timestamp of each sampling point Determined by the following formula: ; In the formula, To unify the zero time of the system reference clock, For the first The local counter value of the sample source is sampled. The initial value of the counter at the instant of time synchronization. Local clock frequency, This is a fixed link delay correction amount. This is the amount of jitter compensation; S3: Within a preset sliding window, cache, sort, and time-align the multi-source raw data with appended timestamps to obtain an aligned dataset organized along a unified timeline. ,in To standardize absolute timestamps, For sampled values, For sampling source identification; S4: Based on the aligned dataset, use a cubic spline interpolation algorithm at the target time node to perform interpolation reconstruction and generate equivalent high-frequency state variables for the software layer. Reconstructing time series , Less than the original main sampling period And the interpolation function In the interval The above satisfies: ; in , The second derivative at the nodes is obtained by solving the tridiagonal system of equations: , ; And the equivalent high-frequency state quantity The temporal resolution is higher than the update frequency of at least one type of original sampled source data; S5: Calculate the machining error compensation amount based on the equivalent high-frequency state quantity, and output the machining error compensation amount to the compensation channel or related execution module of the CNC system to realize machining error compensation.
[0009] In the above-mentioned high-frequency sampling error compensation method for CNC system software layer, the servo or spindle feedback source includes at least one of feed axis encoder, spindle encoder, turret encoder, milling spindle encoder, and tool changer motor encoder.
[0010] In the above-mentioned high-frequency sampling error compensation method for the software layer of a CNC system, the timestamp is generated based on a unified system clock, or generated based on the local clocks of each sampling source and then converted to a unified time reference using the formula.
[0011] In the above-mentioned high-frequency sampling error compensation method for CNC system software layer, the preset sliding window length Set as the reference sampling period 3 to 10 times, that is .
[0012] In the above-mentioned high-frequency sampling error compensation method for the software layer of a CNC system, the interpolation reconstruction adopts a cubic spline interpolation algorithm, and its boundary conditions adopt natural boundary conditions. , or clamping boundary conditions.
[0013] In the above-mentioned high-frequency sampling error compensation method for the software layer of a CNC system, the equivalent high-frequency state quantities of the software layer include at least one of position quantity, velocity quantity, acceleration quantity, displacement change quantity, temperature quantity, current quantity, and switching event timing information.
[0014] In the above-mentioned high-frequency sampling error compensation method for CNC system software layer, the machining error compensation includes at least one of position error compensation, dynamic following error compensation, contour error compensation, and thermal error compensation; Thermal error compensation amount Calculated by the following formula: ; In the formula, The reconstructed temperature value. As the reference temperature, and Thermal error model coefficients.
[0015] In the above-mentioned high-frequency sampling error compensation method for CNC system software layer, the machining error compensation amount is written into the CNC system compensation parameter channel, servo correction channel, or motion control correction interface.
[0016] In the above-mentioned high-frequency sampling error compensation method of CNC system software layer, the preset sliding window is implemented by cyclic buffer or ring buffer, and maintains several recent valid sampling points for each sampling source, and removes or fills in missing points, late points or abnormal jump points.
[0017] A high-frequency sampling error compensation system for the software layer of a numerical control system, characterized in that it includes: The sampling acquisition module is used to collect raw sampling source data from multiple sampling frequencies; The time calibration module is used to append timestamps to the original sampled source data and map it to a unified time reference; The window alignment module is used to cache, sort, and time-align multi-source raw data within a preset sliding window to obtain an aligned dataset. The high-frequency reconstruction module is used to perform interpolation reconstruction on the target time node based on the aligned dataset to generate equivalent high-frequency state variables of the software layer. The compensation calculation module is used to calculate the machining error compensation amount based on the equivalent high-frequency state quantity; The compensation output module is used to output the machining error compensation amount to the compensation channel or related execution module of the CNC system.
[0018] Compared with existing technologies, the high-frequency sampling error compensation method and system for the software layer of this CNC system have the following advantages: 1. Without modifying the underlying hardware structure and inherent sampling period of the CNC system, the software layer can overcome the sampling frequency limitation visible to upper-layer applications. 2. By using unified time base mapping, multi-source caching, and window alignment, the timing consistency and data fusion capabilities among state variables from different sources are improved; 3. By reconstructing continuous quantities and event quantities at high frequency, the temporal resolution of the state observation of high-speed machining process is improved, which is more conducive to capturing transient disturbances, local deviations and abnormal action timing; 4. By directly using the reconstructed equivalent high-frequency state variables for error estimation and compensation output, the foresight, real-time performance, and engineering applicability of the compensation calculation are improved. 5. This invention is applicable to the unified processing of various heterogeneous signals such as servo axes, spindles, turrets, milling spindles, tool changers, temperature, current, and switching signals. Attached Figure Description
[0019] Figure 1 This is a logic diagram of the high-frequency sampling and processing error compensation method in this invention; Figure 2 This is a block diagram of the high-frequency sampling and processing error compensation system in this invention. Detailed Implementation
[0020] The following are specific embodiments of the present invention, which are described in conjunction with the accompanying drawings. However, the present invention is not limited to these embodiments.
[0021] like Figure 1 , Figure 2 As shown, the high-frequency sampling error compensation method and system of this CNC system software layer are applied to CNC equipment for turning, milling or composite machining. By performing unified time calibration, window alignment and high-frequency reconstruction on the original sampling source data of different frequencies, an equivalent high-frequency state quantity that can be called by the machining error compensation module is generated.
[0022] Assume the X-axis encoder sampling period is 4ms (250Hz), the temperature sampling period is 100ms (10Hz), and the switching signal sampling period is 1ms (1kHz). After timestamp calibration, the sliding window length is set to 20ms (5 reference periods), containing 5 position points, 1 temperature point, and 20 switching event points. After cubic spline interpolation, the position data is reconstructed with an output period of 1ms, resulting in an equivalent high-frequency position sequence with a time resolution four times that of the original. This sequence is compared with the commanded position, the position error compensation is calculated, and written to the servo correction channel.
[0023] S1. Acquisition of the original sampling source In this embodiment, the original sampling sources include at least the following four types: The first category is servo or spindle encoder feedback sources. Specifically, this includes X-axis and Z-axis encoders, both employing equivalent multi-turn absolute encoders. These encoders have 24-bit single-turn absolute resolution and 12-bit multi-turn counting capability, providing high-resolution absolute angular position within one turn and multi-turn absolute position information within a range of 4096 turns. Turret or milling spindle encoders also employ equivalent single-turn absolute encoders with a single-turn resolution of 24 bits. Turret tool changer motor encoders employ equivalent multi-turn absolute encoders with an absolute resolution of 22 bits and 12-bit multi-turn counting capability. The encoder interface can be an M17 circular interface or an equivalent industrial interface, depending on the installation environment. In low-vibration scenarios, an RJ45 or equivalent signal interface can also be used. This type of sampling source is used to acquire the position, angle, relative displacement, or speed-related state quantities of each motion axis, turret, and related actuators. The second category is temperature sensor sources. Specifically, this includes replacement platinum resistance temperature sensors of the same specifications installed inside or near the thermal location of the servo motor or spindle motor, such as a 1000Ω nominal resistance platinum resistance temperature sensor, using a three-wire or four-wire connection method, to obtain the motor temperature rise status and provide auxiliary information for thermal error modeling and thermal drift compensation; The third category is analog A / D sampling sources. For example, a 4-channel A / D sampling system can be used to acquire current, voltage, vibration, force, or other auxiliary analog signals. To improve the quality of subsequent high-frequency reconstruction, the A / D channels can adopt a unified sampling interrupt driving method, and the sampling time information can be immediately appended after each conversion. The fourth category is digital I / O sampling sources. These sampling sources are used to acquire discrete event information such as tool change, limit switch, position adjustment, clamping, alarm, and process stage switching. In this embodiment, the sampling frequency is approximately 1kHz. Besides serving as a status sampling source, digital signals can also be used as event trigger markers for determining the effective time of subsequent timeline correction and compensation. The available frequencies of the different sampling sources can vary depending on the control cycle, communication refresh frequency, and interface access cycle. In this embodiment, the available frequencies of the servo or spindle encoder feedback data are 250Hz to 8kHz.
[0024] S2. Absolute timestamp calibration To achieve unified time-series fusion of multi-source data, this embodiment adds an absolute timestamp to the data from each sampling source and maps the local sampling times of different sampling sources to the same absolute time base. This embodiment specifies this as follows: Let the zero point of the unified system reference clock be... , No. The local counter value of the sample source is The local clock frequency is The initial value of the counter of the sampling source at the instant of reference time synchronization is The fixed link delay correction is The jitter compensation amount is Then the first Class sampling source absolute timestamp of each sampling point It can be represented as: ; in, Used to compensate for the fixed delays introduced by bus transmission, driver buffering, A / D conversion, task scheduling, and interface refresh; This is used to compensate for instantaneous deviations caused by communication congestion, operating system scheduling jitter, or asynchronous thread wake-up errors during real-time operation. For sampling sources without independent local clocks, data can be directly stamped by a high-precision system clock when it enters the buffer queue, and the stamping result can be reversed by combining the average link delay of the sampling source to obtain the estimated sampling time. Timestamp calibration includes the following sub-steps: (1) Establish a unified reference clock, using at least one of the following as the global reference clock: the real-time kernel clock of the CNC system, the high-precision monotonic clock of the industrial PC, or the hardware clock of the motion control card. (2) Establish the local time mapping relationship of the sampling source. For drivers, encoder interface modules or A / D acquisition modules with local clocks, record the one-time correspondence between their local counter values and the global reference clock, forming a local time mapping relationship. Mapping point; (3) Determine the fixed link delay. Determine the data arrival delay of various sampling sources through multiple round-trip tests or offline calibration, and use the average value or steady-state value as the reference value. ; (4) Online jitter correction. The time interval of several consecutive sampling points is filtered using moving average or median to extract abnormal deviations and form... Correction amount; (5) Unified write to cache. Write the original sampled value, sampled source identifier, absolute timestamp, and validity flag together to the asynchronous cache area; Through the above timestamp calibration method, although different sampling sources have different sampling frequencies, different refresh phases and different data arrival times, they can all be mapped to a unified absolute time axis, thus providing a unified basis for subsequent sorting, alignment and high-frequency reconstruction within the sliding window.
[0025] S3. Sliding window cache aligned with time. The multi-source data, with appended absolute timestamps, is written to the buffer and cached, sorted, and time-aligned according to a preset sliding window. The sliding window length is set to 3 to 10 times the original sampling period; in this embodiment, 5 original sampling periods are selected. If the original sampling period of the main sampling source is Then the length of the sliding window Take as: ; Window step size It can be set to the target output period or an integer multiple thereof, for the window. All sampling points within the window are first sorted in ascending order by absolute timestamp, then grouped according to sampling source type, and duplicate, out-of-bounds, and invalid points are removed. For discrete events, such as limit switches, alarms, and tool changers, they can be used as event markers within the window; for continuous state variables, such as position, angle, temperature, and current, they are used as the original nodes for interpolation reconstruction. After alignment, a unified dataset is formed. ; in, To standardize absolute timestamps, For sampled values, This is the identifier for the sampling source.
[0026] S4. High-frequency reconstruction Based on the multi-source raw data after time alignment, a cubic spline interpolation algorithm is used within a sliding window to perform high-frequency reconstruction, generating an equivalent high-frequency state quantity with a time resolution higher than the update frequency of the original sampling source. Let the effective sampling nodes of a certain continuous state variable within the window be: ; Let the time interval between adjacent nodes be: ; In each interval Construct a cubic spline function on top: ; The cubic spline satisfies the following condition: (1) Interpolation conditions: ; (2) Continuity condition of the first derivative: ; (3) Condition for continuity of the second derivative: ; (4) Natural boundary conditions are adopted, i.e. ; Clamping boundary conditions can also be used based on known endpoint velocity information to improve the accuracy of boundary segment reconstruction; Furthermore, the second derivative at each node is defined as... ,but Satisfies the tridiagonal system of equations: ; in After solving this system of equations, the interval can be obtained. spline expression on: ; After obtaining the piecewise spline function within the window, the target high-frequency output period is determined. Generate reconstructed time series: ; And for each The corresponding interval is called The equivalent high-frequency state variables of the software layer are obtained as follows: ; in, Less than the original main sampling period In this embodiment, it is taken as , For example, when the main sampling period is 4ms, it can be... Set to 1ms or 0.5ms to obtain equivalent high-frequency sequences with 4x or 8x time resolution; Independent spline functions are established for different continuous state variables. For smoothly changing signals such as servo axis position, turret angle, spindle angular displacement, and temperature change, cubic spline interpolation is directly used. For signals with abrupt boundary changes, segmented modeling can be performed at event marker points to avoid unreasonable smoothing across discrete events such as tool change, clamping, releasing, and limit collision. When the number of sample points in the window is less than 4, linear interpolation or quadratic interpolation can be used to degenerate and ensure computational stability. Using the above method, the generated equivalent high-frequency state variables not only remain consistent with the original sampled values at the nodes, but also have the characteristic of continuous first and second derivatives within the window, making them more suitable for estimating velocity, acceleration, and thermal drift trends in subsequent error compensation.
[0027] S5. Machining Error Compensation The reconstructed equivalent high-frequency state quantities are input into the machining error compensation module, which calculates the compensation amount and outputs it to the corresponding compensation channel or execution module of the CNC system. The machining error compensation includes, but is not limited to, the following types: Firstly, position error compensation. Based on the axis position after high-frequency reconstruction. With the target trajectory The deviation between them is used to calculate the positional error: ; And generate position correction amount according to preset gain or compensation mapping relationship. ; Secondly, dynamic tracking error compensation. Based on the real-time tracking differences reflected by high-frequency state variables, a tracking error is constructed: ; in To control the position of the command, After feedforward or gain correction, a compensation amount is generated for the servo response; Third, contour error compensation: In multi-axis linkage or turret coordinated operation, the normal deviation between the actual contour point and the theoretical contour point is estimated based on the high-frequency reconstruction state variables of each axis, and the normal deviation is mapped to the compensation components of each axis. Fourth, thermal error compensation, based on the high-frequency reconstructed value of motor temperature. Based on its rate of change and a pre-established thermal error model, the thermal drift compensation is calculated: ; in As the reference temperature, and These are the coefficients of the thermal error model; In comprehensive compensation, the total compensation amount can be expressed as: ; in This is the contour error compensation component. Finally, the total compensation amount is output to the CNC system compensation module or related execution module to achieve real-time correction of the machining process.
[0028] Electronic device examples This invention also provides an electronic device, including a processor and a memory. The memory stores a computer program, which, when executed by the processor, implements the high-frequency sampling error compensation method for the software layer of the CNC system according to any of the above embodiments. The electronic device can be a host computer of a CNC system, an industrial controller, an embedded industrial control computer, or an edge computing gateway, etc. The processor can be a CPU, DSP, MCU, or FPGA, and the memory can be a non-volatile storage medium such as ROM, RAM, flash memory, or solid-state drive.
[0029] Storage Media Examples The present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it implements the high-frequency sampling error compensation method for the software layer of the CNC system according to any of the above embodiments. The storage medium can be any medium capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory, a random access memory, a magnetic disk, or an optical disk.
[0030] The specific embodiments described herein are merely illustrative of the spirit of the invention. Those skilled in the art to which this invention pertains may make various modifications or additions to the described specific embodiments or use similar methods to substitute them, without departing from the spirit of the invention or exceeding the scope defined by the appended claims.
[0031] Although this document uses a considerable amount of technical terms, the possibility of using other terms is not excluded. These terms are used merely for the convenience of describing and explaining the essence of the invention; interpreting them as any additional limitation would be contrary to the spirit of the invention.
Claims
1. A method for compensating for high-frequency sampling errors in the software layer of a numerical control system, characterized in that, Includes the following steps: S1: Collect raw sampling source data from multiple sampling frequencies, wherein the raw sampling source includes at least two of the following: servo or spindle feedback source, analog sampling source, temperature sampling source, and digital sampling source; S2: Append an absolute timestamp to the original sampled source data, and map the time information corresponding to each sampled source to a unified time base, wherein the first... Class sampling source absolute timestamp of each sampling point Determined by the following formula: ; In the formula, To unify the zero time of the system reference clock, For the first The local counter value of the sample source is sampled. The initial value of the counter at the instant of time synchronization. Local clock frequency, This is a fixed link delay correction amount. This is the amount of jitter compensation; S3: Within a preset sliding window, cache, sort, and time-align the multi-source raw data with appended timestamps to obtain an aligned dataset organized along a unified timeline. ,in To standardize absolute timestamps, For sampled values, For sampling source identification; S4: Based on the aligned dataset, use a cubic spline interpolation algorithm at the target time node to perform interpolation reconstruction and generate equivalent high-frequency state variables for the software layer. Reconstructing time series , Less than the original main sampling period And the interpolation function In the interval The above satisfies: ; in , The second derivative at the nodes is obtained by solving the tridiagonal system of equations: , ; And the equivalent high-frequency state quantity The temporal resolution is higher than the update frequency of at least one type of original sampled source data; S5: Calculate the machining error compensation amount based on the equivalent high-frequency state quantity, and output the machining error compensation amount to the compensation channel or related execution module of the CNC system to realize machining error compensation.
2. The method for compensating for high-frequency sampling errors in the software layer of a CNC system according to claim 1, characterized in that, The servo or spindle feedback source includes at least one of the following: feed axis encoder, spindle encoder, turret encoder, milling spindle encoder, and tool changer motor encoder.
3. The method for compensating for high-frequency sampling errors in the software layer of a CNC system according to claim 1, characterized in that, The timestamp is generated based on a unified system clock, or generated based on the local clocks of each sampling source and then converted to a unified time base using the formula.
4. The method for compensating for high-frequency sampling errors in the software layer of a CNC system according to claim 1, characterized in that, The preset sliding window length Set as the reference sampling period 3 to 10 times, that is .
5. The method for high-frequency sampling error compensation in the software layer of a CNC system according to claim 1, characterized in that, The interpolation reconstruction employs a cubic spline interpolation algorithm, and its boundary conditions are natural boundary conditions. , or clamping boundary conditions.
6. The method for high-frequency sampling error compensation in the software layer of a CNC system according to claim 1, characterized in that, The equivalent high-frequency state quantities of the software layer include at least one of position, velocity, acceleration, displacement change, temperature, current, and switching event timing information.
7. The method for compensating for high-frequency sampling errors in the software layer of a CNC system according to claim 1, characterized in that, The machining error compensation includes at least one of position error compensation, dynamic following error compensation, contour error compensation, and thermal error compensation. Thermal error compensation amount Calculated by the following formula: ; In the formula, The reconstructed temperature value. As the reference temperature, and Thermal error model coefficients.
8. The method for compensating for high-frequency sampling errors in the software layer of a CNC system according to claim 1, characterized in that, The machining error compensation amount is written into the CNC system compensation parameter channel, servo correction channel, or motion control correction interface.
9. A method for compensating for high-frequency sampling errors in the software layer of a numerical control system according to claim 1, characterized in that, The preset sliding window is implemented using a circular buffer or a ring buffer. For each sampling source, several recent valid sampling points are maintained, and missing points, late points, or abnormal jump points are removed or supplemented.
10. A high-frequency sampling error compensation system for the software layer of a numerical control system, characterized in that, include: The sampling acquisition module is used to collect raw sampling source data from multiple sampling frequencies; The time calibration module is used to append timestamps to the original sampled source data and map it to a unified time reference; The window alignment module is used to cache, sort, and time-align multi-source raw data within a preset sliding window to obtain an aligned dataset. The high-frequency reconstruction module is used to perform interpolation reconstruction on the target time node based on the aligned dataset to generate equivalent high-frequency state variables of the software layer. The compensation calculation module is used to calculate the machining error compensation amount based on the equivalent high-frequency state quantity; The compensation output module is used to output the machining error compensation amount to the compensation channel or related execution module of the CNC system.