carte esclave pompe 2020 V1

Dependencies:   mbed ident_crac

Committer:
maximilienlv
Date:
Fri Jul 17 14:34:32 2020 +0000
Revision:
24:3fb41d2b91af
Parent:
23:7f62f27c028f
version fonctionnel strat

Who changed what in which revision?

UserRevisionLine numberNew 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
marwanesaich 2:4cc8fa2f64be 7 Ventouse::Ventouse(PinName pinPompe, PinName pinElectrovanne, PinName pinCapteurPression, char index) : m_pinPompe(pinPompe),
marwanesaich 2:4cc8fa2f64be 8 m_pinElectrovanne(pinElectrovanne), m_pinCapteurPression(pinCapteurPression), m_index(index)
marwanesaich 0:84a8c24e29ae 9 {
marwanesaich 0:84a8c24e29ae 10 m_pompe = new PwmOut(m_pinPompe);
maximilienlv 19:952208276c63 11 m_electrovanne = new PwmOut(m_pinElectrovanne);
marwanesaich 0:84a8c24e29ae 12 m_pression = new AnalogIn(m_pinCapteurPression);
marwanesaich 0:84a8c24e29ae 13
maximilienlv 19:952208276c63 14 m_pompe->period_us(20);
maximilienlv 19:952208276c63 15 m_electrovanne->period_us(20);
marwanesaich 0:84a8c24e29ae 16
marwanesaich 0:84a8c24e29ae 17 m_pompe->write(0);
marwanesaich 0:84a8c24e29ae 18 m_electrovanne->write(0);
marwanesaich 2:4cc8fa2f64be 19
marwanesaich 2:4cc8fa2f64be 20 flag_attraper = 0;
marwanesaich 2:4cc8fa2f64be 21 flag_relacher = 0;
marwanesaich 2:4cc8fa2f64be 22
marwanesaich 2:4cc8fa2f64be 23 etat = Attente;
marwanesaich 2:4cc8fa2f64be 24 m_ack = 0;
marwanesaich 5:176e7353ba1c 25 flag_electrovanne = 1;
marwanesaich 2:4cc8fa2f64be 26 }
marwanesaich 2:4cc8fa2f64be 27
marwanesaich 2:4cc8fa2f64be 28 void Ventouse::automate()
marwanesaich 2:4cc8fa2f64be 29 {
marwanesaich 2:4cc8fa2f64be 30 switch(etat)
marwanesaich 2:4cc8fa2f64be 31 {
marwanesaich 2:4cc8fa2f64be 32 case Attente :
marwanesaich 2:4cc8fa2f64be 33 if(flag_attraper)
marwanesaich 2:4cc8fa2f64be 34 {
marwanesaich 2:4cc8fa2f64be 35 attraper();
marwanesaich 2:4cc8fa2f64be 36 etat = Attraper;
marwanesaich 2:4cc8fa2f64be 37 }
marwanesaich 2:4cc8fa2f64be 38 break;
marwanesaich 2:4cc8fa2f64be 39
marwanesaich 2:4cc8fa2f64be 40 case Attraper :
marwanesaich 6:fda992188a2f 41 wait_ms(10.0);
marwanesaich 7:43d9c70b6689 42 if(getPression()==1)
marwanesaich 4:82c90657da4a 43 {
marwanesaich 2:4cc8fa2f64be 44 etat = Attraper_ok;
marwanesaich 2:4cc8fa2f64be 45 }else if(flag_relacher)
marwanesaich 2:4cc8fa2f64be 46 {
marwanesaich 2:4cc8fa2f64be 47 relacher();
marwanesaich 2:4cc8fa2f64be 48 etat = Relacher;
marwanesaich 2:4cc8fa2f64be 49 }
marwanesaich 2:4cc8fa2f64be 50 break;
marwanesaich 2:4cc8fa2f64be 51
marwanesaich 2:4cc8fa2f64be 52 case Attraper_ok :
marwanesaich 2:4cc8fa2f64be 53 if(flag_relacher)
marwanesaich 2:4cc8fa2f64be 54 {
marwanesaich 2:4cc8fa2f64be 55 relacher();
marwanesaich 2:4cc8fa2f64be 56 etat = Relacher;
marwanesaich 2:4cc8fa2f64be 57 }
marwanesaich 2:4cc8fa2f64be 58 break;
marwanesaich 2:4cc8fa2f64be 59
marwanesaich 2:4cc8fa2f64be 60 case Relacher :
marwanesaich 7:43d9c70b6689 61 wait_ms(10.0);
marwanesaich 7:43d9c70b6689 62 if(getPression() == 0)
marwanesaich 2:4cc8fa2f64be 63 {
kyxstark 8:a25a9c22ba91 64 if(flag_electrovanne) m_electrovanne->write(0);
marwanesaich 2:4cc8fa2f64be 65 etat = Attente;
marwanesaich 2:4cc8fa2f64be 66 }
maximilienlv 22:f104afbecb98 67 break;
marwanesaich 2:4cc8fa2f64be 68 }
marwanesaich 2:4cc8fa2f64be 69 }
marwanesaich 2:4cc8fa2f64be 70
marwanesaich 2:4cc8fa2f64be 71 void Ventouse::action(bool action)
marwanesaich 2:4cc8fa2f64be 72 {
marwanesaich 2:4cc8fa2f64be 73 flag_attraper = action;
marwanesaich 2:4cc8fa2f64be 74 flag_relacher = !action;
marwanesaich 0:84a8c24e29ae 75 }
marwanesaich 0:84a8c24e29ae 76
marwanesaich 0:84a8c24e29ae 77 void Ventouse::attraper()
marwanesaich 0:84a8c24e29ae 78 {
kyxstark 10:765b4ff6d721 79 m_pompe->write(PWM_POMPE);
maximilienlv 19:952208276c63 80 if(flag_electrovanne) m_electrovanne->write(0.0);
maximilienlv 23:7f62f27c028f 81 //modifier ligne de condition
marwanesaich 0:84a8c24e29ae 82 }
marwanesaich 0:84a8c24e29ae 83
marwanesaich 0:84a8c24e29ae 84 void Ventouse::relacher()
marwanesaich 0:84a8c24e29ae 85 {
maximilienlv 24:3fb41d2b91af 86 if(flag_electrovanne) m_electrovanne->write(PWM_ELECTROVANNE);
marwanesaich 0:84a8c24e29ae 87 m_pompe->write(0.0);
marwanesaich 0:84a8c24e29ae 88 }
marwanesaich 0:84a8c24e29ae 89
marwanesaich 2:4cc8fa2f64be 90 bool Ventouse::getPression()
marwanesaich 6:fda992188a2f 91 {
marwanesaich 6:fda992188a2f 92 if(m_pression->read() > seuil[m_index]){
marwanesaich 0:84a8c24e29ae 93 return 1;
marwanesaich 0:84a8c24e29ae 94 }
marwanesaich 0:84a8c24e29ae 95 else{
marwanesaich 0:84a8c24e29ae 96 return 0;
marwanesaich 0:84a8c24e29ae 97 }
marwanesaich 0:84a8c24e29ae 98 }
marwanesaich 0:84a8c24e29ae 99
marwanesaich 2:4cc8fa2f64be 100 bool Ventouse::getPompe()
marwanesaich 0:84a8c24e29ae 101 {
marwanesaich 0:84a8c24e29ae 102 if(m_pompe->read() > 0){
marwanesaich 0:84a8c24e29ae 103 return 1;
marwanesaich 0:84a8c24e29ae 104 }
marwanesaich 0:84a8c24e29ae 105 else{
marwanesaich 0:84a8c24e29ae 106 return 0;
marwanesaich 0:84a8c24e29ae 107 }
marwanesaich 0:84a8c24e29ae 108 }
marwanesaich 0:84a8c24e29ae 109
marwanesaich 0:84a8c24e29ae 110 void Ventouse::setPompe(float val)
marwanesaich 0:84a8c24e29ae 111 {
marwanesaich 0:84a8c24e29ae 112 m_pompe->write(val);
marwanesaich 0:84a8c24e29ae 113 }
marwanesaich 0:84a8c24e29ae 114
kyxstark 8:a25a9c22ba91 115 void Ventouse::setElectrovanne(int val)
marwanesaich 0:84a8c24e29ae 116 {
marwanesaich 5:176e7353ba1c 117 if(flag_electrovanne)m_electrovanne->write(val);
maximilienlv 21:42d6cead9cc2 118 }