*-----------------------------------------------------------------------------
*  Warm up
*-----------------------------------------------------------------------------
*  Module Description
*    Spindle off time > KL_daily_timer  -> Run daily procedure
*
*-----------------------------------------------------------------------------

#define /s    KL_daily_timer                           K+28800

#define /s    ML_servo_drive_S_status                  M
#define /s    ML_S_warm_up_commanded                   M
#define /s    ML_S_warm_up_required                    M

#define /s /r DL_Time_at_spindle_stop                  D
#define /s    DL_S_off_time                            D
#define /s    DL_S_W_start_key                         D
#define /s    DL_S_W_stop_key                          D

#define /s    BL_S_warm_up_macro                       B

#include Mac_Lib.inc

GLOBAL Warm_up

;----------------------------
LBL Warm_up
;----------------------------

  LN     MG_spindle_active
  ON     MG_machine_parameter_are_read
  EMT

  L      ML_servo_drive_S_status
  AN     O_servo_drive_release_S1
  AN     ML_S_warm_up_required
  IFT
    L      DG_real_time
    =      DL_Time_at_spindle_stop
  ENDI

  L      O_servo_drive_release_S1
  =      ML_servo_drive_S_status

  L      O_servo_drive_release_S1
  IFT
    L      K+0
    =      DL_S_off_time
  ENDI

  LN     O_servo_drive_release_S1
  IFT
    L      DG_real_time
    -      DL_Time_at_spindle_stop
    =      DL_S_off_time
  ENDI

  LN     MG_reference_axes_traversed
  EMT

  L      DL_S_off_time
  >=     KL_daily_timer
  S      MG_S_daily_warm_up_required

  L      MG_S_daily_warm_up_required
  =      ML_S_warm_up_required

  L      MG_key_spindle_M3
  A      ML_S_warm_up_required
  O      MG_SK_warm_up
  A      MG_manual_mode
  AN     MG_S_W_macro_running
  IFT
    L      MG_pulse_1_S
    IFT
      INC    DL_S_W_start_key
    ENDI

    L      DL_S_W_start_key
    >=     K+3
    S      MG_win_balance_tool_yes_no
  ELSE
    L      K+0
    =      DL_S_W_start_key
  ENDI

  L      MG_SK_warm_up
  S      MG_win_balance_tool_yes_no

  L      NP_M4153_mode_program_run_single_block
  O      NP_M4154_mode_program_run_full_sequence
  O      MG_auto_manu_mode_change
  O      PN_M4005_S_M03_nominal_and_status
  O      PN_M4006_S_M04_nominal_and_status
  A      ML_S_warm_up_required
  AN     PN_error_S_warm_up_running
  S      PN_error_S_warm_up_required
  R      PN_M4005_S_M03_nominal_and_status
  R      PN_M4006_S_M04_nominal_and_status
  S      PN_M4007_S_M05_nominal_0_and_status

  L      MG_win_balance_tool_yes_no
  A      MG_key_NC_start_p_pulse
  S      ML_S_warm_up_commanded
  R      MG_win_balance_tool_yes_no
  R      PN_error_S_warm_up_required

  L      MG_key_NC_stop_p_pulse
  R      MG_win_balance_tool_yes_no
  R      MG_SK_warm_up

  L      WG_number_active_NC_macro
  ==     K+1101
  =      PN_error_S_warm_up_running

  L      MG_key_spindle_M5
  A      MG_key_NC_stop
  A      ML_S_warm_up_required
  A      MG_manual_mode
  AN     NP_M4176_control_in_operation_on_or_flashes
  IFT
    L      MG_pulse_1_S
    IFT
      INC    DL_S_W_stop_key
    ENDI

    L      DL_S_W_stop_key
    >=     K+10
    R      MG_win_balance_tool_yes_no
    R      PN_error_S_warm_up_required
    R      PN_error_S_warm_up_running
    R      ML_S_warm_up_commanded
    R      MG_S_daily_warm_up_required
    IFT
      L      K+0
      =      DL_S_off_time
      L      DG_real_time
      =      DL_Time_at_spindle_stop
    ENDI
  ELSE
    L      K+0
    =      DL_S_W_stop_key
  ENDI

  L      ML_S_warm_up_commanded
  IFT
    SUBM   S_warm_up_macro
    =      BL_S_warm_up_macro
    ==     K+0
    S      PN_error_submit_spawn_queue_full
    RN     ML_S_warm_up_commanded
  ENDI

  L      PN_error_S_warm_up_running
  IFT
    L      K+10000                     ;100%
    =      PN_W764_S_override_PLC
  ENDI

EM

;----------------------------
LBL S_warm_up_macro

  PS     S"WARM_UP"
  CM     9291
  M_display_module_error(KG_error_module_9291)

EM
