Montvydas Klumbys / Mbed 2 deprecated QuadcopterProgram

Dependencies:   MPU6050 PID Quadcopter Servo mbed

Files at this revision

API Documentation at this revision

Comitter:
moklumbys
Date:
Thu Feb 19 12:20:06 2015 +0000
Parent:
2:3161f535d71a
Child:
4:eb418af66d81
Commit message:
finally looks like it gives sensible ritchDiff and rollDiff values. I will have to check what does it give for the actual speed values too.

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	Thu Feb 19 10:38:43 2015 +0000
+++ b/Quadcopter.lib	Thu Feb 19 12:20:06 2015 +0000
@@ -1,1 +1,1 @@
-Quadcopter#cadf589cab2f
+Quadcopter#62e387f1d095
--- a/main.cpp	Thu Feb 19 10:38:43 2015 +0000
+++ b/main.cpp	Thu Feb 19 12:20:06 2015 +0000
@@ -1,3 +1,5 @@
+
+//firstly enable calibrating
 #include "mbed.h"
 #include "Quadcopter.h"
 #include "PID.h"
@@ -7,11 +9,6 @@
 #define MAX_CALIBRATE 1.0
 #define MIN_CALIBRATE 0.35
 
-#define FL   0    // Front left    
-#define FR   1    // Front right
-#define BL   2    // back left
-#define BR   3    // back right
-
 #define OFFSET_SAMPLES 50
 //define how the accelerometer is placed on surface
 #define X_AXIS 1
@@ -28,17 +25,17 @@
 
 #define PITCH_IN_MIN -90.0
 #define PITCH_IN_MAX 90.0
-#define PITCH_OUT_MIN -0.5
-#define PITCH_OUT_MAX 0.5
+#define PITCH_OUT_MIN -0.3
+#define PITCH_OUT_MAX 0.3
 
 #define ROLL_IN_MIN -90.0
 #define ROLL_IN_MAX 90.0
-#define ROLL_OUT_MIN -0.5
-#define ROLL_OUT_MAX 0.5
+#define ROLL_OUT_MIN -0.3
+#define ROLL_OUT_MAX 0.3
 
-#define Kc 0.1
-#define Ti 0.1
-#define Td 0.0
+#define Kc 0.5
+#define Ti 0.01
+#define Td 0.00
 #define RATE 0.01
 //--------------------------------ALL THE FUNCTION HEADERS-----------------------
 float map(float x, float in_min, float in_max, float out_min, float out_max);
@@ -77,7 +74,7 @@
     
     mpu.setAlpha(0.97);     //set Alpha coefficient for low/high pass filters
     
-    quad.calibrate(MIN_CALIBRATE, MAX_CALIBRATE);   //calibrating motors
+//    quad.calibrate(MIN_CALIBRATE, MAX_CALIBRATE);   //calibrating motors
     
     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);
@@ -102,6 +99,7 @@
         speed[i] = 0.0;
     }
 //-------------------------------------------START INFINITE LOOP-------------------------------------------------
+pitchPID.setSetPoint (45.0);    //head forward! by 45 degrees :D
     while(1) {
 //        for (float height = 0.0; height < 0.5; height+=0.05){
 //            for (int i = 0; i < 4; i++){
@@ -125,13 +123,13 @@
         
             pitchDiff = pitchPID.compute();     //compute the difference
             rollDiff = rollPID.compute();
-        
+        pc.printf ("pitchDiff=%0.4f, rollDiff=%0.4f\n", pitchDiff, rollDiff);
             quad.stabilise(speed, actSpeed, rollDiff, pitchDiff);   //stabilise the speed by giving new actSpeed value
             
             //print some values to check how thing work out
-     //       pc.printf("x=%0.3f y=%0.3f z=%0.3f\n", angle[X_AXIS], angle[Y_AXIS], angle[Z_AXIS]);
-            pc.printf("Speed_FL=%0.4f, Speed_FR=%0.4f, Speed_BL= %0.4f, Speed_BR=%0.4f\n", speed[FL], speed[FR], speed[BL], speed[BR]);
-            pc.printf("ActSpeed_FL=%0.4f, ActSpeed_FR=%0.4f, ActSpeed_BL=%0.4f, ActSpeed_BR=%0.4f\n", actSpeed[FL], actSpeed[FR], actSpeed[BL], actSpeed[BR]);
+      //      pc.printf("x=%0.3f y=%0.3f z=%0.3f\n", angle[X_AXIS], angle[Y_AXIS], angle[Z_AXIS]);
+     //       pc.printf("Speed_FL=%0.4f, Speed_FR=%0.4f, Speed_BL= %0.4f, Speed_BR=%0.4f\n", speed[FL], speed[FR], speed[BL], speed[BR]);
+      //      pc.printf("ActSpeed_FL=%0.4f, ActSpeed_FR=%0.4f, ActSpeed_BL=%0.4f, ActSpeed_BR=%0.4f\n", actSpeed[FL], actSpeed[FR], actSpeed[BL], actSpeed[BR]);
             
      //       quad.run(actSpeed); //run the motors at the spesified speed actSpeed