I just finished a long debugging session with Andrew Tridgell and he has discovered the cause of my yaw (and attitude) issues. In case you don't know Andrew Tridgell, he is the genius developer who made the the latest release fly so well with his DCM improvements.
I think the majority of people out there are experiencing this issue can fix the problem very easily.
"So, what is it?!?!"
It turns out that the automatic compass calibration code on the APM does not work so well. I suspect it is working even more poorly under 2.5 because of the improvements to the DCM, but that correlation has not been confirmed. Like most of the users out there, I have never given more than a moments thought to compass offsets because they have been set automatically for as long as I have been a user, but it turns out they have an enormous impact on the performance of one's copter.
First, what are compass offsets? The offsets are three values that account for the difference in the magnetic field of the earth and the magnetic field that your copter experiences due to interference created by the ESCs, motors, etc. So, the magnetic interference can't possible effect heading that much, right? Wrong. If you don't believe me take a look at this graph:
You can see that towards the beginning of the flight when I am not doing much, the red and green lines are not that far off. As the flight continues and I start using more throttle, they are way off. At about 5:20:20 my heading is off by about 250 degrees. That is massive!!!! So why does it change throughout the flight? The more throttle that is applied the more current is flowing through one's electronics which increases the magnetic interference. Normally this field offset is accounted for, but recently I suspect that some users have bad offsets like I did. My offsets were essentially 1,1,1 when they should have been -180,3,52. Check out the next graph which shows the effect throttle has on the magnetic field:
This is a log from another user, Marco Robustini. The green line shows the throttle and the red line shows the magnetic field. You can see that as the throttle increases, the magnetic field more than doubles.
So how do you fix it? There is a new feature in the latest Mission Planner that allows you to use a telemetry log to determine the offsets OR you can calibrate your compass in real time by holding and spinning your copter 360 degrees. It is highly recommended that you use the telemetry log method. The reason is that when you are holding your copter and spinning it, you are not accounting for the amount of mag interference from the motors (because they are hopefully not running :-D ). Follow these steps:
With Telemetry Log (recommended)
1. Connect to your copter via telemetry.
2. Take off and fly around for a few minutes like you would normally fly. At this point we are collecting data about the magnetic fields during flight.
3. Land and disarm.
4. Download the tlog from that flight. (Instructions here: http://code.google.com/p/arducopter/wiki/AC2_Logs)
5. Connect to your board
6. Goto the Configuration tab
7. Click on the Setup tab
8. Click on the Hardware tab in the popup
9. Click the "Calibrate" button
10. Click "No" when asked if you want to use live data.
11. Browse to the fresh tlog
12. Your offsets are now saved
Without Telemetry Log
1. Follow the above steps 1 through 9
2. Click "Yes" when asked to use Live Data
3. Rotate the copter 360 degrees
The calibration utility is leagues ahead of the automatic calibration on the board that most of us are relying on. Many thanks to Andrew Tridgell, Michael Oborne, and all the devs who had a hand in the compass calibration utility in the planner. There is some serious brain power behind these features we take for granted.
Andrew Tridgell is working on improving the automatic calibration routines that reside on the board based on the updated (and original) algorithms by Bill Premerlani, but for now the Mission Planner calibration is everyone's best bet for improved flight performance.
If you have any questions just leave a comment.
Thanks,
Adam
Comments
Thank you very much for this info. I have had several crash landings caused by my AC spontaneously rotating up to 180deg, that I believe are related to this problem. I'll test and revert.
I have had a much better flight experience after a clean reset/recalibration of everything and PID setup (all from memory), including the mag calibration (calibrated with planner). I then flew through a few packs and the yaw slowly deteriorated until it was all over the place at the end of the day.
The next day I went flying again and it was not good at all.
So maybe we should actually disable the in flight calibration altogether if we do a proper ground calibration in planner?
Finally the situation "compass" is evolving, is a great leap forward, thanks guys for the great job!
My log has been the "trailblazer" and I am glad that the problem was not isolated in this way has been found the problem and "solved".
yes rotation only
Thanks, Michael.
That's what I've been doing to date. I shift it along, as well as rotate it about each of the three axes. Am I correctly understanding that only the rotation part is necessary?
Eric, Turn it over every axis. x y and z
I very much like the sound of this. A couple of questions though. First, regarding the "Rotate 360 deegrees" for live data calibration, does this mean spin the copter about the Z axis, or hold it in your hands and turn your body around? Is it necessary to rotate or translate about any other axes as well (being a 3-axis mag and all that)?
I'm having log issues, so I'm more likely to try the live data method. Is it significantly worse than using a log, or should I see some comparable results?
Thanks for the info, this is immensely useful!
Tridge: Thanks for the clarification on that. And definitely a massive thanks to Bill as well!
Hi Adam,
Thanks for posting this!
I've now pushed the new mag offset learning algorithm. I've posted about it in a discussion with Bill
One minor correction to your post. The main reason the offsets have a different impact during different times of your flight is that you are pointing in different directions. There is an impact with the throttle as well as you say, but its also expected that bad offsets don't have a uniform impact in all directions.
Also, Bill Premerlani should really get the credit for this work. I'm just happy to be able to implement his great ideas.
Cheers, Tridge
Two more quick notes:
1. This is not necessarily going to fix your specific issue. If this does not work for you, please share logs with us so we can analyze it and solve the issue.
2. UPDATE: Just got off another call with Andrew Tridgell and he has the new compass learning algorithm (by Bill Premerlani) implemented and it looks very promising. It will get tested by the dev team and integrated soon, but as I stated above, your best bet for now is using the Mission Planner with the tlog.