Gyro calibration (zeroing), movement detection

Post Reply
User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Gyro calibration (zeroing), movement detection

Post by alll »

Hi,

I have had weird behaviors when starting motors after power up the copter.
So if i hold the copter upsidedown and move it while powering the board, arm and start, sometimes, not all motors start at the same time. If after power up, i do a gyro cal. all is smooth! So, for now i always do a manual gyro calibration.

So, could we not always do a gyro zeroing on power up (automatic gyro cal.), as long as "movement" is detected, redo a gyro calibration (zeroing).

manu

User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Re: Gyro calibration (zeroing), movement detection

Post by alll »

So, i came up with this: Goal, when board is powered up, and the board moves, continue trying to find gyro zero's (gyro calibration)

Alex, or some other developer, can you tell me if this could be written using less variables. Is the the right place to do it?

manu

In void setup() at line

Code: Select all

//  calibratingG = 400;


i replaced with :

Code: Select all

  int16_t movement1[3]={10,10,10};
  uint8_t movement=10;
  while (movement>0) {
    calibratingG = 400;
    while (calibratingG>0)computeIMU();
    movement1[ROLL]=gyroZero[ROLL];
    movement1[PITCH]=gyroZero[PITCH];
    movement1[YAW]=gyroZero[YAW];
    calibratingG = 400;
    while (calibratingG>0)computeIMU();
    movement=abs(movement1[ROLL]-gyroZero[ROLL])+abs(movement1[PITCH]-gyroZero[PITCH])+abs(movement1[YAW]-gyroZero[YAW]);
  }

Mis
Posts: 203
Joined: Fri Apr 01, 2011 12:23 am

Re: Gyro calibration (zeroing), movement detection

Post by Mis »

Check leatest DEV version.

Code: Select all

 /************************        continuous gyro calibration        ********************/
  /* Gyrocalibration will be repeated if copter is moving during calibration. */
    //#define GYROCALIBRATIONFAILSAFE

If you uncomment this line you get effect exactly as you want.
Calibration is restarted until the board stop moving.

User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Re: Gyro calibration (zeroing), movement detection

Post by alll »

Good! But i can't imagine doing a gyro zero calibration without this movement check! Why is it not enabled by default ?
Thanksmanu

doughboy
Posts: 252
Joined: Tue Sep 04, 2012 7:20 am

Re: Gyro calibration (zeroing), movement detection

Post by doughboy »

alll wrote:Good! But i can't imagine doing a gyro zero calibration without this movement check! Why is it not enabled by default ?
Thanksmanu


I agree.
why it is not enabled? people with check in priviledge is turning mw source into their own personal source code. just look at trunk/multiwii, someone checked in his personal config.h. imho, there should be some kind of code review process before check in.

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

Re: Gyro calibration (zeroing), movement detection

Post by Hamburger »

We do peer reviews after checkin :)

User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Re: Gyro calibration (zeroing), movement detection

Post by alll »

i don't find GYROCALIBRATIONFAILSAFE in v2.1 ?

doughboy
Posts: 252
Joined: Tue Sep 04, 2012 7:20 am

Re: Gyro calibration (zeroing), movement detection

Post by doughboy »


User avatar
jevermeister
Posts: 708
Joined: Wed Jul 20, 2011 8:56 am
Contact:

Re: Gyro calibration (zeroing), movement detection

Post by jevermeister »

we had this discussion weeks ago. gyro calibration is influenced by temperature. so automatic repeat can lead to an unflyable copter. especially if you can arm it while it is still trying to calibrate.

Imho everybody should manually calibrate the gyro after powering up anyway. No toy!

User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Re: Gyro calibration (zeroing), movement detection

Post by alll »

No!
The code i posted is called only in setup, and only on power up as long as you don't keep the copter still, it loops calibrating.

I fly like this now and this is the way it should be imho. You can still calibrate via sticks after if you want.

manu

User avatar
jevermeister
Posts: 708
Joined: Wed Jul 20, 2011 8:56 am
Contact:

Re: Gyro calibration (zeroing), movement detection

Post by jevermeister »

Heard that.

But what if the gyro won't stop restarting calibration because of temp drift?I experienced that the last time I tested this. I' d rather fly with a not proper centered gyro than with a gyro that tries to calibrate over and over again.

This topic has been discussed three times in multiwii and two times at shreddiquette. Everytime we came to the same conclusion: Not neccesary and has to be overrideable in case of temp drift.
This function is called "moron mode" in certain other projects for a reason. *wink at tc*

I think it is good to be disabled by default.Everyone who is unable to find,change and compile it should not fly a copter. everyone else may enable it.

by the way: I only follow arguments given to me regarding vbat, inflight acc etc. enable as less as possible per default and make the user have to change config.h to get a flying copter.
Nils

User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Re: Gyro calibration (zeroing), movement detection

Post by alll »

Again, the way i do the calibration (movement detection) is to do 2 calibrations after each other, compare, if == it means no movement and the gyroZero's are correct! Even if temperature affects gyro, it should settle at a certain point, and the 2 calibrations will be identical.
Am i missing something here?
Where can i read about the discussion you had before, to better understand your point.
Thanks,
manu

Mis
Posts: 203
Joined: Fri Apr 01, 2011 12:23 am

Re: Gyro calibration (zeroing), movement detection

Post by Mis »

I commit this feature some times ago as mandatory. But someone change it to an option, and turn off by default. Why ? I don't know.
In my opinion the argument about themperature drift is irrational. It is not possible to quickly change the temperature so that no calibration to be performed.
And this is not "moron mode", if you have battery conector at bottom of copter can't power up the copter without shaking it.
But jevermeister is guru and knows better.

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

Re: Gyro calibration (zeroing), movement detection

Post by timecop »

It is moron mode, because people repeatedly have plugged stuff in while shaking the copter, have SEEN non-zero offsets on gyros, and STILL continue attempting to take off after that, resulting in flips/crashes/wahtever.

The wiki/faq/whatever clearly says gyro MUST be calibrated after each power up by stick combo before flight.

NOONE reads this.

User avatar
jevermeister
Posts: 708
Joined: Wed Jul 20, 2011 8:56 am
Contact:

Re: Gyro calibration (zeroing), movement detection

Post by jevermeister »

Who said I am guru?I gave a technical explanation why I am againat rhat everytime I stared my point. What more do you expext?
That "someone" who changed the geature to an option was me - I even explained why. FYI: You can see who changed the code in SVN.

If you do not like it, then change it but provide an explanation for that. Dude, even failsafe isn't mandatory.Those people start their copters without even knowing what they to on a connectoon lost. My only intention was to make flying saver. But go on and change it - I don't care anymore.

nils

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

Re: Gyro calibration (zeroing), movement detection

Post by scrat »

So it is not good to uncomment gyrocalibrationfailsafe?

User avatar
jevermeister
Posts: 708
Joined: Wed Jul 20, 2011 8:56 am
Contact:

Re: Gyro calibration (zeroing), movement detection

Post by jevermeister »

hi,
scrat you can try to uncomment it and see if it works for you.if not then you can comment it again. that was the whole intention.

By disabling it default I wanted to prevent the idiots that do not read the manual from killing their copter by arming, or getting nts because the copter is unable to arm.

the function is still there. I don't see a problem with that.
it is alex policy to disable most of the features by default.
see infligt calibration,failsafe,vbat,motorstop. all are important featurea that are diaqbled by default and noones has a problem with simply enabling them.

guru

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

Re: Gyro calibration (zeroing), movement detection

Post by scrat »

I just ask because I have uncommented this feature and it works for me.
I have tested it and if I move copter when powering it gyrocalibration goes on and on. When I stop moving the copter gyrocal stops and copter flyes very well.

And I'm using define motor_stop too :)

User avatar
jevermeister
Posts: 708
Joined: Wed Jul 20, 2011 8:56 am
Contact:

Re: Gyro calibration (zeroing), movement detection

Post by jevermeister »

Hi, I am happy that it works for you. I had several problems with functions like this when I moved gyros from warm inside or car to cold outside. I tried that with a whole selection of gyros. This is the reason why I am against a default activation - I stated this countless times before btw.

scrat: thanks for that feedback.

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

Re: Gyro calibration (zeroing), movement detection

Post by scrat »

But I always leave my quad outside in winter for about 20 minutes before connecting battery. I wait for gyros to settle in cold weather.

User avatar
jevermeister
Posts: 708
Joined: Wed Jul 20, 2011 8:56 am
Contact:

Re: Gyro calibration (zeroing), movement detection

Post by jevermeister »

scrat wrote:But I always leave my quad outside in winter for about 20 minutes before connecting battery. I wait for gyros to settle in cold weather.

that is a correct behavior especcially for the battery and the cpu but I do not have time for that every time I fly.

Nils

nicog
Posts: 88
Joined: Tue Aug 21, 2012 2:21 pm

Re: Gyro calibration (zeroing), movement detection

Post by nicog »

Hmmm, I'm not so sure, waiting and leaving the batery to cool down to below freeze level will just make things bad. Lipos don't like the cold (there is some alcohol inside) and make the electrolyte to densify. This leads to a less responsive batery in terms of electric power.

And as everybody knows, batery gets warm on use, wich is normal. So from all of my testing (flew a lot last year and filmed ice climbing) best thing is keep the bat inside the jacket to keep it warm, then plug it when ready (yes you can leave the MR outside in the cold) and fly. Flight time is much similar to summer time this way.

User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Re: Gyro calibration (zeroing), movement detection

Post by alll »

The way you do the calibration is different from mine!
If I get it correct, you check every 10 samples (out of the 400) the difference of current gyroADC with previousgyroADC(10 samples before) for the 3 axis. If there is a difference you reset calibrating=1000 (not 400?) to start over.
(by the way the line after #if defined(GYROCALIBRATIONFAILSAFE) “previousGyroADC[axis] = gyroADC[axis];” should not be there…)
Why if tilt==1 you set calibratingG =1000 and not 400?

My implementation of “movement detection” just compares 2 successive 400 sample calibrations = comparing 2 averages.

So your statement to never get out this loop (not able to arm) because of temperature is maybe true for your implementation, but is less with my implementation.

And the way it is implemented in v2.1, is more dangerous for us “noops, Mormons, idiots”. Let the code help those Mormons that don’t have a clue what they are doing…

PS:
“Who said I am guru?” : Just the fact you mentioned TC as a reference. ;)
Also, what is the best failsafe procedure for multicopters…, tell me?



Your code ver dev_r1240:

Code: Select all

if (calibratingG>0) {
    for (axis = 0; axis < 3; axis++) {
      // Reset g[axis] at start of calibration
      if (calibratingG == 400) {
        g[axis]=0;
       
        #if defined(GYROCALIBRATIONFAILSAFE)
            previousGyroADC[axis] = gyroADC[axis];
          }
          if (calibratingG % 10 == 0) {
            if(abs(gyroADC[axis] - previousGyroADC[axis]) > 8) tilt=1;
            previousGyroADC[axis] = gyroADC[axis];
       #endif
      }
      // Sum up 400 readings
      g[axis] +=gyroADC[axis];
      // Clear global variables for next reading
      gyroADC[axis]=0;
      gyroZero[axis]=0;
      if (calibratingG == 1) {
        gyroZero[axis]=g[axis]/400;
        blinkLED(10,15,1);
      #if defined(BUZZER)
        alarmArray[7] = 4;
      #endif
      }
    }
    #if defined(GYROCALIBRATIONFAILSAFE)
      if(tilt) {
        calibratingG=1000;
        LEDPIN_ON;
      } else {
        calibratingG--;
        LEDPIN_OFF;
      }
      return;
    #else
      calibratingG--;
    #endif

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

Re: Gyro calibration (zeroing), movement detection

Post by timecop »

Pretty sure calibratingG=1000 was a copypaste from baseflight where this number is higher due to lower cycle time.

User avatar
jevermeister
Posts: 708
Joined: Wed Jul 20, 2011 8:56 am
Contact:

Re: Gyro calibration (zeroing), movement detection

Post by jevermeister »

its not my code... I only put it into a define clause.
feel free to erase it.

the battery facts are correct. I was wrong. sorry

nils

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

Re: Gyro calibration (zeroing), movement detection

Post by timecop »

I know, I was referring about mis copypaste.

User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Re: Gyro calibration (zeroing), movement detection

Post by alll »

Could you come to a conclusion here? Is the code i posted in the beginning a valid option?

ALWAYS do a manual gyro calibration before takeoff (for the gurus)
OR
Automatically calibrate after power up, with correct working code (for the Mormons that expect code logic could do it for them)

thanks,
manu

doughboy
Posts: 252
Joined: Tue Sep 04, 2012 7:20 am

Re: Gyro calibration (zeroing), movement detection

Post by doughboy »

If we all look at this objectively,

MIS committed the original code, with no option to disable.
Nils ran into some problem, then made the change to add a config option and disabled by default.
http://code.google.com/p/multiwii/sourc ... d/config.h
As far as I can tell from previous discussion, even Alex thinks the issue Nils encountered should be addressed separately (if I were reading between the lines, that means to just disable it in his own code).

As far as I can tell, nobody else has this problem. We are not doubting Nils experienced this problem, but so this does not appear like a committer checking in his personal code, we can compromise and say keep the option in but make the default enabled, unless the original author have any other suggestions.

if this is enabled by default, and more users come forward with problems, then this can be addressed at that time. But for now, I have not seen anyone else having problem with the option enabled. and while this option is disabled by default, this type of discussion will just keep coming up again and again.

comparing this to vbat disabled by default is not right. since not all boards have vbat circuit so it does not make sense to enable it by default, but all boards must have a gyro.

Mis
Posts: 203
Joined: Fri Apr 01, 2011 12:23 am

Re: Gyro calibration (zeroing), movement detection

Post by Mis »

Timecop, you are wrong.

Why if tilt==1 you set calibratingG =1000 and not 400?

Load a 1000 to calibratingG counter is for additional delay between stop moving detection and begin of calibration. The calibration begin after calibratingG reached value of 400.

(by the way the line after #if defined(GYROCALIBRATIONFAILSAFE) “previousGyroADC[axis] = gyroADC[axis];” should not be there…)

This statement set initial value of previousGyroADC at start of calibration (if calibratingG == 400). Without this, if the copter is stable at startup, the first attempt to calibration can give a false motion detection.

timecop wrote:The wiki/faq/whatever clearly says gyro MUST be calibrated after each power up by stick combo before flight.NOONE reads this.

Show me this in FAQ/WIKI ect.
The FAQ says: "Calibration is made on each power on, but you can do it manually like before:". CAN, not MUST... How about this ??

User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Re: Gyro calibration (zeroing), movement detection

Post by alll »

(by the way the line after #if defined(GYROCALIBRATIONFAILSAFE) “previousGyroADC[axis] = gyroADC[axis];” should not be there…)

This statement set initial value of previousGyroADC at start of calibration (if calibratingG == 400). Without this, if the copter is stable at startup, the first attempt to calibration can give a false motion detection.


Sorry, didn't look carefully enough, didn't saw the "if calibratingG == 400 {...}"

For the math people, is there a difference for the detection of movement, comparing
"2 consecutive 200 sample averages"
to
"40 compares (separated by 10 samples) out of 400 samples"

Thanks for the constructive feedback,

manu

User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Re: Gyro calibration (zeroing), movement detection

Post by alll »

Since temperature will affect gyroZero values, we could store the gyro temp after a successful calibration, if the temp changes a warning should tell us to do a manual recalibration... or if there a magic formula that compensates the gyroZero values base on temp changes after calibration...

Is there already a temp compensation build in or to activate in resent gyro's?

manu

Mis
Posts: 203
Joined: Fri Apr 01, 2011 12:23 am

Re: Gyro calibration (zeroing), movement detection

Post by Mis »

For the math people, is there a difference for the detection of movement, comparing
"2 consecutive 200 sample averages"
to
"40 compares (separated by 10 samples) out of 400 samples"


Yes of course. But the effect is similar. Is many ways for getting the same effect :-) I found one, you found another. I think both ways are good.

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

Re: Gyro calibration (zeroing), movement detection

Post by scrat »

nicog wrote:Hmmm, I'm not so sure, waiting and leaving the batery to cool down to below freeze level will just make things bad. Lipos don't like the cold (there is some alcohol inside) and make the electrolyte to densify. This leads to a less responsive batery in terms of electric power.

And as everybody knows, batery gets warm on use, wich is normal. So from all of my testing (flew a lot last year and filmed ice climbing) best thing is keep the bat inside the jacket to keep it warm, then plug it when ready (yes you can leave the MR outside in the cold) and fly. Flight time is much similar to summer time this way.


I leave outside just quad. Battery is in my garage.

User avatar
alll
Posts: 220
Joined: Fri Dec 07, 2012 9:53 am

Re: Gyro calibration (zeroing), movement detection

Post by alll »

Hi,

I tested Mis code and mine regarding the supposed temperature drift problem with the GYROCALIBRATIONFAILSAFE option (heat gun while power up). Both do calibrate well without problems. Invensense gyro MPU6050.
I don't think many people still do use piezo gyro's, these were really temp sensitive, but even then, the code logic should get it done, unless you have a defect or noisy gyro.
manu

Post Reply