简体   繁体   中英

MPU9150 data (gyro, mag, acce, e.g 9DoF) to Quaternion

I faced a serious problem yesterday. I am trying to find absolute position of an object using MPU9150. It has gyroscope, accelerometer and magnetometer. Each of them providing information in 3 axises(x, y, z). I am looking how to convert these 9 numbers to Quaternion, which I will later to convert to Euler angles. I found some libs but....I am looking for explanation what to do with raw data from sensor, because in every lib they are processing data from magnetometer differently.

To obtain data from sensor I am using some lib which is just reading data according to code below:

mx = MPU9150_readSensor(MPU9150_CMPS_XOUT_L,MPU9150_CMPS_XOUT_H);
my = MPU9150_readSensor(MPU9150_CMPS_YOUT_L,MPU9150_CMPS_YOUT_H);
mz = MPU9150_readSensor(MPU9150_CMPS_ZOUT_L,MPU9150_CMPS_ZOUT_H);
gx = (MPU9150_readSensor(MPU9150_GYRO_XOUT_L,MPU9150_GYRO_XOUT_H)/32768.0)*250.0;
gy = (MPU9150_readSensor(MPU9150_GYRO_YOUT_L,MPU9150_GYRO_YOUT_H)/32768.0)*250.0;
gz = (MPU9150_readSensor(MPU9150_GYRO_ZOUT_L,MPU9150_GYRO_ZOUT_H)/32768.0)*250.0;
ax = (MPU9150_readSensor(MPU9150_ACCEL_XOUT_L,MPU9150_ACCEL_XOUT_H)/32768.0)*2.0;
ay = (MPU9150_readSensor(MPU9150_ACCEL_YOUT_L,MPU9150_ACCEL_YOUT_H)/32768.0)*2.0;
az = (MPU9150_readSensor(MPU9150_ACCEL_ZOUT_L,MPU9150_ACCEL_ZOUT_H)/32768.0)*2.0;

Acceleration is measured in G, not in m/s/s.

So using this code I obtain following data:

mx = 104.0f; my = 104.0f; mz = 106.0f;
gx = -1.62f; gy = 0.12f; gz = 0.32f;
ax = -0.01f; ay = -0.1f; az = 1.0f;

Then I tried to rotate the object 180 degrees (around Z) and data is as follows:

mx = 116.f; my = 116.f; mz = 115.f;
gx = -1.63f; gy = 0.18f; gz = 0.58f;
ax = -0.02f; ay = -0.06f; az = 1.01f;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM