Open beratozbay opened 6 years ago
How did you calibrate the sensors?
On Sat, Feb 24, 2018 at 4:51 AM, Berat Özbay notifications@github.com wrote:
Hello,
I have a sparkfun MPU9250 breakout board and a teensy 3.5. When I tried the example "MPU9250BasicAHRS_t3" I take the this kind of result.
ax = -61.89 ay = 0.79 az = 930.85 mg gx = -0.02 gy = 0.08 gz = 0.00 deg/s mx = -119 my = -125 mz = 382 mG q0 = 0.27 qx = -0.30 qy = 0.91 qz = 0.14 Yaw, Pitch, Roll: -151.28, 34.77, 174.09 Rate = 0.17 Hz
ax = -64.51 ay = 0.49 az = 936.34 mg gx = -0.05 gy = 0.05 gz = 0.07 deg/s mx = -135 my = -137 mz = 367 mG q0 = 0.33 qx = -0.28 qy = 0.89 qz = 0.15 Yaw, Pitch, Roll: -152.97, 41.85, 173.53 Rate = 6015.74 Hz
ax = -63.96 ay = 0.55 az = 935.73 mg gx = -0.13 gy = 0.08 gz = 0.06 deg/s mx = -124 my = -123 mz = 374 mG q0 = 0.39 qx = -0.27 qy = 0.86 qz = 0.17 Yaw, Pitch, Roll: -155.29, 50.34, 172.48 Rate = 6061.90 Hz
ax = -64.82 ay = -1.53 az = 937.19 mg gx = -0.08 gy = 0.00 gz = -0.00 deg/s mx = -119 my = -128 mz = 389 mG q0 = 0.47 qx = -0.24 qy = 0.83 qz = 0.19 Yaw, Pitch, Roll: -159.16, 60.73, 170.03 Rate = 6017.94 Hz
ax = -64.27 ay = -0.31 az = 936.28 mg gx = -0.04 gy = 0.06 gz = 0.05 deg/s mx = -139 my = -127 mz = 377 mG q0 = 0.56 qx = -0.21 qy = 0.77 qz = 0.21 Yaw, Pitch, Roll: -168.56, 73.20, 162.11 Rate = 6064.35 Hz
ax = -64.76 ay = -1.10 az = 932.19 mg gx = 0.02 gy = 0.10 gz = 0.02 deg/s mx = -117 my = -130 mz = 395 mG q0 = 0.67 qx = -0.17 qy = 0.68 qz = 0.24 Yaw, Pitch, Roll: 116.67, 84.48, 88.63 Rate = 6000.43 Hz
ax = -62.19 ay = 1.10 az = 937.07 mg gx = -0.13 gy = 0.09 gz = -0.00 deg/s mx = -122 my = -128 mz = 369 mG q0 = 0.78 qx = -0.13 qy = 0.56 qz = 0.27 Yaw, Pitch, Roll: 43.41, 68.89, 15.96 Rate = 6062.08 Hz
ax = -63.96 ay = -1.34 az = 935.49 mg gx = -0.10 gy = -0.00 gz = 0.04 deg/s mx = -128 my = -123 mz = 377 mG q0 = 0.88 qx = -0.08 qy = 0.36 qz = 0.30 Yaw, Pitch, Roll: 34.38, 43.28, 5.62 Rate = 6007.13 Hz
ax = -63.84 ay = -0.49 az = 934.02 mg gx = -0.11 gy = -0.00 gz = -0.04 deg/s mx = -121 my = -120 mz = 377 mG q0 = 0.93 qx = -0.06 qy = 0.10 qz = 0.36 Yaw, Pitch, Roll: 36.31, 13.50, -2.08 Rate = 6061.65 Hz
ax = -62.19 ay = 0.06 az = 936.58 mg gx = -0.11 gy = 0.07 gz = 0.04 deg/s mx = -128 my = -130 mz = 374 mG q0 = 0.84 qx = -0.06 qy = 0.08 qz = 0.54 Yaw, Pitch, Roll: 59.63, 11.33, -0.26 Rate = 6016.45 Hz
ax = -63.29 ay = 0.06 az = 933.04 mg gx = -0.13 gy = 0.02 gz = 0.09 deg/s mx = -128 my = -148 mz = 374 mG q0 = 0.74 qx = -0.05 qy = 0.07 qz = 0.66 Yaw, Pitch, Roll: 77.90, 9.82, 1.02 Rate = 6075.08 Hz
ax = -67.08 ay = 0.73 az = 934.81 mg gx = -0.11 gy = 0.02 gz = 0.03 deg/s mx = -115 my = -139 mz = 376 mG q0 = 0.66 qx = -0.04 qy = 0.05 qz = 0.75 Yaw, Pitch, Roll: 91.83, 7.77, 1.26 Rate = 6014.19 Hz
ax = -66.22 ay = -2.50 az = 937.01 mg gx = -0.09 gy = 0.05 gz = 0.06 deg/s mx = -121 my = -123 mz = 381 mG q0 = 0.59 qx = -0.04 qy = 0.04 qz = 0.81 Yaw, Pitch, Roll: 102.03, 6.29, 1.06 Rate = 6075.62 Hz
ax = -62.56 ay = -0.06 az = 936.40 mg gx = 0.02 gy = 0.13 gz = 0.06 deg/s mx = -112 my = -132 mz = 386 mG q0 = 0.54 qx = -0.04 qy = 0.03 qz = 0.84 Yaw, Pitch, Roll: 109.26, 5.65, 0.96 Rate = 5996.22 Hz
ax = -63.48 ay = -2.01 az = 935.12 mg gx = -0.05 gy = 0.09 gz = -0.02 deg/s mx = -135 my = -123 mz = 363 mG q0 = 0.51 qx = -0.03 qy = 0.03 qz = 0.86 Yaw, Pitch, Roll: 113.21, 4.85, 0.49 Rate = 6005.31 Hz
ax = -64.51 ay = -0.67 az = 934.94 mg gx = -0.11 gy = 0.08 gz = 0.13 deg/s mx = -124 my = -116 mz = 374 mG q0 = 0.49 qx = -0.03 qy = 0.02 qz = 0.87 Yaw, Pitch, Roll: 115.43, 4.47, 0.34 Rate = 6065.58 Hz
ax = -64.33 ay = 1.40 az = 935.36 mg gx = -0.06 gy = -0.02 gz = -0.05 deg/s mx = -131 my = -105 mz = 370 mG q0 = 0.48 qx = -0.03 qy = 0.02 qz = 0.88 Yaw, Pitch, Roll: 116.74, 4.13, 0.14 Rate = 6012.50 Hz
ax = -63.17 ay = -2.62 az = 939.33 mg gx = -0.05 gy = 0.05 gz = 0.00 deg/s mx = -126 my = -118 mz = 382 mG q0 = 0.47 qx = -0.03 qy = 0.02 qz = 0.88 Yaw, Pitch, Roll: 117.65, 4.24, 0.19 Rate = 6074.97 Hz
ax = -65.43 ay = -0.12 az = 934.08 mg gx = -0.02 gy = 0.11 gz = -0.02 deg/s mx = -146 my = -127 mz = 374 mG q0 = 0.47 qx = -0.03 qy = 0.02 qz = 0.88 Yaw, Pitch, Roll: 118.06, 4.08, 0.03 Rate = 6013.12 Hz
ax = -63.66 ay = -0.92 az = 938.42 mg gx = -0.10 gy = 0.06 gz = 0.02 deg/s mx = -139 my = -120 mz = 370 mG q0 = 0.46 qx = -0.03 qy = 0.02 qz = 0.89 Yaw, Pitch, Roll: 118.77, 4.14, 0.12 Rate = 6075.12 Hz
ax = -63.90 ay = 2.69 az = 935.55 mg gx = -0.07 gy = 0.08 gz = 0.00 deg/s mx = -124 my = -109 mz = 370 mG q0 = 0.46 qx = -0.03 qy = 0.02 qz = 0.89 Yaw, Pitch, Roll: 118.76, 4.10, 0.15 Rate = 5995.27 Hz
ax = -64.51 ay = 0.12 az = 935.49 mg gx = -0.13 gy = 0.05 gz = 0.07 deg/s mx = -133 my = -125 mz = 369 mG q0 = 0.46 qx = -0.03 qy = 0.02 qz = 0.89 Yaw, Pitch, Roll: 118.81, 3.96, -0.00 Rate = 6075.85 Hz
ax = -64.27 ay = -1.34 az = 935.18 mg gx = -0.10 gy = 0.09 gz = 0.10 deg/s mx = -144 my = -118 mz = 376 mG q0 = 0.46 qx = -0.03 qy = 0.01 qz = 0.89 Yaw, Pitch, Roll: 118.82, 3.78, -0.13 Rate = 6008.87 Hz
ax = -64.09 ay = -1.46 az = 933.35 mg gx = -0.06 gy = 0.10 gz = 0.02 deg/s mx = -140 my = -111 mz = 372 mG q0 = 0.46 qx = -0.03 qy = 0.01 qz = 0.89 Yaw, Pitch, Roll: 118.92, 3.84, -0.07 Rate = 6075.31 Hz
ax = -66.28 ay = -0.92 az = 934.63 mg gx = -0.07 gy = 0.07 gz = 0.00 deg/s mx = -151 my = -118 mz = 382 mG q0 = 0.46 qx = -0.03 qy = 0.01 qz = 0.89 Yaw, Pitch, Roll: 118.74, 3.80, -0.14 Rate = 6044.13 Hz
ax = -67.02 ay = 0.85 az = 932.50 mg gx = -0.08 gy = 0.03 gz = 0.08 deg/s mx = -135 my = -105 mz = 374 mG q0 = 0.46 qx = -0.03 qy = 0.02 qz = 0.89 Yaw, Pitch, Roll: 118.91, 4.06, 0.07 Rate = 6063.93 Hz
ax = -66.59 ay = -0.79 az = 932.50 mg gx = -0.04 gy = -0.03 gz = 0.04 deg/s mx = -130 my = -111 mz = 379 mG q0 = 0.46 qx = -0.03 qy = 0.02 qz = 0.89 Yaw, Pitch, Roll: 119.03, 4.05, 0.03 Rate = 6051.77 Hz
ax = -65.12 ay = 0.18 az = 938.05 mg gx = -0.19 gy = 0.04 gz = 0.06 deg/s mx = -158 my = -118 mz = 376 mG q0 = 0.46 qx = -0.03 qy = 0.02 qz = 0.89 Yaw, Pitch, Roll: 118.93, 4.05, -0.01 Rate = 6019.22 Hz
ax = -67.81 ay = 7.63 az = 934.75 mg gx = 0.14 gy = 0.08 gz = 0.02 deg/s mx = -137 my = -132 mz = 372 mG q0 = 0.46 qx = -0.03 qy = 0.02 qz = 0.89 Yaw, Pitch, Roll: 118.90, 4.07, 0.06 Rate = 6075.66 Hz
ax = -63.48 ay = 3.11 az = 933.84 mg gx = -0.43 gy = 0.02 gz = 0.08 deg/s mx = -122 my = -111 mz = 379 mG q0 = 0.46 qx = -0.03 qy = 0.02 qz = 0.88 Yaw, Pitch, Roll: 118.72, 3.98, 0.12 Rate = 6033.06 Hz
ax = -63.72 ay = 1.89 az = 935.24 mg gx = -0.13 gy = 0.11 gz = 0.11 deg/s mx = -126 my = -107 mz = 389 mG q0 = 0.46 qx = -0.03 qy = 0.02 qz = 0.88 Yaw, Pitch, Roll: 118.69, 4.11, 0.06 Rate = 6063.83 Hz
ax = -66.59 ay = -1.16 az = 932.56 mg gx = 0.06 gy = 0.08 gz = 0.00 deg/s mx = -126 my = -107 mz = 372 mG q0 = 0.47 qx = -0.03 qy = 0.01 qz = 0.88 Yaw, Pitch, Roll: 118.53, 3.79, -0.17 Rate = 6053.34 Hz
ax = -67.32 ay = -2.14 az = 932.50 mg gx = -0.11 gy = 0.04 gz = -0.00 deg/s mx = -126 my = -118 mz = 382 mG q0 = 0.47 qx = -0.03 qy = 0.02 qz = 0.88 Yaw, Pitch, Roll: 118.55, 4.03, -0.01 Rate = 6067.06 Hz
ax = -38.21 ay = 40.71 az = 933.23 mg gx = -1.78 gy = 1.59 gz = 97.27 deg/s mx = -115 my = -121 mz = 376 mG q0 = 0.41 qx = -0.03 qy = 0.02 qz = 0.91 Yaw, Pitch, Roll: 125.96, 3.45, 0.66 Rate = 5628.82 Hz
ax = -56.34 ay = 10.99 az = 931.21 mg gx = 5.08 gy = 0.14 gz = 80.84 deg/s mx = -43 my = -24 mz = 379 mG q0 = -0.24 qx = -0.02 qy = -0.03 qz = 0.97 Yaw, Pitch, Roll: -158.72, 2.37, -2.45 Rate = 6062.89 Hz
ax = -56.27 ay = -39.12 az = 938.35 mg gx = -2.11 gy = 0.05 gz = 2.46 deg/s mx = -51 my = -13 mz = 372 mG q0 = -0.20 qx = -0.00 qy = -0.04 qz = 0.98 Yaw, Pitch, Roll: -162.69, 1.67, -3.86 Rate = 6029.79 Hz
ax = -61.65 ay = -2.99 az = 937.74 mg gx = -0.26 gy = 0.02 gz = -1.28 deg/s mx = -51 my = -17 mz = 400 mG q0 = -0.10 qx = -0.01 qy = -0.03 qz = 0.99 Yaw, Pitch, Roll: -173.96, 1.75, -2.89 Rate = 6075.68 Hz
ax = -62.81 ay = -1.28 az = 935.06 mg gx = -0.06 gy = 0.06 gz = 0.05 deg/s mx = -54 my = -21 mz = 369 mG q0 = 0.03 qx = -0.01 qy = -0.02 qz = 1.00 Yaw, Pitch, Roll: 170.70, 1.45, -2.72 Rate = 6029.47 Hz
ax = -63.72 ay = -1.59 az = 934.20 mg gx = -0.04 gy = -0.00 gz = 0.02 deg/s mx = -51 my = -6 mz = 386 mG q0 = 0.20 qx = -0.01 qy = -0.01 qz = 0.98 Yaw, Pitch, Roll: 150.75, 1.21, -1.67 Rate = 6065.12 Hz
ax = -60.67 ay = -0.24 az = 934.27 mg gx = -0.13 gy = 0.06 gz = -0.03 deg/s mx = -42 my = -12 mz = 384 mG q0 = 0.39 qx = -0.02 qy = -0.00 qz = 0.92 Yaw, Pitch, Roll: 127.80, 1.93, -0.94 Rate = 6042.25 Hz
ax = -63.23 ay = -1.77 az = 932.37 mg gx = 0.00 gy = 0.10 gz = 0.06 deg/s mx = -56 my = -12 mz = 377 mG q0 = 0.56 qx = -0.02 qy = 0.00 qz = 0.83 Yaw, Pitch, Roll: 106.16, 2.14, -0.27 Rate = 6076.12 Hz
ax = -61.28 ay = -1.04 az = 936.22 mg gx = 0.00 gy = 0.02 gz = -0.02 deg/s mx = -47 my = -17 mz = 393 mG q0 = 0.67 qx = -0.02 qy = 0.02 qz = 0.74 Yaw, Pitch, Roll: 90.03, 2.98, -0.04 Rate = 6044.29 Hz
ax = -60.79 ay = -1.77 az = 935.42 mg gx = -0.05 gy = 0.11 gz = 0.09 deg/s mx = -56 my = 2 mz = 374 mG q0 = 0.73 qx = -0.02 qy = 0.02 qz = 0.68 Yaw, Pitch, Roll: 80.29, 2.93, 0.13 Rate = 6027.94 Hz
ax = -60.85 ay = -2.38 az = 933.04 mg gx = 0.00 gy = 0.05 gz = 0.03 deg/s mx = -61 my = -6 mz = 382 mG q0 = 0.76 qx = -0.02 qy = 0.02 qz = 0.65 Yaw, Pitch, Roll: 75.33, 3.41, 0.01 Rate = 6066.50 Hz
ax = -60.06 ay = -1.22 az = 932.19 mg gx = -0.03 gy = 0.03 gz = -0.04 deg/s mx = -60 my = -26 mz = 384 mG q0 = 0.77 qx = -0.02 qy = 0.02 qz = 0.63 Yaw, Pitch, Roll: 72.83, 3.61, -0.05 Rate = 6030.10 Hz
ax = -62.93 ay = -1.28 az = 933.17 mg gx = -0.08 gy = 0.03 gz = 0.08 deg/s mx = -47 my = -3 mz = 376 mG q0 = 0.78 qx = -0.02 qy = 0.03 qz = 0.62 Yaw, Pitch, Roll: 71.23, 3.81, -0.06 Rate = 6074.03 Hz
ax = -61.40 ay = -0.85 az = 935.85 mg gx = 0.00 gy = 0.06 gz = -0.00 deg/s mx = -43 my = -17 mz = 393 mG q0 = 0.79 qx = -0.02 qy = 0.03 qz = 0.61 Yaw, Pitch, Roll: 69.93, 3.96, -0.08 Rate = 6044.62 Hz
ax = -63.84 ay = -2.62 az = 933.72 mg gx = -0.04 gy = 0.09 gz = 0.00 deg/s mx = -49 my = -12 mz = 367 mG q0 = 0.80 qx = -0.02 qy = 0.03 qz = 0.60 Yaw, Pitch, Roll: 67.66, 4.02, -0.16 Rate = 6075.50 Hz
ax = -64.15 ay = -0.18 az = 932.86 mg gx = -0.02 gy = 0.02 gz = 0.02 deg/s mx = -36 my = -21 mz = 372 mG q0 = 0.81 qx = -0.02 qy = 0.03 qz = 0.59 Yaw, Pitch, Roll: 66.22, 4.04, -0.05 Rate = 6045.68 Hz
ax = -61.16 ay = -1.40 az = 937.19 mg gx = 0.02 gy = 0.05 gz = 0.02 deg/s mx = -52 my = 5 mz = 381 mG q0 = 0.81 qx = -0.02 qy = 0.03 qz = 0.59 Yaw, Pitch, Roll: 66.54, 3.83, -0.13 Rate = 6061.86 Hz
ax = -59.39 ay = -2.08 az = 936.83 mg gx = -0.03 gy = 0.00 gz = 0.11 deg/s mx = -38 my = -8 mz = 384 mG q0 = 0.80 qx = -0.02 qy = 0.02 qz = 0.60 Yaw, Pitch, Roll: 67.35, 3.52, 0.00 Rate = 6027.97 Hz
As you can see there is a stabilization period at the begining. Yaw goes to 118 degree. Then I turned the board to 90 degree left and again a stabilization period until degree 66. I don't know where the problem is.
My first usage of IMU's and I will use the components for gesture recognition from wrist.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/239, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qn_4LFtWpS0AQwcJ68SbY5cp9tXSks5tYAXrgaJpZM4SR4ZR .
I didn't change the example code too much. My calibrate function is
void calibrateMPU9250(float * dest1, float * dest2)
{
uint8_t data[12]; // data array to hold accelerometer and gyro x, y, z, data
uint16_t ii, packet_count, fifo_count;
int32_t gyro_bias[3] = {0, 0, 0}, accel_bias[3] = {0, 0, 0};
// reset device
writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x80); // Write a one to bit 7 reset bit; toggle reset device
delay(100);
// get stable time source; Auto select clock source to be PLL gyroscope reference if ready
// else use the internal oscillator, bits 2:0 = 001
writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x01);
writeByte(MPU9250_ADDRESS, PWR_MGMT_2, 0x00);
delay(200);
// Configure device for bias calculation
writeByte(MPU9250_ADDRESS, INT_ENABLE, 0x00); // Disable all interrupts
writeByte(MPU9250_ADDRESS, FIFO_EN, 0x00); // Disable FIFO
writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x00); // Turn on internal clock source
writeByte(MPU9250_ADDRESS, I2C_MST_CTRL, 0x00); // Disable I2C master
writeByte(MPU9250_ADDRESS, USER_CTRL, 0x00); // Disable FIFO and I2C master modes
writeByte(MPU9250_ADDRESS, USER_CTRL, 0x0C); // Reset FIFO and DMP
delay(15);
// Configure MPU6050 gyro and accelerometer for bias calculation
writeByte(MPU9250_ADDRESS, CONFIG, 0x01); // Set low-pass filter to 188 Hz
writeByte(MPU9250_ADDRESS, SMPLRT_DIV, 0x00); // Set sample rate to 1 kHz
writeByte(MPU9250_ADDRESS, GYRO_CONFIG, 0x00); // Set gyro full-scale to 250 degrees per second, maximum sensitivity
writeByte(MPU9250_ADDRESS, ACCEL_CONFIG, 0x00); // Set accelerometer full-scale to 2 g, maximum sensitivity
uint16_t gyrosensitivity = 131; // = 131 LSB/degrees/sec
uint16_t accelsensitivity = 16384; // = 16384 LSB/g
/* // Configure FIFO to capture accelerometer and gyro data for bias calculation
writeByte(MPU9250_ADDRESS, USER_CTRL, 0x40); // Enable FIFO
writeByte(MPU9250_ADDRESS, FIFO_EN, 0x78); // Enable gyro and accelerometer sensors for FIFO (max size 512 bytes in MPU-9150)
delay(40); // accumulate 40 samples in 40 milliseconds = 480 bytes
// At end of sample accumulation, turn off FIFO sensor read
writeByte(MPU9250_ADDRESS, FIFO_EN, 0x00); // Disable gyro and accelerometer sensors for FIFO
readBytes(MPU9250_ADDRESS, FIFO_COUNTH, 2, &data[0]); // read FIFO sample count
fifo_count = ((uint16_t)data[0] << 8) | data[1];
packet_count = fifo_count/12;// How many sets of full gyro and accelerometer data for averaging*/
if (digitalRead(calibrateEnablePin) == HIGH) {
delay(500);
packet_count = 10000;
for (ii = 0; ii < packet_count; ii++) {
int16_t accel_temp[3] = {0, 0, 0}, gyro_temp[3] = {0, 0, 0};
//readBytes(MPU9250_ADDRESS, FIFO_R_W, 12, &data[0]); // read data for averaging
readBytes(MPU9250_ADDRESS, ACCEL_XOUT_H, 6, &data[0]); // Read the six raw data registers sequentially into data array
readBytes(MPU9250_ADDRESS, GYRO_XOUT_H, 6, &data[6]); // Read the six raw data registers sequentially into data array
accel_temp[0] = (int16_t) (((int16_t)data[0] << 8) | data[1] ) ; // Form signed 16-bit integer for each sample in FIFO
accel_temp[1] = (int16_t) (((int16_t)data[2] << 8) | data[3] ) ;
accel_temp[2] = (int16_t) (((int16_t)data[4] << 8) | data[5] ) ;
gyro_temp[0] = (int16_t) (((int16_t)data[6] << 8) | data[7] ) ;
gyro_temp[1] = (int16_t) (((int16_t)data[8] << 8) | data[9] ) ;
gyro_temp[2] = (int16_t) (((int16_t)data[10] << 8) | data[11]) ;
//Serial.println("TEMP DATA : " + String(accel_temp[0]) + " " + String(accel_temp[1]) + " " + String(accel_temp[2]) + " " + String(gyro_temp[0]) + " " + String(gyro_temp[1]) + " " + String(gyro_temp[2]));
accel_bias[0] += (int32_t) accel_temp[0]; // Sum individual signed 16-bit biases to get accumulated signed 32-bit biases
accel_bias[1] += (int32_t) accel_temp[1];
accel_bias[2] += (int32_t) accel_temp[2];
gyro_bias[0] += (int32_t) gyro_temp[0];
gyro_bias[1] += (int32_t) gyro_temp[1];
gyro_bias[2] += (int32_t) gyro_temp[2];
}
accel_bias[0] /= (int32_t) packet_count; // Normalize sums to get average count biases
accel_bias[1] /= (int32_t) packet_count;
accel_bias[2] /= (int32_t) packet_count;
gyro_bias[0] /= (int32_t) packet_count;
gyro_bias[1] /= (int32_t) packet_count;
gyro_bias[2] /= (int32_t) packet_count;
if(accel_bias[2] > 0L) {accel_bias[2] -= (int32_t) accelsensitivity;} // Remove gravity from the z-axis accelerometer bias calculation
else {accel_bias[2] += (int32_t) accelsensitivity;}
EEPROM.put(eeAddr, accel_bias);
eeAddr += sizeof(accel_bias);
EEPROM.put(eeAddr, gyro_bias);
eeAddr += sizeof(gyro_bias);
} else {
EEPROM.get(eeAddr, accel_bias);
eeAddr += sizeof(accel_bias);
EEPROM.get(eeAddr, gyro_bias);
eeAddr += sizeof(gyro_bias);
}
// Construct the gyro biases for push to the hardware gyro bias registers, which are reset to zero upon device startup
data[0] = (-gyro_bias[0]/4 >> 8) & 0xFF; // Divide by 4 to get 32.9 LSB per deg/s to conform to expected bias input format
data[1] = (-gyro_bias[0]/4) & 0xFF; // Biases are additive, so change sign on calculated average gyro biases
data[2] = (-gyro_bias[1]/4 >> 8) & 0xFF;
data[3] = (-gyro_bias[1]/4) & 0xFF;
data[4] = (-gyro_bias[2]/4 >> 8) & 0xFF;
data[5] = (-gyro_bias[2]/4) & 0xFF;
// Push gyro biases to hardware registers
writeByte(MPU9250_ADDRESS, XG_OFFSET_H, data[0]);
writeByte(MPU9250_ADDRESS, XG_OFFSET_L, data[1]);
writeByte(MPU9250_ADDRESS, YG_OFFSET_H, data[2]);
writeByte(MPU9250_ADDRESS, YG_OFFSET_L, data[3]);
writeByte(MPU9250_ADDRESS, ZG_OFFSET_H, data[4]);
writeByte(MPU9250_ADDRESS, ZG_OFFSET_L, data[5]);
// Output scaled gyro biases for display in the main program
dest1[0] = (float) gyro_bias[0]/(float) gyrosensitivity;
dest1[1] = (float) gyro_bias[1]/(float) gyrosensitivity;
dest1[2] = (float) gyro_bias[2]/(float) gyrosensitivity;
// Construct the accelerometer biases for push to the hardware accelerometer bias registers. These registers contain
// factory trim values which must be added to the calculated accelerometer biases; on boot up these registers will hold
// non-zero values. In addition, bit 0 of the lower byte must be preserved since it is used for temperature
// compensation calculations. Accelerometer bias registers expect bias input as 2048 LSB per g, so that
// the accelerometer biases calculated above must be divided by 8.
int32_t accel_bias_reg[3] = {0, 0, 0}; // A place to hold the factory accelerometer trim biases
readBytes(MPU9250_ADDRESS, XA_OFFSET_H, 2, &data[0]); // Read factory accelerometer trim values
accel_bias_reg[0] = (int32_t) (((int16_t)data[0] << 8) | data[1]);
readBytes(MPU9250_ADDRESS, YA_OFFSET_H, 2, &data[0]);
accel_bias_reg[1] = (int32_t) (((int16_t)data[0] << 8) | data[1]);
readBytes(MPU9250_ADDRESS, ZA_OFFSET_H, 2, &data[0]);
accel_bias_reg[2] = (int32_t) (((int16_t)data[0] << 8) | data[1]);
uint32_t mask = 1uL; // Define mask for temperature compensation bit 0 of lower byte of accelerometer bias registers
uint8_t mask_bit[3] = {0, 0, 0}; // Define array to hold mask bit for each accelerometer bias axis
for(ii = 0; ii < 3; ii++) {
if((accel_bias_reg[ii] & mask)) mask_bit[ii] = 0x01; // If temperature compensation bit is set, record that fact in mask_bit
}
// Construct total accelerometer bias, including calculated average accelerometer bias from above
accel_bias_reg[0] -= (accel_bias[0]/8); // Subtract calculated averaged accelerometer bias scaled to 2048 LSB/g (16 g full scale)
accel_bias_reg[1] -= (accel_bias[1]/8);
accel_bias_reg[2] -= (accel_bias[2]/8);
data[0] = (accel_bias_reg[0] >> 8) & 0xFF;
data[1] = (accel_bias_reg[0]) & 0xFF;
data[1] = data[1] | mask_bit[0]; // preserve temperature compensation bit when writing back to accelerometer bias registers
data[2] = (accel_bias_reg[1] >> 8) & 0xFF;
data[3] = (accel_bias_reg[1]) & 0xFF;
data[3] = data[3] | mask_bit[1]; // preserve temperature compensation bit when writing back to accelerometer bias registers
data[4] = (accel_bias_reg[2] >> 8) & 0xFF;
data[5] = (accel_bias_reg[2]) & 0xFF;
data[5] = data[5] | mask_bit[2]; // preserve temperature compensation bit when writing back to accelerometer bias registers
// Apparently this is not working for the acceleration biases in the MPU-9250
// Are we handling the temperature correction bit properly?
// Push accelerometer biases to hardware registers
writeByte(MPU9250_ADDRESS, XA_OFFSET_H, data[0]);
writeByte(MPU9250_ADDRESS, XA_OFFSET_L, data[1]);
writeByte(MPU9250_ADDRESS, YA_OFFSET_H, data[2]);
writeByte(MPU9250_ADDRESS, YA_OFFSET_L, data[3]);
writeByte(MPU9250_ADDRESS, ZA_OFFSET_H, data[4]);
writeByte(MPU9250_ADDRESS, ZA_OFFSET_L, data[5]);
// Output scaled accelerometer biases for display in the main program
dest2[0] = (float)accel_bias[0]/(float)accelsensitivity;
dest2[1] = (float)accel_bias[1]/(float)accelsensitivity;
dest2[2] = (float)accel_bias[2]/(float)accelsensitivity;
}
Problem is can be seen in plotter better.
This is the 90 degree right(Yaw).
Is this a timing issue ? Calibration problem? Is mpu9250 not a good sensor? Can't my components just can't calculate it fast enough?
I am really stuck and I want to achieve this speed and accuracy https://www.youtube.com/watch?v=BXsGWoOMtmU
You are going to have to calibrate the magnetometer too. See here https://github.com/kriswiner/MPU6050/wiki/Simple-and-Effective-Magnetometer-Calibration .
This sketch has an example.
https://github.com/kriswiner/ESP8285/tree/master/MPU9250
On Sat, Feb 24, 2018 at 5:15 PM, Berat Özbay notifications@github.com wrote:
I didn't change the example code too much. My calibrate function is
void calibrateMPU9250(float dest1, float dest2) { uint8_t data[12]; // data array to hold accelerometer and gyro x, y, z, data uint16_t ii, packet_count, fifo_count; int32_t gyro_bias[3] = {0, 0, 0}, accel_bias[3] = {0, 0, 0};
// reset device writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x80); // Write a one to bit 7 reset bit; toggle reset device delay(100);
// get stable time source; Auto select clock source to be PLL gyroscope reference if ready // else use the internal oscillator, bits 2:0 = 001 writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x01); writeByte(MPU9250_ADDRESS, PWR_MGMT_2, 0x00); delay(200);
// Configure device for bias calculation writeByte(MPU9250_ADDRESS, INT_ENABLE, 0x00); // Disable all interrupts writeByte(MPU9250_ADDRESS, FIFO_EN, 0x00); // Disable FIFO writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x00); // Turn on internal clock source writeByte(MPU9250_ADDRESS, I2C_MST_CTRL, 0x00); // Disable I2C master writeByte(MPU9250_ADDRESS, USER_CTRL, 0x00); // Disable FIFO and I2C master modes writeByte(MPU9250_ADDRESS, USER_CTRL, 0x0C); // Reset FIFO and DMP delay(15);
// Configure MPU6050 gyro and accelerometer for bias calculation writeByte(MPU9250_ADDRESS, CONFIG, 0x01); // Set low-pass filter to 188 Hz writeByte(MPU9250_ADDRESS, SMPLRT_DIV, 0x00); // Set sample rate to 1 kHz writeByte(MPU9250_ADDRESS, GYRO_CONFIG, 0x00); // Set gyro full-scale to 250 degrees per second, maximum sensitivity writeByte(MPU9250_ADDRESS, ACCEL_CONFIG, 0x00); // Set accelerometer full-scale to 2 g, maximum sensitivity
uint16_t gyrosensitivity = 131; // = 131 LSB/degrees/sec uint16_t accelsensitivity = 16384; // = 16384 LSB/g
/* // Configure FIFO to capture accelerometer and gyro data for bias calculation writeByte(MPU9250_ADDRESS, USER_CTRL, 0x40); // Enable FIFO writeByte(MPU9250_ADDRESS, FIFO_EN, 0x78); // Enable gyro and accelerometer sensors for FIFO (max size 512 bytes in MPU-9150) delay(40); // accumulate 40 samples in 40 milliseconds = 480 bytes
// At end of sample accumulation, turn off FIFO sensor read writeByte(MPU9250_ADDRESS, FIFO_EN, 0x00); // Disable gyro and accelerometer sensors for FIFO readBytes(MPU9250_ADDRESS, FIFO_COUNTH, 2, &data[0]); // read FIFO sample count fifo_count = ((uint16_t)data[0] << 8) | data[1]; packet_count = fifo_count/12;// How many sets of full gyro and accelerometer data for averaging*/
if (digitalRead(calibrateEnablePin) == HIGH) { delay(500); packet_count = 10000; for (ii = 0; ii < packet_count; ii++) { int16_t accel_temp[3] = {0, 0, 0}, gyro_temp[3] = {0, 0, 0}; //readBytes(MPU9250_ADDRESS, FIFO_R_W, 12, &data[0]); // read data for averaging
readBytes(MPU9250_ADDRESS, ACCEL_XOUT_H, 6, &data[0]); // Read the six raw data registers sequentially into data array readBytes(MPU9250_ADDRESS, GYRO_XOUT_H, 6, &data[6]); // Read the six raw data registers sequentially into data array accel_temp[0] = (int16_t) (((int16_t)data[0] << 8) | data[1] ) ; // Form signed 16-bit integer for each sample in FIFO accel_temp[1] = (int16_t) (((int16_t)data[2] << 8) | data[3] ) ; accel_temp[2] = (int16_t) (((int16_t)data[4] << 8) | data[5] ) ; gyro_temp[0] = (int16_t) (((int16_t)data[6] << 8) | data[7] ) ; gyro_temp[1] = (int16_t) (((int16_t)data[8] << 8) | data[9] ) ; gyro_temp[2] = (int16_t) (((int16_t)data[10] << 8) | data[11]) ; //Serial.println("TEMP DATA : " + String(accel_temp[0]) + " " + String(accel_temp[1]) + " " + String(accel_temp[2]) + " " + String(gyro_temp[0]) + " " + String(gyro_temp[1]) + " " + String(gyro_temp[2])); accel_bias[0] += (int32_t) accel_temp[0]; // Sum individual signed 16-bit biases to get accumulated signed 32-bit biases accel_bias[1] += (int32_t) accel_temp[1]; accel_bias[2] += (int32_t) accel_temp[2]; gyro_bias[0] += (int32_t) gyro_temp[0]; gyro_bias[1] += (int32_t) gyro_temp[1]; gyro_bias[2] += (int32_t) gyro_temp[2]; } accel_bias[0] /= (int32_t) packet_count; // Normalize sums to get average count biases accel_bias[1] /= (int32_t) packet_count; accel_bias[2] /= (int32_t) packet_count; gyro_bias[0] /= (int32_t) packet_count; gyro_bias[1] /= (int32_t) packet_count; gyro_bias[2] /= (int32_t) packet_count; if(accel_bias[2] > 0L) {accel_bias[2] -= (int32_t) accelsensitivity;} // Remove gravity from the z-axis accelerometer bias calculation else {accel_bias[2] += (int32_t) accelsensitivity;} EEPROM.put(eeAddr, accel_bias); eeAddr += sizeof(accel_bias); EEPROM.put(eeAddr, gyro_bias); eeAddr += sizeof(gyro_bias);
} else { EEPROM.get(eeAddr, accel_bias); eeAddr += sizeof(accel_bias); EEPROM.get(eeAddr, gyro_bias); eeAddr += sizeof(gyro_bias); }
// Construct the gyro biases for push to the hardware gyro bias registers, which are reset to zero upon device startup data[0] = (-gyro_bias[0]/4 >> 8) & 0xFF; // Divide by 4 to get 32.9 LSB per deg/s to conform to expected bias input format data[1] = (-gyro_bias[0]/4) & 0xFF; // Biases are additive, so change sign on calculated average gyro biases data[2] = (-gyro_bias[1]/4 >> 8) & 0xFF; data[3] = (-gyro_bias[1]/4) & 0xFF; data[4] = (-gyro_bias[2]/4 >> 8) & 0xFF; data[5] = (-gyro_bias[2]/4) & 0xFF;
// Push gyro biases to hardware registers writeByte(MPU9250_ADDRESS, XG_OFFSET_H, data[0]); writeByte(MPU9250_ADDRESS, XG_OFFSET_L, data[1]); writeByte(MPU9250_ADDRESS, YG_OFFSET_H, data[2]); writeByte(MPU9250_ADDRESS, YG_OFFSET_L, data[3]); writeByte(MPU9250_ADDRESS, ZG_OFFSET_H, data[4]); writeByte(MPU9250_ADDRESS, ZG_OFFSET_L, data[5]);
// Output scaled gyro biases for display in the main program dest1[0] = (float) gyro_bias[0]/(float) gyrosensitivity; dest1[1] = (float) gyro_bias[1]/(float) gyrosensitivity; dest1[2] = (float) gyro_bias[2]/(float) gyrosensitivity;
// Construct the accelerometer biases for push to the hardware accelerometer bias registers. These registers contain // factory trim values which must be added to the calculated accelerometer biases; on boot up these registers will hold // non-zero values. In addition, bit 0 of the lower byte must be preserved since it is used for temperature // compensation calculations. Accelerometer bias registers expect bias input as 2048 LSB per g, so that // the accelerometer biases calculated above must be divided by 8.
int32_t accel_bias_reg[3] = {0, 0, 0}; // A place to hold the factory accelerometer trim biases readBytes(MPU9250_ADDRESS, XA_OFFSET_H, 2, &data[0]); // Read factory accelerometer trim values accel_bias_reg[0] = (int32_t) (((int16_t)data[0] << 8) | data[1]); readBytes(MPU9250_ADDRESS, YA_OFFSET_H, 2, &data[0]); accel_bias_reg[1] = (int32_t) (((int16_t)data[0] << 8) | data[1]); readBytes(MPU9250_ADDRESS, ZA_OFFSET_H, 2, &data[0]); accel_bias_reg[2] = (int32_t) (((int16_t)data[0] << 8) | data[1]);
uint32_t mask = 1uL; // Define mask for temperature compensation bit 0 of lower byte of accelerometer bias registers uint8_t mask_bit[3] = {0, 0, 0}; // Define array to hold mask bit for each accelerometer bias axis
for(ii = 0; ii < 3; ii++) { if((accel_bias_reg[ii] & mask)) mask_bit[ii] = 0x01; // If temperature compensation bit is set, record that fact in mask_bit }
// Construct total accelerometer bias, including calculated average accelerometer bias from above accel_bias_reg[0] -= (accel_bias[0]/8); // Subtract calculated averaged accelerometer bias scaled to 2048 LSB/g (16 g full scale) accel_bias_reg[1] -= (accel_bias[1]/8); accel_bias_reg[2] -= (accel_bias[2]/8);
data[0] = (accel_bias_reg[0] >> 8) & 0xFF; data[1] = (accel_bias_reg[0]) & 0xFF; data[1] = data[1] | mask_bit[0]; // preserve temperature compensation bit when writing back to accelerometer bias registers data[2] = (accel_bias_reg[1] >> 8) & 0xFF; data[3] = (accel_bias_reg[1]) & 0xFF; data[3] = data[3] | mask_bit[1]; // preserve temperature compensation bit when writing back to accelerometer bias registers data[4] = (accel_bias_reg[2] >> 8) & 0xFF; data[5] = (accel_bias_reg[2]) & 0xFF; data[5] = data[5] | mask_bit[2]; // preserve temperature compensation bit when writing back to accelerometer bias registers
// Apparently this is not working for the acceleration biases in the MPU-9250 // Are we handling the temperature correction bit properly? // Push accelerometer biases to hardware registers writeByte(MPU9250_ADDRESS, XA_OFFSET_H, data[0]); writeByte(MPU9250_ADDRESS, XA_OFFSET_L, data[1]); writeByte(MPU9250_ADDRESS, YA_OFFSET_H, data[2]); writeByte(MPU9250_ADDRESS, YA_OFFSET_L, data[3]); writeByte(MPU9250_ADDRESS, ZA_OFFSET_H, data[4]); writeByte(MPU9250_ADDRESS, ZA_OFFSET_L, data[5]);
// Output scaled accelerometer biases for display in the main program dest2[0] = (float)accel_bias[0]/(float)accelsensitivity; dest2[1] = (float)accel_bias[1]/(float)accelsensitivity; dest2[2] = (float)accel_bias[2]/(float)accelsensitivity; }
Problem is can be seen in plotter better. [image: screenshot 18 _li] https://user-images.githubusercontent.com/9295395/36636935-a95fae9a-19e1-11e8-85d6-2506df03ff4d.jpg
This is the 90 degree right.
Is this a timing issue ? Calibration problem? Is mpu9250 not a good sensor? Can't my components just can't calculate it fast enough?
I am reall stuck and I want to achive this speed and accuracy https://www.youtube.com/watch?v=BXsGWoOMtmU
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/239#issuecomment-368274417, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qsmQc9qlYqd_fI3vHIznKUbBym0wks5tYLRJgaJpZM4SR4ZR .
Sorry for my late response.
I tried different calibration tecqniues both yours and diydrones second one worked well but not perfect.
When I calculate angles pitch behaves abnormal (I think it's abnormal). When Pitch goes exactly up suddenly yaw goes to 270(initally 90) and roll goes to -180 (initally 0).
My madgwick parameters.
MadgwickQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, my, mx, -mz);
The sudden change I mentioned doesn't seem bad in visualizer. Even so, changes not well for me because I want to use the angles as joystick angles.
This is in ENU convention, and should work. Maybe the accel nd gyro aren;t calibrated?
How do you check your sensor calibrations?
On Mon, Mar 5, 2018 at 1:08 PM, Berat Özbay notifications@github.com wrote:
Sorry for my late response.
I tried different calibration tecqniues both yours https://github.com/kriswiner/MPU6050/wiki/Simple-and-Effective-Magnetometer-Calibration and diydrones https://diydrones.com/profiles/blogs/advanced-hard-and-soft-iron-magnetometer-calibration-for-dummies second one worked well but not perfect.
When I calculate angles pitch behaves abnormal (I think it's abnormal). When Pitch goes exactly up suddenly yaw goes to 270(initally 90) and roll goes to -180 (initally 0).
My madgwick parameters. MadgwickQuaternionUpdate(ax, ay, az, gxPI/180.0f, gyPI/180.0f, gz*PI/180.0f, my, mx, -mz);
The sudden change I mentioned doesn't seem bad in visualizer https://github.com/arduino-libraries/MadgwickAHRS/tree/master/extras/Visualizer. Even so, changes not well for me because I want to use the angles as joystick angles.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/239#issuecomment-370566136, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qpUG1_Brh20lHVXc-ijsbmWCslnkks5tbalKgaJpZM4SR4ZR .
For accel and gyro, I just check the outputs while sensor standing. For mag, I wrote a program in processing. It has output mag points in 2D(Mxy, Mxz, Myz).
Not sure what to tell you. Although the Sparkfun design has power traces running under the MPU9250, maybe tthese are interfering with your measurements...
On Mon, Mar 5, 2018 at 1:39 PM, Berat Özbay notifications@github.com wrote:
For accel and gyro, I just check the outputs while sensor standing. For mag, I wrote a program in processing. It has output mag points in 2D(Mxy, Mxz, Myz).
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/239#issuecomment-370575604, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qpb7A5SK3tj95ikBs7bOn60o-Nlzks5tbbCIgaJpZM4SR4ZR .
I see. Thank you so much. I learned a lot while trying to calibrate sensor. But I want to ask an out of topic question.
Can you suggest a high quality sensor(s) for motion tracking?
What kind of motion tracking? Absolute orientation, dead reckoning, velocimetry...?
On Tue, Mar 6, 2018 at 6:25 PM, Berat Özbay notifications@github.com wrote:
I see. Thank you so much. I learned a lot while trying to calibrate sensor. But I want to ask an out of topic question.
Can you suggest a high quality sensor(s) for motion tracking?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/239#issuecomment-371000558, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qo-TFNav0TyfnOchEEhhpH8twDkuks5tb0UhgaJpZM4SR4ZR .
Motion recognition. Like smart watches you know
You mean running versus walking versus sitting versus standing?
Can you be more specific?
On Tue, Mar 6, 2018 at 6:32 PM, Berat Özbay notifications@github.com wrote:
Motion recognition. Like smart watches you know
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/239#issuecomment-371001708, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qj6Eb9HAj2qZZqp3TQXtSJEKx6suks5tb0a-gaJpZM4SR4ZR .
Yes I want to able to recognize mainly runnig, walking, sitting, standig. Besides I will try to recognize specific movements like tennis or fitness movement.
This will be more about the contextual interpretation of the data then than the quality of the sensor or sensor fusion. I would use either 1) an MPU9250 or 2) an MPU9250 + EM7180. There are also some sensors that have contextual awareness libraries that are offered as binaries like the LSM6DSM, which is a fine sensor.
On Tue, Mar 6, 2018 at 7:19 PM, Berat Özbay notifications@github.com wrote:
Yes I want to able to recognize mainly runnig, walking, sitting, standig. Besides I will try to recognize specific movements like tennis or fitness movement.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/239#issuecomment-371009339, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qrOXYG62rCRuo17KQlQQno1fGHgrks5tb1G4gaJpZM4SR4ZR .
Hello,
I have a sparkfun MPU9250 breakout board and a teensy 3.5. When I tried the example "MPU9250BasicAHRS_t3" I take the this kind of result.
As you can see there is a stabilization period at the begining. Yaw goes to 118 degree. Then I turned the board to 90 degree left and again a stabilization period until degree 66. I don't know where the problem is.
My first usage of IMU's and I will use the components for gesture recognition from wrist.