*-----------------------------------------------------------------------------
*  Feed Release
*-----------------------------------------------------------------------------
*  Module Description
*    Special function F99999:
*    The PLC program interprets the programmed feed rate F99999 as
*    modally effective rapid traverse (Fmax - non-modal, blockwise).
*    Spindle speed and spindle ramp are not monitored.
*
*-----------------------------------------------------------------------------

#define /s    KL_10_percent                            K +1000
#define /s    KL_100_percent                           K +10000

#define /s    ML_M31_processing_without_M3_M4          M
#define /s    ML_key_pressed                           M
#define /s    ML_feed_release_axes                     M
#define /s    ML_key_NC_start                          M
#define /s    ML_T_torque_monitoring_was_active        M

#define /s    WL_S_max_torque                          W
#define /s    WL_factor_feed_override                  W

EXTERN Absolute

GLOBAL Feed_release

;----------------------------
LBL Feed_release
;----------------------------

  L      MG_M31_processing_without_M3_M4
  S      PN_M4092_quit_M_function
  S      ML_M31_processing_without_M3_M4

  L      MG_pulse_END_PGM_M02_M30
  O      MG_auto_manu_mode_change
  ON     PN_M4007_S_M05_nominal_0_and_status
  ON     MG_control_operational
  R      ML_M31_processing_without_M3_M4

  L      MG_key_override_F_100
  AN     ML_key_pressed
  XO     MG_SK_override_F_100
  =      MG_SK_override_F_100
  IFT
    L      KL_100_percent
    =      PN_W766_factor_feed_override_PLC

    L      NP_W494_factor_feed_override_NC
    -      WL_factor_feed_override
    PSW
    CM     Absolute
    PLW
    >=     KL_10_percent
    R      MG_SK_override_F_100
  ELSE
    L      NP_W494_factor_feed_override_NC
    =      WL_factor_feed_override
  ENDI

  L      MG_key_override_F_100
  =      ML_key_pressed

  L      DG_hirth_axes
  O      KG_axes_with_c_axis_mode
  AN     NP_D1104_axes_in_position
  <>     K+0
  O[
    L      NP_D360_programmed_feed_rate_PLC
    ==     K+99999
  ]
  O      MG_axes_PLC_posit_active
#if CFG_free_rotation              = "inactive"
  O      MG_spindle_nominal_rpm_reached
  ON     PN_M4012_S_open_control_loop
#else
  O[
    L      MG_spindle_nominal_rpm_reached
    ON     PN_M4012_S_open_control_loop
    AN     MG_free_rotation_active
  ]
  O[
    L      MG_free_rotation_nominal_rpm_reached
    A      MG_free_rotation_active
  ]
#endif
  O      MG_touch_probe_active
  O      ML_M31_processing_without_M3_M4
  O      MG_feed_monitoring_M3_M4_inactive
  O      MG_manual_mode
  O      NP_M4060_tool_measurement_active
  =      ML_feed_release_axes
  IFF
    L      K+0
    =      PN_W766_factor_feed_override_PLC
  ENDI

  L      NP_D388_current_path_posit_feed
  ==     K+0
  AN     MG_NC_axes_in_position
  AN     ML_feed_release_axes
  =      MG_display_feed_release_in_PLC_window

  L      DG_controlled_axes
  AN     DG_feed_hold_axes
  AN     DG_feed_stop_PLC_axes
  =      PN_D1172_feed_release_axis_specific

#if CFG_tool_specific_torque_monitoring  = "active"
  L      MG_M82_T_torque_off
  O      MG_M83_T_torque_on
  S      MG_clear_screen
  S      PN_M4092_quit_M_function

  L      MG_M83_T_torque_on
  O      MG_auto_manu_mode_change
  O      MG_pulse_END_PGM_M02_M30
  ON     MG_control_operational
  S      MG_SK_T_torque_monitoring

  L      MG_M82_T_torque_off
  R      MG_SK_T_torque_monitoring

  L      MG_SK_T_torque_monitoring
  XO     ML_T_torque_monitoring_was_active
  S      MG_clear_screen

  L      MG_SK_T_torque_monitoring
  =      ML_T_torque_monitoring_was_active

  L      MG_SK_T_torque_monitoring
  IFT
    L      WG_S_max_torque_tool_table
    =      WL_S_max_torque
  ELSE
    L      DG_S1_max_torque[BG_number_active_spindle]
    =      WL_S_max_torque
  ENDI

  L      NP_M4002_S_nominal_0
  ON     NP_M4001_S_nominal_not_in_ramp
  =      TS_S_nominal_value_in_ramp

*$$WS
; 2. Schwelle einführen MP_Data.tab
;
;  LN     MG_Spindel_Drehzahl_N_ok
;  AN     TR_S_Sollwert_in_Rampe
;  AN     PN_M4007_S_M05_Sollwert_0_und_Status
;  AN     PN_M4008_S_Sollwert_aus_Status_invers
;  A      MG_BA_Automatik
;  S      PN_Fehler_Spindel_Nist_Ueberlast

  L      WG_drive_utilization_S
  >      WL_S_max_torque
  A      ML_feed_release_axes
  AN     TR_S_nominal_value_in_ramp
  =      PN_error_S_torque_max
  IFT
    L      WL_S_max_torque
    -      WG_drive_utilization_S
    X      DG_S1_factor_feed_reduction[BG_number_active_spindle]
    /      K+10
    +      K+100
    X      NP_W494_factor_feed_override_NC
    /      K+100
    =      PN_W766_factor_feed_override_PLC

    L      PN_W766_factor_feed_override_PLC
    <      K+1000
    A[
      L      NP_W494_factor_feed_override_NC
      >      K+1000
    ]
    IFT
      L      K+1000
      =      PN_W766_factor_feed_override_PLC
    ENDI
  ENDI
#endif

  L      K+300000
  =      NP_D596_max_feed_rate_PLC

  L      MG_SLS_operating_mode_2_set_up
  AN     MG_SLS_operating_mode_4
  =      PN_error_op_mode_2
  IFT
    L      DG_feed_operating_mode_2
    =      NP_D596_max_feed_rate_PLC
  ENDI

  L      MG_SLS_operating_mode_3
  AN     MG_SLS_operating_mode_4
  =      PN_error_op_mode_3
  IFT
    L      DG_feed_operating_mode_3
    =      NP_D596_max_feed_rate_PLC
  ENDI

  L      MG_SLS_operating_mode_4
  =      PN_error_op_mode_4
  IFT
    L      DG_feed_operating_mode_4
    =      NP_D596_max_feed_rate_PLC
  ENDI

  L      MG_TC_help
  O      MG_PC_help
  AN     MG_key_rapid_traverse
  O      O_axes_motion_from_end_position
  O      MG_manual_motion_in_reference_mode
  O      MG_guard_has_been_opened
  O      MG_pneumatic_source_inactive  ;20120808
  IFT
    L      DG_feed_service
    =      NP_D596_max_feed_rate_PLC
  ENDI

  LN     MG_NC_axes_in_position
  A      PN_M4007_S_M05_nominal_0_and_status
  =      PN_error_M3_M4_missing
  IFT
    L      ML_M31_processing_without_M3_M4
    O      MG_feed_monitoring_M3_M4_inactive
    A      PN_M4007_S_M05_nominal_0_and_status
    R      PN_error_M3_M4_missing

    L      ML_feed_release_axes
    O      NP_M4180_F_max_programmed
    O      MG_TC_magazine_n_start_active
    O      NP_M4070_strobe_G_code
    O      NP_M4072_strobe_M_function
    O      NP_M4073_strobe_TOOL_CALL
    O      NP_M4175_control_in_operation_flashes
    ON     NP_M4176_control_in_operation_on_or_flashes
    O      PN_M4005_S_M03_nominal_and_status
    O      PN_M4006_S_M04_nominal_and_status
    O      NP_M4030_tapping_cycle_active
    O      NP_M4031_tapping_cycle_controlled
    R      PN_error_M3_M4_missing
  ENDI

#if CFG_override_rapid_traverse_instead_spindle  = "active"
  L      NP_W494_factor_feed_override_NC
  ==     K+0
  AN     NP_M4180_F_max_programmed
  O[
    L      NP_W752_rapid_traverse_override_PLC
    ==     K+0
    A      NP_M4180_F_max_programmed
  ]
  PSL
#else
  L      MG_MP7620_TE_with_Fmax_override
  IFT
    L      NP_W494_factor_feed_override_NC
    ==     K+0
    AN     NP_M4180_F_max_programmed
    O[
      L      NP_W752_rapid_traverse_override_PLC
      ==     K+0
      A      NP_M4180_F_max_programmed
    ]
    PSL
  ELSE
    L      NP_W494_factor_feed_override_NC
    ==     K+0
    PSL
  ENDI
#endif

  PLL
  RN     PN_error_override_0
  RN     ML_key_NC_start
  IFT
    L      NP_M4158_mode_block_scan
    O      MG_TC_help
    O      MG_PC_help
    EMT

    L      PN_D1144_manual_motion_plus
    O      PN_D1148_manual_motion_minus
    <>     K+0
    S      PN_error_override_0

    L      MG_key_NC_start
    S      ML_key_NC_start

    L      MG_automatic_mode
    O      NP_M4155_mode_pass_over_reference
    AN     MG_axes_in_position
    A      ML_key_NC_start
    S      PN_error_override_0

    LN     MG_axes_in_position
    R      ML_key_NC_start
  ENDI

EM
