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

main.cpp

Committer:
edy05
Date:
2017-10-26
Revision:
8:b5128641d4cf
Parent:
3:6c9f80f5e865
Child:
9:86a5af9935b1

File content as of revision 8:b5128641d4cf:

#include "mbed.h"
#include "rtos.h"
#include "hardware.h"
#include "Server.h"
#include "PpmRegen.h"
#include "distanceRegulation.h"
#include "hcsr04.h"
#include "PID.h"
#include "ConfigFile.h"

//TEMP

ConfigFile _configFile;
LocalFileSystem local("local");

//VARIABLES
uint16_t ppmInChannelsValue[CHANNELS];
volatile uint16_t distance = 0;

//FUNCTIONS
void print_ppmIn(void);

int main(){
    
    // INITIALIZE CLASSES
    _ppmRegen = new PpmRegen(_interruptPort);
    _sonic = new HCSR04(p29, p30);
    _groundDistance = new PID(10, 0, 0, 2);
    
    // STARTING THREADS
    serverThread.start(serverRun);
    distanceThread.start(distanceRegulationThread);
    
    wait(1);
    
    while(1){
        
        /*
        // writing to configFile
        _configFile.setValue("ahoj", "edo");
        _configFile.write("/local/config.cfg");
        */
        
        //reading configFile
        _configFile.read("/local/config.cfg");
        char* key = "ahoj";
        char value[BUFSIZ];
        if (_configFile.getValue(key, &value[0], sizeof(value)))
            pc.printf("'%s'='%s'\n", key, value);
        
        
        wait(2);
        Thread::wait(osWaitForever);
    }
        
}


void print_ppmIn(){
    _ppmRegen->getAllChannels(ppmInChannelsValue);
    for(uint8_t channel= 0; channel < CHANNELS; channel++){
        pc.printf("PPM In Channel %d: %d \n\r", channel, ppmInChannelsValue[channel]);
    }
    pc.printf("\n\r");
}