Gyro_scale is wrong for MPU6050?

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
ovaltineo
Posts: 15
Joined: Sun Apr 28, 2013 11:41 pm

Gyro_scale is wrong for MPU6050?

Post by ovaltineo »

I'm trying to wrk out the gyro_scale for the L3G4200D and couldn't work out the value already defined for the MPU6050. It turns out that the comment maybe wrong. It is correct for the ITG3200 but should be different for the MPU6050 because according to the data sheets, the ITG3200 has 14.375 LSB/deg/s while the MPU6050 has 16.4. Am I missing something here?

timecop
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: Gyro_scale is wrong for MPU6050?

Post by timecop »

No, you're correct.
That's why in 32bit fork I return gyro scalefactor from each driver.
https://code.google.com/p/afrodevices/s ... 4200d.c#45
https://code.google.com/p/afrodevices/s ... 6050.c#193

brm
Posts: 287
Joined: Mon Jun 25, 2012 12:00 pm

Re: Gyro_scale is wrong for MPU6050?

Post by brm »

ovaltineo wrote:I'm trying to wrk out the gyro_scale for the L3G4200D and couldn't work out the value already defined for the MPU6050. It turns out that the comment maybe wrong. It is correct for the ITG3200 but should be different for the MPU6050 because according to the data sheets, the ITG3200 has 14.375 LSB/deg/s while the MPU6050 has 16.4. Am I missing something here?

sebbi made some suggestions moving towards an abstraction layer.
the way to go...

ovaltineo
Posts: 15
Joined: Sun Apr 28, 2013 11:41 pm

Re: Gyro_scale is wrong for MPU6050?

Post by ovaltineo »

Thanks, I thought i was going crazy. Ok, I can fix the gyro_scale, but in acro mode, gyro_scale is not even used. How do I scale it so that an L3G4200 will produce the same values as an ITG3200 if an accelerometer is not used?

felixrising
Posts: 244
Joined: Sat Mar 23, 2013 12:34 am
Location: Australia

Re: Gyro_scale is wrong for MPU6050?

Post by felixrising »

A HAL isn't really needed to fix this, just using the correct scale factors can't be that hard, and it would make people's PID values more consistent. Adding the correct scale factor for Gyro and Acc(!) under "Sensor Type definitions" for each sensor in def.h and updating IMU.ino would be the first steps in introducing some consistency here. No?

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Gyro_scale is wrong for MPU6050?

Post by Alexinparis »

you're right.
and I think it explains unexpected behavior in stable mode after multiple flips with MPU configs

and no HAL is needed to correct this ;)

only one line should be tuned for each gyro:
#define GYRO_SCALE ((2279 * PI)/((32767.0f / 4.0f ) * 180.0f * 1000000.0f)) //(ITG3200 and MPU6050)

ovaltineo
Posts: 15
Joined: Sun Apr 28, 2013 11:41 pm

Re: Gyro_scale is wrong for MPU6050?

Post by ovaltineo »

Alex, it's the comment in that line that threw me off. It says ITG3200 and MPU6050, instead of just ITG3200.

I would suggest that gyroADC be converted to radians/sec straight after reading from sensor. This way, all maths will give the same result regardless of which gyro or flight mode is used. This would require some change in a few places but it should give consistent results. The same way with accADC, it should be scaled straight after reading from sensor.

BTW, the z axis scale (256) in an ADXL345 is different from x and y axis (265) at 3.3 volts, so I would suggest a couple of acc scale constants.

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Gyro_scale is wrong for MPU6050?

Post by Plüschi »

Is this correct ?

#if defined(MPU6050)
#define GYRO_SCALE ((1998 * PI)/((32767.0f / 4.0f ) * 180.0f * 1000000.0f)) //(MPU6050)
#else
#define GYRO_SCALE ((2279 * PI)/((32767.0f / 4.0f ) * 180.0f * 1000000.0f)) //(ITG3200)
#endif

timecop
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: Gyro_scale is wrong for MPU6050?

Post by timecop »

To make sure every sensor has correct scalefactor, this should probably be enforced by each driver.

-ralf-
Posts: 215
Joined: Mon Dec 03, 2012 7:08 pm

Re: Gyro_scale is wrong for MPU6050?

Post by -ralf- »

Hello,

I've the Crius AIOP with MPU6050. What do I need to change in the sketch
to make the MPU6050 work proper?

Thanks

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Gyro_scale is wrong for MPU6050?

Post by Hamburger »

Use latest dev. It has the. Hanges you need.

-ralf-
Posts: 215
Joined: Mon Dec 03, 2012 7:08 pm

Re: Gyro_scale is wrong for MPU6050?

Post by -ralf- »

Hamburger wrote:Use latest dev. It has the. Hanges you need.


Thanks .... but two questions:

Is it necessary to clear the EEPROM before flashing the dev?
Can I use my config.h from 2.2Final?

Thanks

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Gyro_scale is wrong for MPU6050?

Post by Plüschi »

Since i lost my pid values many times i now do a "save" of the values in the multiwii.conf . You have to add the .mwi extension to the file name (doesent do it automatically) and it doesent save the mode switches, but it does save the numbers. When eeprom gets corrupted i do a "load", enter the switches again, then a "write".

Very useful feature :)

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Gyro_scale is wrong for MPU6050?

Post by Plüschi »

I did some tests with a crius_se (ITG3200) and an AIO V1 (MPU6050). The test consists of start level, do a looping over pitch, level again and quick check the pitch value in conf utility. Should be zero.
I confirm the value of 2380 working excellent for the ITG3200. But for the MPU6050 i found a value of 2020 working good. My code looks like this now:

#if defined(MPU6050)
#define GYRO_SCALE ((2020 * PI)/((32767.0f / 4.0f ) * 180.0f * 1000000.0f)) // MPU6050
#elif defined(ITG3200)
#define GYRO_SCALE ((2380 * PI)/((32767.0f / 4.0f ) * 180.0f * 1000000.0f)) // ITG3200
#else
#define GYRO_SCALE ((2279 * PI)/((32767.0f / 4.0f ) * 180.0f * 1000000.0f)) // dunno
#endif

Is this method correct or is there a systematical error?

-ralf-
Posts: 215
Joined: Mon Dec 03, 2012 7:08 pm

Re: Gyro_scale is wrong for MPU6050?

Post by -ralf- »

Hamburger wrote:Use latest dev. It has the. Hanges you need.


Sorry Hamburger,

but in Version 2.21 "#define Gyro_Scale...." is still the same (equal value for ITG and MPU) as in Version 2.20 ...

ovaltineo
Posts: 15
Joined: Sun Apr 28, 2013 11:41 pm

Re: Gyro_scale is wrong for MPU6050?

Post by ovaltineo »

Plüschi wrote:Is this correct ?

#if defined(MPU6050)
#define GYRO_SCALE ((1998 * PI)/((32767.0f / 4.0f ) * 180.0f * 1000000.0f)) //(MPU6050)
#else
#define GYRO_SCALE ((2279 * PI)/((32767.0f / 4.0f ) * 180.0f * 1000000.0f)) //(ITG3200)
#endif


That is correct, but I would have written it this way coz it's easier to match with the data sheet, and a compile error would alert the user that the GYRO_SCALE is not defined for the sensor:

#if defined(MPU6050)
#define GYRO_SCALE ((4.0f * PI)/(14.375 * 180.0f * 1000000.0f)) //(MPU6050)
#endif
#if defined(ITG3200)
#define GYRO_SCALE ((4.0f * PI)/(16.4 * 180.0f * 1000000.0f)) //(ITG3200)
#endif
#if defined(L3G4200D)
#define GYRO_SCALE ((4.0f * PI * 70.0f)/(1000.0f * 180.0f * 1000000.0f)) //(L3G4200D) this needs changes to Gyro_init and Gyro_getADC to set 2000dps and divide result by 4 instead of 20
#endif

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Gyro_scale is wrong for MPU6050?

Post by Hamburger »

-ralf- wrote:but in Version 2.21 "#define Gyro_Scale...." is still the same (equal value for ITG and MPU) as in Version 2.20 ...

I do not know version 2.21. It is included since dev version r1428.

ovaltineo
Posts: 15
Joined: Sun Apr 28, 2013 11:41 pm

Re: Gyro_scale is wrong for MPU6050?

Post by ovaltineo »

Where can we download the latest dev version? I can only see R1391 from the official download site. This would have saved me a lot of trouble.

ovaltineo
Posts: 15
Joined: Sun Apr 28, 2013 11:41 pm

Re: Gyro_scale is wrong for MPU6050?

Post by ovaltineo »

Never mind, found it under source tab.

scrat
Posts: 925
Joined: Mon Oct 15, 2012 9:47 am
Location: Slovenia

Re: Gyro_scale is wrong for MPU6050?

Post by scrat »

What does correction of Gyro scale - better stability or something else?

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Gyro_scale is wrong for MPU6050?

Post by Plüschi »

I still dont understand why for
ltg should be 16.4 but good results are with 17.12
mpu should be 14.375 but good results are with 14.54
Any ideas?

I did check the time, but ist correct, the time in-between samples is measured each cycle.

@scrat: if this factor is wrong the copter will not stay level right after a looping

ovaltineo
Posts: 15
Joined: Sun Apr 28, 2013 11:41 pm

Re: Gyro_scale is wrong for MPU6050?

Post by ovaltineo »

The data sheet figures are "typical" values at 2.5v VDD and 25 C temperature. Most IMUs are running at 3.3v and we don't all live in the Bahamas. Hence, real values are almost guaranteed to vary.

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: Gyro_scale is wrong for MPU6050?

Post by Plüschi »

TY

your a clever guy.

felixrising
Posts: 244
Joined: Sat Mar 23, 2013 12:34 am
Location: Australia

Re: Gyro_scale is wrong for MPU6050?

Post by felixrising »

If he could make his first quad actually fly, yes... but he can't :lol:

LenzGr
Posts: 166
Joined: Wed Nov 23, 2011 10:50 am
Location: Hamburg, Germany
Contact:

Re: Gyro_scale is wrong for MPU6050?

Post by LenzGr »

ovaltineo wrote:That is correct, but I would have written it this way coz it's easier to match with the data sheet, and a compile error would alert the user that the GYRO_SCALE is not defined for the sensor:

#if defined(MPU6050)
#define GYRO_SCALE ((4.0f * PI)/(14.375 * 180.0f * 1000000.0f)) //(MPU6050)
#endif
#if defined(ITG3200)
#define GYRO_SCALE ((4.0f * PI)/(16.4 * 180.0f * 1000000.0f)) //(ITG3200)
#endif
#if defined(L3G4200D)
#define GYRO_SCALE ((4.0f * PI * 70.0f)/(1000.0f * 180.0f * 1000000.0f)) //(L3G4200D) this needs changes to Gyro_init and Gyro_getADC to set 2000dps and divide result by 4 instead of 20
#endif

Call me confused, but is the current code in _shared actually correct then? Or have the scaling factors between ITG3200 and MPU6050 been mixed up?

Code: Select all

#if defined(ITG3200)
  #define GYRO_SCALE (4 / 14.375 * PI / 180.0 / 1000000.0) //ITG3200   14.375 LSB/(deg/s) and we ignore the last 2 bits
#endif
#if defined(L3G4200D)
  #define GYRO_SCALE ((4.0f * PI * 70.0f)/(1000.0f * 180.0f * 1000000.0f))
#endif
#if defined(MPU6050)
  #define GYRO_SCALE (4 / 16.4 * PI / 180.0 / 1000000.0)   //MPU6050 and MPU3050   16.4 LSB/(deg/s) and we ignore the last 2 bits
#endif

felixrising
Posts: 244
Joined: Sat Mar 23, 2013 12:34 am
Location: Australia

Re: Gyro_scale is wrong for MPU6050?

Post by felixrising »

It was fixed in _shared on commit r1428 https://code.google.com/p/multiwii/source/detail?r=1428 with addition updates to L3G4200D in r1435 and 1439

LenzGr
Posts: 166
Joined: Wed Nov 23, 2011 10:50 am
Location: Hamburg, Germany
Contact:

Re: Gyro_scale is wrong for MPU6050?

Post by LenzGr »

OK, thanks. So the values in _shared are correct, and the ones posted by ovaltineo earlier in this thread were the other way around (and wrong?)

ovaltineo
Posts: 15
Joined: Sun Apr 28, 2013 11:41 pm

Re: Gyro_scale is wrong for MPU6050?

Post by ovaltineo »

Yes, I got them mixed up.

User avatar
linuxslate
Posts: 91
Joined: Mon May 13, 2013 3:55 pm

Re: Gyro_scale is wrong for MPU6050?

Post by linuxslate »

See this post for my quick and dirty backport for the "release" 2.2:

viewtopic.php?f=8&t=1591&start=20#p36799

User avatar
linuxslate
Posts: 91
Joined: Mon May 13, 2013 3:55 pm

Re: Gyro_scale is wrong for MPU6050?

Post by linuxslate »

See this post for my quick and dirty backport for the "release" 2.2:

viewtopic.php?f=8&t=1591&start=20#p36799

(and tell me if anything is wrong with doing that)

User avatar
linuxslate
Posts: 91
Joined: Mon May 13, 2013 3:55 pm

Re: Gyro_scale is wrong for MPU6050?

Post by linuxslate »

Sorry about the double post above, but I also have another MPU6050 possible issue/question:

The MPU6050 has both the ACCEL and the GYRO right? (Crius All in one pro V1)

Does GYRO_SCALE also affect the ACC scale?

Where is the code that sets the ACC gain? Specifically, the individual X,Y, and Z gains?

I still feel that my Z-axis accel is too sensitive.

Shaking the copter randomly and equally in 3 dimensions always produces a larger response in Z.

Also, prop vibrations show up more in the Z axis than in X or Y (Which are IMHO incorrectly marked as ROLL and PITCH in MultiWiiConf. GYRO is ROLL and PITCH, but ACC should be X and Y). Logically, one would expect a prop imbalance (in a Quad) to create significantly more X,Y vibrations, while only showing up a bit in Z.

This is causing prop vibrations to result in vertical surging, while ROLL and PITCH are solid as a rock.

I can get rid of the vertical surging by either balancing my props more carefully, or using more Low pass filter (Lower cut off value), but I think a better fix would be to reduce the influence of the Z axis accel.

I'd like to try reducing my ACC (Not GYRO) gains individually, but I do not know where in the code to do this.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Gyro_scale is wrong for MPU6050?

Post by Alexinparis »

linuxslate wrote:The MPU6050 has both the ACCEL and the GYRO right? (Crius All in one pro V1)

yes


Does GYRO_SCALE also affect the ACC scale?

no

Where is the code that sets the ACC gain? Specifically, the individual X,Y, and Z gains?

in IMU.ino
there is no individual X/Y/Z setting

Shaking the copter randomly and equally in 3 dimensions always produces a larger response in Z.

that should not be the case

Also, prop vibrations show up more in the Z axis than in X or Y (Which are IMHO incorrectly marked as ROLL and PITCH in MultiWiiConf. GYRO is ROLL and PITCH, but ACC should be X and Y). Logically, one would expect a prop imbalance (in a Quad) to create significantly more X,Y vibrations, while only showing up a bit in Z.

I think the effect of unbalanced motors or propellers is hard to predict.
The frequency is high, and frame resonance effects could lead to other axis perturbation.

scrat
Posts: 925
Joined: Mon Oct 15, 2012 9:47 am
Location: Slovenia

Re: Gyro_scale is wrong for MPU6050?

Post by scrat »

@Alexinparis:

I have mwii v2.2 and I have set in EEPROM.ino for stick scalling: 2*...code below.

for(i=0;i<6;i++) {
lookupPitchRollRC[i] = 2* (2500+conf.rcExpo8*(i*i-25))*i*(int32_t)conf.rcRate8/2500;

I know there is fix for gyro scale in new dev code. With gyro scale fixed, can I still set 2* for better stick response?

Thanks!

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Gyro_scale is wrong for MPU6050?

Post by Alexinparis »

scrat wrote:@Alexinparis:

I have mwii v2.2 and I have set in EEPROM.ino for stick scalling: 2*...code below.

for(i=0;i<6;i++) {
lookupPitchRollRC[i] = 2* (2500+conf.rcExpo8*(i*i-25))*i*(int32_t)conf.rcRate8/2500;

I know there is fix for gyro scale in new dev code. With gyro scale fixed, can I still set 2* for better stick response?

Thanks!


this tweak still works and is independent with gyro scale.
you can also raise your rc rate

scrat
Posts: 925
Joined: Mon Oct 15, 2012 9:47 am
Location: Slovenia

Re: Gyro_scale is wrong for MPU6050?

Post by scrat »

Thanks.

I'm using this tweak and rc rate set to 1.50 since I bought AIO pro. Because I'm used to have more response from quad.

Shanthosh Ravikumar
Posts: 1
Joined: Wed Dec 11, 2013 8:09 pm

Re: Gyro_scale is wrong for MPU6050?

Post by Shanthosh Ravikumar »

hey all !!
I am new to this forum and a first time user of Multiwii ( Nanowii)
and i am having an error when i compile the firmware in arduino..
the error is shown like this
"IMU.cpp: In function 'void getEstimatedAttitude()':
IMU.cpp:189: error: 'GYRO_SCALE' was not declared in this scope "

I have no idea about this error ... and I dont know how to correct this
can anyone please help me ???

Thanks in advance :)

User avatar
err888
Posts: 16
Joined: Mon Jul 22, 2013 9:31 am

Re: Gyro_scale is wrong for MPU6050?

Post by err888 »

Shanthosh Ravikumar wrote:hey all !!
I am new to this forum and a first time user of Multiwii ( Nanowii)
and i am having an error when i compile the firmware in arduino..
the error is shown like this
"IMU.cpp: In function 'void getEstimatedAttitude()':
IMU.cpp:189: error: 'GYRO_SCALE' was not declared in this scope "

I have no idea about this error ... and I dont know how to correct this
can anyone please help me ???

Thanks in advance :)

Have you uncommented a specific board type or independent sensors in config.h, and which ones have you uncommented?

Kenny

Post Reply