*-----------------------------------------------------------------------------
*  Axes Control
*-----------------------------------------------------------------------------
*  Module Description
*  - Clamping mode
*     The clamping mode can be (de)activated with M11/M10 or FN19. In FN19
*     you can define on which axes the M-functions have an effect. The first
*     numerical value is the identifier; its value has to be +99991 if the
*     clamping mode is inactive, and +99990 for an active clamping mode.
*     The second numerical value serves to transfer the axes in bit-encoded
*     form. This value is non-volatile and is maintained until FN19 is output
*     again.
*     e.g.:
*     FN 19: PLC =+99991 / +24 -> Clamping mode in axes 4 and 5 inactive
*
*  - Module 9161 Controller enable of the internal current controller
*      Thus the current and speed controller of the drives are switched on.
*
*  - Module 9162 Read status of motor controller
*      After switching on the current and speed controllers, they must
*      first acknowledge readiness before the clamping can be released.
*
*  - Module 9157 Status interrogation of the drive hardware
*      Axes groups are wired via X15x or PL6xxx(HSCI - MP4132.x).
*      The PLC module 9157 returns the corresponding status.
*
*  - Module 9159 Advance warning for stopping the drives (clamping)
*      The axis brake can already be activated before the CC stops the
*      drives. The time between the braking signal and switch off the
*      controller or the time after switch-on can be optimized via
*      machine parameter MP2308 and MP2309.
*
*  - Module 9148 Position Display
*      Nominal instead of actual value may be activated for axes with Hirth
*      coupling and is active when the position controller was opened.
*      Actual value display, kinematics, datum setting refer to the nominal
*      value.
*
*  - Module 9146 Freeze/enable the axis position
*      Axes in the C axis mode or with central drive are assigned to the
*      common encoder.
*
*  - Module 9145: Automatic actual and nominal value transfer for certain
*      axes. When assembling tools and with inactive drive, the magazine can
*      be moved manually.
*
*  - Module 9169 Axis-specific input "Speed 0"
*      With one-channel wiring, magazine axis can be moved despite missing
*      drive release (I32=0).
*      -> not supported at NC-S 340490 06 anymore
*
*  - Module 9168 Read status for commissioning of the PWM controllers
*      Disable current controller commissioning axes.
*
*  - Module 9041 Read the axes coordinates (1/10000)
*      Test if in automatic operation with Hirth axes the target position is
*      within the grid.
*
*-----------------------------------------------------------------------------

#define /s    KL_distance_to_go                        K +4
#define /s    KL_handwheel_axis                        K +10
#define /s    KL_handwheel_axis_M118                   K +23
#define /s    KL_actual_value_fixed                    K +0
#define /s    KL_actual_value_released                 K +1
#define /s    KL_inactive                              K -1
#define /s    KL_active                                K +0
#define /s    KL_runtime_from_MP                       K -1
#define /s    KL_servo_drive_release_UM                K +0
#define /s    KL_servo_drive_release_axis_coded        K +2
#define /s    KL_servo_drive_release_input_level       K +3
#define /s    KL_mode_nominal_value_as_actual          K +0
#define /s    KL_PLC_posit_active                      K +2
#define /s    KL_PLC_posit_inactive                    K +0
#define /s    KL_mode_inactive                         K +0
#define /s    KL_hirth_axes_initialized                K +0
#define /s    KL_axis_active                           K -1
#define /s    KL_axis_not_controlled_asynchron_slave   K +2
#define /s    KL_axes_group_max_number                 K +6
#define /s    KL_commissioning_current_control         K +2

#define /s    ML_servo_drives_releases                 M[32]
#define /c    ML_X_servo_drive_release                 M &ML_servo_drives_releases + 0
#define /c    ML_Y_servo_drive_release                 M &ML_servo_drives_releases + 1
#define /c    ML_Z_servo_drive_release                 M &ML_servo_drives_releases + 2
#define /c    ML_4_servo_drive_release                 M &ML_servo_drives_releases + 3
#define /c    ML_5_servo_drive_release                 M &ML_servo_drives_releases + 4
#define /c    ML_6_servo_drive_release                 M &ML_servo_drives_releases + 5
#define /c    ML_7_servo_drive_release                 M &ML_servo_drives_releases + 6
#define /c    ML_8_servo_drive_release                 M &ML_servo_drives_releases + 7
#define /c    ML_9_servo_drive_release                 M &ML_servo_drives_releases + 8
#define /c    ML_10_servo_drive_release                M &ML_servo_drives_releases + 9
#define /c    ML_11_servo_drive_release                M &ML_servo_drives_releases + 10
#define /c    ML_12_servo_drive_release                M &ML_servo_drives_releases + 11
#define /c    ML_13_servo_drive_release                M &ML_servo_drives_releases + 12
#define /c    ML_14_servo_drive_release                M &ML_servo_drives_releases + 13
#define /c    ML_15_servo_drive_release                M &ML_servo_drives_releases + 14
#define /c    ML_16_servo_drive_release                M &ML_servo_drives_releases + 15
#define /c    ML_17_servo_drive_release                M &ML_servo_drives_releases + 16
#define /c    ML_18_servo_drive_release                M &ML_servo_drives_releases + 17

#define /s    ML_unclamping                            M[32]
#define /c    ML_unclamping_X                          M &ML_unclamping + 0
#define /c    ML_unclamping_Y                          M &ML_unclamping + 1
#define /c    ML_unclamping_Z                          M &ML_unclamping + 2
#define /c    ML_unclamping_4                          M &ML_unclamping + 3
#define /c    ML_unclamping_5                          M &ML_unclamping + 4
#define /c    ML_unclamping_6                          M &ML_unclamping + 5
#define /c    ML_unclamping_7                          M &ML_unclamping + 6
#define /c    ML_unclamping_8                          M &ML_unclamping + 7
#define /c    ML_unclamping_9                          M &ML_unclamping + 8
#define /c    ML_unclamping_10                         M &ML_unclamping + 9
#define /c    ML_unclamping_11                         M &ML_unclamping + 10
#define /c    ML_unclamping_12                         M &ML_unclamping + 11
#define /c    ML_unclamping_13                         M &ML_unclamping + 12
#define /c    ML_unclamping_14                         M &ML_unclamping + 13
#define /c    ML_unclamping_15                         M &ML_unclamping + 14
#define /c    ML_unclamping_16                         M &ML_unclamping + 15
#define /c    ML_unclamping_17                         M &ML_unclamping + 16
#define /c    ML_unclamping_18                         M &ML_unclamping + 17

#define /s    ML_clamped_axes                          M[32]
#define /c    ML_clamped_axis_X                        M &ML_clamped_axes + 0
#define /c    ML_clamped_axis_Y                        M &ML_clamped_axes + 1
#define /c    ML_clamped_axis_Z                        M &ML_clamped_axes + 2
#define /c    ML_clamped_axis_4                        M &ML_clamped_axes + 3
#define /c    ML_clamped_axis_5                        M &ML_clamped_axes + 4
#define /c    ML_clamped_axis_6                        M &ML_clamped_axes + 5
#define /c    ML_clamped_axis_7                        M &ML_clamped_axes + 6
#define /c    ML_clamped_axis_8                        M &ML_clamped_axes + 7
#define /c    ML_clamped_axis_9                        M &ML_clamped_axes + 8
#define /c    ML_clamped_axis_10                       M &ML_clamped_axes + 9
#define /c    ML_clamped_axis_11                       M &ML_clamped_axes + 10
#define /c    ML_clamped_axis_12                       M &ML_clamped_axes + 11
#define /c    ML_clamped_axis_13                       M &ML_clamped_axes + 12
#define /c    ML_clamped_axis_14                       M &ML_clamped_axes + 13
#define /c    ML_clamped_axis_15                       M &ML_clamped_axes + 14
#define /c    ML_clamped_axis_16                       M &ML_clamped_axes + 15
#define /c    ML_clamped_axis_17                       M &ML_clamped_axes + 16
#define /c    ML_clamped_axis_18                       M &ML_clamped_axes + 17

#define /s    ML_unclamped_axes                        M[32]
#define /c    ML_unclamped_axis_X                      M &ML_unclamped_axes + 0
#define /c    ML_unclamped_axis_Y                      M &ML_unclamped_axes + 1
#define /c    ML_unclamped_axis_Z                      M &ML_unclamped_axes + 2
#define /c    ML_unclamped_axis_4                      M &ML_unclamped_axes + 3
#define /c    ML_unclamped_axis_5                      M &ML_unclamped_axes + 4
#define /c    ML_unclamped_axis_6                      M &ML_unclamped_axes + 5
#define /c    ML_unclamped_axis_7                      M &ML_unclamped_axes + 6
#define /c    ML_unclamped_axis_8                      M &ML_unclamped_axes + 7
#define /c    ML_unclamped_axis_9                      M &ML_unclamped_axes + 8
#define /c    ML_unclamped_axis_10                     M &ML_unclamped_axes + 9
#define /c    ML_unclamped_axis_11                     M &ML_unclamped_axes + 10
#define /c    ML_unclamped_axis_12                     M &ML_unclamped_axes + 11
#define /c    ML_unclamped_axis_13                     M &ML_unclamped_axes + 12
#define /c    ML_unclamped_axis_14                     M &ML_unclamped_axes + 13
#define /c    ML_unclamped_axis_15                     M &ML_unclamped_axes + 14
#define /c    ML_unclamped_axis_16                     M &ML_unclamped_axes + 15
#define /c    ML_unclamped_axis_17                     M &ML_unclamped_axes + 16
#define /c    ML_unclamped_axis_18                     M &ML_unclamped_axes + 17

#define /s    ML_clamping_mode_on                      M[32]
#define /c    ML_clamping_mode_on_X                    M &ML_clamping_mode_on + 0
#define /c    ML_clamping_mode_on_Y                    M &ML_clamping_mode_on + 1
#define /c    ML_clamping_mode_on_Z                    M &ML_clamping_mode_on + 2
#define /c    ML_clamping_mode_on_4                    M &ML_clamping_mode_on + 3
#define /c    ML_clamping_mode_on_5                    M &ML_clamping_mode_on + 4
#define /c    ML_clamping_mode_on_6                    M &ML_clamping_mode_on + 5
#define /c    ML_clamping_mode_on_7                    M &ML_clamping_mode_on + 6
#define /c    ML_clamping_mode_on_8                    M &ML_clamping_mode_on + 7
#define /c    ML_clamping_mode_on_9                    M &ML_clamping_mode_on + 8
#define /c    ML_clamping_mode_on_10                   M &ML_clamping_mode_on + 9
#define /c    ML_clamping_mode_on_11                   M &ML_clamping_mode_on + 10
#define /c    ML_clamping_mode_on_12                   M &ML_clamping_mode_on + 11
#define /c    ML_clamping_mode_on_13                   M &ML_clamping_mode_on + 12
#define /c    ML_clamping_mode_on_14                   M &ML_clamping_mode_on + 13
#define /c    ML_clamping_mode_on_15                   M &ML_clamping_mode_on + 14
#define /c    ML_clamping_mode_on_16                   M &ML_clamping_mode_on + 15
#define /c    ML_clamping_mode_on_17                   M &ML_clamping_mode_on + 16
#define /c    ML_clamping_mode_on_18                   M &ML_clamping_mode_on + 17

#define /s    ML_clamping_mode_off                     M[32]
#define /c    ML_clamping_mode_off_X                   M &ML_clamping_mode_off + 0
#define /c    ML_clamping_mode_off_Y                   M &ML_clamping_mode_off + 1
#define /c    ML_clamping_mode_off_Z                   M &ML_clamping_mode_off + 2
#define /c    ML_clamping_mode_off_4                   M &ML_clamping_mode_off + 3
#define /c    ML_clamping_mode_off_5                   M &ML_clamping_mode_off + 4
#define /c    ML_clamping_mode_off_6                   M &ML_clamping_mode_off + 5
#define /c    ML_clamping_mode_off_7                   M &ML_clamping_mode_off + 6
#define /c    ML_clamping_mode_off_8                   M &ML_clamping_mode_off + 7
#define /c    ML_clamping_mode_off_9                   M &ML_clamping_mode_off + 8
#define /c    ML_clamping_mode_off_10                  M &ML_clamping_mode_off + 9
#define /c    ML_clamping_mode_off_11                  M &ML_clamping_mode_off + 10
#define /c    ML_clamping_mode_off_12                  M &ML_clamping_mode_off + 11
#define /c    ML_clamping_mode_off_13                  M &ML_clamping_mode_off + 12
#define /c    ML_clamping_mode_off_14                  M &ML_clamping_mode_off + 13
#define /c    ML_clamping_mode_off_15                  M &ML_clamping_mode_off + 14
#define /c    ML_clamping_mode_off_16                  M &ML_clamping_mode_off + 15
#define /c    ML_clamping_mode_off_17                  M &ML_clamping_mode_off + 16
#define /c    ML_clamping_mode_off_18                  M &ML_clamping_mode_off + 17

#define /s    ML_standstill_from_CCU                   M[32]
#define /c    ML_X_standstill_from_CCU                 M &ML_standstill_from_CCU + 0
#define /c    ML_Y_standstill_from_CCU                 M &ML_standstill_from_CCU + 1
#define /c    ML_Z_standstill_from_CCU                 M &ML_standstill_from_CCU + 2
#define /c    ML_4_standstill_from_CCU                 M &ML_standstill_from_CCU + 3
#define /c    ML_5_standstill_from_CCU                 M &ML_standstill_from_CCU + 4
#define /c    ML_6_standstill_from_CCU                 M &ML_standstill_from_CCU + 5
#define /c    ML_7_standstill_from_CCU                 M &ML_standstill_from_CCU + 6
#define /c    ML_8_standstill_from_CCU                 M &ML_standstill_from_CCU + 7
#define /c    ML_9_standstill_from_CCU                 M &ML_standstill_from_CCU + 8
#define /c    ML_10_standstill_from_CCU                M &ML_standstill_from_CCU + 9
#define /c    ML_11_standstill_from_CCU                M &ML_standstill_from_CCU + 10
#define /c    ML_12_standstill_from_CCU                M &ML_standstill_from_CCU + 11
#define /c    ML_13_standstill_from_CCU                M &ML_standstill_from_CCU + 12
#define /c    ML_14_standstill_from_CCU                M &ML_standstill_from_CCU + 13
#define /c    ML_15_standstill_from_CCU                M &ML_standstill_from_CCU + 14
#define /c    ML_16_standstill_from_CCU                M &ML_standstill_from_CCU + 15
#define /c    ML_17_standstill_from_CCU                M &ML_standstill_from_CCU + 16
#define /c    ML_18_standstill_from_CCU                M &ML_standstill_from_CCU + 17

#define /s    ML_commissioning                         M[32]
#define /c    ML_commissioning_I_X                     M &ML_commissioning + 0
#define /c    ML_commissioning_I_Y                     M &ML_commissioning + 1
#define /c    ML_commissioning_I_Z                     M &ML_commissioning + 2
#define /c    ML_commissioning_I_4                     M &ML_commissioning + 3
#define /c    ML_commissioning_I_5                     M &ML_commissioning + 4
#define /c    ML_commissioning_I_6                     M &ML_commissioning + 5
#define /c    ML_commissioning_I_7                     M &ML_commissioning + 6
#define /c    ML_commissioning_I_8                     M &ML_commissioning + 7
#define /c    ML_commissioning_I_9                     M &ML_commissioning + 8
#define /c    ML_commissioning_I_10                    M &ML_commissioning + 9
#define /c    ML_commissioning_I_11                    M &ML_commissioning + 10
#define /c    ML_commissioning_I_12                    M &ML_commissioning + 11
#define /c    ML_commissioning_I_13                    M &ML_commissioning + 12
#define /c    ML_commissioning_I_14                    M &ML_commissioning + 13
#define /c    ML_commissioning_I_15                    M &ML_commissioning + 14
#define /c    ML_commissioning_I_16                    M &ML_commissioning + 15
#define /c    ML_commissioning_I_17                    M &ML_commissioning + 16
#define /c    ML_commissioning_I_18                    M &ML_commissioning + 17

#define /s    ML_servo_drive_release_test              M[8]
#define /c    ML_servo_drive_release_1_test            M &ML_servo_drive_release_test + 0
#define /c    ML_servo_drive_release_2_test            M &ML_servo_drive_release_test + 1
#define /c    ML_servo_drive_release_3_test            M &ML_servo_drive_release_test + 2
#define /c    ML_servo_drive_release_4_test            M &ML_servo_drive_release_test + 3
#define /c    ML_servo_drive_release_5_test            M &ML_servo_drive_release_test + 4
#define /c    ML_servo_drive_release_6_test            M &ML_servo_drive_release_test + 5
#define /c    ML_servo_drive_release_7_test            M &ML_servo_drive_release_test + 6
#define /c    ML_servo_drive_release_8_test            M &ML_servo_drive_release_test + 7

#define /s    ML_servo_drive_release_has_been_off      M[8]
#define /c    ML_servo_release_1_has_been_off          M &ML_servo_drive_release_has_been_off + 0
#define /c    ML_servo_release_2_has_been_off          M &ML_servo_drive_release_has_been_off + 1
#define /c    ML_servo_release_3_has_been_off          M &ML_servo_drive_release_has_been_off + 2
#define /c    ML_servo_release_4_has_been_off          M &ML_servo_drive_release_has_been_off + 3
#define /c    ML_servo_release_5_has_been_off          M &ML_servo_drive_release_has_been_off + 4
#define /c    ML_servo_release_6_has_been_off          M &ML_servo_drive_release_has_been_off + 5
#define /c    ML_servo_release_7_has_been_off          M &ML_servo_drive_release_has_been_off + 6
#define /c    ML_servo_release_8_has_been_off          M &ML_servo_drive_release_has_been_off + 7

#define /s    ML_axes_motion_from_end_position         M
#define /s    ML_auxiliary_marker_clamping_mode        M
#define /s    ML_S_nominal_off_status_inverse          M
#define /s    ML_central_drive_mode_active             M
#define /s    ML_central_drive_operational             M
#define /s    ML_FN19_clamping_axes                    M
#define /s    ML_FN19_unclamping_axes                  M
#define /s    ML_actual_nominal_transfer               M
#define /s    ML_actual_nominal_trans_has_been_active  M
#define /s    ML_commissioning_current_control         M
#define /s    ML_counter_operating_time_on             M
#define /s    ML_reset_axes                            M
#define /s    ML_debug_9161                            M

#define /s    BL_axes_group_index                      B

#define /s    WL_drive_release_input_level             W
#define /c    BL_X150_drive_release_input_level        B &WL_drive_release_input_level + 0
#define /c    BL_X151_drive_release_input_level        B &WL_drive_release_input_level + 1

#define /s    DL_clamping_mode_on                      D
#define /s    DL_axes_in_C_axis_mode                   D
#define /s    DL_initialization                        D
#define /s    DL_standstill_CCU                        D
#define /s    DL_axes_actual_value_released            D
#define /s    DL_axes_actual_value_fixed               D
#define /s    DL_hirth_axes_initialize                 D
#define /s    DL_axes_has_been_in_position             D
#define /s    DL_TC_mag_axes_bit_coded                 D
#define /s    DL_gantry_master_slave_feed_synchron     D
#define /s    DL_controlled_axis                       D

;*$WS Call 58816 - Bit in Position von Slave Axes bleibt u.U. gesetzt
#define /s    DL_gantry_master_slave_axes              D

#define /s /r DL_axes_selection_clamping_mode          D

#define /s    DL_comissioning_current_controler        D

#include Mac_Lib.inc


GLOBAL Axes

;----------------------------
LBL Axes
;----------------------------

  L      NP_M4172_1st_PLC_run_after_power_on
  IFT
    L      DL_axes_selection_clamping_mode
    <=     K+0
    IFT
      L      KG_axis_brake_active
      AN     KG_power_on_clamping_mode_off
      =      DL_axes_selection_clamping_mode
    ENDI
  ENDI

  CM     Motion_from_end_position

  L      DG_clamping_mode_on_external
  O      DG_clamping_mode_off_external
  <>     K+0
  O      NP_M4072_strobe_M_function
  O      NP_M4075_strobe_transfer_FN19
  O      ML_auxiliary_marker_clamping_mode
  CMT    Clamping_mode

  PS     KL_commissioning_current_control
  CM     9065
  PLW
  =      DL_comissioning_current_controler
  <>     KL_inactive
  =      ML_commissioning_current_control
  M_display_module_error

  L      K+0
  =X

  REPEAT
    L      DG_controlled_axes
    O      DG_reset_axes
    BTX
    IFT

      CM     Status_PLC_pos

      CASE   BG_step_axis_X[X]
        CM     Initial                 ;00
        CM     In_position             ;01
        CM     Current_speed_on        ;02
        CM     Close_pos_loop          ;03
        CM     Unclamping              ;04
        CM     Positioning             ;05
        CM     Clamping                ;06
        CM     Open_pos_loop           ;07
        CM     Current_speed_off       ;08
        CM     Step_end                ;09
      ENDC

      PLL
      IFT
        INC    BG_step_axis_X[X]
      ENDI

      CM     Timer_unclamping
      CM     Timer_clamping
      CM     Timer_timeout_function
      CM     Timer_wait

      LN     DG_release_axes_X15x_PL6xxx
      A      DG_drives_digital
      BTX
      A      MG_servo_drive_release_axis_groups_active
      O[
        L      DG_reset_axes
        AN     DG_servo_drives_ready
        BTX
      ]
      IFT
        L      K+0
        =      BG_step_axis_X[X]
      ENDI
    ENDI

    INCX

    LX
    >=     KG_max_number_axes
  UNTILT

  LD     MG_PLC_posit_active_X
  >      KL_PLC_posit_inactive
  =      MG_axes_PLC_posit_active

  LN     MG_power_delayed_on
  ON     I_ESB_servo_drive_release
  ON     I_drives_operational
*$WS 9066
  ON     I_Siemens_supply_recover_unit_operational
  ON     I_Indramat_power_supply_ok
  RN     ML_reset_axes
  IFT
    LN     ML_reset_axes
    S      ML_reset_axes
    IFT
      L      DG_controlled_axes
      BC     KG_spindle
      =      DG_reset_axes
    ENDI
  ENDI

*$WS check error
  L      MG_power_delayed_on
  IFT
    LN     I_Siemens_supply_recover_unit_operational
    ON     I_Indramat_power_supply_ok
    A      I_ESB_servo_drive_release
    S      PN_error_supply_servo_drives
  ENDI

;Position error for axes with nominal- instead of the actual-value display

  L      KG_axes_use_nominal_value_as_actual
  >      KL_active
  IFT
    L      DL_hirth_axes_initialize
    <>     KL_hirth_axes_initialized
    A      MG_power_delayed_on
    =      PN_error_hirth_axes_initialize

    L      DL_hirth_axes_initialize
    A      KG_axes_use_nominal_value_as_actual
    AN     NP_D1108_axes_in_motion
    =      DL_hirth_axes_initialize

    L      MG_CE_key
    A      MG_key_NC_stop
    AN     MG_power_delayed_on
    IFT
      S      PN_error_hirth_axes_initialize

      L      KG_axes_use_nominal_value_as_actual
      A      DG_controlled_axes
      =      DL_hirth_axes_initialize

      PS     KL_mode_inactive
      PS     KL_mode_nominal_value_as_actual
      CM     9148
  M_display_module_error
    ENDI
  ENDI

;Magazine axis

#ifdef KG_TC_magazine_1_axis_index
  L      DG_controlled_axes
  BT     KG_TC_magazine_1_axis_index
  AN     I_TC_magazine_guard_locked_closed
  AN     MG_guard_inactive
  =      ML_actual_nominal_transfer
  IFT
    L      K+0
    BS     KG_TC_magazine_1_axis_index
    =      DL_TC_mag_axes_bit_coded

    L      K+0
    =      BG_step_axis_X[KG_TC_magazine_1_axis_index]

    L      KG_TC_magazine_2_axis_index
    >      KL_axis_active
    IFT
      L      DL_TC_mag_axes_bit_coded
      BS     KG_TC_magazine_1_axis_index
      =      DL_TC_mag_axes_bit_coded

      L      K+0
      =      BG_step_axis_X[KG_TC_magazine_2_axis_index]
    ENDI

    L      KG_axes_use_nominal_value_as_actual
    AN     DL_TC_mag_axes_bit_coded
    PSW
    PS     KL_mode_nominal_value_as_actual
    CM     9148                        ;Display nominal instead of actual value
    M_display_module_error

    PS     DL_TC_mag_axes_bit_coded
    CM     9145                        ;Actual to nominal value transfer
    M_display_module_error
  ENDI

  LN     ML_actual_nominal_transfer
  A      ML_actual_nominal_trans_has_been_active
  IFT
    PS     KG_axes_use_nominal_value_as_actual
    PS     KL_mode_nominal_value_as_actual
    CM     9148                        ;Display nominal instead of actual value
  M_display_module_error
  ENDI

  L      ML_actual_nominal_transfer
  =      ML_actual_nominal_trans_has_been_active
#endif

  CM     Servo_release
  CM     Servo_drive_releases
  CM     Clampings
  CM     Operating_time

  L      DG_servo_drives_ready
  A      DG_drives_digital
  <>     DG_current_speed_loop_on
  AN     TS_servo_drives_ready
  AN     TR_servo_drives_ready
  ON     I_drives_operational
  ON     I_Siemens_supply_recover_unit_operational
  A      MG_power_delayed_on
  AN     ML_commissioning_current_control
  S      PN_error_drives_operational

  M_error_drives_operational


EM

;----------------------------
LBL Initial                            ;00

  LN     DL_initialization
  BTX
  IFT
    L      KG_axes_with_c_axis_mode
    BTX
    R      MG_spindle_C_axis_mode_active

    L      MG_marker_one
    R      ML_servo_drives_releases[X]
    R      ML_unclamping[X]
    R      ML_clamping_mode_off[X]
    R      ML_clamping_mode_on[X]
    R      ML_commissioning[X]

    L      DL_clamping_mode_on
    BCX
    =      DL_clamping_mode_on

    L      DG_clamping_mode_off
    BCX
    =      DG_clamping_mode_off

    L      DG_current_speed_loop_on
    BCX
    =      DG_current_speed_loop_on

    L      DG_keys_inhibit
    BCX
    =      DG_keys_inhibit

    L      DL_axes_in_C_axis_mode
    BCX
    =      DL_axes_in_C_axis_mode

    L      DG_S_axis_activation
    BCX
    =      DG_S_axis_activation

    L      DG_S_axis_release
    BCX
    =      DG_S_axis_release

    L      DG_clamping_mode_on_external
    BCX
    =      DG_clamping_mode_on_external

    L      DG_clamping_mode_off_external
    BCX
    =      DG_clamping_mode_off_external

    L      DL_gantry_master_slave_axes
    BCX
    =      DL_gantry_master_slave_axes

    L      DL_gantry_master_slave_feed_synchron
    BCX
    =      DL_gantry_master_slave_feed_synchron

    L      DL_initialization
    BSX
    =      DL_initialization

    L      DG_controlled_axes
    XO     DL_controlled_axis
    BTX
    IFT
      L      DG_activate_control_loop_open
      BSX
      A      KG_axis_brake_active
      AN     KG_power_on_clamping_mode_off
      =      DG_activate_control_loop_open

      L      DG_controlled_axes
      BTX
      IFT
        L      DL_controlled_axis
        BSX
        =      DL_controlled_axis
      ELSE
        L      DL_controlled_axis
        BCX
        =      DL_controlled_axis
      ENDI
    ENDI

    L      PN_D1128_activate_control_loop_open
    BSX
    =      PN_D1128_activate_control_loop_open

    L      PN_D1132_control_loop_open
    BSX
    =      PN_D1132_control_loop_open

    L      KG_axes_with_common_used_position_ROD
    A      DG_controlled_axes
    BTX
    IFT
      L      KG_axes_with_common_used_position_ROD
      A      DG_controlled_axes
      PSW
      PS     KL_actual_value_fixed
      CM     9146
      M_display_module_error

      L      DG_axes_actual_value_fixed
      BSX
      =      DG_axes_actual_value_fixed
    ENDI

    L      KG_axes_use_nominal_value_as_actual
    BTX
    IFT
      PS     KG_axes_use_nominal_value_as_actual
      PS     KL_mode_nominal_value_as_actual
      CM     9148
      M_display_module_error
    ENDI
  ENDI

  L      DG_reset_axes
  BCX
  =      DG_reset_axes

  L      DG_controlled_axes
  BTX
  A      MG_machine_parameter_are_read
  AN     ML_reset_axes
  PSL
  IFT
    L      DL_initialization
    BCX
    =      DL_initialization
  ENDI

EM

;----------------------------
LBL In_position                        ;01

  L      ML_commissioning_current_control
  IFT
    L      DL_comissioning_current_controler
    A      DG_MP2254_fieldangle_axis_on_PLC
    BTX
    A      MG_key_rapid_traverse
    A      I_ESA_control_operational
    =      ML_commissioning[X]
    IFT
      L      DG_current_speed_loop_on
      BSX
      =      DG_current_speed_loop_on
    ELSE
      L      DG_current_speed_loop_on
      BCX
      =      DG_current_speed_loop_on
    ENDI

    PS     MG_marker_zero
EM
  ENDI

  L      NP_D1104_axes_in_position
  A      DL_axes_in_C_axis_mode
  BTX
  IFT
    R      MG_spindle_C_axis_mode_active

    L      DL_axes_in_C_axis_mode
    BCX
    =      DL_axes_in_C_axis_mode
  ENDI

  L      KG_axes_with_signal_clamped
  O      KG_axes_with_signal_unclamped
  A      NP_D1104_axes_in_position
  AN     NP_D1116_reference_nesessary
  AN     DG_S_axis_activation
  AN     PN_D1144_manual_motion_plus
  AN     PN_D1148_manual_motion_minus
  BTX
  AN     ML_clamped_axes[X]
  AN     MG_commissioning
  S      PN_error_clamping

  M_error_axis_clamping

  LX
  ==     BG_active_T_axis
  A      NP_M4030_tapping_cycle_active
  AN     NP_M4031_tapping_cycle_controlled
  S      PN_error_clamping_mode_not_permitted

  LD     ML_clamping_mode_off
  ON     DG_activate_control_loop_open
  ON     NP_D1104_axes_in_position
*$WS Call 58816 - Bit in Position von Slave Axes bleibt u.U. gesetzt
  O      DL_gantry_master_slave_axes
  BTX
  PSL
  S      TS_axis_timeout_X[X]
  EMF

  L      DG_feed_hold_axes
  BSX
  =      DG_feed_hold_axes

  L      KG_axes_group_1_gantry_or_master_slave
  BTX
  IFT
    L      DL_gantry_master_slave_axes
    O      KG_axes_group_1_gantry_or_master_slave
    =      DL_gantry_master_slave_axes
  ENDI

  L      KG_axes_group_1_gantry_or_master_slave
  BTX
  IFT
    L      DL_gantry_master_slave_axes
    O      KG_axes_group_1_gantry_or_master_slave
    =      DL_gantry_master_slave_axes
  ENDI

  L      KG_axes_group_2_gantry_or_master_slave
  BTX
  IFT
    L      DL_gantry_master_slave_axes
    O      KG_axes_group_2_gantry_or_master_slave
    =      DL_gantry_master_slave_axes
  ENDI

  L      KG_axes_group_3_gantry_or_master_slave
  BTX
  IFT
    L      DL_gantry_master_slave_axes
    O      KG_axes_group_3_gantry_or_master_slave
    =      DL_gantry_master_slave_axes
  ENDI

  L      KG_axes_with_central_drive_mode
  O      KG_axes_with_c_axis_mode
  BTX
  IFT
    LD     ML_clamping_mode_off
    O      NP_D1100_axes_release
    ON     NP_D1104_axes_in_position
    A[
      L      KG_axes_with_central_drive_mode
      O      KG_axes_with_c_axis_mode
    ]
    BCX
    <>     K+0
    =      ML_central_drive_mode_active

    L      ML_central_drive_mode_active
    S      PN_error_central_drive
    R      MG_spindle_C_axis_mode_active
    IFT
      L      K+0
      =      DL_axes_in_C_axis_mode
    ENDI

    L      KG_axes_with_central_drive_mode
    O      KG_axes_with_c_axis_mode
    A      DG_servo_drives_ready
    A      DG_drives_digital
    <>     K+0
    =      ML_central_drive_operational

    PLL
    AN     ML_central_drive_operational
    AN     ML_central_drive_mode_active
    PSL
  ENDI

  L      KG_axes_with_c_axis_mode
  BTX
  IFT
    LN     MG_spindle_C_axis_mode_active
    IFT
      L      PN_M4008_S_nominal_off_status_inverse
      =      ML_S_nominal_off_status_inverse
    ENDI

    L      MG_marker_one
    S      MG_spindle_C_axis_mode_active

    L      DL_axes_in_C_axis_mode
    BSX
    =      DL_axes_in_C_axis_mode

    PLL
    A[
      L      DL_axes_in_C_axis_mode
      BCX
      ==     K+0
    ]
    A[
      L      PN_M4007_S_M05_nominal_0_and_status
      O      PN_M4008_S_nominal_off_status_inverse
    ]
    A      MG_spindle_stand_still
    PSL
  ENDI

#if (CFG_3D_head = "active") or (CFG_S_in_axes_mode = "active")
  PLL
  PSL
  IFT
    L      KG_axes_with_c_axis_mode
    BTX
    IFT
      L      DG_S_axis_activation
      ==     K+0
      IFT
        L      DG_S_axis_activation
        BSX
        =      DG_S_axis_activation
      ENDI

      PLL
      A[
        L      DG_S_axis_release
        BTX
      ]
      AN     MG_3D_head_interruption
      PSL
    ENDI
  ENDI
#endif

EM

;----------------------------
LBL Current_speed_on                   ;02

  L      KG_axes_with_common_used_position_ROD
  BTX
  IFT
    L      DL_axes_actual_value_released
    A      DG_axes_actual_value_fixed
    BSX
    =      DL_axes_actual_value_released
  ENDI

  L      DG_current_speed_loop_on
  BSX
  A      DG_drives_digital
  =      DG_current_speed_loop_on

  L      DG_servo_drives_ready
  AN     DL_standstill_CCU
  O      DG_MP12_simulated_axes
  ON     DG_drives_digital
  BTX
  PSL
  R      ML_commissioning[X]
  S      TS_unclamping_X[X]
  S      TS_axis_timeout_X[X]

  LN     ML_servo_drives_releases[X]
  S      ML_servo_drives_releases[X]

EM

;----------------------------
LBL Close_pos_loop                     ;03

  L      DG_clamping_mode_off
  ON     DG_activate_control_loop_open
  BTX
  IFT
    L      DG_activate_control_loop_open
    BCX
    =      DG_activate_control_loop_open

    L      PN_D1128_activate_control_loop_open
    BCX
    =      PN_D1128_activate_control_loop_open
  ENDI

  L      PN_D1132_control_loop_open
  BCX
  =      PN_D1132_control_loop_open

  L      NP_D1100_axes_release
  O      DG_MP12_simulated_axes
  BTX
  PSL

EM

;----------------------------
LBL Unclamping                         ;04

  L      MG_marker_one
  S      ML_unclamping[X]

  LN     KG_axis_brake_active
  BTX
  IFT
    PSL
    CM     Gantry_master_slave
EM
  ENDI

  L      KG_axes_with_signal_clamped
  O      KG_axes_with_signal_unclamped
  BTX
  IFF
    LN     TR_unclamping_X[X]
    PSL
    CMT    Gantry_master_slave
  ELSE
    L      MG_key_NC_start_p_pulse
    O      MG_pulse_CE_key
    S      TS_axis_timeout_X[X]

    LN     ML_unclamped_axes[X]
    S      TS_unclamping_X[X]

    LN     PN_error_clamping
    A      ML_unclamped_axes[X]
    AN     TR_unclamping_X[X]
    PSL
    CMT    Gantry_master_slave
    EMT

    L      TR_axis_timeout_X[X]
    =      ML_servo_drives_releases[X]
    SN     PN_error_clamping

    M_error_axis_clamping
  ENDI

EM

;----------------------------
LBL Gantry_master_slave

  L      KG_axes_group_1_gantry_or_master_slave
  BTX
  IFT
    PLL
    IFT
      L      DL_gantry_master_slave_feed_synchron
      A      KG_axes_group_1_gantry_or_master_slave
      ==     KG_axes_group_1_gantry_or_master_slave
      PSL

      L      DL_gantry_master_slave_feed_synchron
      BSX
      =      DL_gantry_master_slave_feed_synchron
    ENDI
  ENDI

  L      KG_axes_group_2_gantry_or_master_slave
  BTX
  IFT
    PLL
    IFT
      L      DL_gantry_master_slave_feed_synchron
      A      KG_axes_group_2_gantry_or_master_slave
      ==     KG_axes_group_2_gantry_or_master_slave
      PSL

      L      DL_gantry_master_slave_feed_synchron
      BSX
      =      DL_gantry_master_slave_feed_synchron
    ENDI
  ENDI

  L      KG_axes_group_3_gantry_or_master_slave
  BTX
  IFT
    PLL
    IFT
      L      DL_gantry_master_slave_feed_synchron
      A      KG_axes_group_3_gantry_or_master_slave
      ==     KG_axes_group_3_gantry_or_master_slave
      PSL

      L      DL_gantry_master_slave_feed_synchron
      BSX
      =      DL_gantry_master_slave_feed_synchron
    ENDI
  ENDI

EM

;----------------------------
LBL Positioning                        ;05

  L      DG_feed_hold_axes
  BTX
  IFT
    L      DG_feed_hold_axes
    BCX
    =      DG_feed_hold_axes
  ENDI

  L      ML_clamping_mode_on[X]
  IFT
    L      DG_activate_control_loop_open
    BSX
    =      DG_activate_control_loop_open
  ENDI

  L      KG_axes_with_signal_clamped
  O      KG_axes_with_signal_unclamped
  BTX
  IFT
    LN     ML_unclamped_axes[X]
    S      PN_error_clamping

   M_error_axis_clamping
  ENDI

  L      DG_hirth_axes
  BTX
  IFT
    L      DG_activate_control_loop_open
    A      NP_D1104_axes_in_position
    BTX
    AN     MG_X_in_hirth_position[X]
    =      PN_error_hirth_nominal_position

    M_error_hirth_nominal_position
  ENDI

  L      KG_axes_group_1_gantry_or_master_slave
  BTX
  IFT
    L      DL_gantry_master_slave_feed_synchron
    AN     KG_axes_group_1_gantry_or_master_slave
    =      DL_gantry_master_slave_feed_synchron

;*$WS Call 58816 - Bit in Position von Slave Axes bleibt u.U. gesetzt
    L      NP_D1104_axes_in_position
    A      KG_axes_group_1_gantry_or_master_slave
    ==     KG_axes_group_1_gantry_or_master_slave
    IFT
      L      DL_gantry_master_slave_axes
      AN     KG_axes_group_1_gantry_or_master_slave
      =      DL_gantry_master_slave_axes
    ENDI
  ENDI

  L      KG_axes_group_2_gantry_or_master_slave
  BTX
  IFT
    L      DL_gantry_master_slave_feed_synchron
    AN     KG_axes_group_2_gantry_or_master_slave
    =      DL_gantry_master_slave_feed_synchron

;*$WS Call 58816 - Bit in Position von Slave Axes bleibt u.U. gesetzt
    L      NP_D1104_axes_in_position
    A      KG_axes_group_2_gantry_or_master_slave
    ==     KG_axes_group_2_gantry_or_master_slave
    IFT
      L      DL_gantry_master_slave_axes
      AN     KG_axes_group_2_gantry_or_master_slave
      =      DL_gantry_master_slave_axes
    ENDI
  ENDI

  L      KG_axes_group_3_gantry_or_master_slave
  BTX
  IFT
    L      DL_gantry_master_slave_feed_synchron
    AN     KG_axes_group_3_gantry_or_master_slave
    =      DL_gantry_master_slave_feed_synchron

;*$WS Call 58816 - Bit in Position von Slave Axes bleibt u.U. gesetzt
    L      NP_D1104_axes_in_position
    A      KG_axes_group_3_gantry_or_master_slave
    ==     KG_axes_group_3_gantry_or_master_slave
    IFT
      L      DL_gantry_master_slave_axes
      AN     KG_axes_group_3_gantry_or_master_slave
      =      DL_gantry_master_slave_axes
    ENDI
  ENDI

  LD     MG_X_in_hirth_position
  ON     DG_hirth_axes
  A      DG_activate_control_loop_open
  A      NP_D1104_axes_in_position
  AN     DL_gantry_master_slave_axes
  AN     DG_S_axis_release
  AN     DG_axes_reference_pos_safe
  BTX
  PSL
  SN     TS_waiting_in_posit_X[X]
  IFT
    L      DG_keys_inhibit
    BSX
    =      DG_keys_inhibit
  ENDI

  PLL
  AN     TR_waiting_in_posit_X[X]
  O[
    L      DG_reset_axes
    BTX
  ]
  PSL
  R      ML_unclamping[X]
  S      TS_clamping_X[X]
  S      TS_axis_timeout_X[X]

#if KG_field_angle_saved_in_PLC > 0
  L      KG_field_angle_saved_in_PLC
  BTX
  IFT
    LN     NP_D1104_axes_in_position
    A      DG_axis_field_angle_significant
    BTX
    IFT
      L      DG_axis_field_angle_significant
      BCX
      =      DG_axis_field_angle_significant

      L      DG_axis_field_angle_saving
      BCX
      =      DG_axis_field_angle_saving
    ENDI

    L      NP_D1104_axes_in_position
    AN     NP_D1116_reference_nesessary
    AN     DG_axis_field_angle_significant
    BTX
    IFT
      L      DG_axis_field_angle_saving
      BSX
      =      DG_axis_field_angle_saving
    ENDI
  ENDI
#endif

EM

;----------------------------
LBL Clamping                           ;06

  LN     KG_axis_brake_active
  BTX
  IFT
    PSL
EM
  ENDI

  L      KG_axes_with_signal_clamped
  O      KG_axes_with_signal_unclamped
  BTX
  IFF
    LN     TR_clamping_X[X]
    PSL
  ELSE
    L      MG_key_NC_start_p_pulse
    O      MG_pulse_CE_key
    S      TS_axis_timeout_X[X]

    LN     ML_clamped_axes[X]
    S      TS_clamping_X[X]

    LN     PN_error_clamping
    A      ML_clamped_axes[X]
    AN     TR_clamping_X[X]
    PSL
    EMT

    L      TR_axis_timeout_X[X]
    =      ML_servo_drives_releases[X]
    SN     PN_error_clamping

  M_error_axis_clamping

  ENDI

EM

;----------------------------
LBL Open_pos_loop                      ;07

  L      PN_D1128_activate_control_loop_open
  BSX
  =      PN_D1128_activate_control_loop_open

  L      PN_D1132_control_loop_open
  BSX
  =      PN_D1132_control_loop_open

  LN     NP_D1100_axes_release
  BTX
  PSL
  EMF

  L      KG_axes_with_common_used_position_ROD
  BTX
  IFT
    L      DL_axes_actual_value_fixed
    AN     DG_axes_actual_value_fixed
    BSX
    =      DL_axes_actual_value_fixed
  ENDI

EM

;----------------------------
LBL Current_speed_off                  ;08

  LN     KG_axes_with_active_current_control
  BTX
  IFT
    L      DG_current_speed_loop_on
    BCX
    A      DG_drives_digital
    =      DG_current_speed_loop_on
  ENDI

  LN     DG_servo_drives_ready
  ON     DG_drives_digital
  O      KG_axes_with_active_current_control
  BTX
  PSL

  L      ML_servo_drives_releases[X]
  R      ML_servo_drives_releases[X]

EM

;----------------------------
LBL Step_end                           ;09

  L      DG_keys_inhibit
  BCX
  =      DG_keys_inhibit

  PS     MG_marker_zero

  L      KG_axes_with_c_axis_mode
  BTX
  IFT
    L      DG_S_axis_activation
    BCX
    =      DG_S_axis_activation

    L      MG_3D_head_active
    O      MG_spindle_C_axis_release_active
    EMT

    L      DL_axes_in_C_axis_mode
    BCX
    =      DL_axes_in_C_axis_mode

    L      DL_axes_in_C_axis_mode
    ==     K+0
    R      MG_spindle_C_axis_mode_active
    IFT
      LN     ML_S_nominal_off_status_inverse
      S      MG_spindle_on_axes
    ENDI
  ENDI

  L      DG_reset_axes
  BTX
  IFT
    L      K+0
    =      BG_step_axis_X[X]
  ELSE
    L      K+1
    =      BG_step_axis_X[X]
  ENDI
EM

;----------------------------
LBL Servo_drive_releases

  L      ML_X_servo_drive_release
  =      O_servo_drive_release_X
  L      ML_Y_servo_drive_release
  =      O_servo_drive_release_Y
  L      ML_Z_servo_drive_release
  =      O_servo_drive_release_Z
  L      ML_4_servo_drive_release
  =      O_servo_drive_release_4
  L      ML_5_servo_drive_release
  =      O_servo_drive_release_5
  L      ML_6_servo_drive_release
  =      O_servo_drive_release_6
  L      ML_7_servo_drive_release
  =      O_servo_drive_release_7
  L      ML_8_servo_drive_release
  =      O_servo_drive_release_8
  L      ML_9_servo_drive_release
  =      O_servo_drive_release_9

  L      MG_marker_one
  R      ML_debug_9161

  L      MG_TNC_digital
  IFT
    L      O_servo_drive_release_S1
    O      O_servo_drive_release_S2
*$WS    O      MG_spindle_on_axes
    A      MG_control_operational
    A      MG_spindle_digital
    IFT
      L      DG_current_speed_loop_on
      BS     KG_spindle
      =      DG_current_speed_loop_on
    ELSE
      L      DG_current_speed_loop_on
      BC     KG_spindle
      =      DG_current_speed_loop_on
    ENDI

    L      MG_servo_drive_release_axis_groups_active
    IFT
      L      DG_current_speed_loop_on
      A      DG_release_axes_X15x_PL6xxx
      =      DG_current_speed_loop_on
    ENDI

    LN     I_ESA_control_operational
    ON     I_ESB_servo_drive_release
    IFT
      L      DG_current_speed_loop_on
      AN     DG_drives_digital
      =      DG_current_speed_loop_on
    ENDI

    L      DG_servo_drives_ready
    A      DG_drives_digital
    <>     DG_current_speed_loop_on
    AN     PN_error_drives_operational
    IFT
      L      MG_marker_one
      S      ML_debug_9161

      PS     DG_current_speed_loop_on
      CM     9161
      M_display_module_error
    ENDI

    L      MG_TNC_programming_station_with_PLC
    IFT
      L      DG_current_speed_loop_on
      =      DG_servo_drives_ready
      D=     MG_servo_drives_ready
    ENDI

    L      DG_servo_drives_ready
    A      DG_drives_digital
    ==     DG_current_speed_loop_on
    O      MG_pulse_CE_key
    =      TS_servo_drives_ready
  ENDI

  L      I_drives_operational
  IFT
    L      DG_controlled_axes
    AN     DG_drives_digital
    O      DG_servo_drives_ready
    =      DG_servo_drives_ready
    D=     MG_servo_drives_ready
  ELSE
    L      DG_controlled_axes
    AN     DG_drives_digital
    XO     DG_controlled_axes
    O      DG_servo_drives_ready
    =      DG_servo_drives_ready
    D=     MG_servo_drives_ready
  ENDI

  L      DL_axes_actual_value_released
  >      K+0
  IFT

    PS     DL_axes_actual_value_released
    PS     KL_actual_value_released
    CM     9146
    M_display_module_error

    L      DG_axes_actual_value_fixed
    AN     DL_axes_actual_value_released
    =      DG_axes_actual_value_fixed

    L      K+0
    =      DL_axes_actual_value_released
  ENDI

  L      DL_axes_actual_value_fixed
  >      K+0
  IFT

    PS     DL_axes_actual_value_fixed
    PS     KL_actual_value_fixed
    CM     9146
    M_display_module_error

    L      DG_axes_actual_value_fixed
    O      DL_axes_actual_value_fixed
    =      DG_axes_actual_value_fixed

    L      K+0
    =      DL_axes_actual_value_fixed
  ENDI

EM

;----------------------------
LBL Clampings

  CM     9159
  PLW
  O      DG_MP12_simulated_axes
  =      DL_standstill_CCU
  D=     ML_standstill_from_CCU

  M_display_module_error

#if (KG_axis_brake_active & %000000000000000001) = %000000000000000001
  L      ML_unclamping_X
  A      MG_servo_drive_ready_X
  AN     ML_X_standstill_from_CCU
  O      ML_commissioning_I_X
  =      O_unclamping_X
#endif

#if (KG_axis_brake_active & %000000000000000010) = %000000000000000010
  L      ML_unclamping_Y
  A      MG_servo_drive_ready_Y
  AN     ML_Y_standstill_from_CCU
  O      ML_commissioning_I_Y
  =      O_unclamping_Y
#endif

#if (KG_axis_brake_active & %000000000000000100) = %000000000000000100
  L      ML_unclamping_Z
  A      MG_servo_drive_ready_Z
  AN     ML_Z_standstill_from_CCU
  O      ML_commissioning_I_Z
  =      O_unclamping_Z
#endif

#if (KG_axis_brake_active & %000000000000001000) = %000000000000001000
  L      ML_unclamping_4
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_4
  A      MG_servo_drive_ready_4
  AN     ML_4_standstill_from_CCU
  O      ML_commissioning_I_4
  O      MG_3D_head_unclamp_4
  =      O_unclamping_4
#endif

#if (KG_axis_brake_active & %000000000000010000) = %000000000000010000
  L      ML_unclamping_5
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_5
  A      MG_servo_drive_ready_5
  AN     ML_5_standstill_from_CCU
  O      ML_commissioning_I_5
  O      MG_3D_head_unclamp_5
  =      O_unclamping_5
#endif

#if (KG_axis_brake_active & %000000000000100000) = %000000000000100000
  L      ML_unclamping_6
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_6
  A      MG_servo_drive_ready_6
  AN     ML_6_standstill_from_CCU
  O      ML_commissioning_I_6
  O      MG_3D_head_unclamp_6
  =      O_unclamping_6
#endif

#if (KG_axis_brake_active & %000000000001000000) = %000000000001000000
  L      ML_unclamping_7
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_7
  A      MG_servo_drive_ready_7
  AN     ML_7_standstill_from_CCU
  O      ML_commissioning_I_7
  O      MG_3D_head_unclamp_7
  =      O_unclamping_7
#endif

#if (KG_axis_brake_active & %000000000010000000) = %000000000010000000
  L      ML_unclamping_8
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_8
  A      MG_servo_drive_ready_8
  AN     ML_8_standstill_from_CCU
  O      ML_commissioning_I_8
  O      MG_3D_head_unclamp_8
  =      O_unclamping_8
#endif

#if (KG_axis_brake_active & %000000000100000000) = %000000000100000000
  L      ML_unclamping_9
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_9
  A      MG_servo_drive_ready_9
  AN     ML_9_standstill_from_CCU
  O      ML_commissioning_I_9
  O      MG_3D_head_unclamp_9
  =      O_unclamping_9
#endif

#if (KG_axis_brake_active & %000000001000000000) = %000000001000000000
  L      ML_unclamping_10
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_10
  A      MG_servo_drive_ready_10
  AN     ML_10_standstill_from_CCU
  O      ML_commissioning_I_10
  O      MG_3D_head_unclamp_10
  =      O_unclamping_10
#endif

#if (KG_axis_brake_active & %000000010000000000) = %000000010000000000
  L      ML_unclamping_11
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_11
  A      MG_servo_drive_ready_11
  AN     ML_11_standstill_from_CCU
  O      ML_commissioning_I_11
  O      MG_3D_head_unclamp_11
  =      O_unclamping_11
#endif

#if (KG_axis_brake_active & %000000100000000000) = %000000100000000000
  L      ML_unclamping_12
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_12
  A      MG_servo_drive_ready_12
  AN     ML_12_standstill_from_CCU
  O      ML_commissioning_I_12
  O      MG_3D_head_unclamp_12
  =      O_unclamping_12
#endif

#if (KG_axis_brake_active & %000001000000000000) = %000001000000000000
  L      ML_unclamping_13
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_13
  A      MG_servo_drive_ready_13
  AN     ML_13_standstill_from_CCU
  O      ML_commissioning_I_13
  O      MG_3D_head_unclamp_13
  =      O_unclamping_13
#endif

#if (KG_axis_brake_active & %000010000000000000) = %000010000000000000
  L      ML_unclamping_14
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_14
  A      MG_servo_drive_ready_14
  AN     ML_14_standstill_from_CCU
  O      ML_commissioning_I_14
  O      MG_3D_head_unclamp_14
  =      O_unclamping_14
#endif

#if (KG_axis_brake_active & %000100000000000000) = %000100000000000000
  L      ML_unclamping_15
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_15
  A      MG_servo_drive_ready_15
  AN     ML_15_standstill_from_CCU
  O      ML_commissioning_I_15
  O      MG_3D_head_unclamp_15
  =      O_unclamping_15
#endif

#if (KG_axis_brake_active & %001000000000000000) = %001000000000000000
  L      ML_unclamping_16
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_16
  A      MG_servo_drive_ready_16
  AN     ML_16_standstill_from_CCU
  O      ML_commissioning_I_16
  O      MG_3D_head_unclamp_16
  =      O_unclamping_16
#endif

#if (KG_axis_brake_active & %010000000000000000) = %010000000000000000
  L      ML_unclamping_17
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_17
  A      MG_servo_drive_ready_17
  AN     ML_17_standstill_from_CCU
  O      ML_commissioning_I_17
  O      MG_3D_head_unclamp_17
  =      O_unclamping_17
#endif

#if (KG_axis_brake_active & %100000000000000000) = %100000000000000000
  L      ML_unclamping_18
  R      MG_3D_head_axis_1_service_unclamping
  R      MG_3D_head_axis_2_service_unclamping

  L      ML_unclamping_18
  A      MG_servo_drive_ready_18
  AN     ML_18_standstill_from_CCU
  O      ML_commissioning_I_18
  O      MG_3D_head_unclamp_18
  =      O_unclamping_18
#endif

#if (KG_axes_with_signal_clamped & %000000000000000001) = %000000000000000001
#if (KG_axes_with_signal_unclamped & %000000000000000001) = %000000000000000001
  L      I_clamped_axis_X
  AN     I_unclamped_axis_X
  =      ML_clamped_axis_X

  LN     I_clamped_axis_X
  A      I_unclamped_axis_X
  =      ML_unclamped_axis_X
#else
  L      I_clamped_axis_X
  =      ML_clamped_axis_X
  =N     ML_unclamped_axis_X
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000000000000001) = %000000000000000001
  L      I_unclamped_axis_X
  =N     ML_clamped_axis_X
  =      ML_unclamped_axis_X
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000000000000010) = %000000000000000010
#if (KG_axes_with_signal_unclamped & %000000000000000010) = %000000000000000010
  L      I_clamped_axis_Y
  AN     I_unclamped_axis_Y
  =      ML_clamped_axis_Y

  LN     I_clamped_axis_Y
  A      I_unclamped_axis_Y
  =      ML_unclamped_axis_Y
#else
  L      I_clamped_axis_Y
  =      ML_clamped_axis_Y
  =N     ML_unclamped_axis_Y
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000000000000010) = %000000000000000010
  L      I_unclamped_axis_Y
  =N     ML_clamped_axis_Y
  =      ML_unclamped_axis_Y
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000000000000100) = %000000000000000100
#if (KG_axes_with_signal_unclamped & %000000000000000100) = %000000000000000100
  L      I_clamped_axis_Z
  AN     I_unclamped_axis_Z
  =      ML_clamped_axis_Z

  LN     I_clamped_axis_Z
  A      I_unclamped_axis_Z
  =      ML_unclamped_axis_Z
#else
  L      I_clamped_axis_Z
  =      ML_clamped_axis_Z
  =N     ML_unclamped_axis_Z
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000000000000100) = %000000000000000100
  L      I_unclamped_axis_Z
  =N     ML_clamped_axis_Z
  =      ML_unclamped_axis_Z
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000000000001000) = %000000000000001000
#if (KG_axes_with_signal_unclamped & %000000000000001000) = %000000000000001000
  L      I_clamped_axis_4
  AN     I_unclamped_axis_4
  =      ML_clamped_axis_4

  LN     I_clamped_axis_4
  A      I_unclamped_axis_4
  =      ML_unclamped_axis_4
#else
  L      I_clamped_axis_4
  =      ML_clamped_axis_4
  =N     ML_unclamped_axis_4
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000000000001000) = %000000000000001000
  L      I_unclamped_axis_4
  =N     ML_clamped_axis_4
  =      ML_unclamped_axis_4
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000000000010000) = %000000000000010000
#if (KG_axes_with_signal_unclamped & %000000000000010000) = %000000000000010000
  L      I_clamped_axis_5
  AN     I_unclamped_axis_5
  =      ML_clamped_axis_5

  LN     I_clamped_axis_5
  A      I_unclamped_axis_5
  =      ML_unclamped_axis_5
#else
  L      I_clamped_axis_5
  =      ML_clamped_axis_5
  =N     ML_unclamped_axis_5
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000000000010000) = %000000000000010000
  L      I_unclamped_axis_5
  =N     ML_clamped_axis_5
  =      ML_unclamped_axis_5
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000000000100000) = %000000000000100000
#if (KG_axes_with_signal_unclamped & %000000000000100000) = %000000000000100000
  L      I_clamped_axis_6
  AN     I_unclamped_axis_6
  =      ML_clamped_axis_6

  LN     I_clamped_axis_6
  A      I_unclamped_axis_6
  =      ML_unclamped_axis_6
#else
  L      I_clamped_axis_6
  =      ML_clamped_axis_6
  =N     ML_unclamped_axis_6
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000000000100000) = %000000000000100000
  L      I_unclamped_axis_6
  =N     ML_clamped_axis_6
  =      ML_unclamped_axis_6
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000000001000000) = %000000000001000000
#if (KG_axes_with_signal_unclamped & %000000000001000000) = %000000000001000000
  L      I_clamped_axis_7
  AN     I_unclamped_axis_7
  =      ML_clamped_axis_7

  LN     I_clamped_axis_7
  A      I_unclamped_axis_7
  =      ML_unclamped_axis_7
#else
  L      I_clamped_axis_7
  =      ML_clamped_axis_7
  =N     ML_unclamped_axis_7
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000000001000000) = %000000000001000000
  L      I_unclamped_axis_7
  =N     ML_clamped_axis_7
  =      ML_unclamped_axis_7
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000000010000000) = %000000000010000000
#if (KG_axes_with_signal_unclamped & %000000000010000000) = %000000000010000000
  L      I_clamped_axis_8
  AN     I_unclamped_axis_8
  =      ML_clamped_axis_8

  LN     I_clamped_axis_8
  A      I_unclamped_axis_8
  =      ML_unclamped_axis_8
#else
  L      I_clamped_axis_8
  =      ML_clamped_axis_8
  =N     ML_unclamped_axis_8
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000000010000000) = %000000000010000000
  L      I_unclamped_axis_8
  =N     ML_clamped_axis_8
  =      ML_unclamped_axis_8
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000000100000000) = %000000000100000000
#if (KG_axes_with_signal_unclamped & %000000000100000000) = %000000000100000000
  L      I_clamped_axis_9
  AN     I_unclamped_axis_9
  =      ML_clamped_axis_9

  LN     I_clamped_axis_9
  A      I_unclamped_axis_9
  =      ML_unclamped_axis_9
#else
  L      I_clamped_axis_9
  =      ML_clamped_axis_9
  =N     ML_unclamped_axis_9
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000000100000000) = %000000000100000000
  L      I_unclamped_axis_9
  =N     ML_clamped_axis_9
  =      ML_unclamped_axis_9
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000001000000000) = %000000001000000000
#if (KG_axes_with_signal_unclamped & %000000001000000000) = %000000001000000000
  L      I_clamped_axis_10
  AN     I_unclamped_axis_10
  =      ML_clamped_axis_10

  LN     I_clamped_axis_10
  A      I_unclamped_axis_10
  =      ML_unclamped_axis_10
#else
  L      I_clamped_axis_10
  =      ML_clamped_axis_10
  =N     ML_unclamped_axis_10
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000001000000000) = %000000001000000000
  L      I_unclamped_axis_10
  =N     ML_clamped_axis_10
  =      ML_unclamped_axis_10
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000010000000000) = %000000010000000000
#if (KG_axes_with_signal_unclamped & %000000010000000000) = %000000010000000000
  L      I_clamped_axis_11
  AN     I_unclamped_axis_11
  =      ML_clamped_axis_11

  LN     I_clamped_axis_11
  A      I_unclamped_axis_11
  =      ML_unclamped_axis_11
#else
  L      I_clamped_axis_11
  =      ML_clamped_axis_11
  =N     ML_unclamped_axis_11
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000010000000000) = %000000010000000000
  L      I_unclamped_axis_11
  =N     ML_clamped_axis_11
  =      ML_unclamped_axis_11
#endif
#endif

#if (KG_axes_with_signal_clamped & %000000100000000000) = %000000100000000000
#if (KG_axes_with_signal_unclamped & %000000100000000000) = %000000100000000000
  L      I_clamped_axis_12
  AN     I_unclamped_axis_12
  =      ML_clamped_axis_12

  LN     I_clamped_axis_12
  A      I_unclamped_axis_12
  =      ML_unclamped_axis_12
#else
  L      I_clamped_axis_12
  =      ML_clamped_axis_12
  =N     ML_unclamped_axis_12
#endif
#else
#if (KG_axes_with_signal_unclamped & %000000100000000000) = %000000100000000000
  L      I_unclamped_axis_12
  =N     ML_clamped_axis_12
  =      ML_unclamped_axis_12
#endif
#endif

#if (KG_axes_with_signal_clamped & %000001000000000000) = %000001000000000000
#if (KG_axes_with_signal_unclamped & %000001000000000000) = %000001000000000000
  L      I_clamped_axis_13
  AN     I_unclamped_axis_13
  =      ML_clamped_axis_13

  LN     I_clamped_axis_13
  A      I_unclamped_axis_13
  =      ML_unclamped_axis_13
#else
  L      I_clamped_axis_13
  =      ML_clamped_axis_13
  =N     ML_unclamped_axis_13
#endif
#else
#if (KG_axes_with_signal_unclamped & %000001000000000000) = %000001000000000000
  L      I_unclamped_axis_13
  =N     ML_clamped_axis_13
  =      ML_unclamped_axis_13
#endif
#endif

#if (KG_axes_with_signal_clamped & %000010000000000000) = %000010000000000000
#if (KG_axes_with_signal_unclamped & %000010000000000000) = %000010000000000000
  L      I_clamped_axis_14
  AN     I_unclamped_axis_14
  =      ML_clamped_axis_14

  LN     I_clamped_axis_14
  A      I_unclamped_axis_14
  =      ML_unclamped_axis_14
#else
  L      I_clamped_axis_14
  =      ML_clamped_axis_14
  =N     ML_unclamped_axis_14
#endif
#else
#if (KG_axes_with_signal_unclamped & %000010000000000000) = %000010000000000000
  L      I_unclamped_axis_14
  =N     ML_clamped_axis_14
  =      ML_unclamped_axis_14
#endif
#endif

#if (KG_axes_with_signal_clamped & %000100000000000000) = %000100000000000000
#if (KG_axes_with_signal_unclamped & %000100000000000000) = %000100000000000000
  L      I_clamped_axis_15
  AN     I_unclamped_axis_15
  =      ML_clamped_axis_15

  LN     I_clamped_axis_15
  A      I_unclamped_axis_15
  =      ML_unclamped_axis_15
#else
  L      I_clamped_axis_15
  =      ML_clamped_axis_15
  =N     ML_unclamped_axis_15
#endif
#else
#if (KG_axes_with_signal_unclamped & %000100000000000000) = %000100000000000000
  L      I_unclamped_axis_15
  =N     ML_clamped_axis_15
  =      ML_unclamped_axis_15
#endif
#endif

#if (KG_axes_with_signal_clamped & %001000000000000000) = %001000000000000000
#if (KG_axes_with_signal_unclamped & %001000000000000000) = %001000000000000000
  L      I_clamped_axis_16
  AN     I_unclamped_axis_16
  =      ML_clamped_axis_16

  LN     I_clamped_axis_16
  A      I_unclamped_axis_16
  =      ML_unclamped_axis_16
#else
  L      I_clamped_axis_16
  =      ML_clamped_axis_16
  =N     ML_unclamped_axis_16
#endif
#else
#if (KG_axes_with_signal_unclamped & %001000000000000000) = %001000000000000000
  L      I_unclamped_axis_16
  =N     ML_clamped_axis_16
  =      ML_unclamped_axis_16
#endif
#endif

#if (KG_axes_with_signal_clamped & %010000000000000000) = %010000000000000000
#if (KG_axes_with_signal_unclamped & %010000000000000000) = %010000000000000000
  L      I_clamped_axis_17
  AN     I_unclamped_axis_17
  =      ML_clamped_axis_17

  LN     I_clamped_axis_17
  A      I_unclamped_axis_17
  =      ML_unclamped_axis_17
#else
  L      I_clamped_axis_17
  =      ML_clamped_axis_17
  =N     ML_unclamped_axis_17
#endif
#else
#if (KG_axes_with_signal_unclamped & %010000000000000000) = %010000000000000000
  L      I_unclamped_axis_17
  =N     ML_clamped_axis_17
  =      ML_unclamped_axis_17
#endif
#endif

#if (KG_axes_with_signal_clamped & %100000000000000000) = %100000000000000000
#if (KG_axes_with_signal_unclamped & %100000000000000000) = %100000000000000000
  L      I_clamped_axis_18
  AN     I_unclamped_axis_18
  =      ML_clamped_axis_18

  LN     I_clamped_axis_18
  A      I_unclamped_axis_18
  =      ML_unclamped_axis_18
#else
  L      I_clamped_axis_18
  =      ML_clamped_axis_18
  =N     ML_unclamped_axis_18
#endif
#else
#if (KG_axes_with_signal_unclamped & %100000000000000000) = %100000000000000000
  L      I_unclamped_axis_18
  =N     ML_clamped_axis_18
  =      ML_unclamped_axis_18
#endif
#endif

  L      DG_MP12_simulated_axes
  ==     K+0
  EMT

  L      K+0
  =X

  REPEAT
    L      DG_MP12_simulated_axes
    BTX
    IFT
      L      ML_unclamping[X]
      =      ML_unclamped_axes[X]
      =N     ML_clamped_axes[X]
    ENDI

    INCX

    LX
    >=     KG_max_number_axes
  UNTILT

EM

;----------------------------
LBL Clamping_mode

  L      NP_M4075_strobe_transfer_FN19
  RN     ML_FN19_clamping_axes
  RN     ML_FN19_unclamping_axes
  IFT
    L      NP_D280_FN19_1st_value
    /      K+10000
    ==     K+99990
    =      ML_FN19_clamping_axes
    IFT
      L      NP_D284_FN19_2st_value
      /      K+10000
      A      KG_axis_brake_active
      <=     K+0
      S      PN_error_value_not_permissible
      IFF
        L      NP_D284_FN19_2st_value
        /      K+10000
        =      DL_axes_selection_clamping_mode
      ENDI
    ENDI

    L      NP_D280_FN19_1st_value
    /      K+10000
    ==     K+99991
    =      ML_FN19_unclamping_axes
    IFT
      L      NP_D284_FN19_2st_value
      /      K+10000
      A      KG_axis_brake_active
      <=     K+0
      S      PN_error_value_not_permissible
      IFF
        L      NP_D284_FN19_2st_value
        /      K+10000
        =      DL_axes_selection_clamping_mode
      ENDI
    ENDI
  ENDI

  L      MG_M11_unclamping_axes
  O      ML_FN19_unclamping_axes
  IFT
    L      DL_axes_selection_clamping_mode
    D=     ML_clamping_mode_off
  ELSE
    L      K+0
    D=     ML_clamping_mode_off

    L      MG_M44_unclamping_axis_4
    =      ML_clamping_mode_off_4

    L      MG_M45_unclamping_axis_5
    =      ML_clamping_mode_off_5

    L      MG_M46_unclamping_axis_6
    =      ML_clamping_mode_off_6

    LD     ML_clamping_mode_off
    O      DG_clamping_mode_off_external
    D=     ML_clamping_mode_off
  ENDI

  L      MG_M10_clamping_axes
  O      ML_FN19_clamping_axes
  IFT
    L      DL_axes_selection_clamping_mode
    D=     ML_clamping_mode_on
  ELSE
    L      K+0
    D=     ML_clamping_mode_on

    L      MG_M64_clamping_axis_4
    =      ML_clamping_mode_on_4

    L      MG_M65_clamping_axis_5
    =      ML_clamping_mode_on_5

    L      MG_M66_clamping_axis_6
    =      ML_clamping_mode_on_6

    LD     ML_clamping_mode_on
    O      DG_clamping_mode_on_external
    D=     ML_clamping_mode_on
  ENDI

  L      KG_axes_group_1_gantry_or_master_slave
  >      K+0
  IFT
    LD     ML_clamping_mode_on
    A      KG_axes_group_1_gantry_or_master_slave
    >      K+0
    IFT
      LD     ML_clamping_mode_on
      O      KG_axes_group_1_gantry_or_master_slave
      D=     ML_clamping_mode_on
    ENDI

    LD     ML_clamping_mode_off
    A      KG_axes_group_1_gantry_or_master_slave
    >      K+0
    IFT
      LD     ML_clamping_mode_off
      O      KG_axes_group_1_gantry_or_master_slave
      D=     ML_clamping_mode_off
    ENDI
  ENDI

  L      KG_axes_group_2_gantry_or_master_slave
  >      K+0
  IFT
    LD     ML_clamping_mode_on
    A      KG_axes_group_2_gantry_or_master_slave
    >      K+0
    IFT
      LD     ML_clamping_mode_on
      O      KG_axes_group_2_gantry_or_master_slave
      D=     ML_clamping_mode_on
    ENDI

    LD     ML_clamping_mode_off
    A      KG_axes_group_2_gantry_or_master_slave
    >      K+0
    IFT
      LD     ML_clamping_mode_off
      O      KG_axes_group_2_gantry_or_master_slave
      D=     ML_clamping_mode_off
    ENDI
  ENDI

  L      KG_axes_group_3_gantry_or_master_slave
  >      K+0
  IFT
    LD     ML_clamping_mode_on
    A      KG_axes_group_3_gantry_or_master_slave
    >      K+0
    IFT
      LD     ML_clamping_mode_on
      O      KG_axes_group_3_gantry_or_master_slave
      D=     ML_clamping_mode_on
    ENDI

    LD     ML_clamping_mode_off
    A      KG_axes_group_3_gantry_or_master_slave
    >      K+0
    IFT
      LD     ML_clamping_mode_off
      O      KG_axes_group_3_gantry_or_master_slave
      D=     ML_clamping_mode_off
    ENDI
  ENDI

  LD     ML_clamping_mode_on
  A      DG_controlled_axes
  D=     ML_clamping_mode_on
  =      DL_clamping_mode_on

  LD     ML_clamping_mode_off
  A      DG_controlled_axes
  D=     ML_clamping_mode_off
  =      DG_clamping_mode_off

  L      DL_clamping_mode_on
  <>     K+0
  IFT
    LN     NP_D1100_axes_release
    A      DL_clamping_mode_on
    ==     DL_clamping_mode_on
    IFT
      L      NP_M4072_strobe_M_function
      S      PN_M4092_quit_M_function

      L      NP_M4075_strobe_transfer_FN19
      S      PN_M4095_quit_transfer_FN19

      L      K+0
      =      DG_clamping_mode_on_external
    ENDI
  ENDI

  L      DG_clamping_mode_off
  <>     K+0
  IFT
    L      NP_D1100_axes_release
    O      DG_MP12_simulated_axes
    AN     DG_feed_hold_axes
    A      DG_clamping_mode_off
    ==     DG_clamping_mode_off
    IFT
      L      NP_M4072_strobe_M_function
      S      PN_M4092_quit_M_function

      L      NP_M4075_strobe_transfer_FN19
      S      PN_M4095_quit_transfer_FN19

      L      K+0
      =      DG_clamping_mode_off_external
    ENDI
  ENDI

  L      NP_M4072_strobe_M_function
  O      NP_M4075_strobe_transfer_FN19
  =      ML_auxiliary_marker_clamping_mode

EM

;----------------------------
LBL Timer_unclamping

  L      TS_unclamping_X[X]
  R      TS_unclamping_X[X]
  IFT
    LX
    +      K&TR_unclamping_X
    PSW
    PS     KL_runtime_from_MP
    CM     9006
      M_display_module_error
  ENDI

EM

;----------------------------
LBL Timer_clamping

  L      TS_clamping_X[X]
  R      TS_clamping_X[X]
  IFT
    LX
    +      K&TR_clamping_X
    PSW
    PS     KL_runtime_from_MP
    CM     9006
      M_display_module_error
  ENDI

EM

;----------------------------
LBL Timer_timeout_function

  L      TS_axis_timeout_X[X]
  R      TS_axis_timeout_X[X]
  IFT
    LX
    +      K&TR_axis_timeout_X
    PSW
    PS     KL_runtime_from_MP
    CM     9006
      M_display_module_error
  ENDI

EM

;----------------------------
LBL Timer_wait

  L      TS_waiting_in_posit_X[X]
  R      TS_waiting_in_posit_X[X]
  IFT
    LX
    +      K&TR_waiting_in_posit_X
    PSW
    PS     KL_runtime_from_MP
    CM     9006
      M_display_module_error
  ENDI

EM

;----------------------------
LBL Motion_from_end_position

  LN     I_end_posit_axis_X
  AN     I_end_posit_axis_Y
  AN     I_end_posit_axis_Z
  AN     I_end_posit_axis_4
  AN     I_end_posit_axis_5
  AN     O_axes_motion_from_end_position
  EMT

  L      MG_clock_1_s
  O      O_axes_motion_from_end_position
  =      O_lamp_axes_motion_from_end_position

  L      MG_key_axes_motion_from_end_position
  S      MG_SK_axes_motion_from_end_pos

  L      MG_SK_axes_motion_from_end_pos
  S      O_axes_motion_from_end_position

  L      MG_automatic_mode
  O      NP_M4151_mode_electronic_handwheel
  O      NP_M4660_HR420_active
  AN     MG_commissioning
  ON     ML_axes_motion_from_end_position
  ON     I_emergency_button_unlocked
  R      MG_SK_axes_motion_from_end_pos
  R      O_axes_motion_from_end_position
  R      O_lamp_axes_motion_from_end_position

  L      O_axes_motion_from_end_position
  =      PN_error_axes_motion_from_end_position

  LN     O_axes_motion_from_end_position
  AN     ML_axes_motion_from_end_position
  R      MG_win_end_position_Xp
  R      MG_win_end_position_Xn
  R      MG_win_end_position_Yp
  R      MG_win_end_position_Yn
  R      MG_win_end_position_Zp
  R      MG_win_end_position_Zn
  R      MG_win_end_position_4p
  R      MG_win_end_position_4n
  R      MG_win_end_position_5p
  R      MG_win_end_position_5n

  L      I_end_posit_axis_X
  O      I_end_posit_axis_Y
  O      I_end_posit_axis_Z
  O      I_end_posit_axis_4
  O      I_end_posit_axis_5
  =      ML_axes_motion_from_end_position

EM

;Servo drive release axes group X150/X151 (MC) oder PL6xxx (CC6xxx - MP4132)

;----------------------------
LBL Servo_release

  L      MG_servo_drive_release_axis_groups_active
  IFT
    PS     KL_servo_drive_release_axis_coded
    CM     9157
    PL     DG_release_axes_X15x_PL6xxx
    M_display_module_error

    PS     KL_servo_drive_release_input_level
    CM     9157
    PL     WL_drive_release_input_level
    M_display_module_error

    L      BL_X150_drive_release_input_level
    O      BL_X151_drive_release_input_level
    B=     MG_servo_drive_release_1st_axes_group

    L      DG_release_axes_X15x_PL6xxx
    BT     KG_spindle
    ON     MG_spindle_digital
    =      MG_servo_drive_release_spindle

    LN     MG_guard_open
    O      MG_guard_inactive
#if &I_HRxx0_key_permissive_mode < 1000
    O      I_HRxx0_key_permissive_mode
#endif
    A      MG_power_delayed_on
    =      ML_servo_drive_release_1_test

    L      I_TC_magazine_guard_locked_closed
    O      MG_guard_inactive
    A      MG_power_delayed_on
    =      ML_servo_drive_release_2_test

    L      I_guard_2_closed_locked
    O      MG_guard_inactive
    A      MG_power_delayed_on
    =      ML_servo_drive_release_3_test

    L      I_release_axis_group_4
    O      MG_guard_inactive
    A      MG_power_delayed_on
    =      ML_servo_drive_release_4_test

    L      I_release_axis_group_5
    O      MG_guard_inactive
    A      MG_power_delayed_on
    =      ML_servo_drive_release_5_test

    L      I_release_axis_group_6
    O      MG_guard_inactive
    A      MG_power_delayed_on
    =      ML_servo_drive_release_6_test

    L      I_release_axis_group_7
    O      MG_guard_inactive
    A      MG_power_delayed_on
    =      ML_servo_drive_release_7_test

    L      I_release_axis_group_8
    O      MG_guard_inactive
    A      MG_power_delayed_on
    =      ML_servo_drive_release_8_test

    L      MG_marker_one
    R      TS_servo_drive_releases

    L      K +0
    =      BL_axes_group_index
    REPEAT
      L      BG_active_axes_groups
      BT     BL_axes_group_index
      IFT
        L      ML_servo_drive_release_1_test[BL_axes_group_index]
        A      ML_servo_release_1_has_been_off[BL_axes_group_index]
        O      MG_pulse_CE_key
        S      TS_servo_drive_releases

        LN     ML_servo_drive_release_1_test[BL_axes_group_index]
        =      ML_servo_release_1_has_been_off[BL_axes_group_index]

        LN     MG_servo_drive_release_1st_axes_group[BL_axes_group_index]
        A      ML_servo_drive_release_1_test[BL_axes_group_index]
        AN     TS_servo_drive_releases
        AN     TR_servo_drive_releases
        S      PN_error_X15x_servo_drive_release

      M_X15x_axes_release(BL_axes_group_index)
      ENDI

      INC    BL_axes_group_index

      L      BL_axes_group_index
      >      KL_axes_group_max_number
    UNTILT

    L      MG_power_delayed_on
    AN     I_ESB_servo_drive_release
    S      PN_error_I32_servo_drive_release

  ELSE
    L      MG_marker_one
    S      MG_servo_drive_release_spindle

    L      K$FF
    B=     MG_servo_drive_release_1st_axes_group

    LN     I_guard_1_closed_locked
    ON     I_guard_2_closed_locked
    AN     MG_guard_inactive
#if &I_HRxx0_key_permissive_mode < 1000
    AN     I_HRxx0_key_permissive_mode
#endif
    ON     MG_power_delayed_on
    =      TS_servo_drive_releases

    LN     I_ESB_servo_drive_release
    AN     TS_servo_drive_releases
    AN     TR_servo_drive_releases
    S      PN_error_I32_servo_drive_release
  ENDI

EM

;----------------------------
LBL Operating_time

  L      MG_axes_in_motion
  AN     ML_counter_operating_time_on
  IFT
    PS     KG_operating_time_axes
    CM     9190
    M_display_module_error
  ENDI

  LN     MG_axes_in_motion
  A      ML_counter_operating_time_on
  IFT
    PS     KG_operating_time_axes
    CM     9191
    M_display_module_error
  ENDI

  L      MG_axes_in_motion
  =      ML_counter_operating_time_on

EM

;----------------------------
LBL Status_PLC_pos

  PSX
  CM     9222
  PLW
  PSW
  ==     KL_PLC_posit_active
  =      MG_PLC_posit_active_X[X]
  PL     BG_status_PLC_posit_X[X]

  L      NP_W1022_module_error_status
  <>     KL_axis_not_controlled_asynchron_slave
  IFT
    M_display_module_error
  ENDI

  L      BG_status_PLC_posit_X[X]
  >=     KL_PLC_posit_active
  IFT
    PS     K&DG_distance_to_go_X_axis
    PS     KL_distance_to_go
    CM     9041
    M_display_module_error

    L      DG_distance_to_go_X_axis[X]
    +      DG_position_axis_X_ref[X]
    =      DG_target_posit_axis_X[X]
  ENDI

EM
