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

hardware.h

Committer:
edy05
Date:
2017-10-27
Revision:
9:86a5af9935b1
Parent:
8:b5128641d4cf
Child:
10:bb9c778f8e3e

File content as of revision 9:86a5af9935b1:

#ifndef HARDWARE
#define HARDWARE

#include "mbed.h"
#include "PpmRegen.h"
#include "PID.h"
#include "hcsr04.h"
#include "ConfigFile.h"

Serial pc(USBTX, USBRX); // tx, rx

Thread serverThread;
Thread distanceThread;

InterruptIn*    _interruptPort =    new InterruptIn(p28);
PwmOut*         _roll =             new PwmOut(p21);
PwmOut*         _pitch =            new PwmOut(p22);
PwmOut*         _throttle =         new PwmOut(p23);
PwmOut*         _yaw =              new PwmOut(p24);
PwmOut*         _aux1 =             new PwmOut(p25);
PwmOut*         _aux2 =             new PwmOut(p26);
PpmRegen* _ppmRegen;

PID* _groundDistance;

HCSR04* _sonic;

ConfigFile _configFile;
LocalFileSystem local("local");
char*  _str = new char[1024];

float _P = 0;
float _I = 0;
float _D = 0;

void loadConfigFile(void){
    //reading configFile
    _configFile.read("/local/config.cfg");
    char value[BUFSIZ];
    if (_configFile.getValue("P", &value[0], sizeof(value)))
        _P = atof(value);
    if (_configFile.getValue("I", &value[0], sizeof(value)))
        _I = atof(value);
    if (_configFile.getValue("D", &value[0], sizeof(value)))
        _D = atof(value);
        
}

//Converts float to char array
void ConvertToCharArray(float number)
{
    sprintf(_str, "%4.2f", number );  
}


#endif