carte esclave pompe 2020 V1

Dependencies:   mbed ident_crac

Committer:
kyxstark
Date:
Thu May 23 08:41:01 2019 +0000
Revision:
12:2491a5b0f90b
Parent:
10:765b4ff6d721
Child:
16:5e00af31ae8a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marwanesaich 0:84a8c24e29ae 1 #include "class_ventouse.h"
marwanesaich 0:84a8c24e29ae 2
kyxstark 8:a25a9c22ba91 3 #ifdef ROBOT_SMALL
kyxstark 8:a25a9c22ba91 4 float seuil[NB_VENTOUSES] = {0.10, 0.3, 0.3, 0.3, 0.10, 0.3, 0.3, 0.3};
kyxstark 10:765b4ff6d721 5 #define PWM_POMPE 0.7
kyxstark 8:a25a9c22ba91 6 #endif
kyxstark 8:a25a9c22ba91 7
kyxstark 8:a25a9c22ba91 8 #ifdef ROBOT_BIG
kyxstark 8:a25a9c22ba91 9 float seuil[NB_VENTOUSES] = {0.3, 0.3, 0.3};
kyxstark 10:765b4ff6d721 10 #define PWM_POMPE 1.0
kyxstark 8:a25a9c22ba91 11 #endif
marwanesaich 0:84a8c24e29ae 12
marwanesaich 0:84a8c24e29ae 13
marwanesaich 5:176e7353ba1c 14 Ventouse::Ventouse(PinName pinPompe, PinName pinCapteurPression, char index) : m_pinPompe(pinPompe),
marwanesaich 5:176e7353ba1c 15 m_pinCapteurPression(pinCapteurPression), m_index(index)
marwanesaich 5:176e7353ba1c 16 {
marwanesaich 5:176e7353ba1c 17 m_pompe = new PwmOut(m_pinPompe);
marwanesaich 5:176e7353ba1c 18 m_pression = new AnalogIn(m_pinCapteurPression);
marwanesaich 5:176e7353ba1c 19
marwanesaich 5:176e7353ba1c 20 m_pompe->period_us(50);
marwanesaich 5:176e7353ba1c 21
marwanesaich 5:176e7353ba1c 22 m_pompe->write(0);
marwanesaich 5:176e7353ba1c 23
marwanesaich 5:176e7353ba1c 24 flag_attraper = 0;
marwanesaich 5:176e7353ba1c 25 flag_relacher = 0;
marwanesaich 5:176e7353ba1c 26
marwanesaich 5:176e7353ba1c 27 etat = Attente;
marwanesaich 5:176e7353ba1c 28 m_ack = 0;
marwanesaich 5:176e7353ba1c 29 flag_electrovanne = 0;
marwanesaich 5:176e7353ba1c 30 }
marwanesaich 5:176e7353ba1c 31
marwanesaich 5:176e7353ba1c 32
marwanesaich 2:4cc8fa2f64be 33 Ventouse::Ventouse(PinName pinPompe, PinName pinElectrovanne, PinName pinCapteurPression, char index) : m_pinPompe(pinPompe),
marwanesaich 2:4cc8fa2f64be 34 m_pinElectrovanne(pinElectrovanne), m_pinCapteurPression(pinCapteurPression), m_index(index)
marwanesaich 0:84a8c24e29ae 35 {
marwanesaich 0:84a8c24e29ae 36 m_pompe = new PwmOut(m_pinPompe);
kyxstark 8:a25a9c22ba91 37 m_electrovanne = new DigitalOut(m_pinElectrovanne);
marwanesaich 0:84a8c24e29ae 38 m_pression = new AnalogIn(m_pinCapteurPression);
marwanesaich 0:84a8c24e29ae 39
marwanesaich 0:84a8c24e29ae 40 m_pompe->period_us(50);
kyxstark 8:a25a9c22ba91 41 //m_electrovanne->period_us(50);
marwanesaich 0:84a8c24e29ae 42
marwanesaich 0:84a8c24e29ae 43 m_pompe->write(0);
marwanesaich 0:84a8c24e29ae 44 m_electrovanne->write(0);
marwanesaich 2:4cc8fa2f64be 45
marwanesaich 2:4cc8fa2f64be 46 flag_attraper = 0;
marwanesaich 2:4cc8fa2f64be 47 flag_relacher = 0;
marwanesaich 2:4cc8fa2f64be 48
marwanesaich 2:4cc8fa2f64be 49 etat = Attente;
marwanesaich 2:4cc8fa2f64be 50 m_ack = 0;
marwanesaich 5:176e7353ba1c 51 flag_electrovanne = 1;
marwanesaich 2:4cc8fa2f64be 52 }
marwanesaich 2:4cc8fa2f64be 53
marwanesaich 2:4cc8fa2f64be 54 void Ventouse::automate()
marwanesaich 2:4cc8fa2f64be 55 {
marwanesaich 2:4cc8fa2f64be 56 switch(etat)
marwanesaich 2:4cc8fa2f64be 57 {
marwanesaich 2:4cc8fa2f64be 58 case Attente :
marwanesaich 2:4cc8fa2f64be 59 if(flag_attraper)
marwanesaich 2:4cc8fa2f64be 60 {
marwanesaich 2:4cc8fa2f64be 61 attraper();
marwanesaich 2:4cc8fa2f64be 62 etat = Attraper;
marwanesaich 2:4cc8fa2f64be 63 }
marwanesaich 2:4cc8fa2f64be 64 break;
marwanesaich 2:4cc8fa2f64be 65
marwanesaich 2:4cc8fa2f64be 66 case Attraper :
marwanesaich 6:fda992188a2f 67 wait_ms(10.0);
marwanesaich 7:43d9c70b6689 68 if(getPression()==1)
marwanesaich 4:82c90657da4a 69 {
marwanesaich 4:82c90657da4a 70 can.write(CANMessage(HACHEUR_GET_ATOM_ACK,&m_index,1));
marwanesaich 2:4cc8fa2f64be 71 etat = Attraper_ok;
marwanesaich 2:4cc8fa2f64be 72 }else if(flag_relacher)
marwanesaich 2:4cc8fa2f64be 73 {
marwanesaich 2:4cc8fa2f64be 74 relacher();
marwanesaich 2:4cc8fa2f64be 75 etat = Relacher;
marwanesaich 2:4cc8fa2f64be 76 }
marwanesaich 2:4cc8fa2f64be 77 break;
marwanesaich 2:4cc8fa2f64be 78
marwanesaich 2:4cc8fa2f64be 79 case Attraper_ok :
marwanesaich 2:4cc8fa2f64be 80 if(flag_relacher)
marwanesaich 2:4cc8fa2f64be 81 {
marwanesaich 2:4cc8fa2f64be 82 relacher();
marwanesaich 2:4cc8fa2f64be 83 etat = Relacher;
marwanesaich 2:4cc8fa2f64be 84 }
marwanesaich 2:4cc8fa2f64be 85 break;
marwanesaich 2:4cc8fa2f64be 86
marwanesaich 2:4cc8fa2f64be 87 case Relacher :
marwanesaich 7:43d9c70b6689 88 wait_ms(10.0);
marwanesaich 7:43d9c70b6689 89 if(getPression() == 0)
marwanesaich 2:4cc8fa2f64be 90 {
marwanesaich 4:82c90657da4a 91 can.write(CANMessage(HACHEUR_RELEASE_ATOM_ACK,&m_index,1));
kyxstark 8:a25a9c22ba91 92 if(flag_electrovanne) m_electrovanne->write(0);
marwanesaich 2:4cc8fa2f64be 93 etat = Attente;
marwanesaich 2:4cc8fa2f64be 94 }
marwanesaich 2:4cc8fa2f64be 95 break;
marwanesaich 2:4cc8fa2f64be 96
marwanesaich 2:4cc8fa2f64be 97 }
marwanesaich 2:4cc8fa2f64be 98 }
marwanesaich 2:4cc8fa2f64be 99
marwanesaich 2:4cc8fa2f64be 100
marwanesaich 2:4cc8fa2f64be 101 void Ventouse::action(bool action)
marwanesaich 2:4cc8fa2f64be 102 {
marwanesaich 2:4cc8fa2f64be 103 flag_attraper = action;
marwanesaich 2:4cc8fa2f64be 104 flag_relacher = !action;
marwanesaich 0:84a8c24e29ae 105 }
marwanesaich 0:84a8c24e29ae 106
marwanesaich 0:84a8c24e29ae 107 void Ventouse::attraper()
marwanesaich 0:84a8c24e29ae 108 {
kyxstark 10:765b4ff6d721 109 m_pompe->write(PWM_POMPE);
kyxstark 8:a25a9c22ba91 110 if(flag_electrovanne) m_electrovanne->write(0);
marwanesaich 0:84a8c24e29ae 111
marwanesaich 0:84a8c24e29ae 112 }
marwanesaich 0:84a8c24e29ae 113
marwanesaich 0:84a8c24e29ae 114 void Ventouse::relacher()
marwanesaich 0:84a8c24e29ae 115 {
marwanesaich 0:84a8c24e29ae 116 m_pompe->write(0.0);
kyxstark 8:a25a9c22ba91 117 if(flag_electrovanne) m_electrovanne->write(1);
marwanesaich 7:43d9c70b6689 118 wait_ms(300.0);
marwanesaich 0:84a8c24e29ae 119
marwanesaich 0:84a8c24e29ae 120 }
marwanesaich 0:84a8c24e29ae 121
marwanesaich 2:4cc8fa2f64be 122 bool Ventouse::getPression()
marwanesaich 6:fda992188a2f 123 {
marwanesaich 7:43d9c70b6689 124 printf("capteur %d : %f\n", m_index, m_pression->read());
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