SparkFun 9DOF Razor IMU with AHRS [http://code.google.com/p/sf9domahrs/]

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
aberk
Date:
Thu Jun 17 10:05:46 2010 +0000
Commit message:

Changed in this revision

dof9RazorImuAhrs.cpp Show annotated file Show diff for this revision Revisions of this file
dof9RazorImuAhrs.h 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ef171fe2a7e5 dof9RazorImuAhrs.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dof9RazorImuAhrs.cpp	Thu Jun 17 10:05:46 2010 +0000
@@ -0,0 +1,115 @@
+//****************************************************************************/
+// Description:
+//
+//  Read attitude and heading reference system [AHRS] data from the SparkFun
+//  9DOF Razor Inertial Measurement Unit [IMU].
+//
+// AHRS code:
+//
+//  http://code.google.com/p/sf9domahrs/
+//
+// 9DOF Razor IMU:
+//
+//  http://www.sparkfun.com/commerce/product_info.php?products_id=9623
+//****************************************************************************/
+
+//****************************************************************************/
+// Includes
+//****************************************************************************/
+#include "dof9RazorImuAhrs.h"
+
+dof9RazorImuAhrs::dof9RazorImuAhrs(PinName tx, PinName rx) {
+
+    razor = new Serial(tx, rx);
+    razor->baud(BAUD_RATE);
+
+}
+
+void dof9RazorImuAhrs::update(void) {
+
+    //Make sure we get to the start of a line.
+    while (razor->getc() != '\n');
+
+#if PRINT_EULER == 1
+    razor->scanf("!ANG:%f,%f,%f", &roll, &pitch, &yaw);
+#endif
+
+#if PRINT_ANALOGS == 1
+    razor->scanf(",AN:%f,%f,%f", &gyro_x, &gyro_y, &gyro_z);
+    razor->scanf(",%f,%f,%f", &acc_x, &acc_y, &acc_z);
+    razor->scanf(",%f,%f,%f", &mag_x, &mag_y, &mag_z);
+#endif
+
+}
+
+float dof9RazorImuAhrs::getRoll(void){
+
+    return roll;
+
+}
+
+float dof9RazorImuAhrs::getPitch(void){
+
+    return pitch;
+
+}
+
+float dof9RazorImuAhrs::getYaw(void){
+
+    return yaw;
+
+}
+
+float dof9RazorImuAhrs::getGyroX(void){
+
+    return gyro_x;
+
+}
+
+float dof9RazorImuAhrs::getGyroY(void){
+
+    return gyro_y;
+
+}
+
+float dof9RazorImuAhrs::getGyroZ(void){
+
+    return gyro_z;
+
+}
+
+float dof9RazorImuAhrs::getAccX(void){
+
+    return acc_x;
+
+}
+
+float dof9RazorImuAhrs::getAccY(void){
+
+    return acc_x;
+
+}
+
+float dof9RazorImuAhrs::getAccZ(void){
+
+    return acc_z;
+
+}
+
+float dof9RazorImuAhrs::getMagX(void){
+
+    return mag_x;
+
+}
+
+float dof9RazorImuAhrs::getMagY(void){
+
+    return mag_y;
+
+}
+
+float dof9RazorImuAhrs::getMagZ(void){
+
+    return mag_z;
+
+}
diff -r 000000000000 -r ef171fe2a7e5 dof9RazorImuAhrs.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dof9RazorImuAhrs.h	Thu Jun 17 10:05:46 2010 +0000
@@ -0,0 +1,90 @@
+//****************************************************************************/
+// Description:
+//
+//  Read attitude and heading reference system [AHRS] data from the SparkFun
+//  9DOF Razor Inertial Measurement Unit [IMU].
+//
+// AHRS code:
+//
+//  http://code.google.com/p/sf9domahrs/
+//
+// 9DOF Razor IMU:
+//
+//  http://www.sparkfun.com/commerce/product_info.php?products_id=9623
+//****************************************************************************/
+
+#ifndef DOF9_RAZOR_IMU_H
+#define DOF9_RAZOR_IMU_H
+
+//****************************************************************************/
+// Includes
+//****************************************************************************/
+#include "mbed.h"
+
+//****************************************************************************/
+// Defines
+//****************************************************************************/
+#define PRINT_EULER   1     //Corrected heading data.
+#define PRINT_ANALOGS 0     //Razor spits out raw gyro/accelerometer/magneto
+                            //data.
+                            //Set as a define when compiling AHRS code.
+#define BAUD_RATE     57600 //Default in AHRS code.
+
+class dof9RazorImuAhrs {
+
+public:
+
+    /**
+     * Constructor.
+     *
+     * Parameters:
+     *
+     *  tx - Pin to use for Serial transmission.
+     *  rx - Pin to use for Serial receive.
+     */
+    dof9RazorImuAhrs(PinName tx, PinName rx);
+    
+    /**
+     * Update all of the heading data.
+     */
+    void update(void);
+    
+    float getRoll(void);
+    float getPitch(void);
+    float getYaw(void);
+    
+    float getGyroX(void);
+    float getGyroY(void);
+    float getGyroZ(void);
+    
+    float getAccX(void);
+    float getAccY(void);
+    float getAccZ(void);
+    
+    float getMagX(void);
+    float getMagY(void);
+    float getMagZ(void);
+
+private:
+
+    Serial* razor;
+
+    float roll;
+    float pitch;
+    float yaw;
+    
+    float gyro_x;
+    float gyro_y;
+    float gyro_z;
+    
+    float acc_x;
+    float acc_y;
+    float acc_z;
+    
+    float mag_x;
+    float mag_y;
+    float mag_z;
+
+};
+
+#endif /* DOF9_RAZOR_IMU_H */
diff -r 000000000000 -r ef171fe2a7e5 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jun 17 10:05:46 2010 +0000
@@ -0,0 +1,19 @@
+/**
+ * Read the yaw value from the SparkFun 9DOF Razor IMU.
+ */
+
+#include "dof9RazorImuAhrs.h"
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX);
+dof9RazorImuAhrs theRazor(p9, p10);
+
+int main() {
+    
+    while(1) {
+        wait(0.1);
+        theRazor.update();
+        pc.printf("Yaw: %f\n", theRazor.getYaw());    
+    }
+    
+}
diff -r 000000000000 -r ef171fe2a7e5 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jun 17 10:05:46 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/029aa53d7323