Program used to control a quadcopter. It uses a PID library which can be found in: http://developer.mbed.org/cookbook/PID I also uses my own written library for easily controlling quadcopter motors, which can be found in: https://developer.mbed.org/users/moklumbys/code/Quadcopter/ One more library that I used is MPU6050 that was previously written by Erik Olieman but I was able to update it with new functions: https://developer.mbed.org/users/moklumbys/code/MPU6050/

Dependencies:   MPU6050 PID Quadcopter Servo mbed

Revision:
0:894ba50f267c
Child:
1:40ade596b1e3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Feb 18 23:44:09 2015 +0000
@@ -0,0 +1,62 @@
+#include "mbed.h"
+#include "Quadcopter.h"
+
+#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
+//--------------------------------ALL THE FUNCTION HEADERS-----------------------
+float map(float x, float in_min, float in_max, float out_min, float out_max);
+//---------------------------------------END-------------------------------------
+
+Quadcopter quad (p21, p22, p23, p24);
+Serial pc(USBTX, USBRX); // tx, rx
+
+int main() {
+    float pitchDiff;
+    float rollDiff;
+    float speed[4];
+    float actSpeed[4];
+    
+    quad.calibrate(MIN_CALIBRATE, MAX_CALIBRATE);
+    while(1) {
+        for (float height = 0.0; height < 0.5; height+=0.05){
+            for (int i = 0; i < 4; i++){
+                speed[i] = height;
+            }
+            quad.run (speed);
+            wait(0.1);
+        }
+        for (uint16_t i = 0; i < 600; i++)
+        {
+            rollPID.setProcessValue (imu.roll);
+            rollPID.setProcessValue (imu.pitch);
+        
+            pitchDif = pitchPID.compute();
+            rollDif = rollPID.compute();
+        
+            quad.stabilise(speed, actSpeed, rollDiff, pitchDiff);
+            quad.run(actSpeed);
+            
+            wait (0.01);
+        }
+        
+        for (float height = 0.5; height > 0.0; height-=0.05){
+            for (int i = 0; i < 4; i++){
+                speed[i] = height;
+            }
+            quad.run (speed);
+            wait(0.1);
+        }
+        wait(1);
+    }
+}
+
+//-----------------------------Mapping function-----------------------------
+float map(float x, float in_min, float in_max, float out_min, float out_max)
+{
+  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
\ No newline at end of file