![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
carte esclave pompe 2020 V1
Dependencies: mbed ident_crac
class_ventouse.cpp@6:fda992188a2f, 2019-05-20 (annotated)
- Committer:
- marwanesaich
- Date:
- Mon May 20 09:40:21 2019 +0000
- Revision:
- 6:fda992188a2f
- Parent:
- 5:176e7353ba1c
- Child:
- 7:43d9c70b6689
seuil par capteur pression
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 | 6:fda992188a2f | 5 | float seuil[8] = {0.10, 0.5, 0.5, 0.5, 0.10, 0.5, 0.5, 0.5}; |
marwanesaich | 0:84a8c24e29ae | 6 | |
marwanesaich | 0:84a8c24e29ae | 7 | |
marwanesaich | 5:176e7353ba1c | 8 | Ventouse::Ventouse(PinName pinPompe, PinName pinCapteurPression, char index) : m_pinPompe(pinPompe), |
marwanesaich | 5:176e7353ba1c | 9 | m_pinCapteurPression(pinCapteurPression), m_index(index) |
marwanesaich | 5:176e7353ba1c | 10 | { |
marwanesaich | 5:176e7353ba1c | 11 | m_pompe = new PwmOut(m_pinPompe); |
marwanesaich | 5:176e7353ba1c | 12 | m_pression = new AnalogIn(m_pinCapteurPression); |
marwanesaich | 5:176e7353ba1c | 13 | |
marwanesaich | 5:176e7353ba1c | 14 | m_pompe->period_us(50); |
marwanesaich | 5:176e7353ba1c | 15 | |
marwanesaich | 5:176e7353ba1c | 16 | m_pompe->write(0); |
marwanesaich | 5:176e7353ba1c | 17 | |
marwanesaich | 5:176e7353ba1c | 18 | flag_attraper = 0; |
marwanesaich | 5:176e7353ba1c | 19 | flag_relacher = 0; |
marwanesaich | 5:176e7353ba1c | 20 | |
marwanesaich | 5:176e7353ba1c | 21 | etat = Attente; |
marwanesaich | 5:176e7353ba1c | 22 | m_ack = 0; |
marwanesaich | 5:176e7353ba1c | 23 | flag_electrovanne = 0; |
marwanesaich | 5:176e7353ba1c | 24 | } |
marwanesaich | 5:176e7353ba1c | 25 | |
marwanesaich | 5:176e7353ba1c | 26 | |
marwanesaich | 2:4cc8fa2f64be | 27 | Ventouse::Ventouse(PinName pinPompe, PinName pinElectrovanne, PinName pinCapteurPression, char index) : m_pinPompe(pinPompe), |
marwanesaich | 2:4cc8fa2f64be | 28 | m_pinElectrovanne(pinElectrovanne), m_pinCapteurPression(pinCapteurPression), m_index(index) |
marwanesaich | 0:84a8c24e29ae | 29 | { |
marwanesaich | 0:84a8c24e29ae | 30 | m_pompe = new PwmOut(m_pinPompe); |
marwanesaich | 0:84a8c24e29ae | 31 | m_electrovanne = new PwmOut(m_pinElectrovanne); |
marwanesaich | 0:84a8c24e29ae | 32 | m_pression = new AnalogIn(m_pinCapteurPression); |
marwanesaich | 0:84a8c24e29ae | 33 | |
marwanesaich | 0:84a8c24e29ae | 34 | m_pompe->period_us(50); |
marwanesaich | 0:84a8c24e29ae | 35 | m_electrovanne->period_us(50); |
marwanesaich | 0:84a8c24e29ae | 36 | |
marwanesaich | 0:84a8c24e29ae | 37 | m_pompe->write(0); |
marwanesaich | 0:84a8c24e29ae | 38 | m_electrovanne->write(0); |
marwanesaich | 2:4cc8fa2f64be | 39 | |
marwanesaich | 2:4cc8fa2f64be | 40 | flag_attraper = 0; |
marwanesaich | 2:4cc8fa2f64be | 41 | flag_relacher = 0; |
marwanesaich | 2:4cc8fa2f64be | 42 | |
marwanesaich | 2:4cc8fa2f64be | 43 | etat = Attente; |
marwanesaich | 2:4cc8fa2f64be | 44 | m_ack = 0; |
marwanesaich | 5:176e7353ba1c | 45 | flag_electrovanne = 1; |
marwanesaich | 2:4cc8fa2f64be | 46 | } |
marwanesaich | 2:4cc8fa2f64be | 47 | |
marwanesaich | 2:4cc8fa2f64be | 48 | void Ventouse::automate() |
marwanesaich | 2:4cc8fa2f64be | 49 | { |
marwanesaich | 2:4cc8fa2f64be | 50 | switch(etat) |
marwanesaich | 2:4cc8fa2f64be | 51 | { |
marwanesaich | 2:4cc8fa2f64be | 52 | case Attente : |
marwanesaich | 2:4cc8fa2f64be | 53 | if(flag_attraper) |
marwanesaich | 2:4cc8fa2f64be | 54 | { |
marwanesaich | 2:4cc8fa2f64be | 55 | attraper(); |
marwanesaich | 2:4cc8fa2f64be | 56 | etat = Attraper; |
marwanesaich | 2:4cc8fa2f64be | 57 | } |
marwanesaich | 2:4cc8fa2f64be | 58 | break; |
marwanesaich | 2:4cc8fa2f64be | 59 | |
marwanesaich | 2:4cc8fa2f64be | 60 | case Attraper : |
marwanesaich | 6:fda992188a2f | 61 | wait_ms(10.0); |
marwanesaich | 2:4cc8fa2f64be | 62 | if(getPression()) |
marwanesaich | 4:82c90657da4a | 63 | { |
marwanesaich | 4:82c90657da4a | 64 | can.write(CANMessage(HACHEUR_GET_ATOM_ACK,&m_index,1)); |
marwanesaich | 2:4cc8fa2f64be | 65 | etat = Attraper_ok; |
marwanesaich | 2:4cc8fa2f64be | 66 | }else if(flag_relacher) |
marwanesaich | 2:4cc8fa2f64be | 67 | { |
marwanesaich | 2:4cc8fa2f64be | 68 | relacher(); |
marwanesaich | 2:4cc8fa2f64be | 69 | etat = Relacher; |
marwanesaich | 2:4cc8fa2f64be | 70 | } |
marwanesaich | 2:4cc8fa2f64be | 71 | break; |
marwanesaich | 2:4cc8fa2f64be | 72 | |
marwanesaich | 2:4cc8fa2f64be | 73 | case Attraper_ok : |
marwanesaich | 2:4cc8fa2f64be | 74 | if(flag_relacher) |
marwanesaich | 2:4cc8fa2f64be | 75 | { |
marwanesaich | 2:4cc8fa2f64be | 76 | relacher(); |
marwanesaich | 2:4cc8fa2f64be | 77 | etat = Relacher; |
marwanesaich | 2:4cc8fa2f64be | 78 | } |
marwanesaich | 2:4cc8fa2f64be | 79 | break; |
marwanesaich | 2:4cc8fa2f64be | 80 | |
marwanesaich | 2:4cc8fa2f64be | 81 | case Relacher : |
marwanesaich | 2:4cc8fa2f64be | 82 | if(!getPression()) |
marwanesaich | 2:4cc8fa2f64be | 83 | { |
marwanesaich | 4:82c90657da4a | 84 | can.write(CANMessage(HACHEUR_RELEASE_ATOM_ACK,&m_index,1)); |
marwanesaich | 5:176e7353ba1c | 85 | if(flag_electrovanne) m_electrovanne->write(0.0); |
marwanesaich | 2:4cc8fa2f64be | 86 | etat = Attente; |
marwanesaich | 2:4cc8fa2f64be | 87 | } |
marwanesaich | 2:4cc8fa2f64be | 88 | break; |
marwanesaich | 2:4cc8fa2f64be | 89 | |
marwanesaich | 2:4cc8fa2f64be | 90 | } |
marwanesaich | 2:4cc8fa2f64be | 91 | } |
marwanesaich | 2:4cc8fa2f64be | 92 | |
marwanesaich | 2:4cc8fa2f64be | 93 | |
marwanesaich | 2:4cc8fa2f64be | 94 | void Ventouse::action(bool action) |
marwanesaich | 2:4cc8fa2f64be | 95 | { |
marwanesaich | 2:4cc8fa2f64be | 96 | flag_attraper = action; |
marwanesaich | 2:4cc8fa2f64be | 97 | flag_relacher = !action; |
marwanesaich | 0:84a8c24e29ae | 98 | } |
marwanesaich | 0:84a8c24e29ae | 99 | |
marwanesaich | 0:84a8c24e29ae | 100 | void Ventouse::attraper() |
marwanesaich | 0:84a8c24e29ae | 101 | { |
marwanesaich | 6:fda992188a2f | 102 | m_pompe->write(0.85); |
marwanesaich | 5:176e7353ba1c | 103 | if(flag_electrovanne) m_electrovanne->write(0.0); |
marwanesaich | 0:84a8c24e29ae | 104 | |
marwanesaich | 0:84a8c24e29ae | 105 | } |
marwanesaich | 0:84a8c24e29ae | 106 | |
marwanesaich | 0:84a8c24e29ae | 107 | void Ventouse::relacher() |
marwanesaich | 0:84a8c24e29ae | 108 | { |
marwanesaich | 0:84a8c24e29ae | 109 | m_pompe->write(0.0); |
marwanesaich | 5:176e7353ba1c | 110 | if(flag_electrovanne) m_electrovanne->write(1.0); |
marwanesaich | 0:84a8c24e29ae | 111 | |
marwanesaich | 0:84a8c24e29ae | 112 | } |
marwanesaich | 0:84a8c24e29ae | 113 | |
marwanesaich | 2:4cc8fa2f64be | 114 | bool Ventouse::getPression() |
marwanesaich | 6:fda992188a2f | 115 | { |
marwanesaich | 6:fda992188a2f | 116 | //printf("capteur %d : %f\n", m_index, m_pression->read()); |
marwanesaich | 6:fda992188a2f | 117 | if(m_pression->read() > seuil[m_index]){ |
marwanesaich | 0:84a8c24e29ae | 118 | return 1; |
marwanesaich | 0:84a8c24e29ae | 119 | } |
marwanesaich | 0:84a8c24e29ae | 120 | else{ |
marwanesaich | 0:84a8c24e29ae | 121 | return 0; |
marwanesaich | 0:84a8c24e29ae | 122 | } |
marwanesaich | 0:84a8c24e29ae | 123 | |
marwanesaich | 0:84a8c24e29ae | 124 | } |
marwanesaich | 0:84a8c24e29ae | 125 | |
marwanesaich | 2:4cc8fa2f64be | 126 | bool Ventouse::getPompe() |
marwanesaich | 0:84a8c24e29ae | 127 | { |
marwanesaich | 0:84a8c24e29ae | 128 | if(m_pompe->read() > 0){ |
marwanesaich | 0:84a8c24e29ae | 129 | return 1; |
marwanesaich | 0:84a8c24e29ae | 130 | } |
marwanesaich | 0:84a8c24e29ae | 131 | else{ |
marwanesaich | 0:84a8c24e29ae | 132 | return 0; |
marwanesaich | 0:84a8c24e29ae | 133 | } |
marwanesaich | 0:84a8c24e29ae | 134 | } |
marwanesaich | 0:84a8c24e29ae | 135 | |
marwanesaich | 0:84a8c24e29ae | 136 | void Ventouse::setPompe(float val) |
marwanesaich | 0:84a8c24e29ae | 137 | { |
marwanesaich | 0:84a8c24e29ae | 138 | m_pompe->write(val); |
marwanesaich | 0:84a8c24e29ae | 139 | } |
marwanesaich | 0:84a8c24e29ae | 140 | |
marwanesaich | 0:84a8c24e29ae | 141 | void Ventouse::setElectrovanne(float val) |
marwanesaich | 0:84a8c24e29ae | 142 | { |
marwanesaich | 5:176e7353ba1c | 143 | if(flag_electrovanne)m_electrovanne->write(val); |
marwanesaich | 0:84a8c24e29ae | 144 | } |
marwanesaich | 0:84a8c24e29ae | 145 | |
marwanesaich | 0:84a8c24e29ae | 146 | |
marwanesaich | 0:84a8c24e29ae | 147 |