Page 1 of 1

Gyro_scale is wrong for MPU6050?

Posted: Mon Apr 29, 2013 12:01 am
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?

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon Apr 29, 2013 4:53 am
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

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon Apr 29, 2013 6:48 am
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...

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon Apr 29, 2013 9:10 am
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?

Re: Gyro_scale is wrong for MPU6050?

Posted: Tue Apr 30, 2013 6:57 am
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?

Re: Gyro_scale is wrong for MPU6050?

Posted: Wed May 01, 2013 11:09 pm
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)

Re: Gyro_scale is wrong for MPU6050?

Posted: Fri May 03, 2013 11:05 pm
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.

Re: Gyro_scale is wrong for MPU6050?

Posted: Sun May 05, 2013 8:18 am
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

Re: Gyro_scale is wrong for MPU6050?

Posted: Sun May 05, 2013 8:30 am
by timecop
To make sure every sensor has correct scalefactor, this should probably be enforced by each driver.

Re: Gyro_scale is wrong for MPU6050?

Posted: Sun May 05, 2013 1:44 pm
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

Re: Gyro_scale is wrong for MPU6050?

Posted: Sun May 05, 2013 1:47 pm
by Hamburger
Use latest dev. It has the. Hanges you need.

Re: Gyro_scale is wrong for MPU6050?

Posted: Sun May 05, 2013 4:08 pm
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

Re: Gyro_scale is wrong for MPU6050?

Posted: Sun May 05, 2013 4:33 pm
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 :)

Re: Gyro_scale is wrong for MPU6050?

Posted: Sun May 05, 2013 6:48 pm
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?

Re: Gyro_scale is wrong for MPU6050?

Posted: Sun May 05, 2013 7:11 pm
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 ...

Re: Gyro_scale is wrong for MPU6050?

Posted: Sun May 05, 2013 11:50 pm
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

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon May 06, 2013 8:42 am
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.

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon May 06, 2013 9:32 am
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.

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon May 06, 2013 9:37 am
by ovaltineo
Never mind, found it under source tab.

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon May 06, 2013 12:55 pm
by scrat
What does correction of Gyro scale - better stability or something else?

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon May 06, 2013 3:10 pm
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

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon May 06, 2013 11:43 pm
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.

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon May 06, 2013 11:54 pm
by Plüschi
TY

your a clever guy.

Re: Gyro_scale is wrong for MPU6050?

Posted: Tue May 07, 2013 8:39 am
by felixrising
If he could make his first quad actually fly, yes... but he can't :lol:

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon May 20, 2013 12:22 am
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

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon May 20, 2013 4:20 am
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

Re: Gyro_scale is wrong for MPU6050?

Posted: Mon May 20, 2013 3:34 pm
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?)

Re: Gyro_scale is wrong for MPU6050?

Posted: Wed May 29, 2013 12:18 am
by ovaltineo
Yes, I got them mixed up.

Re: Gyro_scale is wrong for MPU6050?

Posted: Fri May 31, 2013 5:42 pm
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

Re: Gyro_scale is wrong for MPU6050?

Posted: Fri May 31, 2013 5:42 pm
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)

Re: Gyro_scale is wrong for MPU6050?

Posted: Fri May 31, 2013 6:03 pm
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.

Re: Gyro_scale is wrong for MPU6050?

Posted: Sun Jun 02, 2013 6:29 pm
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.

Re: Gyro_scale is wrong for MPU6050?

Posted: Tue Jun 11, 2013 10:50 am
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!

Re: Gyro_scale is wrong for MPU6050?

Posted: Thu Jun 13, 2013 10:14 pm
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

Re: Gyro_scale is wrong for MPU6050?

Posted: Fri Jun 14, 2013 10:56 am
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.

Re: Gyro_scale is wrong for MPU6050?

Posted: Thu Dec 12, 2013 4:58 pm
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 :)

Re: Gyro_scale is wrong for MPU6050?

Posted: Fri Dec 13, 2013 11:20 am
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