*-----------------------------------------------------------------------------
*  Reference
*-----------------------------------------------------------------------------
*  Module Description
*    - by key NC Start all axes are traversed reference in the order defined
*      in MP1340
*    - after traverse reference the PLC positioning to a safe position will
*      be started, if configured in *.cfg
*    - if DCM active, a PLC positioning will be started after a second safty
*      safety confirmation (error message) by key NC Start is done
*    - optional (*.cfg) the traverse reference of the next axis will be
*      started automatically
*
*     additional function
*       - if a PLC positioning in CFG_posit_safe_after_reference activated
*         and interrupted, the following reference positioning can only
*         be done manual by axes jog keys
*       - Test nonvoletile memory, if not initialized, traverse reference can
*         only be done manual by axes jog keys
*       - error messages display always the axis which has to be traversed
*       - Hirth axes can be traversed to the next increment, if the autostart
*         function was interrupted
*
*-----------------------------------------------------------------------------

#define /s    KL_absolute_with_soft_limit_no_DCM       K %1010
#define /s    KL_absolute_with_software_limit_switch   K %010
#define /s    KL_inactive                              K +0
#define /s    KL_memory_non_volatile_test_value        K %01010101
#define /s    KL_not_used                              K +0
#define /s    KL_PLC_posit_started                     K +2
#define /s    KL_target_position_reached               K +1
#define /s    KL_mode_procent_rated_current            K +0

#define /s    ML_PLC_posit_active                      M
#define /s    ML_control_loop_open                     M
#define /s    ML_axes_torque_limited                   M
#define /s    KL_start_posit_safe                      M
#define /s    ML_PLC_posit_started                     M
#define /s    ML_target_position_reached               M

#define /s /r BL_memory_non_volatile_initial           B
#define /s    BL_Case_reference                        B
#define /s    BL_axis_index                            B

#define /s    DL_reference_has_been_necessary          D

#include Mac_Lib.inc

GLOBAL Reference_axes

;----------------------------
LBL Reference_axes
;----------------------------

#if (KG_reference_end_position_software & %000000000000000001) = %000000000000000001
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_X
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_X
    IFT
      L      DG_position_axis_X_ref
      -      DG_MP960_ref_preset_X
      PSW
    ELSE
      PS     DG_position_axis_X_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_X
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_X
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_X
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000000000000010) = %000000000000000010
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_Y
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_Y
    IFT
      L      DG_position_axis_Y_ref
      -      DG_MP960_ref_preset_Y
      PSW
    ELSE
      PS     DG_position_axis_Y_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_Y
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_Y
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_Y
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000000000000100) = %000000000000000100
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_Z
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_Z
    IFT
      L      DG_position_axis_Z_ref
      -      DG_MP960_ref_preset_Z
      PSW
    ELSE
      PS     DG_position_axis_Z_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_Z
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_Z
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_Z
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000000000001000) = %000000000000001000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_4
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_4
    IFT
      L      DG_position_axis_4_ref
      -      DG_MP960_ref_preset_4
      PSW
    ELSE
      PS     DG_position_axis_4_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_4
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_4
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_4
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000000000010000) = %000000000000010000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_5
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_5
    IFT
      L      DG_position_axis_5_ref
      -      DG_MP960_ref_preset_5
      PSW
    ELSE
      PS     DG_position_axis_5_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_5
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_5
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_5
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000000000100000) = %000000000000100000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_6
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_6
    IFT
      L      DG_position_axis_6_ref
      -      DG_MP960_ref_preset_6
      PSW
    ELSE
      PS     DG_position_axis_6_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_6
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_6
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_6
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000000001000000) = %000000000001000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_7
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_7
    IFT
      L      DG_position_axis_7_ref
      -      DG_MP960_ref_preset_7
      PSW
    ELSE
      PS     DG_position_axis_7_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_7
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_7
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_7
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000000010000000) = %000000000010000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_8
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_8
    IFT
      L      DG_position_axis_8_ref
      -      DG_MP960_ref_preset_8
      PSW
    ELSE
      PS     DG_position_axis_8_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_8
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_8
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_8
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000000100000000) = %000000000100000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_9
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_9
    IFT
      L      DG_position_axis_9_ref
      -      DG_MP960_ref_preset_9
      PSW
    ELSE
      PS     DG_position_axis_9_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_9
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_9
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_9
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000001000000000) = %000000001000000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_10
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_10
    IFT
      L      DG_position_axis_10_ref
      -      DG_MP960_ref_preset_10
      PSW
    ELSE
      PS     DG_position_axis_10_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_10
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_10
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_10
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000010000000000) = %000000010000000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_11
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_11
    IFT
      L      DG_position_axis_11_ref
      -      DG_MP960_ref_preset_11
      PSW
    ELSE
      PS     DG_position_axis_11_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_11
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_11
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_11
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000100000000000) = %000000100000000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_12
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_12
    IFT
      L      DG_position_axis_12_ref
      -      DG_MP960_ref_preset_12
      PSW
    ELSE
      PS     DG_position_axis_12_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_12
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_12
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_12
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000001000000000000) = %000001000000000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_13
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_13
    IFT
      L      DG_position_axis_13_ref
      -      DG_MP960_ref_preset_13
      PSW
    ELSE
      PS     DG_position_axis_13_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_13
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_13
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_13
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000010000000000000) = %000010000000000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_14
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_14
    IFT
      L      DG_position_axis_14_ref
      -      DG_MP960_ref_preset_14
      PSW
    ELSE
      PS     DG_position_axis_14_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_14
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_14
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_14
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000100000000000000) = %000100000000000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_15
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_15
    IFT
      L      DG_position_axis_15_ref
      -      DG_MP960_ref_preset_15
      PSW
    ELSE
      PS     DG_position_axis_15_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_15
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_15
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_15
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %001000000000000000) = %001000000000000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_16
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_16
    IFT
      L      DG_position_axis_16_ref
      -      DG_MP960_ref_preset_16
      PSW
    ELSE
      PS     DG_position_axis_16_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_16
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_16
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_16
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %010000000000000000) = %010000000000000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_17
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_17
    IFT
      L      DG_position_axis_17_ref
      -      DG_MP960_ref_preset_17
      PSW
    ELSE
      PS     DG_position_axis_17_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_17
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_17
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_17
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %100000000000000000) = %100000000000000000
  LN     NP_D1116_reference_nesessary
  BT     KG_axis_18
  IFT
    L      DG_axis_encoder_one_reference_mark
    BT     KG_axis_18
    IFT
      L      DG_position_axis_18_ref
      -      DG_MP960_ref_preset_18
      PSW
    ELSE
      PS     DG_position_axis_18_ref
    ENDI

    L      DG_MP1320_direction_traverse_ref_negative
    BT     KG_axis_18
    IFT
      PLW
      <      K+0
      =      MG_ref_end_position_18
    ELSE
      PLW
      >      K+0
      =      MG_ref_end_position_18
    ENDI
  ENDI
#endif

#if (KG_reference_end_position_software & %000000000000000001) = 0
  LN     I_not_ref_end_posit_X
  =      MG_ref_end_position_X
#endif

#if (KG_reference_end_position_software & %000000000000000010) = 0
  LN     I_not_ref_end_posit_Y
  =      MG_ref_end_position_Y
#endif

#if (KG_reference_end_position_software & %000000000000000100) = 0
  LN     I_not_ref_end_posit_Z
  =      MG_ref_end_position_Z
#endif

#if (KG_reference_end_position_software & %000000000000001000) = 0
  LN     I_not_ref_end_posit_4
  =      MG_ref_end_position_4
#endif

#if (KG_reference_end_position_software & %000000000000010000) = 0
  LN     I_not_ref_end_posit_5
  =      MG_ref_end_position_5
#endif

#if (KG_reference_end_position_software & %000000000000100000) = 0
  LN     I_not_ref_end_posit_6
  =      MG_ref_end_position_6
#endif

#if (KG_reference_end_position_software & %000000000001000000) = 0
  LN     I_not_ref_end_posit_7
  =      MG_ref_end_position_7
#endif

#if (KG_reference_end_position_software & %000000000010000000) = 0
  LN     I_not_ref_end_posit_8
  =      MG_ref_end_position_8
#endif

#if (KG_reference_end_position_software & %000000000100000000) = 0
  LN     I_not_ref_end_posit_9
  =      MG_ref_end_position_9
#endif

#if (KG_reference_end_position_software & %000000001000000000) = 0
  LN     I_not_ref_end_posit_10
  =      MG_ref_end_position_10
#endif

#if (KG_reference_end_position_software & %000000010000000000) = 0
  LN     I_not_ref_end_posit_11
  =      MG_ref_end_position_11
#endif

#if (KG_reference_end_position_software & %000000100000000000) = 0
  LN     I_not_ref_end_posit_12
  =      MG_ref_end_position_12
#endif

#if (KG_reference_end_position_software & %000001000000000000) = 0
  LN     I_not_ref_end_posit_13
  =      MG_ref_end_position_13
#endif

#if (KG_reference_end_position_software & %000010000000000000) = 0
  LN     I_not_ref_end_posit_14
  =      MG_ref_end_position_14
#endif

#if (KG_reference_end_position_software & %000100000000000000) = 0
  LN     I_not_ref_end_posit_15
  =      MG_ref_end_position_15
#endif

#if (KG_reference_end_position_software & %001000000000000000) = 0
  LN     I_not_ref_end_posit_16
  =      MG_ref_end_position_16
#endif

#if (KG_reference_end_position_software & %010000000000000000) = 0
  LN     I_not_ref_end_posit_17
  =      MG_ref_end_position_17
#endif

#if (KG_reference_end_position_software & %100000000000000000) = 0
  LN     I_not_ref_end_posit_18
  =      MG_ref_end_position_18
#endif

  L      MG_reference_axes_traversed
  AN     MG_reference_active
  AN     MG_reference_auto_NC_start_blocked
  R      MG_manual_motion_in_reference_mode
  EMT

  L      NP_D1116_reference_nesessary
  O      DG_axes_reference_pos_safe
  AN     DG_PLC_axes
  AN     DG_MP12_simulated_axes
  ==     K+0
  R      MG_reference_auto_NC_start_blocked

  LD     MG_ref_end_positions
  =      PN_D1160_reference_end_position

;Special functions

  L      PN_D1144_manual_motion_plus
  O      PN_D1148_manual_motion_minus
  >      K+0
  =      MG_manual_motion_in_reference_mode
  R      PN_error_reference_timeout
  R      PN_error_reference_NC_start

  L      NP_D1116_reference_nesessary
  A      DG_controlled_axes
  AN     DG_MP12_simulated_axes
  ==     K+0
  A      MG_machine_parameter_are_read
  IFT
    R      MG_reference_auto_NC_start_blocked

    L      KL_memory_non_volatile_test_value
    =      BL_memory_non_volatile_initial

    L      MG_manual_motion_in_reference_mode
    JPT    Ref_reset
  ENDI

  L      BL_memory_non_volatile_initial
  <>     KL_memory_non_volatile_test_value
  A[
    L      KG_reference_end_position_software
    <>     KL_inactive
  ]
  A      NP_M4172_1st_PLC_run_after_power_on
  S      MG_reference_auto_NC_start_blocked

  L      MG_reference_auto_NC_start_blocked
  A      MG_key_NC_start
  S      PN_error_reference_NC_start

  L      MG_reference_auto_NC_start_blocked
  EMT

  CASE   BL_Case_reference
    CM     Reference_reached           ;00
    CM     NC_start_DCM                ;01
    CM     Start_posit_safe            ;02
    CM     In_posit_safe               ;03
    CM     Ref_autostart               ;04
    CM     Ref_end                     ;05
  ENDC

  PLL
  IFT
    INC    BL_Case_reference
  ENDI

  LN     MG_control_operational
  CMT    Ref_reset

EM

;----------------------------
LBL Reference_reached                  ;00

  L      MG_key_NC_start_p_pulse
  S      MG_reference_active

  LN     MG_manual_motion_in_reference_mode
  A      MG_power_delayed_on
  A      MG_axes_in_motion
  IFT
    LN     NP_D1116_reference_nesessary
    A      DL_reference_has_been_necessary
    A      DG_controlled_axes
    AN     DG_slave_axes
    AN     DG_MP12_simulated_axes
    =      DG_axes_reference_pos_safe
  ENDI

  L      DG_axes_reference_pos_safe
  <>     K+0
  AN     MG_reference_auto_NC_start_blocked
  A      MG_reference_active
  S      MG_start_blocked_reference
  PSL
  IFT
    L      K-1
    =      BL_axis_index

    REPEAT
      INC    BL_axis_index
      L      DG_axes_reference_pos_safe
      BT     BL_axis_index
    UNTILT
  ENDI

  L      NP_D1116_reference_nesessary
  =      DL_reference_has_been_necessary

EM

;----------------------------
LBL NC_start_DCM                       ;01

  L      DG_axes_reference_pos_safe
  A      KG_posit_safe_after_reference
  AN     DG_PLC_axes
  <>     K+0
  =      KL_start_posit_safe
  IFF
    L      K+0
    =      DG_axes_reference_pos_safe
  ENDI

  L      MG_key_NC_start_p_pulse
  A      PN_error_DCM_not_yet_active
  O[
    L      NP_D1116_reference_nesessary
    AN     DG_MP12_simulated_axes
    ==     KL_inactive
  ]
  O[
    L      DG_axes_reference_pos_safe
    ==     DG_S_axis_activation
  ]
  ON     MG_DCM_active
  ON     KL_start_posit_safe
  A      MG_axes_in_position
  R      PN_error_DCM_not_yet_active
  PSL
  EMT

  L      NP_D1116_reference_nesessary
  AN     DG_MP12_simulated_axes
  <>     KL_inactive
  A[
    L      DG_axes_reference_pos_safe
    <>     DG_S_axis_activation
  ]
  A      MG_DCM_active
  A      KL_start_posit_safe
  S      PN_error_DCM_not_yet_active
  IFT
    PS     K &PN_error_DCM_not_yet_active - 4800
    L      BL_axis_index
    +      K &SG_identifier_axis_1
    PSW
    L      BL_axis_index
    +      K+1
    PSW
    PS     KL_not_used
    CM     9084
  ENDI

  L      MG_key_NC_stop_p_pulse
  O      MG_manual_motion_in_reference_mode
  A      PN_error_DCM_not_yet_active
  S      MG_reference_auto_NC_start_blocked
  R      PN_error_DCM_not_yet_active
  JPT    Ref_reset

EM

;----------------------------
LBL Start_posit_safe                   ;02

  L      MG_marker_one
  =      TS_reference_timeout
  PSL

  LN     KL_start_posit_safe
  EMT

  PS     BL_axis_index
  PS     DG_posit_after_ref_X[BL_axis_index]
  PS     WG_MP1330_feed_X_ref[BL_axis_index]

  L      MG_DCM_active
  IFT
    PS     KL_absolute_with_soft_limit_no_DCM
  ELSE
    PS     KL_absolute_with_software_limit_switch
  ENDI

  CM     9221
  PLX
  M_display_module_error

EM

;----------------------------
LBL In_posit_safe                      ;03

  LN     KL_start_posit_safe
  IFT
    PS     MG_marker_one
  ELSE
    L      K+0
    =      DG_axes_reference_pos_safe

    PS     BL_axis_index
    CM     9222
    PLW
    PSW
    ==     KL_PLC_posit_started
    =      ML_PLC_posit_started

    PLW
    ==     KL_target_position_reached
    =      ML_target_position_reached
    PSL

    M_display_module_error

    L      MG_key_NC_start_p_pulse
    AN     ML_PLC_posit_started
    R      PN_error_reference_timeout
    =      TS_reference_timeout
    IFT
      DEC    BL_Case_reference
    ENDI

    L      MG_key_NC_stop_p_pulse
    O      MG_manual_motion_in_reference_mode
    A      PN_error_reference_timeout
    R      PN_error_reference_timeout
    S      MG_reference_auto_NC_start_blocked
    JPT    Ref_reset

    LN     TR_reference_timeout
    O      MG_key_NC_stop_p_pulse
    S      PN_error_reference_timeout
    IFT
      PS     K &PN_error_reference_timeout - 4800
      L      BL_axis_index
      +      K &SG_identifier_axis_1
      PSW
      L      BL_axis_index
      +      K+1
      PSW
      PS     KL_not_used
      CM     9084
    ENDI
  ENDI

EM

;----------------------------
LBL Ref_autostart                      ;04

  PS     MG_marker_one

  L      NP_M4155_mode_pass_over_reference
  AN     MG_ref_autostart_inactive
  AN     MG_reference_auto_NC_start_blocked
  R      MG_start_blocked_reference
  =      MG_NC_start_from_reference

EM

;----------------------------
LBL Ref_end

  PS     MG_marker_zero

;----------------------------
LBL Ref_reset

  L      NP_D1116_reference_nesessary
  AN     DG_MP12_simulated_axes
  AN     DG_slave_axes
  ==     K+0
  O      MG_reference_auto_NC_start_blocked
  R      MG_reference_active

  L      MG_marker_one
  R      MG_start_blocked_reference
  R      MG_NC_start_from_reference
  R      KL_start_posit_safe
  R      MG_manual_motion_in_reference_mode

  L      K+0
  =      BL_Case_reference
  =      DG_axes_reference_pos_safe

EM

*$WS
;  L      NP_D1116_reference_nesessary
;  >      DG_PLC_reference_necessary
;  AN     ML_axes_torque_limited
;  IFT
;    S     ML_axes_torque_limited
;    L      K+0
;    =X
;    REPEAT
;      KL_mode_procent_rated_current
;      PSX
;      PS     DG_torque_limited_X[X]
;      CM     9128
;       M_display_module_error
;
;      INCX
;      LX
;      >=     KG_max_number_axes
;    UNTILT
;  ENDI


*$WS
;  L      NP_D1116_reference_nesessary
;  O      DG_PLC_reference_necessary
;  ==     K+0
;  IFT
;    R     ML_axes_torque_limited
;
;    L      K+0
;    =X
;    REPEAT
;      KL_mode_procent_rated_current
;      PSX
;      PS     KL_limitation_off
;      CM     9128
;       M_display_module_error
;      INCX
;      LX
;      >=     KG_max_number_axes
;    UNTILT
;  ENDI

