CNC contour error compensation is challenging because the tool’s actual path can deviate from its programmed path for more than one reason. Feed axes have tracking error, their dynamic responses may differ, and mechanical effects such as backlash and friction can add nonlinear behavior. These influences matter particularly where the tool path changes direction or curves sharply. A data-driven approach combining deep learning and reinforcement learning offers a way to predict the resulting error and tune compensation while accounting for feed-system lag.
Why CNC contour error is difficult to control
In a CNC system, the controller sends reference positions to the feed axes, while the machine’s physical motion follows with some deviation. The tracking error of an individual axis contributes to contour error, but it does not fully describe it: the relative behavior of multiple axes also affects how closely the tool follows the intended path. A mismatch in axis dynamics can therefore produce contour deviation even when each axis is being controlled.
Tracking error itself has both linear and nonlinear components. The steady-state component can be related to feed velocity and the position-loop gain. Additional error can arise from nonlinearities in the drive and mechanical transmission, including friction and backlash. Modeling only the linear component risks missing effects that influence the actual worktable position—and, ultimately, the machined contour.
Compensation also has a timing problem. Because the feed system has inertia, changing a command does not necessarily change machine motion immediately. A correction applied without considering this lag may arrive too early or too late to reduce the error effectively. The compensation amount can also depend on the path, making parameter selection difficult.
Predicting CNC contour error from feed-axis data
The proposed method separates prediction into two connected tasks: estimate each axis’s tracking error, then use the predicted axis positions to calculate the deviation from the reference contour. It uses internal CNC data, including reference velocity, acceleration, and jerk, alongside historical tracking-error information.
For the nonlinear component, the method uses a Nonlinear Auto-Regressive Long Short-Term Memory network, or NAR-LSTM. LSTM networks are suited to time-series data because they can use patterns across previous time steps. During training, the model uses historical measured nonlinear tracking errors. When making predictions, it feeds its prior predicted errors back into the model, along with motion data. The predicted nonlinear component is combined with the linear tracking-error estimate to form an overall estimate for each feed axis.
For two-dimensional machining, predicted positions from the X and Y axes define an estimated tool path. The method calculates contour error by comparing points on that predicted path with nearby segments of the programmed path. This provides an estimate of the combined path deviation, rather than treating the axes’ errors as unrelated values.
Using reinforcement learning to tune compensation
Once the contour error has been estimated, the compensation strategy adjusts the reference positions sent to the CNC. Two parameters govern the correction: a forward compensation cycle and a compensation rate. The forward cycle accounts for system lag by applying a correction based on a contour error expected at a later point; the rate determines how much of that error is applied. The correction is resolved along the contour’s normal direction into axis-specific adjustments.
A Time-Series Deep Q-Network (TS-DQN) selects these parameters. Deep Q-networks learn which actions are useful by evaluating outcomes in an environment; here, the contour-error prediction model serves as that environment. The time-series version modifies experience replay so that rewards from recent steps can be updated in light of subsequent results. This is intended to make parameter identification more efficient for a system whose behavior unfolds over time.
The workflow is significant for implementation planning: prediction and parameter selection are performed offline for a given part program, and the resulting compensated positions are then sent to the CNC controller. The method is not simply a fixed correction applied to every path; it uses predicted contour behavior to select compensation settings.
What the CNC experiments reported
Tests were conducted on a three-axis milling center using circular and freeform 2D contours at four feedrates, from 1,200 to 4,800 mm/min. The NAR-LSTM model predicted axis tracking errors from CNC data, and the resulting contour-error predictions were compared with measured values. For the tested goggles path at 2,400 mm/min, the reported contour-error prediction deviation reached 9.1% of the maximum actual contour error.
Across the tested contours and feedrates, compensation reduced maximum absolute contour error by approximately 70.49% to 84.53%. In a physical cutting test of a circular contour, the reported maximum machining error fell from 15.1 μm to 7.6 μm after compensation. The study also reported that TS-DQN identified parameters in less computational time than the traditional DQN used for comparison in that experiment. These results describe the specific machine, paths, and test conditions; they should not be read as a guaranteed outcome for other CNC installations.
Practical implications for automation teams
For engineers and system integrators, the approach highlights the value of measuring actual worktable position rather than relying only on motor-side feedback when transmission effects need to be represented. The study used linear encoders to capture actual axis position and collected CNC data at a 1 kHz sampling frequency. Applying a similar modeling strategy would require suitable machine data, measured tracking behavior, and validation on the intended tool paths and operating conditions.
It also points to a useful distinction in compensation design: predicting an error accurately is not enough if the correction ignores machine response time. Modeling the path error and tuning both the correction timing and magnitude can address these issues together. However, the reported work focused on 2D contours; extension to 3D surface machining was identified as future work.
Conclusion
Combining NAR-LSTM tracking-error prediction with TS-DQN parameter selection provides a structured approach to CNC contour error compensation. It accounts for nonlinear feed-axis behavior, estimates the resulting path deviation, and incorporates lag into the correction strategy. The reported experiments show substantial reductions in contour and machining error under their test conditions. For plant teams, the practical takeaway is to treat compensation as a machine- and path-dependent control problem: collect representative data, validate predictions, and confirm the effect of any correction through machining inspection.
Access Official Technical PDF