![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
carte esclave pompe 2020 V1
Dependencies: mbed ident_crac
class_ventouse.cpp@22:f104afbecb98, 2020-03-08 (annotated)
- Committer:
- maximilienlv
- Date:
- Sun Mar 08 23:05:13 2020 +0000
- Revision:
- 22:f104afbecb98
- Parent:
- 21:42d6cead9cc2
- Child:
- 23:7f62f27c028f
optimisation du code des pompes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marwanesaich | 0:84a8c24e29ae | 1 | #include "class_ventouse.h" |
maximilienlv | 22:f104afbecb98 | 2 | //valeur de seuil des capteurs de pression |
maximilienlv | 22:f104afbecb98 | 3 | float seuil[NB_VENTOUSES] = {0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; |
maximilienlv | 21:42d6cead9cc2 | 4 | #define PWM_POMPE 0.7 |
maximilienlv | 20:677dcf689523 | 5 | #define PWM_ELECTROVANNE 0.3 |
marwanesaich | 0:84a8c24e29ae | 6 | |
maximilienlv | 22:f104afbecb98 | 7 | /*Ventouse::Ventouse(PinName pinPompe, PinName pinCapteurPression, char index) : m_pinPompe(pinPompe), |
marwanesaich | 5:176e7353ba1c | 8 | m_pinCapteurPression(pinCapteurPression), m_index(index) |
marwanesaich | 5:176e7353ba1c | 9 | { |
marwanesaich | 5:176e7353ba1c | 10 | m_pompe = new PwmOut(m_pinPompe); |
marwanesaich | 5:176e7353ba1c | 11 | m_pression = new AnalogIn(m_pinCapteurPression); |
marwanesaich | 5:176e7353ba1c | 12 | |
maximilienlv | 22:f104afbecb98 | 13 | m_pompe->period_us(20); |
marwanesaich | 5:176e7353ba1c | 14 | m_pompe->write(0); |
marwanesaich | 5:176e7353ba1c | 15 | |
marwanesaich | 5:176e7353ba1c | 16 | flag_attraper = 0; |
marwanesaich | 5:176e7353ba1c | 17 | flag_relacher = 0; |
marwanesaich | 5:176e7353ba1c | 18 | |
marwanesaich | 5:176e7353ba1c | 19 | etat = Attente; |
marwanesaich | 5:176e7353ba1c | 20 | m_ack = 0; |
marwanesaich | 5:176e7353ba1c | 21 | flag_electrovanne = 0; |
maximilienlv | 22:f104afbecb98 | 22 | }*/ |
marwanesaich | 5:176e7353ba1c | 23 | |
marwanesaich | 5:176e7353ba1c | 24 | |
marwanesaich | 2:4cc8fa2f64be | 25 | Ventouse::Ventouse(PinName pinPompe, PinName pinElectrovanne, PinName pinCapteurPression, char index) : m_pinPompe(pinPompe), |
marwanesaich | 2:4cc8fa2f64be | 26 | m_pinElectrovanne(pinElectrovanne), m_pinCapteurPression(pinCapteurPression), m_index(index) |
marwanesaich | 0:84a8c24e29ae | 27 | { |
marwanesaich | 0:84a8c24e29ae | 28 | m_pompe = new PwmOut(m_pinPompe); |
maximilienlv | 19:952208276c63 | 29 | m_electrovanne = new PwmOut(m_pinElectrovanne); |
marwanesaich | 0:84a8c24e29ae | 30 | m_pression = new AnalogIn(m_pinCapteurPression); |
marwanesaich | 0:84a8c24e29ae | 31 | |
maximilienlv | 19:952208276c63 | 32 | m_pompe->period_us(20); |
maximilienlv | 19:952208276c63 | 33 | m_electrovanne->period_us(20); |
marwanesaich | 0:84a8c24e29ae | 34 | |
marwanesaich | 0:84a8c24e29ae | 35 | m_pompe->write(0); |
marwanesaich | 0:84a8c24e29ae | 36 | m_electrovanne->write(0); |
marwanesaich | 2:4cc8fa2f64be | 37 | |
marwanesaich | 2:4cc8fa2f64be | 38 | flag_attraper = 0; |
marwanesaich | 2:4cc8fa2f64be | 39 | flag_relacher = 0; |
marwanesaich | 2:4cc8fa2f64be | 40 | |
marwanesaich | 2:4cc8fa2f64be | 41 | etat = Attente; |
marwanesaich | 2:4cc8fa2f64be | 42 | m_ack = 0; |
marwanesaich | 5:176e7353ba1c | 43 | flag_electrovanne = 1; |
marwanesaich | 2:4cc8fa2f64be | 44 | } |
marwanesaich | 2:4cc8fa2f64be | 45 | |
marwanesaich | 2:4cc8fa2f64be | 46 | void Ventouse::automate() |
marwanesaich | 2:4cc8fa2f64be | 47 | { |
marwanesaich | 2:4cc8fa2f64be | 48 | switch(etat) |
marwanesaich | 2:4cc8fa2f64be | 49 | { |
marwanesaich | 2:4cc8fa2f64be | 50 | case Attente : |
marwanesaich | 2:4cc8fa2f64be | 51 | if(flag_attraper) |
marwanesaich | 2:4cc8fa2f64be | 52 | { |
marwanesaich | 2:4cc8fa2f64be | 53 | attraper(); |
marwanesaich | 2:4cc8fa2f64be | 54 | etat = Attraper; |
marwanesaich | 2:4cc8fa2f64be | 55 | } |
marwanesaich | 2:4cc8fa2f64be | 56 | break; |
marwanesaich | 2:4cc8fa2f64be | 57 | |
marwanesaich | 2:4cc8fa2f64be | 58 | case Attraper : |
marwanesaich | 6:fda992188a2f | 59 | wait_ms(10.0); |
marwanesaich | 7:43d9c70b6689 | 60 | if(getPression()==1) |
marwanesaich | 4:82c90657da4a | 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 | 2:4cc8fa2f64be | 74 | etat = Relacher; |
marwanesaich | 2:4cc8fa2f64be | 75 | } |
marwanesaich | 2:4cc8fa2f64be | 76 | break; |
marwanesaich | 2:4cc8fa2f64be | 77 | |
marwanesaich | 2:4cc8fa2f64be | 78 | case Relacher : |
marwanesaich | 7:43d9c70b6689 | 79 | wait_ms(10.0); |
marwanesaich | 7:43d9c70b6689 | 80 | if(getPression() == 0) |
marwanesaich | 2:4cc8fa2f64be | 81 | { |
kyxstark | 8:a25a9c22ba91 | 82 | if(flag_electrovanne) m_electrovanne->write(0); |
marwanesaich | 2:4cc8fa2f64be | 83 | etat = Attente; |
marwanesaich | 2:4cc8fa2f64be | 84 | } |
maximilienlv | 22:f104afbecb98 | 85 | break; |
marwanesaich | 2:4cc8fa2f64be | 86 | } |
marwanesaich | 2:4cc8fa2f64be | 87 | } |
marwanesaich | 2:4cc8fa2f64be | 88 | |
marwanesaich | 2:4cc8fa2f64be | 89 | void Ventouse::action(bool action) |
marwanesaich | 2:4cc8fa2f64be | 90 | { |
marwanesaich | 2:4cc8fa2f64be | 91 | flag_attraper = action; |
marwanesaich | 2:4cc8fa2f64be | 92 | flag_relacher = !action; |
marwanesaich | 0:84a8c24e29ae | 93 | } |
marwanesaich | 0:84a8c24e29ae | 94 | |
marwanesaich | 0:84a8c24e29ae | 95 | void Ventouse::attraper() |
marwanesaich | 0:84a8c24e29ae | 96 | { |
kyxstark | 10:765b4ff6d721 | 97 | m_pompe->write(PWM_POMPE); |
maximilienlv | 19:952208276c63 | 98 | if(flag_electrovanne) m_electrovanne->write(0.0); |
marwanesaich | 0:84a8c24e29ae | 99 | } |
marwanesaich | 0:84a8c24e29ae | 100 | |
marwanesaich | 0:84a8c24e29ae | 101 | void Ventouse::relacher() |
marwanesaich | 0:84a8c24e29ae | 102 | { |
marwanesaich | 0:84a8c24e29ae | 103 | m_pompe->write(0.0); |
maximilienlv | 19:952208276c63 | 104 | if(flag_electrovanne) m_electrovanne->write(PWM_ELECTROVANNE); |
marwanesaich | 0:84a8c24e29ae | 105 | } |
marwanesaich | 0:84a8c24e29ae | 106 | |
marwanesaich | 2:4cc8fa2f64be | 107 | bool Ventouse::getPression() |
marwanesaich | 6:fda992188a2f | 108 | { |
marwanesaich | 6:fda992188a2f | 109 | if(m_pression->read() > seuil[m_index]){ |
marwanesaich | 0:84a8c24e29ae | 110 | return 1; |
marwanesaich | 0:84a8c24e29ae | 111 | } |
marwanesaich | 0:84a8c24e29ae | 112 | else{ |
marwanesaich | 0:84a8c24e29ae | 113 | return 0; |
marwanesaich | 0:84a8c24e29ae | 114 | } |
marwanesaich | 0:84a8c24e29ae | 115 | } |
marwanesaich | 0:84a8c24e29ae | 116 | |
marwanesaich | 2:4cc8fa2f64be | 117 | bool Ventouse::getPompe() |
marwanesaich | 0:84a8c24e29ae | 118 | { |
marwanesaich | 0:84a8c24e29ae | 119 | if(m_pompe->read() > 0){ |
marwanesaich | 0:84a8c24e29ae | 120 | return 1; |
marwanesaich | 0:84a8c24e29ae | 121 | } |
marwanesaich | 0:84a8c24e29ae | 122 | else{ |
marwanesaich | 0:84a8c24e29ae | 123 | return 0; |
marwanesaich | 0:84a8c24e29ae | 124 | } |
marwanesaich | 0:84a8c24e29ae | 125 | } |
marwanesaich | 0:84a8c24e29ae | 126 | |
marwanesaich | 0:84a8c24e29ae | 127 | void Ventouse::setPompe(float val) |
marwanesaich | 0:84a8c24e29ae | 128 | { |
marwanesaich | 0:84a8c24e29ae | 129 | m_pompe->write(val); |
marwanesaich | 0:84a8c24e29ae | 130 | } |
marwanesaich | 0:84a8c24e29ae | 131 | |
kyxstark | 8:a25a9c22ba91 | 132 | void Ventouse::setElectrovanne(int val) |
marwanesaich | 0:84a8c24e29ae | 133 | { |
marwanesaich | 5:176e7353ba1c | 134 | if(flag_electrovanne)m_electrovanne->write(val); |
maximilienlv | 21:42d6cead9cc2 | 135 | } |