Real-time smooth trajectory generation for 3-axis blending tool-paths based on FIR filtering

Three-axis machining tool-paths are generated using computer-aided manufacturing (CAM) systems and programmed by a series of G01 codes mixed with long and short segments. The computer numerical control (CNC) system needs to analyze path information according to the G-codes through path smoothing, speed planning, and interpolation process; generate smooth trajectory; and ensure the high-order continuity of velocity. This study proposes a real-time smooth trajectory generation algorithm with a simple structure and low calculation for 3-axis blending machining tool-paths. Finite impulse response filters are used to generate a smooth trajectory with bounded acceleration in real-time. Due to the delayed response of the filter, it will inevitably bring contour error. The feed rate is adjusted by considering the influence of the adjacent segments on the contour error in the case of long segments. This idea is then extended to continuous micro-segments. Finally, a direct one-step smooth trajectory generation algorithm for the blending tool-paths is realized through pre-discretization with certain rules. The algorithm can effectively control the contour error but also is suitable for blending tool-paths. Consequently, the effectiveness of the proposed algorithms is validated in simulations and also experimented on a 5-axis machine tool.


Introduction
In typical 3-axis machining, to ensure the geometric dimension accuracy of the machined workpiece, computeraided manufacturing (CAM) systems generally use linear lines instead of curves to discretize the tool-paths into a large number of G01 line segments [1]. To realize high-speed continuous motion, computer numerical control (CNC) systems usually adopt the corner smoothing algorithm based on pre-planning [2]. However, given the existence of multiple buffers, the real-time performance of the system is not strong, and spline interpolation has computational efficiency and accuracy issues. Thus, this study presents a novel real-time smooth trajectory generation technology for accurate interpolation of 3-axis machining.
The G-code generated by CAM is a linear tool-path of point-to-point (P2P) and only has position continuity; thus, it must be completely stopped at the segment transfer, resulting in an extended processing time [3,4]. To ensure the smoothness of the machining path and the high-order continuity of speed, CNC usually adopts "local blending/ smoothing" or "global blending/smoothing" algorithms to improve the geometric continuity of the path and then carries out speed planning and interpolation. In related research, by inserting a line segment, arc, B-spline, and Bezier curve at the adjacent tool-path [5,6], the smooth transition at the corner is realized and the speed continuity of the path corner is improved. The local smoothing has a good local property and can effectively control the contour error at the corner [6]. Compared with the local smoothing method, the global smoothing method adopts the fitting or interpolation to fit a large number of continuous short linear segments into one or more smooth spline curves under the contour error constraint; commonly used splines include Bezier, B-spline, and NURBS curves [7][8][9]. However, most algorithms adopt iterative calculation or even offline mode, 1 3 which may affect the real-time performance of the system [2]. The tool-path is often complex and mixed with long and short segments in actual machining. Therefore, local smoothing and global smoothing algorithms must be used in segments according to the track type, and some tracks at the junction of the two fairing algorithms need to be repeatedly faired. The algorithm structure is complex, and the contour accuracy is not easy to control.
After the trajectory is smoothed, the CNC system needs to perform speed planning based on the kinematic constraints of the machine tool, the geometric constraints of the machining path, and the contour errors. The acceleration of S-shaped velocity is continuous, the vibration of the machine tool is reduced, and the surface quality of the workpiece is improved; thus, it is widely used in practical applications [10][11][12]. Furthermore, algorithms with continuous acceleration and even continuous jerk have also been proposed [13][14][15]. As the order of velocity continuity increases, the amount of calculation also increases geometrically.
Finite impulse response (FIR) technology has the characteristics of good smoothness, simple calculation, and no spline fitting. Song [16] proved that the velocity curve after FIR filtering is equivalent to the polynomial velocity curve. Thus, some scholars proposed to use the FIR filters to realize the trajectory control process of the CNC system in one step. The algorithm has a simple structure and is conducive to real-time calculation. For the long segment tool-paths, Sencer [17] and Liu [18] proposed a path-smoothing algorithm based on FIR filtering for adjacent corners. The dwell time is deduced according to the given contour error to adjust the overlapping speed area of the adjacent segments and realize the precise contouring control while meeting the requirements of vibration avoidance, high precision, and short machining time. Bearee [19] realized the maximum utilization of acceleration and shortened the processing time by changing the time constant of the filter. Furthermore, in order to realize jerk continuity, Li [20] further deduced the model of constant velocity sequence passing through the third filter and obtained the third-order continuous velocity curve, satisfying the contour error constraint. Another scheme of contour error control is adjusting the adjacent speed within the delay time, also called the velocity-controlled blending algorithm [21], which can further reduce velocity fluctuation at the corner.
The above studies only considered two adjacent trajectories at the corner but did not give continuous microsegment processing methods. Hayasaka [22] proposed a block-splitting method to adjust the speed within the delay time and realized the machining of continuous micro-segments based on FIR filtering. Sencer [23,24] proposed a highly computationally efficient global smoothing interpolation method and determined the final velocity proportion coefficient by solving the influence of each corner on multi-stage speed. In the algorithm, trapezoidal shaped velocity (acceleration limited) is used to solve the contour error, but S-shaped velocity (jerk limited) is commonly used in processing.
This study proposes a universal algorithm of acceleration continuity based on FIR filtering for complex path machining of CNC systems. Using second-order FIR filters, the interpolation smoothing trajectory with continuous acceleration can be generated by adjusting the velocity proportion coefficient. Firstly, a non-stop velocity proportion compression algorithm for continuous long linear segments is proposed, and the adjustment coefficients of the speed of the front and rear segments are calculated according to the contour errors at the corners. On this basis, a blending velocity proportion compression algorithm for continuous micro-segments is proposed. Considering the influence of multiple trajectories before and after a single corner, the final velocity proportion compression coefficient is calculated, so that the generated trajectory satisfies the contour of each corner. Finally, a pre-discrete velocity proportion compression algorithm for blending tool-paths is proposed, which is suitable for complex trajectories in practical machining. Thus, the paper is organized as follows. Section 2 introduces the generation of acceleration continuous jerk-bounded tool-paths based on FIR filters. Section 3 presents the continuous trajectory generation that satisfies the contour error constraint. Section 4 verifies the effectiveness of the algorithm through simulation and actual machining experiments.

FIR filter principle
The commonly used velocity acceleration curve of the numerical control system is S-shaped velocity; that is, the acceleration is continuous, and the jerk is bounded, which can be easily obtained by passing through two cascaded FIR filters through the equivalent speed sequence. The transfer function (TF) of the first-order FIR filter under Laplace(s) domain is as follows: where T i is the time duration for the i th FIR filter. The transfer function consists of an integrator 1 s and a pure delay The impulse response is obtained by inverse Laplace transform: is a rectangular pulse of unit area, as shown in Fig. 1, revealing that the final position of the trajectory will not change after passing through the FIR filter, which is the "position invariance" of the FIR filter [18].

Generation of S-shaped velocity curve
In 3-axis machining, for each line of G-code, the start position coordinate P s X s , Y s , Z s , end position coordinate P E X E , Y E , Z E and feed rate F can be obtained by compiling and analyzing. The speed planning of the rectangular-frame is obtained from the segment length L and the feed rate F: where T v represents the duration of the rectangular frame speed pulse. When the velocity curve of the rectangularframe is convolved with an FIR filter with a time constant of T 1 and then convoluted with an FIR filter with a time constant of T 2 , the S-shaped velocity curve commonly used in CNC system can be obtained [16]. To get a seven-segmented S-shaped velocity curve, that is, the acceleration curve of the system is a trapezoid and its jerk is bounded; it must also be ensured that T v > T 1 + T 2 and T 2 < T 1 . At this time, the maximum acceleration and jerk of the system are calculated as: After the filtering effect of these two cascaded FIR filters, the obtained speed is as follows: The acceleration and position can be obtained by differentiating and integrating the velocity. The whole process is shown in Fig. 2.
The total processing time of the system is calculated as: where T d is the delay time brought by the introduction of the filter. If the system introduces an nth order FIR filter, theoretically, the speed curve can achieve nth order continuity [17,25], and the delay time T d is calculated as:

Continuous trajectory generation under contour error constraints
It has been introduced that a single-segment S-shaped velocity curve with continuous acceleration can be generated based on FIR filtering. Thus, this chapter will further introduce the trajectory generation method for continuous tool-paths following contour control. Section 3.1 first solves the velocity proportion coefficients of the two front and rear trajectories under the constraint of contour error at a single corner for long segments. The velocity proportion coefficient is used to adjust the speed of each track segment on the premise that the track segment length remains unchanged, so as to meet the contour accuracy at the track corner. Section 3.2 extends this idea to the case of continuous micro-segments, solves the influence of multiple trajectories at a single corner under the constraint of contour error one by one, and obtains the velocity proportion coefficient of each micro-segment by synthesizing the results at multiple corners. Section 3.3 adopts pre-discretization to scatter the complex trajectory into continuous micro-segments to satisfy the application of the algorithm in Sect. 3.2 and realize a universal continuous trajectory generation method based on FIR filtering.

Non-stop velocity proportion compression for long segments
As described in Section 2, the premise of obtaining the S-shaped curve of the maximum feed speed F is to ensure Then, for continuous trajectory, by carrying out rectangular-frame speed planning (RSP), a series of rectangular-frame speeds can be obtained. If the dwell time between adjacent rectangular-frame is greater than or equal to the delay time, a full-stop and an exact P2P motion can be obtained; that is, the system will continue to run the next track after each track has completely stopped, as shown in Fig. 3. At this time, the system shows no contour error, but this movement will seriously affect the machining efficiency of the system and greatly increase the machining time. Therefore, Ref. [21] proposed two methods: non-stop dwell-time control path blending (NS-DCB) and non-stop velocity-controlled blending (NS-VCB). By adjusting the dwell time between adjacent rectangular-frame (corresponding to NS-DCB) or the mixing velocity between adjacent rectangular-frame (corresponding to NS-VCB), the system can shorten the processing time to satisfy the contour error constraint. However, as pointed out in the literature, both methods are only suitable for long segments, which require To suggest a general trajectory control algorithm based on FIR filtering for long segments, this paper proposes a non-stop velocity proportion compression algorithm (NS-VPC), which makes the system dwell time T dwell = 0 and the mixing time T mix = T d − T dwell = T d at the corner. At this time, the system starts to perform the trajectory interpolation of the second segment when the first segment of the trajectory has not reached the end position, resulting in mixed corner and contour errors, as shown in Fig. 4.
Line N1 corresponds to the starting point and it is assumed that the feed rate of the two tracks is the same, that is, The maximum contour error of the system occurs at the angle bisector of ∠P 1 P 2 P 3 [21], the corresponding time is set to T b , and the maximum contour error is set to . Where �� ⃗ l 1 corresponds to the vector of the post-influence area s 1 at the maximum contour error of the first track, and �� ⃗ l 2 corresponds to the vector of the pre-influence area s 2 at the maximum contour error of the second track.
From Eq. (5), Thus, by plugging Eqs. (9)-(12) into Eq. (8), is calculated as: Assuming that the allowable error given by the numerical control system is ε allow , the velocity proportion coefficient k v should be calculated as: To satisfy the contour error of the system, the velocity of the N 1 N 2 trajectory segment and the N 2 N 3 trajectory segment should be adjusted is calculated as:  To ensure that the length of the track segment remains unchanged, the time of these two segments should also be adjusted accordingly.
It should be noted that the above derivation is based on F 1 = F 2 . If F 1 ≠ F 2 , the maximum contour error at the corner is not at the angle bisector of ∠P 1 P 2 P 3 , but the actual contour error is greater than the calculated value of Eq. (12), and the above algorithm can still meet the contour error constraint of the system [21].

Multi-stage mixing velocity proportion compression for micro-segments
In CNC machining, CAM usually breaks up the spline into a large number of continuous tiny linear segments. Then, because of T v < T 2 < T 1 , the NS-VPC algorithm is no longer applicable. Therefore, based on the NS-VPC algorithm in Section 3.1, this section proposes a multi-stage mixing velocity proportion compression (MM-VPC) algorithm for continuous micro-segments, which can effectively ensure that the system meets the contours. Under the premise of error constraints, a smooth transition of the angular velocity is achieved. Given T v < T 2 < T 1 , the maximum speed and acceleration that the system can reach at this time is calculated as: The jerk is the same as that in the case of the long segment, which is still j max = F T 1 T 2 . Then, after the rectangularframe speed passes through the second-order FIR filter, the S-shaped speed curve is shown in Fig. 5.
Its speed formula is calculated as: For a continuous micro-segment trajectory, the maximum value of the contour error at the kth contour point is generated in T b,k , and the maximum contour error k is affected by the displacement vector of the rear area of the front m rectangularframes and the front area displacement of the rear n rectangular-frames, as shown in Fig. 6. Where, where T k represents the starting time of the kth rectangularframe. Then, the key of the algorithm is to solve the displacement vectors ����⃗ l k+i and �������� ⃗ l k−j−1 .
where L k−j−1 represents the length corresponding to the ( k − j − 1)th rectangular-frame, t k+i represents the influence time of each rectangular-frame in the previous m rectangular-frames on the contour error point and ������⃗ O k+i is its direction vector. t k−j−1 represents the influence time of each of the By substituting Eqs. (19) and (20) into Eq. (18), the contour error k of the system at the k th contour point can be obtained, and the velocity proportion coefficient k v,k is calculated as: Therefore, the velocity scale coefficient of the m + n rectangular-frames at the kth contour point is k v,k . Given that each rectangular-frame may affect more than one corner, it may have multiple speed scale factors. The minimum value is taken as the final velocity proportion coefficient among the multiple velocity proportion coefficients of each rectangular-frame to ensure that the contour error of each contour point meets the constraint.
Its speed and duration are also adjusted accordingly as: (20)

Pre-discrete velocity proportion compression algorithm for blending tool-paths
In actual processing, most G-codes are mixed paths with long segments and micro-segments. In this case, neither the NS-VPC nor MM-VPC algorithms are applicable anymore. Thus, this section proposes a pre-discrete velocity proportion compression algorithm (PD-VPC) for mixed paths, which can meet the needs of various machining paths and improve machining efficiency by effectively ensuring contour error constraints.
The key to the PD-VPC algorithm is to pre-discretize in advance, break the long G-codes into micro-segments based on certain rules, and then put the broken G-code into the MM-VPC algorithm to realize speed adjustment and interpolation. The algorithm flow is shown in Fig. 7.
The premise of the MM-VPC algorithm is to satisfy T v < T 2 < T 1 , the critical condition T v = T 2 , and the system acceleration reaching the maximum value at this time. Thus, the minimum time for segmentation is T div,min = T 2 . Firstly, the entire G-code is read in advance, the speed planning of the rectangular-frame is carried out, the line segment T v ≥ T div,min is marked as a long segment, and linear interpolation is performed on the long segment and discretize into micro-segments. To break up the long segment into a certain number of micro-segments, a discrete coefficient k s is introduced, and the duration of each micro-segment is denoted as T v,s , It should be noted that the value of k s will not affect the actual running time and velocity acceleration trend of G-code trajectory but only break the long segment into micro-segments for application to the MM-VPC algorithm. However, the value of k s will directly affect the number of broken segments, thus affecting the operational efficiency of the algorithm.
Assuming that the running time of a long segment of G-code is denoted as T i , the coordinates of the starting point are P i−1 X i−1 , Y i−1 , Z i−1 , and the coordinates of the end point are P i X i , Y i , Z i . Then, the number of short segments that will be broken up into the following: The ceil function means rounding up. Through linear interpolation, the newly added intermediate position G-code point P n = X n , Y n , Z n can be obtained. The coordinates of each axis are solved as follows where n = 1, 2, … , N − 1.

Experimental results
This study uses an actual 5-axis machine tool for practical verification in combination with the interpolation point data generated by the simulation experiment. The experimental machine tool is shown in Fig. 8. The machine tool adopts five-axis full closed-loop control and supports locking the rotating axes. The maximum feed speed of the (26) linear axis is 48,000 [mm/min], and the control resolution is 0.001 [mm]. In this section, the rotating axes are locked in the whole experiment, and the closed-loop sampling period of the servo control system is set to 1 [kHz].
The Mercedes-Benz mold testing sample is the standard test sample of 3-axis milling in the industry [2]. It is recognized by many countries in Europe and the USA and is widely used to evaluate NC machine tools' machining efficiency and accuracy. The specimen's surface contains various complex tool-path features such as lines, curves and surfaces, as shown in Fig. 9a. By importing the G-code of the Mercedes Benz mold testing sample into the PD-VPC algorithm proposed in this paper, given the FIR filter parameters and contour error (the specific parameters are the same as below), the interpolation points that meet the actual processing requirements can be obtained. The speed expressed by the coloring method is shown in Fig. 9b. The dark red represents the maximum speed of 3000 [mm/ min], and the dark blue represents the speed approaching 0. It can be seen from the figure that the speed trend conforms to the track characteristics of the Mercedes Benz sample. There are different degrees of deceleration at each corner, and the maximum speed is basically obtained at long segments and small curvature.
As the Mercedes Benz sample is composed of several regions, and the number of G-code points for finish machining exceeds 620 thousand, this study needs to select a representative path for specific comparison. The G-code toolpaths in the red dotted box in Fig. 9 has a large curvature change, and the complexity of the track segment length is the largest. Thus, this study uses a section of the line-cutting path as the processing path, as shown in Fig. 10, to verify the feasibility and effectiveness of the algorithm. The red point represents the command position of G-code, and the The tool-path is composed of long segments and continuous micro-segments, and the trajectory contour includes lines, curves, sharp corners, and rounded corners. This multifeature complex tool-path is representative of practical NC machining.
The line-cutting trajectory includes 233 linear segments, of which the shortest path length is 0.021 [mm], the longest path length is 29.078 [mm], the total path length is 221.849 [mm], and the average length is 0.952 [mm]. The given feed rate during machining is 3000 [mm/min], and the set contour error is 10 [μm]. To make a fair and comprehensive comparison, this study uses the following FIR filter interpolation algorithms for the line-cutting trajectory: (1) the P2P mode, where the dwell time is equal to the delay time; (2) the NS-DCB algorithm proposed in Ref. [21], which controls the dwell time according to the contour error; (3) the proposed PD-VPC algorithm; (4) velocity directly blending mode, whose dwell time is zero and hereinafter referred to as VDB mode. It is worth mentioning that the NS-VCB algorithm proposed in Ref. [21] is only applicable to long segments; thus, it does not participate in the comparative experiment.
For the above three algorithms, the same filter constant must be used. In this study, T 1 = 20 [ms] and T 2 = 10 [ms] are set. The PD-VPC algorithm needs to discretize the G-code points in advance. Through the simulation of the line-cutting trajectory, the running time T run of the algorithm and the total interpolation time T interp of G-code under different k s are obtained, as shown in Fig. 11.
It can be seen from the figure that when k s is close to 1, the running time of the algorithm T run is short. Due to the number of discrete segments of the system is small, the speed of some regions is depressed and the duration time is long, so the total interpolation time of G-code T interp is long. When k s is close to 0.67, the total interpolation time T interp is significantly shorter, but the running time T run is slightly increased because of too many discrete segments of the system. Later, as k s exceeds 0.5 and approaches 0.1, the total interpolation time T interp basically remains unchanged, while the running time T run increases exponentially. Thus, the running time of the algorithm and the total interpolation time of G-code are usually appropriate when k s ∈ [0.5, 0.75] is usually taken. In this study, the local optimal solution k s = 0.5 is chosen.
The G-code track before and after discretization is shown in the Fig. 12. The blue point is the original G-code point, and the orange point is the discrete G-code point. It is obvious that long segments are regularly broken into short segments, while the micro-segments remain unchanged. After discretization, the number of track segments is 799, and the length of the shortest segment remains unchanged because this segment is not discretized. The longest segment length is 0.503 [mm], and the duration of its rectangular-frame speed can be calculated to be 10.12 [ms], which is approximately equal to the delay time of the second-order filter. As shown in the red dotted line box in the figure, on the one hand, in the area of rapid curvature change, such as corner [1], the track segments are micro-segments and will not be discrete. On the other hand, the micro-segment on a path close to a straight line, such as corner [2], also remains unchanged. Discretization realizes consistent processing of trajectory characteristics, making the processed trajectory meet the input requirements of the MM-VPC algorithm. Figure 13a shows the distribution of trajectory velocity on the interpolation contour obtained by the PD-VPC algorithm. RGB, three primary colors, are selected to represent the speed. Red color represents high speed, and light colors represent low speed. There are 13 obviously light colored areas, corresponding to the deceleration part in Fig. 13b. For large corners, that is, close to a straight line, such as corners [2,4,12], the speed will drop slightly, and then quickly return to the maximum speed. However, for areas with large curvature changes, such as corners [3,7,11], the corresponding deceleration time is longer, and there are multiple speed extreme points. Consequently, the result of velocity planning conforms to the geometric characteristics of the trajectory. Figure 14 shows the machining contour calculated by interpolation with four algorithms, in which the blue point represents the G-code point of the Benz sample. The 3-axis contouring performance for the interpolation schemes are measured in Fig. 15. As can be seen from the figures, the P2P mode performs point-to-point precise motion. It completely coincides with the G-code point trajectory. Thus, no contour errors are observed. The VDB mode directly mixes the speed without considering the contour error constraint. So out-of-tolerance is evident at the corner. The proposed PD-VPC algorithm complies with the set contour error requirement of 10 [μm] in all processing areas, whereas the NS-DCB algorithm has an out-of-tolerance phenomenon in local areas. The corners [1][2][3][4][5][6] in the Fig. 14 show that the contour error of the PD-VPC algorithm is smaller than that of the NS-DCB algorithm at various corners. Figure 15 also shows that the contour error of the PD-VPC algorithm is smaller than NS-DCB algorithm in most areas of the whole trajectory. Summarily, the PD-VPC algorithm can effectively and accurately control contour error.
The composite velocity, acceleration, and jerk of the four algorithms are shown in Fig. 16. No dwell time is observed in VDB mode. Thus, the processing time is . In P2P mode, given frequent acceleration and deceleration, the processing time is the longest, which is 11.43 [s]. Although the processing time of the PD-VPC algorithm is slightly longer than that of the NS-DCB algorithm, Fig. 16b and c show that the PD-VPC algorithm effectively reduces the acceleration and jerk amplitude of the system. The performance of acceleration on CNC machine tools is force. Decreasing the acceleration and jerk means that the amplitude and change rate of the force on the system become smaller. Therefore, system vibration will be reduced, and the surface quality will be improved. Given the starting and ending of the profiles correspond to the feed section and withdrawal section of the machining, it is not considered when comparing the acceleration and jerk amplitude. Figure 17 shows the single-axis kinematics parameters for the X-axis and Z-axis of the system. Figure 17b and c show that the motion trajectory acceleration generated by the PD-VPC algorithm is continuous, the jerk is bounded, and the amplitude of acceleration and jerk is greatly reduced. Thus, the interpolation point trajectory generated by PD-VPC algorithm is smooth and secondorder continuous. The PD-VPC algorithm can effectively reduce the uniaxial vibration of the system. Given the trajectory characteristics of the Benz tool-path, the performance on each axis is also different. The acceleration amplitude of X-axis is reduced by 18%, and the jerk amplitude is reduced by 73%. The acceleration amplitude of Z-axis is reduced by 51%, and the jerk amplitude is reduced by 82%. Conclusively, the acceleration amplitude of each axis is reduced to a certain extent, and the jerk amplitude is greatly reduced.

Conclusions
This paper presents a universal algorithm for blending tool-paths machining of CNC system based on FIR filtering. The results show that the algorithm can control the contour error effectively, reduce system vibration, and improve machining quality. The existing algorithms mainly focus on smooth trajectory generation for long segments. Few studies for continuous micro-segments adopt the trapezoidal shaped velocity scheme when calculating the corner contour error. This study proposes a general algorithm for generating continuous acceleration trajectory based on FIR filtering, which can be applied to the blending tool-paths with long segments and microsegments and effectively control the contour error. Experimental results show that the overall processing  time can be reduced up to 50% compared to the P2P mode. On the other hand, the acceleration amplitudes of the single axis can be reduced up to 10-50%, and the jerk amplitude can be reduced up to 70-80%. Thus, the algorithm can effectively suppress the vibration in the processing process and improve machining surface quality. In the future, the PD-VPC algorithm will also be applied to the research of 5-axis trajectory planning, and the core problem is to solve the model of tool orientation vector contour error.