Building your own tilt cycle – rotation matrices in NC macros

Build a custom tilt cycle without G68.2 or PLANE SPATIAL: read work offsets via macro variables and compute the shifted zero point with rotation matrices.

On machines where a rotary/tilt table has been retrofitted, the control often provides no tilt cycle such as G68.2 or PLANE SPATIAL. This means that for every tilted position, a zero point has to be probed manually and entered into the offset table. The procedure is cumbersome and error-prone: setup time and scrap rates increase because – at a compound angle, for example – a correction can only be made after machining.

A custom tilt cycle, however, can be built with the control’s own resources – macro variables and a little linear algebra.

Procedure

Computing the zero point after the rotation requires a few pieces of information; from these, the new position is then calculated using linear algebra.

The procedure looks like this:

  1. Read the active work offset (part zero in machine coordinates)
  2. Determine the rotation center of the tilting device
  3. Compute the position of the part zero point relative to the rotation center of the rotary axes
  4. Compute the position after the rotation relative to the rotation center of the rotary axes
  5. Compute the new position relative to the machine zero point
  6. Write the new position as the part zero point
  7. Activate the new part zero point

Part zero point relative to the rotation center

First, the part zero point is expressed relative to the rotation center of the rotary axes:

{POINT_X} = {PART_ZERO_X} - {ROTATION_CENTER_X}
{POINT_Y} = {PART_ZERO_Y} - {ROTATION_CENTER_Y}
{POINT_Z} = {PART_ZERO_Z} - {ROTATION_CENTER_Z}
Determine the exact rotation center

The example uses an arbitrary value for the position of the rotation center. You must determine the exact rotation center to achieve the best possible accuracy.

Adapted to Fanuc macro language:

#21 = #5221 - [-200.5] (X)
#22 = #5222 - 333.56 (Y)
#23 = #5223 - 123.54 (Z)

The variables #5221, #5222 and #5223 contain the corresponding values from the offset table for the G54 work offset.

Reading the offsets can also be parameterized: if the work-offset number (54–59) is passed in #11, the address of the respective offset variable can be computed:

#21 = #[5221 + [[#11 - 54] * 20]] (X-VALUE)
#22 = #[5222 + [[#11 - 54] * 20]] (Y-VALUE)
#23 = #[5223 + [[#11 - 54] * 20]] (Z-VALUE)

Rotation about the C axis

The rotation about the Z axis (C axis) can be expressed by the following matrix:

RC(ϕ)=[cos(ϕ)sin(ϕ)0sin(ϕ)cos(ϕ)0001]R_C(\phi) = \begin{bmatrix} \cos(\phi) & -\sin(\phi) & 0 \\ \sin(\phi) & \cos(\phi) & 0 \\ 0 & 0 & 1 \end{bmatrix}

Adapted to Fanuc macro language – #3 holds the rotation angle, #4 to #6 the coordinates of the point before the rotation:

#14 = [#4 * COS[#3]] - [#5 * SIN[#3]] (X)
#15 = [#5 * COS[#3]] + [#4 * SIN[#3]] (Y)
#16 = #6 (Z)

Rotation about the B axis

The rotation about the Y axis (B axis) is described analogously by this matrix:

RB(θ)=[cos(θ)0sin(θ)010sin(θ)0cos(θ)]R_B(\theta) = \begin{bmatrix} \cos(\theta) & 0 & \sin(\theta) \\ 0 & 1 & 0 \\ -\sin(\theta) & 0 & \cos(\theta) \end{bmatrix}

Here θ and φ are the rotation angles about the Y and Z axes respectively.

Combined rotation matrix

The combined rotation about both axes is obtained by multiplying the two individual rotation matrices:

R=RB(θ)RC(ϕ)=[cos(θ)0sin(θ)010sin(θ)0cos(θ)][cos(ϕ)sin(ϕ)0sin(ϕ)cos(ϕ)0001]=[cos(θ)cos(ϕ)cos(θ)sin(ϕ)sin(θ)sin(ϕ)cos(ϕ)0sin(θ)cos(ϕ)sin(θ)sin(ϕ)cos(θ)]\begin{aligned} R &= R_B(\theta)\,R_C(\phi) \\[6pt] &= \begin{bmatrix} \cos(\theta) & 0 & \sin(\theta) \\ 0 & 1 & 0 \\ -\sin(\theta) & 0 & \cos(\theta) \end{bmatrix} \begin{bmatrix} \cos(\phi) & -\sin(\phi) & 0 \\ \sin(\phi) & \cos(\phi) & 0 \\ 0 & 0 & 1 \end{bmatrix} \\[6pt] &= \begin{bmatrix} \cos(\theta)\cos(\phi) & -\cos(\theta)\sin(\phi) & \sin(\theta) \\ \sin(\phi) & \cos(\phi) & 0 \\ -\sin(\theta)\cos(\phi) & \sin(\theta)\sin(\phi) & \cos(\theta) \end{bmatrix} \end{aligned}

This combined rotation matrix is applied to the point P′ – the part zero point relative to the rotation center computed earlier:

P=RPP'' = R\,P'

Here P″ is the point after the rotation.

Check the sign of the angles

The sign of the angles depends on whether the rotary axis carries the table or the tool (see ISO 841). Test with a single known rotation before production use – a wrong sign shifts the zero point in the wrong direction.

Outlook

This completes the mathematical foundation. Writing the computed offsets back into the work-offset table, along with a complete macro listing, will follow in an update to this article.