carte esclave pompe 2020 V1
Dependencies: mbed ident_crac
class_ventouse.cpp@4:82c90657da4a, 2019-05-08 (annotated)
- Committer:
- marwanesaich
- Date:
- Wed May 08 17:46:13 2019 +0000
- Revision:
- 4:82c90657da4a
- Parent:
- 2:4cc8fa2f64be
- Child:
- 5:176e7353ba1c
changement pinout sans surcharge constructeur
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marwanesaich | 0:84a8c24e29ae | 1 | #include "class_ventouse.h" |
marwanesaich | 4:82c90657da4a | 2 | #include "extern.h" |
marwanesaich | 4:82c90657da4a | 3 | #include "ident_CRAC.h" |
marwanesaich | 0:84a8c24e29ae | 4 | |
marwanesaich | 2:4cc8fa2f64be | 5 | #define SEUIL 0.30 |
marwanesaich | 0:84a8c24e29ae | 6 | |
marwanesaich | 0:84a8c24e29ae | 7 | |
marwanesaich | 2:4cc8fa2f64be | 8 | Ventouse::Ventouse(PinName pinPompe, PinName pinElectrovanne, PinName pinCapteurPression, char index) : m_pinPompe(pinPompe), |
marwanesaich | 2:4cc8fa2f64be | 9 | m_pinElectrovanne(pinElectrovanne), m_pinCapteurPression(pinCapteurPression), m_index(index) |
marwanesaich | 0:84a8c24e29ae | 10 | { |
marwanesaich | 0:84a8c24e29ae | 11 | m_pompe = new PwmOut(m_pinPompe); |
marwanesaich | 0:84a8c24e29ae | 12 | m_electrovanne = new PwmOut(m_pinElectrovanne); |
marwanesaich | 0:84a8c24e29ae | 13 | m_pression = new AnalogIn(m_pinCapteurPression); |
marwanesaich | 0:84a8c24e29ae | 14 | |
marwanesaich | 0:84a8c24e29ae | 15 | m_pompe->period_us(50); |
marwanesaich | 0:84a8c24e29ae | 16 | m_electrovanne->period_us(50); |
marwanesaich | 0:84a8c24e29ae | 17 | |
marwanesaich | 0:84a8c24e29ae | 18 | m_pompe->write(0); |
marwanesaich | 0:84a8c24e29ae | 19 | m_electrovanne->write(0); |
marwanesaich | 2:4cc8fa2f64be | 20 | |
marwanesaich | 2:4cc8fa2f64be | 21 | flag_attraper = 0; |
marwanesaich | 2:4cc8fa2f64be | 22 | flag_relacher = 0; |
marwanesaich | 2:4cc8fa2f64be | 23 | |
marwanesaich | 2:4cc8fa2f64be | 24 | etat = Attente; |
marwanesaich | 2:4cc8fa2f64be | 25 | m_ack = 0; |
marwanesaich | 2:4cc8fa2f64be | 26 | } |
marwanesaich | 2:4cc8fa2f64be | 27 | |
marwanesaich | 2:4cc8fa2f64be | 28 | void Ventouse::automate() |
marwanesaich | 2:4cc8fa2f64be | 29 | { |
marwanesaich | 2:4cc8fa2f64be | 30 | switch(etat) |
marwanesaich | 2:4cc8fa2f64be | 31 | { |
marwanesaich | 2:4cc8fa2f64be | 32 | case Attente : |
marwanesaich | 2:4cc8fa2f64be | 33 | if(flag_attraper) |
marwanesaich | 2:4cc8fa2f64be | 34 | { |
marwanesaich | 2:4cc8fa2f64be | 35 | attraper(); |
marwanesaich | 2:4cc8fa2f64be | 36 | etat = Attraper; |
marwanesaich | 2:4cc8fa2f64be | 37 | } |
marwanesaich | 2:4cc8fa2f64be | 38 | break; |
marwanesaich | 2:4cc8fa2f64be | 39 | |
marwanesaich | 2:4cc8fa2f64be | 40 | case Attraper : |
marwanesaich | 2:4cc8fa2f64be | 41 | if(getPression()) |
marwanesaich | 4:82c90657da4a | 42 | { |
marwanesaich | 4:82c90657da4a | 43 | can.write(CANMessage(HACHEUR_GET_ATOM_ACK,&m_index,1)); |
marwanesaich | 2:4cc8fa2f64be | 44 | etat = Attraper_ok; |
marwanesaich | 2:4cc8fa2f64be | 45 | }else if(flag_relacher) |
marwanesaich | 2:4cc8fa2f64be | 46 | { |
marwanesaich | 2:4cc8fa2f64be | 47 | relacher(); |
marwanesaich | 2:4cc8fa2f64be | 48 | etat = Relacher; |
marwanesaich | 2:4cc8fa2f64be | 49 | } |
marwanesaich | 2:4cc8fa2f64be | 50 | break; |
marwanesaich | 2:4cc8fa2f64be | 51 | |
marwanesaich | 2:4cc8fa2f64be | 52 | case Attraper_ok : |
marwanesaich | 2:4cc8fa2f64be | 53 | if(flag_relacher) |
marwanesaich | 2:4cc8fa2f64be | 54 | { |
marwanesaich | 2:4cc8fa2f64be | 55 | relacher(); |
marwanesaich | 2:4cc8fa2f64be | 56 | wait(0.5); |
marwanesaich | 2:4cc8fa2f64be | 57 | etat = Relacher; |
marwanesaich | 2:4cc8fa2f64be | 58 | } |
marwanesaich | 2:4cc8fa2f64be | 59 | break; |
marwanesaich | 2:4cc8fa2f64be | 60 | |
marwanesaich | 2:4cc8fa2f64be | 61 | case Relacher : |
marwanesaich | 2:4cc8fa2f64be | 62 | if(!getPression()) |
marwanesaich | 2:4cc8fa2f64be | 63 | { |
marwanesaich | 4:82c90657da4a | 64 | can.write(CANMessage(HACHEUR_RELEASE_ATOM_ACK,&m_index,1)); |
marwanesaich | 2:4cc8fa2f64be | 65 | m_electrovanne->write(0.0); |
marwanesaich | 2:4cc8fa2f64be | 66 | etat = Attente; |
marwanesaich | 2:4cc8fa2f64be | 67 | } |
marwanesaich | 2:4cc8fa2f64be | 68 | break; |
marwanesaich | 2:4cc8fa2f64be | 69 | |
marwanesaich | 2:4cc8fa2f64be | 70 | } |
marwanesaich | 2:4cc8fa2f64be | 71 | } |
marwanesaich | 2:4cc8fa2f64be | 72 | |
marwanesaich | 2:4cc8fa2f64be | 73 | |
marwanesaich | 2:4cc8fa2f64be | 74 | void Ventouse::action(bool action) |
marwanesaich | 2:4cc8fa2f64be | 75 | { |
marwanesaich | 2:4cc8fa2f64be | 76 | flag_attraper = action; |
marwanesaich | 2:4cc8fa2f64be | 77 | flag_relacher = !action; |
marwanesaich | 0:84a8c24e29ae | 78 | } |
marwanesaich | 0:84a8c24e29ae | 79 | |
marwanesaich | 0:84a8c24e29ae | 80 | void Ventouse::attraper() |
marwanesaich | 0:84a8c24e29ae | 81 | { |
marwanesaich | 0:84a8c24e29ae | 82 | m_pompe->write(0.5); |
marwanesaich | 0:84a8c24e29ae | 83 | m_electrovanne->write(0.0); |
marwanesaich | 0:84a8c24e29ae | 84 | |
marwanesaich | 0:84a8c24e29ae | 85 | } |
marwanesaich | 0:84a8c24e29ae | 86 | |
marwanesaich | 0:84a8c24e29ae | 87 | void Ventouse::relacher() |
marwanesaich | 0:84a8c24e29ae | 88 | { |
marwanesaich | 0:84a8c24e29ae | 89 | m_pompe->write(0.0); |
marwanesaich | 0:84a8c24e29ae | 90 | m_electrovanne->write(1.0); |
marwanesaich | 0:84a8c24e29ae | 91 | |
marwanesaich | 0:84a8c24e29ae | 92 | } |
marwanesaich | 0:84a8c24e29ae | 93 | |
marwanesaich | 2:4cc8fa2f64be | 94 | bool Ventouse::getPression() |
marwanesaich | 0:84a8c24e29ae | 95 | { |
marwanesaich | 0:84a8c24e29ae | 96 | if(m_pression->read() > SEUIL){ |
marwanesaich | 0:84a8c24e29ae | 97 | return 1; |
marwanesaich | 0:84a8c24e29ae | 98 | } |
marwanesaich | 0:84a8c24e29ae | 99 | else{ |
marwanesaich | 0:84a8c24e29ae | 100 | return 0; |
marwanesaich | 0:84a8c24e29ae | 101 | } |
marwanesaich | 0:84a8c24e29ae | 102 | |
marwanesaich | 0:84a8c24e29ae | 103 | } |
marwanesaich | 0:84a8c24e29ae | 104 | |
marwanesaich | 2:4cc8fa2f64be | 105 | bool Ventouse::getPompe() |
marwanesaich | 0:84a8c24e29ae | 106 | { |
marwanesaich | 0:84a8c24e29ae | 107 | if(m_pompe->read() > 0){ |
marwanesaich | 0:84a8c24e29ae | 108 | return 1; |
marwanesaich | 0:84a8c24e29ae | 109 | } |
marwanesaich | 0:84a8c24e29ae | 110 | else{ |
marwanesaich | 0:84a8c24e29ae | 111 | return 0; |
marwanesaich | 0:84a8c24e29ae | 112 | } |
marwanesaich | 0:84a8c24e29ae | 113 | } |
marwanesaich | 0:84a8c24e29ae | 114 | |
marwanesaich | 0:84a8c24e29ae | 115 | void Ventouse::setPompe(float val) |
marwanesaich | 0:84a8c24e29ae | 116 | { |
marwanesaich | 0:84a8c24e29ae | 117 | m_pompe->write(val); |
marwanesaich | 0:84a8c24e29ae | 118 | } |
marwanesaich | 0:84a8c24e29ae | 119 | |
marwanesaich | 0:84a8c24e29ae | 120 | void Ventouse::setElectrovanne(float val) |
marwanesaich | 0:84a8c24e29ae | 121 | { |
marwanesaich | 0:84a8c24e29ae | 122 | m_electrovanne->write(val); |
marwanesaich | 0:84a8c24e29ae | 123 | } |
marwanesaich | 0:84a8c24e29ae | 124 | |
marwanesaich | 0:84a8c24e29ae | 125 | |
marwanesaich | 0:84a8c24e29ae | 126 |