Author Topic: MPU6050 DMP6 Coding Function  (Read 8956 times)

0 Members and 1 Guest are viewing this topic.

Offline alberttanTopic starter

  • Newbie
  • Posts: 5
  • Country: my
MPU6050 DMP6 Coding Function
« on: April 15, 2016, 03:11:20 pm »
Hi, I am using Arduino UNO and a MPU6050, the purpose of the project is to use the sensor to sense the yaw pitch roll movement of an object, so I am now running the code of MPU6050 dmp6, which can give me quaternion value, euler angles and also yaw pitch roll.
How can I check if the values are correct for all those 3 data obtained. If there any calculation method to prove that the data obtained is accurate?

Here is some the examples of my data obtained from the sensor:
Quaternion: [0.85, 0.51, 0.03, 0.10]
Euler angle: [-7.90, -8.70, -61.73]
YPR: [-7.88, 2.80, 61.60]

How can we actually find the offsets values of the MPU6050 to run the code for dmp6.
I am running the dmp6 code from Jeff Rowberg.

Your answer is appreciated, thank you so much
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: MPU6050 DMP6 Coding Function
« Reply #1 on: April 15, 2016, 03:43:35 pm »
Hi, I am using Arduino UNO and a MPU6050, the purpose of the project is to use the sensor to sense the yaw pitch roll movement of an object, so I am now running the code of MPU6050 dmp6, which can give me quaternion value, euler angles and also yaw pitch roll.
How can I check if the values are correct for all those 3 data obtained. If there any calculation method to prove that the data obtained is accurate?

What exactly are you after? You can display a 3D object that rotates bases on your quaternion values (ignore the Euler angle and YPR for that purpose, they have singularities that would throw you off). That should give you an idea whether or not the quaternion is correct - the object should rotate when you rotate your board.

If you want to verify the absolute accuracy, then you will need to build a (non-metallic) jig with protractors or some other method of measuring angles (e.g. encoders) and compare the output against a hand-calculated quaternion that you get from that.

The Euler angles and YPR values (yaw-pitch-roll - another form of Euler angles) are calculated from the quaternion, so it doesn't make much sense to compare against them (unless you want to check that calculation).

How can we actually find the offsets values of the MPU6050 to run the code for dmp6.
I am running the dmp6 code from Jeff Rowberg.

Your answer is appreciated, thank you so much

What offsets do you have in mind? The gyro, accelerometer and magnetometer calibration data? That has to be determined at runtime, actually. Accelerometer and gyro offsets are measured when the device is not moving (usually on power up) and the magnetometer must be calibrated first. The exact procedure depends on the code you are using.

You mean these lines?

Code: [Select]
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
mpu.setZAccelOffset(1788); // 1688 factory default for my test chip

Use the "raw" example and print those values out when the device is not moving.
Then put them in the other sketch. However, this is something you should ideally be doing automatically whenever the device is powered up - the offsets change with temperature, voltage, etc.



« Last Edit: April 15, 2016, 03:49:46 pm by janoc »
 
The following users thanked this post: alberttan

Offline alberttanTopic starter

  • Newbie
  • Posts: 5
  • Country: my
Re: MPU6050 DMP6 Coding Function
« Reply #2 on: April 15, 2016, 04:58:02 pm »
Hi, thank you for the reply. I am not sure if there is some mistakes I have made when running the MPU6050 raw code, because I get some weird display which the screen keeps running to the right, is there anyone can provide me a mpu6050 raw data code? All my codes are from Jeff Rowberg. Thanks.

So, how exactly I can check if the dmp6 coding is running properly? Is it just consider about the movement of the sensor? What if the sensor was in horizontal and it rotates towards the right,at 90degrees.
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: MPU6050 DMP6 Coding Function
« Reply #3 on: April 15, 2016, 09:20:10 pm »
Hi, thank you for the reply. I am not sure if there is some mistakes I have made when running the MPU6050 raw code, because I get some weird display which the screen keeps running to the right, is there anyone can provide me a mpu6050 raw data code? All my codes are from Jeff Rowberg. Thanks.

I am not using that code myself, my IMU is MPU9250 which is similar to your MPU6050, but has a built-in magnetometer too. Moreover, I have the thing running on an ARM mcu anyhow, so my data wouldn't help you much.

Can't speak much about the Jeff Rowberg's code, but from what I have seen that code is good only as an example how to make the thing work. Without the calibration functionality it is going to be useless in practice - the sensor fusion gives unusable values unless the accelerometer and gyro offsets and the magnetometer extents are calibrated.

So, how exactly I can check if the dmp6 coding is running properly? Is it just consider about the movement of the sensor? What if the sensor was in horizontal and it rotates towards the right,at 90degrees.

The numbers alone are not very useful - you could potentially calculate the quaternion yourself if you know the orientation of the device and refer to the coordinate system for each of your sensors (=> datasheet!). Then you would have to do the fusion by hand. However, as you are using the DMP, the result may still differ, because you don't know which exact algorithm is the DMP engine using.

You need an application like this:


Then you will see whether the rotation of your device matches the rotation of the object on the screen. It is by far the most obvious way how to see whether or not the device performs well. Any noise, drift or other issues will be readily visible. The video actually shows how to run the demo app in Jeff Rowberg's code you are using.



« Last Edit: April 15, 2016, 09:28:12 pm by janoc »
 
The following users thanked this post: alberttan

Offline alberttanTopic starter

  • Newbie
  • Posts: 5
  • Country: my
Re: MPU6050 DMP6 Coding Function
« Reply #4 on: April 16, 2016, 06:25:27 am »
Hi, thanks for the reply, so is there anyone knows what is the function of the code dmp6? Can it measure the movement of an object by yaw pitch roll? How can I actually calibrate the offsets values? Using which code to calibrate the offsets values? Thanks yah.
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: MPU6050 DMP6 Coding Function
« Reply #5 on: April 16, 2016, 08:29:58 pm »
Hi, thanks for the reply, so is there anyone knows what is the function of the code dmp6? Can it measure the movement of an object by yaw pitch roll? How can I actually calibrate the offsets values? Using which code to calibrate the offsets values? Thanks yah.

Have you actually looked at the code you are using? The YPR values in your first message correspond to yaw,pitch,roll (in this order) in degrees.

If you google a bit, you will find this description of the basic calibration procedure:
http://www.i2cdevlib.com/forums/topic/91-how-to-decide-gyro-and-accelerometer-offsett/

That uses the "raw" application from Jeff's github:
https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050/examples





 

Offline cgroen

  • Supporter
  • ****
  • Posts: 631
  • Country: dk
    • Carstens personal web
Re: MPU6050 DMP6 Coding Function
« Reply #6 on: April 17, 2016, 03:56:39 pm »
I know this is not what you asked, but I will answer anyway :D
I have used the MPU9150 (similar to 6050) and to be honest, I gave up! The hazzle with downloading the dmp code to the device and the workings of the algorithm didn't suit me very well.
So I began looking at the Bosch BNO055 sensor which is so much easier to use! It will directly give you euler (roll, pitch and yaw) and quaterions etc without uploading any code to the device (and a huge library running on your host cpu!)

Currently I have it a number of projects with this sensor, one of them a "pitch/roll" compensated LIDAR device (picture below)

 

Offline alberttanTopic starter

  • Newbie
  • Posts: 5
  • Country: my
Re: MPU6050 DMP6 Coding Function
« Reply #7 on: April 17, 2016, 05:35:20 pm »
Hi, thanks for the reply anyway, actually my project purpose is to measure the movement of an object, then once I know the movement of the object, I wish to create an opposite force on it, by using Arduino Uno and also a motor with varying speed, in order to compensate that movement, so what can I use from the mpu6050 for my project? Anyone with suggestions? Your reply is much appreciated. Thanks

Note: Is there any other codes which I can get the values of yaw pitch roll from the mpu6050? Which is other than the dmp6 code? Thanks.
« Last Edit: April 17, 2016, 06:28:38 pm by alberttan »
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: MPU6050 DMP6 Coding Function
« Reply #8 on: April 17, 2016, 07:31:06 pm »
I believe you need to actually start doing some research. Google is your friend. I feel that you don't really know much about the subject of what you want to achieve. We can't do the entire problem analysis for you.

First, MPU-6050 is an accelerometer and a gyroscope in one package. So you can use any sensor fusion algorithm you want (Kalman filter, complementary filter, Extended Kalman filter, cosine matrix ...), you don't have to use the DMP code from Invensense. There are plenty of examples for this line of chips online, including e.g. the complete Oculus Rift tracker which used MPU-6050 and an external Honeywell magnetometer.

Second, you don't seem to realize that in order to have yaw, you will need an external magnetometer or some other way of compensating the gyroscope drift in yaw (e.g. a camera or some optical sensor). MPU-6050 alone will not do it because it lacks the sensor, so you will always have drift in yaw. The later MPU-9150 and MPU-9250 integrate a magnetometer as well, with the latter being a bit better. The Bosch device mentioned does as well.

Third, "creating opposite force" - I am not sure what you mean, really. These chips allow you to measure orientation in space and related quantities (angular velocity/acceleration) and possibly linear acceleration. That may or may not be enough to do what you want - but without knowing more about your project it is impossible to help you. These parts have been used for self-balancing robots, so at least something similar is possible. Again, Google is you friend.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf