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