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