# Distance control (sensed spindles) (DIST_CTRL)

## Release Note

The availability of this function depends on the configuration and on the version scope.

If the tool-supporting axis (spindle axis) is equipped with the necessary hardware, this function specifies the distance of the tool to an uneven workpiece surface. The distance is detected by a measuring system and is continuously tracked by the NC on the uneven surface.

The distance control for a sensed spindle is enabled by the parameter P-AXIS-00328. It is activated by the following NC command. For more information please refer to the functional description "Distance control” [FCT-M3]

Syntax for Select by specifying the position of the workpiece surface:
<axis_name> [DIST_CTRL ON | DRYRUN [ SET_POS=.. ] ]

Syntax for Select by specifying a constant distance to the workpiece surface:
<axis_name> [DIST_CTRL ON | DRYRUN CONST_DIST [ SET_DIST=.. ] ]

Syntax for Deselect or Freeze offset
<axis_name> [DIST_CTRL [ OFF [ NO_MOVE ] ] | FREEZE ]

Syntax for Test or reference sensor:
<axis_name> [DIST_CTRL CHECK_POS | REF ]

Optionally, the following parameters can also be programmed in combination with select/deselect:

Syntax for additional sensor parameters:
<axis_name> [DIST_CTRL [SENSOR_SOURCE=<ident> SENSOR_VAR=..] [ VAL1=.. - VAL5=.. ] { \ } ]

Syntax for additional control parameters:
<axis_name> [DIST_CTRL [ KP=.. ] [ I_TN=.. ] [ D_TV=.. ] { \ } ]

Syntax for additional parameters for smoothing sensor signal:
<axis_name> [DIST_CTRL [ FILTER_TYPE=.. ] [ N_CYCLES=.. ] [ FG_F0=.. ] [ ORDER=.. ] [ SMOOTH_FACT=.. ] [ KALMAN_SIGMA=.. ] { \ } ]

<axis_name> | Name of the axis supporting the tool.
DIST_CTRL | Identifier for the "Sensed spindles” function. Must always be programmed as the first keyword.
ON | Activate distance control specifying the position of the workpiece surface. A set position at activation must be set with SET_POS.
SET_POS=.. | Specify the position of the workpiece surface in [mm, inch] (absolute position). In the event of reset or program end, the parameter is reset, i.e. a new parameter must be specified before distance control is reactivated.
CONST_DIST | Activate distance control in combination with ON by specifying a constant distance to the workpiece surface. A distance must be set with SET_DIST at activation. [as of V2.11.2804.03]
SET_DIST=.. | Specify the constant distance to the workpiece surface in [mm, inch]. In the event of reset or program end, the distance is reset, i.e. a new distance must be specified before distance control is reactivated.
DRYRUN | In combination with ON, the axis is not tracked in DRYRUN mode when there are changes in the workpiece surface. This allows data to be evaluated without feedback from the controller (e.g. filter effect). [as of V3.1.3079.23] When distance control is activated specifying the position of the workpiece surface, a set position must be set with SET_POS.

When distance control is activated specifying a constant distance to the workpiece surface, a set distance must be set with SET_DIST.

OFF | Deactivate distance control.
NO_MOVE | By default, the resulting correction offset is executed when distance control is switched off. This motion can be suppressed by specifying NO_MOVE in combination with OFF. The channel is initialised with the changed axis position. The position offset is only executed at the next axis motion programmed in the NC program.
FREEZE | Freeze the compensated control distance across the workpiece. The axis position or the output compensation value is maintained. Axis tracking is interrupted.
CHECK_POS | Check whether position is within the tolerance window.
REF | Reference measuring system (sensor) (only if there is no absolute measuring system).
SENSOR_SOURCE=<ident> | Specify the source of the sensor signal [as of V3.1.3080.12 or V3.1.3107.45]. The following sources can be set for channel-specific distance control. Valid identifiers: DEFAULT: IF “DEFAULT” is selected as the sensor source, the CNC automatically sets to the “SECOND_ENCODER” sensor source internally.

VARIABLE: The sensor signal is transferred to the CNC by a V.E. variable. In addition, the name of the V.E. variable must also be specified by the parameter “SENSOR_VAR”.

SECOND_ENCODER: Make sure that the first configured encoder (Signal for main encoder (P-AXIS-00823)) is used for axis position control and the second encoder (Signal for secondary encoder (P-AXIS-00824)) for distance control.

SENSOR_VAR=.. | Name of the V.E. variable which transfers the sensor signal to the CNC. [as of V3.1.3080.12 or V3.1.3107.45]
VAL1=..-VAL5=.. | Five freely assignable values in real format.
KP=.. | Weighting the distance control output values. Parameterisation can be executed analogous to P-AXIS-00759. The value range is limited to 0.0 < KP <= 2.0. For KP values less than 1.0, the distance control dynamics are reduced; for KP values greater than 1.0, the dynamics are increased.

A KP factor less than 1 reduces a possible distance control oscillation and steadies control in the event of minor distance errors. [as of V2.11.2809.06 or V3.1.3079.06]

I_TN=.. | Integral action time of the PID controller in [s]. The integral action time defines the time after which the P and I components of the manipulated variable are equal. Parameterisation can be executed analogous to P-AXIS-00764. The value range is limited to 0.0 <= I_TN <= 50.0. A large integral action time produces greater control stability. The shorter the integration action time, the greater the I component and the faster the control. A short integral action time excites oscillations more strongly. [as of V2.11.2809.06 or V3.1.3079.06]
D_TV=.. | Derivative action time of the PID controller in [s]. The derivative action time defines the time after which the P and D components of the manipulated variable are equal. Parameterisation can be executed analogous to P-AXIS-00765. The value range is limited to 0.0 <= D_TV <= 2.0. The larger the derivative action time, the stronger the D component. [as of V2.11.2809.06 or V3.1.3079.06]
FILTER_TYPE=.. | Filter type to filter sensor values according to P-AXIS-00782. [as of V3.1.3079.23]
N_CYCLES=.. | Number the measured values used for filtering according to P-AXIS-00413. [as of V3.1.3079.23]
FG_F0=.. | Cut-off frequency for the low-pass filter in [Hz] according to P-AXIS-00508. [as of V3.1.3079.23]
ORDER=.. | Order of the low-pass filter according to P-AXIS-00507. [as of V3.1.3079.23]
SMOOTH_FACT=.. | Smoothing factor of the exponential averaging filter according to P-AXIS-00784. Specifies the weighting of the current measured value.
KALMAN_SIGMA=.. | Uncertainty of the included measured values according to P-AXIS-00783. [as of V3.1.3079.23]
\ | Separator ("backslash") for clear programming of the command over multiple lines.

## Notice

If distance control is still active at program end, it is not automatically deselected.

When a reset or axis error occurs, active distance control is always deselected automatically.

## Notice

Parameters of the PID controller are not reset at program end.

## Programing Example

Programming examples for distance control

%DIST_1

;Set expected position of the workpiece surface

N10 Z[DIST_CTRL SET_POS=30]

N20 Z[DIST_CTRL ON] ;Select

; …

Nxx Z[DIST_CTRL OFF] ;Deselect

N999 M30

%DIST_2

;Select + set expected position of the workpiece surface

N10 Z[DIST_CTRL ON SET_POS=30]

; …

Nxx Z[DIST_CTRL FREEZE] ;Hold position

; …

Nxx Z[DIST_CTRL OFF] ;Deselect

N999 M30

%DIST_3

;Select + set expected position of the workpiece surface

N10 Z[DIST_CTRL ON SET_POS=50]

;Deactivate distance control; Z axis does not move

Nxx Z[DIST_CTRL OFF NO_MOVE]

;The generated compensation offset is included for motion
;to the target point 100

Nxx G0 Z100

N999 M30

%DIST_4

;Set distance parameters

N10 Z[DIST_CTRL SET_POS=30]

;Select specifying the position of the workpiece surface (SET_POS)

N20 Z[DIST_CTRL ON]

; …

Nxx Z[DIST_CTRL OFF] ;Deselect

; …

;Select specifying the workpiece surface (SET_DIST)

Nxx Z[DIST_CTRL SET_DIST=10]

Nxx Z[DIST_CTRL ON CONST_DIST]

; …

Nxx Z[DIST_CTRL OFF] ;Deselect

N999 M30

%DIST_5

;Select filter type

N10Z[DIST_CTRL FILTER_TYPE=KALMAN_MA]

;Parametrise filter

N20 Z[DIST_CTRL N_CYCLES=30 KALMAN_SIGMA=1000]

;Check the filter effect on the sensor signal

N30 Z[DIST_CTRL DRYRUN]

;…

;Parameterise the PID controller

Nxx Z[DIST_CTRL KP=0.3 I_TN=0 D_TV=0.01]

;Activate distance control

Nxx Z[DIST_CTRL ON CONST_DIST SET_DIST=1]

; …

;Change filter

Nxx Z[DIST_CTRL FILTER_TYPE=KALMAN_EXPO SMOOTH_FACT=0.3]

; …

Nxx Z[DIST_CTRL OFF]; Deselect

N999 M30