
FUNCTION_BLOCK FB22
VAR
    TR: ARRAY[0..4] OF BOOL; // tableau de transition
    flag_Z7_charg: BOOL;
    demandePalette: BOOL;
    init: INT :=7;

END_VAR

//Transition
TR[0]:= "G7_GestionSection".section_0[0] AND B_ASI20B1_presenceP0 AND 
            (NOT B_ASI20B3_presenceRack
            OR B_ASI20B3_presenceRack AND TypeRackSection(section:= 0, typeChariot:= 2)
            OR demandePalette
            OR ChariotZero404(section:=0)
            OR init >0); // 0 vers 2
TR[1]:= "G7_GestionSection".section_0[0] AND B_ASI20B1_presenceP0 AND B_ASI20B3_presenceRack AND NOT TR[0]; // 0 vers 1
TR[2]:= "G7_GestionSection".section_0[1] AND (NOT Z7_chargementEnCours AND flag_Z7_charg
                                              OR demandePalette AND NOT Z7_chargementEnCours
                                              OR init >0 ); // 1 vers 2
TR[3]:= "G7_GestionSection".section_0[2] AND "GestionChariotDB".nbChariotSection[1] <4 AND NOT B_ASI20B2_presenceP1; //2 vers 3
TR[4]:= "G7_GestionSection".section_0[3] AND NOT B_ASI20B1_presenceP0; // 3 vers 0
    
// étapes
IF TR[0] THEN // TR 0 vers 2
    "G7_GestionSection".section_0[0]:= false;
    "G7_GestionSection".section_0[2]:= true;
END_IF;
IF TR[1] THEN //TR 0 vers 1
    "G7_GestionSection".section_0[0]:= false;
    "G7_GestionSection".section_0[1]:= true;
END_IF;
IF TR[2] THEN //TR 1 vers 2
    "G7_GestionSection".section_0[1]:= false;
    "G7_GestionSection".section_0[2]:= true;
END_IF;
IF TR[3] THEN //TR 2 vers 3
    "G7_GestionSection".section_0[2]:= false;
    "G7_GestionSection".section_0[3]:= true;
END_IF;
IF TR[4] THEN //TR 3 vers 0
    "G7_GestionSection".section_0[3]:= false;
    "G7_GestionSection".section_0[0]:= true;
END_IF;

//prog
IF TR[0] AND init >0 THEN
    init := init -1;
END_IF;

//gestion demande palette (attention, doit être derrière la gestion front)
demandePalette:= (Z10_demandePaletteVide OR Z9_demandePaletteVide)
                   AND RackDansSection(section:=0, typeRack:=0) 
                   AND NOT RackDansSection(section:=1, typeRack:=0) 
                   AND NOT RackDansSection(section:=2, typeRack:=0);


//gestion front
flag_Z7_charg:= Z7_chargementEnCours;

END_FUNCTION_BLOCK
