Accumulative drift

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

Hi Ziss_dm,

Sorry for my delayed response.
My setup is:
-Paris V 3 board
-BMA180 ACC
-HMC5883l MAG
-BMP085 BARO
-Original Wii+ WMP
-Dys 30A ESC
-Robbe Roxxy 2827-34
-10" Props front 4,7 and back 3,8 to have more lift at the cam mount (front)
-70cm Diameter

The drift:
If using firmware V 1.8p1 the Quad seems quite stable after take off. (even in stable mode)

So if i am just descending around a bit in stable mode, there will start a drift at random direction. After the drift has choosen its direction, its additive. The drift gets stronger and stronger into that direction.
In acro mode everything works fine.

Using firmware V1.8p2 the drift seems to start, but most time it compensates after 2-4 meters of drift quite well.

I also got confusing readings about the yaw of my compass. :oops:

I will update this post soon with the GUI readings you requested.

Update:
I did another testflight, it seems that hmc5883 is the main cause of the drift.
Without activated mag the whole flight went well without drift. (fw 1.8p2)

here the gui:
45 grades
Image

90 grades
Image

i did not yaw the quad at this time of capturing, watch at its direction (mag has been calibrated)

flat
Image

inverted
Image

yawed
Image

update:
last test flight seemed to have a drift with acc only, but this one seems to be based on a poor return to level because drift ocured in different directions.

gyro reactions:
move pitch forward
Image

move roll to the right
Image

invert quad per roll to the right
Image

i hope this are the inforations you need!

cheers
Noc

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

My conclusion:
I think the main drift is based on the HMC - caused by wrong axis definition - but right now i am not sure wich to swap...
The drift wich occurs in stable mode without HMC should be based on my lowered P settings on Roll and Pitch? (bad return to level)
Acro mode works fine as ever.

This test all were taken with FW 1.8p2

cheers,
Noctaro

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

Re: Accumulative drift

Post by Alexinparis »

Hi,

Your MAG is not well calibrated:
MAG YAW should be positive when the multi is flat.

During the calibration step, the multi needs to point in every direction (not only the flat circle, but the whole 3D sphere)

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

Hi Alex,
thats the point! I did not know that i have to calibrate the whole sphere. :? As you mentioned i just did the flat circle.
Ok i will correct that, thank you very much for that advice, i will give you a feedback of the performance after recalibrating.

cheers
Noc

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Accumulative drift

Post by ziss_dm »

Hi Noc,

Can I ask you to comment this lines of code in imu.pde:

Code: Select all

  // Apply complimentary filter (Gyro drift correction)
  // If accel magnitude >1.4G or <0.6G and ACC vector outside of the limit range => we neutralize the effect of accelerometers in the angle estimation.
  // To do that, we just skip filter, as EstV already rotated by Gyro
// accLim = acc_1G*4/10;
//  if ( ( 36 < accMag && accMag < 196 ) || (  abs(accSmooth[ROLL])<accLim  && abs(accSmooth[PITCH])<accLim ) ) {
    for (axis = 0; axis < 3; axis++)
      EstG.A[axis] = (EstG.A[axis] * GYR_CMPF_FACTOR + ACC_VALUE) * INV_GYR_CMPF_FACTOR;
//  }


and try?

You also can play with:

Code: Select all

/* Set the Gyro Weight for Gyro/Acc complementary filter */
/* Increasing this value would reduce and delay Acc influence on the output of the filter*/
/* Default WMC value: 300*/
#define GYR_CMPF_FACTOR 310.0f


Decrease it to 200 - if drift increases it is coming from ACC
Increase it to 600 - if drift increases it is coming from Gyro

regards,
ziss_dm

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

Hi ziss_dm,

that sounds quite intresting! I will try that! Thank you.

I´ve got another quesstion, is there an stick combination implemented to start the compass calibration?
Its quite hard to do a flawless calibration in the whole 3d sphere, since i am connected via USB. I did a little workaround, because i could not find any hints about a stick combination for this routine. Is it ok to start the routine via GUI and then disconnect from USB? -> Update: Seems to work perfect.


UPDATE:
It seems that drift has nearly gone by correct calibration of MAG.

I will try ziss_dms idea today, yesterday i had not enough time to test.

cheers
Noc

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Accumulative drift

Post by ziss_dm »

Hi Noc,

Noctaro wrote:UPDATE:
It seems that drift has nearly gone by correct calibration of MAG.

Are you sure? The MAG should not affect Level mode (theoretically). :shock:

Did you have a chance to play with IMU settings?

regards,
ziss_dm

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

Hey ziss_dm,
It seems that the wrong MAG calibration did effect the level mode. I am not toatally sure about, but as example,
if i pitch my quad to the front:
- calibrated: There will be no Yaw at all shown in GUI.
-wrong calibrated: The Gui will show that the quad is also yawed.
I do not know how this exactly manipulates level mode in flight, but it felt quite smoother after calibrating the MAG.

I tried to comment the lines you posted. I have to say, drift compensates !much! better now. I did not play with the Gyro<->ACC settings until now. Will do that as soon as my new bearings arrive.
The intresting part: If descending around, quad does a really nice job compensating the drift. Within 2 meters of drifting, it seems to go back to perfect level. It really feels save to fly. Even with heavy wind. Btw. drift is now not limited to one direction, it drifts a bit to the left sometimes to the right sometimes forwards and so on.
But if i will do a fast speedup around 4 secounds of pitch input, the quad seems to guess this position as "in level". I have to do some counter stick movements, to get it back to level and stop speeding up. :?

I will keep on testing to get further impressions.

cheers
Noc

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Accumulative drift

Post by ziss_dm »

It seems that the wrong MAG calibration did affect the level mode. I am not totally sure about, but as example,
If I pitch my quad to the front:
- calibrated: There will be no Yaw at all shown in GUI.
-wrong calibrated: The Gui will show that the quad is also yawed.
I do not know how this exactly manipulates level mode in flight, but it felt quite smoother after calibrating the MAG.

Yes, I can understand, that wrongly calibrated orientated MAG can cause Yaw drifts and probably level drifts due cross axis sensitivity (BTW: is your ACC level in reference to the frame body? ;)).
But definitely should not affect anything in case it switched off by switch.. So, you not saying, that just uncommenting MAG in the code (and not switching it on) causing drift? ;)


Btw. drift is now not limited to one direction, it drifts a bit to the left sometimes to the right sometimes forwards and so on.

Recently, I have found that 1.8 is really sensitive during Gyro calibration. Even connecting power on carpet and having slight movement causing slight drift. Can I ask you to execute Gyro calibration by sticks before each
flight, to see is it the reason for your drifts. In case it would help, we can easily modify calibration procedure to make it more "smart". Also note, that gyro drifts quite often not visible in the GUI as we dividing
Gyro values by 8 (as I remember).

I tried to comment the lines you posted. I have to say, drift compensates !much! better now. I did not play with the Gyro<->ACC settings until now. Will do that as soon as my new bearings arrive.
The interesting part: If descending around, quad does a really nice job compensating the drift. Within 2 meters of drifting, it seems to go back to perfect level. It really feels save to fly. Even with heavy wind.


To avoid confusions, I would probably try to explain how this thing works. So let’s start with ACC. ACC is nice device which reports acceleration ;), the 3axis ACC reports 3d vector pointing to the acceleration direction and Magnitude of this vector (vector length) is equal (at least should be) to the acceleration value. The trick here that it cannot distinct between latent acceleration and gravitation, so than it sitting flat and still, the vector is pointing straight down to the centre of earth (in case of wmc straight up ;)) and it should report X = 0, Y = 0, Z = 9.8 m/s/s. In case you accelerating up with 2 m/s/s it should report X = 0, Y = 0, Z = 11.8 m/s/s and if you falling dawn X = 0, Y = 0, Z = 0. And if you accelerating left, let say 9.8 m/s/s, the reported vector would point to center of earth any more, it would inclined left by 45 degrees and length of the vector would be 13.86 m/s/s and it should report X = 0, Y = 9.8, Z = 9.8. The another problem with ACC is vibrations, because vibration is usually linear acceleration, the ACC is designed to sense it, so any vibration in any direction would reported as a jitter of acceleration vector and because vibration acceleration could be quite high, comparatively to the gravitation the jitter could be quite high up to 3-5 degrees.

Let's continue with Gyro, the gyro reports angular rates, which means it reports how fast it is rotated. The 3 axis gyro report how fast it is rotated around all 3 axes. The interesting thing, that it is does not matter how it is moved in space, in case it is not rotated during this movement it reports zeros (In perfect world). The gyro pretty much not sensitive to linear vibrations, but... It is quite easy to make it sense vibrations. What you need is just put it on something soft.. ;) preferably asymmetrically (one side softer than other). Using this recipe we can quite successfully convert linear vibrations to rotations. We can use gyro data to get our position in space just by integrating gyro date, but there are couple of problems: 1) it reporting rates relatively to the body, not to the ground. 2) even very small errors in the rates would cause unbounded growth in the integrated quantities. The Gyro has 2 types of errors (drifts). Static drift, it is sitting still but reporting some movement. And dynamic drift: you rotating it left and right with exactly the same speed but for left rotation it reports, for example, 10 and for right 15..

To overcome those problems, we are doing the following: we integrating Gyro (accumulating vector rotations):

Code: Select all

  // Rotate Estimated vector(s), ROLL
  deltaGyroAngle  = gyroADC[ROLL] * deltaTime;
  EstG.V.Z =  scos(deltaGyroAngle) * EstG.V.Z - ssin(deltaGyroAngle) * EstG.V.X;
  EstG.V.X =  ssin(deltaGyroAngle) * EstG.V.Z + scos(deltaGyroAngle) * EstG.V.X;
...
  // Rotate Estimated vector(s), PITCH
  deltaGyroAngle  = gyroADC[PITCH] * deltaTime;
  EstG.V.Y =  scos(deltaGyroAngle) * EstG.V.Y + ssin(deltaGyroAngle) * EstG.V.Z;
  EstG.V.Z = -ssin(deltaGyroAngle) * EstG.V.Y + scos(deltaGyroAngle) * EstG.V.Z;
  ...
  // Rotate Estimated vector(s), YAW
  deltaGyroAngle  = gyroADC[YAW] * deltaTime;
  EstG.V.X =  scos(deltaGyroAngle) * EstG.V.X - ssin(deltaGyroAngle) * EstG.V.Y;
  EstG.V.Y =  ssin(deltaGyroAngle) * EstG.V.X + scos(deltaGyroAngle) * EstG.V.Y;
  ...

If you comment this part and only ACC would be used to calculate position.

And we correcting results using ACC data:

Code: Select all

  // Apply complimentary filter (Gyro drift correction)
  // If accel magnitude >1.4G or <0.6G => we neutralize the effect of accelerometers in the angle estimation.
  // To do that, we just skip filter, as EstV already rotated by Gyro
   if (!((36 > AccMag) or (AccMag > 196))) {
    for (axis = 0; axis < 3; axis++)
      EstG.A[axis] = (EstG.A[axis] * GYR_CMPF_FACTOR + ACC_VALUE) * INV_GYR_CMPF_FACTOR;
  }

If you comment this part and only Gyro would be used to calculate position.
GYR_CMPF_FACTOR – how “strong” correction from ACC.

Now, why we have this part:

Code: Select all

   if (!((36 > AccMag) or (AccMag > 196))) {
 

As we discussed before, in case of latent acceleration the acceleration vector can be shifted from vertical. We are not able to remove latent acceleration from ACC data, so we just limiting total acceleration to 0.6G - 1.4G. With in this range we trust ACC, outside we using only Gyro.

Regards,
Ziss_dm

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

Hi ziss_dm,
i have to thank you for your great explanation!

Yes, I can understand, that wrongly calibrated orientated MAG can cause Yaw drifts and probably level drifts due cross axis sensitivity (BTW: is your ACC level in reference to the frame body? ;)).
But definitely should not affect anything in case it switched off by switch.. So, you not saying, that just uncommenting MAG in the code (and not switching it on) causing drift?


My ACC is directly mounted on my parisboard with special foam tape.The board itslef is screwed on shock absorbers on the groundplate of my quad. So its in reference to the frame body i guess.
If MAG is not activated there is also a drift, but it seems to behave in diffrent ways. If MAG(uncalibrated) is active, the copter will hold its direction but seems to have more roll and pitch drifts.

Recently, I have found that 1.8 is really sensitive during Gyro calibration. Even connecting power on carpet and having slight movement causing slight drift
.


Ok i will try to use stick calibration for the next flights. But as far as i know, sensor calibration is executed during the board led blinks. I never touched the quad at this time of the boot routine, so i guess this should not be the problem.

The another problem with ACC is vibrations, because vibration is usually linear acceleration, the ACC is designed to sense it, so any vibration in any direction would reported as a jitter of acceleration vector and because vibration acceleration could be quite high, comparatively to the gravitation the jitter could be quite high up to 3-5 degrees.


I now added new bearings and rebalanced props, as far as i can see using onboard captures, vibrations are gone. Flight seems smoother now.

Let's continue with Gyro, the gyro reports angular rates, which means it reports how fast it is rotated. The 3 axis gyro report how fast it is rotated around all 3 axes. The interesting thing, that it is does not matter how it is moved in space, in case it is not rotated during this movement it reports zeros (In perfect world). The gyro pretty much not sensitive to linear vibrations, but... It is quite easy to make it sense vibrations. What you need is just put it on something soft.. ;) preferably asymmetrically (one side softer than other).

I think my gyro is mounted perfect on special foam tape, but its not asymmetrically... :idea: I will give this an try. By the way, in Acro Mode there is no drift at all! Acromode is based on the gyro only? :?

We are not able to remove latent acceleration from ACC data, so we just limiting total acceleration to 0.6G - 1.4G. With in this range we trust ACC, outside we using only Gyro.


I think i do understand now. Gyro estimates the changes of position, while acc corrects this data by estimating the absolute position. While ACC only has effect within the mentioned acceleration rate.
So if i pitch my quad and it starts speeding up very fast, only gyro estimates the angle. As the G gets back again to trusted range, ACC will be used to get my vehicle back to level.

At the moment i use firmware with the ACC line commented.

Code: Select all

     if (!((36 > AccMag) or (AccMag > 196))) {
        for (axis = 0; axis < 3; axis++)
          EstG.A[axis] = (EstG.A[axis] * GYR_CMPF_FACTOR + ACC_VALUE) * INV_GYR_CMPF_FACTOR;
      }

So my quad does not use ACC to correct the drift of gyro.

Did i get this right?

Again, thank you very much for your help!

regards,
Noc

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

Re: Accumulative drift

Post by jevermeister »

Recently, I have found that 1.8 is really sensitive during Gyro calibration. Even connecting power on carpet and having slight movement causing slight drift. Can I ask you to execute Gyro calibration by sticks before each
flight, to see is it the reason for your drifts. In case it would help, we can easily modify calibration procedure to make it more "smart". Also note, that gyro drifts quite often not visible in the GUI as we dividing
Gyro values by 8 (as I remember).


Hi,

I stated this a while ago, my old Tricopter ha a routine that adresses this problem, it checks the ACC while calibrating and if there are differences bigger than a given value it will start the calibration over until it finished the calibration without any disturbances, I find that very useful and handy, but the idea was rejected.
So maybe it is time tho rethink this issue.

Nils

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

Hi Nils!
That sounds quite nice. Would you post me the code of calibration routine? I would like to give it a try :)

regards
Noc

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

Re: Accumulative drift

Post by jevermeister »

The code is written in bascom, but I think it is easy do adapt, I will try something over the weekend and report back.

Nils

kataventos
Posts: 702
Joined: Sun Aug 28, 2011 8:14 pm
Contact:

Re: Accumulative drift

Post by kataventos »

Rob wrote:@noctaro

if I read your post, ik think the problem is your ESC ,
if you decrease the P the problem is less but still there (try it)

Rob

Hi, I´m having the same problem as Noctaro and I use the Hobby Wing Fly Fun (Pentium) 18A. I have tried to decrease the I value to 0 and does not fix the problem, then I tried Alex patch2 and what I get is "better but false stability" I have unstable random movements trying to get it self leveled, like 2sec for the left then level, 3sec for the right level again, etc. In acro mode everything is perfect I only fly FPV and I must say that in the beginning it was hard not to pee on my pants! :) but once get used to it, is full freedom. Anyway I do sometimes need the stable mode for some filming and photography and if anyone could help... Thanks


Original PID´s
Level I= 0
Hobby Wing 18A ESC
Paris V4
Original WMP + NK

Cheers
Kataventos

mahowik
Posts: 332
Joined: Sun Apr 10, 2011 6:26 pm

Re: Accumulative drift

Post by mahowik »

Hi guys!!!

Thanks to all for help to understand how IMU works and how it's tune the best.

Does anyone have a good news on avoid ACC drift? Some new tests etc.

Have an idea to configure bma020/180 for the Range 4G (or 8g). If I'm not mistaken it will reduce the ACC sensitivity and helps to filter the unnecessary noise. Right?

thx-
Alex

mahowik
Posts: 332
Joined: Sun Apr 10, 2011 6:26 pm

Re: Accumulative drift

Post by mahowik »

I have added more useful low pass filter to play with ACC filtering. Now it's possible to set cut frequency in Hz by setting ACC_LPF_CUT_FREQ value.

Pls. pass this after #define ACC_LPF_FACTOR
IMU.ide

Code: Select all

// #define ACC_LPF_FACTOR 8

/* Set the Low Pass Filter cut frequency for derivative calculation. */
/* It's discrete LPF, cuts out the high frequency noise that can drive the controller crazy and produce a drift. */
/* Pls. see http://en.wikipedia.org/wiki/Low-pass_filter. */
/* Decreasing the cut frequency would reduce ACC noise (visible in GUI), but would increase ACC lag time */
/* Preferably it should be less 25 Hz because anything over that is probably noise for ACC. */
#define ACC_LPF_CUT_FREQ 10


Also it's possible to tune/manage the cut freq via GUI at runtime by using for examle "P" value for magnetometer (P8[PIDMAG]).
But make sure that in GUI it's displayed with dot. I.e. 1.0=10Hz or 2.5=25Hz.

Code: Select all

#define ACC_LPF_CUT_FREQ P8[PIDMAG]

I.e. it's just for testing. Then you can put the best found value as constant.

Also you should replace the getEstimatedAttitude() function with provided below (for MultiWii_1_8_patch2):

Code: Select all

void getEstimatedAttitude(){
  uint8_t axis;
  uint16_t accMag = 0;
  static t_fp_vector EstG = {0,0,300};
  static t_fp_vector EstM = {0,0,300};
  float scale, deltaGyroAngle;
  static int16_t mgSmooth[3];  //projection of smoothed and normalized magnetic vector on x/y/z axis, as measured by magnetometer
  static uint16_t previousT;
 
  uint16_t currentT  = micros();
  uint16_t dt = currentT - previousT;
  previousT = currentT;
  scale = dt * GYRO_SCALE;
 
  // Initialization
  for (axis = 0; axis < 3; axis++) {
    #if defined(ACC_LPF_CUT_FREQ)
     
      /// accurate version: with float calculation
      /*
        float delta_time   = (float)dt / (1000.0 * 1000.0); // get time in seconds
        float RC = 1 / (2 * M_PI * ACC_LPF_CUT_FREQ);
        accSmooth[axis] = accSmooth[axis] + (delta_time / (RC + delta_time)) * (accADC[axis] - accSmooth[axis]);
      */

      /// simplified version: add more performance in diff with accurate version (i.e. without float calculation)
      /// RC(IN_MICROSECONDS) = 1000000 * / (2 * M_PI * ACC_LPF_CUT_FREQ) = 159154.94309189533576888378278968 / ACC_LPF_CUT_FREQ ~= 159155 / ACC_LPF_CUT_FREQ
      accSmooth[axis] = accSmooth[axis] + ((int32_t)dt * (accADC[axis] - accSmooth[axis])) / ((159155 / ACC_LPF_CUT_FREQ) + dt);
    
      #define ACC_VALUE accSmooth[axis]

    #else 
      accSmooth[axis] = accADC[axis];
      #define ACC_VALUE accADC[axis]
    #endif
    accMag += (ACC_VALUE * 10 / acc_1G) * (ACC_VALUE * 10 / acc_1G); //788
    #if MAG
      #if defined(MG_LPF_FACTOR)
        mgSmooth[axis] = (mgSmooth[axis] * (MG_LPF_FACTOR - 1) + magADC[axis]) / MG_LPF_FACTOR; // LPF for Magnetometer values
        #define MAG_VALUE mgSmooth[axis]
      #else 
        #define MAG_VALUE magADC[axis]
      #endif
    #endif
  }

  // Rotate Estimated vector(s), ROLL
  deltaGyroAngle  = gyroADC[ROLL] * scale;
  EstG.V.Z =  scos(deltaGyroAngle) * EstG.V.Z - ssin(deltaGyroAngle) * EstG.V.X;
  EstG.V.X =  ssin(deltaGyroAngle) * EstG.V.Z + scos(deltaGyroAngle) * EstG.V.X;
  #if MAG
    EstM.V.Z =  scos(deltaGyroAngle) * EstM.V.Z - ssin(deltaGyroAngle) * EstM.V.X;
    EstM.V.X =  ssin(deltaGyroAngle) * EstM.V.Z + scos(deltaGyroAngle) * EstM.V.X;
  #endif
  // Rotate Estimated vector(s), PITCH
  deltaGyroAngle  = gyroADC[PITCH] * scale;
  EstG.V.Y =  scos(deltaGyroAngle) * EstG.V.Y + ssin(deltaGyroAngle) * EstG.V.Z;
  EstG.V.Z = -ssin(deltaGyroAngle) * EstG.V.Y + scos(deltaGyroAngle) * EstG.V.Z;
  #if MAG
    EstM.V.Y =  scos(deltaGyroAngle) * EstM.V.Y + ssin(deltaGyroAngle) * EstM.V.Z;
    EstM.V.Z = -ssin(deltaGyroAngle) * EstM.V.Y + scos(deltaGyroAngle) * EstM.V.Z;
  #endif
  // Rotate Estimated vector(s), YAW
  deltaGyroAngle  = gyroADC[YAW] * scale;
  EstG.V.X =  scos(deltaGyroAngle) * EstG.V.X - ssin(deltaGyroAngle) * EstG.V.Y;
  EstG.V.Y =  ssin(deltaGyroAngle) * EstG.V.X + scos(deltaGyroAngle) * EstG.V.Y;
  #if MAG
    EstM.V.X =  scos(deltaGyroAngle) * EstM.V.X - ssin(deltaGyroAngle) * EstM.V.Y;
    EstM.V.Y =  ssin(deltaGyroAngle) * EstM.V.X + scos(deltaGyroAngle) * EstM.V.Y;
  #endif
 
  // Apply complimentary filter (Gyro drift correction)
  // If accel magnitude >1.4G or <0.6G and ACC vector outside of the limit range => we neutralize the effect of accelerometers in the angle estimation.
  // To do that, we just skip filter, as EstV already rotated by Gyro

  if ( (36 < accMag) && (accMag < 196) ) { 
    for (axis = 0; axis < 3; axis++)
      EstG.A[axis] = (EstG.A[axis] * GYR_CMPF_FACTOR + ACC_VALUE) * INV_GYR_CMPF_FACTOR;
  }
 
  // Attitude of the estimated vector
  angle[ROLL]  =  _atan2(EstG.V.X, EstG.V.Z);
  angle[PITCH] =  _atan2(EstG.V.Y, EstG.V.Z);
 
  #if MAG
    // Apply complimentary filter (Gyro drift correction)
    for (axis = 0; axis < 3; axis++)
      EstM.A[axis] = (EstM.A[axis] * GYR_CMPFM_FACTOR - MAG_VALUE) * INV_GYR_CMPFM_FACTOR;
    // Attitude of the cross product vector GxM
    heading = _atan2(EstG.V.Z * EstM.V.X - EstG.V.X * EstM.V.Z, EstG.V.Y * EstM.V.Z - EstG.V.Z * EstM.V.Y) / 10;
  #endif
}


Generally speaking all we need: get delta time and replace the filter:

Code: Select all

................
  uint16_t currentT  = micros();
  uint16_t dt = currentT - previousT;
  previousT = currentT;
  scale = dt * GYRO_SCALE;
 
  // Initialization
  for (axis = 0; axis < 3; axis++) {
    #if defined(ACC_LPF_CUT_FREQ)
     
      /// accurate version: with float calculation
      /*
        float delta_time   = (float)dt / (1000.0 * 1000.0); // get time in seconds
        float RC = 1 / (2 * M_PI * ACC_LPF_CUT_FREQ);
        accSmooth[axis] = accSmooth[axis] + (delta_time / (RC + delta_time)) * (accADC[axis] - accSmooth[axis]);
      */

      /// simplified version: add more performance in diff with accurate version (i.e. without float calculation)
      /// RC(IN_MICROSECONDS) = 1000000 * / (2 * M_PI * ACC_LPF_CUT_FREQ) = 159154.94309189533576888378278968 / ACC_LPF_CUT_FREQ ~= 159155 / ACC_LPF_CUT_FREQ
      accSmooth[axis] = accSmooth[axis] + ((int32_t)dt * (accADC[axis] - accSmooth[axis])) / ((159155 / ACC_LPF_CUT_FREQ) + dt);
    
      #define ACC_VALUE accSmooth[axis]

    #else 
      accSmooth[axis] = accADC[axis];
      #define ACC_VALUE accADC[axis]
    #endif
................


Could anyone (who has the drift issue in stab/level mode) test this in hands and probably on fly and give me a feedback? :)
Because I damaged my copter some weeks ago...

kataventos
Posts: 702
Joined: Sun Aug 28, 2011 8:14 pm
Contact:

Re: Accumulative drift

Post by kataventos »

Hi Mahowik, I can test in hands and report in a few moments, my doubt is in patch 1 or 2? I have patch 2 at the moment but I can get to 1 quick!
Test will be made with original WMP and NK only, no mag.

Update: I have tested in hands and sorry to say that did not make any diference in my case, starts leveled and with or without stick commands it starts to drift like before.
What I notice diferent was if it drift to the right/front and I force it in the same direction for some time it leveled better but if I get to long, in the end leveled was the oposite direction, odd! Anyway I´m going to do the same without your line and see. Thanks for the help.
Test was performed with: P= 9.0 I=0.045

Cheers,
Henrique

mahowik
Posts: 332
Joined: Sun Apr 10, 2011 6:26 pm

Re: Accumulative drift

Post by mahowik »

kataventos wrote:Hi Mahowik, I can test in hands and report in a few moments, my doubt is in patch 1 or 2? I have patch 2 at the moment but I can get to 1 quick!
Test will be made with original WMP and NK only, no mag.

Update: I have tested in hands and sorry to say that did not make any diference in my case, starts leveled and with or without stick commands it starts to drift like before.
What I notice diferent was if it drift to the right/front and I force it in the same direction for some time it leveled better but if I get to long, in the end leveled was the oposite direction, odd! Anyway I´m going to do the same without your line and see. Thanks for the help.
Test was performed with: P= 9.0 I=0.045

Cheers,
Henrique


Hi Henrique! Thanks for your help with tests!
Just play with patch 2...

At first try to decrease level "I" to 0.015-0.025

Also to make sure that issue in ACC drift pls. check step by step:
1. In acro mode it has no any drifts.
2. if first point is true, try to increase GYR_CMPF_FACTOR to 10000 (to check IMU based on gyro data) and test in level mode.
3. only then play with cut frequency. Just set this to P8[PIDMAG] and tune/manage the cut freq via GUI by using for "P" value for magnetometer

Code: Select all

 #define ACC_LPF_CUT_FREQ       P8[PIDMAG]

kataventos
Posts: 702
Joined: Sun Aug 28, 2011 8:14 pm
Contact:

Re: Accumulative drift

Post by kataventos »

Hi Mahowik,

sorry to say but I performed the above test with patch1, with patch2 the drift was gone but it dont level assertively, it´s more like trying to find what´s the leveled position, and with the changes is the same, I´ve decreased the I from 0.045 to 0.015 and 0

Thanks,
Henrique

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

After further testings with 1.9, i seem to get an gyro drift at around 10 minutes of flighttime. The drift is accumulative (gets stronger). It is the same behaviour as stable acc mode showed up. I have to admit that it could be the same drift, and i misinterprated it to acc all the time.
I do not want to revert to 1.8 because i like the icc problems to be .solved like in 1.9.
If any of you say it would help of course i will give it a try.

Temperature drift?
Its one possibility i thought of, but i am nearly sure its not the problem.
I dismounted my cam to gain some extra flying time. After 10 minutes of flight (and noticable drift to right front) i dis- and reconnected power.
Drift was gone.
After another 10 minutes of flight same happening.
The gyro does not really feel warm, so i am not sure if its really based on the temp.
My onboard vids, show some good balanced props without vibrations.
I thought of the Voltage has to do with the drift, but as i reconnected the same accu and drift is gone, i think its not depended to it.

As i got no bt serial thingy, i cant capture inflight data. At gui with motors on, i could not detect a drift on gyro, constant zero even at full throttle. (Without props tested for 10 minutes.)
Only thing i could see, that the left front motor starts to speedup slowly.
Most case my drift will go to front right.
I have tested my mx-16 rc at gui and set deadband 6, to be sure that drift will not be related to its pottis.

Does anyone know how i could prevent this drift in acro mode?
I use standart PID settings. (My quad is a heavy bot carring 4000mah, but at takeoff they seem to just work fine ;)
internall pullups enabled - may this be a problem?

Quad X
- 30A ESC DYS
- 10" Prop
- Robbe roxxy 2827-34
- MX-16 FrSky modded
- Paris V3
- Orig WMP
- BMA180
- BMP085

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Accumulative drift

Post by ziss_dm »

Hi Noctaro,

Can you connect GUI after flight without re-connecting power and check gyro values?
If they not 0 - problem with gyro, if not somethere else.

regards,
ziss_dm

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

hey ziss_dm,
thanks for your advise. I did a testflight, did not reconnect power and connected programmer. As i connect it, Arduino seems to reinit, so i am not sure if i would get the correct inflight data. But as far i could test it, Gyro was at constant 0(rolling and pitching worked as it should). Same with I2C errors. What else could cause a drift over time that will influence acro mode? By over time i mean, the drift starts suddenly, but everytime around 8-10 minutes of flighttime. Its predictable, it will start drifting front right. Sometimes more front sometimes more right. Intresting thing, if i roll left at 30°, it compensates nearly like in stable mode and goes nearly back to level(Rolls faster right). Then slowly starts to drift right again(Rolls slowly right). Feels a bit of a "left roll stable to right" mode :D I don´t get it. Any ideas are welcome. Feel free to ask for more infos if needed :)
greetz
noc

btw. handling the drift in acromode is not a big problem, but in stable mode its hard to compensate, as if drift occurs, new leveled positions is constant right front around 10° i guess.
The overall performance with 1.9 is impressing. I now can fly my quad through doors if i want to because its that precise inflight. Thanks to all for development!

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

Hi,
doing the gyro calibration routine when drift starts does solve it in both acro and stable mode.
But i have to do it around every 6 minutes. Is my gyro damaged?

I think i did not see the drift of gyro with my old akkus because they only supplied me for around 7 minutes of flight.
Now i got around 18 minutes of flighttime and can see acro mode drifting away again and again. Predictable to front right.
As some variable would run away and keep increasing. But maybe it is really depended to my wmc+

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

Hey,
i found out, that if i hit start in gui and then disconnect my quad without hitting stop, it will not reinitalize if i reconnect. So now i am sure i will get the correct inflight data, but gyro does not show up drift, before or after flight. (Constant 0 if not moving)
Also temperature,light and wind should not be the cause, because i also get the drift indoors.
Am i the only one who got this problem using WMP+?
Are there any other tests i could do?

please help

Noctaro
Posts: 280
Joined: Thu Sep 08, 2011 11:15 am
Contact:

Re: Accumulative drift

Post by Noctaro »

Solved a big mystery.
Replacing the WMP+ with a ITG3200-breakoutboard(defualt lpf set), did the trick. No accumulative drift in acro or level mode(BMA180). Everything working fine, tested both sensors with mw2.0pre2 (wmp+ still caused a drift).

greetz
Noc

btw. never touch your mag with a soldering iron, it may cause i2c errors afterwards. 8-)

Post Reply