collapse

Author Topic: Investigating the MPU 6050 DMP  (Read 15634 times)

BaldwinK

  • Member
  • ****
  • B
  • Posts: 22
Investigating the MPU 6050 DMP
« on: December 02, 2015, 08:06:10 AM »
It is easy to get raw data from the listed registers, but most people use Jeff Rowberg’s libraries to extract processed information from the DMP.  I wanted to find out more about the actual chip capabilities so I gathered all available publications by the manufacturer Invensense.  There are also lots of clues to be found on the web but nowhere to see the whole picture.

Initially I used a Picaxe 28X2 module with native i2c ability, four slots of 4k program space, 64MHz clock speed but no negative number arithmetic.  In parallel with the investigation was a Nano V3 CH380G with no native i2c but 30k of program space, 16MHz clock and extensive advanced number crunching.  It wasn’t a contest because the Nano would always win in the end but I have a stalled two wheeled (in line) bot awaiting balance feedback and it uses a Picaxe so far.  The breakout board I have is the GY-521.

This is a very complex chip with a hundred odd registers to set parameters, calibrate and read acceleration and gyro data.  Post processing is possible with filters etc but the DMP ‘fuses’ acceleration and gyro data for a more stable output.  The gyro will self calibrate if motionless for a number of seconds, but acceleration offsets have to be applied once the DMP is up and running.  I have initially tended to ignore accurate orientation since one chip can be rotated inside the bot as necessary.

There is a 4k volatile memory space in the MPU, 1k for the FIFO and 3k for a firmware image (it was only 2k when Jeff did his original work).  The firmware image has to be loaded each time the chip is powered up.  Notice there is a gap in the listed registers from 109 to 113 and these concern the DMP:

Register 109    (0x6D)           Bank Select Address – firmware loaded in 256 byte banks 0-11 (total 3k)
Register 110   (0x6E)      Bank Memory Address – the actual byte address within the bank
Register 111   (0x6F)      Firmware Read/Write – the portal to read and write a byte through
Register 112   (0x70)      Program Start Address H – this is where this firmware version begins to execute (0x0400)
Register 113   (0x71)      Program Start Address L

Once the firmware is loaded (and checked by reading blocks back) it has to be set running.  Now notice in Register 106 (user control) there are two reserved bits next to the FIFO enable and FIFO reset – these are for the DMP enable and reset.  So in principle this should be easy – load the firmware and set it running!

Of course we still have choices to make now - such as what information from the DMP should be placed in the FIFO and how frequently should the FIFO be filled.  With the Picaxe it is necessary to slow the rate in order to have a chance to process the data.  The Nano could probably manage anything but with a sampling rate of 200Hz this is still a lot to cope with.  There is a way to set the rate lower by changing areas of the firmware code.  I set it for 5Hz but it seems to run at 10Hz which is fine.  Invensense provide function calls to do this but if we have a fixed requirement then these changes can be made before the firmware is loaded.  However, there is a known bug in the firmware such that rate changes will be ignored if tap data is not requested.  So we have to have it and just discard it.  Perhaps this tap data might be useful as a last resort collision detection as it can indicate the direction of impact.  Gesture must also be set for the tap data to be sent.

The primary function of the DMP is to provide quaternions so we should ask to have the 6X quat data put into the FIFO.  This will be four 32 bit signed values w,x,y,z followed by four bytes of tap data.  Quaternions mean very little to a non-mathematician so they tend to get changed into Yaw, Pitch and Roll for us laymen.  Whereas quaternions use four dimensions, the conversion to three dimensions, so that we can comprehend, means there may be issues at certain rotations (known as gimbal lock).

Mostly, the registers have usable default values at power up but one must be changed for the DMP to run correctly.  Reg 27 (gyro config) defaults to FSR 250dps and must be changed to FSR 2000dps.

The pdf for the MPU 6050 gives a clear description of the i2c protocol expected.  I find using my own routines allows for debugging when my single-trace handheld oscilloscope can’t capture unique high speed events.  I had trouble with the tricky clock inversion for the ‘restart’ event to function.  This is when the slave address is sent followed by the register to read from.  Then, rather than sending a stop, the master continues with a restart to read the data from the register.  My routines may not be elegant nor super fast but then the bus speed should not exceed 400kHz.

The firmware array code is commented for locations of interest.  There is still work to be done to use the accelerometer biases found in unlisted registers 6 to 11 and the 12 bytes in the firmware that might accept them if scaled to suit.  The Invensense references provide code and explanations for other changes.  The attached program simply simply tests the FIFO count and outputs w,x,y,z,yaw, pitch and roll to the screen.

*GY-521 code.doc

At this time my Picaxe attempt is failing, it seems the Nano is the only way forward.

Source documentation found on the web - keep on looking, it will be there:

inv_mpu.h; inv_mpu.c; inv_mpu_dmp_motion_driver.h; inv_mpu_dmp_motion_driver.c; MPU-6000-Datasheet1.pdf; RM-MPU-6000A.pdf; MPU HW Offset Registers 1.0.pdf; Vectornav.pdf; MotionDriver_Tutorial_12212018 CB.pdf



erco

  • Member
  • *
  • e
  • Posts: 205
Re: Investigating the MPU 6050 DMP
« Reply #1 on: December 02, 2015, 07:46:11 PM »
Impressive presentation. More than I can absorb in the minute I have, but I hope to grasp it later. Welcome BaldwinK! Rebels, BaldwinK always raises the bar (IOW, an instigator). If you haven't seen his Tai Chi bot, you're in for a treat: His very thorough post is at http://www.picaxeforum.co.uk/showthread.php?27524-9g-Tai-Chi-Stepper  and his video at https://youtu.be/imq0HPXiQmM

 

* Search


* Recent Topics

The unnamed (yet) quatruped spider project by tinhead
[July 01, 2020, 04:22:11 PM]


"1984 Nixie Time" by 1 what
[May 08, 2020, 01:04:18 AM]


2D Side Scroller Cyberpunk themed by Killer Angel
[February 06, 2020, 06:39:40 AM]


A new wing design for model aircraft / drones by OddBot
[February 06, 2020, 04:42:06 AM]


SDR (Software Defined Radio) by Gareth
[February 02, 2020, 06:15:42 AM]


Circuit Math by ZeroMax
[January 31, 2020, 01:50:18 PM]


NanOMeter by Protowrxs
[January 01, 2020, 12:59:44 PM]


Investigating the VL53L0X Laser Rangefinder by erco
[December 30, 2019, 10:45:44 PM]


PS4 Single Handed Controller Deployed (part 7 of 7) by Gareth
[December 30, 2019, 09:52:29 AM]


"D" -Pad Workio just like Magic (Will Merlin stay or Go) (part 6 of 7) by Gareth
[December 30, 2019, 09:51:27 AM]


PS4 Joystick Digitals 4,5,6,7,10 - Analog's Lx,Ly,Rx,Ry Workio (part 5 of 7) by Gareth
[December 30, 2019, 09:50:37 AM]


Menu Workio ! (part 4 of 7) by Gareth
[December 30, 2019, 09:49:49 AM]


L1 trigger design Workio (Hori controller) (part 3 of 7) by Gareth
[December 30, 2019, 09:48:50 AM]


Hori aka PS4 Joystick Mappings (part 2 of 7) by Gareth
[December 30, 2019, 09:47:17 AM]


PS4 Single Left-Handed Controller (part 1 of 7) by Gareth
[December 30, 2019, 09:44:58 AM]

* Recent Posts

Re: The unnamed (yet) quatruped spider project by tinhead
[July 01, 2020, 04:22:11 PM]


Re: The unnamed (yet) quatruped spider project by jinx
[July 01, 2020, 04:06:19 PM]


Re: "1984 Nixie Time" by 1 what
[May 08, 2020, 01:04:18 AM]


Re: "1984 Nixie Time" by tomasp
[April 13, 2020, 06:03:28 PM]


Re: 2D Side Scroller Cyberpunk themed by Killer Angel
[February 06, 2020, 06:39:40 AM]


A new wing design for model aircraft / drones by OddBot
[February 06, 2020, 04:42:06 AM]


Re: "1984 Nixie Time" by Gareth
[February 02, 2020, 06:23:01 AM]


Re: SDR (Software Defined Radio) by Gareth
[February 02, 2020, 06:15:42 AM]


Re: SDR (Software Defined Radio) by ZeroMax
[January 31, 2020, 01:54:21 PM]


Re: "1984 Nixie Time" by ZeroMax
[January 31, 2020, 01:52:29 PM]


Circuit Math by ZeroMax
[January 31, 2020, 01:50:18 PM]


Re: 2D Side Scroller Cyberpunk themed by ZeroMax
[January 31, 2020, 01:45:33 PM]


NanOMeter by Protowrxs
[January 01, 2020, 12:59:44 PM]


Re: Investigating the VL53L0X Laser Rangefinder by erco
[December 30, 2019, 10:45:44 PM]


PS4 Single Handed Controller Deployed (part 7 of 7) by Gareth
[December 30, 2019, 09:52:29 AM]