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:
31:5f1737e480f3
Parent:
27:5956d5e3ff63
Child:
32:c729e6da7f9a
--- a/distanceRegulation.h	Sat Jan 20 12:09:04 2018 +0000
+++ b/distanceRegulation.h	Sun Feb 04 15:21:12 2018 +0000
@@ -12,7 +12,7 @@
     pc.printf("Flight controller thread started\r\n");
     
     _groudRegulationUpdateTimer = new RtosTimer(distanceRegulationTask, osTimerPeriodic, (void *)0);   
-    int rate = 5; 
+    int rate = (1.0 / FLIGHT_CONTROLLER_FREQUENCY) * 1000; 
     _groudRegulationUpdateTimer->start(rate);
     
     Thread::wait(osWaitForever);
@@ -28,17 +28,6 @@
     float groundDistancePIDValue;
     int regulatedThrottle;
     
-    //setup PID
-    _groundDistance->setInputLimits(0, 300);
-    //_groundDistance->setOutputLimits(100, 300);
-    _groundDistance->setMode(AUTO_MODE);
-    //_groundDistance->setSetPoint(0.0);
-    //_groundDistance->setBias(0);
-    _groundDistance->setTunings(_P, _I, _D);
-    
-    //Timer timer;
-    
-    
     if(_groundRegulation){
         //timer.reset();
         //timer.start();
@@ -47,17 +36,26 @@
         //PID SETUP
         if(_configChanges){
             _configChanges = false;
-            _groundDistance->resetError();
-            //pc.printf("PID tunings changed \n\r");    
-            _groundDistance->setTunings(_P, _I, _D);
-            _groundDistance->setSetPoint(_groundSetPoint);
-            _groundDistance->setOutputLimits(_groundPidMinOutput, _groundPidMaxOutput);
-            _groundDistance->setBias(_bias);
+            
+            if(_onlyDistanChanged){
+                _onlyDistanChanged = false;
+                //change only set point
+                pc.printf("Only distance changed \n\r");
+                _groundDistance->setSetPoint(_groundSetPoint);
+            }
+            else{
+                _groundDistance->resetError();
+                //pc.printf("PID tunings changed \n\r");    
+                _groundDistance->setTunings(_P, _I, _D);
+                _groundDistance->setSetPoint(_groundSetPoint);
+                _groundDistance->setOutputLimits(_groundPidMinOutput, _groundPidMaxOutput);
+                _groundDistance->setBias(_bias);
+            }
         }
         distance = _sonic->getDistan();
         _groundDistance->setProcessValue(distance);
         groundDistancePIDValue = _groundDistance->compute();
-        groundDistancePIDValue += _bias;
+        //groundDistancePIDValue += _bias;
         
         
         //Update PWM values