NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.

Dependencies:   mbed MODI2C

Files at this revision

API Documentation at this revision

Comitter:
maetugr
Date:
Mon Oct 15 17:23:06 2012 +0000
Parent:
6:179752756e9f
Child:
8:d25ecdcdbeb5
Commit message:
RC vorgelegt und vor Tickereinbau

Changed in this revision

PC/PC.cpp Show annotated file Show diff for this revision Revisions of this file
PC/PC.h Show annotated file Show diff for this revision Revisions of this file
RC/RC_Channel.cpp Show annotated file Show diff for this revision Revisions of this file
RC/RC_Channel.h Show annotated file Show diff for this revision Revisions of this file
Servo/Servo.cpp Show annotated file Show diff for this revision Revisions of this file
Terminal-Emulation/terminal.cpp Show diff for this revision Revisions of this file
Terminal-Emulation/terminal.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PC/PC.cpp	Mon Oct 15 17:23:06 2012 +0000
@@ -0,0 +1,18 @@
+#include "PC.h"
+#include "mbed.h"
+
+PC::PC(PinName tx, PinName rx) : Serial(tx, rx) 
+{
+}
+
+
+void PC::cls() 
+{
+    printf("\x1B[2J");
+}
+
+
+void PC::locate(int Spalte, int Zeile) 
+{
+    printf("\x1B[%d;%dH", Zeile + 1, Spalte + 1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PC/PC.h	Mon Oct 15 17:23:06 2012 +0000
@@ -0,0 +1,13 @@
+#include "mbed.h"
+
+#ifndef PC_H
+#define PC_H
+
+class PC : public Serial 
+{
+    public:
+        PC(PinName tx, PinName rx);
+        void cls();
+        void locate(int column, int row);
+};
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RC/RC_Channel.cpp	Mon Oct 15 17:23:06 2012 +0000
@@ -0,0 +1,25 @@
+#include "RC_Channel.h"
+#include "mbed.h"
+
+RC_Channel::RC_Channel(PinName mypin) : myinterrupt(mypin)
+{
+    myinterrupt.rise(this, &RC_Channel::rise);
+    myinterrupt.fall(this, &RC_Channel::fall);
+}
+
+int RC_Channel::read()
+{
+    return time;
+}
+
+void RC_Channel::rise()
+{
+    timer.start();
+}
+
+void RC_Channel::fall()
+{
+    timer.stop();
+    time = timer.read_us();
+    timer.reset();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RC/RC_Channel.h	Mon Oct 15 17:23:06 2012 +0000
@@ -0,0 +1,20 @@
+#ifndef RC_CHANNEL_H
+#define RC_CHANNEL_H
+
+#include "mbed.h"
+
+class RC_Channel
+{
+    public:
+        RC_Channel(PinName mypin); // noooo p19/p20!!!!
+        int read();
+       
+    private:
+        InterruptIn myinterrupt;
+        void rise();
+        void fall();
+        Timer timer;
+        int time;
+};
+
+#endif
\ No newline at end of file
--- a/Servo/Servo.cpp	Sat Oct 13 11:12:22 2012 +0000
+++ b/Servo/Servo.cpp	Mon Oct 15 17:23:06 2012 +0000
@@ -7,7 +7,7 @@
 void Servo::initialize() {
     // initialize ESC
     Enable(2000,20000);   // full throttle
-    wait(0.01);    // for 2 secs
+    wait(0.01);    // for 0.01 secs
     SetPosition(1000);    // low throttle
 }
 
--- a/Terminal-Emulation/terminal.cpp	Sat Oct 13 11:12:22 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-
-#include "terminal.h"
-#include "mbed.h"
-
-terminal::terminal(PinName tx, PinName rx) : Serial(tx, rx) 
-    {
-    }
-
-
-void terminal::cls() 
-    {
-    printf("\x1B[2J");
-    }
-
-
-void terminal::locate(int Spalte, int Zeile) 
-    {
-    printf("\x1B[%d;%dH", Zeile + 1, Spalte + 1);
-    }
--- a/Terminal-Emulation/terminal.h	Sat Oct 13 11:12:22 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-
-#include "mbed.h"
-
-#ifndef MBED_TERMINAL_H
-#define MBED_TERMINAL_H
-
-class terminal : public Serial 
-    {
-    public:
-        terminal(PinName tx, PinName rx);
-        void cls();
-        void locate(int column, int row);
-    };
-#endif
--- a/main.cpp	Sat Oct 13 11:12:22 2012 +0000
+++ b/main.cpp	Mon Oct 15 17:23:06 2012 +0000
@@ -1,11 +1,12 @@
-#include "mbed.h" // Standar Library
-#include "LED.h" // LEDs
-#include "L3G4200D.h" // Gyro (Gyroscope)
-#include "ADXL345.h" // Acc (Accelerometer)
-#include "HMC5883.h" // Comp (Compass)
-#include "BMP085.h" // Alt (Altitude sensor)
-#include "Servo.h" // Motor
-#include "terminal.h"
+#include "mbed.h"       // Standard Library
+#include "LED.h"        // LEDs framework for blinking ;)
+#include "L3G4200D.h"   // Gyro (Gyroscope)
+#include "ADXL345.h"    // Acc (Accelerometer)
+#include "HMC5883.h"    // Comp (Compass)
+#include "BMP085.h"     // Alt (Altitude sensor)
+#include "RC_Channel.h" // RemoteControl Chnnels with PPM
+#include "Servo.h"      // Motor PPM
+#include "PC.h"         // Serial Port via USB for debugging
 
 Timer GlobalTimer;
 
@@ -15,9 +16,12 @@
 ADXL345     Acc(p28, p27);
 HMC5883     Comp(p28, p27, GlobalTimer);
 BMP085      Alt(p28, p27);
-Servo     Motor(p20);
+//Servo       Motor_front(p18);
+Servo       Motor_left(p17);
+Servo       Motor_right(p19);
+Servo       Motor_back(p20);
 
-terminal       pc(USBTX, USBRX);        //Achtung: Treiber auf PC fuer Serial-mbed installieren. hier herunterladen https://mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe
+PC          pc(USBTX, USBRX);        //Achtung: Treiber auf PC fuer Serial-mbed installieren. hier herunterladen https://mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe
 
 #define PI             3.1415926535897932384626433832795
 #define Rad2Deg        57.295779513082320876798154814105
@@ -40,7 +44,9 @@
     float Comp_angle = 0;
     float tempangle = 0;
     
-    Motor.initialize();
+    Motor_left.initialize();
+    Motor_right.initialize();
+    Motor_back.initialize();
     //Kompass kalibrieren  --> Problem fremde Magnetfelder!
     //Comp.AutoCalibration = 1;
     short MagRawMin[3]= {-400, -400, -400};     //Gespeicherte Werte verwenden
@@ -67,8 +73,8 @@
         Comp_angle = Comp.getAngle(Comp.Mag[0], Comp.Mag[1]);
         
         // meassure dt
-        dt = GlobalTimer.read_us() - time_loop; // Zeit in us seit letzter loop
-        time_loop = GlobalTimer.read_us(); // setze aktuelle zeit f�r n�chste messung
+        dt = GlobalTimer.read_us() - time_loop; // time in us since last loop
+        time_loop = GlobalTimer.read_us();      // set new time for next measurement
         
         // calculate angles for roll, pitch an yaw
         angle[0] += (Acc_angle[0] - angle[0])/50 + Gyro_data[0] *dt/15000000.0;
@@ -77,23 +83,28 @@
         tempangle -= Gyro_data[2] *dt/15000000.0;
         
         // LCD output
-        pc.locate(10,5); // first line
-        pc.printf("Y:%2.1f %2.1fm   ", angle[2], Alt.CalcAltitude(Alt.Pressure));
-        //LCD.printf("%2.1f %2.1f %2.1f   ", Comp.RawMag[0], Comp.RawMag[1], Comp.RawMag[2]);
-        pc.locate(10,8); // second line
+        pc.locate(10,5);
+        pc.printf("dt:%d %6.1fm   ", dt, Alt.CalcAltitude(Alt.Pressure));
+        pc.locate(10,8);
         pc.printf("Roll:%6.1f Pitch:%6.1f Yaw:%6.1f    ", angle[0], angle[1], angle[2]);
-        //LCD.printf("R:%2.1f P:%2.1f  ", Comp_angle, tempangle);
-        //LCD.printf("%2.1f %2.1f %2.1f   ", Comp.Mag[0], Comp.Mag[1], Comp.Mag[2]);
+        pc.locate(10,10);
+        pc.printf("Debug_Yaw:  Comp:%6.1f Gyro:%6.1f  ", Comp_angle, tempangle);
+        pc.locate(10,12);
+        pc.printf("Comp_Raw: %6.1f %6.1f %6.1f   ", Comp.RawMag[0], Comp.RawMag[1], Comp.RawMag[2]);
+        pc.locate(10,13);
+        pc.printf("Comp_Mag: %6.1f %6.1f %6.1f   ", Comp.Mag[0], Comp.Mag[1], Comp.Mag[2]);
         
-        Motor = 1000 + 5*abs(angle[1]); // set new motor speed
+        // Read RC data
+        //RC[0].read() // TODO: RC daten lesen und einberechnen!
+        
+        // PID Regelung
         
-        //LED hin und her
-        int ledset = 0;
-        if (angle[0] < 0) ledset += 1; else ledset += 8; 
-        if (angle[1] < 0) ledset += 2; else ledset += 4;
-        LEDs = ledset;
+        // set new motor speeds
+        Motor_left = 1000 + 5*abs(angle[1]);
+        Motor_right = 1000 + 5*abs(angle[1]);
+        Motor_back = 1000 + 5*abs(angle[1]);
         
-        //LEDs.rollnext();
-        //wait(0.1);
+        LEDs.rollnext();
+        wait(0.1);
     }
 }