%%%
  VERSION: 1
  LANGUAGE: ENGLISH
%%%

MODULE SWDEFUSR (SYSMODULE, NOVIEW)

!---------------------------------------
! G L O B A L  D A T A
!--------------------------------------- 

  ! Definition of force data
  RECORD forcedata
    num tip_force;
    num force_time;
    num plate_thickness;
    num plate_tolerance;
  ENDRECORD

  ! Definition of simulate data
  RECORD simdata
    num sim_type;
    num sim_time;
    bool inhib_close;
    bool no_plates;
  ENDRECORD

  ! Definition of process spot data
  RECORD spotdata
    num prog_no;
    num tip_force;
    num plate_thickness;
    num plate_tolerance;
  ENDRECORD

  ! Definition of process gun data
  RECORD gundata
    string gun_name;
    num pre_close_time;
    num pre_equ_time;
    num weld_counter;
    num max_nof_welds;
    num curr_tip_wear;
    num max_tip_wear;
    num weld_timeout;
  ENDRECORD

  ! Description: 
  ! CONST string Version_XXXXXXXX := "1.2";
  !
  !          XXXXXXXX - Module name
  !                 1 - version number  (changed of SEROP) 
  !                 2 - revision number (changed of SEROP)
  CONST string Version_SWDEFUSR := "4.2";

  ! Allowed instruction parameter values
  ! These variable names is used
  ! internally. Don't change the names.
  PERS maxnum MAX_TIP_FORCE := 6000;
  CONST maxnum MAX_PRE_CLOSE_T := 0.5;
  CONST maxnum MAX_PRE_EQU_T := 0.1;
  CONST maxnum MAX_PLATE_THICK := 40;
  CONST maxnum MAX_PLATE_TOLER := 1;
  CONST maxnum MAX_PROG_NO := 64;
  CONST minnum MIN_WELD_TOUT := 2;
  CONST maxnum MAX_WELD_TOUT := 10;
  CONST minnum MIN_FORCE_T := 0.05;
  CONST maxnum MAX_FORCE_T := 10;

  ! Number of defined guns.
  ! The variable name is used internally.
  ! Don't change the name.
  CONST num SW_NOF_GUNS := 2;

  ! Active gun when SpotL/J is used.
  ! These variable names is used
  ! internally. Don't change the names.
  PERS gunnum gun1 := 1;
  PERS gunnum gun2 := 2;

  ! Automatic reweld: Number of automatic tries to reweld
  ! after weld_complete timeout.
  ! This variable name is used internally.
  ! Don't change the name.
  PERS num auto_reweld := 0;

  ! Program parity: 0 = none, 1 = odd, 2 = even
  ! This variable name is used internally.
  ! Don't change the name.
  PERS num prog_num_parity := 0;

  ! If the equalize signal should be set/reset from the process kernel
  ! then set this variable to TRUE
  ! This variable name is used internally.
  ! Don't change the name.
  PERS bool manage_equalize := TRUE;

  ! Spotdata
  PERS spotdata spot1:=[1, 1000, 0, 0];

  ! Forcedata
  PERS forcedata force1:=[1000, 1, 0, 0];

  ! Reset pulse (s)
  PERS num reset_fault_time := 0.5;

  ! Wait time after reset pulse (s)
  PERS num reset_fault_idle := 0.5;

!----------------------------------------------------
! D A T A  D E F I N I T I O N  R O U T I N E S
!----------------------------------------------------

  ! These routines are used to connect user defined data component names to internal used names.

  ! Called in the beginnning of each Spot shell routine.
  PROC DefineSpotData (spotdata Spot, num GunNum)

    int_spotdata{GunNum}.prog_no:= 		Spot.prog_no;
    int_spotdata{GunNum}.tip_force:= 		Spot.tip_force;
    int_spotdata{GunNum}.plate_thickness:= 	Spot.plate_thickness;
    int_spotdata{GunNum}.plate_tolerance:= 	Spot.plate_tolerance;

  ENDPROC

  ! Called just before execution of SwPowerOn, SwStart or SwReStart.
  PROC DefineGunData ()

    FOR i FROM 1 TO SW_NOF_GUNS DO
      int_gundata{i}.gun_name :=		curr_gundata{i}.gun_name;
      int_gundata{i}.gun_type := 1;
      int_gundata{i}.pre_close_time :=		curr_gundata{i}.pre_close_time;
      int_gundata{i}.pre_equ_time :=		curr_gundata{i}.pre_equ_time;
      int_gundata{i}.weld_timeout:= 		curr_gundata{i}.weld_timeout;
    ENDFOR

  ENDPROC

  ! Called in the beginnning of each SetForce instruction.
  PROC DefineForceData (forcedata Force, num GunNum)

    int_forcedata{GunNum}.tip_force:= 			Force.tip_force;
    int_forcedata{GunNum}.force_time:= 			Force.force_time;
    int_forcedata{GunNum}.plate_thickness:= 		Force.plate_thickness;
    int_forcedata{GunNum}.plate_tolerance:= 		Force.plate_tolerance;

  ENDPROC

  ! Called just before execution of SwPowerOn, SwStart or SwReStart.
  ! Also called in the beginning of all shell routines if they are
  ! not equal.
  PROC DefineSimData ()

    int_simdata.sim_type :=			curr_simdata.sim_type;
    int_simdata.sim_time :=			curr_simdata.sim_time;
    int_simdata.inhib_close :=			curr_simdata.inhib_close;
    int_simdata.no_plates :=			curr_simdata.no_plates;

  ENDPROC

!------------------------------------------------------
! U P D A T E  P R O C E S S  D A T A   R O U T I N E S
!------------------------------------------------------

  ! Update current tipwear in curr_gundata.
  ! Called at the end of each CalibL/J and Calib instruction.
  PROC UpdateCalibData (num CurrTipWear,
                        num GunNum
  			\switch ToolChg | switch TipChg | switch TipWear)

    curr_gundata{GunNum}.curr_tip_wear :=	CurrTipWear;

  ENDPROC

  ! Update curr_spotdata.
  ! Called at the start of motion.
  PROC UpdateSpotData (z_int_spotdata Spot, num GunNum)

    curr_spotdata{GunNum}.prog_no :=		Spot.prog_no;
    curr_spotdata{GunNum}.tip_force :=		Spot.tip_force;
    curr_spotdata{GunNum}.plate_thickness :=	Spot.plate_thickness;
    curr_spotdata{GunNum}.plate_tolerance :=	Spot.plate_tolerance;

  ENDPROC

ENDMODULE
