Idea: active compass compensation

Post Reply
Quad FRITZ
Posts: 44
Joined: Wed Apr 25, 2012 11:21 pm

Idea: active compass compensation

Post by Quad FRITZ »

Hi-

I think it is a common problem with aio boards that the compass is influenced by the (high) currents in the battery / ESC cables. This might become an issue when using GPS or "headfree mode".
At least for RTH- why not:

- RTH enabled?
- stop yaw
- switch off motors for a (very) short time
- reference compass value
- power motors sufficiently for RTH with height hold
- average compass difference
- subtract error
--> voila: corrected compass value for RTH calculation (at average current needed for RTH)

Please let me know what you think! :o

Kind regards
Roman

User avatar
Crashpilot1000
Posts: 631
Joined: Tue Apr 03, 2012 7:38 pm

Re: Idea: active compass compensation

Post by Crashpilot1000 »

Thanks for sharing your idea!
But i think you will have to shut down the motors for a few seconds and on bad setups the variance depends on throttleopening and Lipo (different lipos can do different variation). Perhaps it would be possible to do a throttle-magnetometer compensation. After the mag calibrationdance you will have to tie your copter to the ground (no moving possible) and throttleup motors a few times. By doing this the mag deviation depending on throttle on your copter could be gathered.

Cheers
Kraut Rob

Quad FRITZ
Posts: 44
Joined: Wed Apr 25, 2012 11:21 pm

Re: Idea: active compass compensation

Post by Quad FRITZ »

Sounds good- thank you for your feedback!
Now just one of the brilliant programmers needs to volunteer ;-)

Greets

QuadBow
Posts: 532
Joined: Fri Jan 04, 2013 10:06 am

Re: Idea: active compass compensation

Post by QuadBow »

Quad FRITZ wrote:Please let me know what you think! :o


Today, I have implemented this funcionality for my miniquad. Normally, I would prefer to wire the accu cable as far away from the mag as possible.
For small and very small copters, that is not feasible.

Thus, I measured the current of the main power line (from the accu) via POWERMETER and found out a quite linear relation of 3° offset per 1 ampere.
Furthermore, I changed the code in imu.ino as follows:

Code: Select all

  #if MAG
    heading = _atan2(
      EstM32.V.Z * EstG32.V.X - EstM32.V.X * EstG32.V.Z,
      EstM32.V.Y * invG * sqGX_sqGZ  - (EstM32.V.X * EstG32.V.X + EstM32.V.Z * EstG32.V.Z) * invG * EstG32.V.Y );
    heading += MAG_DECLINIATION * 10; //add declination
    #if defined(POWERMETER)
      heading += pCurrent * MAG_COMPENSATION / 10;             // compensate MAG disturbance by power cable
    #endif
    heading = heading /10;
    if (heading <= - 180) heading += 360;                                // for safety reasons
    if (heading >= + 180) heading -= 360;
  #endif


For the compiling process I had to define
#define MAG_COMPENSATION 3
and to use pCurrent (from POWERMETER).
The only issue was to use the right direction of the compensation (plus or minus).
Now, my minicopter flies without any remarkable yawing.

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

Re: Idea: active compass compensation

Post by Mis »

I think, that this should not work propertly. With different orientations of copter you get different disturbance by magnetic fields from cables. Check it with several yaw orientations of copter.

QuadBow
Posts: 532
Joined: Fri Jan 04, 2013 10:06 am

Re: Idea: active compass compensation

Post by QuadBow »

Mis wrote:With different orientations of copter you get different disturbance by magnetic fields from cables.

You are right, the copter has a weak orientation at 180°. So, I have to experiment a bit more. Or do you have a solution, Mis?

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

Re: Idea: active compass compensation

Post by Mis »

IMHO this is wrong way. You can correct the disturbance on each MAG axis separatly BEFORE heading computation. But this is more complicated, because You need check the disturbance on all axis separatly (this is depended of cable position) and then apply correction to "imu.magADC" values in sensors.ino

QuadBow
Posts: 532
Joined: Fri Jan 04, 2013 10:06 am

Re: Idea: active compass compensation

Post by QuadBow »

Mis wrote:You can correct the disturbance on each MAG axis separatly BEFORE heading computation.


That was exactly the way a went firstly. I wrote a table with the dependencies of the three mag axises to the current and approximated it by a linear function. One axis was the dominating factor. Afterwards, I computated the heading via the normal equation.
Despite all efforts, the result of this more complex computation was quite disappointing since it not a advantage over the simplified way I introduced assuming
- a linear disturbance to only one axis and
- a linear approximation of the atan2 function.
So, the mag compensation remains an issue in my view.

Post Reply