Gestion de la porte de garage
SCÉNARIO 2 : Pilotage de la porte de garage.
Cahier des charges : un appui sur le bouton 1 de la télécommande ouvre la porte du garage, après une temporisation de 5 secondes en position ouverte, la porte se referme. Lors de la fermeture, si on appuie une nouvelle fois sur le bouton 1 ou, si le détecteur infrarouge présent au niveau de la porte du garage détecte un passage, la porte s’ouvre à nouveau. Ce cycle est répété tant que la porte du garage n’est pas fermée.
On pourra fortement s'inspirer du grafcet donnée sur ce lien
Proposer le grafcet
Traduire le grafcet en équations
Coder les équations
// Some code
private bool bp1 = false;
private bool bp1prec = false;
private bool capteurIR = false;
private bool porteOuverte = false;
private bool porteFermee = false;
private bool frontBp1 = false;
private bool X1g = true;
private bool X2g = false;
private bool X3g = false;
private bool X3gprec = false;
private bool frontX3g = false;
private bool X4g = false;
private bool X5g = false;
private bool ft1g = false;
private bool ft2g = false;
private bool ft3g = false;
private bool ft4g = false;
private bool ft5g = false;
private bool ft6g = false;
private bool finTempo = false;
private System.Windows.Threading.DispatcherTimer dispatcherTimer5s;
private void runPorteGarage()
{
//sauvegarde de l'état précédent
bp1prec = bp1;
X3gprec = X3g;
//timer
//lecture des entrées
bp1 = MemoryMap.Instance.GetBit(274, MemoryType.Input).Value;
capteurIR = MemoryMap.Instance.GetBit(102, MemoryType.Input).Value;
porteOuverte = MemoryMap.Instance.GetBit(100, MemoryType.Input).Value;
porteFermee = MemoryMap.Instance.GetBit(101, MemoryType.Input).Value;
//calcul des fronts montants
frontBp1 = !bp1prec && bp1;
ft1g = X1g && frontBp1;
ft2g = X2g && porteOuverte;
ft3g = X3g && finTempo;
ft4g = X4g && !porteOuverte;
ft5g = X5g && porteFermee;
ft6g = X5g && (frontBp1 || capteurIR) && !porteFermee;
X1g = ft5g || X1g && !ft1g;
X2g = (ft1g || ft6g) || X2g && !ft2g;
X3g = ft2g || X3g && !ft3g;
X4g = ft3g || X4g && !ft4g;
X5g = ft4g || X5g && !(ft5g || ft6g);
MemoryBit OuvrirPorte = MemoryMap.Instance.GetBit(72, MemoryType.Output);
MemoryBit FermerPorte = MemoryMap.Instance.GetBit(73, MemoryType.Output);
OuvrirPorte.Value = X2g;
FermerPorte.Value = X4g || X5g;
frontX3g = !X3gprec && X3g;
if (!X3g)
{
System.Diagnostics.Debug.WriteLine("Plus X3");
if (dispatcherTimer5s != null)
{
dispatcherTimer5s.Stop();
finTempo = false;
}
}
if (frontX3g && finTempo == false)
{
dispatcherTimer5s = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer5s.Tick += new EventHandler(dispatcherTimer5S_Tick);
dispatcherTimer5s.Interval = TimeSpan.FromSeconds(5);
dispatcherTimer5s.Start(); // ou avec un thread.sleep(5000) + fintempo = true
}
}
private void dispatcherTimer5S_Tick(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Tick 5S");
finTempo = true;
}
Last updated
Was this helpful?