![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
mbed-os github
Dependencies: ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep
Fork of ARNSRS_testDFU by
main.cpp@18:bfd78c05b589, 2017-12-05 (annotated)
- Committer:
- POTLESS_2
- Date:
- Tue Dec 05 15:20:29 2017 +0000
- Revision:
- 18:bfd78c05b589
- Parent:
- 17:bef8abc445f2
- Child:
- 19:cac3761a5d0b
OTU, secours
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
POTLESS_2 | 17:bef8abc445f2 | 1 | /* |
POTLESS_2 | 17:bef8abc445f2 | 2 | |
POTLESS_2 | 17:bef8abc445f2 | 3 | Câblage complet STM32L476RG : |
POTLESS_2 | 17:bef8abc445f2 | 4 | |
POTLESS_2 | 17:bef8abc445f2 | 5 | - Port SPI carte SD : |
POTLESS_2 | 17:bef8abc445f2 | 6 | |
POTLESS_2 | 17:bef8abc445f2 | 7 | MOSI -> PA_7 |
POTLESS_2 | 17:bef8abc445f2 | 8 | MISO -> PA_6 |
POTLESS_2 | 17:bef8abc445f2 | 9 | SCK -> PA_5 |
POTLESS_2 | 17:bef8abc445f2 | 10 | CS -> PB_6 |
POTLESS_2 | 17:bef8abc445f2 | 11 | |
POTLESS_2 | 17:bef8abc445f2 | 12 | - Sensor Head : |
POTLESS_2 | 17:bef8abc445f2 | 13 | |
POTLESS_2 | 17:bef8abc445f2 | 14 | Alim en 3.3v |
POTLESS_2 | 17:bef8abc445f2 | 15 | |
POTLESS_2 | 17:bef8abc445f2 | 16 | SCL -> PB_8 |
POTLESS_2 | 17:bef8abc445f2 | 17 | SDA -> PB_9 |
POTLESS_2 | 17:bef8abc445f2 | 18 | TX -> PC_12 |
POTLESS_2 | 17:bef8abc445f2 | 19 | RX -> PD_2 |
POTLESS_2 | 17:bef8abc445f2 | 20 | AlertRdy -> PA_11 |
POTLESS_2 | 17:bef8abc445f2 | 21 | |
POTLESS_2 | 17:bef8abc445f2 | 22 | |
POTLESS_2 | 17:bef8abc445f2 | 23 | - HC_06 : |
POTLESS_2 | 17:bef8abc445f2 | 24 | |
POTLESS_2 | 17:bef8abc445f2 | 25 | Alim en 3.3v ou 5v |
POTLESS_2 | 17:bef8abc445f2 | 26 | |
POTLESS_2 | 17:bef8abc445f2 | 27 | TX -> PC_10 |
POTLESS_2 | 17:bef8abc445f2 | 28 | RX -> PC_11 |
POTLESS_2 | 17:bef8abc445f2 | 29 | |
POTLESS_2 | 17:bef8abc445f2 | 30 | - STM32L476RG sur H-Bridge L293 : |
POTLESS_2 | 17:bef8abc445f2 | 31 | |
POTLESS_2 | 17:bef8abc445f2 | 32 | Reférence L293 : http://www.ti.com/lit/ds/symlink/l293.pdf |
POTLESS_2 | 17:bef8abc445f2 | 33 | |
POTLESS_2 | 17:bef8abc445f2 | 34 | Volet Poumon : |
POTLESS_2 | 17:bef8abc445f2 | 35 | PWM -> PB_5 -> 1 |
POTLESS_2 | 17:bef8abc445f2 | 36 | FWD -> PB_4 -> 2 |
POTLESS_2 | 17:bef8abc445f2 | 37 | REV -> PB_10 -> 7 |
POTLESS_2 | 17:bef8abc445f2 | 38 | |
POTLESS_2 | 17:bef8abc445f2 | 39 | Volet Fuite : |
POTLESS_2 | 17:bef8abc445f2 | 40 | PWM -> PB_13 -> 9 |
POTLESS_2 | 17:bef8abc445f2 | 41 | FWD -> PB_14 -> 10 |
POTLESS_2 | 17:bef8abc445f2 | 42 | REV -> PB_15 -> 15 |
POTLESS_2 | 17:bef8abc445f2 | 43 | |
POTLESS_2 | 17:bef8abc445f2 | 44 | Potentiomètres retour Position : |
POTLESS_2 | 17:bef8abc445f2 | 45 | |
POTLESS_2 | 17:bef8abc445f2 | 46 | Alim en 3.3v |
POTLESS_2 | 17:bef8abc445f2 | 47 | |
POTLESS_2 | 17:bef8abc445f2 | 48 | Feedback Volet Poumon -> PC_2 |
POTLESS_2 | 17:bef8abc445f2 | 49 | Feedback Volet Fuite -> PC_3 |
POTLESS_2 | 17:bef8abc445f2 | 50 | |
POTLESS_2 | 17:bef8abc445f2 | 51 | - Câblage complet du H-Bridge L293 : |
POTLESS_2 | 17:bef8abc445f2 | 52 | |
POTLESS_2 | 17:bef8abc445f2 | 53 | 1 -> PB_5 |
POTLESS_2 | 17:bef8abc445f2 | 54 | 2 -> PB_4 |
POTLESS_2 | 17:bef8abc445f2 | 55 | 3 -> Borne moteur |
POTLESS_2 | 17:bef8abc445f2 | 56 | 4 -> non connectée |
POTLESS_2 | 17:bef8abc445f2 | 57 | 5 -> GND |
POTLESS_2 | 17:bef8abc445f2 | 58 | 6 -> Borne moteur |
POTLESS_2 | 17:bef8abc445f2 | 59 | 7 -> PB_10 |
POTLESS_2 | 17:bef8abc445f2 | 60 | 8 -> V+ Alimentation moteurs 4.5v - 36v |
POTLESS_2 | 17:bef8abc445f2 | 61 | |
POTLESS_2 | 17:bef8abc445f2 | 62 | 9 -> PB_13 |
POTLESS_2 | 17:bef8abc445f2 | 63 | 10 -> PB_14 |
POTLESS_2 | 17:bef8abc445f2 | 64 | 11 -> Borne moteur |
POTLESS_2 | 17:bef8abc445f2 | 65 | 12 -> GND |
POTLESS_2 | 17:bef8abc445f2 | 66 | 13 -> non connectée |
POTLESS_2 | 17:bef8abc445f2 | 67 | 14 -> borne moteur |
POTLESS_2 | 17:bef8abc445f2 | 68 | 15 -> PB_15 |
POTLESS_2 | 17:bef8abc445f2 | 69 | 16 -> V+ Alimentation logic 5v (alim moteur si tension compatible....) |
POTLESS_2 | 17:bef8abc445f2 | 70 | |
POTLESS_2 | 17:bef8abc445f2 | 71 | */ |
POTLESS_2 | 18:bfd78c05b589 | 72 | |
potless | 1:bef7856b5c0a | 73 | #include "mbed.h" |
potless | 2:4a8bf1d53439 | 74 | #include <string> |
POTLESS_2 | 7:ad15c386e960 | 75 | #include "Sensor_head_revB.h" |
POTLESS_2 | 8:a750d531b381 | 76 | #include "HTU21D.h" |
POTLESS_2 | 12:7f3aadd79f89 | 77 | #include "PID.h" |
POTLESS_2 | 17:bef8abc445f2 | 78 | #include "Actuonix.h" |
POTLESS_2 | 4:d84250f67dec | 79 | |
POTLESS_2 | 17:bef8abc445f2 | 80 | //Commandes des servos |
POTLESS_2 | 17:bef8abc445f2 | 81 | #define PWM_SERVO_POUMON PB_5 |
POTLESS_2 | 17:bef8abc445f2 | 82 | #define FWD_SERVO_POUMON PB_4 |
POTLESS_2 | 17:bef8abc445f2 | 83 | #define REV_SERVO_POUMON PB_10 |
POTLESS_2 | 10:aca745a66d51 | 84 | #define FEED_BACK_SERVO_POUMON PC_2 |
POTLESS_2 | 17:bef8abc445f2 | 85 | |
POTLESS_2 | 17:bef8abc445f2 | 86 | #define PWM_SERVO_FUITE PB_13 |
POTLESS_2 | 17:bef8abc445f2 | 87 | #define FWD_SERVO_FUITE PB_14 |
POTLESS_2 | 17:bef8abc445f2 | 88 | #define REV_SERVO_FUITE PB_15 |
POTLESS_2 | 10:aca745a66d51 | 89 | #define FEED_BACK_SERVO_FUITE PC_3 |
POTLESS_2 | 9:04bfdfc029cb | 90 | |
POTLESS_2 | 17:bef8abc445f2 | 91 | //Mapping des valeur. |
POTLESS_2 | 17:bef8abc445f2 | 92 | #define MAX_MAP 100//Mapping en pourcentage |
POTLESS_2 | 17:bef8abc445f2 | 93 | //#define MAX_MAP 90//Mapping en en degrés sur 90 degrés |
POTLESS_2 | 17:bef8abc445f2 | 94 | |
POTLESS_2 | 17:bef8abc445f2 | 95 | //Ecrit dans le moniteur série de la tablette à 115200 bds si sur 1, penser à mettre NEED_CONSOLE_OUTPUT à 0 |
POTLESS_2 | 9:04bfdfc029cb | 96 | #define NEED_ANDROID_OUTPUT 1 |
POTLESS_2 | 9:04bfdfc029cb | 97 | |
POTLESS_2 | 10:aca745a66d51 | 98 | //Sortie en mode VT100, à commenter si on veut une sortie type Arduino |
POTLESS_2 | 10:aca745a66d51 | 99 | //#define VT100 |
POTLESS_2 | 9:04bfdfc029cb | 100 | |
POTLESS_2 | 17:bef8abc445f2 | 101 | //Mode PID, STD à commenter / décommenter |
POTLESS_2 | 17:bef8abc445f2 | 102 | #define STD_MODE |
POTLESS_2 | 17:bef8abc445f2 | 103 | //#define PID_MODE |
POTLESS_2 | 11:b2feed92584a | 104 | |
POTLESS_2 | 12:7f3aadd79f89 | 105 | #ifdef STD_MODE |
POTLESS_2 | 12:7f3aadd79f89 | 106 | int MODE_FLAG = 0; |
POTLESS_2 | 11:b2feed92584a | 107 | #endif |
POTLESS_2 | 11:b2feed92584a | 108 | |
POTLESS_2 | 12:7f3aadd79f89 | 109 | #ifdef PID_MODE |
POTLESS_2 | 12:7f3aadd79f89 | 110 | int MODE_FLAG = 2; |
POTLESS_2 | 11:b2feed92584a | 111 | #endif |
POTLESS_2 | 11:b2feed92584a | 112 | |
POTLESS_2 | 9:04bfdfc029cb | 113 | #if NEED_ANDROID_OUTPUT |
POTLESS_2 | 9:04bfdfc029cb | 114 | #define ANDROID(...) { android.printf(__VA_ARGS__); } |
POTLESS_2 | 9:04bfdfc029cb | 115 | #else |
POTLESS_2 | 9:04bfdfc029cb | 116 | #define ANDROID(...) |
POTLESS_2 | 9:04bfdfc029cb | 117 | #endif |
POTLESS_2 | 9:04bfdfc029cb | 118 | |
POTLESS_2 | 17:bef8abc445f2 | 119 | Actuonix Servo_Poumon(FEED_BACK_SERVO_POUMON, PWM_SERVO_POUMON, FWD_SERVO_POUMON, REV_SERVO_POUMON, 1, MAX_MAP); |
POTLESS_2 | 18:bfd78c05b589 | 120 | |
POTLESS_2 | 17:bef8abc445f2 | 121 | Actuonix Servo_Fuite(FEED_BACK_SERVO_FUITE, PWM_SERVO_FUITE, FWD_SERVO_FUITE, REV_SERVO_FUITE, 1, MAX_MAP); |
POTLESS_2 | 17:bef8abc445f2 | 122 | |
POTLESS_2 | 17:bef8abc445f2 | 123 | //Moniteur série, Serial 2 |
POTLESS_2 | 17:bef8abc445f2 | 124 | Serial serialMonit(USBTX,USBRX,115200); |
POTLESS_2 | 10:aca745a66d51 | 125 | |
POTLESS_2 | 9:04bfdfc029cb | 126 | //COM Série vers Android, Serial 3 |
POTLESS_2 | 17:bef8abc445f2 | 127 | Serial android(PC_10,PC_11,115200); |
POTLESS_2 | 4:d84250f67dec | 128 | |
POTLESS_2 | 7:ad15c386e960 | 129 | //Init de la lib ARNSRS; |
POTLESS_2 | 7:ad15c386e960 | 130 | SENSOR_HEAD_REV_B sensors; |
potless | 2:4a8bf1d53439 | 131 | |
POTLESS_2 | 6:ebed9093d661 | 132 | //pour Param Cozir |
POTLESS_2 | 9:04bfdfc029cb | 133 | const int sizeParam = 20; |
POTLESS_2 | 11:b2feed92584a | 134 | char param[sizeParam]; |
POTLESS_2 | 11:b2feed92584a | 135 | volatile int indexParam = 0; |
POTLESS_2 | 6:ebed9093d661 | 136 | bool newParamFlag = false; |
potless | 2:4a8bf1d53439 | 137 | |
POTLESS_2 | 9:04bfdfc029cb | 138 | //pour Commandes Android |
POTLESS_2 | 9:04bfdfc029cb | 139 | const int sizeAndroid = 20; |
POTLESS_2 | 11:b2feed92584a | 140 | char Android[sizeAndroid]; |
POTLESS_2 | 11:b2feed92584a | 141 | volatile int indexAndroid = 0; |
POTLESS_2 | 9:04bfdfc029cb | 142 | bool newAndroidFlag = false; |
POTLESS_2 | 12:7f3aadd79f89 | 143 | char to_android[100]; |
POTLESS_2 | 9:04bfdfc029cb | 144 | |
POTLESS_2 | 7:ad15c386e960 | 145 | //Variables de stockage des infos capteurs |
POTLESS_2 | 7:ad15c386e960 | 146 | int co2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 147 | float pression = 0; |
POTLESS_2 | 9:04bfdfc029cb | 148 | float Temp1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 149 | int ppO2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 150 | int CellO2_1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 151 | int CellO2_2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 152 | |
POTLESS_2 | 18:bfd78c05b589 | 153 | //Variables et constantes OTU |
POTLESS_2 | 18:bfd78c05b589 | 154 | float OTU = 0; |
POTLESS_2 | 18:bfd78c05b589 | 155 | float COEF_OTU = 0.83; |
POTLESS_2 | 18:bfd78c05b589 | 156 | |
POTLESS_2 | 17:bef8abc445f2 | 157 | //Mesure du temps d'éxecution du loop |
POTLESS_2 | 7:ad15c386e960 | 158 | Timer REAL_RATE; |
POTLESS_2 | 7:ad15c386e960 | 159 | float RATE = 0; |
POTLESS_2 | 11:b2feed92584a | 160 | float RATE_TRUE = 0; |
POTLESS_2 | 12:7f3aadd79f89 | 161 | float Ref_Time = 1.0; //La durée de la boucle désirée... |
POTLESS_2 | 7:ad15c386e960 | 162 | |
POTLESS_2 | 17:bef8abc445f2 | 163 | //HTU21D sur l'I2C |
POTLESS_2 | 8:a750d531b381 | 164 | HTU21D temphumid(PB_9, PB_8); //Temp humid sensor || SDA, SCL |
POTLESS_2 | 9:04bfdfc029cb | 165 | float Temp2; |
POTLESS_2 | 9:04bfdfc029cb | 166 | int Humid; |
POTLESS_2 | 9:04bfdfc029cb | 167 | |
POTLESS_2 | 9:04bfdfc029cb | 168 | //Data LOG |
POTLESS_2 | 9:04bfdfc029cb | 169 | char to_store[50]; |
POTLESS_2 | 9:04bfdfc029cb | 170 | time_t seconds; |
POTLESS_2 | 8:a750d531b381 | 171 | |
POTLESS_2 | 8:a750d531b381 | 172 | //VT100 |
POTLESS_2 | 8:a750d531b381 | 173 | static const char CLS[] = "\x1B[2J"; |
POTLESS_2 | 8:a750d531b381 | 174 | static const char HOME[] = "\x1B[H"; |
POTLESS_2 | 8:a750d531b381 | 175 | |
POTLESS_2 | 17:bef8abc445f2 | 176 | //Thread d'intérogation des capteurs et de positionnement des volets |
POTLESS_2 | 7:ad15c386e960 | 177 | Thread thread; |
POTLESS_2 | 7:ad15c386e960 | 178 | |
POTLESS_2 | 10:aca745a66d51 | 179 | //Contrôle des servos |
POTLESS_2 | 17:bef8abc445f2 | 180 | float Consigne_poumon = 50; |
POTLESS_2 | 10:aca745a66d51 | 181 | float volet_poumon_Position; |
POTLESS_2 | 10:aca745a66d51 | 182 | |
POTLESS_2 | 17:bef8abc445f2 | 183 | float Consigne_fuite = 50; |
POTLESS_2 | 10:aca745a66d51 | 184 | float volet_fuite_Position; |
POTLESS_2 | 10:aca745a66d51 | 185 | |
POTLESS_2 | 12:7f3aadd79f89 | 186 | #ifdef PID_MODE |
POTLESS_2 | 12:7f3aadd79f89 | 187 | //Paramètre du PID |
POTLESS_2 | 12:7f3aadd79f89 | 188 | float Kc = 40; |
POTLESS_2 | 12:7f3aadd79f89 | 189 | float Ti = 0; |
POTLESS_2 | 12:7f3aadd79f89 | 190 | float Td = 0; |
POTLESS_2 | 12:7f3aadd79f89 | 191 | float RATE_PID = Ref_Time; |
POTLESS_2 | 12:7f3aadd79f89 | 192 | float Commande_PID; |
POTLESS_2 | 15:efd3b3bf3f37 | 193 | float consigne = 210; |
POTLESS_2 | 15:efd3b3bf3f37 | 194 | float Max_Input = 1000; |
POTLESS_2 | 15:efd3b3bf3f37 | 195 | float Min_Input = 80; |
POTLESS_2 | 18:bfd78c05b589 | 196 | float Max_Output = MAX_MAP - 5;//Vérifier la valeur pour angle à laisser ouvert... |
POTLESS_2 | 18:bfd78c05b589 | 197 | float Min_Output = 0; |
POTLESS_2 | 10:aca745a66d51 | 198 | |
POTLESS_2 | 12:7f3aadd79f89 | 199 | //Init PID |
POTLESS_2 | 17:bef8abc445f2 | 200 | PID control_Servo(Kc, Ti, Td, RATE_PID); |
POTLESS_2 | 12:7f3aadd79f89 | 201 | #endif |
POTLESS_2 | 10:aca745a66d51 | 202 | |
POTLESS_2 | 18:bfd78c05b589 | 203 | //Boolean du status de l'appareil, en mode secours ou nominal |
POTLESS_2 | 18:bfd78c05b589 | 204 | bool EN_MODE_SCOURS = false; |
POTLESS_2 | 18:bfd78c05b589 | 205 | |
POTLESS_2 | 18:bfd78c05b589 | 206 | //Passage en mode secours |
POTLESS_2 | 18:bfd78c05b589 | 207 | void Mode_Secours() |
POTLESS_2 | 18:bfd78c05b589 | 208 | { |
POTLESS_2 | 18:bfd78c05b589 | 209 | #ifdef PID_MODE |
POTLESS_2 | 18:bfd78c05b589 | 210 | //Mise du PID en mode manuel (desactivation...) |
POTLESS_2 | 18:bfd78c05b589 | 211 | control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 18:bfd78c05b589 | 212 | #endif |
POTLESS_2 | 18:bfd78c05b589 | 213 | Consigne_poumon = MAX_MAP; |
POTLESS_2 | 18:bfd78c05b589 | 214 | Consigne_fuite = MAX_MAP; |
POTLESS_2 | 18:bfd78c05b589 | 215 | printf("-------------- Appareil en mode secours ---------------"); |
POTLESS_2 | 18:bfd78c05b589 | 216 | EN_MODE_SCOURS = true; |
POTLESS_2 | 18:bfd78c05b589 | 217 | } |
POTLESS_2 | 18:bfd78c05b589 | 218 | |
POTLESS_2 | 18:bfd78c05b589 | 219 | //Contrôle du status de l'appareil / des constantes |
POTLESS_2 | 18:bfd78c05b589 | 220 | bool Check() |
POTLESS_2 | 18:bfd78c05b589 | 221 | { |
POTLESS_2 | 18:bfd78c05b589 | 222 | if (ppO2 > 100) |
POTLESS_2 | 18:bfd78c05b589 | 223 | return true;//Situation OK |
POTLESS_2 | 18:bfd78c05b589 | 224 | else |
POTLESS_2 | 18:bfd78c05b589 | 225 | return false;//Situation dégradée |
POTLESS_2 | 18:bfd78c05b589 | 226 | } |
POTLESS_2 | 18:bfd78c05b589 | 227 | |
POTLESS_2 | 18:bfd78c05b589 | 228 | //Calcul des OTU |
POTLESS_2 | 18:bfd78c05b589 | 229 | float Calcul_OTU() |
POTLESS_2 | 18:bfd78c05b589 | 230 | { |
POTLESS_2 | 18:bfd78c05b589 | 231 | /* |
POTLESS_2 | 18:bfd78c05b589 | 232 | La formule suivante permet de calculer la quantité d' OTU accumulée |
POTLESS_2 | 18:bfd78c05b589 | 233 | OTU = T * (2* PpO2 -1)0,83 |
POTLESS_2 | 18:bfd78c05b589 | 234 | avec : |
POTLESS_2 | 18:bfd78c05b589 | 235 | T = temps de plongée en minutes |
POTLESS_2 | 18:bfd78c05b589 | 236 | PpO2 = pression partielle d’ oxygène en bars |
POTLESS_2 | 18:bfd78c05b589 | 237 | */ |
POTLESS_2 | 18:bfd78c05b589 | 238 | |
POTLESS_2 | 18:bfd78c05b589 | 239 | if (ppO2 > 500){ |
POTLESS_2 | 18:bfd78c05b589 | 240 | float val = (2 * (float)ppO2/1000 - 1);//je divise par 1000 car la PP est en mb... |
POTLESS_2 | 18:bfd78c05b589 | 241 | OTU += Ref_Time * pow(val, COEF_OTU); |
POTLESS_2 | 18:bfd78c05b589 | 242 | } |
POTLESS_2 | 18:bfd78c05b589 | 243 | } |
POTLESS_2 | 10:aca745a66d51 | 244 | |
POTLESS_2 | 17:bef8abc445f2 | 245 | //Thread d'intérogation des capteurs, positions servo |
POTLESS_2 | 10:aca745a66d51 | 246 | void Get_Info_thread() |
POTLESS_2 | 6:ebed9093d661 | 247 | { |
POTLESS_2 | 7:ad15c386e960 | 248 | while (true) { |
POTLESS_2 | 7:ad15c386e960 | 249 | |
POTLESS_2 | 7:ad15c386e960 | 250 | //CO2 sur Cozir |
POTLESS_2 | 7:ad15c386e960 | 251 | co2 = sensors.requestCO2(); |
POTLESS_2 | 7:ad15c386e960 | 252 | //P / T sur MS5837 |
POTLESS_2 | 7:ad15c386e960 | 253 | pression = sensors.requestPress(); |
POTLESS_2 | 9:04bfdfc029cb | 254 | Temp1 = sensors.requestTemp(); |
POTLESS_2 | 7:ad15c386e960 | 255 | //PPO2 sur ADS1015 |
POTLESS_2 | 7:ad15c386e960 | 256 | ppO2 = sensors.requestPpO2(); |
POTLESS_2 | 7:ad15c386e960 | 257 | //Cell O2 en mV |
POTLESS_2 | 7:ad15c386e960 | 258 | CellO2_1 = sensors.requestCellO2_1(); |
POTLESS_2 | 7:ad15c386e960 | 259 | CellO2_2 = sensors.requestCellO2_2(); |
POTLESS_2 | 9:04bfdfc029cb | 260 | |
POTLESS_2 | 8:a750d531b381 | 261 | //HTU21D |
POTLESS_2 | 9:04bfdfc029cb | 262 | Temp2 = temphumid.sample_ctemp(); |
POTLESS_2 | 9:04bfdfc029cb | 263 | Humid = temphumid.sample_humid(); |
POTLESS_2 | 9:04bfdfc029cb | 264 | |
POTLESS_2 | 10:aca745a66d51 | 265 | //Retour position des servos |
POTLESS_2 | 17:bef8abc445f2 | 266 | volet_poumon_Position = Servo_Poumon.Get_Position(); |
POTLESS_2 | 17:bef8abc445f2 | 267 | volet_fuite_Position = Servo_Fuite.Get_Position(); |
POTLESS_2 | 12:7f3aadd79f89 | 268 | |
POTLESS_2 | 17:bef8abc445f2 | 269 | //Position des servo mise à jour en permanence dans le thread |
POTLESS_2 | 17:bef8abc445f2 | 270 | Servo_Poumon.Go_To_Prop(Consigne_poumon); |
POTLESS_2 | 17:bef8abc445f2 | 271 | Servo_Fuite.Go_To_Prop(Consigne_fuite); |
POTLESS_2 | 18:bfd78c05b589 | 272 | |
POTLESS_2 | 18:bfd78c05b589 | 273 | if(!Check()) Mode_Secours(); |
POTLESS_2 | 15:efd3b3bf3f37 | 274 | } |
potless | 2:4a8bf1d53439 | 275 | } |
POTLESS_2 | 4:d84250f67dec | 276 | |
POTLESS_2 | 7:ad15c386e960 | 277 | void Affichage_moniteur() |
POTLESS_2 | 4:d84250f67dec | 278 | { |
POTLESS_2 | 12:7f3aadd79f89 | 279 | #ifndef VT100 |
POTLESS_2 | 9:04bfdfc029cb | 280 | printf("\r\n"); |
POTLESS_2 | 9:04bfdfc029cb | 281 | printf(" CO2 = %d ppm\r\n" , co2); |
POTLESS_2 | 9:04bfdfc029cb | 282 | printf(" PPO2 = %d mb\r\n", ppO2); |
POTLESS_2 | 18:bfd78c05b589 | 283 | printf(" OTU = %d \r\n", OTU); |
POTLESS_2 | 9:04bfdfc029cb | 284 | printf(" Pression = %f msw\r\n", pression); |
POTLESS_2 | 10:aca745a66d51 | 285 | printf(" Temp MS5837 = %f C\r\n", Temp1); |
POTLESS_2 | 10:aca745a66d51 | 286 | printf(" Temp HTU21D = %f C\n\r", Temp2); |
POTLESS_2 | 9:04bfdfc029cb | 287 | printf(" Humidity = %d %%\n\r", Humid); |
POTLESS_2 | 8:a750d531b381 | 288 | printf("\n\r"); |
POTLESS_2 | 8:a750d531b381 | 289 | printf(" Cell O2 n 1 = %d\r\n" , CellO2_1); |
POTLESS_2 | 8:a750d531b381 | 290 | printf(" Cell O2 n 2 = %d\r\n" , CellO2_2); |
POTLESS_2 | 7:ad15c386e960 | 291 | printf("\r\n"); |
POTLESS_2 | 9:04bfdfc029cb | 292 | printf("\n"); |
POTLESS_2 | 17:bef8abc445f2 | 293 | printf(" Volet Poumon = %f\r\n" , volet_poumon_Position); |
POTLESS_2 | 17:bef8abc445f2 | 294 | printf(" Volet Fuite = %f\r\n" , volet_fuite_Position); |
POTLESS_2 | 10:aca745a66d51 | 295 | printf("\r\n"); |
POTLESS_2 | 12:7f3aadd79f89 | 296 | printf("Temps d execution de la boucle = %f seconde(s)\n", (RATE + RATE_TRUE / 1000)); |
POTLESS_2 | 17:bef8abc445f2 | 297 | printf("\r\n"); |
POTLESS_2 | 9:04bfdfc029cb | 298 | printf("A enregistrer = %s\n", to_store); |
POTLESS_2 | 9:04bfdfc029cb | 299 | printf("\r\n"); |
POTLESS_2 | 10:aca745a66d51 | 300 | #endif |
POTLESS_2 | 9:04bfdfc029cb | 301 | |
POTLESS_2 | 12:7f3aadd79f89 | 302 | #ifdef VT100 |
POTLESS_2 | 8:a750d531b381 | 303 | printf(HOME); |
POTLESS_2 | 8:a750d531b381 | 304 | printf("\x1b[30m"); |
POTLESS_2 | 9:04bfdfc029cb | 305 | printf("\x1b[0m\r CO2 = \x1b[1m\x1b[K%d ppm\n", co2); |
POTLESS_2 | 9:04bfdfc029cb | 306 | printf("\x1b[0m\r PPO2 = \x1b[1m\x1b[K%d mb\n", ppO2); |
POTLESS_2 | 9:04bfdfc029cb | 307 | printf("\n"); |
POTLESS_2 | 18:bfd78c05b589 | 308 | printf("\x1b[0m\r OTU = \x1b[1m\x1b[K%d mb\n", OTU); |
POTLESS_2 | 18:bfd78c05b589 | 309 | printf("\n"); |
POTLESS_2 | 9:04bfdfc029cb | 310 | printf("\x1b[0m\r Pression = \x1b[1m\x1b[K%.2f msw\n", pression); |
POTLESS_2 | 9:04bfdfc029cb | 311 | printf("\n"); |
POTLESS_2 | 10:aca745a66d51 | 312 | printf("\x1b[0m\r Temp MS5837 = \x1b[1m\x1b[K%.2f C\n", Temp1); |
POTLESS_2 | 10:aca745a66d51 | 313 | printf("\x1b[0m\r Temp HTU21D = \x1b[1m\x1b[K%.2f C\n", Temp2); |
POTLESS_2 | 9:04bfdfc029cb | 314 | printf("\n"); |
POTLESS_2 | 9:04bfdfc029cb | 315 | printf("\x1b[0m\r Humidity = \x1b[1m\x1b[K%d %\n", Humid); |
POTLESS_2 | 9:04bfdfc029cb | 316 | printf("\n"); |
POTLESS_2 | 8:a750d531b381 | 317 | printf("\x1b[0m\r Cell O2 n 1 = \x1b[1m\x1b[K%d\n", CellO2_1); |
POTLESS_2 | 8:a750d531b381 | 318 | printf("\x1b[0m\r Cell O2 n 2 = \x1b[1m\x1b[K%d\n", CellO2_2); |
POTLESS_2 | 8:a750d531b381 | 319 | printf("\n"); |
POTLESS_2 | 17:bef8abc445f2 | 320 | printf("\x1b[0m\r Volet Poumon = \x1b[1m\x1b[K%.2f\n", volet_poumon_Position); |
POTLESS_2 | 17:bef8abc445f2 | 321 | printf("\x1b[0m\r Volet Fuite = \x1b[1m\x1b[K%.2f\n", volet_fuite_Position); |
POTLESS_2 | 10:aca745a66d51 | 322 | printf("\n"); |
POTLESS_2 | 13:22a96dc67e85 | 323 | printf("\x1b[0m\r Temps d execution de la boucle = \x1b[1m\x1b[K%f seconde(s)\n", (RATE + RATE_TRUE / 1000)); |
POTLESS_2 | 17:bef8abc445f2 | 324 | printf("\r\n"); |
POTLESS_2 | 9:04bfdfc029cb | 325 | printf("\x1b[0m\r A enregistrer = \x1b[1m\x1b[K%s\n", to_store); |
POTLESS_2 | 17:bef8abc445f2 | 326 | printf("\r\n"); |
POTLESS_2 | 12:7f3aadd79f89 | 327 | #endif |
POTLESS_2 | 4:d84250f67dec | 328 | } |
POTLESS_2 | 4:d84250f67dec | 329 | |
POTLESS_2 | 11:b2feed92584a | 330 | //Callback de l'intérruption des envois de commandes depuis le terminal |
POTLESS_2 | 6:ebed9093d661 | 331 | void callbackParam() |
POTLESS_2 | 4:d84250f67dec | 332 | { |
POTLESS_2 | 6:ebed9093d661 | 333 | while(serialMonit.readable()) { |
POTLESS_2 | 6:ebed9093d661 | 334 | if (indexParam == sizeParam) //éviter la saturation du buffer |
POTLESS_2 | 6:ebed9093d661 | 335 | serialMonit.getc(); |
POTLESS_2 | 6:ebed9093d661 | 336 | else |
POTLESS_2 | 6:ebed9093d661 | 337 | param [indexParam++] = serialMonit.getc();//chargement du buffer dans le message |
POTLESS_2 | 6:ebed9093d661 | 338 | if ((indexParam == sizeParam) || (param[indexParam -1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 6:ebed9093d661 | 339 | param[indexParam] = 0; |
POTLESS_2 | 6:ebed9093d661 | 340 | newParamFlag = true; |
POTLESS_2 | 6:ebed9093d661 | 341 | } |
POTLESS_2 | 4:d84250f67dec | 342 | } |
POTLESS_2 | 6:ebed9093d661 | 343 | } |
POTLESS_2 | 4:d84250f67dec | 344 | |
POTLESS_2 | 9:04bfdfc029cb | 345 | //Callback de l'intérruption des envois de commandes depuis Android |
POTLESS_2 | 9:04bfdfc029cb | 346 | void callbackAndroid() |
POTLESS_2 | 9:04bfdfc029cb | 347 | { |
POTLESS_2 | 9:04bfdfc029cb | 348 | while(android.readable()) { |
POTLESS_2 | 9:04bfdfc029cb | 349 | if (indexAndroid == sizeAndroid) //éviter la saturation du buffer |
POTLESS_2 | 9:04bfdfc029cb | 350 | android.getc(); |
POTLESS_2 | 9:04bfdfc029cb | 351 | else |
POTLESS_2 | 9:04bfdfc029cb | 352 | Android [indexAndroid++] = android.getc();//chargement du buffer dans le message |
POTLESS_2 | 9:04bfdfc029cb | 353 | if ((indexAndroid == sizeAndroid) || (Android[indexAndroid -1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 9:04bfdfc029cb | 354 | Android[indexAndroid] = 0; |
POTLESS_2 | 9:04bfdfc029cb | 355 | newAndroidFlag = true; |
POTLESS_2 | 9:04bfdfc029cb | 356 | } |
POTLESS_2 | 9:04bfdfc029cb | 357 | } |
POTLESS_2 | 9:04bfdfc029cb | 358 | } |
POTLESS_2 | 11:b2feed92584a | 359 | |
POTLESS_2 | 9:04bfdfc029cb | 360 | void Decoding_Message(char message []) |
POTLESS_2 | 9:04bfdfc029cb | 361 | { |
POTLESS_2 | 9:04bfdfc029cb | 362 | char *commande = 0; |
POTLESS_2 | 14:b5e0e882205e | 363 | float valeur = 0; |
POTLESS_2 | 9:04bfdfc029cb | 364 | |
POTLESS_2 | 14:b5e0e882205e | 365 | sscanf(message,"%s %f",&commande , &valeur); |
POTLESS_2 | 9:04bfdfc029cb | 366 | |
POTLESS_2 | 9:04bfdfc029cb | 367 | if ((char)commande == 'T') { |
POTLESS_2 | 9:04bfdfc029cb | 368 | set_time(valeur); |
POTLESS_2 | 12:7f3aadd79f89 | 369 | } else if ((char)commande == 'I') { |
POTLESS_2 | 17:bef8abc445f2 | 370 | Consigne_poumon = (float)valeur; |
POTLESS_2 | 17:bef8abc445f2 | 371 | printf(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 12:7f3aadd79f89 | 372 | } else if ((char)commande == 'O') { |
POTLESS_2 | 17:bef8abc445f2 | 373 | Consigne_fuite = (float)valeur; |
POTLESS_2 | 17:bef8abc445f2 | 374 | printf(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 10:aca745a66d51 | 375 | } else if ((char)commande == 'R') { |
POTLESS_2 | 10:aca745a66d51 | 376 | NVIC_SystemReset(); |
POTLESS_2 | 12:7f3aadd79f89 | 377 | ///////////////////////////////////////// |
POTLESS_2 | 12:7f3aadd79f89 | 378 | //Pour rajouter une commande |
POTLESS_2 | 12:7f3aadd79f89 | 379 | //} else if ((char)commande == 'X') { |
POTLESS_2 | 12:7f3aadd79f89 | 380 | // attribuer à une VARIABLE = valeur; |
POTLESS_2 | 12:7f3aadd79f89 | 381 | // ou une action, avec ou sans valeur |
POTLESS_2 | 12:7f3aadd79f89 | 382 | ///////////////////////////////////////// |
POTLESS_2 | 12:7f3aadd79f89 | 383 | } else { |
POTLESS_2 | 9:04bfdfc029cb | 384 | sensors.cozirSend(message); |
POTLESS_2 | 9:04bfdfc029cb | 385 | } |
POTLESS_2 | 9:04bfdfc029cb | 386 | |
POTLESS_2 | 9:04bfdfc029cb | 387 | strcpy(param," "); |
POTLESS_2 | 9:04bfdfc029cb | 388 | indexParam = 0; |
POTLESS_2 | 9:04bfdfc029cb | 389 | newParamFlag = false; |
POTLESS_2 | 9:04bfdfc029cb | 390 | } |
POTLESS_2 | 9:04bfdfc029cb | 391 | |
POTLESS_2 | 9:04bfdfc029cb | 392 | void Decoding_Message_Android(char message []) |
POTLESS_2 | 9:04bfdfc029cb | 393 | { |
POTLESS_2 | 9:04bfdfc029cb | 394 | char *commande = 0; |
POTLESS_2 | 14:b5e0e882205e | 395 | float valeur = 0; |
POTLESS_2 | 9:04bfdfc029cb | 396 | |
POTLESS_2 | 14:b5e0e882205e | 397 | sscanf(message,"%s %f",&commande , &valeur); |
POTLESS_2 | 9:04bfdfc029cb | 398 | |
POTLESS_2 | 9:04bfdfc029cb | 399 | if ((char)commande == 'T') { |
POTLESS_2 | 9:04bfdfc029cb | 400 | set_time(valeur); |
POTLESS_2 | 12:7f3aadd79f89 | 401 | } else if ((char)commande == 'I') { |
POTLESS_2 | 17:bef8abc445f2 | 402 | Consigne_poumon = (float)valeur; |
POTLESS_2 | 17:bef8abc445f2 | 403 | printf(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 12:7f3aadd79f89 | 404 | } else if ((char)commande == 'O') { |
POTLESS_2 | 17:bef8abc445f2 | 405 | Consigne_fuite = (float)valeur; |
POTLESS_2 | 17:bef8abc445f2 | 406 | printf(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 12:7f3aadd79f89 | 407 | ///////////////////////////////////////// |
POTLESS_2 | 12:7f3aadd79f89 | 408 | //Pour rajouter une commande |
POTLESS_2 | 12:7f3aadd79f89 | 409 | //} else if ((char)commande == 'X') { |
POTLESS_2 | 12:7f3aadd79f89 | 410 | // attribuer à une VARIABLE = valeur; |
POTLESS_2 | 12:7f3aadd79f89 | 411 | // ou une action, avec ou sans valeur |
POTLESS_2 | 12:7f3aadd79f89 | 412 | ///////////////////////////////////////// |
POTLESS_2 | 9:04bfdfc029cb | 413 | } else if ((char)commande == 'R') { |
POTLESS_2 | 9:04bfdfc029cb | 414 | NVIC_SystemReset(); |
POTLESS_2 | 9:04bfdfc029cb | 415 | } |
POTLESS_2 | 12:7f3aadd79f89 | 416 | #ifdef PID_MODE |
POTLESS_2 | 12:7f3aadd79f89 | 417 | else if ((char)commande == 'p') { |
POTLESS_2 | 12:7f3aadd79f89 | 418 | Kc = (float)valeur; |
POTLESS_2 | 16:917656586772 | 419 | control_Servo.reset(); |
POTLESS_2 | 12:7f3aadd79f89 | 420 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 14:b5e0e882205e | 421 | printf(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); |
POTLESS_2 | 15:efd3b3bf3f37 | 422 | } else if ((char)commande == 'i') { |
POTLESS_2 | 12:7f3aadd79f89 | 423 | Ti = (float)valeur; |
POTLESS_2 | 16:917656586772 | 424 | control_Servo.reset(); |
POTLESS_2 | 12:7f3aadd79f89 | 425 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 14:b5e0e882205e | 426 | printf(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); |
POTLESS_2 | 15:efd3b3bf3f37 | 427 | } else if ((char)commande == 'd') { |
POTLESS_2 | 12:7f3aadd79f89 | 428 | Td = (float)valeur; |
POTLESS_2 | 16:917656586772 | 429 | control_Servo.reset(); |
POTLESS_2 | 12:7f3aadd79f89 | 430 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 14:b5e0e882205e | 431 | printf(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); |
POTLESS_2 | 15:efd3b3bf3f37 | 432 | } else if ((char)commande == 'c') { |
POTLESS_2 | 12:7f3aadd79f89 | 433 | consigne = valeur; |
POTLESS_2 | 15:efd3b3bf3f37 | 434 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 14:b5e0e882205e | 435 | printf(" UPDATE CONSIGNE PID --> Consigne = %d\r\n\n", consigne); |
POTLESS_2 | 12:7f3aadd79f89 | 436 | } |
POTLESS_2 | 15:efd3b3bf3f37 | 437 | #endif |
POTLESS_2 | 18:bfd78c05b589 | 438 | |
POTLESS_2 | 9:04bfdfc029cb | 439 | strcpy(Android," "); |
POTLESS_2 | 9:04bfdfc029cb | 440 | indexAndroid = 0; |
POTLESS_2 | 9:04bfdfc029cb | 441 | newAndroidFlag = false; |
POTLESS_2 | 9:04bfdfc029cb | 442 | } |
POTLESS_2 | 9:04bfdfc029cb | 443 | |
POTLESS_2 | 4:d84250f67dec | 444 | int main() |
POTLESS_2 | 12:7f3aadd79f89 | 445 | { |
POTLESS_2 | 12:7f3aadd79f89 | 446 | |
POTLESS_2 | 17:bef8abc445f2 | 447 | Servo_Poumon.Calibrate(); |
POTLESS_2 | 17:bef8abc445f2 | 448 | Servo_Fuite.Calibrate(); |
POTLESS_2 | 12:7f3aadd79f89 | 449 | |
POTLESS_2 | 18:bfd78c05b589 | 450 | /* |
POTLESS_2 | 18:bfd78c05b589 | 451 | Par défaut les valeur en cas de calibration sur true sont les suivant |
POTLESS_2 | 18:bfd78c05b589 | 452 | |
POTLESS_2 | 18:bfd78c05b589 | 453 | nbCalibO2 = 5 |
POTLESS_2 | 18:bfd78c05b589 | 454 | Mode = SPOOLING |
POTLESS_2 | 18:bfd78c05b589 | 455 | Filtre = DIGI_FILTER32 |
POTLESS_2 | 18:bfd78c05b589 | 456 | CalibrationCO2 = "CALIB_AIR" |
POTLESS_2 | 18:bfd78c05b589 | 457 | |
POTLESS_2 | 18:bfd78c05b589 | 458 | Parfois la calibration du Cozir coince...faire reset et relancer... |
POTLESS_2 | 6:ebed9093d661 | 459 | |
POTLESS_2 | 18:bfd78c05b589 | 460 | Pour calibrer avec ces paramètres : |
POTLESS_2 | 18:bfd78c05b589 | 461 | |
POTLESS_2 | 18:bfd78c05b589 | 462 | sensors.Sensors_INIT(true, true); |
POTLESS_2 | 18:bfd78c05b589 | 463 | |
POTLESS_2 | 18:bfd78c05b589 | 464 | Pour changer utiliser la syntaxe suivante : |
POTLESS_2 | 18:bfd78c05b589 | 465 | |
POTLESS_2 | 18:bfd78c05b589 | 466 | sensors.Sensors_INIT(true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR); |
POTLESS_2 | 18:bfd78c05b589 | 467 | |
POTLESS_2 | 18:bfd78c05b589 | 468 | */ |
POTLESS_2 | 18:bfd78c05b589 | 469 | |
POTLESS_2 | 16:917656586772 | 470 | sensors.Sensors_INIT(false, true); |
POTLESS_2 | 18:bfd78c05b589 | 471 | |
POTLESS_2 | 6:ebed9093d661 | 472 | serialMonit.attach(&callbackParam, Serial::RxIrq); |
POTLESS_2 | 6:ebed9093d661 | 473 | |
POTLESS_2 | 9:04bfdfc029cb | 474 | android.attach(&callbackAndroid, Serial::RxIrq); |
POTLESS_2 | 9:04bfdfc029cb | 475 | |
POTLESS_2 | 7:ad15c386e960 | 476 | serialMonit.printf(" Demarrage...\r\n\r\n Entrez les comandes COZIR si besoin :\r\n"); |
POTLESS_2 | 6:ebed9093d661 | 477 | |
POTLESS_2 | 18:bfd78c05b589 | 478 | /* |
POTLESS_2 | 15:efd3b3bf3f37 | 479 | |
POTLESS_2 | 18:bfd78c05b589 | 480 | Pour mémoire, les réglage de priorité des thread |
POTLESS_2 | 15:efd3b3bf3f37 | 481 | |
POTLESS_2 | 18:bfd78c05b589 | 482 | osPriorityIdle = -3, ///< priority: idle (lowest) |
POTLESS_2 | 18:bfd78c05b589 | 483 | osPriorityLow = -2, ///< priority: low |
POTLESS_2 | 18:bfd78c05b589 | 484 | osPriorityBelowNormal = -1, ///< priority: below normal |
POTLESS_2 | 18:bfd78c05b589 | 485 | osPriorityNormal = 0, ///< priority: normal (default) |
POTLESS_2 | 18:bfd78c05b589 | 486 | osPriorityAboveNormal = +1, ///< priority: above normal |
POTLESS_2 | 18:bfd78c05b589 | 487 | osPriorityHigh = +2, ///< priority: high |
POTLESS_2 | 18:bfd78c05b589 | 488 | osPriorityRealtime = +3, ///< priority: realtime (highest) |
POTLESS_2 | 18:bfd78c05b589 | 489 | osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority |
POTLESS_2 | 18:bfd78c05b589 | 490 | */ |
POTLESS_2 | 18:bfd78c05b589 | 491 | |
POTLESS_2 | 10:aca745a66d51 | 492 | thread.start(Get_Info_thread); |
POTLESS_2 | 9:04bfdfc029cb | 493 | |
POTLESS_2 | 16:917656586772 | 494 | thread.set_priority(osPriorityNormal); |
POTLESS_2 | 12:7f3aadd79f89 | 495 | |
POTLESS_2 | 12:7f3aadd79f89 | 496 | #ifdef PID_MODE |
POTLESS_2 | 12:7f3aadd79f89 | 497 | //Init PID |
POTLESS_2 | 12:7f3aadd79f89 | 498 | //Entrée PPO2 entre 100 et 1000 mb |
POTLESS_2 | 12:7f3aadd79f89 | 499 | control_Servo.setInputLimits(Min_Input, Max_Input); |
POTLESS_2 | 12:7f3aadd79f89 | 500 | //Sortie servo entre 0 et 100 % |
POTLESS_2 | 12:7f3aadd79f89 | 501 | control_Servo.setOutputLimits(Min_Output, Max_Output); |
POTLESS_2 | 15:efd3b3bf3f37 | 502 | //Mode auto au démarrage |
POTLESS_2 | 12:7f3aadd79f89 | 503 | control_Servo.setMode(AUTO_MODE); |
POTLESS_2 | 12:7f3aadd79f89 | 504 | //Consigne à x mb |
POTLESS_2 | 12:7f3aadd79f89 | 505 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 15:efd3b3bf3f37 | 506 | #endif |
POTLESS_2 | 15:efd3b3bf3f37 | 507 | |
POTLESS_2 | 11:b2feed92584a | 508 | #ifdef VT100 |
POTLESS_2 | 8:a750d531b381 | 509 | printf(CLS); |
POTLESS_2 | 11:b2feed92584a | 510 | #endif |
POTLESS_2 | 9:04bfdfc029cb | 511 | |
POTLESS_2 | 7:ad15c386e960 | 512 | while (true) { |
POTLESS_2 | 6:ebed9093d661 | 513 | |
POTLESS_2 | 7:ad15c386e960 | 514 | //Démarrage du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 7:ad15c386e960 | 515 | REAL_RATE.start(); |
POTLESS_2 | 7:ad15c386e960 | 516 | |
POTLESS_2 | 6:ebed9093d661 | 517 | if (newParamFlag) { |
POTLESS_2 | 6:ebed9093d661 | 518 | serialMonit.printf("Param = %s\r\n", param); |
POTLESS_2 | 9:04bfdfc029cb | 519 | Decoding_Message(param); |
POTLESS_2 | 9:04bfdfc029cb | 520 | } |
POTLESS_2 | 9:04bfdfc029cb | 521 | |
POTLESS_2 | 9:04bfdfc029cb | 522 | if (newAndroidFlag) { |
POTLESS_2 | 9:04bfdfc029cb | 523 | serialMonit.printf("Android = %s\r\n", Android); |
POTLESS_2 | 9:04bfdfc029cb | 524 | Decoding_Message_Android(Android); |
POTLESS_2 | 6:ebed9093d661 | 525 | } |
POTLESS_2 | 7:ad15c386e960 | 526 | |
POTLESS_2 | 15:efd3b3bf3f37 | 527 | //Fabrication de la chaine Date / heure |
POTLESS_2 | 15:efd3b3bf3f37 | 528 | seconds = time(NULL); |
POTLESS_2 | 15:efd3b3bf3f37 | 529 | char Time_buf[32]; |
POTLESS_2 | 15:efd3b3bf3f37 | 530 | strftime(Time_buf, 32, "%D %I-%M-%S ", localtime(&seconds)); |
POTLESS_2 | 15:efd3b3bf3f37 | 531 | |
POTLESS_2 | 17:bef8abc445f2 | 532 | #ifdef PID_MODE |
POTLESS_2 | 15:efd3b3bf3f37 | 533 | //Fabrication de la chaine à enregistrer |
POTLESS_2 | 17:bef8abc445f2 | 534 | sprintf(to_store,"%s:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%.2f:%.2f:%d:%.3f:%.3f:%.3f:%d", |
POTLESS_2 | 15:efd3b3bf3f37 | 535 | Time_buf, |
POTLESS_2 | 15:efd3b3bf3f37 | 536 | co2, |
POTLESS_2 | 15:efd3b3bf3f37 | 537 | ppO2, |
POTLESS_2 | 15:efd3b3bf3f37 | 538 | pression, |
POTLESS_2 | 15:efd3b3bf3f37 | 539 | Temp1, |
POTLESS_2 | 15:efd3b3bf3f37 | 540 | Temp2, |
POTLESS_2 | 15:efd3b3bf3f37 | 541 | Humid, |
POTLESS_2 | 15:efd3b3bf3f37 | 542 | CellO2_1, |
POTLESS_2 | 15:efd3b3bf3f37 | 543 | CellO2_2, |
POTLESS_2 | 15:efd3b3bf3f37 | 544 | volet_poumon_Position, |
POTLESS_2 | 15:efd3b3bf3f37 | 545 | volet_fuite_Position, |
POTLESS_2 | 15:efd3b3bf3f37 | 546 | MODE_FLAG, |
POTLESS_2 | 15:efd3b3bf3f37 | 547 | Kc, |
POTLESS_2 | 15:efd3b3bf3f37 | 548 | Ti, |
POTLESS_2 | 18:bfd78c05b589 | 549 | Td, |
POTLESS_2 | 17:bef8abc445f2 | 550 | (int)consigne |
POTLESS_2 | 18:bfd78c05b589 | 551 | ); |
POTLESS_2 | 17:bef8abc445f2 | 552 | #endif |
POTLESS_2 | 17:bef8abc445f2 | 553 | #ifndef PID_MODE |
POTLESS_2 | 17:bef8abc445f2 | 554 | //Fabrication de la chaine à enregistrer sans les variables du PID |
POTLESS_2 | 17:bef8abc445f2 | 555 | sprintf(to_store,"%s:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%.2f:%.2f:%d:%.3f:%.3f:%.3f:%d", |
POTLESS_2 | 17:bef8abc445f2 | 556 | Time_buf, |
POTLESS_2 | 17:bef8abc445f2 | 557 | co2, |
POTLESS_2 | 17:bef8abc445f2 | 558 | ppO2, |
POTLESS_2 | 17:bef8abc445f2 | 559 | pression, |
POTLESS_2 | 17:bef8abc445f2 | 560 | Temp1, |
POTLESS_2 | 17:bef8abc445f2 | 561 | Temp2, |
POTLESS_2 | 17:bef8abc445f2 | 562 | Humid, |
POTLESS_2 | 17:bef8abc445f2 | 563 | CellO2_1, |
POTLESS_2 | 17:bef8abc445f2 | 564 | CellO2_2, |
POTLESS_2 | 17:bef8abc445f2 | 565 | volet_poumon_Position, |
POTLESS_2 | 17:bef8abc445f2 | 566 | volet_fuite_Position, |
POTLESS_2 | 17:bef8abc445f2 | 567 | MODE_FLAG, |
POTLESS_2 | 17:bef8abc445f2 | 568 | 0, |
POTLESS_2 | 17:bef8abc445f2 | 569 | 0, |
POTLESS_2 | 18:bfd78c05b589 | 570 | 0, |
POTLESS_2 | 17:bef8abc445f2 | 571 | 0 |
POTLESS_2 | 18:bfd78c05b589 | 572 | ); |
POTLESS_2 | 17:bef8abc445f2 | 573 | #endif |
POTLESS_2 | 15:efd3b3bf3f37 | 574 | |
POTLESS_2 | 15:efd3b3bf3f37 | 575 | //Enregistrement de la chaine |
POTLESS_2 | 15:efd3b3bf3f37 | 576 | sensors.Write_SD((string)to_store); |
POTLESS_2 | 15:efd3b3bf3f37 | 577 | |
POTLESS_2 | 15:efd3b3bf3f37 | 578 | //Pour Android on ajoute < et > pour décoder l'arrivée du message |
POTLESS_2 | 9:04bfdfc029cb | 579 | if (NEED_ANDROID_OUTPUT == 1) { |
POTLESS_2 | 15:efd3b3bf3f37 | 580 | sprintf(to_android,"<%s>",to_store); |
POTLESS_2 | 12:7f3aadd79f89 | 581 | ANDROID(to_android); |
POTLESS_2 | 9:04bfdfc029cb | 582 | } |
POTLESS_2 | 15:efd3b3bf3f37 | 583 | |
POTLESS_2 | 18:bfd78c05b589 | 584 | //Calcul des OTU |
POTLESS_2 | 18:bfd78c05b589 | 585 | Calcul_OTU(); |
POTLESS_2 | 18:bfd78c05b589 | 586 | |
POTLESS_2 | 13:22a96dc67e85 | 587 | //Vers le moniteur dérie |
POTLESS_2 | 13:22a96dc67e85 | 588 | Affichage_moniteur(); |
POTLESS_2 | 15:efd3b3bf3f37 | 589 | |
POTLESS_2 | 15:efd3b3bf3f37 | 590 | |
POTLESS_2 | 15:efd3b3bf3f37 | 591 | #ifdef PID_MODE |
POTLESS_2 | 15:efd3b3bf3f37 | 592 | //Update du PID |
POTLESS_2 | 15:efd3b3bf3f37 | 593 | control_Servo.setProcessValue(ppO2); |
POTLESS_2 | 18:bfd78c05b589 | 594 | //Nouvelle sortie servo fuite si on est pas en mode secours |
POTLESS_2 | 18:bfd78c05b589 | 595 | if(!EN_MODE_SCOURS) Consigne_fuite = control_Servo.compute(); |
POTLESS_2 | 12:7f3aadd79f89 | 596 | #endif |
POTLESS_2 | 15:efd3b3bf3f37 | 597 | |
POTLESS_2 | 7:ad15c386e960 | 598 | //Arrêt du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 7:ad15c386e960 | 599 | REAL_RATE.stop(); |
POTLESS_2 | 7:ad15c386e960 | 600 | //Définition de la nouvelle valeur du temps d'échantillonage du PID. |
POTLESS_2 | 7:ad15c386e960 | 601 | RATE = REAL_RATE.read(); |
POTLESS_2 | 7:ad15c386e960 | 602 | //Reset du Timer |
POTLESS_2 | 7:ad15c386e960 | 603 | REAL_RATE.reset(); |
POTLESS_2 | 12:7f3aadd79f89 | 604 | |
POTLESS_2 | 16:917656586772 | 605 | //Pour ralentir le code à Ref_Time seconde fixe quelque soit les intéruptions du loop.... |
POTLESS_2 | 18:bfd78c05b589 | 606 | if (Ref_Time > RATE) { |
POTLESS_2 | 18:bfd78c05b589 | 607 | RATE_TRUE = (Ref_Time - RATE) * 1000; |
POTLESS_2 | 18:bfd78c05b589 | 608 | } else { |
POTLESS_2 | 18:bfd78c05b589 | 609 | RATE_TRUE = 0; |
POTLESS_2 | 16:917656586772 | 610 | #ifdef PID_MODE |
POTLESS_2 | 18:bfd78c05b589 | 611 | control_Servo.setInterval(RATE); |
POTLESS_2 | 18:bfd78c05b589 | 612 | #endif |
POTLESS_2 | 18:bfd78c05b589 | 613 | printf("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE); |
POTLESS_2 | 16:917656586772 | 614 | } |
POTLESS_2 | 18:bfd78c05b589 | 615 | |
POTLESS_2 | 11:b2feed92584a | 616 | wait_ms(RATE_TRUE); |
POTLESS_2 | 4:d84250f67dec | 617 | } |
POTLESS_2 | 4:d84250f67dec | 618 | } |