1 Introduction

Postprocessor is the bridge between CAM software and CNC machines, responsible for converting toolpath data from CAM software into G-code data that CNC machines can read and execute. Each CAM software typically comes with postprocessor sets for 3-axis milling machines and a few types of 5-axis CNC machines. However, for 5-axis CNC machines, there are many parameters that affect the compilation of data and one postprocessor set cannot be used for many different types of 5-axis CNC machines. Usually, each type of 5-axis CNC machine will have a suitable postprocessor set. Many previous studies have investigated the problem of writing postprocessor for 5-axis CNC machines. For example, Lee and She developed a post-processor for 3 type of five-axis CNC machine: table-tilting type, head-tilting type, and table/head tilting type. In general, all 5-axis CNC machines today have a suitable postprocessor [1]. She and Lee studied postprocessors for three types of 5-axis CNC milling machines: Table tilting type, spindle tilting type, and table-spindle tilting type based on the generalized kinematics model of five-axis machine tools [2]. Jung et al. developed a post- processor for 5-axis milling machine of table-rotating/tilting type. With this type of machine, the translation from workpiece coordinates to absolute coordinate is not dependent on the tool length; this means that when changing the tool length, the CNC programing does not change [3]. Fatan and Feng (2004) have developed a generic kinematic model for various configurations of 5-axis machines [4]. Sørby presents an algorithm for calculating the inverse kinematics of five-axis machines close to singular and the kinematics of a five-axis machine with non-orthogonal rotary axes is analyzed [5]. She and Chang have presented a postprocessor algorithm for the five-axis machine tool with a nutating head whose rotational axis is in an inclined plane and a five-axis machine tool with a C-axis behind a B-axis nutating rotary head is selected as an example [6]. Jung et al. (2011) developed postprocessor for 5-axis machines with orthogonal and non-orthogonal table rotary axes [7]. Son et al. introduce a post-processor program that tilts from axis B, of which the head is inclined at about 45 degrees, moves straight toward the X and Z axes, rotates the table from C, and then moves along axis Y based on the calculating of inverse kinematics, [8]. Tran (2012) researched the postprocessor set for a 5-axis milling machine in the form of a B-rotary table and C-rotary table, with the B-axis tilted 45 degrees to the Y-axis, [9]. Chu et al. (2020) developed postprocessor for 5-axis milling machine Spinner U5-620, [10]. This machine is dual table rotating type so tool length does not affect the CAM data transfer. Chu and his colleagues also require setting the workpiece coordinate origin at the intersection of the B-axis and the C-axis in their post processor. Furthermore, the current postprocessor sets for 5-axis machines often require the workpiece origin to be set on the axis of rotation, while the postprocessor software in this study allows the workpiece origin to be set at any position on the table of machine. This study presents the author’s approach in building a postprocessor for 2 types of 5-axis milling machine: table-head tilting CNC machine and head-head tilting CNC machine, based on the determination of coordinate transfer matrices. Based on this approach, through the construction of coordinate transfer matrices, it is possible to build a postprocessor set for various types of 5-axis CNC machine configurations. This study builds postprocessor software for 5-axis CNC milling machine model B-head rotary/C table rotary and B-head rotary/C head rotary with rotation direction B + and C- and can add postprocessor for other 5-axis CNC machines to the software easily by changing the formula of the coordinate transfer matrix. There are three important factors for building a post-processor set: the kinematic model of the CNC machine, depending on the structure and motion configuration of the axes; the CL data format; and the method of processing CL data. The goal of this study is to build a post-processor software with CLSF format input data exported from a CAM software and G-code output data that can be used for CNC machines (Fig. 1).

Fig. 1
figure 1

B-axis with tilt angle \(\alpha^\circ\) and C-axis

2 Methodology

2.1 Developing the kinematic equations of the CNC machine

  1. a.

    Choosing the CNC machine configuration

The configurations of the 5-axis CNC machines selected in this study fall into two categories:

  • The head-table type with B-axis rotary/tilt head and C- axis rotary table, with the rotation direction in the form of B + , C-

  • The head-head type with B-axis rotary/tilt head and C-axis rotary head, with the rotation direction in the form of B + , C-, as show below:

In this study, there are 4 types of rotary/tilt head CNC machines with two common tilt angles \(\alpha =0^\circ\) and \(\alpha =45^\circ\) as shown in Figs. 2, 3, 4, and 5.

Fig. 2
figure 2

CNC machine 5-axis B Head tilt \(\alpha =0^\circ\) and C table; configuration B + , C-

Fig. 3
figure 3

CNC machine 5 axis B head tilt \(\alpha =45^\circ\) and C table; configuration: B + , C-

Fig. 4
figure 4

CNC machine 5-axis B head tilt \(\alpha =0^\circ\) and C head; configuration: B + , C-

Fig. 5
figure 5

CNC machine 5 axis B head tilt \(\alpha =45^\circ\) and C head; configuration: B + , C-

  1. b.

    Kinematics of 5-axis CNC machines

The symbols and corresponding definition of terminologies (Fig. 6):

  • Limits of rotary axes:

  • The value of angle B varies from − B0 to + B.0 (adjustable through the postprocessor software)

  • The value of angle C varies from 00 to 359.999.0

  • \(L\): the distance from the tool center to the intersection point of B-axis and the spindle- axis (\({O}_{2}T=L\))

  • *\(\alpha\): the tilt angle of axis B with respect to spindle axis. (Figs. 1 and 7)

  • *\(Axyz\): the absolute coordinate system has axes \(Ax,Ay,\mathrm{and }\,Az\) parallel to the axes of the CNC machine, attached to the XY table of CNC machine. For 5-axis CNC machines head-head type, it coincides with workpiece coordinate system.

  • *\({O}_{1}{x}_{1}{y}_{1}{z}_{1}\): the coordinate system attached to the rotation axis C. For 5-axis CNC machines head-table type, it is the workpiece coordinate system.

  • *\({O}_{2}{x}_{2}{y}_{2}{z}_{2}\): the non-orthogonal coordinate system, which is attached to the spindle, \({O}_{2}\) is the intersection point of B- axis and the spindle axis. \({O}_{2}{z}_{2}\) is aligned with the spindle axis, \({O}_{2}{y}_{2}\) coincides with B-Axis. When\(B={0}^{0},C={0}^{0}\):\({O}_{2}{x}_{2}\) parallel with AX.

  • *\(T\): tool center (Figs. 6 and 7)

  • *\(O\): center of C-axis in the head-table machine type (it is on the axis of rotation C, in the same plane as \({O}_{1}\) and \(A\))

  • *\(\overrightarrow{i},\overrightarrow{j},\overrightarrow{k}\): the unit vector corresponding to the \(AX,AY,\mathrm{and }\,AZ\) axes

  • *\({\overrightarrow{i}}_{1},{\overrightarrow{j}}_{1},{\overrightarrow{k}}_{1}\): the unit vector corresponding to the \({O}_{1}{x}_{1},{O}_{1}{y}_{1},\mathrm{and }\,{O}_{1}{z}_{1}\) axes

  • *\({\overrightarrow{i}}_{2},{\overrightarrow{j}}_{2},{\overrightarrow{k}}_{2}\): the unit vector corresponding to the \({O}_{2}{x}_{2},{O}_{2}{y}_{2},\mathrm{and} \,{O}_{2}{z}_{2}\) axes.

  • *\({C}_{0}\): angle between \(\overrightarrow{OA}\) and \(\overrightarrow{AX}\) (for the Head- Table machine type)

  • *\({X}_{0},{Y}_{0}\): absolute coordinates of point O in the coordinate system \(AXYZ\) (for the head-table machine type)

  • *\(R\): length of \(OA\) and \(O{O}_{1}\) (for the head-table machine type,\(OA=O{O}_{1}\), when angle \(C=0^\circ\): \(A\equiv {O}_{1}\))

  • *\(X,Y,Z\): absolute coordinates (coordinates in the output NC file)

  • *\({x}_{w},{y}_{w},{z}_{w}\): workpiece coordinates (coordinates in CL data)

  • *\({L}_{1}:\) the distance from \({O}_{1}\) to the intersection point \(H\) of \({O}_{1}{x}_{1}\) axis with \({O}_{2}{x}_{2}\) axis (\({L}_{1}={O}_{1}H\), for the head-head machine type)

  • *\({y}_{H}:\) algebraic length of line segment \(\overline{{O}_{2}H}\) (for the head-head machine type, \({y}_{H}=\overline{{O}_{2}H}\))

  • *\({B}_{\mathrm{previous}}\): the angle B at the previous time point

  • *\({C}_{\mathrm{previous}}\): the angle C at the previous time point

Fig. 6
figure 6

Relationships between coordinate systems of table-head tilting 5-axis CNC machines

Fig. 7
figure 7

Relationships between coordinate systems of head-head tilting 5-axis CNC machines

2.1.1 The relationship between absolute coordinates and workpiece coordinates

So, the coordinates in the NC file are the coordinates of the tool when viewed in the coordinate system \(\left(AXYZ\right)\). To calculate the forward and inverse kinematics of the CNC machine, we need to determine the relationship between the coordinate systems \(\left({O}_{1}{x}_{1}{y}_{1}{z}_{1}\right)\), \(\left({O}_{2}{x}_{2}{y}_{2}{z}_{2}\right)\), and \(\left(AXYZ\right)\).

  • Forward kinematic of table-head tilting 5-axis CNC machines:

We have the following:

$$\overrightarrow{{O}_{1}T}=\overrightarrow{{O}_{1}O}+\overrightarrow{OA}+\overrightarrow{A{O}_{2}}+\overrightarrow{{O}_{2}T}$$
(1)

Expand:

$$\begin{array}{l}\begin{array}{l}\overrightarrow{{O}_{1}O}=-R\mathrm{cos}({C}_{0}+C)\overrightarrow{i}-R\mathrm{sin}({C}_{0}+C)\overrightarrow{j}\\ \overrightarrow{OA}=-{X}_{0}\overrightarrow{i}-{Y}_{0}\overrightarrow{j}\end{array}\\ \overrightarrow{A{O}_{2}}=X\overrightarrow{i}+Y\overrightarrow{j}+\left(Z+L\right)\overrightarrow{k}\\ \overrightarrow{{O}_{2}T}=-L{\overrightarrow{k}}_{2}\end{array}$$

So,

$$\overrightarrow{{O}_{1}T}=\left[X-{X}_{0}-R\mathit{cos}({C}_{0}+C)\right]\overrightarrow{i}+\left[Y-{Y}_{0}-R\mathit{sin}({C}_{0}+C)\right]\overrightarrow{j}+\left[Z+L\right]\overrightarrow{k}-L\overrightarrow{{k}_{2}}$$
(2)

With

$$\begin{array}{l}C_0=\left\{\begin{array}{l}\begin{array}{c}\mathrm{arcos}\left(\frac{-X_0}{\sqrt{X_0^2+Y_0^2}}\right),\mathrm{when:}\,Y_0\leq0\mathrm{,}\,X_0\neq0\end{array}\\\begin{array}{l}360^0-\mathrm{arcos}\left(\frac{-X_0}{\sqrt{X_0^2+Y_0^2}}\right),\mathrm{when:}\,Y_0>0\mathrm{,}\,X_0\neq0\\0^0,\mathrm{when:}\,Y_0=0\mathrm{,}\,X_0=0\,\end{array}\end{array}\right.\\R=\sqrt{X_0^2+Y_0^2}\end{array}$$

The relationship between the vector systems \(\left(\overrightarrow{i},\overrightarrow{j},\overrightarrow{k}\right),\left(\overrightarrow{{i}_{1}},\overrightarrow{{j}_{1}},\overrightarrow{{k}_{1}}\right),\mathrm{ and }\left(\overrightarrow{{i}_{2}},\overrightarrow{{j}_{2}},\overrightarrow{{k}_{2}}\right)\) through the coordinate transfer matrix:

$$\left[\begin{array}{c}\overrightarrow{{i}_{1}}\\ \overrightarrow{{j}_{1}}\\ \overrightarrow{{k}_{1}}\end{array}\right]=\left[{A}_{1}\right]\left[\begin{array}{c}\overrightarrow{i}\\ \overrightarrow{j}\\ \overrightarrow{k}\end{array}\right];\left[\begin{array}{c}\overrightarrow{{i}_{2}}\\ \overrightarrow{{j}_{2}}\\ \overrightarrow{{k}_{2}}\end{array}\right]=\left[{A}_{2}\right]\left[\begin{array}{c}\overrightarrow{i}\\ \overrightarrow{j}\\ \overrightarrow{k}\end{array}\right]$$
(3)

With:

$$\begin{array}{l}\left[{A}_{1}\right]=\left[\begin{array}{ccc}\mathrm{cos}\;C& \mathrm{sin}\;C& 0\\ -\mathrm{sin}\;C& \mathrm{cos}\;C& 0\\ 0& 0& 1\end{array}\right]\\ \left[{A}_{2}\right]=\left[\begin{array}{ccc}\mathrm{cos}\;B& \mathrm{sin}\;B\;\mathrm{sin}\;\alpha & -\mathrm{sin}\;B\;\mathrm{cos}\;\alpha \\ 0& \mathrm{cos}\;\alpha & \mathrm{sin}\;\alpha \\ \mathrm{sin}\;B\;\mathrm{cos}\;\alpha & \mathrm{sin}\;\alpha\; \mathrm{cos}\;\alpha \left(1-\mathrm{cos}\;B\right)& 1-{\mathrm{cos}}^{2}\;\alpha \left(1-\mathrm{cos}\;B\right)\end{array}\right]\end{array}$$
(4)

From (2), (3), and (4):

$$\begin{array}{l}\overrightarrow{{O}_{1}T}=\left[X-{X}_{O}-R\;\mathrm{cos}({C}_{0}+C)-L\;\mathrm{cos}\;\alpha\; \mathrm{sin}\;B\right]\overrightarrow{i}\\ +\left[Y-{Y}_{O}-R\;\mathrm{sin}({C}_{0}+C)-L\;\mathrm{sin}\;\alpha\; \mathrm{cos}\;\alpha \left(1-\mathrm{cos}\;B\right)\right]\overrightarrow{j}\\ +\left[Z+L\;{\mathrm{cos}}^{2}\;\alpha \left(1-\mathrm{cos}\;B\right)\right]\overrightarrow{k}\end{array}$$

On the other hand,

$$\begin{array}{l}\overrightarrow{{O}_{1}T}={x}_{w}\overrightarrow{{i}_{1}}+{y}_{w}\overrightarrow{{j}_{1}}+{z}_{w}\overrightarrow{{k}_{1}}\\ =\left[\begin{array}{ccc}{x}_{w}& {y}_{w}& {z}_{w}\end{array}\right]\left[\begin{array}{c}\overrightarrow{{i}_{1}}\\ \overrightarrow{{j}_{1}}\\ \overrightarrow{{k}_{1}}\end{array}\right]=\left[\begin{array}{ccc}{x}_{w}& {y}_{w}& {z}_{w}\end{array}\right]\left[{A}_{1}\right]\left[\begin{array}{c}\overrightarrow{i}\\ \overrightarrow{j}\\ \overrightarrow{k}\end{array}\right]\end{array}$$
(5)

So,

$$\begin{array}{l}\left[\begin{array}{ccc}\left(\begin{array}{c}X-{X}_{O}\\ -R\;\mathrm{cos}({C}_{0}+C)\\ -L\;\mathrm{cos}\;\alpha\; \mathrm{sin}\;B\end{array}\right)& \left(\begin{array}{c}Y-{Y}_{O}\\ -R\;\mathrm{sin}({C}_{0}+C)\\ -L\;\mathrm{sin}\;\alpha\; \mathrm{cos}\;\alpha \left(1-\mathrm{cos}\;B\right)\end{array}\right)& \left(Z+L\;{\mathrm{cos}}^{2}\;\alpha \left(1-\mathrm{cos}\;B\right)\right)\end{array}\right]\\ =\left[\begin{array}{ccc}{x}_{w}& {y}_{w}& {z}_{w}\end{array}\right]\left[{A}_{1}\right]\end{array}$$

And

$$\begin{array}{l}\left[\begin{array}{ccc}{x}_{w}& {y}_{w}& {z}_{w}\end{array}\right]=\\ \left[\begin{array}{ccc}\left(\begin{array}{c}X-{X}_{O}\\ -R\;\mathrm{cos}({C}_{0}+C)\\ -L\;\mathrm{cos}\;\alpha\; \mathrm{sin}\;B\end{array}\right)& \left(\begin{array}{c}Y-{Y}_{O}\\ -R\;\mathrm{sin}({C}_{0}+C)\\ -L\;\mathrm{sin}\;\alpha\; \mathrm{cos}\;\alpha \left(1-\mathrm{cos}\;B\right)\end{array}\right)& \left(Z+L\;{\mathrm{cos}}^{2}\;\alpha \left(1-\mathrm{cos}\;B\right)\right)\end{array}\right]{\left[{A}_{1}\right]}^{-1}\end{array}$$
(6)

Tool direction is \(\overrightarrow{{k}_{2}}\):

$$\overrightarrow{{k}_{2}}=\left[\begin{array}{ccc}I& J& K\end{array}\right]\left[\begin{array}{c}\overrightarrow{{i}_{1}}\\ \overrightarrow{{j}_{1}}\\ \overrightarrow{{k}_{1}}\end{array}\right]$$
(7)

And

$$\begin{array}{l}\overrightarrow{{k}_{2}}=\left[\begin{array}{ccc}\mathrm{sin}\;B\;\mathrm{cos}\;\alpha & \mathrm{sin}\;\alpha\; \mathrm{cos}\;\alpha \left(1-\mathrm{cos}\;B\right)& 1-{\mathrm{cos}}^{2}\;\alpha \left(1-\mathrm{cos}\;B\right)\end{array}\right]\left[\begin{array}{c}\overrightarrow{i}\\ \overrightarrow{j}\\ \overrightarrow{k}\end{array}\right]\\ =\left[\begin{array}{ccc}\mathrm{sin}\;B\;\mathrm{cos}\;\alpha & \mathrm{sin}\;\alpha\; \mathrm{cos}\;\alpha \left(1-\mathrm{cos}\;B\right)& 1-{\mathrm{cos}}^{2}\;\alpha \left(1-\mathrm{cos}\;B\right)\end{array}\right]{\left[{A}_{1}\right]}^{-1}\left[\begin{array}{c}\overrightarrow{{i}_{1}}\\ \overrightarrow{{j}_{1}}\\ \overrightarrow{{k}_{1}}\end{array}\right]\end{array}$$
(8)

From (6), (7), and (8), forward kinematic of table-head tilting 5-axis CNC machines is as follows:

$$\left\{\begin{array}{l}I=\mathrm{c}\mathrm{o}\mathrm{s}\,\alpha\,\mathrm{s}\mathrm{i}\mathrm{n}\,\mathrm{B}\,\mathrm{c}\mathrm{o}\mathrm{s}\,\mathrm{C}+\frac12\mathrm{s}\mathrm{i}\mathrm{n}\,2\,\alpha\left(1-\mathrm{cos}\,B\right)\mathrm{s}\mathrm{i}\mathrm{n}\,\mathrm{C}\\J=-\mathrm{c}\mathrm{o}\mathrm{s}\,\alpha\;\mathit{sin}\;C\;\mathrm{s}\mathrm{i}\mathrm{n}\,\mathrm{B}+\frac12\mathrm{s}\mathrm{i}\mathrm{n}\,2\alpha\left(1-\mathrm{cos}\,B\right)\mathit{cos}\;C\\K=\mathit{sin}^2\;\alpha+\mathit{cos}^2\;\alpha\;\mathit{cos}\;B\\x_w=\begin{pmatrix}X-X_O\\-R\;\mathit{cos}(C_0+C)\\-L\;\mathit{cos}\;\alpha\;\mathit{sin}\;B\end{pmatrix}\mathit{cos}\;C+\begin{pmatrix}Y-Y_O\\-R\;\mathit{sin}(C_0+C)\\-L\;\mathit{sin}\;\alpha\;\mathit{cos}\;\alpha\left(1-\mathit{cos}\;B\right)\end{pmatrix}\mathit{sin}\;C\\y_w=-\begin{pmatrix}X-X_O\\-R\;\mathit{cos}(C_0+C)\\-L\;\mathit{cos}\;\alpha\;\mathit{sin}\;B\end{pmatrix}\mathit{sin}\;C+\begin{pmatrix}Y-Y_O\\-R\;\mathit{sin}(C_0+C)\\-L\;\mathit{sin}\;\alpha\;\mathit{cos}\;\alpha\left(1-\mathit{cos}\;B\right)\end{pmatrix}\mathit{cos}\;C\\z_w=Z+L\;\mathit{cos}^2\;\alpha\left(1-\mathit{cos}\;B\right)\end{array}\right.$$
(9)
  • Forward kinematic of head-head tilting 5-axis CNC machines

We have the following:

$$\overrightarrow{AT}=\overrightarrow{A{O}_{1}}+\overrightarrow{{O}_{1}H}+\overrightarrow{H{O}_{2}}+\overrightarrow{{O}_{2}T}$$
(10)

Expand:

$$\begin{array}{l}\begin{array}{l}\overrightarrow{A{O}_{1}}=X\overrightarrow{i}+\left(Y+{y}_{H}{\mathrm{cos}}\alpha \right)\overrightarrow{j}+\left(Z+L+{L}_{1}+{y}_{H}{\mathrm{sin}}\alpha \right)\overrightarrow{k}\\ \overrightarrow{{O}_{1}H}=-{L}_{1}\overrightarrow{{k}_{1}}\end{array}\\ \overrightarrow{H{O}_{2}}=-{y}_{H}\overrightarrow{{j}_{2}}\\ \overrightarrow{{O}_{2}T}=-L\overrightarrow{{k}_{2}}\end{array}$$
(11)

Because:

$$\left[\begin{array}{c}\overrightarrow{{i}_{1}}\\ \overrightarrow{{j}_{1}}\\ \overrightarrow{{k}_{1}}\end{array}\right]=\left[{A}_{1}\right]\left[\begin{array}{c}\overrightarrow{i}\\ \overrightarrow{j}\\ \overrightarrow{k}\end{array}\right];\left[\begin{array}{c}\overrightarrow{{i}_{2}}\\ \overrightarrow{{j}_{2}}\\ \overrightarrow{{k}_{2}}\end{array}\right]=\left[{A}_{2}\right]\left[\begin{array}{c}\overrightarrow{i}\\ \overrightarrow{j}\\ \overrightarrow{k}\end{array}\right]$$
(12)

With:

$$\begin{array}{l}\begin{array}{c}\left[A_1\right]=\begin{bmatrix}\mathrm{cosC}&-\mathit{sin}\;C&0\\\mathrm{sinC}&\mathit{cos}\;C&0\\0&0&1\end{bmatrix}\\\left[A_2\right]=\begin{bmatrix}\left(\mathrm{cosBcosC}+\mathrm{sin}\alpha\mathrm{sinBsinC}\right)&-sin\;C\;\mathrm{cosB}+\mathrm{sin}\alpha\mathrm{sinB}\;cos\;C&-\mathrm{cos}\alpha\;sin\;B\\\mathrm{cos}\alpha\mathrm{sinC}&\mathrm{cos}\alpha\;cos\;C&sin\;\alpha\\\begin{pmatrix}\mathrm{cos}\alpha\mathrm{sinBcosC}\\+\frac12\mathrm{sin}2\alpha\left(1-\mathrm{cos}B\right)\mathrm{sinC}\end{pmatrix}&\begin{pmatrix}-sin\;C\;\mathrm{cos}\alpha\mathrm{sinB}\\+\frac12\mathrm{sin}2\alpha\left(1-\mathrm{cos}B\right)\;cos\;C\end{pmatrix}&\left(sin^2\;\alpha+cos^2\;\alpha\;cos\;B\right)\end{bmatrix}\end{array}\end{array}$$
(13)

From (11), (12), (13):

$$\overrightarrow{AT}=\begin{pmatrix}X-y_H\mathrm{c}\mathrm{o}\mathrm{s}\alpha\;\mathit{sin}\;C\\-L\begin{pmatrix}\mathrm{c}\mathrm{o}\mathrm{s}\alpha\mathrm{s}\mathrm{i}\mathrm{n}\mathrm{B}\mathrm{c}\mathrm{o}\mathrm{s}\mathrm{C}\\+\frac12\mathrm{s}\mathrm{i}\mathrm{n}2\alpha\left(1-\mathrm{cos}B\right)\mathrm{s}\mathrm{i}\mathrm{n}\mathrm{C}\end{pmatrix}\end{pmatrix}\overrightarrow i+\begin{pmatrix}Y+y_H\mathrm{c}\mathrm{o}\mathrm{s}\alpha\left(1-\mathit{cos}\;C\right)\\+L\begin{pmatrix}\mathrm{c}\mathrm{o}\mathrm{s}\alpha\;\mathit{sin}\;C\;\mathrm{s}\mathrm{i}\mathrm{n}\mathrm{B}\\-\frac12\mathrm{s}\mathrm{i}\mathrm{n}2\alpha\left(1-\mathrm{cos}B\right)\mathit{cos}\;C\end{pmatrix}\end{pmatrix}\overrightarrow j+\begin{pmatrix}Z\\+L\mathrm{c}\mathrm{o}\mathrm{s}^2\alpha\left(1-\mathit{cos}\;B\right)\end{pmatrix}\overrightarrow k$$
(14)

On the other hand,

$$\overrightarrow{AT}={x}_{w}\overrightarrow{i}+{y}_{w}\overrightarrow{j}+{z}_{w}\overrightarrow{k}$$
(15)

From (13), (14), and (15), forward kinematic of head-head tilting 5-axis CNC machines is as follows:

$$\left\{\begin{array}{l}I=\mathrm{c}\mathrm{o}\mathrm{s}\,\alpha\,\mathrm{s}\mathrm{i}\mathrm{n}\,\mathrm{B}\,\mathrm{c}\mathrm{o}\mathrm{s}\,\mathrm{C}+\frac12\mathrm{s}\mathrm{i}\mathrm{n}\,2\,\alpha\left(1-\mathrm{cos}\,B\right)\mathrm{s}\mathrm{i}\mathrm{n}\,\mathrm{C}\\J=-\mathrm{c}\mathrm{o}\mathrm{s}\,\alpha\,\mathit{sin}\;C\;\mathrm{s}\mathrm{i}\mathrm{n}\,\mathrm{B}+\frac12\mathrm{s}\mathrm{i}\mathrm{n}\,2\,\alpha\left(1-\mathrm{cos}\,B\right)\;\mathit{cos}\;C\\K=\mathit{sin}^2\;\alpha+\mathit{cos}^2\;\alpha\;\mathit{cos}\;B\\x_w=X-y_H\mathrm{c}\mathrm{o}\mathrm{s}\alpha\;\mathit{sin}\;C-L\left(\mathrm{cos}\alpha\mathrm{sinBcosC}+\frac12\mathrm{sin2}\alpha\left(1-\mathrm{cos}B\right)\mathrm{sinC}\right)\\y_w=Y+y_H\mathrm{c}\mathrm{o}\mathrm{s}\alpha\left(1-\mathit{cos}\;C\right)+L\left(\mathrm{cos}\alpha\;\mathit{sin}\;C\;\mathrm{sinB}-\frac12\mathrm{sin2}\alpha\left(1-\mathrm{cos}B\right)\mathit{cos}C\right)\\z_w=Z+L\mathrm{c}\mathrm{o}\mathrm{s}^2\alpha\left(1-\mathit{cos}\;B\right)\end{array}\right.$$
(16)

2.2 Inverse kinematic of CNC machines and solutions

There are two sets of values \(\left(X,Y,Z,B,\mathrm{and }\,C\right)\) that satisfy Eq. (9) or (16). For the initial rotary motion of angle \(B\), there are two values of angle \(B\) that fulfill Eq. (9) or (16). Once the value of angle B has been determined, there is only one value of angle C determined by angle B by (9) or (16). For each toolpath, once the initial value of angle B is determined, the subsequent values of angle B are uniquely determined based on the continuity of the toolpath. In this study, the set of values \(\left(X,Y,Z,B,\mathrm{and }\,C\right)\) can be chosen according to the following option:

2.2.1 For table-head tilting machine type

Angle B is determined to the following formula:

$$\left\{\begin{array}{l}B=\mathrm{a}\mathrm{r}\mathrm{c}\mathrm{o}\mathrm{s}\frac{K-\mathit{sin}^2\;\alpha}{\mathit{cos}^2\mathrm{ }\alpha},\alpha\neq90^0\\\mathrm{o}\mathrm{r}:\\B=-\mathrm{a}\mathrm{r}\mathrm{c}\mathrm{o}\mathrm{s}\frac{K-\mathit{sin}^2\;\alpha}{\mathit{cos}^2\mathrm{ }\alpha},\alpha\neq90^0\\\mathrm{o}\mathrm{r}:\\B=B_\mathrm{previous},\,\,\mathrm{w}hen:K=K_\mathrm{previous}\end{array}\right.$$

Angle C is then determined by angle B according to the following formula:

$$\left\{\begin{array}{l}\mathrm{C}\mathrm{=}\mathrm{a}\mathrm{r}\mathrm{c}\mathrm{o}\mathrm{s}\left(\frac{\mathrm{Icos}\alpha\;\mathit{sin}\;B+\frac12\mathrm{Jsin2}\alpha\left(1-\mathrm{cos}B\right)}{\mathrm{co}\mathrm{s}^2\alpha\;\mathit{sin}^{2\;}\mathrm{B}+\frac14\mathrm{si}\mathrm{n}^22\alpha\left(1-\mathrm{cos}B\right)^2}\right),\,\,\,\,\,\,\,\,\,\,\,\,\,\frac12\mathrm{I}\mathrm{s}\mathrm{i}\mathrm{n}2\alpha\left(1-\mathrm{cos}B\right)-\mathrm{J}\mathrm{c}\mathrm{o}\mathrm{s}\alpha\;\mathit{sin}\;B\geq0,B\neq0^0\\\mathrm{C}\mathrm{=}36\mathrm{0}^0-\mathrm{a}\mathrm{r}\mathrm{c}\mathrm{o}\mathrm{s}\left(\frac{\mathrm{Icos}\alpha\;\mathit{sin}\;B+\frac12\mathrm{Jsin2}\alpha\left(1-\mathrm{cos}B\right)}{\mathrm{co}\mathrm{s}^2\alpha\;\mathit{sin}^{2\;}\mathrm{B}+\frac14\mathrm{si}\mathrm{n}^22\alpha\left(1-\mathrm{cos}B\right)^2}\right),\,\,\frac12\mathrm{I}\mathrm{s}\mathrm{i}\mathrm{n}2\alpha\left(1-\mathrm{cos}B\right)-\mathrm{J}\mathrm{c}\mathrm{o}\mathrm{s}\alpha\;\mathit{sin}\;B<0,B\neq0^0\\C=C_{previous}\mathrm{,}\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,B=0\end{array}\right.$$
(17)

From (9), the absolute coordinates \(\left(X,Y,Z\right)\) is determined according to the formula:

$$\left\{\begin{array}{l}X=x_w\mathrm{c}\mathrm{o}\mathrm{s}C-y_w\;\mathit{sin}\;C+X_O+R\;\mathit{cos}(C_0+C)+L\;\mathit{cos}\;\alpha\;\mathit{sin}\;B\\Y=x_w\mathrm{s}\mathrm{i}\mathrm{n}C+y_w\mathrm{c}\mathrm{o}\mathrm{s}C+Y_O+R\;\mathit{sin}(C_0+C)+L\;\mathit{sin}\;\alpha\;\mathit{cos}\;\alpha\left(1-\mathit{cos}\;B\right)\\Z=z_w-L\;\mathit{cos}^2\;\alpha\left(1-\mathit{cos}\;B\right)\end{array}\right.$$
(18)

2.2.2 For head-head tilting machine type

Angle B is determined by the formula:

$$\left\{\begin{array}{l}B={\mathrm{a}}{\mathrm{r}}{\mathrm{c}}{\mathrm{o}}{\mathrm{s}}\frac{K-{\mathit{sin}}^{2}\alpha }{{\mathit{cos}}^{2}\alpha },\alpha \ne 9{0}^{0}\\ {\mathrm{o}}{\mathrm{r}}:\\ B=-{\mathrm{a}}{\mathrm{r}}{\mathrm{c}}{\mathrm{o}}{\mathrm{s}}\frac{K-{\mathit{sin}}^{2}\alpha }{{\mathit{cos}}^{2}\alpha },\alpha \ne 9{0}^{0}\\ {\mathrm{o}}{\mathrm{r}}:\\ B={B}_{previous}, \, \, {\mathrm{w}}hen:K={K}_{previous}\end{array}\right.$$

Angle C is then determined by angle B according to the formula:

$$\left\{\begin{array}{l}C=ar\mathit{cos}\left(\frac{I\mathit{cos}\alpha \mathit{sin}B+\frac{1}{2}J\mathit{sin}2\alpha \left(1-\mathit{cos}B\right)}{{\mathit{cos}}^{2}\alpha {\mathit{sin}}^{2}B+\frac{1}{4}{\mathit{sin}}^{2}2\alpha {\left(1-\mathit{cos}B\right)}^{2}}\right), \, \, \, \, \, \, \, \, \, \, \, \, \, \frac{1}{2}I\mathit{sin}2\alpha \left(1-\mathit{cos}B\right)-J\mathit{cos}\alpha \mathit{sin}B\ge 0,B\ne {0}^{0}\\ C=36{0}^{0}-ar\mathit{cos}\left(\frac{I\mathit{cos}\alpha \mathit{sin}B+\frac{1}{2}J\mathit{sin}2\alpha \left(1-\mathit{cos}B\right)}{{\mathit{cos}}^{2}\alpha {\mathit{sin}}^{2}B+\frac{1}{4}{\mathit{sin}}^{2}2\alpha {\left(1-\mathit{cos}B\right)}^{2}}\right), \, \, \frac{1}{2}I\mathit{sin}2\alpha \left(1-\mathit{cos}B\right)-J\mathit{cos}\alpha \mathit{sin}B<0,B\ne {0}^{0}\\ C={C}_{previous }, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, \, B=0\end{array}\right.$$
(19)

From (16), the absolute coordinates \(\left(X,Y,Z\right)\) is determined according to the formula:

$$\left\{\begin{array}{l}X=x_w+y_H\mathrm{c}\mathrm{o}\mathrm{s}\alpha\;\mathit{sin}\;C+L\left(\mathrm{cos}\alpha\mathrm{sinBc}\mathrm{osC}+\frac12\mathrm{sin2}\alpha\left(1-\mathrm{cos}B\right)\mathrm{sinC}\right)\\Y=y_w-y_H\mathrm{c}\mathrm{o}\mathrm{s}\alpha\left(1-\mathit{cos}\;C\right)-L\left(\mathrm{cos}\alpha\;\mathit{sin}\;C\;\mathrm{sinB}-\frac12\mathrm{sin2}\alpha\left(1-\mathrm{cos}B\right)\mathit{cos}\;C\right)\\Z=z_w-L\mathrm{c}\mathrm{o}\mathrm{s}^2\alpha\left(1-\mathit{cos}\;B\right)\end{array}\right.$$
(20)

CAM software will output coordinates \({x}_{w},{y}_{w},{z}_{w},I,J,\mathrm{and }\,K\) and in order for the CNC machine to operate on this data, coordinates \(X,Y,Z,B,\mathrm{and }\,C\) need to be determined by formulas (17) and (18) for head-table machine type and by formulas (19) and (20) for head-head machine type.

3 Developing the postprocessor software for testing

3.1 Functions of postprocessor the software

Functions of postprocessor the software are as follows:

  • A field for selecting the type of CNC machine

  • A field for entering the distance parameter from the tool center to the intersection point of B-axis and spindle

  • A field for entering the origin coordinate of the blank relative to the rotational axis

  • A field for entering the cutting speed

  • The function to select a CL data file

  • The function to export an NC file

3.2 Verify software accuracy

  1. a.

    Input data structure

The input CL Data is taken from a CAM software according to the CLSF ISO standard format. The data is in the following format:

  • Rapid movement: \(\mathrm{RAPID\, GOTO/}x,y,z,I,J,K\)  

  • Linear movement: \(\mathrm{GOTO/}x,y,z,I,J,K\)

  • Circular movement: \(\mathrm{CIRCLE/}{x}_{C},{y}_{C},{z}_{C},{I}_{C},{J}_{C},{K}_{C},R,\mathrm{GOTO/}x,y,z\)

  • Finish Program: END-OF-PATH

Here, \({x}_{C},{y}_{C},\mathrm{ and }\,{z}_{C}\) are the coordinates of the center of the circle \({I}_{C},{J}_{C},\mathrm{ and }\,{K}_{C}\) represent the axis of rotation of the circle, \(R\) is the radius of the circle, and \(x,y,and\, z\) are the coordinates of the endpoint of the circle (Figs. 8, 9, and 10).

Fig. 8
figure 8

Postprocessor for 5-axis milling B-rotary head tilt \(\alpha^\circ\) and C-rotary table

Fig. 9
figure 9

Toolpath in CAM Software

Fig. 10
figure 10

CL data input and G-code output

The postprocessor software will read data from the CL data file line by line. It will then calculate the corresponding absolute coordinates and generate G-code data with motion modes such as linear motion, circular interpolation, or rapid motion corresponding to GOTO, CIRCLE, or RAPID GOTO modes, respectively. Similarly, appropriate M-code commands will be added based on the data read from the CL data file.

  1. b.

    Compare the input data and the output data

  •  + Create a turbine blade machining program using CAM software.

  •  + Export the CL Data (file: turbine-CLdata.cls attached).

  •  + Utilize the Post-Processor software developed in this research to generate G-code (file: turbine-Gcode.NC attached) using the parameters of the head/table rotary mill 5-axis machine as follows:

    • Distance from tool tip to the intersection of spindle axis and B-axis: \(L=380 \mathrm{mm}\)

    • Inclination angle of axis B with respect to axis Y: \(\alpha ={0}^{0}\)

    • Coordinates of the rotary table center in terms of the absolute coordinate system: \({X}_{O}=0 \mathrm{mm};{Y}_{O}=0 \mathrm{mm}\) (origin set at the center of the rotary table). Input and output data are illustrated in Fig. 7.

    •  + The command line in the red rectangle on the right shows the tool tip coordinates in the absolute coordinate system, while the command line in the red rectangle on the left displays the tool tip coordinates in the corresponding workpiece coordinate system.

    •  + Simulate the production process on virtual CNC machines (Fig. 11).

      Fig. 11
      figure 11

      Machining simulation on virtual Head-Table Rotary 5-Axis CNC machines with generated G-code

    •  + Verify the compatibility of absolute coordinate and workpiece coordinate using CIMCO EDIT software (Fig. 12):

      Fig. 12
      figure 12

      Comparison of absolute coordinates and workpiece coordinates

Workpiece coordinates in CL data:

$${x}_{1}=-43.6849; \, {y}_{1}=-31.3404; \, {z}_{1}=244.0143$$

Workpiece coordinates in CIMCO EDIT:

$${x}_{1}=-43.686; \, {y}_{1}=-31.340; \, {z}_{1}=244.014$$

Compare the workpiece coordinate values in the CL data file with the workpiece coordinates calculated from the NC file, revealing a slight discrepancy:

$$\delta {x}_{1}=0.0011 \left(\mathrm{mm}\right), \, \delta {y}_{1}=0.0004 \left(\mathrm{mm}\right), \, \delta {z}_{1}=0.0003 \left(\mathrm{mm}\right).$$

This discrepancy arises from accumulated errors and computational inaccuracies introduced by the computer when using workpiece coordinate data from the CL data to calculate absolute coordinates and then reversing the process by using absolute data to calculate workpiece coordinates again. Simulations results can be seen at: https://www.youtube.com/watch?v=JNx5otKT4FI.

3.3 Simulating machining processes on 5-axis CNC machines with varying configurations

Programing the machining of a turbine rotor component using CAM software, and then exporting the CL data (attached file: turbinerotor-Cldata.cls) (Figs. 13, 14, 15, 16, and 17).

Fig. 13
figure 13

Programming the machining of a turbine rotor component using CAM software

Fig. 14
figure 14

Simulate the machining process of a turbine rotor component using a head/table rotary CNC machine. Simulations results can be seen at https://www.youtube.com/watch?v=RPUlYXTLBqs

Fig. 15
figure 15

Simulate the machining process of a turbine rotor component using a head tilt 45 deg/table rotary. Simulations results can be seen at https://www.youtube.com/watch?v=XooxCrheJ6E

Fig. 16
figure 16

Simulate the machining process of a turbine rotor component using a head/head rotary. Simulations results can be seen at https://youtu.be/yv9xuK6OR98

Fig. 17
figure 17

Simulate the machining process of a turbine rotor component using a head tilt 45 deg/head rotary. Simulations results can be seen at https://youtu.be/XgV2rwWCFQc

Example 1

Simulating machining on a virtual head/table rotary 5-axis CNC machine

Generate G-code (attached file: turbinerotor-tilt0deg.nc) using the parameters of the head/table rotary mill 5-axis machine as follows:

  • Distance from tool tip to the intersection of spindle axis and B-axis: \(L=380 \mathrm{mm}\)

  • Inclination angle of axis B with respect to axis Y: \(\alpha =0^\circ\)

  • Coordinates of the rotary table center in terms of the Absolute coordinate system: \({X}_{O}=0 \mathrm{mm};{Y}_{O}=0 \mathrm{mm}\) (origin set at the center of the rotary table).

Example 2

Simulating machining on a virtual head tilt 45 deg/table rotary 5-axis CNC machine

Generate G-code (attached file: turbinerotor-tilt45deg.nc) using the parameters of the head/table rotary mill 5-axis machine as follows:

  • Distance from tool tip to the intersection of spindle axis and B-axis: \(L=96 \mathrm{mm}\)

  • Inclination angle of axis B with respect to axis Y: \(\alpha =45^\circ\)

  • Coordinates of the rotary table center in terms of the absolute coordinate system: \({X}_{O}=0 \mathrm{mm};{Y}_{O}=0 \mathrm{mm}\) (origin set at the center of the rotary table).

Example 3

Simulating machining on a virtual head /head rotary 5 axis CNC machine

Generate G-code (attached file: “For Head-Head CNC Machine.nc” and “For Head-Head CNC.cls”) using the parameters of the Head/Head Rotary Mill 5-Axis machine as follows:

  • Distance from tool tip to the intersection of spindle axis and B-axis: \(L=433.75 \mathrm{mm}\)

  • Inclination angle of axis B with respect to axis Y: \(\alpha =0^\circ\)

  • \({y}_{H}=-5\,\mathrm{ mm}\)  

Example 4

Simulating machining on a virtual head tilt 45°/head rotary 5 axis CNC machine

Generate G-code (attached file: “For Head Tilt 45-Head CNC Machine.nc” and “For Head Tilt 45-Head CNC.cls”) using the parameters of the head tilt 45°/head rotary mill 5-axis machine as follows:

  • Distance from tool tip to the intersection of spindle axis and B-Axis: \(L=390mm\)

  • Inclination angle of axis B with respect to axis Y: \(\alpha =4{5}^{0}\)

  • \({y}_{H}=12.9287mm\)

4 Conclusion

This study has employed a novel approach to establish the relationship between machine coordinates and workpiece coordinates for B-head rotary tilting, C-table rotary 5-axis CNC milling machines type and B-head rotary tilting, and C-head rotary 5-axis CNC milling machines type. The postprocessor software allows the establishment of the machining coordinate system at any position on the machine table, not necessarily on the rotational axis; this function facilitates the setting of workpieces for machining to be more straightforward, as the requirement for accurately positioning the workpiece on the machine table center (virtual datum) poses difficulties for the operator. Using this method, the postprocessor can be developed for different configurations of 5-axis CNC machines by substituting values in the matrices \(\left[{A}_{1}\right],\left[{A}_{2}\right]\). Furthermore, the approach employed in this study allows for the straightforward incorporation of additional parameters affecting the accuracy of toolpath generation. These parameters include factors such as the non-intersection of the spindle and axis B, as well as evaluating the impact of errors in the tilt angle of axis B on the overall accuracy of the toolpath. This approach can also be applied to developing kinematics for industrial robots with more than 5 degrees of freedom. We will continue to explore this research direction in future studies.