![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
carte esclave pompe 2020 V1
Dependencies: mbed ident_crac
class_ventouse.cpp@19:952208276c63, 2020-03-05 (annotated)
- Committer:
- maximilienlv
- Date:
- Thu Mar 05 16:32:21 2020 +0000
- Revision:
- 19:952208276c63
- Parent:
- 16:5e00af31ae8a
- Child:
- 20:677dcf689523
carte esclave pompe 2020
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 | 16:5e00af31ae8a | 3 | //float seuil[NB_VENTOUSES] = {0.10, 0.3, 0.3, 0.3, 0.10, 0.3, 0.3, 0.3}; |
marwanesaich | 16:5e00af31ae8a | 4 | float seuil[NB_VENTOUSES] = {0.1, 0.1, 0.1, 0.1, 0.10, 0.1, 0.1, 0.1}; |
kyxstark | 10:765b4ff6d721 | 5 | #define PWM_POMPE 0.7 |
maximilienlv | 19:952208276c63 | 6 | #define PWM_ELECTROVANNE 0.35 |
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 | |
maximilienlv | 19:952208276c63 | 14 | m_pompe->period_us(20); |
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); |
maximilienlv | 19:952208276c63 | 31 | m_electrovanne = new PwmOut(m_pinElectrovanne); |
marwanesaich | 0:84a8c24e29ae | 32 | m_pression = new AnalogIn(m_pinCapteurPression); |
marwanesaich | 0:84a8c24e29ae | 33 | |
maximilienlv | 19:952208276c63 | 34 | m_pompe->period_us(20); |
maximilienlv | 19:952208276c63 | 35 | m_electrovanne->period_us(20); |
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 | 7:43d9c70b6689 | 62 | if(getPression()==1) |
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 | 7:43d9c70b6689 | 82 | wait_ms(10.0); |
marwanesaich | 7:43d9c70b6689 | 83 | if(getPression() == 0) |
marwanesaich | 2:4cc8fa2f64be | 84 | { |
marwanesaich | 4:82c90657da4a | 85 | can.write(CANMessage(HACHEUR_RELEASE_ATOM_ACK,&m_index,1)); |
kyxstark | 8:a25a9c22ba91 | 86 | if(flag_electrovanne) m_electrovanne->write(0); |
marwanesaich | 2:4cc8fa2f64be | 87 | etat = Attente; |
marwanesaich | 2:4cc8fa2f64be | 88 | } |
marwanesaich | 2:4cc8fa2f64be | 89 | break; |
marwanesaich | 2:4cc8fa2f64be | 90 | |
marwanesaich | 2:4cc8fa2f64be | 91 | } |
marwanesaich | 2:4cc8fa2f64be | 92 | } |
marwanesaich | 2:4cc8fa2f64be | 93 | |
marwanesaich | 2:4cc8fa2f64be | 94 | |
marwanesaich | 2:4cc8fa2f64be | 95 | void Ventouse::action(bool action) |
marwanesaich | 2:4cc8fa2f64be | 96 | { |
marwanesaich | 2:4cc8fa2f64be | 97 | flag_attraper = action; |
marwanesaich | 2:4cc8fa2f64be | 98 | flag_relacher = !action; |
marwanesaich | 0:84a8c24e29ae | 99 | } |
marwanesaich | 0:84a8c24e29ae | 100 | |
marwanesaich | 0:84a8c24e29ae | 101 | void Ventouse::attraper() |
marwanesaich | 0:84a8c24e29ae | 102 | { |
kyxstark | 10:765b4ff6d721 | 103 | m_pompe->write(PWM_POMPE); |
maximilienlv | 19:952208276c63 | 104 | if(flag_electrovanne) m_electrovanne->write(0.0); |
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); |
maximilienlv | 19:952208276c63 | 110 | if(flag_electrovanne) m_electrovanne->write(PWM_ELECTROVANNE); |
marwanesaich | 0:84a8c24e29ae | 111 | } |
marwanesaich | 0:84a8c24e29ae | 112 | |
marwanesaich | 2:4cc8fa2f64be | 113 | bool Ventouse::getPression() |
marwanesaich | 6:fda992188a2f | 114 | { |
marwanesaich | 6:fda992188a2f | 115 | if(m_pression->read() > seuil[m_index]){ |
marwanesaich | 0:84a8c24e29ae | 116 | return 1; |
marwanesaich | 0:84a8c24e29ae | 117 | } |
marwanesaich | 0:84a8c24e29ae | 118 | else{ |
marwanesaich | 0:84a8c24e29ae | 119 | return 0; |
marwanesaich | 0:84a8c24e29ae | 120 | } |
marwanesaich | 0:84a8c24e29ae | 121 | |
marwanesaich | 0:84a8c24e29ae | 122 | } |
marwanesaich | 0:84a8c24e29ae | 123 | |
marwanesaich | 2:4cc8fa2f64be | 124 | bool Ventouse::getPompe() |
marwanesaich | 0:84a8c24e29ae | 125 | { |
marwanesaich | 0:84a8c24e29ae | 126 | if(m_pompe->read() > 0){ |
marwanesaich | 0:84a8c24e29ae | 127 | return 1; |
marwanesaich | 0:84a8c24e29ae | 128 | } |
marwanesaich | 0:84a8c24e29ae | 129 | else{ |
marwanesaich | 0:84a8c24e29ae | 130 | return 0; |
marwanesaich | 0:84a8c24e29ae | 131 | } |
marwanesaich | 0:84a8c24e29ae | 132 | } |
marwanesaich | 0:84a8c24e29ae | 133 | |
marwanesaich | 0:84a8c24e29ae | 134 | void Ventouse::setPompe(float val) |
marwanesaich | 0:84a8c24e29ae | 135 | { |
marwanesaich | 0:84a8c24e29ae | 136 | m_pompe->write(val); |
marwanesaich | 0:84a8c24e29ae | 137 | } |
marwanesaich | 0:84a8c24e29ae | 138 | |
kyxstark | 8:a25a9c22ba91 | 139 | void Ventouse::setElectrovanne(int val) |
marwanesaich | 0:84a8c24e29ae | 140 | { |
marwanesaich | 5:176e7353ba1c | 141 | if(flag_electrovanne)m_electrovanne->write(val); |
marwanesaich | 0:84a8c24e29ae | 142 | } |
marwanesaich | 0:84a8c24e29ae | 143 | |
marwanesaich | 0:84a8c24e29ae | 144 | |
marwanesaich | 0:84a8c24e29ae | 145 |