Yaw from magnetometer locked in one position.

Firmware/software/electronics/mechanics
Post Reply
luisruiz
Beginner
Posts: 14
Joined: Fri May 31, 2013 7:39 am

Yaw from magnetometer locked in one position.

Post 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
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Yaw from magnetometer locked in one position.

Post 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.
luisruiz
Beginner
Posts: 14
Joined: Fri May 31, 2013 7:39 am

Re: Yaw from magnetometer locked in one position.

Post 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
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Yaw from magnetometer locked in one position.

Post by tobias »

Great achievement! Do you have your code on bitbucket?
luisruiz
Beginner
Posts: 14
Joined: Fri May 31, 2013 7:39 am

Re: Yaw from magnetometer locked in one position.

Post 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 5078 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?
marco.tognon
Member
Posts: 38
Joined: Mon Sep 16, 2013 10:22 am

Re: Yaw from magnetometer locked in one position.

Post 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.
Post Reply