EnglishSvenska

This post is automatically translated to English by Google Translate.

Gyro, accellerometer och kompass i Arduino

IMU står för inertial measurement unit och innebär kort en enhet som känner av riktning, hastighet och gravitationskrafter. De sitter exempelvis i telefoner för att rotera skärmen beroende på i vilken vilken man håller den. De går att köpa från Sparkfun eller om man är sparsam från ebay. De består oftast av chip-kombinationen ITG3205 (gyro), ADXL345 (accellerometer) och HMC5883L (kompass). Att använda varje chip var för sig ger inte speciellt mycket men kombinationen ger desto mer. En video visar detta bättre (dock med en annan IMU):

http://www.youtube.com/watch?v=x1vpl6H42Mo

Det finns tyvärr relativt dålig dokumentation till hur man får igång en IMU i Arduino varför jag här publicerar ett enkelt exempel.

Arduino-bibliotek:

Biblioteket på veresano.net är bra (trots att sidan är rörig). Sök efter FreeIMU library och ladda ner arduino-biblioteket. Flytta allt till libraries i din projektmapp.

Beroende på vilken IMU du har behöver du redigera FreeIMU.h. Leta efter "Uncomment the appropriated version of FreeIMU you are using". Jag använder en billig 9 DOF IMU från ebay och valde SEN_10724 eftersom den har samma komponenter. Såhär ser den ut:

Test-program:

#include <ADXL345.h>
#include <HMC58X3.h>
#include <ITG3200.h>
//#include <bma180.h>
#include <MS561101BA.h>

//#define DEBUG
#include "DebugUtils.h"

#include "FreeIMU.h"
//#include "CommunicationUtils.h"
#include <Wire.h>

int raw_values[9];
float ypr[3]; // yaw pitch roll
float val[9];

// Set the FreeIMU object
FreeIMU imu = FreeIMU();

void setup() { 
  Serial.begin(115200);
  Wire.begin();

  delay(5);
  imu.init(); // the parameter enable or disable fast mode
  delay(5);
}

void loop() { 
  imu.getValues(val);
  imu.getYawPitchRoll(ypr);

  Serial.print("acc1: ");
  Serial.print(val[0]);
  Serial.print("\tacc2: ");
  Serial.print(val[1]);
  Serial.print("\tacc3: ");
  Serial.print(val[2]);

  Serial.print("\tgyr1: ");
  Serial.print(val[3]);
  Serial.print("\tgyr2: ");
  Serial.print(val[4]);
  Serial.print("\tgyr3: ");
  Serial.print(val[5]);

  Serial.print("\tmag1: ");
  Serial.print(val[6]);
  Serial.print("\tmag2: ");
  Serial.print(val[7]);
  Serial.print("\tmag3: ");
  Serial.print(val[8]);

  Serial.print("\tYaw: ");
  Serial.print(ypr[0]);
  Serial.print("\tPitch: ");
  Serial.print(ypr[1]);
  Serial.print("\tRoll: ");
  Serial.print(ypr[2]);
  Serial.println("");

  delay(100);
}

Posted in Arduino
3 Comments »Gyro, accellerometer och kompass i Arduino
  1. Fabian says:

    hi Sebastian,

    Great work, is the extended Kalman filter you talk about the built in DMP that comes with InvenSense MPU 6050? I know the new FreeIMU's ship with MUP 6050.

    Also, I was wondering if you could share the visualization code.

    Thank you very much,
    Fabian

  2. Jeremy says:

    Hello Sebastian,

    I'm using the exact same ebay IMU board and Arduino Nano as you did in your example, but I've fought with it for 2 days trying to get it to work. I receive such horrible drift that it spins like a top when I use the Processing 3D cube program. I'm using the latest files from the FreeIMU repository for the FreeIMU library, the FreeIMU_GUI calibration tool, and the Processing 3D cube demo. In FreeIMU.h I am also using SEN_10724 as you did. Do you have any ideas about why I can't get this thing calibrated/working? I actually have 2 of the IMU chips and both behave the same way. After the first frustrating day I switched to the other identical chip to see if the first might have had faulty hardware. The problem must be either software or something I'm doing wrong in the steps. I'm getting quite desperate since I should have had this working by today, so absolutely any help you can provide will be a life-saver!

  3. Esmeraldz says:

    Im doing a project involving sen-10724 as well using arduino software. I was just wondering if anybody happen to know let say i put 2 of these sensors from 1 end to another end in a bendable stylet for example, Knowing that i have the angle of curvature already, how do i calculate the distance of this curvature between this 2 sensors at the point when i bend it? anybody have an idea?
    Thanks!:D

Leave a Reply

Your email address will not be published. Required fields are marked *

*