Giter Site home page Giter Site logo

mpu9150's Introduction

MPU-9150

Arduino sketch for MPU-9150 9DoF sensor with AHRS sensor fusion

Demonstrate MPU-9150 basic functionality including parameterizing the register addresses, initializing the sensor, getting properly scaled accelerometer, gyroscope, and magnetometer data out, calibration of sensors. Added display functions to allow display to on breadboard monitor. Addition of 9 DoF sensor fusion using open source Madgwick and Mahony filter algorithms. Sketch runs on the 3.3 V 8 MHz Pro Mini and the Teensy 3.1.

Simplified sketch by among other things breaking out the quaternion sensor fusion filter algorithms to a separate file.

A discussion of the use and limitations of this sensor and sensor fusion in general is found here: https://github.com/kriswiner/MPU-6050/wiki/Affordable-9-DoF-Sensor-Fusion.

mpu9150's People

Contributors

kriswiner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpu9150's Issues

MPU9250 Magnetometer outputs same data in 3 axes

Hello,

I am trying to read magnetometer data from MPU9250 using dsPIC33F. The code was running well in MPU9150 platform and when I tried porting (with modification on the Bypass Enable bit) to MPU9250 it does not work.
I am able to read device ID and it shows 0x48. Then I did tried to read the calibration data by reading from ASAX,ASAY,ASAZ. This executes but all the data are the same. Then I tried to read the magneto registers by,

setting INT_PIN_CFG = 0x02 (this is as part of the initialisation of IMU)
power down and then setting AK8963_CNTL = 0x02 and tried 0x01 too (delay of 10ms)
read magneto registers and ST2 (as in datasheet they say in continuous mode we have to read ST2)
I am able to read accelerometer and gyroscope by populating it to FIFO and this part works well.At this stage am able to read data and which is sensitive to external mag field too but the mx,my, and mz values are the same.

Could you help me to sort out this issue ? (Think timing delay is the culprit, and I am not using Interrupt lines)

Thanks :)

mres calculation mistake at row 398

I was looking at your MPU9150BasicAHRS.ino file and I noticed that mres calculation at row 398 is wrong.
It is mRes = 10.*1229./4096 but it should be mres = 12.29 / 4096. Because 1 uT is 0.01 Gauss
I think you made a typing mistake because in the comment you write that 1229 uT is 12.29 Gauss

Magnetometer calibration and heading (yaw)

Hi Kris,
Amazing work porting the MARG into a nice arduino sketch!

I have got it to work with the https://www.sparkfun.com/products/11486, but the yaw values don't range 360 degrees as I rotate the sensors on its axis (rotating around itself, flat on the table mag-z) and there is not good response, so I may turn it 90 degrees North and it only registers 10ΒΊ change. The other two pitch and roll seem to work fine.

How good is the calibration? Is it worth implementing something like this? http://www.camelsoftware.com/firetail/blog/uavs/3-axis-magnetometer-calibration-a-simple-technique-for-hard-soft-errors/

Many thanks,
Panos

Magnetometer Calibration

Hi Kris, thank you for this amazing library!

I'm using an MPU9150 and the calibration routine from here to calibrate the magnetometer. However, the min and max values that I'm getting are
Max X 7034
Max Y 16416
Max Z 4000
Min X 0
Min Y 0
Min Z 0
When I try different calibration code from RTIMULib, I get the following values

image

I'm not sure which of these are supposed to be correct. The biases are the averages of the min and max values if I'm not wrong, can I write them directly to the offset register? Or do I have to multiply them with mRes and magCalibration as you have done here?

Right now I'm looking at the output without any magnetometer calibration. Roll and Pitch seem to be correct(Both are 0 when the IMU is on a flat surface) but Yaw is way off. When I rotate the IMU a bit, the yaw, pitch and roll values vary wildly but settle down later. Also, the stability of the readings depends on the starting orientation of the IMU. If I start the AHRS algorithm in certain orientations, yaw pitch and roll just keep oscillating, Will these problems be solved after calibrating the magnetometer or could there be other issues?

Accelerometer calibration

I use this source with an Arduino Uno board, I have a problem with the calibration of the accelerometer. If the initial posture of the board is leaned then there is an offset and it can not get back to the true value after calibrating. I tried to remove the following lines, then the offset dissapeared but I do not know how to calibrate the accelerometer in a right way.
// // Push accelerometer biases to hardware registers
// writeByte(MPU9150_ADDRESS, XA_OFFSET_H, data[0]);
// writeByte(MPU9150_ADDRESS, XA_OFFSET_L_TC, data[1]);
// writeByte(MPU9150_ADDRESS, YA_OFFSET_H, data[2]);
// writeByte(MPU9150_ADDRESS, YA_OFFSET_L_TC, data[3]);
// writeByte(MPU9150_ADDRESS, ZA_OFFSET_H, data[4]);
// writeByte(MPU9150_ADDRESS, ZA_OFFSET_L_TC, data[5]);

Please give me some ideas about this.

intPin useless?

is the "intPin" used at all? it is set as an input but that's all i can find - this variable could be deleted I guess?

int intPin = 12; // These can be changed, 2 and 3 are the Arduinos ext int pins

mRes is wrong?

Hi,Kriswiner

The mRes = 10.*1229./4096. is 3 , the comment says // Conversion from 1229 microTesla full scale (4096) to 12.29 Gauss full scale //actually has no change because 1T=10^4G .

I read the datasheet ,I think the mRes should be 1229./4096. not 10.*1229./4096. or tell me where I have the misunderstanding.

Self-test

Hello, I'm trying to program the self-test for the sensor, and your code is proving to be really helpful, but so far I couldn't find the reference where it says how to get the results.

So far, the only thing I've seen is that in order to know if you pass the self-test or not, you needed the self-test value, which is defined in the datasheet as (sensor output w/out self-test - sensor output w/ self-test).

Where did you find the procedure to calculate the self-test value?
Many thanks.

AK8975 adjustment value calculation

I noticed that in row 675, 676 and 677 of MPU9150BasicAHRS.ino, calculation of adjustment values are wrong.
In the datasheet it says that Hadj = H * (((asa - 128) * 0.5)/128) + 1) where H is the measurement data and Hadj is the adjusted measurement data.
So, I think you do not need a calculation to output adjustment values in your initAK8975A procedure. You should do the calculation for every individual readed mesaurement data in you measurement reading procedure.

So, initAK8975A should be:

void initAK8975A(float * destination)
{
uint8_t rawData[3]; // x/y/z gyro register data stored here
writeByte(AK8975A_ADDRESS, AK8975A_CNTL, 0x00); // Power down
delay(10);
writeByte(AK8975A_ADDRESS, AK8975A_CNTL, 0x0F); // Enter Fuse ROM access mode
delay(10);
readBytes(AK8975A_ADDRESS, AK8975A_ASAX, 3, &rawData[0]); // Read the x-, y-, and z-axis calibration values
destination[0] = (float)(rawData[0]; // Return x-axis sensitivity adjustment values
destination[1] = (float)(rawData[1];
destination[2] = (float)(rawData[2];
}

how to access the magnetometer

hello kriswiner,
actually i have used mpu9250 library and i have got reading of the accelerometer and gyrometer data,but when i tried to communicate with mpu9250,i could not.
Means that after reading data of accel. and gyro ,i have enable the bypass_i2c.then when try to something write/read with magnetometer_address(0x0C) and send start_condition of i2c ,it could not get acknowledgement.

Cannot store magnetometer data into FIFO

Hi. Thank you for this library, it's very helpful for figuring out how to work with mpu-9150.

My current state of work with this sensor is as follows:

  1. I can read 3d acc,gyro,magnetometer in single measurement mode correctly.
  2. I can read 3d acc and/or gyro to FIFO correctly.
  3. I can NOT read magnetometer data into FIFO. It always load zeros in places where should be magnetometer data.

I've tried many approaches, example approach is here (it's based on your code):

 mpu9150a_driver_write_register(this, MPU9150_RA_INT_PIN_CFG, 0x02); // enable bypass to have access to magnetometer 
  // Configure Magnetometer for FIFO
  // Initialize AK8975A for write
  mpu9150a_driver_write_register(this, MPU9150_RA_I2C_SLV1_ADDR, 0x0C);  // Write address of AK8975A
  mpu9150a_driver_write_register(this, MPU9150_RA_I2C_SLV1_REG, 0x0A);   // Register from within the AK8975 to which to write
  mpu9150a_driver_write_register(this, MPU9150_RA_I2C_SLV1_DO, 0x01);    // Register that holds output data written into Slave 1 when in write mode
  mpu9150a_driver_write_register(this, MPU9150_RA_I2C_SLV1_CTRL, 0x81);  // Enable Slave 1
  // Set up auxilliary communication with AK8975A for FIFO read
  mpu9150a_driver_write_register(this, MPU9150_RA_I2C_SLV0_ADDR, 0x8C); // Enable and read address (0x0C) of the AK8975A
  mpu9150a_driver_write_register(this, MPU9150_RA_I2C_SLV0_REG, 0x03);  // Register within AK8975A from which to start data read
  mpu9150a_driver_write_register(this, MPU9150_RA_I2C_SLV0_CTRL, 0x86); // Read six bytes and swap bytes

  mpu9150a_driver_write_register(this, MPU9150_RA_FIFO_EN, 0x79); // capture gyro and accelerometer and slave 0 (magnetometer) to fifo
  mpu9150a_driver_write_register(this, MPU9150_RA_I2C_MST_DELAY_CTRL, 0x80); // Enable delay of external sensor data until all data registers have been read

  mpu9150a_driver_write_register(this, MPU9150_RA_USER_CTRL, 0x40);   // Enable FIFO  

Raw data in my fifo looks like this:

-1851 | -983 | -3746 // acc
-83 | 8 | -32 // gyro
0 | 0 | 0 // magn
-1858 | -997 | -3720 // acc
-54 | 4 | -17 // gyro
0 | 0 | 0 // magn
-1883 | -997 | -3745
-56 | 5 | -19
0 | 0 | 0
-1823 | -985 | -3718
-57 | 4 | -19
0 | 0 | 0
-1857 | -998 | -3764
-54 | 5 | -20
0 | 0 | 0
-1876 | -997 | -3751
-55 | 5 | -17
0 | 0 | 0
-1860 | -993 | -3747
-54 | 6 | -19
0 | 0 | 0
-1830 | -981 | -3746
-52 | 4 | -19
0 | 0 | 0
-1846 | -981 | -3764
-57 | 4 | -20
0 | 0 | 0
-1837 | -1002 | -3765
-53 | 4 | -20
0 | 0 | 0

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.