mbed-os github

Dependencies:   ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep

Fork of ARNSRS_testDFU by POTLESS

Revision:
18:bfd78c05b589
Parent:
17:bef8abc445f2
Child:
19:cac3761a5d0b
diff -r bef8abc445f2 -r bfd78c05b589 main.cpp
--- a/main.cpp	Mon Dec 04 16:14:19 2017 +0000
+++ b/main.cpp	Tue Dec 05 15:20:29 2017 +0000
@@ -69,7 +69,7 @@
 16      ->      V+ Alimentation logic  5v (alim moteur si tension compatible....)
 
 */
- 
+
 #include "mbed.h"
 #include <string>
 #include "Sensor_head_revB.h"
@@ -92,7 +92,6 @@
 #define MAX_MAP 100//Mapping en pourcentage
 //#define MAX_MAP 90//Mapping en en degrés sur 90 degrés
 
-
 //Ecrit dans le moniteur série de la tablette à 115200 bds si sur 1, penser à mettre NEED_CONSOLE_OUTPUT à 0
 #define NEED_ANDROID_OUTPUT 1
 
@@ -118,7 +117,7 @@
 #endif
 
 Actuonix Servo_Poumon(FEED_BACK_SERVO_POUMON, PWM_SERVO_POUMON, FWD_SERVO_POUMON, REV_SERVO_POUMON, 1, MAX_MAP);
- 
+
 Actuonix Servo_Fuite(FEED_BACK_SERVO_FUITE, PWM_SERVO_FUITE, FWD_SERVO_FUITE, REV_SERVO_FUITE, 1, MAX_MAP);
 
 //Moniteur série, Serial 2
@@ -151,6 +150,10 @@
 int CellO2_1 = 0;
 int CellO2_2 = 0;
 
+//Variables et constantes OTU
+float OTU = 0;
+float COEF_OTU = 0.83;
+
 //Mesure du temps d'éxecution du loop
 Timer REAL_RATE;
 float RATE = 0;
@@ -190,13 +193,54 @@
 float consigne = 210;
 float Max_Input = 1000;
 float Min_Input = 80;
-float Max_Output = MAX_MAP - 10;//Vérifier la valeur pour angle à laisser ouvert...
-float Min_Output = 10;
+float Max_Output = MAX_MAP - 5;//Vérifier la valeur pour angle à laisser ouvert...
+float Min_Output = 0;
 
 //Init PID
 PID control_Servo(Kc, Ti, Td, RATE_PID);
 #endif
 
+//Boolean du status de l'appareil, en mode secours ou nominal
+bool EN_MODE_SCOURS = false;
+
+//Passage en mode secours
+void Mode_Secours()
+{
+#ifdef PID_MODE    
+    //Mise du PID en mode manuel (desactivation...)
+    control_Servo.setMode(MANUAL_MODE);
+#endif
+    Consigne_poumon = MAX_MAP;
+    Consigne_fuite = MAX_MAP;
+    printf("-------------- Appareil en mode secours ---------------");
+    EN_MODE_SCOURS = true;
+}
+
+//Contrôle du status de l'appareil / des constantes
+bool Check()
+{
+    if (ppO2 > 100)
+    return true;//Situation OK
+    else
+    return false;//Situation dégradée
+}
+
+//Calcul des OTU
+float Calcul_OTU()
+{
+    /*
+    La formule suivante permet de calculer la quantité d' OTU accumulée
+    OTU = T * (2* PpO2 -1)0,83
+    avec :
+    T = temps de plongée en minutes
+    PpO2 = pression partielle d’ oxygène en bars
+    */
+
+    if (ppO2 > 500){
+        float val = (2 * (float)ppO2/1000 - 1);//je divise par 1000 car la PP est en mb...
+        OTU += Ref_Time * pow(val, COEF_OTU);
+        } 
+}
 
 //Thread d'intérogation des capteurs, positions servo
 void Get_Info_thread()
@@ -225,6 +269,8 @@
         //Position des servo mise à jour en permanence dans le thread
         Servo_Poumon.Go_To_Prop(Consigne_poumon);
         Servo_Fuite.Go_To_Prop(Consigne_fuite);
+        
+        if(!Check()) Mode_Secours();
     }
 }
 
@@ -234,6 +280,7 @@
     printf("\r\n");
     printf("  CO2             = %d ppm\r\n"  , co2);
     printf("  PPO2            = %d mb\r\n", ppO2);
+    printf("  OTU             = %d \r\n", OTU);
     printf("  Pression        = %f msw\r\n", pression);
     printf("  Temp MS5837     = %f C\r\n", Temp1);
     printf("  Temp HTU21D     = %f C\n\r", Temp2);
@@ -258,6 +305,8 @@
     printf("\x1b[0m\r  CO2           = \x1b[1m\x1b[K%d ppm\n", co2);
     printf("\x1b[0m\r  PPO2          = \x1b[1m\x1b[K%d mb\n", ppO2);
     printf("\n");
+    printf("\x1b[0m\r  OTU           = \x1b[1m\x1b[K%d mb\n", OTU);
+    printf("\n");
     printf("\x1b[0m\r  Pression      = \x1b[1m\x1b[K%.2f msw\n", pression);
     printf("\n");
     printf("\x1b[0m\r  Temp MS5837   = \x1b[1m\x1b[K%.2f C\n", Temp1);
@@ -386,7 +435,7 @@
         printf("  UPDATE CONSIGNE PID -->  Consigne = %d\r\n\n", consigne);
     }
 #endif
-   
+
     strcpy(Android," ");
     indexAndroid = 0;
     newAndroidFlag = false;
@@ -398,48 +447,48 @@
     Servo_Poumon.Calibrate();
     Servo_Fuite.Calibrate();
 
-/*
-Par défaut les valeur en cas de calibration sur true sont les suivant
+    /*
+    Par défaut les valeur en cas de calibration sur true sont les suivant
+
+        nbCalibO2 = 5
+        Mode = SPOOLING
+        Filtre = DIGI_FILTER32
+        CalibrationCO2 = "CALIB_AIR"
+
+        Parfois la calibration du Cozir coince...faire reset et relancer...
 
-    nbCalibO2 = 5
-    Mode = SPOOLING
-    Filtre = DIGI_FILTER32
-    CalibrationCO2 = "CALIB_AIR"
-    
-    Parfois la calibration du Cozir coince...faire reset et relancer...
-    
-    Pour calibrer avec ces paramètres :
-    
-    sensors.Sensors_INIT(true, true);
-     
-    Pour changer utiliser la syntaxe suivante :
-    
-    sensors.Sensors_INIT(true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR);
-    
- */   
-    
+        Pour calibrer avec ces paramètres :
+
+        sensors.Sensors_INIT(true, true);
+
+        Pour changer utiliser la syntaxe suivante :
+
+        sensors.Sensors_INIT(true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR);
+
+     */
+
     sensors.Sensors_INIT(false, true);
-    
+
     serialMonit.attach(&callbackParam, Serial::RxIrq);
 
     android.attach(&callbackAndroid, Serial::RxIrq);
 
     serialMonit.printf("  Demarrage...\r\n\r\n  Entrez les comandes COZIR si besoin :\r\n");
 
-/*
+    /*
 
-Pour mémoire, les réglage de priorité des thread
+    Pour mémoire, les réglage de priorité des thread
 
-      osPriorityIdle          = -3,          ///< priority: idle (lowest)
-      osPriorityLow           = -2,          ///< priority: low
-      osPriorityBelowNormal   = -1,          ///< priority: below normal
-      osPriorityNormal        =  0,          ///< priority: normal (default)
-      osPriorityAboveNormal   = +1,          ///< priority: above normal
-      osPriorityHigh          = +2,          ///< priority: high
-      osPriorityRealtime      = +3,          ///< priority: realtime (highest)
-      osPriorityError         =  0x84        ///< system cannot determine priority or thread has illegal priority
-*/
-    
+          osPriorityIdle          = -3,          ///< priority: idle (lowest)
+          osPriorityLow           = -2,          ///< priority: low
+          osPriorityBelowNormal   = -1,          ///< priority: below normal
+          osPriorityNormal        =  0,          ///< priority: normal (default)
+          osPriorityAboveNormal   = +1,          ///< priority: above normal
+          osPriorityHigh          = +2,          ///< priority: high
+          osPriorityRealtime      = +3,          ///< priority: realtime (highest)
+          osPriorityError         =  0x84        ///< system cannot determine priority or thread has illegal priority
+    */
+
     thread.start(Get_Info_thread);
 
     thread.set_priority(osPriorityNormal);
@@ -497,9 +546,9 @@
                 MODE_FLAG,
                 Kc,
                 Ti,
-                Td, 
+                Td,
                 (int)consigne
-                );
+               );
 #endif
 #ifndef PID_MODE
         //Fabrication de la chaine à enregistrer sans les variables du PID
@@ -518,9 +567,9 @@
                 MODE_FLAG,
                 0,
                 0,
-                0, 
+                0,
                 0
-                );
+               );
 #endif
 
         //Enregistrement de la chaine
@@ -532,6 +581,9 @@
             ANDROID(to_android);
         }
 
+        //Calcul des OTU
+        Calcul_OTU();
+        
         //Vers le moniteur dérie
         Affichage_moniteur();
 
@@ -539,8 +591,8 @@
 #ifdef PID_MODE
         //Update du PID
         control_Servo.setProcessValue(ppO2);
-        //Nouvelle sortie servo fuite
-        Consigne_fuite = control_Servo.compute();
+        //Nouvelle sortie servo fuite si on est pas en mode secours
+        if(!EN_MODE_SCOURS) Consigne_fuite = control_Servo.compute();
 #endif
 
         //Arrêt du Timer mesurant le temps d'éxecution du code
@@ -551,16 +603,16 @@
         REAL_RATE.reset();
 
         //Pour ralentir le code à Ref_Time seconde fixe quelque soit les intéruptions du loop....
-        if (Ref_Time > RATE){
-        RATE_TRUE = (Ref_Time - RATE) * 1000;
-        }else{
-        RATE_TRUE = 0;
+        if (Ref_Time > RATE) {
+            RATE_TRUE = (Ref_Time - RATE) * 1000;
+        } else {
+            RATE_TRUE = 0;
 #ifdef PID_MODE
-        control_Servo.setInterval(RATE);
-#endif        
-        printf("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE);      
+            control_Servo.setInterval(RATE);
+#endif
+            printf("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE);
         }
-        
+
         wait_ms(RATE_TRUE);
     }
 }