*-----------------------------------------------------------------------------
*  Touch Probe
*-----------------------------------------------------------------------------
*  Module Description
*
*  - A touch Probe is activated by a TOOL CALL. In this case the #Bit 0
*    of the PLC status (tool table) must be set (%00000001).
*  - The battery-free TS444 touch probe is supported.
*
*-----------------------------------------------------------------------------

#define /s    KL_TS640                                 K +2
#define /s    KL_TS444                                 K +3

#define /s    ML_TSxxx_compressed_air_blocked          M
#define /s    ML_TS444_initialize                      M

#include Mac_Lib.inc

GLOBAL Touch_probe

;----------------------------
LBL Touch_probe

  L      NP_M4060_tool_measurement_active
  R      NP_M4055_touch_probe_start_0_active

  L      NP_M4062_tool_wear_tolerance_exceeded
  O      NP_M4063_tool_breakage_tolerance_exceeded
  S      PN_error_tool_tolerance
*$WS
  IFT
    R      NP_M4062_tool_wear_tolerance_exceeded
    R      NP_M4063_tool_breakage_tolerance_exceeded
  ENDI

  L      PN_error_touch_probe_not_in_spindle
  R      NP_M4055_touch_probe_start_0_active

  L      NP_M4055_touch_probe_start_0_active
  AN     MG_touch_probe_active
  S      PN_error_touch_probe_not_in_spindle

  L      MG_M16_TSxxx_blow_off
  AN     MG_touch_probe_active
  S      PN_error_M_function_not_used

  LN     MG_touch_probe_active
  R      PN_M4056_NC_stop_stylus_deflected
  EMT

; Load TS444 by compressed air, Blow off chips

  L      BG_MP6010_touch_probe_type
  ==     KL_TS444
  IFT
    L      NP_M4050_touch_probe_not_ready
    A      MG_pulse_CE_key
    O      PN_M4093_quit_TOOL_CALL
    ON     I_ESA_control_operational
    S      ML_TS444_initialize
  ENDI

  LN     NP_M4073_strobe_TOOL_CALL
  IFT
    L      MG_M16_TSxxx_blow_off
    S      PN_M4092_quit_M_function

    LN     TR_TSxxx_blow_off
    A      O_spindle_blow_clean
    ON     I_ESA_control_operational
    R      MG_SK_blow_off
    R      O_spindle_blow_clean

    L      BG_MP6010_touch_probe_type
    ==     KL_TS444
    A      NP_M4054_Probe_DC_supply_too_low
    O      ML_TS444_initialize
    O      MG_M16_TSxxx_blow_off
    O[
      L      MG_SK_blow_off
      AN     O_spindle_blow_clean
    ]
    AN     ML_TSxxx_compressed_air_blocked
    =      TS_TSxxx_blow_off
    R      ML_TS444_initialize
    S      MG_SK_blow_off
    S      O_spindle_blow_clean

    L      NP_M4055_touch_probe_start_0_active
    AN     O_spindle_blow_clean
    R      NP_M4055_touch_probe_start_0_active
    S      ML_TSxxx_compressed_air_blocked

    L      NP_M4053_touch_probe_end_stop
    ON     I_ESA_control_operational
    R      ML_TSxxx_compressed_air_blocked
  ENDI

; Switch on infrared touch probe besides TS640

  L      MG_pulse_CE_key
  O      NP_M4073_strobe_TOOL_CALL
  A      NP_M4050_touch_probe_not_ready
  IFT
    L      BG_MP6010_touch_probe_type
    <>     KL_TS640
    IFT
      CM     9135
      M_display_module_error
    ENDI
  ENDI

  LN     NP_M4073_strobe_TOOL_CALL
  AN     NP_M4520_TOOL_CALL_2nd_strobe
  =      PN_M4056_NC_stop_stylus_deflected

; Relieve touch probe by NC start key if not ready

  L      NP_M4050_touch_probe_not_ready
  A      MG_manual_mode
  A      MG_key_NC_start
  R      PN_M4056_NC_stop_stylus_deflected

; Error not permitted functions

  L      MG_M03_spindle_right_cw_on
  O      MG_M04_spindle_left_ccw_on
  O      MG_M13_Spindle_right_coolant_on
  O      MG_M14_Spindle_left_coolant_on
  O      MG_key_spindle_M3
  O      MG_key_spindle_M4
  S      PN_error_touch_probe_in_spindle

EM
