Regenerating PPM signal based on distances from ultrasonic sensors, ESP8266 for connectin via wifi. Autonomous quadcopter behaviour, autonomou height holding. Flying direction based on front and back ultrasonic sensors.

Dependencies:   ConfigFile HCSR04 PID PPM2 mbed-rtos mbed

Branch:
DistanceRegulation
Revision:
25:69190c222dbf
Parent:
21:0afb91824792
Child:
26:11539036f0fb
--- a/hardware.h	Sun Nov 05 09:41:25 2017 +0000
+++ b/hardware.h	Sun Nov 26 17:27:39 2017 +0000
@@ -42,6 +42,9 @@
 float _I = 0;
 float _D = 0;
 int _groundSetPoint = 0;
+int _bias = 0;
+int _groundPidMinOutput = 0;
+int _groundPidMaxOutput = 0;
 bool _groundRegulation = false;
 
 
@@ -52,6 +55,12 @@
     //reading configFile
     _configFile.read("/local/config.cfg");
     char value[BUFSIZ];
+    if (_configFile.getValue("bias", &value[0], sizeof(value)))
+        _bias = atof(value);
+    if (_configFile.getValue("groundPidMinOutput", &value[0], sizeof(value)))
+        _groundPidMinOutput = atof(value);
+    if (_configFile.getValue("groundPidMaxOutput", &value[0], sizeof(value)))
+        _groundPidMaxOutput = atof(value);
     if (_configFile.getValue("P", &value[0], sizeof(value)))
         _P = atof(value);
     if (_configFile.getValue("I", &value[0], sizeof(value)))
@@ -64,6 +73,15 @@
 }
 
 void writeSettingsToConfig(void){
+    ConvertToCharArray(_bias);
+    if(!_configFile.setValue("bias", _str))
+        strcat(_serverMessage, "bias value could not be saved to configFile\n\r");
+    ConvertToCharArray(_groundPidMinOutput);
+    if(!_configFile.setValue("groundPidMinOutput", _str))
+        strcat(_serverMessage, "groundPidMinOutput value could not be saved to configFile\n\r");
+    ConvertToCharArray(_groundPidMaxOutput);
+    if(!_configFile.setValue("groundPidMaxOutput", _str))
+        strcat(_serverMessage, "groundPidMaxOutput value could not be saved to configFile\n\r");
     ConvertToCharArray(_P);
     if(!_configFile.setValue("P", _str))
         strcat(_serverMessage, "P value could not be saved to configFile\n\r");
@@ -97,7 +115,7 @@
 //Converts float to char array
 void ConvertToCharArray(float number)
 {
-    sprintf(_str, "%4.2f", number );  
+    sprintf(_str, "%3.6f", number );  
 }
 
 //Converts integer to char array