Shop OBEX P1 Docs P2 Docs Learn Events
HMC5843 Magnetometer for Tri/Quadcopter — Parallax Forums

HMC5843 Magnetometer for Tri/Quadcopter

A. ESERA. ESER Posts: 24
edited 2011-05-20 14:00 in Propeller 1
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 ?

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2011-05-17 19:36
    Sorry, you are ahead of my quad (lack of time :( ). Please post your results and any pics :)
  • th3jesterth3jester Posts: 81
    edited 2011-05-18 07:47
    I used the HMC6352. I only used it for a feedback signal to the end user. My main problem is flight stabilization. My quad-copter starts to oscillate after a few seconds. This was for a senior design and since the semester is over I am done working on it. Although I have started making a different version at home. Sorry I can't be much more help, other than checking out the HMC6352.
  • A. ESERA. ESER Posts: 24
    edited 2011-05-18 12:06
    @th3jester,
    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
  • th3jesterth3jester Posts: 81
    edited 2011-05-19 07:33
    Your tricopter looks great. I've spent numerous days tuning the PID and Kalman Filter. I've concluded the sensors pick up way too much noise and also the whole frame design is inherently unstable (motors are too close). Since this was a senior design I had to let the other team members make choices also. The next quadcopter I build will be much better and hopefully more stable. Thanks for the info on the digital compass, I did not know that about them. I wasn't too concerned at the time but I would've eventually ran into the same problem your having.

    What is going to be the functionality of your tricopter? sensors? surveillance? ect...
  • A. ESERA. ESER Posts: 24
    edited 2011-05-20 03:10
    @th3jester;

    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 :)
  • th3jesterth3jester Posts: 81
    edited 2011-05-20 06:34
    Thank you for the advice. The control board is actually suspended by fishing line in the center. We made a circular frame. It's fairly sturdy yet still noisy, I think the fishing line either amplifies the noise or the IMU isn't secured enough.

    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
  • A. ESERA. ESER Posts: 24
    edited 2011-05-20 14:00
    I am using complementary filter for attitude estimation (not Kalman not DCM)
    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
Sign In or Register to comment.