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

Committer:
edy05
Date:
Fri Oct 27 09:29:29 2017 +0000
Revision:
10:bb9c778f8e3e
Parent:
9:86a5af9935b1
Child:
11:002927b2675d
Server - after sending refresh - save PID values to config file.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edy05 2:d172c9963f87 1 #ifndef HARDWARE
edy05 2:d172c9963f87 2 #define HARDWARE
edy05 2:d172c9963f87 3
edy05 2:d172c9963f87 4 #include "mbed.h"
edy05 2:d172c9963f87 5 #include "PpmRegen.h"
edy05 2:d172c9963f87 6 #include "PID.h"
edy05 2:d172c9963f87 7 #include "hcsr04.h"
edy05 8:b5128641d4cf 8 #include "ConfigFile.h"
edy05 2:d172c9963f87 9
edy05 2:d172c9963f87 10 Serial pc(USBTX, USBRX); // tx, rx
edy05 2:d172c9963f87 11
edy05 2:d172c9963f87 12 Thread serverThread;
edy05 2:d172c9963f87 13 Thread distanceThread;
edy05 2:d172c9963f87 14
edy05 2:d172c9963f87 15 InterruptIn* _interruptPort = new InterruptIn(p28);
edy05 2:d172c9963f87 16 PwmOut* _roll = new PwmOut(p21);
edy05 2:d172c9963f87 17 PwmOut* _pitch = new PwmOut(p22);
edy05 2:d172c9963f87 18 PwmOut* _throttle = new PwmOut(p23);
edy05 2:d172c9963f87 19 PwmOut* _yaw = new PwmOut(p24);
edy05 2:d172c9963f87 20 PwmOut* _aux1 = new PwmOut(p25);
edy05 2:d172c9963f87 21 PwmOut* _aux2 = new PwmOut(p26);
edy05 2:d172c9963f87 22 PpmRegen* _ppmRegen;
edy05 2:d172c9963f87 23
edy05 2:d172c9963f87 24 PID* _groundDistance;
edy05 2:d172c9963f87 25
edy05 2:d172c9963f87 26 HCSR04* _sonic;
edy05 2:d172c9963f87 27
edy05 9:86a5af9935b1 28 ConfigFile _configFile;
edy05 9:86a5af9935b1 29 LocalFileSystem local("local");
edy05 9:86a5af9935b1 30 char* _str = new char[1024];
edy05 2:d172c9963f87 31
edy05 9:86a5af9935b1 32 float _P = 0;
edy05 9:86a5af9935b1 33 float _I = 0;
edy05 9:86a5af9935b1 34 float _D = 0;
edy05 8:b5128641d4cf 35
edy05 10:bb9c778f8e3e 36 void loadConfigFile(void);
edy05 10:bb9c778f8e3e 37 void writeServerSettingsToConfig(void);
edy05 10:bb9c778f8e3e 38 void ConvertToCharArray(float number);
edy05 10:bb9c778f8e3e 39
edy05 9:86a5af9935b1 40 void loadConfigFile(void){
edy05 9:86a5af9935b1 41 //reading configFile
edy05 9:86a5af9935b1 42 _configFile.read("/local/config.cfg");
edy05 9:86a5af9935b1 43 char value[BUFSIZ];
edy05 9:86a5af9935b1 44 if (_configFile.getValue("P", &value[0], sizeof(value)))
edy05 9:86a5af9935b1 45 _P = atof(value);
edy05 9:86a5af9935b1 46 if (_configFile.getValue("I", &value[0], sizeof(value)))
edy05 9:86a5af9935b1 47 _I = atof(value);
edy05 9:86a5af9935b1 48 if (_configFile.getValue("D", &value[0], sizeof(value)))
edy05 9:86a5af9935b1 49 _D = atof(value);
edy05 9:86a5af9935b1 50
edy05 9:86a5af9935b1 51 }
edy05 9:86a5af9935b1 52
edy05 10:bb9c778f8e3e 53 void writeServerSettingsToConfig(void){
edy05 10:bb9c778f8e3e 54 ConvertToCharArray(_P);
edy05 10:bb9c778f8e3e 55 _configFile.setValue("P", _str);
edy05 10:bb9c778f8e3e 56 ConvertToCharArray(_I);
edy05 10:bb9c778f8e3e 57 _configFile.setValue("I", _str);
edy05 10:bb9c778f8e3e 58 ConvertToCharArray(_D);
edy05 10:bb9c778f8e3e 59 _configFile.setValue("D", _str);
edy05 10:bb9c778f8e3e 60
edy05 10:bb9c778f8e3e 61 _configFile.write("/local/config.cfg");
edy05 10:bb9c778f8e3e 62
edy05 10:bb9c778f8e3e 63 }
edy05 10:bb9c778f8e3e 64
edy05 9:86a5af9935b1 65 //Converts float to char array
edy05 9:86a5af9935b1 66 void ConvertToCharArray(float number)
edy05 9:86a5af9935b1 67 {
edy05 9:86a5af9935b1 68 sprintf(_str, "%4.2f", number );
edy05 9:86a5af9935b1 69 }
edy05 8:b5128641d4cf 70
edy05 8:b5128641d4cf 71
edy05 2:d172c9963f87 72 #endif