Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep
Fork of ARNSRS_testDFU by
Diff: main.cpp
- Revision:
- 11:b2feed92584a
- Parent:
- 10:aca745a66d51
- Child:
- 12:7f3aadd79f89
--- a/main.cpp Thu Nov 02 10:39:53 2017 +0000
+++ b/main.cpp Sun Nov 05 16:03:02 2017 +0000
@@ -16,6 +16,18 @@
//Sortie en mode VT100, à commenter si on veut une sortie type Arduino
//#define VT100
+//Mode Delta constant entre les servos à commenter si on en veut pas
+//#define DELTA_MODE
+float delta = 0.0f;
+
+#ifndef DELTA_MODE
+int DELTA_FLAG = 0;
+#endif
+
+#ifdef DELTA_MODE
+int DELTA_FLAG = 1;
+#endif
+
#if NEED_ANDROID_OUTPUT
#define ANDROID(...) { android.printf(__VA_ARGS__); }
#else
@@ -33,14 +45,14 @@
//pour Param Cozir
const int sizeParam = 20;
-char param[sizeParam ];
-int indexParam;
+char param[sizeParam];
+volatile int indexParam = 0;
bool newParamFlag = false;
//pour Commandes Android
const int sizeAndroid = 20;
-char Android[sizeParam ];
-int indexAndroid;
+char Android[sizeAndroid];
+volatile int indexAndroid = 0;
bool newAndroidFlag = false;
//Variables de stockage des infos capteurs
@@ -54,6 +66,7 @@
//Mesure du tempsd'éxecution du loop
Timer REAL_RATE;
float RATE = 0;
+float RATE_TRUE = 0;
//HTU21D
HTU21D temphumid(PB_9, PB_8); //Temp humid sensor || SDA, SCL
@@ -127,7 +140,7 @@
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>",
+ sprintf(to_store,"<%s:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%3.2f:%3.2f:%d>",
Time_buf,
co2,
ppO2,
@@ -138,7 +151,8 @@
CellO2_1,
CellO2_2,
volet_poumon_Position,
- volet_fuite_Position);
+ volet_fuite_Position,
+ DELTA_FLAG);
}
}
@@ -160,7 +174,7 @@
printf(" Volet Poumon = %3.2f%\r\n" , volet_poumon_Position);
printf(" Volet Fuite = %3.2f%\r\n" , volet_fuite_Position);
printf("\r\n");
- printf("Temps d execution de la boucle = %f secondes\n", RATE);
+ printf("Temps d execution de la boucle = %f secondes\n", (RATE + RATE_TRUE) / 1000);
printf("\r\n", "");
printf("A enregistrer = %s\n", to_store);
printf("\r\n");
@@ -185,14 +199,14 @@
printf("\x1b[0m\r Volet Poumon = \x1b[1m\x1b[K%3.2f%\n", volet_poumon_Position);
printf("\x1b[0m\r Volet Fuite = \x1b[1m\x1b[K%3.2f%\n", volet_fuite_Position);
printf("\n");
- printf("\x1b[0m\r Temps d execution de la boucle = \x1b[1m\x1b[K%f secondes\n", RATE);
+ printf("\x1b[0m\r Temps d execution de la boucle = \x1b[1m\x1b[K%f secondes\n", (RATE + RATE_TRUE) / 1000);
printf("\r\n", "");
printf("\x1b[0m\r A enregistrer = \x1b[1m\x1b[K%s\n", to_store);
printf("\r\n", "");
#endif
}
-//Callback de l'intérruption des envois de commandes au Cozir
+//Callback de l'intérruption des envois de commandes depuis le terminal
void callbackParam()
{
while(serialMonit.readable()) {
@@ -207,7 +221,6 @@
}
}
-
//Callback de l'intérruption des envois de commandes depuis Android
void callbackAndroid()
{
@@ -222,6 +235,7 @@
}
}
}
+
void Decoding_Message(char message [])
{
char *commande = 0;
@@ -231,19 +245,37 @@
if ((char)commande == 'T') {
set_time(valeur);
- } else if ((char)commande == 'P'){
+ } else if ((char)commande == 'I'){
servo_poumon = remap(valeur, 0, 90, 0, 100) / 100.f;
+ #ifdef DELTA_MODE
+ float Sf = servo_poumon + remap(delta, 0, 90, 0, 100) / 100.f;
+ if(Sf >= 0 && Sf <= 90)
+ servo_fuite = Sf;
+ #endif
printf(" Servo Poumon = %f\r\n", remap(valeur, 0, 90, 0, 100) / 100.f);
- } else if ((char)commande == 'F'){
+ } else if ((char)commande == 'O'){
servo_fuite = 1 - remap(valeur, 0, 90, 0, 100) / 100.f;
printf(" Servo Fuite = %f\r\n", 1 - remap(valeur, 0, 90, 0, 100) / 100.f);
+ } else if ((char)commande == 'D') {
+ delta = valeur;
+ #ifdef DELTA_MODE
+ float Sf = servo_poumon + remap(delta, 0, 90, 0, 100) / 100.f;
+ if(Sf >= 0 && Sf <= 90)
+ servo_fuite = Sf;
+ #endif
} else if ((char)commande == 'R') {
NVIC_SystemReset();
+ /////////////////////////////////////////
+ //Pour rajouter une commande
+ //} else if ((char)commande == 'X') {
+ // attribuer à une VARIABLE = valeur;
+ // ou une action, avec ou sans valeur
+ /////////////////////////////////////////
}else {
sensors.cozirSend(message);
}
- //wait_ms(500);
+ //wait_ms(100);
strcpy(param," ");
indexParam = 0;
newParamFlag = false;
@@ -258,17 +290,37 @@
if ((char)commande == 'T') {
set_time(valeur);
- } else if ((char)commande == 'P'){
+ } else if ((char)commande == 'I'){
servo_poumon = remap(valeur, 0, 90, 0, 100) / 100.f;
+ #ifdef DELTA_MODE
+ float Sf = servo_poumon + remap(delta, 0, 90, 0, 100) / 100.f;
+ if(Sf >= 0 && Sf <= 90)
+ servo_fuite = Sf;
+ #endif
printf(" Servo Poumon = %f\r\n", remap(valeur, 0, 90, 0, 100) / 100.f);
- } else if ((char)commande == 'F'){
+ } else if ((char)commande == 'O'){
servo_fuite = 1 - remap(valeur, 0, 90, 0, 100) / 100.f;
- printf(" Servo Fuite = %f\r\n", 1 - remap(valeur, 0, 90, 0, 100) / 100.f);
+ printf(" Servo Fuite = %f\r\n", 1 - remap(valeur, 0, 90, 0, 100) / 100.f);
+ } else if ((char)commande == 'D') {
+ delta = valeur;
+ #ifdef DELTA_MODE
+ float Sf = servo_poumon + remap(delta, 0, 90, 0, 100) / 100.f;
+ if(Sf >= 0 && Sf <= 90)
+ servo_fuite = Sf;
+ #endif
+ /////////////////////////////////////////
+ //Pour rajouter une commande
+ //} else if ((char)commande == 'X') {
+ // attribuer à une VARIABLE = valeur;
+ // ou une action, avec ou sans valeur
+ /////////////////////////////////////////
} else if ((char)commande == 'R') {
NVIC_SystemReset();
+ } else {
+ sensors.cozirSend(message);
}
- //wait_ms(500);
+ //wait_ms(100);
strcpy(Android," ");
indexAndroid = 0;
newAndroidFlag = false;
@@ -321,15 +373,21 @@
printf(" Delta Servo 2 = %f\n", Delta_FB_2);
if(Delta_FB_1 > 10 || Delta_FB_2 > 10) printf(" Delta Servos non satisfaisant...\r\n\r\n");
+
+#ifdef DELTA_MODE
+ //Position initial delta
+ servo_poumon = 0.5;
+ servo_fuite = 0.5 + remap(delta, 0, 90, 0, 100) / 100.f;
+#endif
}
int main()
-{
+{
+ //UNIX TIMESTAMP depuis le erminal MAC = date +%s + 7200 pour heure d'été.....
- //UNIX TIMESTAMP depuis le erminal MAC = date +%s + 7200 pour heure d'été.....
Calibration_servo();
- sensors.Sensors_INIT(true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR);
+ sensors.Sensors_INIT(false, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR);
serialMonit.attach(&callbackParam, Serial::RxIrq);
@@ -340,8 +398,10 @@
thread.start(Get_Info_thread);
thread.set_priority(osPriorityRealtime);
-
+
+#ifdef VT100
printf(CLS);
+#endif
while (true) {
@@ -351,13 +411,11 @@
Affichage_moniteur();
if (newParamFlag) {
- wait_ms(500);
serialMonit.printf("Param = %s\r\n", param);
Decoding_Message(param);
}
if (newAndroidFlag) {
- wait_ms(500);
serialMonit.printf("Android = %s\r\n", Android);
Decoding_Message_Android(Android);
}
@@ -365,13 +423,8 @@
//Vers Android
if (NEED_ANDROID_OUTPUT == 1) {
ANDROID(to_store);
- //build_send_Message_int("t", co2, ppO2);
- //build_send_Message_float("v", Temp1, pression);
- //build_send_Message_int("m", CellO2_1, CellO2_2);
}
- wait_ms(500);
-
sensors.Write_SD((string)to_store);
//Arrêt du Timer mesurant le temps d'éxecution du code
@@ -380,6 +433,9 @@
RATE = REAL_RATE.read();
//Reset du Timer
REAL_RATE.reset();
-
+
+ //Pour ralentir le code à 1 seconde fixe quelque soit les intéruptions du loop....
+ RATE_TRUE = (1000 - (RATE / 1000));
+ wait_ms(RATE_TRUE);
}
}
