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:
15:efd3b3bf3f37
Parent:
14:b5e0e882205e
Child:
16:917656586772
--- a/main.cpp	Fri Nov 10 15:00:41 2017 +0000
+++ b/main.cpp	Sat Nov 25 16:22:38 2017 +0000
@@ -114,11 +114,11 @@
 float Td = 0;
 float RATE_PID = Ref_Time;
 float Commande_PID;
-int consigne = 210;
-int Max_Input = 1000;
-int Min_Input = 100;
-int Max_Output = 100;
-int Min_Output = 0;
+float consigne = 210;
+float Max_Input = 1000;
+float Min_Input = 80;
+float Max_Output = 1;//Vérifier la valeur pour angle à laisser ouvert...
+float Min_Output = 0;
 
 //Init PID
 PID control_Servo(Kc, Ti, Td, RATE_PID);//Kc, Ti, Td, interval
@@ -155,32 +155,7 @@
         volet_poumon_Position = 90 - remap(FeedBack_Servo_Poumon, Limit_max_Servo_Poumon, Limit_min_Servo_Poumon, 0, 90);
         volet_fuite_Position = remap(FeedBack_Servo_Fuite, Limit_max_Servo_Fuite, Limit_min_Servo_Fuite, 0, 90);
 
-        //Fabrication de la chaine Date / heure
-        seconds = time(NULL);
-        char Time_buf[32];
-        strftime(Time_buf, 32, "%D %I-%M-%S ", localtime(&seconds));
-
-        //Fabrication de la chaine à enregistrer
-        sprintf(to_store,"%s:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%3.2f:%3.2f:%d",
-                Time_buf,
-                co2,
-                ppO2,
-                pression,
-                Temp1,
-                Temp2,
-                Humid,
-                CellO2_1,
-                CellO2_2,
-                volet_poumon_Position,
-                volet_fuite_Position,
-                MODE_FLAG);
-        
-        //Pour Android on ajoute < et > pour décoder l'arrivée du message  
-        if (NEED_ANDROID_OUTPUT == 1) {
-        sprintf(to_android,"<%s>",to_store);
-        }    
-              
-     }
+    }
 }
 
 void Affichage_moniteur()
@@ -349,19 +324,20 @@
         Kc = (float)valeur;
         control_Servo.setTunings(Kc, Ti, Td);
         printf("  UPDATE PID -->  Kc = %f   Ti = %f   Td = %f\r\n\n", Kc, Ti, Td);
-    }else if ((char)commande == 'i') {
+    } else if ((char)commande == 'i') {
         Ti = (float)valeur;
         control_Servo.setTunings(Kc, Ti, Td);
         printf("  UPDATE PID -->  Kc = %f   Ti = %f   Td = %f\r\n\n", Kc, Ti, Td);
-    }else if ((char)commande == 'd') {
+    } else if ((char)commande == 'd') {
         Td = (float)valeur;
         control_Servo.setTunings(Kc, Ti, Td);
         printf("  UPDATE PID -->  Kc = %f   Ti = %f   Td = %f\r\n\n", Kc, Ti, Td);
-    }else if ((char)commande == 'c') {
+    } else if ((char)commande == 'c') {
         consigne = valeur;
+        control_Servo.setSetPoint(consigne);
         printf("  UPDATE CONSIGNE PID -->  Consigne = %d\r\n\n", consigne);
     }
-#endif    
+#endif
     //wait_ms(100);
     strcpy(Android," ");
     indexAndroid = 0;
@@ -437,6 +413,20 @@
 
     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
+
+      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(osPriorityRealtime);
@@ -447,13 +437,13 @@
     control_Servo.setInputLimits(Min_Input, Max_Input);
     //Sortie servo entre 0 et 100 %
     control_Servo.setOutputLimits(Min_Output, Max_Output);
-    //Mode manuel au démarrage
+    //Mode auto au démarrage
     control_Servo.setMode(AUTO_MODE);
     //Consigne à x mb
     control_Servo.setSetPoint(consigne);
 
-#endif 
-   
+#endif
+
 #ifdef VT100
     printf(CLS);
 #endif
@@ -473,27 +463,51 @@
             Decoding_Message_Android(Android);
         }
 
-        //Vers Android
+        //Fabrication de la chaine Date / heure
+        seconds = time(NULL);
+        char Time_buf[32];
+        strftime(Time_buf, 32, "%D %I-%M-%S ", localtime(&seconds));
+
+        //Fabrication de la chaine à enregistrer
+        sprintf(to_store,"%s:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%3.2f:%3.2f:%d:%f:%f:%f",
+                Time_buf,
+                co2,
+                ppO2,
+                pression,
+                Temp1,
+                Temp2,
+                Humid,
+                CellO2_1,
+                CellO2_2,
+                volet_poumon_Position,
+                volet_fuite_Position,
+                MODE_FLAG,
+                Kc,
+                Ti,
+                Td);
+
+        //Enregistrement de la chaine
+        sensors.Write_SD((string)to_store);
+
+        //Pour Android on ajoute < et > pour décoder l'arrivée du message
         if (NEED_ANDROID_OUTPUT == 1) {
+            sprintf(to_android,"<%s>",to_store);
             ANDROID(to_android);
         }
-        
+
         //Vers le moniteur dérie
         Affichage_moniteur();
-        
-        sensors.Write_SD((string)to_store);
-        
-#ifdef PID_MODE 
-            //Adéquation du RATE du PID avec la contrainte du temps du loop
-            //control_Servo.setInterval(RATE_PID);
-            //Update du PID
-            control_Servo.setProcessValue(ppO2);
-            //Nouvelle sortie servo
-            Commande_PID = control_Servo.compute();
-            //Appliquer la consigne
-            servo_fuite = Commande_PID / 100.0f;
+
+
+#ifdef PID_MODE
+        //Update du PID
+        control_Servo.setProcessValue(ppO2);
+        //Nouvelle sortie servo
+        Commande_PID = control_Servo.compute();
+        //Appliquer la consigne
+        servo_fuite = Commande_PID;
 #endif
-        
+
         //Arrêt du Timer mesurant le temps d'éxecution du code
         REAL_RATE.stop();
         //Définition de la nouvelle valeur du temps d'échantillonage du PID.
@@ -503,6 +517,7 @@
 
         //Pour ralentir le code à 1 seconde fixe quelque soit les intéruptions du loop....
         RATE_TRUE = (Ref_Time - RATE) * 1000;
+
         wait_ms(RATE_TRUE);
     }
 }