Montvydas Klumbys / Mbed 2 deprecated QuadcopterProgram

Dependencies:   MPU6050 PID Quadcopter Servo mbed

Files at this revision

API Documentation at this revision

Comitter:
moklumbys
Date:
Sun Mar 01 22:45:31 2015 +0000
Parent:
7:0c31ccba7b3c
Child:
9:588b1618c710
Commit message:
connects to bluetooth at the beginning, allowing to skip calibration of motors every time quadcopter is turned on.

Changed in this revision

Quadcopter.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Quadcopter.lib	Wed Feb 25 10:38:30 2015 +0000
+++ b/Quadcopter.lib	Sun Mar 01 22:45:31 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/moklumbys/code/Quadcopter/#22c52af13ac2
+http://developer.mbed.org/users/moklumbys/code/Quadcopter/#8147131fcebd
--- a/main.cpp	Wed Feb 25 10:38:30 2015 +0000
+++ b/main.cpp	Sun Mar 01 22:45:31 2015 +0000
@@ -25,14 +25,14 @@
 //input and output values for pitch
 #define PITCH_IN_MIN -90.0
 #define PITCH_IN_MAX 90.0
-#define PITCH_OUT_MIN -0.2
-#define PITCH_OUT_MAX 0.2
+#define PITCH_OUT_MIN -0.1
+#define PITCH_OUT_MAX 0.1
 
 //input and output values for roll
 #define ROLL_IN_MIN -90.0
 #define ROLL_IN_MAX 90.0
-#define ROLL_OUT_MIN -0.2
-#define ROLL_OUT_MAX 0.2
+#define ROLL_OUT_MIN -0.1
+#define ROLL_OUT_MAX 0.1
 
 //PID intervals/constants
 #define Kc 1.0
@@ -82,7 +82,23 @@
     mpu.setAlpha(0.97);     //set Alpha coefficient for low/high pass filters
     
     quad.setLimits(MIN_CALIBRATE, MAX_CALIBRATE);   //set calibration limits for the system
-    quad.calibrate();   //calibrating motors
+    
+    while(1){
+        if (!bt.readable()){
+            if (!bt.scanf("%f", &val)){
+                bt.scanf("%c", &buff);
+            } else {
+                if (val == 'c'){
+                    pc.printf ("Calibrating motors.\n");
+                    quad.calibrate();   //calibrating motors  
+                }
+                if (val == 's'){
+                    pc.printf ("Skipping calibration.\n");
+                    break;  
+                }
+            }
+        }   
+    }
     
     pitchPID.setInputLimits (PITCH_IN_MIN, PITCH_IN_MAX);   //seting input and output limits for both pitch and roll
     pitchPID.setOutputLimits (PITCH_OUT_MIN, PITCH_OUT_MAX);
@@ -105,6 +121,11 @@
     
     timer.start();                  //will need timer to detect when was the last time the values were updated
     prevTime = timer.read();        //set previous timer value
+    
+    for (int i = 0; i < 4; i++){    //initialise speed to be 0.3
+        speed[i] = 0.2;
+    }   
+    quad.run (speed); 
 //-------------------------------------------START INFINITE LOOP-------------------------------------------------
     while(1) {
         if(bt.readable()){
@@ -115,22 +136,7 @@
                     rollPID.setTunings(val, 0.0, 0.0);  
                     pc.printf ("______________________SET______________________\n"); 
                 }             
-//                if (buff == 'k'){
-//                    bt.scanf("%f", &val);
-//                    pitchPID.setTunings(val, 0.0, 0.0);
-//                    rollPID.setTunings(val, 0.0, 0.0);
-//                }
-//                if (buff == 's'){
-//                    bt.scanf("%f", &val);
-//                    spd = val;
-//                }
-     //       }
         }
-        
-        for (int i = 0; i < 4; i++){    //initialise speed to be 0.0
-            speed[i] = 0.3;
-        }   
-        quad.run (speed); 
             
             mpu.computeAngle (angle, accOffset, gyroOffset, timer.read()-prevTime);  // get angle using all these values