jrowberg / i2cdevlib

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

Custom define MPU6050 DMP setting is important in the MPU6050_6Axis_MotionApps_V6_12 #591

Open williamesp2015 opened 2 years ago

williamesp2015 commented 2 years ago

In dmpInitialize() function the Accelerometer scale is fixed in 2g and gyro in 2000 dpm. Is anyone made an effort to customize the Acc and gyro sampling rate and scale and Low pass filter?

eadf commented 2 years ago

I could have sworn I made an experiment with template specializations that solved that problem (some 5+ years ago) But I can't find the source anymore. Maybe the idea is still valid?

Edit: This solution is, ofc, no good if we don't know what bits in the DMP to alter in the first place

ZHomeSlice commented 2 years ago

So This is the reason the rates are where they are at:

Refference: Motion Driver 6.12 – Features User Guide Document Number: AN-EMAPPS-0.0.6 Revision: 1.1 Release Date: 05/05/2015 Page 4 Reads:

4 The DMP features The DMP is a fast, low power, programmable, embedded lightweight processor in the MPU devices. It is design to offload functionality, like sensor fusion and gesture recognition, from the MCU to save overall power in the system. The DMP has many features which can be dynamically turned off and on at run-time. Individual feature can also be disabled while leaving others running. All DMP data is outputted to the FIFO except for pedometer. The DMP can also be programmed to generate an interrupt via gesture or if data ready. For details on flashing and enabling the DMP please read the porting guide.

 3 Axis Low Power Quaternions – ...... not used here

 6 Axis Low Power Quaternions – gyro and accel quaternions. Similar to the 3-axis LPQ, integrates the accel and gyro at 200Hz sampling rates will outputting to the FIFO at the user requested rates. The 3-axis LPQ and 6-axis LPQ are mutually exclusive and should not be run concurrently. If enabled the 6-axis quaternions can be pushed into the MPL library and the MPL will handle the compass integration for 9-axis.

DMP is the pre-compiled proprietary code that is embedded into the MPU it has minimal configuration options that mostly turn on and off features. Something more interesting is the MPL library another proprietary pre-compiled library that I haven't gotten to work with the Arduino IDE :) but that's for another discussion.

Download location https://invensense.tdk.com/developers/ you will need an account to get to the downloads look for "eMD 6.12"

Z

williamesp2015 commented 2 years ago

Dear @ZHomeSlice you haven't respond to the issue regarding custom Acc and Gyro measurement range not fixed 2g and 2000 Degree/sec.

ZHomeSlice commented 2 years ago

oops. :) This is not an easy task to remember where I looked to find all the settings to make this work correctly. I did a major revamp of the library startup to get here.

you will need to find this document to get all the details on starting up DMP Application Note Programming Sequence for DMP Hardware Functions Document Number: AN-MAPPS-x.x.x Revision: 0.1 Release Date: 11/28/2012

This document is likely found with a google search. go to page 35 of 44 you will see the "7 MPU Setup for Enabling Advanced Hardware Features"

7 MPU Setup for Enabling Advanced Hardware Features
Please set up the MPU as shown below before using the advanced hardware features.

7.1 Configure Power Management Registers
 Write 0x00 to PWR_MGMT_1 (0x6B).
 Write 0x00 to PWR_MGMT_2 (0x6C).
Note: This is also the hardware reset value for these registers.

7.2 Configure Gyroscope Parameters
 Write 0x03 to CONFIG (0x1A).
 Write 0x18 to GYRO_CONFIG (0x1B).
Sets the cut-off frequency of the Digital Low-Pass Frequency (DLPF) filter to 42Hz.
Sets the Full Scale Range (FSR) of the gyroscope to 2000dps.

7.3 Configure Accelerometer Parameters
 Write 0x00 to ACCEL_CONFIG (0x1C)
Sets the Accelerometer FSR to 2g.

7.4 Configure FIFO and Interrupts
 Write 0x00 to FIFO_EN (0x23).
 Write 0x00 to INT_ENABLE (0x38).
Defers control of the FIFO and the interrupts from the MPU to the DMP.

7.5 Reset the FIFO
 Write 0x04 to USER_CTRL (0x6A)

7.6 Configure Sensor Sample Rate
 Write 0x04 to SMPLRT_DIV (0x19)
Sets sample rate to 200Hz.

7.7 Load DMP Firmware
The DMP firmware is a few kbytes in size. The exact size depends on the particular hardware feature set.

7.7.1 Load Firmware One Byte at a Time
Starting from the byte[0] of data of the firmware image, perform the following for each byte[N] of data:
 Write the value (N >> 8) to DMP_CTRL_1 (0x6D)
 Write the value (N & 0xFF) to DMP_CTRL_2 (0x6E)
 Write the Nth byte of data to DMP_CTRL_3 (0x6F)
Repeat the steps above for each byte of the DMP firmware image.

7.7.2 (Deleted not used in the MPU6050 Library)

7.7.3 Load Firmware Start Value
Please perform the following once the DMP firmware has been loaded.
 Write the 2 byte Firmware Start Value to FW_START (0x70 & 0x71)
The Firmware Start Value is provided by InvenSense. If you do not have this value, please contact your field representative.

This is an older document meant for an earlier version than DMP 6.12 use the DMP 6.12 documentation to adjust registers and starting values to match...

Play at your own risk :)

Z

P.S. Please report back as to what improvements you discover

wrickout commented 1 month ago

DMP sensor fusion works only with gyro at +-2000dps and accel +-2G