Gestion de imu y arranque de motores cuadcopter primera fase

Dependencies:   mbed Servo

Files at this revision

API Documentation at this revision

Comitter:
cr0n0s20
Date:
Tue Feb 22 22:08:30 2011 +0000
Commit message:
cuadcopter

Changed in this revision

9dof.cpp Show annotated file Show diff for this revision Revisions of this file
9dof.h Show annotated file Show diff for this revision Revisions of this file
Servo.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
main.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/9dof.cpp	Tue Feb 22 22:08:30 2011 +0000
@@ -0,0 +1,52 @@
+#include "9dof.h"
+
+dof9RazorImu::dof9RazorImu(PinName tx, PinName rx) 
+{
+    razor = new Serial(tx, rx);
+    razor->baud(BAUD_RATE);
+}
+
+void dof9RazorImu::update(void) 
+{
+  
+   if(DOFFW == 0){
+     razor->printf("4");
+        while (razor->getc() != '$');
+        razor->scanf(",%d,%d,%d", &acc_x, &acc_y, &acc_z);
+        razor->scanf(",%d,%d,%d", &gyro_x, &gyro_y, &gyro_z);
+        razor->scanf(",%d,%d,%d,#", &mag_x, &mag_y, &mag_z);
+    }else{
+        while (razor->getc() != '$');
+        razor->scanf(",%d,%d,%d", &gyro_x, &gyro_y, &gyro_z);
+        razor->scanf(",%d,%d,%d", &acc_x, &acc_y, &acc_z);    
+        razor->scanf(",%d,%d,%d,#", &mag_x, &mag_y, &mag_z);
+    }
+}
+
+
+int dof9RazorImu::getGyroX(void)
+{ return gyro_x; }
+
+int dof9RazorImu::getGyroY(void)
+{ return gyro_y; }
+
+int dof9RazorImu::getGyroZ(void)
+{ return gyro_z; }
+
+int dof9RazorImu::getAccX(void)
+{ return acc_x; }
+
+int dof9RazorImu::getAccY(void)
+{ return acc_x; }
+
+int dof9RazorImu::getAccZ(void)
+{ return acc_z; }
+
+int dof9RazorImu::getMagX(void)
+{ return mag_x; }
+
+int dof9RazorImu::getMagY(void)
+{ return mag_y; }
+
+int dof9RazorImu::getMagZ(void)
+{ return mag_z; }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/9dof.h	Tue Feb 22 22:08:30 2011 +0000
@@ -0,0 +1,62 @@
+#ifndef DOF9_RAZOR_IMU_H
+#define DOF9_RAZOR_IMU_H
+
+//****************************************************************************/
+// Includes
+//****************************************************************************/
+#include "mbed.h"
+
+//****************************************************************************/
+// Defines
+//****************************************************************************/
+
+class dof9RazorImu {
+#define BAUD_RATE     38400 //Default in frimware from SparkFun.
+#define DOFFW 0// 1 PARA MODIFICADO
+public:
+
+    /**
+     * Constructor.
+     *
+     * Parameters:
+     *
+     *  tx - Pin to use for Serial transmission.
+     *  rx - Pin to use for Serial receive.
+     */
+    dof9RazorImu(PinName tx, PinName rx);
+
+    /**
+     * Update all of the heading data.
+     */
+    void update(void);
+
+    int getGyroX(void);
+    int getGyroY(void);
+    int getGyroZ(void);
+
+    int getAccX(void);
+    int getAccY(void);
+    int getAccZ(void);
+
+    int getMagX(void);
+    int getMagY(void);
+    int getMagZ(void);
+
+private:
+
+    Serial* razor;
+
+    int gyro_x;
+    int gyro_y;
+    int gyro_z;
+
+    int acc_x;
+    int acc_y;
+    int acc_z;
+
+    int mag_x;
+    int mag_y;
+    int mag_z;
+};
+
+#endif /* DOF9_RAZOR_IMU_H */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Tue Feb 22 22:08:30 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/cr0n0s20/code/Servo/#5490c22f727d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 22 22:08:30 2011 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+#include "Servo.h"
+#include "main.h"
+#include "9dof.h"
+
+Servo motor(p21);
+
+Serial pc(USBTX, USBRX);
+dof9RazorImu Razor(p9, p10);
+
+int main() {
+
+
+
+    armarESC();
+    wait_ms(10000);
+    for (int i = 0; i < 50000; i++) {
+        motor = 50.0;
+
+        Razor.update();
+        pc.printf("%d\r\n", Razor.getGyroZ());
+        wait(0.5);
+
+    }
+
+}
+//Función para armar el ESC
+void armarESC() {
+    wait_ms(10000);
+    motor = 0.0;
+    wait_ms(10000);
+    motor = 11.56;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Tue Feb 22 22:08:30 2011 +0000
@@ -0,0 +1,8 @@
+#ifndef _main_H_
+#define _main_H_
+ 
+ void armarESC();
+
+ 
+ 
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 22 22:08:30 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912