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
- Branch:
- DistanceRegulation
- Revision:
- 41:5fe200d20022
- Parent:
- 40:0aa1cefe80ab
diff -r 0aa1cefe80ab -r 5fe200d20022 main.cpp --- a/main.cpp Tue May 15 10:34:35 2018 +0000 +++ b/main.cpp Tue May 22 19:43:09 2018 +0000 @@ -5,7 +5,7 @@ #include "PpmRegen.h" #include "distanceRegulation.h" #include "hcsr04.h" -#include "front_sensor.h" +#include "front_back_sensors.h" #include "PID.h" #include "ConfigFile.h" @@ -14,19 +14,21 @@ //VARIABLES uint16_t ppmInChannelsValue[CHANNELS]; -volatile uint16_t distance = 0; + //FUNCTIONS void print_ppmIn(void); -//RtosTimer distanceRegulation(distanceRegulationTask, osTimerPeriodic, (void *)0); int main(){ - pc.baud(115200); + osThreadId mainID; + mainID = Thread::gettid(); + pc.printf("main gettid 0x%08X \n\r", mainID); + // INITIALIZE CLASSES - _ppmRegen = new PpmRegen(_interruptPort); + _ppmRegen = new PpmRegen(_interruptPin); float rate = (1.0 / FLIGHT_CONTROLLER_FREQUENCY); _groundDistance = new PID(0, 0, 0, rate); @@ -46,6 +48,8 @@ // STARTING THREADS pc.printf("starting distance thread \n\r"); _distanceThread = new Thread(distanceRegulationThread); + osThreadId distanceID; + pc.printf("distance gettid 0x%08X \n\r", distanceID); _distanceThread->set_priority(osPriorityRealtime); //_sonic = new HCSR04(p7, p8, p5, p6); @@ -57,19 +61,18 @@ //_leftSensorThread.start(left_sensor); //_leftSensorThread.set_priority(osPriorityHigh); - _leftSensorThread.start(callback(semaphore_thread, (void *)"leftSensor")); + pc.printf("Starting sonic threads \n\r"); _frontSensorThread.start(callback(semaphore_thread, (void *)"frontSensor")); - _rightSensorThread.start(callback(semaphore_thread, (void *)"rightSensor")); _backSensorThread.start(callback(semaphore_thread, (void *)"backSensor")); _frontSensorThread.set_priority(osPriorityHigh); - _leftSensorThread.set_priority(osPriorityHigh); - _rightSensorThread.set_priority(osPriorityHigh); _backSensorThread.set_priority(osPriorityHigh); pc.printf("starting server thread \n\r"); + osThreadId serverID; + pc.printf("server gettid 0x%08X \n\r", serverID); _serverThread.start(serverRun); _serverThread.set_priority(osPriorityHigh); @@ -78,6 +81,7 @@ //wait(1); + while(1){ Thread::wait(osWaitForever); }