*-----------------------------------------------------------------------------
*  Pallet change help - service
*-----------------------------------------------------------------------------
*  Module Description
*    In manual mode it is possible to start several tool changer functions
*    by using a selected help file (SERVICE.HLP>.
*-----------------------------------------------------------------------------

#define       KL_absolute_with_software_limit_switch   K%010

#define /s    ML_PC_posit_Z                            M
#define /s    ML_PC_posit_Y                            M
#define /s    ML_PC_posit_X                            M
#define /s    ML_PC_posit_4                            M
#define /s    ML_key_NC_start_stop                     M
#define /s    ML_key_NC_start_stop_p_pulse             M
#define /s    ML_PC_to_down_position                   M
#define /s    ML_PC_to_up_position                     M
#define /s    ML_PC_to_position_1                      M
#define /s    ML_PC_to_position_2                      M
#define /s    ML_PC_unclamp                            M
#define /s    ML_PC_clamp                              M
#define /s    ML_PC_basic_position                     M
#define /s    ML_function_on                           M
#define /s    ML_key_pressed                           M
#define /s    ML_pallet_in_middle_unclamped            M
#define /s    ML_pallet_middle_to_down                 M
#define /s    ML_pallet_oil_pressure_low               M

#define /s /r ML_PC_pallet_in_machine_unclamping       M

#define /s    BL_step_PC_help                          B

#include Mac_Lib.inc

EXTERN Absolute

GLOBAL PC_help
GLOBAL PC_output_restore
GLOBAL PC_output_backup

;----------------------------
LBL PC_help
;----------------------------

  L      MG_pallet_change_alternat_table_inactive
  EMT

  L      NP_M4172_1st_PLC_run_after_power_on
  O      NP_M4173_1st_PLC_run_after_compile
  O      NP_M4174_1st_PLC_run_after_MP_edit
  O      MG_p_pulse_control_operational
  CMT    PC_initial

  L      MG_key_NC_stop
  A      MG_key_NC_start
  AN     ML_key_NC_start_stop
  =      ML_key_NC_start_stop_p_pulse

  L      MG_key_NC_stop
  A      MG_key_NC_start
  =      ML_key_NC_start_stop

  CM     PC_basic_position

  L      PN_error_function_ok
  A      MG_PC_help
  R      PN_error_function_ok

  L      NP_W270_help_file_line_number
  /      K+100
  <>     K+6
  A      MG_PC_help
  CMT    PC_service_reset

  L      NP_W270_help_file_line_number
  /      K+100
  ==     K+6
  A[
    L      MG_manual_mode
    AN     MG_edit_mode
    O      MG_commissioning
  ]
  =      MG_PC_help
  R      PN_error_PC_standby_position
  EMF

  L      NP_W270_help_file_line_number
  MOD    K+100
  <>     BL_step_PC_help
  ON     MG_control_operational
  AN[
    L      ML_PC_to_down_position
    O      ML_PC_to_up_position
    O      ML_PC_to_position_1
    O      ML_PC_to_position_2
  ]
  CMT    PC_service_reset

  L      NP_W270_help_file_line_number
  MOD    K+100
  =      BL_step_PC_help

  L      I_PC_in_down_position
  A      I_key_enable_new_workpiece_on_pallet
  AN     ML_key_pressed
  O      ML_PC_to_up_position
  IFT
    S      ML_PC_to_up_position

    L      K+5
    =      BL_step_PC_help
  ENDI

  L      I_PC_in_up_position
  A      I_key_enable_new_workpiece_on_pallet
  AN     ML_key_pressed
  O      ML_PC_to_down_position
  IFT
    S      ML_PC_to_down_position

    L      K+8
    =      BL_step_PC_help
  ENDI

  L      I_PC_position_in_2
  O[
    LN     I_PC_position_in_1
    AN     I_PC_position_in_2
  ]
  A      I_key_PC_run
  A      I_PC_in_up_position
  AN     ML_key_pressed
  O      ML_PC_to_position_1
  IFT
    S      ML_PC_to_position_1

    L      K+6
    =      BL_step_PC_help
  ENDI

  L      I_PC_position_in_1
  A      I_key_PC_run
  A      I_PC_in_up_position
  AN     ML_key_pressed
  O      ML_PC_to_position_2
  IFT
    S      ML_PC_to_position_2

    L      K+7
    =      BL_step_PC_help
  ENDI

  L      I_PC_pallet_in_clamped
  A      I_key_PC_unclamp
  AN     ML_key_pressed
  O      ML_PC_unclamp
  IFT
    S      ML_PC_unclamp

    L      K+10
    =      BL_step_PC_help
  ENDI

  LN     I_PC_pallet_in_clamped
  A      I_key_PC_unclamp
  AN     ML_key_pressed
  O      ML_PC_clamp
  IFT
    S      ML_PC_clamp

    L      K+11
    =      BL_step_PC_help
  ENDI

  L      I_key_enable_new_workpiece_on_pallet
  O      I_key_PC_run
  O      I_key_PC_unclamp
  =      ML_key_pressed

;  L      ML_PC_to_down_position
;  O      ML_PC_to_up_position
;  O      ML_PC_to_position_1
;  O      ML_PC_to_position_2
;  A      PN_error_function_ok
;  CMT    PC_service_reset

  LN     MG_control_operational
  ON     I_guard_1_closed
  EMT

  CASE   BL_step_PC_help
    CM     PC_EndOfModule              ;00
    CM     Z_PC_posit_start            ;01
    CM     X_PC_posit_start            ;02
    CM     Y_PC_posit_start            ;03
    CM     C_PC_posit_start            ;04
    CM     PC_to_up_posit              ;05
    CM     PC_posit_1                  ;06
    CM     PC_posit_2                  ;07
    CM     PC_to_down_posit            ;08
    CM     PC_cone_air_pressure_test   ;09
    CM     PC_unclamp                  ;10
    CM     PC_clamp                    ;11
    CM     PC_up_to_middle_posit       ;12
  ENDC

LBL PC_EndOfModule

EM

;----------------------------
LBL Z_PC_posit_start                   ;01

  L      NP_D1116_reference_nesessary
  BT     KG_axis_Z
  =      PN_error_reference_necessary
  EMT

  CM     Z_in_PC_pos

  L      ML_PC_posit_Z
  =      PN_error_function_ok

  LN     MG_key_NC_start
  O      PN_M4122_strobe_PLC_posit_axis_Z
  EMT

  PS     KG_axis_Z
  PS     DG_PC_posit_Z
  PS     DG_feed_PLC_Z
  PS     KL_absolute_with_software_limit_switch
  CM     9221
  PLX

  M_display_module_error(KG_error_module_9221)

EM

;----------------------------
LBL Z_in_PC_pos

  L      DG_position_axis_Z_ref
  -      DG_PC_posit_Z
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_Z
  AN     PN_M4122_strobe_PLC_posit_axis_Z
  =      ML_PC_posit_Z

EM

;----------------------------
LBL X_PC_posit_start                   ;02

  L      NP_D1116_reference_nesessary
  BT     KG_axis_X
  =      PN_error_reference_necessary
  EMT

  CM     X_in_PC_Pos

  L      ML_PC_posit_X
  =      PN_error_function_ok

  LN     MG_key_NC_start
  O      PN_M4120_strobe_PLC_posit_axis_X
  EMT

  PS     KG_axis_X
  PS     DG_PC_posit_X
  PS     DG_feed_PLC_X
  PS     KL_absolute_with_software_limit_switch
  CM     9221
  PLX
  M_display_module_error(KG_error_module_9221)

EM

;----------------------------
LBL X_in_PC_pos

  L      DG_position_axis_X_ref
  -      DG_PC_posit_X
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_X
  AN     PN_M4120_strobe_PLC_posit_axis_X
  =      ML_PC_posit_X

EM

;----------------------------
LBL Y_PC_posit_start                   ;03

  L      NP_D1116_reference_nesessary
  BT     KG_axis_Y
  =      PN_error_reference_necessary
  EMT

  CM     Y_in_PC_Pos

  L      ML_PC_posit_Y
  =      PN_error_function_ok

  LN     MG_key_NC_start
  O      PN_M4121_strobe_PLC_posit_axis_Y
  EMT

  PS     KG_axis_Y
  PS     DG_PC_posit_Y
  PS     DG_feed_PLC_Y
  PS     KL_absolute_with_software_limit_switch
  CM     9221
  PLX
  M_display_module_error(KG_error_module_9221)

EM

;----------------------------
LBL Y_in_PC_pos

  L      DG_position_axis_Y_ref
  -      DG_PC_posit_Y
  PSW
  CM     Absolute
  PLW
  <      DG_MP1030_pos_window_Y
  AN     PN_M4121_strobe_PLC_posit_axis_Y
  =      ML_PC_posit_Y

EM

;----------------------------
LBL C_PC_posit_start

EM

;----------------------------
LBL PC_to_up_posit                     ;05

  CM     Z_in_PC_Pos
  CM     Y_in_PC_Pos
  CM     X_in_PC_Pos

  LN     ML_PC_posit_Z
  =      MG_win_PC_posit_Z

  LN     ML_PC_posit_Y
  =      MG_win_PC_posit_Y

  LN     ML_PC_posit_X
  =      MG_win_PC_posit_X

  L      I_PC_position_in_1
  O      I_PC_dec_speed_pos_1
  XON[
    L      I_PC_position_in_2
    O      I_PC_dec_speed_pos_2
  ]
  O[
    LN     I_PC_position_in_1
    AN     I_PC_position_in_2
  ]
  =      MG_win_PC_neither_pos_1_nor_pos_2

  L      MG_marker_one
  S      TS_PC_pallet_unclamping

  LN     MG_win_PC_posit_Z
  AN     MG_win_PC_posit_Y
  AN     MG_win_PC_posit_X
  AN     MG_win_PC_neither_pos_1_nor_pos_2
  A      I_PC_load_door_closed
  A[
    L      I_key_enable_new_workpiece_on_pallet
    O      MG_key_NC_start
    A      MG_manual_mode
  ]
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  A[
    L      O_PC_pallet_in_machine_unclamping
    AN     I_PC_pallet_in_clamped
    O[
      L      I_PC_pallet_in_clamped
      AN     ML_pallet_in_middle_unclamped
    ]
  ]
  AN     ML_function_on
  S      O_PC_table_up
  R      O_PC_table_down
  S      ML_function_on

  LN     I_PC_position_in_1
  AN     I_PC_position_in_2
  R      O_PC_to_position_1
  R      O_PC_to_position_2

  L      I_PC_in_middle_position
  A      ML_function_on
  AN     ML_pallet_in_middle_unclamped
  S      O_PC_pallet_in_machine_unclamping
  R      O_PC_table_up
  R      O_PC_table_down
  R      TS_PC_pallet_unclamping

  LN     TS_PC_pallet_unclamping
  AN     TR_PC_pallet_unclamping
  A      I_PC_in_middle_position
  AN     I_PC_pallet_in_clamped
  S      ML_pallet_in_middle_unclamped
  S      O_PC_table_up
  R      O_PC_table_down

  L      ML_pallet_in_middle_unclamped
  AN     I_PC_in_middle_position
  AN     I_PC_in_up_position
  A      I_PC_load_door_closed
  A      I_ESA_control_operational
  =      O_PC_air_blast

  LN     I_PC_load_door_closed
  ON     I_ESA_control_operational
  O      MG_key_NC_stop_p_pulse
  R      O_PC_table_up
  R      ML_function_on

  LN     I_PC_in_down_position
  A      I_PC_in_up_position
  AN     I_PC_in_middle_position
  AN     I_PC_pallet_in_clamped
  R      ML_pallet_in_middle_unclamped
  R      ML_function_on
  R      ML_PC_to_up_position
  =      PN_error_function_ok

EM

;----------------------------
LBL PC_up_to_middle_posit              ;12

  CM     Z_in_PC_Pos
  CM     Y_in_PC_Pos
  CM     X_in_PC_Pos

  LN     ML_PC_posit_Z
  =      MG_win_PC_posit_Z

  LN     ML_PC_posit_Y
  =      MG_win_PC_posit_Y

  LN     ML_PC_posit_X
  =      MG_win_PC_posit_X

  L      MG_marker_one
  S      TS_PC_pallet_unclamping

  L      I_PC_position_in_1
  O      I_PC_dec_speed_pos_1
  XON[
    L      I_PC_position_in_2
    O      I_PC_dec_speed_pos_2
  ]
  O[
    LN     I_PC_position_in_1
    AN     I_PC_position_in_2
  ]
  =      MG_win_PC_neither_pos_1_nor_pos_2

  LN     MG_win_PC_posit_Z
  AN     MG_win_PC_posit_Y
  AN     MG_win_PC_posit_X
  AN     MG_win_PC_neither_pos_1_nor_pos_2
  A      I_PC_load_door_closed
  A[
    L      MG_key_NC_start
    A      MG_manual_mode
  ]
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  AN     ML_function_on
  S      O_PC_table_up
  R      O_PC_table_down
  S      ML_function_on

  LN     I_PC_position_in_1
  AN     I_PC_position_in_2
  R      O_PC_to_position_1
  R      O_PC_to_position_2

  LN     I_PC_load_door_closed
  ON     I_ESA_control_operational
  O      MG_key_NC_stop_p_pulse
  R      O_PC_table_up
  R      ML_function_on

  LN     I_PC_in_down_position
  AN     I_PC_in_up_position
  A      I_PC_in_middle_position
  R      ML_function_on
  R      O_PC_table_up
  R      ML_PC_to_up_position
  =      PN_error_function_ok

EM

;----------------------------
LBL PC_posit_1                         ;06

  LN     I_PC_in_up_position
  =      MG_win_PC_to_up_position

  LN     MG_win_PC_to_up_position
  A      I_PC_load_door_closed
  A[
    L      MG_key_NC_start
    O      I_key_PC_run
  ]
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  S      O_PC_to_position_1
  R      O_PC_to_position_2

  L      MG_marker_one
  S      TS_delay_slow_motion

  LN     I_PC_load_door_closed
  ON     I_ESA_control_operational
  O      MG_key_NC_stop_p_pulse
  R      O_PC_to_position_1
  R      ML_PC_to_position_1

  L      I_PC_position_in_1
  R      ML_PC_to_position_1
  =      PN_error_function_ok

EM

;----------------------------
LBL PC_posit_2                         ;07

  LN     I_PC_in_up_position
  =      MG_win_PC_to_up_position

  LN     MG_win_PC_to_up_position
  A      I_PC_load_door_closed
  A[
    L      MG_key_NC_start
    O      I_key_PC_run
  ]
  O[
    L      MG_key_NC_stop
    A      MG_key_NC_start
  ]
  S      O_PC_to_position_2
  R      O_PC_to_position_1

  L      MG_marker_one
  S      TS_delay_slow_motion

  LN     I_PC_load_door_closed
  ON     I_ESA_control_operational
  O      MG_key_NC_stop_p_pulse
  R      O_PC_to_position_2
  R      ML_PC_to_position_2

  L      I_PC_position_in_2
  R      ML_PC_to_position_2
  =      PN_error_function_ok

EM

;----------------------------
LBL PC_to_down_posit                   ;8

  L      I_PC_pallet_in_clamped
  AN     ML_pallet_middle_to_down
  AN     I_PC_in_down_position
  =      MG_win_PC_pallet_unclamping_in_machine

  L      I_PC_position_in_1
  O      I_PC_dec_speed_pos_1
  XON[
    L      I_PC_position_in_2
    O      I_PC_dec_speed_pos_2
  ]
  O[
    LN     I_PC_position_in_1
    AN     I_PC_position_in_2
  ]
  =      MG_win_PC_neither_pos_1_nor_pos_2

  LN     MG_win_PC_neither_pos_1_nor_pos_2
  A      I_PC_load_door_closed
  A[
    L      I_key_enable_new_workpiece_on_pallet
    O      MG_key_NC_start
    A      MG_manual_mode
  ]
  AN     ML_function_on
  S      O_PC_pallet_in_machine_unclamping
  S      ML_function_on

  LN     I_PC_position_in_1
  AN     I_PC_position_in_2
  R      O_PC_to_position_1
  R      O_PC_to_position_2

  LN     ML_pallet_middle_to_down
  AN     I_PC_pallet_in_clamped
  O      ML_pallet_middle_to_down
  A      ML_function_on
  S      O_PC_table_down
  R      O_PC_table_up

  L      ML_pallet_middle_to_down
  AN     I_PC_in_middle_position
  R      O_PC_pallet_in_machine_unclamping

  LN     ML_pallet_middle_to_down
  A      ML_function_on
  =      O_PC_air_blast

  L      I_PC_in_middle_position
  S      ML_pallet_middle_to_down

  LN     I_PC_load_door_closed
  ON     I_ESA_control_operational
  O      MG_key_NC_stop_p_pulse
  R      O_PC_table_down
  R      O_PC_air_blast
  R      ML_function_on

  L      I_PC_in_down_position
  R      O_PC_pallet_in_machine_unclamping
  R      O_PC_air_blast
  R      O_PC_table_up
  R      ML_function_on
  R      ML_pallet_middle_to_down
  R      ML_PC_to_down_position
  =      PN_error_function_ok

EM

;----------------------------
LBL PC_cone_air_pressure_test          ;9

  L      MG_marker_one
  R      MG_win_PC_pallet_clamping_in_machine
  R      MG_win_PC_pallet_unclamping_in_machine

  L      MG_key_NC_start_p_pulse
  S      O_PC_air_blast
  =      TS_PC_cone_air_blast_pressure

  LN     TS_PC_cone_air_blast_pressure
  AN     TR_PC_cone_air_blast_pressure
  A      I_PC_in_down_position
  A      I_PC_cone_air_pressure_ok
  =      PN_error_function_ok

EM

;----------------------------
LBL PC_unclamp                         ;10

  L      I_key_PC_unclamp
  O      MG_key_NC_start
  A      MG_manual_mode
  S      O_PC_pallet_in_machine_unclamping

  LN     I_PC_pallet_in_clamped
  R      ML_PC_unclamp
  =      PN_error_function_ok

EM

;----------------------------
LBL PC_clamp                           ;11

  LN     I_PC_in_down_position
  =      MG_win_PC_to_down_position

  L      I_key_PC_unclamp
  O      MG_key_NC_start
  A      MG_manual_mode
  A      I_PC_in_down_position
  R      O_PC_pallet_in_machine_unclamping

  L      I_PC_pallet_in_clamped
  R      ML_PC_clamp
  =      PN_error_function_ok

EM

;----------------------------
LBL PC_basic_position

  L      I_PC_position_in_1
  A      I_PC_dec_speed_pos_1
  XO[
    L      I_PC_position_in_2
    A      I_PC_dec_speed_pos_2
  ]
  AN     O_PC_pallet_in_machine_unclamping
  A      I_PC_pallet_in_clamped
  A      I_PC_in_down_position
  AN     I_PC_in_up_position
  AN     I_PC_in_middle_position
  =      ML_PC_basic_position

  L      ML_PC_basic_position
  A      I_PC_load_door_closed
  =      MG_PC_standby_position

  L      MG_PC_active
  O      MG_PC_help
  EMT

  LN     O_PC_pallet_in_machine_unclamping
  A      MG_power_delayed_on
  IFT
    LN     I_PC_pallet_in_clamped
    A      ML_pallet_oil_pressure_low
    AN     TS_PC_pallet_clamped_oil_pres_low
    AN     TR_PC_pallet_clamped_oil_pres_low
    A      MG_power_delayed_on
    S      PN_error_pallet_clamped_oil_pres_low

    LN     I_PC_pallet_in_clamped
    AN     ML_pallet_oil_pressure_low
    =      TS_PC_pallet_clamped_oil_pres_low

    LN     I_PC_pallet_in_clamped
    =      ML_pallet_oil_pressure_low
  ENDI

  LN     ML_PC_basic_position
  A      MG_power_delayed_on
  S      PN_error_PC_standby_position
  EMF

  L      I_PC_position_in_1
  O      I_PC_dec_speed_pos_1
  XON[
    L      I_PC_position_in_2
    O      I_PC_dec_speed_pos_2
  ]
  O[
    LN     I_PC_position_in_1
    AN     I_PC_position_in_2
  ]
  =      MG_win_PC_neither_pos_1_nor_pos_2

  LN     I_PC_in_down_position
  O      I_PC_in_up_position
  =      MG_win_PC_to_down_position

  LN     I_PC_pallet_in_clamped
  O      O_PC_pallet_in_machine_unclamping
  =      MG_win_PC_pallet_clamping_in_machine

EM

;----------------------------
LBL PC_service_reset

  L      MG_marker_one
  R      PN_M4120_strobe_PLC_posit_axis_X
  R      PN_M4121_strobe_PLC_posit_axis_Y
  R      PN_M4122_strobe_PLC_posit_axis_Z
  R      PN_M4123_strobe_PLC_posit_axis_4
  R      PN_error_function_ok
  R      MG_win_PC_posit_X
  R      MG_win_PC_posit_Y
  R      MG_win_PC_posit_Z
  R      MG_win_PC_posit_4
  R      MG_win_PC_neither_pos_1_nor_pos_2
  R      MG_win_PC_to_up_position
  R      MG_win_PC_to_down_position
  R      MG_win_PC_pallet_clamping_in_machine
  R      MG_win_PC_pallet_unclamping_in_machine
*  R      O_PC_to_position_2
*  R      O_PC_to_position_1
*  R      O_PC_table_slow_motion
*  R      O_PC_table_down
*  R      O_PC_pallet_in_machine_unclamping
  R      O_PC_air_blast
  R      O_PC_cone_air_blast
*  R      O_PC_table_up
  R      ML_PC_to_down_position
  R      ML_PC_to_up_position
  R      ML_PC_to_position_1
  R      ML_PC_to_position_2
  R      ML_PC_unclamp
  R      ML_PC_clamp
  R      ML_function_on

EM

;----------------------------
LBL PC_output_restore

  L      MG_pallet_change_alternat_table_inactive
  EMT

  L      ML_PC_pallet_in_machine_unclamping
  =      O_PC_pallet_in_machine_unclamping

EM

;----------------------------
LBL PC_output_backup

  L      MG_pallet_change_alternat_table_inactive
  EMT

*  LN     MG_control_operational
*  R      O_PC_pin_unlock
*  EMT

  L      O_PC_pallet_in_machine_unclamping
  =      ML_PC_pallet_in_machine_unclamping

EM

;----------------------------
LBL PC_initial

  L      I_PC_in_up_position
  AN     I_PC_in_middle_position
  AN     I_PC_in_down_position
  S      O_PC_table_up
  R      O_PC_table_down

  LN     I_PC_in_up_position
  AN     I_PC_in_middle_position
  A      I_PC_in_down_position
  R      O_PC_table_up
  S      O_PC_table_down
  R      O_PC_pallet_in_machine_unclamping

  L      I_PC_position_in_1
  AN     I_PC_position_in_2
  S      O_PC_to_position_1
  R      O_PC_to_position_2

  LN     I_PC_position_in_1
  A      I_PC_position_in_2
  R      O_PC_to_position_1
  S      O_PC_to_position_2

EM
