Created Wed, 07 Sep 2016 14:54:48 +0000 by ricklon
Wed, 07 Sep 2016 14:54:48 +0000
For the Sparkfun AVC race I'm putting together an autonomous toy tractor about the size of a kids power wheels racer. I selected the mpu9250 as the IMU. Cheap and Arduino friendly. https://www.sparkfun.com/products/13762?_ga=1.258969674.1916523252.1465569739
It uses this library: https://github.com/sparkfun/MPU-9250_Breakout
It uses an interrupt to check if there are new values in the IMU. I've tested and the interrupt defaults to true even if no new data occurs. So I started to guess that maybe there was a problem with how the i2c library interrupt was configured. In the good news category there is a delta to prevent I believe some of the data from coming back too soon. I'm certainly missing something. Maybe, an interrupt pin would need to be configured? How does i2c generate an interrupt?
In the bad news category the yaw,pitch,roll calculations change by themselves without the unit moving.
Current test code: https://gist.github.com/ricklon/fbb698e2a574e1cd71c0015eeb49ea1c
Example Output:
MPU9250 I AM 71 I should be 71
MPU9250 is online...
x-axis self test: acceleration trim within : -1.3% of factory value
y-axis self test: acceleration trim within : 3.4% of factory value
z-axis self test: acceleration trim within : 0.9% of factory value
x-axis self test: gyration trim within : -0.5% of factory value
y-axis self test: gyration trim within : 0.3% of factory value
z-axis self test: gyration trim within : -0.6% of factory value
MPU9250 initialized for active data mode....
AK8963 I AM 48 I should be 48
AK8963 initialized for active data mode....
X-Axis sensitivity adjustment value 1.18
Y-Axis sensitivity adjustment value 1.18
Z-Axis sensitivity adjustment value 1.14
millis: 7912, diff: 7912
Interrupt
ax = 1.71 ay = -97.90 az = 1000.73 mg
gx = -0.08 gy = -0.10 gz = -0.07 deg/s
mx = -1002 my = 524 mz = 297 mG
q0 = 0.03 qx = -0.35 qy = 0.15 qz = 0.92
Yaw, Pitch, Roll: -188.84, 41.19, 19.27
rate = 0.13 Hz
millis: 10317, diff: 2405
Interrupt
ax = 1.77 ay = -96.37 az = 1003.60 mg
gx = -0.04 gy = -0.04 gz = -0.01 deg/s
mx = -1002 my = 541 mz = 300 mG
q0 = 0.10 qx = 0.58 qy = -0.44 qz = -0.68
Yaw, Pitch, Roll: -127.92, 44.35, 95.11
rate = 0.42 Hz
millis: 11965, diff: 1648
Interrupt
ax = 3.36 ay = -98.88 az = 996.15 mg
gx = -0.06 gy = -0.08 gz = 0.06 deg/s
mx = -997 my = 525 mz = 295 mG
q0 = 0.04 qx = -0.54 qy = 0.08 qz = -0.83
Yaw, Pitch, Roll: -172.35, -64.19, -24.32
rate = 0.61 Hz
millis: 12085, diff: 120
Interrupt
millis: 12204, diff: 119
Interrupt
Data from later
Interrupt
millis: 350138, diff: 337933
Interrupt
ax = 1.59 ay = -97.47 az = 998.47 mg
gx = -0.03 gy = -0.05 gz = 0.03 deg/s
mx = -997 my = 533 mz = 316 mG
q0 = -0.00 qx = 0.64 qy = -0.09 qz = 0.76
Yaw, Pitch, Roll: -158.00, -77.76, -42.10
rate = 0.01 Hz
millis: 351505, diff: 1367
Interrupt
ax = 1.53 ay = -96.31 az = 998.29 mg
gx = -0.01 gy = 0.03 gz = 0.03 deg/s
mx = -995 my = 524 mz = 297 mG
q0 = 0.10 qx = -0.75 qy = -0.06 qz = 0.65
Yaw, Pitch, Roll: 44.46, 74.72, -119.68
rate = 0.73 Hz
millis: 351697, diff: 191
Interrupt
millis: 351889, diff: 192
Interrupt
millis: 352081, diff: 191
Interrupt
ax = 1.77 ay = -94.60 az = 1002.62 mg
gx = 0.04 gy = 0.01 gz = -0.03 deg/s
mx = -1007 my = 525 mz = 295 mG
q0 = 0.89 qx = 0.08 qy = 0.35 qz = 0.29
Yaw, Pitch, Roll: 31.31, 35.25, 24.82
rate = 5.21 Hz
millis: 352265, diff: 184
Interrupt
millis: 352465, diff: 200
Interrupt
millis: 352657, diff: 192
Interrupt
ax = 1.95 ay = -96.01 az = 1003.23 mg
gx = 0.11 gy = 0.08 gz = -0.02 deg/s
mx = -1000 my = 511 mz = 305 mG
q0 = 0.80 qx = -0.23 qy = -0.12 qz = 0.54
Yaw, Pitch, Roll: 54.00, 2.48, -29.74
rate = 5.21 Hz
millis: 352865, diff: 207
Interrupt
millis: 353065, diff: 200
Interrupt
millis: 353265, diff: 200
Interrupt
ax = 2.14 ay = -96.98 az = 997.68 mg
gx = 0.02 gy = -0.16 gz = -0.05 deg/s
mx = -995 my = 541 mz = 304 mG
q0 = 0.90 qx = 0.35 qy = -0.13 qz = 0.21
Yaw, Pitch, Roll: 5.48, -23.00, 39.27
rate = 4.94 Hz
millis: 353473, diff: 208
Interrupt
millis: 353673, diff: 200
Interrupt
millis: 353889, diff: 216
Interrupt
ax = 2.38 ay = -94.97 az = 995.18 mg
gx = -0.12 gy = -0.11 gz = 0.07 deg/s
mx = -995 my = 531 mz = 300 mG
q0 = 0.63 qx = -0.13 qy = 0.40 qz = 0.65
Yaw, Pitch, Roll: 91.66, 42.76, 29.46
rate = 4.81 Hz
millis: 354081, diff: 192
Interrupt
millis: 354281, diff: 200
Interrupt
millis: 354481, diff: 200
Interrupt
ax = 0.79 ay = -94.91 az = 1002.32 mg
gx = -0.07 gy = -0.05 gz = 0.03 deg/s
mx = -997 my = 525 mz = 305 mG
q0 = 0.87 qx = -0.04 qy = -0.37 qz = 0.33
Yaw, Pitch, Roll: 36.86, -38.08, -23.55
rate = 5.07 Hz
millis: 354673, diff: 192
Interrupt
Thu, 08 Sep 2016 10:01:21 +0000
I can't help with the YPR values, but I see they have broken rule #1 of magnetometers with that breakout board - do not have ground pour or any traces under the chip.
I would suggest hooking up a logic analyser to the I2C and interrupt lines and examine the traces that it produces to see just what is being transferred between the chip and the PIC32.
Thu, 08 Sep 2016 16:44:23 +0000
Rick, I agree with Matt. If you can post some Saleae data files for us to download and examine, it might be a lot easier for us to help you figure out why it's not working.
*Brian
Thu, 08 Sep 2016 21:57:52 +0000
I will do that tonight. I've reread the data sheet. So I think I'll eliminate the simple issues and then do the data gathering.
--Rick
Fri, 09 Sep 2016 15:12:41 +0000
The easy part. Wire the physical interrupt pin from i2c device to a physical pin on board. That keeps it from floating. Now that it's in place it appears to get ignored.
Link to barely modified standard code from Sparkfun. I added a wait until I hit "s" to start. Set the intPin to 3. https://gist.github.com/ricklon/e01b399fdec0ee5d7a0497943ce0553e
Feed back from the serial port: https://gist.github.com/ricklon/86551268b4ab577545cb5a2fa72aa510
Link to the logic analyzer data: https://drive.google.com/open?id=0B_rtrA3nEeTgMEw2ZndQWTkzMUk
Thanks for looking.
Fri, 09 Sep 2016 15:18:37 +0000
Hang on logic analyzer data might be wrong. Arg!!! Will report back. --Rick
Fri, 09 Sep 2016 15:45:59 +0000
The Logic Analyzer isn't recognized on my laptop. Worked on my other computer fine. OK. Here's the fixed version and matching data.
Link to barely modified standard code from Sparkfun. I added a wait until I hit "s" to start. Set the intPin to 3. https://gist.github.com/ricklon/e01b399 ... 943ce0553e
Data on the serial port: https://gist.github.com/ricklon/86551268b4ab577545cb5a2fa72aa510
Logic analyzer data: https://drive.google.com/open?id=0B_rtrA3nEeTgQ0x4eklyV0RNbms
Sun, 11 Sep 2016 17:45:51 +0000
So the other things is for AHRS I don't know what the values I should see are. So it could be right and I have the wrong frame of reference.
Sun, 11 Sep 2016 17:48:18 +0000
Could there be a problem with the math library?
myIMU.yaw = atan2(2.0f * (*(getQ() + 1) * *(getQ() + 2) + *getQ() * *(getQ() + 3)), *getQ() * *getQ() + * (getQ() + 1) * *(getQ() + 1) - * (getQ() + 2) * *(getQ() + 2) - * (getQ() + 3) * (getQ() + 3)); myIMU.pitch = -asin(2.0f * ((getQ() + 1) * *(getQ() + 3) - *getQ() * *(getQ() + 2))); myIMU.roll = atan2(2.0f * (*getQ() * *(getQ() + 1) + * (getQ() + 2) * *(getQ() + 3)), *getQ() * *getQ() - * (getQ() + 1) * *(getQ() + 1) - * (getQ() + 2) * *(getQ() + 2) + * (getQ() + 3) * *(getQ() + 3));
Mon, 12 Sep 2016 00:02:46 +0000
So this article shows a image of a uncalibrated magnetometer and it looks closer to what I'm seeing. I'll review the calibration information.
[url]https://github.com/kriswiner/MPU-6050/wiki/Simple-and-Effective-Magnetometer-Calibration[/url]