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