Page 1 of 1

Yaw from magnetometer locked in one position.

Posted: Mon Oct 21, 2013 9:54 am
by luisruiz
Hello,

I am trying to implement an autopilot in the Crazyflie. I have been making some changes to the firmware to implement a new control law. For that I need to know the orientation in pitch, roll and yaw.

I already added gyro drift subtraction for pitch and roll, and the readings seems to be right. I tested it with the 2 Crazyflies I have.

For yaw, it has been a lot of fun, and by that I mean lot of troubles, :P. First, the gyro drift subtraction does not work on yaw. I am using the magnetometer based on the information on this post:

http://forum.bitcraze.se/viewtopic.php? ... ilit=10dof

I tried that and then changed to something similar using tilt compensation, but it is the same. The yaw position is always locked. I was wondering why this happens. I already surfed the web a million times, :). The magnetometer datasheet says it can be used to have a 360 heading reading and there are numerous projects using it with tilt compensation to have the same effect. Does the magnetic field produced by the motors is so strong it locks the value?

Thanks.
--Luis

Re: Yaw from magnetometer locked in one position.

Posted: Tue Oct 22, 2013 8:07 am
by tobias
Great project and a big challenge. It might be that the magnetometer has saturated and needs to be set in a different sensitivity. Have you tried logging the raw magnetometer values?

One difficult thing with the magnetometer is to calibrate it from all the soft and hard iron effects caused by the surrounding magnetic fields. Before doing that the magnetometer readings are way off.

Re: Yaw from magnetometer locked in one position.

Posted: Fri Oct 25, 2013 5:29 am
by luisruiz
It is working! The yaw reading is spanning 360 degrees and it does not drift. :) I had to get lots of data to do the calibration and I removed data out of range.
magnetometerCalibrationCH9_05.png
X axis: Data point
Y axis: Angle

Re: Yaw from magnetometer locked in one position.

Posted: Fri Oct 25, 2013 12:11 pm
by tobias
Great achievement! Do you have your code on bitbucket?

Re: Yaw from magnetometer locked in one position.

Posted: Sat Nov 02, 2013 8:18 am
by luisruiz
Hello,

I do not have an account on bitbucket yet, : P. I was doing more testings and it seems the calibration does not work if the CF is tilted too much. More over, I think only the hard iron calibration is needed, the one that adjust the offset of the readings. Below is a graph of the raw data:
magnetometerCalibrationCH9_03.png
After hard iron calibration the norm is around 1, which means the sensor is OK. Now for both hard iron and soft iron:
magnetometerCalibrationCH9_04.png
The norm is also around 1. In both cases the output for the heading is almost the same, tested on the CF:
magnetometerCalibrationCH9_06.png
magnetometerCalibrationCH9_06.png (8.63 KiB) Viewed 5077 times
Now, the heading spans 360 degrees. To calculate the hard iron and soft iron matrices I used this information:

http://diydrones.com/forum/topics/compa ... n-magnetic

Now, back to the heading problem, has anyone been able to read the yaw angle effectively, whereas using the magnetometer or other methods?

Re: Yaw from magnetometer locked in one position.

Posted: Thu Nov 07, 2013 10:03 am
by marco.tognon
Oh really good job!! :D

But did you use the calibration method of ak1394 http://forum.bitcraze.se/viewtopic.php? ... ilit=10DOF or of Ozan Aktaş http://diydrones.com/forum/topics/compa ... n-magnetic.
I would understand what is the best and easiest method.