1. Introduction
Coordinated multiaxis CNC machine tools controlled with LinuxCNC, require a special kinematics component for each type of machine. This chapter describes some of the most popular 5axis machine configurations and then develops the forward (from work to joint coordinates) and inverse (from joint to work) transformations in a general mathematical process for two types of machine.
The kinematics components are given as well as vismach simulation models to demonstrate their behaviour on a computer screen. Examples of HAL file data are also given.
Note that with these kinematics, the rotational axes move in the opposite direction of what the convention is. See section ["rotational axes"](https://linuxcnc.org/docs/html/gcode/machiningcenter.html#_rotational_axes) for details.
2. 5Axis Machine Tool Configurations
In this section we deal with the typical 5axis milling or router machines with five joints or degreesoffreedom which are controlled in coordinated moves.
3axis machine tools cannot change the tool orientation, so 5axis machine tools use two extra axes to set the cutting tool in an appropriate orientation for efficient machining of freeform surfaces.
Typical 5axis machine tool configurations are shown in Figs. 3, 5, 7 and 911 [1,2] in section Figures.
The kinematics of 5axes machine tools are much simpler than that of 6axis serial arm robots, since 3 of the axes are normally linear axes and only two are rotational axes.
3. Tool Orientation and Location
CAD/CAM systems are typically used to generate the 3D CAD models of the workpiece as well as the CAM data for input to the CNC 5axis machine. The tool or cutter location (CL) data, is composed of the cutter tip position and the cutter orientation relative to the workpiece coordinate system. Two vectors, as generated by most CAM systems and shown in Fig. 1, contain this information:
The K vector is equivalent to the 3rd vector from the pose matrix E_{6} that was used in the 6axis robot kinematics [3] and the Q vector is equivalent to the 4th vector of E_{6}. In MASTERCAM for example this information is contained in the intermediate output ".nci" file.
4. Translation and Rotation Matrices
Homogeneous transformations provide a simple way to describe the mathematics of multiaxis machine kinematics. A transformation of the space H is a 4x4 matrix and can represent translation and rotation transformations. Given a point x,y,x described by a vector u = {x,y,z,1}^{T}, then its transformation v is represented by the matrix product
There are four fundamental transformation matrices on which 5axis kinematics can be based:
The matrix T(a,b,c) implies a translation in the X, Y, Z coordinate directions by the amounts a, b, c respectively. The R matrices imply rotations of the angle theta about the X, Y and Z coordinate axes respectively. The C and S symbols refer to cosine and sine functions respectively.
5. Table Rotary/Tilting 5Axis Configurations
In these machine tools the two rotational axes mount on the work table of the machine. Two forms are typically used:

A rotary table which rotates about the vertical Zaxes (Crotation, secondary) mounted on a tilting table which rotates about the X or Yaxis (A or Brotation, primary). The workpiece is mounted on the rotary table.

A tilting table which rotates about the X or Yaxis (A or Brotation, secondary) is mounted on a rotary table which rotates about the Zaxis (Crotation, primary), with the workpiece on the tilting table.
A multiaxis machine can be considered to consist of a series of links connected by joints. By embedding a coordinate frame in each link of the machine and using homogeneous transformations, we can describe the relative position and orientation between these coordinate frames
We need to describe a relationship between the workpiece coordinate system and the tool coordinate system. This can be defined by a transformation matrix ^{w}A_{t}, which can be found by subsequent transformations between the different structural elements or links of the machine, each with its own defined coordinate system. In general such a transformation may look as follows:
where each matrix ^{i1}A_{j} is a translation matrix T or a rotation matrix R of the form (2,3).
Matrix multiplication is a simple process in which the elements of each row of the lefthand matrix A is multiplied by the elements of each column of the righthand matrix B and summed to obtain an element in the result matrix C, ie.
In Fig. 2 a generic configuration with coordinate systems is shown [4]. It includes table rotary/tilting axes as well as spindle rotary/tilting axes. Only two of the rotary axes are actually used in a machine tool.
First we will develop the transformations for the first type of configuration mentioned above, ie. a table tilting/rotary (trt) type with no rotating axis offsets. We may give it the name xyzactrt configuration.
We also develop the transformations for the same type (xyzactrt), but with rotating axis offsets.
Then we develop the transformations for a xyzbctrt configuration with rotating axis offsets.
5.1. Transformations for a xyzactrt machine tool with work offsets
We deal here with a simplified configuration in which the tilting axis and rotary axis intersects at a point called the pivot point as shown in Fig. 4. therefore the two coordinate systems O_{ws} and O_{wp} of Fig. 2 are coincident.
5.1.1. Forward transformation
The transformation can be defined by the sequential multiplication of the matrices:
with the matrices built up as follows:
In these equations L_{x}, L_{y}, L_{z} defines the offsets of the pivot point of the two rotary axes A and C relative to the workpiece coordinate system origin. Furthermore, P_{x}, P_{y}, P_{z} are the relative distances of the pivot point to the cutter tip position, which can also be called the "joint coordinates" of the pivot point. The pivot point is at the intersection of the two rotary axes. The signs of the S_{A} and S_{C} terms are different to those in [2,3] since there the table rotations are negative relative to the workpiece coordinate axes (note that sin(theta) = sin(theta), cos(theta) = cos(theta)).
When multiplied in accordance with (5), we obtain:
We can now equate the third column of this matrix with our given tool orientation vector K, ie.:
From these equations we can solve for the rotation angles theta_{A}, theta_{C}. From the third row we find:
and by dividing the first row by the second row we find:
These relationships are typically used in the CAM postprocessor to convert the tool orientation vectors to rotation angles.
Equating the last column of (8) with the tool position vector Q, we can write:
The vector on the right hand side can also be written as the product of a matrix and a vector resulting in:
This can be expanded to give
which is the forward transformation of the kinematics.
5.1.2. Inverse Transformation
We can solve for P from equation (13) as P = (^{Q}A_{P})^{1} * Q. Noting that the square matrix is a homogeneous 4x4 matrix containing a rotation matrix R and translation vector q, for which the inverse can be written as:
where R^T is the transpose of R (rows and columns swappped). We therefore obtain:
The desired equations for the inverse transformation of the kinematics thus can be written as:
5.2. Transformations for a xyzactrt machine with rotary axis offsets
We deal here with a extended configuration in which the tilting axis and rotary axis do not intersect at a point but have an offset D_{y}. Furthermore, there is also an zoffset between the two coordinate systems O_{ws} and O_{wp} of Fig. 2, called D_{z}. A vismach model is shown in Fig. 5 and the offsets are shown in Fig. 6 (positive offsets in this example). To simplify the configuration, the offsets L_{x}, L_{y}, L_{z} of the previous case are not included. They are probably not necessary if one uses the G54 offsets in LinuxCNC by means of the "touch of" facility.
5.2.1. Forward Transformation
The transformation can be defined by the sequential multiplication of the matrices:
with the matrices built up as follows:
In these equations D_{y}, D_{z} defines the offsets of the pivot point of the rotary axes A relative to the workpiece coordinate system origin. Furthermore, P_{x}, P_{y}, P_{z} are the relative distances of the pivot point to the cutter tip position, which can also be called the "joint coordinates" of the pivot point. The pivot point is on the A rotary axis.
When multiplied in accordance with (18), we obtain:
We can now equate the third column of this matrix with our given tool orientation vector K, ie.:
From these equations we can solve for the rotation angles theta_{A}, theta_{C}. From the third row we find:
and by dividing the second row by the first row we find:
These relationships are typically used in the CAM postprocessor to convert the tool orientation vectors to rotation angles.
Equating the last column of (21) with the tool position vector Q, we can write:
The vector on the right hand side can also be written as the product of a matrix and a vector resulting in:
which is the forward transformation of the kinematics.
5.2.2. Inverse Transformation
We can solve for P from equation (25) as P = (^{Q}A_{P})^{1} * Q using (15) as before. We thereby obtain:
The desired equations for the inverse transformation of the kinematics thus can be written as:
5.3. Transformations for a xyzbctrt machine with rotary axis offsets
We deal here again with a extended configuration in which the tilting axis (about the yaxis) and rotary axis do not intersect at a point but have an offset D_{x}. Furthermore, there is also an zoffset between the two coordinate systems O_{ws} and O_{wp} of Fig. 2, called D_{z}. A vismach model is shown in Fig. 7 (negative offsets in this example) and the positive offsets are shown in Fig. 8.
5.3.1. Forward Transformation
The transformation can be defined by the sequential multiplication of the matrices:
with the matrices built up as follows:
In these equations D_{x}, D_{z} defines the offsets of the pivot point of the rotary axes B relative to the workpiece coordinate system origin. Furthermore, P_{x}, P_{y}, P_{z} are the relative distances of the pivot point to the cutter tip position, which can also be called the "joint coordinates" of the pivot point. The pivot point is on the B rotary axis.
When multiplied in accordance with (29), we obtain:
We can now equate the third column of this matrix with our given tool orientation vector K, i.e.:
From these equations we can solve for the rotation angles theta_{B}, theta_{C}. From the third row we find:
and by dividing the second row by the first row we find:
These relationships are typically used in the CAM postprocessor to convert the tool orientation vectors to rotation angles.
Equating the last column of (32) with the tool position vector Q, we can write:
The vector on the right hand side can also be written as the product of a matrix and a vector resulting in:
which is the forward transformation of the kinematics.
5.3.2. Inverse Transformation
We can solve for P from equation (37) as P = (^{Q}A_{P})^{1} * Q.
With the same approach as before, we obtain:
The desired equations for the inverse transformation of the kinematics thus can be written as:
6. Table Rotary/Tilting Examples
LinuxCNC includes kinematics modules for the xyzactrt and xyzbctrt topologies described in the mathematics detailed above. For interested users, the source code is available in the git tree in the src/emc/kinematics/ directory.
Example xyzactrt and xyzbctrt simulation configurations are located in the Sample Configurations (configs/sim/axis/vismach/5axis/tablerotarytilting/) directory.
The example configurations include the required INI files and an examples subdirectory with Gcode (NGC) files. These sim configurations invoke a realistic 3dimensional model using the LinuxCNC vismach facility.
6.1. Vismach Simulation Models
Vismach is a library of python routines to display a dynamic simulation of a CNC machine on the PC screen. The python script for a particular machine is loaded in HAL and data passed by HAL pin connections. The nonrealtime vismach model is loaded by a HAL command like:
loadusr W xyzactrtgui
and connections are made using HAL commands like:
net :tablex joint.0.posfb xyzactrtgui.tablex
net :saddley joint.1.posfb xyzactrtgui.saddley
...
See the simulation INI files for details of the HAL connections used for the vismach model.
6.2. ToolLength Compensation
In order to use tools from a tool table sequentially with toollength compensation applied automatically, a further Zoffset is required. For a tool that is longer than the "master" tool, which typically has a tool length of zero, LinuxCNC has a variable called "motion.tooloffset.z". If this variable is passed on to the kinematic component (and vismach python script), then the necessary additional Zoffset for a new tool can be accounted for by adding the component statement, for example:
The required HAL connection (for xyzactrt) is:
net :tooloffset motion.tooloffset.z xyzactrtkins.tooloffset
where:
:tooloffset  signal name
motion.tooloffset.z  output HAL pin from LinuxCNC motion module
xyzactrtkins.tooloffset  input HAL pin to xyzactrtkins
7. Custom Kinematics Components
LinuxCNC implements kinematics using a HAL component that is loaded at startup of LinuxCNC. The most common kinematics module, trivkins, implements identity (trivial) kinematics where there is a onetoone correspondence between an axis coordinate letter and a motor joint. Additional kinematics modules for more complex systems (including xyzactrt and xyzbctrt described above) are available.
See the kins manpage (\$ man kins) for brief descriptions of the available kinematics modules.
The kinematics modules provided by LinuxCNC are typically written in the Clanguage. Since a standard structure is used, creation of a custom kinematics module is facilitated by copying an existing source file to a user file with a new name, modifying it, and then installing.
Installation is done using halcompile:
sudo halcompile install kinsname.c
where "kinsname" is the name you give to your component. The sudo prefix is required to install it and you will be asked for your root password. See the halcompile man page for more information (\$ man halcompile)
Once it is compiled and installed you can reference it in your config setup of your machine. This is done in the INI file of your config directory. For example, the common INI specificaion:
[KINS] KINEMATICS = trivkins
is replaced by
[KINS] KINEMATICS = kinsname
where "kinsname" is the name of your kins program. Additional HAL pins may be created by the module for variable configuration items such as the D_{x}, D_{y}, D_{z}, tooloffset used in the xyzactrt kinematics module. These pins can be connected to a signal for dynamic control or set once with HAL connections like:
# set offset parameters net :tooloffset motion.tooloffset.z xyzactrtkins.tooloffset setp xyzactrtkins.yoffset 0 setp xyzactrtkins.zoffset 20
8. Figures
9. REFERENCES

AXIS MACHINE TOOLS: Kinematics and Vismach Implementation in LinuxCNC, RJ du Preez, SACNCCLUB, April 7, 2016.

A Postprocessor Based on the Kinematics Model for General FiveAxis machine Tools: CH She, RS Lee, J Manufacturing Processes, V2 N2, 2000.

NC Postprocessor for 5axis milling of tablerotating/tilting type: YH Jung, DW Lee, JS Kim, HS Mok, J Materials Processing Technology,130131 (2002) 641646.

3D 6DOF Serial Arm Robot Kinematics, RJ du Preez, SACNCCLUB, Dec. 5, 2013.

Design of a generic fiveaxis postprocessor based on generalized kinematics model of machine tool: CH She, CC Chang, Int. J Machine Tools & Manufacture, 47 (2007) 537545.