PINOUT à jour, trame CAN OK

Dependencies:   mbed ident_crac

Code carte pompe

Committer:
marwanesaich
Date:
Tue May 21 14:17:12 2019 +0000
Revision:
7:43d9c70b6689
Parent:
6:fda992188a2f
Child:
8:a25a9c22ba91
a jour;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marwanesaich 0:84a8c24e29ae 1 #include "class_ventouse.h"
marwanesaich 4:82c90657da4a 2 #include "extern.h"
marwanesaich 4:82c90657da4a 3 #include "ident_CRAC.h"
marwanesaich 0:84a8c24e29ae 4
marwanesaich 7:43d9c70b6689 5 float seuil[8] = {0.10, 0.3, 0.3, 0.3, 0.10, 0.3, 0.3, 0.3};
marwanesaich 0:84a8c24e29ae 6
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
marwanesaich 5:176e7353ba1c 14 m_pompe->period_us(50);
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);
marwanesaich 0:84a8c24e29ae 31 m_electrovanne = new PwmOut(m_pinElectrovanne);
marwanesaich 0:84a8c24e29ae 32 m_pression = new AnalogIn(m_pinCapteurPression);
marwanesaich 0:84a8c24e29ae 33
marwanesaich 0:84a8c24e29ae 34 m_pompe->period_us(50);
marwanesaich 0:84a8c24e29ae 35 m_electrovanne->period_us(50);
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));
marwanesaich 5:176e7353ba1c 86 if(flag_electrovanne) m_electrovanne->write(0.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 {
marwanesaich 7:43d9c70b6689 103 m_pompe->write(0.7);
marwanesaich 5:176e7353ba1c 104 if(flag_electrovanne) m_electrovanne->write(0.0);
marwanesaich 0:84a8c24e29ae 105
marwanesaich 0:84a8c24e29ae 106 }
marwanesaich 0:84a8c24e29ae 107
marwanesaich 0:84a8c24e29ae 108 void Ventouse::relacher()
marwanesaich 0:84a8c24e29ae 109 {
marwanesaich 0:84a8c24e29ae 110 m_pompe->write(0.0);
marwanesaich 5:176e7353ba1c 111 if(flag_electrovanne) m_electrovanne->write(1.0);
marwanesaich 7:43d9c70b6689 112 wait_ms(300.0);
marwanesaich 0:84a8c24e29ae 113
marwanesaich 0:84a8c24e29ae 114 }
marwanesaich 0:84a8c24e29ae 115
marwanesaich 2:4cc8fa2f64be 116 bool Ventouse::getPression()
marwanesaich 6:fda992188a2f 117 {
marwanesaich 7:43d9c70b6689 118 printf("capteur %d : %f\n", m_index, m_pression->read());
marwanesaich 6:fda992188a2f 119 if(m_pression->read() > seuil[m_index]){
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
marwanesaich 2:4cc8fa2f64be 128 bool Ventouse::getPompe()
marwanesaich 0:84a8c24e29ae 129 {
marwanesaich 0:84a8c24e29ae 130 if(m_pompe->read() > 0){
marwanesaich 0:84a8c24e29ae 131 return 1;
marwanesaich 0:84a8c24e29ae 132 }
marwanesaich 0:84a8c24e29ae 133 else{
marwanesaich 0:84a8c24e29ae 134 return 0;
marwanesaich 0:84a8c24e29ae 135 }
marwanesaich 0:84a8c24e29ae 136 }
marwanesaich 0:84a8c24e29ae 137
marwanesaich 0:84a8c24e29ae 138 void Ventouse::setPompe(float val)
marwanesaich 0:84a8c24e29ae 139 {
marwanesaich 0:84a8c24e29ae 140 m_pompe->write(val);
marwanesaich 0:84a8c24e29ae 141 }
marwanesaich 0:84a8c24e29ae 142
marwanesaich 0:84a8c24e29ae 143 void Ventouse::setElectrovanne(float val)
marwanesaich 0:84a8c24e29ae 144 {
marwanesaich 5:176e7353ba1c 145 if(flag_electrovanne)m_electrovanne->write(val);
marwanesaich 0:84a8c24e29ae 146 }
marwanesaich 0:84a8c24e29ae 147
marwanesaich 0:84a8c24e29ae 148
marwanesaich 0:84a8c24e29ae 149