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

MODULE PAL_CYC
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  !                                       !
  ! MODULE PAL_CYC  : Cycle definitions   !
  !                                       !
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  !
  !  Module data
  !
  PERS bool CycMReloaded:=TRUE;
  !
  !  User routine names
  !
  CONST num ROUTINE_NB:=14;
  VAR string ROUTINE_NAMES{ROUTINE_NB}:=["rfeeder_in","rfeeder_out","rpstack_in","rpstack_out","rpallet_in","rpallet_out","rstack_search","rpal_start","rpal_end","rlayer_start","rlayer_end","rbef_pic_plac","rbetw_pic_plac","rafter_pic_plac"];
  !
  !  Layer cycles names
  !
  CONST num NBPALLAYER:=4;
  VAR string all_layer_names{NBPALLAYER}:=["LayPal","LayB1","LayB2","ABBlayer"];
  !
  !  Pallet cycles names
  !
  CONST num NBPALCYC:=2;
  PERS num NbPalCycScr:=2;
  PERS string PalCyc_names{NBPALCYC}:=["PalABB1","PalABB2"];
  !
  !  Pallet cycles
  !
  !  Pallet cycle definition
CONST pallet_cyc_def  PalABB1_def:=[PALLETIZE,18,2,8,0,9,0,2,TRUE,ALIGN_CENTER,ALIGN_CENTER,0,0,TRUE,FALSE];

  !  Layer cycle definition
CONST layer_cyc_def  LayPal_def:=[FALSE,FALSE,1,1,2,7,10,0,11,0,12,0,13,0,14,0];

  !  Pick and place definition
CONST pp_cyc_def  LayPal_1:=[4,1,1,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  LayPal_1_pk1:=[1,1,90,0,0,0,600,0,0,0.5,0,0,0,[0,-0.5,0.5,0,600,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  LayPal_1_pl1:=[1,0,90,0,0,0,600,0,0,0.5,0,0,0,[0,0,0.5,0,0,0,0,0,0,0,0,0,0,0,0]];

  !  Layer cycle definition
CONST layer_cyc_def  LayB1_def:=[TRUE,FALSE,3,9,1,0,10,0,11,0,12,0,13,0,14,0];

  !  Pick and place definition
CONST pp_cyc_def  LayB1_1:=[1,1,1,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  LayB1_1_pk1:=[3,1023,90,0,0,0,587,0,0,0.5,0,0,0,[0,-1.5,0.5,0,587,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  LayB1_1_pl1:=[3,0,90,0,0,0,587,0,0,0.5,0,0,0,[0,0,0.5,0,10,0,0,0,0,0,0,0,0,0,0]];

  !  Pick and place definition
CONST pp_cyc_def  LayB1_2:=[1,1,1,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  LayB1_2_pk1:=[3,1023,90,0,0,0,587,0,0,0.5,0,0,0,[0,-1.5,0.5,0,587,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  LayB1_2_pl1:=[3,0,90,0,0,0,587,0,0,1.5,0,0,-1,[0,0,0.5,0,10,0,0,0,0,0,0,0,0,0,0]];

  !  Pick and place definition
CONST pp_cyc_def  LayB1_3:=[1,1,1,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  LayB1_3_pk1:=[3,1023,90,0,0,0,587,0,0,0.5,0,0,0,[0,-1.5,0.5,0,587,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  LayB1_3_pl1:=[3,0,90,0,0,0,587,0,0,2.5,0,0,-1,[0,0,0.5,0,10,0,0,0,0,0,0,0,0,0,0]];

  !  Pallet cycle definition
CONST pallet_cyc_def  PalABB2_def:=[PALLETIZE,13,2,8,0,9,0,2,TRUE,ALIGN_CENTER,ALIGN_CENTER,0,0,TRUE,FALSE];

  !  Layer cycle definition
CONST layer_cyc_def  LayB2_def:=[TRUE,FALSE,3,9,1,0,10,0,11,0,12,0,13,0,14,0];

  !  Pick and place definition
CONST pp_cyc_def  LayB2_1:=[1,1,2,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  LayB2_1_pk1:=[3,1023,90,0,0,0,530,0,0,0.5,0,0,0,[0,-1.5,0.5,0,530,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  LayB2_1_pl1:=[2,896,90,0,0,0,530,0,0,0.5,0,0,0,[0,-2.5,0.5,0,530,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  LayB2_1_pl2:=[1,0,-90,0,3,0,-530,0,0,0.5,0,-1,0,[0,0,0.5,0,10,0,0,0,0,0,0,0,0,0,0]];

  !  Pick and place definition
CONST pp_cyc_def  LayB2_2:=[1,1,2,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  LayB2_2_pk1:=[3,1023,90,0,0,0,530,0,0,0.5,0,0,0,[0,-1.5,0.5,0,530,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  LayB2_2_pl1:=[2,896,90,0,0,0,530,0,0,1.5,0,0,-1,[0,-2.5,0.5,0,530,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  LayB2_2_pl2:=[1,0,-90,0,3,0,-530,0,0,1.5,0,-1,-1,[0,0,0.5,0,10,0,0,0,0,0,0,0,0,0,0]];

  !  Pick and place definition
CONST pp_cyc_def  LayB2_3:=[1,1,2,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  LayB2_3_pk1:=[3,1023,90,0,0,0,530,0,0,0.5,0,0,0,[0,-1.5,0.5,0,530,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  LayB2_3_pl1:=[2,896,90,0,0,0,530,0,0,2.5,0,0,-1,[0,-2.5,0.5,0,530,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  LayB2_3_pl2:=[1,0,-90,0,3,0,-530,0,0,2.5,0,-1,-1,[0,0,0.5,0,10,0,0,0,0,0,0,0,0,0,0]];

  !  Layer cycle definition
CONST layer_cyc_def  ABBlayer_def:=[TRUE,FALSE,4,4,1,0,10,0,11,0,12,0,13,0,14,0];

  !  Pick and place definition
CONST pp_cyc_def  ABBlayer_1:=[1,1,1,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  ABBlayer_1_pk1:=[1,120,90,0,0,0,202,0,0,0.5,0,0,0,[0,-0.5,0.5,0,202,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  ABBlayer_1_pl1:=[1,0,90,0,0,0,202,0,0,0.5,0,0,0,[0,0,0.5,0,10,0,0,0,0,0,0,0,0,0,0]];

  !  Pick and place definition
CONST pp_cyc_def  ABBlayer_2:=[1,1,1,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  ABBlayer_2_pk1:=[1,120,90,0,0,0,202,0,0,0.5,0,0,0,[0,-0.5,0.5,0,202,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  ABBlayer_2_pl1:=[1,0,90,0,1,0,202,0,0,0.5,0,-1,0,[0,0,0.5,0,10,0,0,0,0,0,0,0,0,0,0]];

  !  Pick and place definition
CONST pp_cyc_def  ABBlayer_3:=[1,1,1,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  ABBlayer_3_pk1:=[1,120,90,0,0,0,202,0,0,0.5,0,0,0,[0,-0.5,0.5,0,202,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  ABBlayer_3_pl1:=[1,0,90,0,0,0,202,0,0,1.5,0,0,-1,[0,0,0.5,0,10,0,0,0,0,0,0,0,0,0,0]];

  !  Pick and place definition
CONST pp_cyc_def  ABBlayer_4:=[1,1,1,FALSE,0];

  !  Pick or Place cycle data
  !  Pick cycle data
CONST pp_action  ABBlayer_4_pk1:=[1,120,90,0,0,0,202,0,0,0.5,0,0,0,[0,-0.5,0.5,0,202,0,0,0,0,0,0,0,0,0,0]];

  !  Place cycle data
CONST pp_action  ABBlayer_4_pl1:=[1,0,90,0,1,0,202,0,0,1.5,0,-1,-1,[0,0,0.5,0,10,0,0,0,0,0,0,0,0,0,0]];

  !  Pallet cycle pallet station list
  PROC PalABB1_sta(
  num index,
  INOUT num n)

  VAR num stat_nb{2}:=[4,5];
  
  IF (index=0) THEN
    n:=Dim(stat_nb,1);
  ELSEIF ((index>=1) AND (index<=Dim(stat_nb,1))) THEN
    n:=stat_nb{index};
  ELSE
    n:=-1;
  ENDIF
  ENDPROC

  !  Pallet cycle layer cycle list
  PROC PalABB1_lay(
  num index,
  INOUT num n)

  VAR num layers_nb{3}:=[1,2,2];
  
  IF (index=0) THEN
    n:=Dim(layers_nb,1);
  ELSEIF ((index>=1) AND (index<=Dim(layers_nb,1))) THEN
    n:=layers_nb{index};
  ELSE
    n:=-1;
  ENDIF
  ENDPROC

  !  Layer cycle enveloppe definition
  PROC LayPal_env(
  num prod_l,
  num prod_w,
  num base_x,
  num base_y,
  INOUT num env_x,
  INOUT num env_y)

  env_x:=prod_l;
  env_y:=prod_w;
  ENDPROC

  !  Layer cycle stack/feeder station list
  PROC LayPal_sta(
  num index,
  INOUT num n)

  VAR num stat_nb{1}:=[3];
  
  IF (index=0) THEN
    n:=Dim(stat_nb,1);
  ELSEIF ((index>=1) AND (index<=Dim(stat_nb,1))) THEN
    n:=stat_nb{index};
  ELSE
    n:=-1;
  ENDIF
  ENDPROC

  !  Layer cycle enveloppe definition
  PROC LayB1_env(
  num prod_l,
  num prod_w,
  num base_x,
  num base_y,
  INOUT num env_x,
  INOUT num env_y)

  env_x:=3*prod_l;
  env_y:=3*prod_w;
  ENDPROC

  !  Layer cycle stack/feeder station list
  PROC LayB1_sta(
  num index,
  INOUT num n)

  VAR num stat_nb{1}:=[1];
  
  IF (index=0) THEN
    n:=Dim(stat_nb,1);
  ELSEIF ((index>=1) AND (index<=Dim(stat_nb,1))) THEN
    n:=stat_nb{index};
  ELSE
    n:=-1;
  ENDIF
  ENDPROC

  !  Pallet cycle pallet station list
  PROC PalABB2_sta(
  num index,
  INOUT num n)

  VAR num stat_nb{2}:=[4,5];
  
  IF (index=0) THEN
    n:=Dim(stat_nb,1);
  ELSEIF ((index>=1) AND (index<=Dim(stat_nb,1))) THEN
    n:=stat_nb{index};
  ELSE
    n:=-1;
  ENDIF
  ENDPROC

  !  Pallet cycle layer cycle list
  PROC PalABB2_lay(
  num index,
  INOUT num n)

  VAR num layers_nb{3}:=[1,3,4];
  
  IF (index=0) THEN
    n:=Dim(layers_nb,1);
  ELSEIF ((index>=1) AND (index<=Dim(layers_nb,1))) THEN
    n:=layers_nb{index};
  ELSE
    n:=-1;
  ENDIF
  ENDPROC

  !  Layer cycle enveloppe definition
  PROC LayB2_env(
  num prod_l,
  num prod_w,
  num base_x,
  num base_y,
  INOUT num env_x,
  INOUT num env_y)

  env_x:=3*prod_l;
  env_y:=3*prod_w;
  ENDPROC

  !  Layer cycle stack/feeder station list
  PROC LayB2_sta(
  num index,
  INOUT num n)

  VAR num stat_nb{1}:=[2];
  
  IF (index=0) THEN
    n:=Dim(stat_nb,1);
  ELSEIF ((index>=1) AND (index<=Dim(stat_nb,1))) THEN
    n:=stat_nb{index};
  ELSE
    n:=-1;
  ENDIF
  ENDPROC

  !  Layer cycle enveloppe definition
  PROC ABBlayer_env(
  num prod_l,
  num prod_w,
  num base_x,
  num base_y,
  INOUT num env_x,
  INOUT num env_y)

  env_x:=2*prod_l;
  env_y:=2*prod_w;
  ENDPROC

  !  Layer cycle stack/feeder station list
  PROC ABBlayer_sta(
  num index,
  INOUT num n)

  VAR num stat_nb{2}:=[1,2];
  
  IF (index=0) THEN
    n:=Dim(stat_nb,1);
  ELSEIF ((index>=1) AND (index<=Dim(stat_nb,1))) THEN
    n:=stat_nb{index};
  ELSE
    n:=-1;
  ENDIF
  ENDPROC

  !  Empty routine for the RAPID to check if the module is loaded
  PROC Pal_Cyc0()

  ! Don't insert ANY instruction in that routine
  ENDPROC

ENDMODULE
