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:09:24 2017 +0000
Revision:
9:86a5af9935b1
Parent:
8:b5128641d4cf
Child:
10:bb9c778f8e3e
Server - Reading PID values from configFile

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 9:86a5af9935b1 36 void loadConfigFile(void){
edy05 9:86a5af9935b1 37 //reading configFile
edy05 9:86a5af9935b1 38 _configFile.read("/local/config.cfg");
edy05 9:86a5af9935b1 39 char value[BUFSIZ];
edy05 9:86a5af9935b1 40 if (_configFile.getValue("P", &value[0], sizeof(value)))
edy05 9:86a5af9935b1 41 _P = atof(value);
edy05 9:86a5af9935b1 42 if (_configFile.getValue("I", &value[0], sizeof(value)))
edy05 9:86a5af9935b1 43 _I = atof(value);
edy05 9:86a5af9935b1 44 if (_configFile.getValue("D", &value[0], sizeof(value)))
edy05 9:86a5af9935b1 45 _D = atof(value);
edy05 9:86a5af9935b1 46
edy05 9:86a5af9935b1 47 }
edy05 9:86a5af9935b1 48
edy05 9:86a5af9935b1 49 //Converts float to char array
edy05 9:86a5af9935b1 50 void ConvertToCharArray(float number)
edy05 9:86a5af9935b1 51 {
edy05 9:86a5af9935b1 52 sprintf(_str, "%4.2f", number );
edy05 9:86a5af9935b1 53 }
edy05 8:b5128641d4cf 54
edy05 8:b5128641d4cf 55
edy05 2:d172c9963f87 56 #endif