![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ESE350 project, Spring 2016, University of Pennsylvania
Dependencies: Adafruit9-DOf Receiver mbed-rtos mbed
Diff: main.cpp
- Revision:
- 22:92401a4fec13
- Parent:
- 21:336faf452989
- Child:
- 23:04338a5ef404
--- a/main.cpp Sun Apr 10 21:47:17 2016 +0000 +++ b/main.cpp Mon Apr 11 16:41:56 2016 +0000 @@ -15,6 +15,8 @@ PwmOut motor_3(p25); PwmOut motor_4(p26); +// to read the battery voltage +AnalogIn battery(p20); void controller_thread(void const *args) { @@ -28,8 +30,8 @@ motor_2=motorsPwm.m2; motor_3=motorsPwm.m3; motor_4=motorsPwm.m4; - - // pc.printf("m1: %f m2: %f m3: %f m4: %f \n\r", motorsPwm.m1, motorsPwm.m2, motorsPwm.m3, motorsPwm.m4); + + // pc.printf("m1: %f m2: %f m3: %f m4: %f \n\r", motorsPwm.m1, motorsPwm.m2, motorsPwm.m3, motorsPwm.m4); Thread::wait(10); } @@ -43,6 +45,22 @@ } } +void battery_thread(void const *args) +{ + float threshold_voltage = 13.0; // desired lowest battery voltage + float max_voltage = 14.8; // max voltage level of battery + float saturating_voltage = 18.38; // voltage at which ADC == 1 + float max_adc = 0.80522; // when battery is at 14.8V + float threshold_adc = max_adc * threshold_voltage / max_voltage; + while(true) { + if (battery.read() < threshold_adc) { + printf("low battery! %f\r\n", battery.read() * saturating_voltage); + } + Thread::wait(1000); // wait for some number of miliseconds + } +} + + int main() { @@ -51,10 +69,15 @@ // get desired values from joystick (to be implemented) // myQuadcopter.setDes(...) - motor_1.period(0.002); // motor requires a 2ms period - motor_2.period(0.002); // motor requires a 2ms period - motor_3.period(0.002); // motor requires a 2ms period - motor_4.period(0.002); // motor requires a 2ms period + motor_1.period(0.01); // motor requires a 2ms period + motor_2.period(0.01); // motor requires a 2ms period + motor_3.period(0.01); // motor requires a 2ms period + motor_4.period(0.01); // motor requires a 2ms period + + //pc.printf("Pestingt.\n\r"); + + + // startup procedure pc.printf("Type 's' to start up Motors, or anything else to abort.\n\r"); @@ -64,12 +87,14 @@ return 0; }; + + // Duty cycle at beginning must be 50% pc.printf("Starting up ESCs\n\r"); - motor_1 = 0.5; - motor_2 = 0.5; - motor_3 = 0.5; - motor_4 = 0.5; + motor_1 = 0.1; + motor_2 = 0.1; + motor_3 = 0.1; + motor_4 = 0.1; pc.printf("Type 'c' to enter control loop, or anything else to abort.\n\r"); char b = pc.getc(); @@ -78,11 +103,26 @@ return 0; }; + + + /* pc.printf("Outputting duty cycle specified below now press all but b to abort.\n\r"); + motor_1 = 0.07; + + + char c = pc.getc(); + if (c!='c') { + pc.printf("Aborting"); + return 0; + }; + */ + + Thread threadR(rc_thread); + Thread battery(battery_thread); //check if remote controll is working with if statement -Thread threadC(controller_thread); + Thread threadC(controller_thread); pc.printf("Entering control loop\n\r"); while (1) { @@ -94,7 +134,7 @@ // wait(0.01); // Set duty cycle - // motors motorsPwm=myQuadcopter.getPwm(); + // motors motorsPwm=myQuadcopter.getPwm(); //motor_2=motorsPwm.m2; //motor_4=motorsPwm.m4;