jrowberg / i2cdevlib

I2C device library collection for AVR/Arduino or other C++-based MCUs
http://www.i2cdevlib.com
3.89k stars 7.52k forks source link

Quaternions, MPU6050 #292

Open RusakDmitry opened 7 years ago

RusakDmitry commented 7 years ago

Hi everyone! I have problem with quaternions. When I connect MPU6050 and read quaternions data (I dont rotate it), almost every time first quaternions data is different but data should be [1, 0, 0, 0]. Perhapse anybody knows how to solve the problem?

thomasck commented 7 years ago

It won't ever be exactly [1, 0, 0, 0], but are you saying it is not even close to this? Often the dmp algorithm needs to settle - run the dmp and read the fifo a few times and the quaternion should go to the right value. If the chip z-axis is aligned with gravity then the quaternion should be close to [1,0,0,0]. Also, since the dmp doesn't fuse magnetometer data, the quaternion will usually initialize at values corresponding to zero yaw, regardless of the chips actual heading.

Hope this helps

-Thomas

RusakDmitry commented 7 years ago

Thomas, thanks for reply. Sometimes run MPU and data is close [1, 0, 0, 0] and sometimes it isn't. As I understood I have to connect magnetometer for best orientation and quaternion will show right values. Right?

-Dmitry

thomasck commented 7 years ago

Not quite; if you connect a magnetometer and want its data to fuse with the gyro and accel quaternions (which are what the dmp outputs) you have to write that code yourself. As a first step it would be easier to just extract heading from the raw magnetometer data alone without any filtering/fusion implementation, but I haven't tried this so I don't know how well it works.

However if you are using an ARM compiler or msp micro-controller, Invensense has provided a binary library, part of their motion driver 6.12, which you can compile and then use to get "9 axis" fusion from MPU9150/MPU9250. This takes the the accel and gyro quaternions ('6 axis') and fuses them with the magnetometer quaternion ('3 axis') to give absolute orientation.

-Thomas

RusakDmitry commented 7 years ago

@thomasck Thomas, could you give me your e-mail adress? I'll tell you about my project. I guess you can help me.

-Dmitry

franky82008 commented 6 years ago

Dmitry, have you already fixed the problem? I run into the same situation, if reading the quaternion from dmp. I find that sometimes the axis are in a different order (e.g. pitch and roll is swaped). Do you have an idea to solce this problem?