![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
carte esclave pompe 2020 V1
Dependencies: mbed ident_crac
Diff: class_ventouse.cpp
- Revision:
- 2:4cc8fa2f64be
- Parent:
- 0:84a8c24e29ae
- Child:
- 3:cf33f9d4d6ff
- Child:
- 4:82c90657da4a
--- a/class_ventouse.cpp Tue May 07 08:33:42 2019 +0000 +++ b/class_ventouse.cpp Tue May 07 13:14:29 2019 +0000 @@ -1,11 +1,10 @@ #include "class_ventouse.h" -#define SEUIL 0.3 +#define SEUIL 0.30 - -Ventouse::Ventouse(PinName pinPompe, PinName pinElectrovanne, PinName pinCapteurPression) : m_pinPompe(pinPompe), -m_pinElectrovanne(pinElectrovanne), m_pinCapteurPression(pinCapteurPression) +Ventouse::Ventouse(PinName pinPompe, PinName pinElectrovanne, PinName pinCapteurPression, char index) : m_pinPompe(pinPompe), +m_pinElectrovanne(pinElectrovanne), m_pinCapteurPression(pinCapteurPression), m_index(index) { m_pompe = new PwmOut(m_pinPompe); m_electrovanne = new PwmOut(m_pinElectrovanne); @@ -16,6 +15,62 @@ m_pompe->write(0); m_electrovanne->write(0); + + flag_attraper = 0; + flag_relacher = 0; + + etat = Attente; + m_ack = 0; +} + +void Ventouse::automate() +{ + switch(etat) + { + case Attente : + if(flag_attraper) + { + attraper(); + etat = Attraper; + } + break; + + case Attraper : + if(getPression()) + { + etat = Attraper_ok; + }else if(flag_relacher) + { + relacher(); + etat = Relacher; + } + break; + + case Attraper_ok : + if(flag_relacher) + { + relacher(); + wait(0.5); + etat = Relacher; + } + break; + + case Relacher : + if(!getPression()) + { + m_electrovanne->write(0.0); + etat = Attente; + } + break; + + } +} + + +void Ventouse::action(bool action) +{ + flag_attraper = action; + flag_relacher = !action; } void Ventouse::attraper() @@ -32,7 +87,7 @@ } -int Ventouse::getPression() +bool Ventouse::getPression() { if(m_pression->read() > SEUIL){ return 1; @@ -43,7 +98,7 @@ } -int Ventouse::getPompe() +bool Ventouse::getPompe() { if(m_pompe->read() > 0){ return 1; @@ -65,4 +120,3 @@ -