![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
Diff: distanceRegulation.h
- Branch:
- DistanceRegulation
- Revision:
- 32:c729e6da7f9a
- Parent:
- 31:5f1737e480f3
- Child:
- 33:a2f9fea05cb9
--- a/distanceRegulation.h Sun Feb 04 15:21:12 2018 +0000 +++ b/distanceRegulation.h Sat Feb 17 15:48:49 2018 +0000 @@ -21,38 +21,40 @@ void distanceRegulationTask(void const *args){ - //pc.printf("Flight controller task started\r\n"); + pc.printf("Flight controller task started\r\n"); uint16_t channels[CHANNELS]; int distance=0; float groundDistancePIDValue; int regulatedThrottle; + //PID SETUP + if(_configChanges){ + _configChanges = false; + 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); + } + } + if(_groundRegulation){ //timer.reset(); //timer.start(); _ppmRegen->getAllChannels(channels); - //PID SETUP - if(_configChanges){ - _configChanges = false; - - 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(); + pc.printf("distance: %d \n\r", distance); _groundDistance->setProcessValue(distance); groundDistancePIDValue = _groundDistance->compute(); //groundDistancePIDValue += _bias; @@ -89,7 +91,7 @@ //distance = _sonic->getDistan(); //pc.printf("Sonic distance: %d \n\r", distance); //pc.printf("channel throttle pid value: %f \n\r", groundDistancePIDValue); - //pc.printf("channel throttle original value: %d \n\r", channels[THROTTLE]); + pc.printf("channel throttle original value: %d \n\r", channels[THROTTLE]); //pc.printf("channel throttle final value: %d \n\r", regulatedThrottle); // Generate PWM _ppmRegen->getAllChannels(channels);