Introduction

Five-axis CNC machine tools have extensive applications in aerospace, automotive, and medical devices, primarily used for machining components with complex surfaces like impeller blades, precision molds, and ship propellers1,2. Five-axis CNC machines, building upon the traditional three-axis models, incorporate two additional rotation axes and can complete multiple operations in a single clamping of the workpiece. These advantages significantly enhance the machining efficiency and precision of complex surface components3,4. However, the current five-axis CNC machining process still utilizes numerous continuous small linear path segments to approximate the contour surface curve of the workpiece, with these tiny segments forming the trajectory of the tool-workpiece CC point during five-axis CNC machining. This traditional approximation machining approach initially results in a contour approximation error. Even if the error is not considered, it will further produce the nonlinear error of the CC point trajectory caused by the introduction of the rotation axes in the five-axis CNC interpolation process5,6, which in turn reduces the machining accuracy and surface machining quality of the five-axis CNC machine tool. It can be seen that effectively reducing the nonlinear error of the CC point trajectory in five-axis CNC machining to improve the accuracy of five-axis CNC machining has gradually become a key technical problem to be solved in the field of five-axis CNC machining.

In response to the issues mentioned above, researchers domestically and internationally have extensively and deeply studied the nonlinear error problem in five-axis CNC machining and proposed various implementation methods.

Wang7 introduced the DICT (Double Interpolation algorithm based on the Cosine Theorem) method, which uses the STE (Second-order Taylor’s Expansion) method twice within one interpolation cycle, achieving minimal feed rate fluctuations within a stable consumption time. Liu8 proposed a method that uses a flat-bottom cutter to substitute the cutter envelope surface with a discrete bottom circle, iterating step errors in calculations. Chen9 modeled the nonlinear error of the tool center point, demonstrating that, within the same interpolation cycle, the tool center point lies on the same plane, thereby converting the three-dimensional problem into a two-dimensional one for research. Wang10 established a motion error model of five-axis machine tools using a method based on dual quaternions and analyzed its correlation with the PIGE (Position Independent Geometric Error) definition in ISO 230-7. Zhang11 proposed a new pre-compensation method for contour errors in five-axis CNC machine tools. This method involves fitting the machine tool’s position commands with quintic spline functions and using analytical techniques to predict the servo system’s tracking errors, thereby pre-compensating for contour errors before machining. Li12 proposed a three-parameter tool path interpolation method for five-axis machining with three-dimensional tool compensation, providing a suitable method for generating three-parameter tools in five-axis parameter interpolation. Wang13, based on HTM (Homogeneous Transformation Matrix) theory, developed an identification model for the incremental length of the double ball screw C-axis rod, mapping the relationship between the rod length increment and C-axis geometric error parameters. On this basis, five measurement trajectories were designed to identify the geometric error of the C-axis. Zhang14 introduced a BP neural network model to predict step error values. Sang15 proposed a simplified calculation model for the deviation between the ideal cutter trajectory and the actual cutter trajectory caused by the nonlinear motion of the rotary and translational axes and an improved interpolation algorithm considering geometric deviation and motion constraints, which improves the precision of machining to a certain extent. Zhang16 proposed an angle single sphere domain linear interpolation method to reduce nonlinear errors. Fu17 compensated for geometric errors by optimizing CNC codes with particle swarm optimization algorithms. Remus18 introduced a method for precisely determining errors, different from the traditional chordal deviation method, describing the exact interpolation position of the tool between two contact points. Ma19 proposed a feasible region solution for tool orientation with nonlinear error constraints, which can effectively avoid tool interference and improve machining accuracy, yet it may concurrently impact the efficiency of interpolation. Duong20 proposed an OGA (Offline Gain Adjustment) method to reduce contour errors in five-axis high-speed machining. This method optimizes servo drive control gains based on model predictive control, enhancing machining accuracy by considering machine dynamics and constraints. Chen21 proposed an innovative analytical path-reshaping model and solution algorithm for pre-compensating contour errors in multi-axis CNC machining. This approach integrates analytical prediction of contour error, optimal path reshaping, and a decoupling solution algorithm, significantly enhancing the accuracy of five-axis machining processes.

This paper distinguishes itself from existing literature by addressing not only the reduction of contour errors but also the positional errors of the CC point due to deviations of the actual CC point trajectory from the theoretical CC point trajectory. It adopts the concept of vector composition to synthesize these errors into a comprehensive nonlinear error, which is then compensated and corrected accordingly. This innovative approach allows for a more accurate and holistic error correction mechanism in multi-axis CNC machining processes. Existing research methods mainly focus on compensating and optimizing the nonlinear error of the tool center point trajectory caused by tool swinging. However, they do not consider the actual positional error of the CC point, which ultimately leads to low control of the CC point trajectory accuracy. The reason is the lack of CC point data throughout the five-axis CNC machining process, which results in insufficient data support for correcting the position of the CC point. This deficiency hinders effective compensation and correction of the CC point positional error during CNC machining trajectory interpolation. Furthermore, the absence of CC point data information also makes it challenging to carry out effective contour error compensation during the trajectory interpolation process, thereby complicating the reduction of surface contour errors on the workpiece.

The machining path of the CC point and the associated trajectory errors are investigated in this paper. A five-axis linear interpolation method is proposed to reduce CC point trajectory errors by adjusting the tool center point’s machining trajectory. In this method, the first step involves calculating the nonlinear error and contour error of the CC point trajectory. Subsequently, the positions where these errors are maximized are identified, leading to the determination of the error compensation direction unit vector. Finally, the corrected positions of the tool center points needed to minimize both types of errors are calculated. These corrected positions are used as the output locations for interpolation to control the machine tool’s position. The subsequent content of this paper primarily includes an introduction to conventional five-axis linear interpolation methods and their error analysis, as well as the presentation of the proposed five-axis linear interpolation method and its techniques for error compensation and correction.

Conventional five-axis linear interpolation methods

Five-axis linear interpolation is a motion control technique used in multi-axis mechanical systems. It is primarily utilized in systems requiring complex motion paths across multiple axes, such as CNC machines and robots. Five-axis linear interpolation achieves linear movement in multidimensional space by simultaneously controlling five axes (typically three linear axes and two rotation axes). Through the collaboration of mathematical algorithms and motion controllers, five-axis linear interpolation enables synchronized and precise motion control of multiple axes, allowing mechanical systems to move along specified paths. In five-axis linear interpolation, the motion trajectory is usually composed of parameters such as target positions and the speeds of each axis. By interpolating these parameters, controllers can generate corresponding motion commands, facilitating smooth movement of the mechanical system in multidimensional space.

Currently, the five-axis linear interpolation method is achieved by data sampling between the start and endpoint of the linear path segment to be interpolated. Assuming that the coordinates of the start and endpoint of the path segment in the machine tool coordinate system are \((X_{s} ,Y_{s} ,Z_{s} ,\theta_{As} ,\theta_{Cs} )\) and \((X_{e} ,Y_{e} ,Z_{e} ,\theta_{Ae} ,\theta_{Ce} )\), respectively, with a feed rate of f, and the CNC system interpolation cycle is T, then the total number of interpolation cycles required between the start and endpoint is:

$$ {\text{n}} = \left[ {{\text{D}}/({\text{fT}})} \right] $$
(1)

In the formula, the operator [*] represents the function of rounding * to the nearest integer, and D denotes the total length of the path segment to be interpolated.

$$ D = \sqrt {\left( {X_{e} - X_{s} } \right)^{2} + \left( {Y_{e} - Y_{s} } \right)^{2} + \left( {Z_{e} - Z_{s} } \right)^{2} } $$
(2)

Based on the principle of data sampling interpolation, it is understood that the coordinates of the interpolation points between the start and endpoint can be calculated as:

$$ \left\{ \begin{gathered} x_{i} = i[(X_{e} - X_{s} )/n] + X_{s} \hfill \\ y_{i} = i[(Y_{e} - Y_{s} )/n] + Y_{s} \hfill \\ z_{i} = i[(Z_{e} - Z_{s} )/n] + Z_{s} \hfill \\ \theta_{Ai} = i[(\theta_{Ae} - \theta_{As} )/n] + \theta_{As} \hfill \\ \theta_{Ci} = i[(\theta_{Ce} - \theta_{Cs} )/n] + \theta_{Cs} \hfill \\ \end{gathered} \right.(i = 1, \cdots ,n) $$
(3)

In Eq. (3), xi, yi, and zi represent the target motion position coordinates of each translational axis of the machine tool for the i-th interpolation cycle, while \({\uptheta }_{{{\text{Ai}}}}\) and \({\uptheta }_{{{\text{Ci}}}}\), respectively, represent the target motion position coordinates for the A and C rotation axes. Through the calculation of the interpolation above point position coordinates, the five interpolation motion position coordinates are transmitted to the corresponding servo drivers, ultimately achieving the synchronous joint movement of the five feed coordinate axes of the machine tool.

Conventional five-axis linear interpolation error analysis

While interpolating in the joint space as discussed in references22,23 maximizes the reduction of nonlinear errors, our decision was based on striking a balance between computational complexity and the precision requirements of the specific machining process we studied. Interpolation in task space, although advantageous in certain scenarios, could introduce its own challenges in terms of computational demands and the complexity of implementing real-time control systems for high-speed machining.

Tool center point trajectory error

Through the interpolation calculation process of the aforementioned conventional five-axis linear interpolation, it is known that after the combined movement of translational and rotation axes, the resulting motion trajectory at the tool will be as shown in Fig. 1. Os and Oe represent the tool center point position vectors in the workpiece coordinate system corresponding to the start point \(\left( {X_{s} ,Y_{s} ,Z_{s} ,\theta_{As} ,\theta_{Cs} } \right)\) and end point \(\left( {X_{e} ,Y_{e} ,Z_{e} ,\theta_{Ae} ,\theta_{Ce} } \right)\) of the path segment to be interpolated. Ds and De, respectively, represent the unit vectors in the direction of the tool axis at the start and endpoint. In an ideal scenario of five-axis CNC machining, the tool follows the red path depicted in Fig. 1 for cutting operations, which can produce a workpiece with a high-quality contour surface.

Figure 1
figure 1

Generation of nonlinear error of five-axis linear interpolation.

However, due to the interconnected relationship between translational and rotation axes during the actual cutting motion, the tool performs a rotation movement around its pivot point while simultaneously translating. This leads to the tool center point actually following the black path depicted in Fig. 1 for the cutting motion. Consequently, during the interpolation process, a positional deviation \(\sigma\) occurs between the actual interpolated cutter location \(\left( {{\text{O}}_{{\text{i}}} {\text{,D}}_{{\text{i}}} } \right)\) at the i-th point and the anticipated ideal interpolated cutter location. This deviation represents the nonlinear error in the tool center point trajectory during five-axis linear interpolation.

To calculate the tool center point trajectory nonlinear error generated during conventional five-axis linear interpolation, one can first determine the tool axis point position vectors corresponding to Fig. 1, based on the tool center point position vectors at the start and endpoints.

$$ \left\{ \begin{gathered} {\mathbf{T}}_{s} {\mathbf{ = O}}_{s} {\mathbf{ + }}{\text{L}}{\mathbf{D}}_{s} \hfill \\ {\mathbf{T}}_{e} {\mathbf{ = O}}_{e} {\mathbf{ + }}{\text{L}}{\mathbf{D}}_{e} \hfill \\ \end{gathered} \right. $$
(4)

In the above formula, L represents the total length from the tool center point to the tool rotation pivot point (swing tool length). Referring to Eq. (3), the position coordinates of the tool axis point corresponding to the i-th interpolated tool center point can be calculated as:

$$ {\mathbf{T}}_{i} {\mathbf{ = T}}_{s} {\mathbf{ + (T}}_{e} {\mathbf{ - T}}_{s} {\mathbf{)*}}{\text{i}}/n $$
(5)

Utilizing the two rotation motion coordinates in Eq. (3), the unit vector of the cutter axis at the i-th interpolated tool center point can be derived as follows:

$$ \left\{ \begin{gathered} I_{i} = \sin \theta_{Ai} \sin \theta_{Ci} \hfill \\ J_{i} = - \sin \theta_{Ai} \cos \theta_{Ci} \hfill \\ K_{i} = \cos \theta_{Ai} \hfill \\ \end{gathered} \right. $$
(6)

Combining Eq. (4), the expression for the position vector Oi of the i-th interpolated tool center point can be calculated as

$$ \left\{ \begin{gathered} X_{i} = (X_{s} + LI_{s} ) + i[(X_{e} + LI_{e} - X_{s} - LI_{s} )/n] - LI_{i} \hfill \\ Y_{i} = (Y_{s} + LJ_{s} ) + i[(Y_{e} + LJ_{e} - Y_{s} - LJ_{s} )/n] - LJ_{i} \hfill \\ Z_{i} = (Z_{s} + LK_{s} ) + i[(Z_{e} + LK_{e} - Z_{s} - LK_{s} )/n] - LK_{i} \hfill \\ \end{gathered} \right. $$
(7)

Therefore, the nonlinear error \(\sigma_{i}\) at the i-th interpolated tool center point is the distance from point Oi to the spatial line OsOe, which can be calculated as

$$ \sigma_{i} = \frac{{\left| {{\mathbf{a}} \times {\mathbf{b}}} \right|}}{{\left| {\mathbf{a}} \right|}} $$
(8)

In Eq. (8), a = Oe − Os, b = Oi − Os.

CC point trajectory error

Having discussed the errors associated with the tool center point, it is essential to now shift the focus to the trajectory errors of the CC point. Understanding the distinction between the tool center point and the CC point is crucial for a comprehensive grasp of machining accuracy. While the tool center point errors illuminate the spatial positioning of the tool itself, the CC point errors delve into the specifics of how the tool interacts with the material being machined. This aspect is vital for assessing the quality of the machined surface and the efficiency of material removal. The following discussion will explore the nuances of CC point trajectory errors, highlighting how these differ from and impact the errors associated with the tool center point. This examination is pivotal for optimizing machining processes and enhancing overall workpiece quality.

CC point trajectory chord error

In current five-axis machining CNC programming, the common practice involves extracting several discrete data points within the permissible accuracy range on the surface contour of the workpiece to serve as CC points. These points are then connected by line segments, forming the ideal trajectory of the CC points. When this continuous ideal CC point trajectory is used as an interpolation path segment to approximate a designed curve on the workpiece contour surface (contour design curve), each interpolation path segment (the j-th segment in Fig. 2) will generate a distance error (hj in Fig. 2) relative to the contour design curve. This error, inherent in CNC programming, is defined as the CC point trajectory chord error.

Figure 2
figure 2

Chord error in CC point trajectory.

Due to the complexity of accurately calculating the chord error in the CC point trajectory, an arc model is typically used to approximate the solution of the tool path. To calculate the chord error of the CC point trajectory, it is first necessary to determine the curvature radius of the contour design curve based on the approximate circular arc formed by three adjacent CC points. As shown in Fig. 3, \({\varvec{C}}_{s}^{j - 1}\) and \({\varvec{C}}_{e}^{j - 1}\) represent the starting and ending CC points of the j-1th interpolation path segment, while \({\varvec{C}}_{s}^{j}\) and \({\varvec{C}}_{e}^{j}\) denote the starting and ending CC points of the j-th interpolation path segment.

Figure 3
figure 3

The curvature circle and curvature radius at the CC point.

The curvature radius \({\uprho }^{j}\) at the starting CC point of the j-th interpolation path segment can be calculated as

$$ \rho^{j} = \frac{{|{\mathbf{C}}_{e}^{j} - {\mathbf{C}}_{s}^{j} | \cdot |{\mathbf{C}}_{s}^{{j - {1}}} - {\mathbf{C}}_{e}^{{j - {1}}} | \cdot |{\mathbf{C}}_{e}^{j} - {\mathbf{C}}_{s}^{{j - {1}}} |}}{{2|({\mathbf{C}}_{e}^{j} - {\mathbf{C}}_{s}^{j} ) \times ({\mathbf{C}}_{e}^{{j - {1}}} - {\mathbf{C}}_{s}^{{j - {1}}} )|}} $$
(9)

The chord error at this CC point can be obtained using the circular arc approximation method, as illustrated in Fig. 4.

$$ h^{j} = \rho^{j} - \sqrt {(\rho^{j} )^{2} - (\Delta L^{j} /2)^{2} } $$
(10)
Figure 4
figure 4

Estimating chord error using the approximate circular arc method.

The equation,\(\Delta {\text{L}}^{j}\) represents the distance between the given CC point and its adjacent CC point, which can be calculated using the following formula:

$$ \Delta L^{j} = {\mathbf{|C}}_{e}^{j} {\mathbf{ - C}}_{s}^{j} {\mathbf{|}} $$
(11)

CC point trajectory nonlinear error

Unlike chord error, which is caused by approximating the tool path with tiny linear segments instead of a smooth, continuous trajectory, nonlinear error arises from the tool’s oscillation or deviation from the predetermined path. During the conventional five-axis linear interpolation process, the combined movement of three translational axes and two rotation axes can cause the actual CC point’s motion trajectory to deviate from the ideal CC point trajectory, resulting in nonlinear errors in the CC point trajectory. This deviation arises because, following the linear interpolation movement through the CNC system, only the precision of the CC points at the start and endpoint can be guaranteed. It cannot ensure that the CC points, after tool rotation at intermediate interpolation points, still remain on the ideal CC point trajectory. Thus, the actual CC point trajectory between Cs and Ce (the black curve in Fig. 5) deviates from the ideal CC point trajectory (the red line segment CsCe in Fig. 5). The distance δ between the two trajectories represents the nonlinear error of the CC point trajectory.

Figure 5
figure 5

Nonlinear error in CC point trajectory.

Five-axis linear interpolation method incorporating CC points

The conventional five-axis linear interpolation methods exhibit errors in both tool center point and CC point trajectories. Current technological approaches, due to the lack of relevant data on the CC points, are unable to effectively reduce these trajectory errors. Therefore, it is necessary to propose a new method of five-axis linear interpolation, distinct from conventional approaches, that allows comprehensive compensation and correction of both types of trajectory errors during the interpolation process. To ensure that the compensation and correction of trajectory errors are data-supported, a new five-axis linear interpolation method that incorporates CC point data is introduced in this paper.

From the cutter location file, two adjacent cutter location data are extracted. Let’s assume that the cutter location data for the cutting start and end points are respectively \(\left( {{\varvec{X}}_{{\varvec{s}}} {,}{\varvec{Y}}_{{\varvec{s}}} {,}{\varvec{Z}}_{{\varvec{s}}} {,}{\varvec{I}}_{{\varvec{s}}} {,}{\varvec{J}}_{{\varvec{s}}} {,}{\varvec{K}}_{{\varvec{s}}} {,}\user2{X^{\prime}}_{{\varvec{s}}} {,}\user2{Y^{\prime}}_{{\varvec{s}}} {,}\user2{Z^{\prime}}_{{\text{s}}} } \right)\) and \(\left( {{\varvec{X}}_{e} {,}{\varvec{Y}}_{e} {,}{\varvec{Z}}_{e} {,}{\varvec{I}}_{e} {,}{\varvec{J}}_{e} {,}{\varvec{K}}_{e} {,}\user2{X^{\prime}}_{e} {,}\user2{Y^{\prime}}_{e} {,}\user2{Z^{\prime}}_{e} } \right)\), where (X, Y, Z) represents the coordinates of the tool center point, (I, J, K) the unit vector of the cutter axis, and (X′, Y′, Z′) the coordinates of the CC point.

Based on the structure of the five-axis CNC machine tool being used (taking an A-C type dual-rotary table CNC machine as an example), the angular displacements of the two rotation axes can always be calculated from the unit vector of the cutter axis.

$$ \left\{ \begin{gathered} \theta_{A} = arc\cos K \hfill \\ \theta_{C} = \left\{ \begin{gathered} \pi /2 - \arctan (J/I) \, (I > 0,J < 0) \hfill \\ \pi /2 + \arctan (J/I){ (}I > 0,J > 0) \hfill \\ 3\pi /2 - \arctan (J/I) \, (I < 0,J < 0) \hfill \\ 3\pi /2 + \arctan (J/I) \, (I < 0,J > 0) \hfill \\ \end{gathered} \right. \hfill \\ \end{gathered} \right. $$
(12)

Utilizing Eq. (3), the rotation motion coordinates for the i-th interpolation cycle can be calculated. By employing Eqs. (4), (5), (6), and (7), the position coordinates of the tool center point for the i-th interpolation cycle can be determined, as well as the calculation of the corresponding ideal CC point position coordinates for the i-th interpolation cycle.

$$ \left\{ \begin{gathered} X^{\prime}_{i} = X^{\prime}_{s} + i/n * (X^{\prime}_{e} - X^{\prime}_{s} ) \hfill \\ Y^{\prime}_{i} = Y^{\prime}_{s} + i/n * (Y^{\prime}_{e} - Y^{\prime}_{s} ) \hfill \\ Z^{\prime}_{i} = Z^{\prime}_{s} + i/n * (Z^{\prime}_{e} - Z^{\prime}_{s} ) \hfill \\ \end{gathered} \right. $$
(13)

Interpolation error compensation and correction based on CC point information

As can be understood from Sect. "Conventional five-axis linear interpolation methods", the calculation of interpolation errors in conventional five-axis linear interpolation methods includes CC point data information. However, due to the lack of detailed descriptions of the CC point position data in the interpolation data, it is not feasible to calculate the position error of the interpolated CC point and the contour error, let alone carry out error compensation and correction during the interpolation process. This section will detail the derivation of the calculation of errors in the interpolation of CC points separately. Based on the calculation results, compensation and correction for the errors obtained in the workpiece coordinate system will be conducted. This ensures that errors are assessed based on the final expected geometric shape of the workpiece, thereby directly demonstrating machining accuracy from the perspective of the finished product.

Calculation of interpolated CC point position error

Based on Eqs. (5), (6), and (7), the tool axis point vector Ti, cutter axis unit vector Di, and tool center point vector Oi for the i-th interpolation cycle can be calculated, respectively. Utilizing the coordinate vectors Oi, Ti, and Ci, the spatial relationship between the tool and the ideal CC point trajectory during the i-th interpolation cycle can be depicted, as shown in Fig. 6. This research concentrates on the application of ball end cutters in multi-axis CNC machining processes and their impact on machining accuracy. Due to their unique geometric shape, ball end cutters necessitate a different method for calculating the actual CC point compared to flat end cutters, which in turn affects the implementation of error compensation strategies.

Figure 6
figure 6

The spatial relationship between the tool and the ideal CC point trajectory.

As can be seen from Fig. 6, the position coordinates of the ball center point can be expressed as

$$ {\mathbf{t}}_{i} {\mathbf{ = O}}_{i} + r{\mathbf{D}}_{i} $$
(14)

where r is the tool radius. Magnifying a section of Fig. 6 results in the enlarged view of the entire path segment interpolation as shown in Fig. 7.

Figure 7
figure 7

Local magnification during full path segment interpolation.

A perpendicular line \({\mathbf{t}}_{i} {\mathbf{C^{\prime}}}_{ri}\) is drawn from the ball center point ti to the line segment CsCe, with the foot of perpendicular being the point \({\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}}\). The perpendicular line \({\mathbf{t}}_{{\mathbf{i}}} {\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}}\) intersects the cutter edge contour line at Cri. The intersection point Cri represents the nearest point to the ideal trajectory of the CC point CsCe, and it is considered the actual CC point. The unit vector B in the direction of nonlinear error compensation and correction can be calculated as

$$ {\mathbf{B}} = \frac{{{\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}} {\mathbf{ - t}}_{i} }}{{\left| {{\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}} {\mathbf{ - t}}_{i} } \right|}} = \frac{{\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}}}{{\left| {\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}} \right|}} $$
(15)

In the above equation, \({\mathbf{d}} = {\mathbf{t}}_{i} - {\mathbf{C}}_{{\mathbf{s}}}\), \({\mathbf{e}} = {\mathbf{C}}_{e} - {\mathbf{C}}_{s}\).

Assuming the foot of the perpendicular \({\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}} = (X^{\prime}_{c} ,Y^{\prime}_{c} ,Z^{\prime}_{c} )\), based on the equation of the linear path segment CsCe of the CC point

$$ \frac{{X^{\prime}_{c} - X^{\prime}_{s} }}{{X^{\prime}_{e} - X^{\prime}_{s} }} = \frac{{Y^{\prime}_{c} - Y^{\prime}_{s} }}{{Y^{\prime}_{e} - Y^{\prime}_{s} }} = \frac{{Z^{\prime}_{c} - Z^{\prime}_{s} }}{{Z^{\prime}_{e} - Z^{\prime}_{s} }} $$
(16)

The equation of the plane passing through a point \({\mathbf{t}}_{i} = (X^{\prime}_{o} ,Y^{\prime}_{o} ,Z^{\prime}_{o} )\) and perpendicular to the line CsCe can be derived as

$$ (X^{\prime}_{e} - X^{\prime}_{s} )(X^{\prime}_{c} - X^{\prime}_{o} ) + (Y^{\prime}_{e} - Y^{\prime}_{s} )(Y^{\prime}_{c} - Y^{\prime}_{o} ) + (Z^{\prime}_{e} - Z^{\prime}_{s} )(Z^{\prime}_{c} - Z^{\prime}_{o} ) = 0 $$
(17)

By combining Eqs. (16) and (17), the foot of perpendicular \({\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}}\) can be calculated.

Using Eq. (18), the actual CC point position vector for the i-th interpolation cycle can be calculated.

$$ {\mathbf{C}}_{ri} = {\mathbf{t}}_{i} + r{\mathbf{B}} $$
(18)

Therefore, the position error at the interpolated CC point can be calculated as

$$ {\updelta }_{{\text{i}}} = \left| {{\mathbf{C^{\prime}}}_{ri} - {\mathbf{t}}_{i} } \right| - {\text{r}} = \frac{{\left| {{\mathbf{e}} \times {\mathbf{d}}} \right|}}{{\left| {\mathbf{e}} \right|}} - {\text{r}} $$
(19)

Approximate calculation of interpolated CC point contour error

For the contour design curve represented by the red line in Fig. 8, an approximate calculation process for the contour error at the CC point within any interpolation cycle can be performed as follows:

Figure 8
figure 8

Approximate calculation of contour error.

The chord error h at the midpoint of the segment CsCe is approximated as the maximum error. A perpendicular line \({\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}} {\mathbf{C^{\prime\prime}}}_{{{\mathbf{ri}}}}\) is drawn from the point \({\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}}\) to the segment CsCe, intersecting the contour design curve at the point \({\mathbf{C^{\prime\prime}}}_{{{\mathbf{ri}}}}\). The unit vector E directed from \({\mathbf{C^{\prime\prime}}}_{{{\mathbf{ri}}}}\) towards \({\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}}\) is calculated as:

$$ {\mathbf{E}} = \frac{{{\mathbf{e}} \times \left[ {{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} } \right]}}{{\left| {{\mathbf{e}} \times \left[ {{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} } \right]} \right|}} $$
(20)

In Eq. (20), Ds and De, respectively, represent the unit vectors of the cutter axis at the start and endpoints.

The length of the segment \({\mathbf{C}}_{{\mathbf{s}}} {\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}}\) can be calculated as

$$ L_{i} = \sqrt {\left| {{\mathbf{C}}_{ri} - {\mathbf{C}}_{s} } \right|^{2} - \left| {{\mathbf{C}}_{ri} - {\mathbf{C^{\prime}}}_{ri} } \right|^{2} } $$
(21)

In Eq. (21),\(\left| {{\mathbf{C}}_{{{\mathbf{ri}}}} - {\mathbf{C^{\prime}}}_{{{\mathbf{ri}}}} } \right| = \delta_{i}\).

From the proportional relationship between the sides of similar triangles, it is known that

$$ \left\{ \begin{gathered} \frac{{L_{i} }}{{|{\mathbf{C}}_{e} - {\mathbf{C}}_{s} |/2}} = \frac{{\gamma_{i} }}{h} \, (L_{i} \le |{\mathbf{C}}_{e} - {\mathbf{C}}_{s} |/2) \hfill \\ \frac{{|{\mathbf{C}}_{e} - {\mathbf{C}}_{s} | - L_{i} }}{{|{\mathbf{C}}_{e} - {\mathbf{C}}_{s} |/2}} = \frac{{\gamma_{i} }}{h} \, (L_{i} > |{\mathbf{C}}_{e} - {\mathbf{C}}_{s} |/2) \hfill \\ \end{gathered} \right. $$
(22)

In Eq. (22), h represents the chord error of the interpolation path segment, which can be obtained by calculating using Eq. (10). Further, the contour error γi at the i-th interpolated CC point can be calculated as:

$$ \left\{ \begin{gathered} \gamma_{i} = \frac{{2L_{i} }}{{|{\mathbf{C}}_{e} - {\mathbf{C}}_{s} |}} \times h \, ({\text{L}}_{{\text{i}}} \le |{\mathbf{C}}_{e} - {\mathbf{C}}_{s} |/2) \hfill \\ \gamma_{i} = \frac{{2(|{\mathbf{C}}_{{\mathbf{e}}} - {\mathbf{C}}_{{\mathbf{s}}} | - L_{i} )}}{{|{\mathbf{C}}_{e} - {\mathbf{C}}_{s} |}} \times h \, ({\text{L}}_{{\text{i}}} > |{\mathbf{C}}_{e} - {\mathbf{C}}_{s} |/2) \hfill \\ \end{gathered} \right. $$
(23)

Comprehensive compensation and correction of interpolation errors

In Fig. 8, βi represents the combined nonlinear interpolation error formed by the contour error and the position error of the CC point at the i-th interpolated point, which can be calculated using the following formula.

$$ {\upbeta }_{{\text{i}}} = \left| {{\mathbf{C}}_{ri} {\mathbf{C^{\prime\prime}}}_{ri} } \right| = \left| {{\mathbf{C}}_{ri} {\mathbf{C^{\prime}}}_{ri} + {\mathbf{C^{\prime}}}_{ri} {\mathbf{C^{\prime\prime}}}_{ri} } \right| = \left| {{\updelta }_{{\text{i}}} {\mathbf{B}} - {\upgamma }_{{\text{i}}} {\mathbf{E}}} \right| $$
(24)

By substituting Eqs. (15), (19), (20), and (23) into Eq. (24) and rearranging, the following can be obtained.

$$ {\upbeta }_{{\text{i}}} = \left| {\left( {\frac{{|{\mathbf{e}} \times {\mathbf{d}}|}}{{|{\mathbf{e}}|}} - {\text{r}}} \right) \cdot \frac{{\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}}}{{|\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}|}} - \frac{k \times h}{{|{\mathbf{C}}_{{\mathbf{e}}} - {\mathbf{C}}_{{\mathbf{s}}} |}} \cdot \frac{{{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]}}{{|{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]|}}} \right| $$
(25)

In Eq. (25)

$$ k = \left\{ \begin{gathered} 2L_{i} \, ({\text{L}}_{{\text{i}}} \le |{\mathbf{C}}_{e} - {\mathbf{C}}_{s} |/2) \hfill \\ 2(|{\mathbf{C}}_{e} - {\mathbf{C}}_{s} | - L_{i} ) \, ({\text{L}}_{{\text{i}}} > |{\mathbf{C}}_{e} - {\mathbf{C}}_{s} |/2) \hfill \\ \end{gathered} \right. $$

The unit vector F for the direction of compensation and correction of the comprehensive interpolation error is:

$$ {\mathbf{F}} = \frac{{{\mathbf{B}} - {\mathbf{E}}}}{{\left| {{\mathbf{B}} - {\mathbf{E}}} \right|}} = \frac{{\frac{{\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}}}{{|\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}|}} - \frac{{{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]}}{{|{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]|}}}}{{\left| {\frac{{\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}}}{{|\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}|}} - \frac{{{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]}}{{|{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]|}}} \right|}} $$
(26)

Based on Eqs. (25) and (26), the coordinates of the tool center point of the new interpolated point after compensation can be calculated.

$$ {\mathbf{O^{\prime}}}_{i} = {\mathbf{O}}_{i} + \beta_{i} {\mathbf{F}} $$
(27)

By substituting Eqs. (24) and (26) into Eq. (27), the following can be obtained:

$$ \user2{O^{\prime}}_{i} = {\mathbf{O}}_{i} + \left| {(\frac{{|{\mathbf{e}} \times {\mathbf{d}}|}}{{|{\mathbf{e}}|}} - r) \cdot \frac{{\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}}}{{|\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}|}} - \frac{k \times h}{{|{\mathbf{C}}_{{\mathbf{e}}} - {\mathbf{C}}_{{\mathbf{s}}} |}} \cdot \frac{{{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]}}{{|{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]|}}} \right| \cdot \frac{{\frac{{\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}}}{{|\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}|}} - \frac{{{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]}}{{|{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]|}}}}{{\left| {\frac{{\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}}}{{|\left[ {{\mathbf{d}} \times {\mathbf{e}}} \right] \times {\mathbf{e}}|}} - \frac{{{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]}}{{|{\mathbf{e}} \times [{\mathbf{D}}_{s} \times {\mathbf{D}}_{e} ]|}}} \right|}} $$
(28)

The calculation process for the comprehensive compensation and correction of interpolation nonlinear errors is now summarized and illustrated in Fig. 9.

Figure 9
figure 9

Comprehensive compensation and correction process for interpolation error.

Using C++ to read the cutter location file generated by UG (Unigraphics), the nine coordinates of discrete data are extracted. The curvature radius at each point is calculated using Eq. (9), and then the chord error at each point is determined using the approximate circular arc method. By selecting adjacent cutter location data, the actual coordinates of the tool center point are calculated, followed by determining the actual CC point coordinates. Using Eqs. (15) and (19), the magnitude of the positional error at the CC point and the unit vector for error correction are calculated sequentially. Then, the compensation direction of the contour error is determined using the start/end tool axis vectors and the ideal CC point trajectory vectors. The magnitude of the contour error approximating the contour curve is calculated through chord error, and unit vectors for correcting both types of errors are assigned their respective magnitudes for vectors synthesis. Using Eqs. (24) and (26) are used in sequence to calculate the magnitude of the combined nonlinear error at the CC point and the unit vector for the error correction position. A comprehensive correction is then applied to the tool center point to obtain new tool center point coordinates. These new coordinates, along with the rotation axes information, are transmitted to the controllers of the five feed axes. The process continues in a loop until the endpoint is reached, checking at each iteration whether the endpoint has been achieved.

Computational example

Utilizing UG/NX, a spatial freeform surface as shown in Fig. 10 is modeled. In the CAM module, the surface is processed with a discrete tolerance of 3 μm to obtain the required CC point trajectory for machining the surface, as indicated by the red curve in Fig. 10. One of the CC point trajectories (as shown by the blue dot sequence of discrete CC points in Fig. 10) is selected for interpolation calculations and comprehensive nonlinear error compensation and correction. This is done to verify the effectiveness of the methods presented in this paper in reducing contour errors and nonlinear errors in the CC point trajectory. The extracted CC point trajectory consists of 85 points. The corresponding machining cutter location data in the workpiece coordinate system is listed in Table 1. After post-processing calculations, the five-coordinate G01 interpolation instruction data in the machine tool coordinate system can be obtained (Table 2). The complete versions of Tables 1 and 2 are included in the Supplementary material as Supplementary Table S1 and Supplementary Table S2, respectively.

Figure 10
figure 10

Spatial freeform surface.

Table 1 Machining cutter location data.
Table 2 Five-axis G01 interpolation command data.

Using Eq. (11), the distance between adjacent CC points on the trajectory shown in Fig. 10 can be calculated. Then, based on Eqs. (9) and (10), the approximate curvature radius and chord error at each CC point on this trajectory can be determined. Based on these calculations, the distance, curvature radius, and chord error data curves at each CC point are plotted respectively as shown in Figs. 11 and 12. It can be observed that to ensure the chord error in approximating the contour of freeform surfaces remains within the tolerance range, at areas with smaller curvature radii, the distance between adjacent CC points is also smaller. A dense CC point approximation approach is adopted to reduce chord error. Conversely, in areas with larger curvature radii, the distance between CC points is increased, utilizing a sparse CC point approximation to improve machining efficiency.

Figure 11
figure 11

Spacing distance between the adjacent CC points.

Figure 12
figure 12

Chord error and curvature radius at the all CC points.

Using Eq. (3), the conventional five-axis linear interpolation for the commands in Table 2 is calculated (assuming an interpolation cycle T = 2 ms and feed rate f = 250 mm/min). Then, based on Eqs. (8) and (19), the nonlinear error in the tool center point position and the positional error at the CC point for each interpolation cycle are calculated. The trajectory error curve is shown in Fig. 13, where the blue curve represents the error of the tool center point and the red curve represents the error of the CC point. It is evident that during the processing of the data in interpolation Table 2, the tool’s swing results in significant positional deviation of the tool center point, with a maximum value reaching 21 μm. With the increase in trajectory error of the tool center point, the positional error of the CC point also grows incrementally. It can be observed that the magnitude of their errors is not significantly different, due to the small distances and angular differences between the start and end points of each interpolation path segment in Table 2. During linear interpolation between these points, the movement between adjacent interpolated CC points can be approximated as micro translational movement, leading to a similarity in the magnitude of errors at the interpolated CC point and the tool center point. However, a detailed observation around interpolated CC point number 120 in Fig. 13 shows that there are still slight differences in their error magnitudes, as depicted in Fig. 14.

Figure 13
figure 13

Trajectory error curves of the tool center points and the CC points.

Figure 14
figure 14

Local amplification of the two trajectory error curves.

To illustrate scenarios where the positional error of the CC point significantly differs from that of the tool center point, data from Table 3 is presented in this paper. The data in Table 3, obtained through post-processing calculations, represents the five-coordinate G01 interpolation instruction data in the machine tool coordinate system. The distance and angular difference between the start and endpoints of the interpolation path segments are 2.162 mm and 5.0008°/8.877°, respectively, which are significantly larger than the data listed in Table 2. Figure 15 shows the positional error data curve of the CC point when the tool center point moves along the ideal tool center point trajectory. Figure 15 indicates that the positional error of the CC point relative to the tool center point can reach a maximum of 15.3 μm. This demonstrates that when the movement between any adjacent interpolated CC points cannot be approximated as microscopic translation, the positional error of the CC point relative to the tool center point is significant and cannot be ignored. Therefore, it is necessary to consider both tool center point trajectory error and CC point trajectory error for compensation and correction when performing nonlinear error compensation.

Table 3 Command data for large-spacing path segments.
Figure 15
figure 15

Position error curve of the interpolated CC points between the adjacent CC points with large spacing distance.

Further, using Eq. (23), the contour error at all interpolated CC points during the conventional five-axis linear interpolation process can be calculated. The data curve of the error is plotted as shown in Fig. 16. It is evident that the contour error at each interpolated CC point fluctuates within the range of the chord error, indicating that the conventional five-axis linear interpolation method cannot adequately address the chord error issue when the CC point trajectory approximates the contour design curve. For subsequent comprehensive compensation and correction of the nonlinear error, Eq. (25) can be used to combine the CC point position error from Fig. 13 and the CC point contour error from Fig. 16. This allows for the calculation of the comprehensive nonlinear error that needs to be compensated and corrected at each interpolated CC point, with its error curve depicted in Fig. 17. The maximum comprehensive nonlinear error of the interpolated CC points can reach 19um. Since the positional error at the interpolated CC points is significantly larger than the contour error, the difference in magnitude between the comprehensive nonlinear error and the positional error is not pronounced after the vector synthesis calculation, with only minor differences.

Figure 16
figure 16

Contour error curve of the interpolated CC points without compensating and correcting.

Figure 17
figure 17

Comprehensive nonlinear error curve of the interpolated CC points without compensating and correcting.

Following the method of comprehensive compensation and correction of nonlinear errors described in Sect. “Five-axis linear interpolation method incorporating CC points”, Eq. (28) is used to adjust the position of the tool center point while simultaneously readjusting the CC point position. Then, using Eqs. (19) and (23), the curves for the CC point position error and contour error after compensation and correction are plotted (Figs. 18 and 19). A comparison with Figs. 13 and 16 shows that after adjusting the CC point position, the maximum nonlinear error in the CC point trajectory can be reduced from 21 to 0.88 μm, a decrease of 96%; the maximum contour error can also be reduced from 2.8 to 0.69 μm, a reduction of 76%, achieving better machining results than the preset tolerance of 3 μm.

Figure 18
figure 18

Position error curve of the interpolated CC points using compensation and correction method.

Figure 19
figure 19

Contour error curve of the interpolated CC points using compensation and correction method.

Using Eq. (25), the curve for the comprehensive nonlinear error after compensation and correction is plotted (Fig. 20). The maximum comprehensive nonlinear error of the interpolated CC points can reach 1.5 μm. Comparing with Fig. 17, it is evident that after the adjustment of the CC point position, the comprehensive error is reduced from 19 to 1.5 μm, with the reduction also reaching 93%. After zooming in on the trajectory between CC points 32 and 33, the resulting image, shown as Fig. 10, displays the CC point trajectories: the blue line represents the trajectory before compensation, the black line represents the trajectory after compensation, and the red line represents the ideal CC point trajectory. Using the method from reference24, we obtained the compensated comprehensive nonlinear error as shown in Fig. 21. This approach only accounted for contour errors, neglecting the positional errors caused by tool deflection. Consequently, the maximum comprehensive nonlinear error after compensation was 3.94 μm, which exceeds the machining tolerance of 3 μm. In contrast, the method proposed in this paper successfully meets the tolerance requirement, with the maximum compensated comprehensive nonlinear error also within limits. A comparison indicates that the method proposed in this paper has good machining accuracy.

Figure 20
figure 20

Comprehensive nonlinear error curve after compensation and correction using the method proposed in this paper.

Figure 21
figure 21

Comprehensive nonlinear error curve after compensation and correction using the method from reference24.

The above only involves linear interpolation machining for a specific curve. Next, the entire surface shown in Fig. 10 will be processed through linear interpolation. Based on the coordinates of the interpolation points and the error values, a four-dimensional surface will be generated. This surface will be displayed using a mesh grid, and the grid will be colored according to the error values of each point to more intuitively present the effects before and after compensation. Figure 22a shows the comprehensive nonlinear error of CC points before compensation, with a maximum error of 60.5 μm; Fig. 22b shows the comprehensive nonlinear error of the interpolated CC points after compensation and correction using the method described in this paper, with a maximum error of 2.82 μm; Fig. 22c shows the comprehensive nonlinear error of the CC points after correction using the method proposed in reference 24, with a maximum error of 6.02 μm. The experimental results demonstrate that the compensation and correction of CC points proposed in this paper can significantly reduce errors.

Figure 22
figure 22

Four-dimensional surface plot before and after compensation.

Experiment results

To verify the total amount of nonlinear error and compensation methods in this paper, the experiment utilized the spatial freeform surface shown in Fig. 10 for actual machining. The processing was conducted on T-6045 and V-1160 machines using the FANUC-0i MD system, comprising three stages: rough machining, semi-finishing, and finishing. A 65 mm*15 mm*15 mm aluminum 6061 workpiece was used. Initial rough machining and semi-finishing were performed on the T-6045 machine using a 10 mm diameter flat end mill for roughing, followed by a 4 mm diameter flat end mill and ball end mill for semi-finishing to achieve the basic shape. Finally, finishing was carried out on the V-1160 machine, using the method proposed in this paper as well as the traditional method without compensation for comparison. A 4 mm diameter ball end mill was used with an interpolation cycle T = 2 ms and a feed rate f = 250 mm/min. The machining process are shown in Fig. 23.

Figure 23
figure 23

The machining process of spatial freeform surface (a) T-6045 and V-1160 machines (b) workpiece and base (c) rough machining and semi-finishing (d) finish machining (e) after machining.

As shown in Fig. 24, the surface roughness of the machined surface was measured using the SRA series surface roughness tester. The machining result without compensation, as shown in Table 4, had an average surface roughness of 1.133 μm and a maximum surface roughness of 6.667 μm. After machining with the nonlinear error comprehensive compensation method proposed in this paper, the surface roughness obtained is shown in Table 4. The average surface roughness was reduced to 0.220 μm, and the maximum surface roughness was decreased to 1.240 μm. In comparison, the compensation and correction methods adopted in this paper significantly improved the machining effect and quality of the parts. Figure 25 shows a comparative diagram of the machined workpieces before and after compensation and correction. The close-up view is a magnified image using a stereomicroscope, which also demonstrates that the method proposed in this paper significantly improved the machining precision of the parts.

Figure 24
figure 24

Measuring the roughness of machined parts with the SRA series surface roughness tester.

Table 4 Comparison of the roughness of machined parts before and after compensation and correction.
Figure 25
figure 25

Comparison of machined workpieces before and after compensation and correction.

Conclusions

  1. (1)

    The mechanism of chord error generation at interpolated CC points is analyzed in this paper, and a method for calculating the chord error of interpolation points by using an approximate circular arc approach is proposed; It also analyzes the mechanisms of trajectory errors at interpolated tool center points and positional errors at CC points, proposing a method to determine the actual CC points based on the current actual interpolated tool center points.

  2. (2)

    The introduction of contour error combines the CC point contour error with the positional error of the CC point during interpolation into a comprehensive nonlinear error. A method for calculating the magnitude and compensation direction of this error has been proposed and implemented, resulting in new coordinates for the interpolated tool center point.

  3. (3)

    Using Matlab, the curves of comprehensive nonlinear error data before and after correction were plotted. After compensation and correction, the contour error was reduced by 76%, and the nonlinear error of the CC point trajectory was reduced to below 0.88 μm. The comprehensive nonlinear error of the CC point trajectory decreased from 19 to 1.5 μm, a reduction of 93%. And the entire surface underwent simulation calculations, with the nonlinear error after compensation also meeting the machining tolerance of 3 μm. Finally, using this comprehensive compensation method for nonlinear errors in actual machining, the average surface roughness was reduced from 1.133 to 0.220 μm, and the maximum surface roughness was reduced from 6.667 to 1.240 μm. This method significantly reduces the interpolation error of the CC point position and the comprehensive nonlinear error, and it has important practical value in improving the accuracy of CC point trajectory control in five-axis CNC machining.

  4. (4)

    However, the main focus of this study is on the impact of CC point trajectory error on the precision of five-axis CNC machining. Additionally, the influence of other error sources on the precision of five-axis CNC machining will be analyzed and discussed in future research.