1 Introduction

The evolution of Computer Numerical Control (CNC) machining has brought about a revolution in manufacturing processes, not only enhancing precision and efficiency but also addressing the challenges posed by complex geometries and demanding machining applications. This paper deals with the domain of CNC thread milling, introducing an innovative approach through the development and implementation of a comprehensive canned cycle.

A canned cycle is a predefined machining operation that entails a sequence of machine movements to perform various machining tasks like drilling, pocketing, slotting, boring, and tapping. It aims to simplify programming by consolidating multiple commands into a single block, utilizing G-code to define machining operations that would typically necessitate multiple blocks [1, 2]. Continuous efforts are made by CNC manufacturers to incorporate new canned cycles into their controllers, specifically designed to handle intricate and complex geometries [3, 4]. This is easily concluded by comparing the canned cycles available nowadays with the older ones.

Centered on programming and facilitating the precise and efficient cutting of threads within a user-friendly environment, incorporating both fixed and variable pitch and radius, the presented canned cycle addresses limitations posed by conventional canned cycles, which primarily target fixed pitch threads. In the precise domains of engineering and manufacturing, the use of variable pitch threads is necessitated by diverse potential applications. These applications encompass manufacturing components for automotive vehicle engines, fasteners for aerospace systems, industrial devices, robots manufacturing parts [5,6,7,8] and the creation of medical implants [9,10,11,12]. The mentioned references constitute a sample of recent related research work.

The foundation of work’s innovation lies in the integration of a sophisticated control algorithm into the CNC milling machine's software. This integration empowers operators with an unprecedented level of control over the thread cutting process. Operators can seamlessly choose between external or internal threads, define initial and final radii, determine initial and final pitch, specify the number of turns, and even select the thread's direction. This flexibility allows for the creation of threads with diverse geometries, significantly broadening the applicability of CNC milling machines in thread machining applications. Furthermore, the proposed canned cycle provides the means to switch between roughing and finishing passes. This is achieved through precise regulation of the step motion along the prescribed helical curve, adding another layer of adaptability to the machining process.

To validate the effectiveness of the approach, extensive simulation tests have been conducted under various threading cases. The results clearly demonstrate the efficiency of the proposed canned cycle, showcasing its capability to address a wide spectrum of machining scenarios.

The present study represents an evolution of prior research [13], wherein plans were discussed to extend the scope by incorporating cases with variable radius and pitch, along with predefined initial and final radii and pitches, with the number of turns also pre-selected. The current work builds upon and extends the findings from the previous research, resulting in a significant expansion of the capabilities of the proposed new canned cycle.

In the following sections, the paper presents the mathematical formulation of helix equations (Section 2), CNC parametric programming (Section 3), and the design and formulation of the interpolation algorithm (Sections 4 and 5). Implementation issues (Section 6) and comprehensive test results (Section 7) are then discussed. In the conclusion (Section 8), the paper highlights the innovative canned cycle's contribution to advancing CNC thread milling.

2 Mathematical formulation of helix equations

To facilitate the cutting of threads with constant or variable radius and pitch on a 3-axis CNC milling machine, it is crucial to have the ability to generate 3D motion along a helix with the specific characteristics. This involves solving the parametric equations x(t), y(t), z(t) of the helix within the framework of an interpolation algorithm.

When examining a conical helix, which is a helix situated on the curved surface of a cone, its parametric equations can be formulated as follows [14, 15]

$$x\left(t\right)=r\left(t\right)\text{cos}\left(2\pi n\left(t\right)\right),$$
(1)
$$y\left(t\right)=r\left(t\right)\text{sin}\left(2\pi n\left(t\right)\right),$$
(2)
$$z\left(t\right)={z}_{0}+m r\left(t\right)$$
(3)

where,

tf:

the time it takes the cutting tool to complete the process.

t:

the time variable, with \(0\le t\le {t}_{f}\).

r(t)-:

the radius of the helix at time \(t\).

n(t)-:

the number of turns of a helix at time \(t\).

m-:

the slope of the cone’s lines with respect to the \(x-y\) plane.

z0-:

a constant\(.\)

In the following stage of the modeling process, the definition of a function, labeled as r(t), is undertaken to embody ideal construction specifications. The preferred input parameters for the model, as illustrated in Fig. 1, include:

Ri:

the initial radius of the helix.

Rf:

the final radius of the helix.

pi:

the initial pitch of the helix.

pf:

the final pitch of the helix.

n:

the number of turns.

Fig. 1
figure 1

Helix with variable radius and pitch

Then \(r\left(t\right)\) should be calibrated accordingly accommodating these special parameter values. Assuming linear increase of the pitch from \({p}_{i}\) to \({p}_{f}\), \(p\left(t\right)\) can be expressed in the form:

$$p\left(t\right)={{p}_{i}+(p}_{f}-{p}_{i})\frac{t}{{t}_{f}}.$$
(4)

If T represents the time required for traversing a complete revolution, then \(z\left(t\right)\) at time \(t\) is given by:

$$z\left(t\right)=\frac{1}{T}{\int }_{0}^{t}p\left(s\right) ds=\frac{1}{T}{\int }_{0}^{t}\left({{p}_{i}+(p}_{f}-{p}_{i})\frac{t}{{t}_{f}}\right) ds=\frac{{p}_{i}t}{T}+\frac{{(p}_{f}-{p}_{i}){t}^{2}}{2T{t}_{f}}+C$$
(5)

Supposing that \(z\left(0\right)=0\), then obtain that \(C=0\). As a result:

$$z\left(t\right)=\frac{{p}_{i}t}{T}+\frac{{(p}_{f}-{p}_{i}){t}^{2}}{2T{t}_{f}}.$$
(6)

Assuming that the helix is traversed with constant angular velocity, \({n}_{0}\) (rev/min), implies that \(T=\frac{1 }{{n}_{0}}\), and \({t}_{f}=\frac{n }{{n}_{0}}\), which gives that \(\frac{T }{{t}_{f}}=\frac{1 }{n}\). Given this, Eq. (6) simplifies to:

$$z\left(t\right)=n{p}_{i}\frac{t}{{t}_{f}}+\frac{{n(p}_{f}-{p}_{i})}{2}{\left(\frac{t}{{t}_{f}}\right)}^{2}.$$
(7)

Equation (3) suggests that the radius \(r\left(t\right)\) can then be expressed as:

$$r\left(t\right)= \frac{1}{m} \left(z\left(t\right)-{z}_{0}\right)=\frac{1}{m} \left(n{p}_{i}\frac{t}{{t}_{f}}+\frac{{n(p}_{f}-{p}_{i})}{2}{\left(\frac{t}{{t}_{f}}\right)}^{2}-{z}_{0}\right).$$
(8)

Given that \(r\left(0\right)={R}_{i}\) and that \(r\left({t}_{f}\right)={R}_{f}\), obtain that:

$${z}_{0}=-{mR}_{i},\text{ with }m= \frac{n\left({p}_{f}+{p}_{i}\right)}{2\left({R}_{f}-{R}_{i}\right)}$$
(9)

A simple calculation then gives that:

$$r\left(t\right)= {R}_{i}+\frac{2{p}_{i}\left({R}_{f}-{R}_{i}\right)}{{p}_{f}+{p}_{i}}\frac{t}{{t}_{f}}+\frac{{(p}_{f}-{p}_{i})\left({R}_{f}-{R}_{i}\right)}{{p}_{f}+{p}_{i}} {\left(\frac{t}{{t}_{f}}\right)}^{2}$$
(10)

Given the constant angular velocity \({n}_{0}\), one can also derive \(n\left(t\right)={n}_{0}t\). Thus, the corresponding equations of motion are given by:

$$x\left(t\right)=\left({R}_{i}+\frac{2{p}_{i}\left({R}_{f}-{R}_{i}\right)}{{p}_{f}+{p}_{i}}\frac{t}{{t}_{f}}+\frac{{(p}_{f}-{p}_{i})\left({R}_{f}-{R}_{i}\right)}{{p}_{f}+{p}_{i}} {\left(\frac{t}{{t}_{f}}\right)}^{2} \right)\text{cos}\left(2\pi {n}_{0}t\right),$$
(11a)
$$y\left(t\right)=\left({R}_{i}+\frac{2{p}_{i}\left({R}_{f}-{R}_{i}\right)}{{p}_{f}+{p}_{i}}\frac{t}{{t}_{f}}+\frac{{(p}_{f}-{p}_{i})\left({R}_{f}-{R}_{i}\right)}{{p}_{f}+{p}_{i}} {\left(\frac{t}{{t}_{f}}\right)}^{2}\right)\text{sin}\left(2\pi {n}_{0}t\right),$$
(11b)
$$z\left(t\right)=n{p}_{i}\frac{t}{{t}_{f}}+\frac{{n(p}_{f}-{p}_{i})}{2}{\left(\frac{t}{{t}_{f}}\right)}^{2}$$
(11c)

Since \(0\le t\le {t}_{f},\) dividing by \({t}_{f}\) gives that \(0\le \frac{t}{{t}_{f}}\le 1\) and thus define \(\tau =\frac{t}{{t}_{f}}=\frac{{n}_{0}t}{n}\). Thus, the equations of motion in terms of the new variable \(\tau\) with \(0\le \tau \le 1\), can be written as follows:

$$x\left(\tau \right)=\left({R}_{i}+\frac{2{p}_{i}\left({R}_{f}-{R}_{i}\right)}{{p}_{f}+{p}_{i}}\tau +\frac{{(p}_{f}-{p}_{i})\left({R}_{f}-{R}_{i}\right)}{{p}_{f}+{p}_{i}} {\tau }^{2} \right)\text{cos}\left(2\pi n\tau \right),$$
(12a)
$$y\left(\tau \right)=\left({R}_{i}+\frac{2{p}_{i}\left({R}_{f}-{R}_{i}\right)}{{p}_{f}+{p}_{i}}\tau +\frac{{(p}_{f}-{p}_{i})\left({R}_{f}-{R}_{i}\right)}{{p}_{f}+{p}_{i}} {\tau }^{2}\right)\text{sin}\left(2\pi n\tau \right),$$
(12b)
$$z\left(\tau \right)=n{p}_{i}\tau +\frac{{n(p}_{f}-{p}_{i})}{2}{\tau }^{2}.$$
(12c)

Notice that the final height of the workpiece H is given by \(H=z\left(1\right)=n\frac{{p}_{f}+{p}_{i}}{2}\).

It can be easily shown that these equations are also valid for \({R}_{i}={R}_{f}\) as the equations of motion reduce to:

$$x\left(\tau \right)={R}_{i}\text{cos}\left(2\pi n\tau \right),$$
(13a)
$$y\left(\tau \right)={R}_{i}\text{sin}\left(2\pi n\tau \right),$$
(13b)
$$z\left(\tau \right)=n{p}_{i}\tau +\frac{{n(p}_{f}-{p}_{i})}{2}{\tau }^{2} .$$
(13c)

Moreover, swapping the sine and cosine functions in the initial two Eqs. (12a) and (12b), allows for either a left-hand or right-hand thread type. The validation of Eqs. (12) is illustrated in the plots of Figs. 2, 3, 4, 5, 6 and 7 using representative values for pitch, radius and number of turns.

Fig. 2
figure 2

Helix with constant radius and variable increasing pitch (Ri = Rf = 40, pi = 4, pf = 16, n = 10)

Fig. 3
figure 3

Helix with constant radius and variable decreasing pitch (Ri = Rf = 40, pi = 16, pf = 4, n = 8)

Fig. 4
figure 4

Helix with variable radius and variable increasing pitch (Ri = 50, Rf = 80, pi = 5, pf = 25, n = 8)

Fig. 5
figure 5

Helix with variable radius and variable decreasing pitch (Ri = 50, Rf = 80, pi = 25, pf = 5, n = 8)

Fig. 6
figure 6

Helix with variable radius and constant pitch (Ri = 50, Rf = 80, pi = 15, pf = 15, n = 8)

Fig. 7
figure 7

Helix with initial radius set to zero and variable Increasing pitch (Ri = 0, Rf = 40, pi = 0, pf = 20, n = 7)

3 CNC parametric programming

CNC parametric programming serves as a flexible platform accessible in widely adopted controllers, known by various names depending on the provider controller. Fanuc custom macro B, Fadal macro, Okuma user task, Sinumeric and Heidenhain parametric technique are among the most widely used. Numerous research studies [16,17,18,19,20] have utilized this platform to resolve complex machining cases. This section aims to provide a detailed explanation of Heidenhain's parametric programming, the chosen programming language for this study. For a comprehensive understanding of the language, readers are directed to Lynch's in-depth book on the subject [21].

Within the Heidenhain control system, parameters are denoted by the letter Q followed by an integer. These parameters can be assigned numerical values directly or via arithmetic or trigonometric operations. Furthermore, the Q parameters can undergo dynamic updates during program execution and continuous checks to determine adherence to specific conditions, thereby influencing the program flow. In addition to the Q parameters, the letter D is employed to encode various functions, with specific functions represented by numbers 1 to 13 (refer to Table 1). The table presented herein has been adopted from the reference [13] mentioned earlier in the introduction. To illustrate the language's structure, the table provides examples and explanations for each individual D code. It is significant to emphasize that Q parameters and fixed numerical values can coexist within the same function, allowing enhanced flexibility in programming.

Table 1 Heidenhain Control System Parameter Guide

4 Design of the interpolation algorithm

The interpolation algorithm is designed to handle a broad spectrum of thread geometries under desired cutting conditions. In this regard, the operator is empowered with the capability to define any of the features outlined in Table 2. Each feature is correspondingly assigned to a Q parameter, constituting the input values for the algorithm.

Table 2 Summary of thread features along with the corresponding assigned input parameters (Q)

The development of the G-code algorithm is achieved through a main program and two subprograms. The main program initiates thread data by configuring parameters Q1-Q11 (refer to Table 2), positions the cutter at the starting point, and directs the execution flow to one of the two subprograms. These subprograms are formulated to address either a right-hand or a left-hand thread. The structure of the main program and the two subprograms is depicted in the flowcharts of Figs. 8 and 9 respectively.

Fig. 8
figure 8

Main program flowchart

Fig. 9
figure 9

Subprogram flowchart

While the flowchart of the subprogram (Fig. 9) illustrates the scenario of a right-hand thread, a similar flowchart can be easily created for the left-hand thread case by interchanging the sine and cosine functions in the first two Eqs. (12a) and (12b).

5 Formulation of the G-code algorithm

The G-code algorithm is developed within the Heidenhain control framework. Furthermore, it can be effortlessly adapted for integration with any other CNC control system supporting parametric programming. Entering the necessary thread data and cutting conditions into the G-code algorithm is achieved through the utilization of Q parameters, as detailed in Section 4.

The flowcharts presented in Figs. 8 and 9 serve as the foundation for developing the G-code parametric algorithm, illustrating the logical structure of both the main program and the two subprograms. The corresponding code, along with accompanying comments, can be found in Tables 3 and 4. Table 3 outlines the main program, while Table 4 details subprogram 1. Subprogram 2 maintains the same structure but exchanges the sine and cosine functions in the first two Eqs. (12a and 12b).

Table 3 List of G-code for the main program
Table 4 List of G-code for the Subprogram-1

6 Implementation

6.1 Practical aspects

A suitable cutter for threading on a CNC milling machine is the single form cutter depicted in Fig. 10. Figures 11 and 12 illustrate the same cutter during the milling process for an external and internal thread respectively.

Fig. 10
figure 10

A single-form thread cutter

Fig. 11
figure 11

External thread milling

Fig. 12
figure 12

Internal thread milling

The zero-reference point is located at the upper surface of the workpiece, aligning with the center of the helix. The algorithm directs the rotating cutter differently based on the thread type, whether internal or external. For internal threads, the cutter is moved linearly to the starting position with coordinates X = Ri – r, Y = 0, Z = 0. Alternatively, for external threads, the starting position is at coordinates X = Ri + r, Y = 0, Z = 0. The starting position is indicated in Figs. 13 and 14 for cases involving a constant and variable radius, respectively.

Fig. 13
figure 13

Thread milling – Case: constant radius

Fig. 14
figure 14

Thread milling – Case: variable radius (a) Internal threading (b) External threading

After positioning the cutter at the starting position, the algorithm directs the flow to one of the two subprograms based on the desired thread direction. Upon completion of the machining process, the tool first retracts from the workpiece before moving to a safe height above the top surface.

6.2 G-codification

Typically, canned cycles are standardized and encoded using a G-code accompanied by a set of parameters. It's essential to highlight that CNC controllers deliberately reserve certain G-codes for potential future applications, enabling customized implementations and enhanced flexibility. Specifically, within the Heidenhain control framework, the unassigned G101 code has been chosen for the proposed implementation. The required supplemental data for the canned cycle can be conveyed through parameters P01 to P10 in a statement following the structure given in Fig. 15.

Fig. 15
figure 15

Structure of the proposed thread canned cycle

7 Test results

Simulation tests (depicted in Figs. 16, 17, 18, 19, 20, 21, 22 and 23) have been carefully chosen to showcase the efficiency of the proposed canned cycle, encompassing all possible threading cases it is capable of handling. TEST-1 and TEST-2 simulate the same threading scenario but with different precision steps, offering a valuable capability for both roughing and finishing passes. TEST-3 represents a left-hand thread with a variable radius and increasing pitch, while TEST-4 demonstrates a right-hand thread with a variable radius and decreasing pitch. TEST-5 maintains the settings of TEST-4 but incorporates an increased number of turns. TEST-6 focuses on a left-hand thread with a variable radius and constant pitch. TEST-7 examines a case of a left-hand thread with an initial radius set to zero and a variable increasing pitch. While all previous tests relate to external threads, the final TEST-8 illustrates a case of an internal thread. In all instances, the traced path displayed in the graphical simulation corresponds to the center of the cutting tool.

Fig. 16
figure 16

TEST-1: Left-hand thread on constant radius with increasing pitch (Ri = Rf = 40, pi = 4, pf = 16, n = 10, precision τ = 0.01)

Fig. 17
figure 17

TEST-2: Left-hand thread on constant radius with increasing pitch (Ri = Rf = 40, pi = 4, pf = 16, n = 10, precision τ = 0.001)

Fig. 18
figure 18

TEST-3: Left-hand thread on variable radius with increasing pitch (Ri = 50, Rf = 80, pi = 5, pf = 25, n = 8, precision τ = 0.001)

Fig. 19
figure 19

TEST-4: Right-hand thread on variable radius with decreasing pitch (Ri = 40, Rf = 90, pi = 20, pf = 4, n = 7, precision τ = 0.001)

Fig. 20
figure 20

TEST-5: Right-hand thread on variable radius with decreasing pitch (Ri = 40, Rf = 90, pi = 20, pf = 4, n = 10, precision τ = 0.001)

Fig. 21
figure 21

TEST-6: Left-hand thread on variable radius with constant pitch (Ri = 40, Rf = 80, pi = 15, pf = 15, n = 10, precision τ = 0.001)

Fig. 22
figure 22

TEST-7: Left-hand thread with initial radius set to zero and increasing pitch (Ri = 0, Rf = 40, pi = 0, pf = 20, n = 8, precision τ = 0.001)

Fig. 23
figure 23

TEST-8: Internal left-hand thread on variable radius with increasing pitch (Ri = 100, Rf = 50, pi = 5, pf = 20, n = 10, precision τ = 0.001)

8 Conclusions

The work presented in this paper built upon the foundations laid in previous mentioned research. As predicted in that earlier work, the present study advanced and extended the capabilities of the thread canned cycle to encompass threads with predefined start and ending radii, start and ending pitches, and the desired number of turns, applicable to both left- or right-hand, internal or external threads. Moreover, the proposed canned cycle seamlessly transitions between roughing and finishing passes, allowing precise regulation of step motion along the prescribed helical curve. The introduced canned cycle surpasses the limitations of conventional cycles, which are confined to fixed pitch threads, by providing a comprehensive solution for diverse threading requirements.

Simulation tests confirm the adaptability of the proposed canned cycle across diverse threading conditions. The graphical outputs, combined with the mathematical formulation of helix equations and CNC milling machine simulations across various threading cases, collectively verify the efficiency, and validation of the proposed canned cycle.