HMC5843 Magnetometer for Tri/Quadcopter
A. ESER
Posts: 24
Hi all,
I am working on a propeller based quadcopter project. I have managed basic flight stabisation and autoleveling. Now I am trying to add HMC5843 3 axis magnetometer as a tilt compansated compass. I have used Tim Moore's HMC5843 Driver 1.2 from OBEX. but I ommited LMM parts. See attached file. This worked for me.
The problem is tilt compansating heading calculation. When the board is level heading is true, but when its tilted heading is deviate to much. I mean tilt compansating does not work. Here is the tilt compansated heading calculating code.
Cos_Pitch := f32.Cos(f32.Radians(Pitch))
Sin_Pitch := f32.Sin(f32.Radians(Pitch))
Cos_Roll := f32.Cos(f32.Radians(Roll))
Sin_Roll := f32.Sin(f32.Radians(Roll))
compass.GetData(21,hmc5843, @Mx, @My, @Mz)
Mx_f := f32.FFloat(Mx)
My_f := f32.FFloat(My)
Mz_f := f32.FFloat(Mz)
' Xh = Mx * cos(pitch) + My * sin(roll) * sin(pitch) + Mz * cos(roll) * sin(pitch)
' Yh = My * cos(roll) - Mz * sin(roll)
Head_X := f32.FAdd(f32.FAdd(f32.FMul(Mx_f,Cos_Pitch),f32.FMul(f32.Fmul(My_f,Sin_Roll),Sin_Pitch)),f32.FMul(f32.FMul(Mz_f,Cos_Roll),Sin_Pitch))
Head_Y := f32.FSub(f32.FMul(My_f,Cos_Roll),f32.FMul(Mz_f,Sin_Roll))
Heading := f32.Degrees(f32.Atan2(f32.FNeg(Head_Y),Head_X))
Any idea ?
I am working on a propeller based quadcopter project. I have managed basic flight stabisation and autoleveling. Now I am trying to add HMC5843 3 axis magnetometer as a tilt compansated compass. I have used Tim Moore's HMC5843 Driver 1.2 from OBEX. but I ommited LMM parts. See attached file. This worked for me.
The problem is tilt compansating heading calculation. When the board is level heading is true, but when its tilted heading is deviate to much. I mean tilt compansating does not work. Here is the tilt compansated heading calculating code.
Cos_Pitch := f32.Cos(f32.Radians(Pitch))
Sin_Pitch := f32.Sin(f32.Radians(Pitch))
Cos_Roll := f32.Cos(f32.Radians(Roll))
Sin_Roll := f32.Sin(f32.Radians(Roll))
compass.GetData(21,hmc5843, @Mx, @My, @Mz)
Mx_f := f32.FFloat(Mx)
My_f := f32.FFloat(My)
Mz_f := f32.FFloat(Mz)
' Xh = Mx * cos(pitch) + My * sin(roll) * sin(pitch) + Mz * cos(roll) * sin(pitch)
' Yh = My * cos(roll) - Mz * sin(roll)
Head_X := f32.FAdd(f32.FAdd(f32.FMul(Mx_f,Cos_Pitch),f32.FMul(f32.Fmul(My_f,Sin_Roll),Sin_Pitch)),f32.FMul(f32.FMul(Mz_f,Cos_Roll),Sin_Pitch))
Head_Y := f32.FSub(f32.FMul(My_f,Cos_Roll),f32.FMul(Mz_f,Sin_Roll))
Heading := f32.Degrees(f32.Atan2(f32.FNeg(Head_Y),Head_X))
Any idea ?
spin
20K
Comments
HMC6352 is the chip, I used before. I upgraded my board from HMC6352 to HMC5843. HMC6352 is a 2 axis compass. It is useless on quadcopter, because it has no tilt compansation. Without tilt compansation 5 degree tilting on pitch or roll axis can couse 30 degree heading error. I need tilt compsated heading for GPS position hold and way point navigation.
If you have oscillations try decrease differantial gain (gyro gain)
@Cluso99
my tricopter test flight http://vimeo.com/23909597
What is going to be the functionality of your tricopter? sensors? surveillance? ect...
My control board is rather old (analog gyros and accellerometers IDG500 - IXZ500 - ADXL335) i will switch to I2C sensors ITG3200 and ADXL345 etc. when I design a new board.
Up to this point;
* basic flight stabilisation - done
* autoleveling - done
* heading hold with gyro only - done
* heading hold with gyro+magnetometer - ( I am TRYING TO !!!!)
* altitude hold with barometer - to do
* GPS postion hold - to do
* Way Point Navigation - to do
but firstly I will move to quad frame because tricopters tail assembly is a big disadvantage (mechanical complexity and failure point)
I few tips for your project;
* do not assamble control board to frame. Attached it with o-rings tigthly (but it should move when you push with your finger). This will help for sensor noise.
* do not filter gyro signal (low pass filters etc makes control unstable)
* do not use DIFFERANTIAL ERROR = ANGLE - ANGLE_PREVİOUS, use DIFFERANTIAL ERROR = GYRO_VALUE
I hope these helps
And I hope there is someone experienced with HMC5843
All my sensors are I2C also, I'm using the Nintendo Wii MotionPlus and Nunchuck which I believe are the IDG-500 (or 300) and the ADXL-330. Or something close.
I'll try taking out the angle_previous in my PID. I see how that would greatly affect the output.
Are you using any kind of software filtering? DCM or Kalman?
I'm considering buying one of those HoverFlyTech boards, http://www.hoverflytech.com/, because all the other functions of my quadcopter works except stable flight. We'll see.
Here's a link to what my quadcopter entails. http://forums.parallax.com/showthread.php?131124-Visitor-brought-fascinating-things-to-Parallax-today-%28quadcopters!%29/page2
its soo simple, but It works.
angle = (0.98)*(angle + gyro*dt) + (0.02)*(x_acc);
x_acc is the angle calculated from accelerometer.
at my last post I wrote "do not filter gyro signal (low pass filters etc makes control unstable)"
I mean no filter other than attitude estimation filter