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