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: main.cpp
- Revision:
- 2:d172c9963f87
- Parent:
- 1:3a5a074b39e0
- Child:
- 3:6c9f80f5e865
- Child:
- 4:c909ed06dc1f
--- a/main.cpp Wed Sep 27 17:06:19 2017 +0000 +++ b/main.cpp Thu Oct 26 15:54:47 2017 +0000 @@ -1,50 +1,56 @@ #include "mbed.h" +#include "rtos.h" +#include "hardware.h" +#include "Server.h" #include "PpmRegen.h" -//#include "ultrasonic.h" -//#include "MyPID.h" +#include "distanceRegulation.h" +#include "hcsr04.h" +#include "PID.h" -#define AUX1 4 -#define PIEZZO_START 0.1 -#define PIEZZO_STOP 0.0 -#define PPMOUT_CHANNELS 6 -#define PPMIN_CHANNELS 8 -#define PPMIN_FILTERS 5 - -#define ROLL 0 -#define PITCH 1 -#define YAW 2 -#define THROTTLE 3 - -//PPM SETTINGS -PpmRegen ppmRegen(p28, p21, p22, p23, p24, p25, p26); -Serial pc(USBTX, USBRX); // tx, rx - -uint16_t ppmInChannelsValue[PPMIN_CHANNELS]; +//VARIABLES +uint16_t ppmInChannelsValue[CHANNELS]; +volatile uint16_t distance = 0; //FUNCTIONS void print_ppmIn(void); +void dist(int); +//HCSR04 sonic(p6, p7); +//_ppmRegen = new PpmRegen(_interruptPort, _roll, _pitch, _yaw, _throttle, _aux1, _aux2); int main(){ - //PPMIN SETTINGS - /* - NVIC_SetPriority(TIMER0_IRQn, 0); - NVIC_SetPriority(TIMER1_IRQn, 1); - NVIC_SetPriority(TIMER2_IRQn, 2); - NVIC_SetPriority(TIMER3_IRQn, 3); - */ + + _ppmRegen = new PpmRegen(_interruptPort); + _sonic = new HCSR04(p29, p30); + _groundDistance = new PID(10, 0, 0, 2); + serverThread.start(serverRun); + distanceThread.start(distanceRegulationThread); + //_sonic.startUpdates(); + + wait(1); while(1){ //print_ppmIn(); - //print_ppmOut(); - + //_sonic.checkDistance(); + //distance = _sonic.getCurrentDistance(); + //distance = sonic.getDistance(); + //pc.printf("Distance: %d \n\r", distance); + Thread::wait(100); + } } + +void dist(int distan) +{ + //pc.printf("Distance: %d \n\r", distan); + distance = distan; +} + void print_ppmIn(){ - ppmRegen.getAllChannels(ppmInChannelsValue); - for(uint8_t channel= 0; channel < PPMIN_CHANNELS; channel++){ + _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");