View RSS Feed

pyjamasam

The DIYDrones HMC5843 breakout board and the Ardupilot Mega/Oilpan.

Rate this Entry
I am slowly working through validating all the diffrent parts of hardware for my Quad and I got to the Compass today.

With the break-away sides removed it fits nicely on-top of the Oilpan. The I2C holes line up well. It does stick a little off the end, but thats ok.

The only problem is that the axis directions of the board are now different from the ones for the APM/Oilpan.

I have been using the mounting orientation that arducoptor guys are using. The servo and RX connections (and relay) are at the "back" of the quad. GPS connector is at the front.

With the APM orientated this way the HMC5843 is oriented out by 90 degrees clockwise.

Software to the rescue. Its easy enough to correct in code.

The easiest way to do this is swap the X and Y readings, and then invert the Y reading.

This brings things back to the correct orientation and you now get correct readings that are pointed the same way as the APM board.

While I was going through the process of testing things I stumbled across a very helpful tool. Its a combination Arduino sketch and a Processing sketch.

It lets you visualize the magnetic readings as you move the board around. It really helped me find out how things were oriented and how they should be orientated.

The code is originally from here: http://www.evilmadscientist.com/article.php/fields
(Scroll down to a little past half way. They use the HMC5843 to demonstrate magnetic fields.)

I have modified the Arduino sketch to perform the changes I described to get the sensor "pointing" the right direction when mounted on the APM board. But you can easily comment out the code to see it in its native orientation.

You are going to need the HMC library to use this test. Its available here:
http://eclecti.cc/hardware/hmc5843-m...ry-for-arduino

You can also use the APM library for the sensor, but you'll have to tweak the code to use that. Though its basically the exact same library, so it doesn't much matter.

The processing sketch is almost stock, I just commented out the line that prints out the calculated readings as it gets them.

You can see the magnetic readings plotted in 3d as you move the board around.

If you spin the board around all its axis you should get something resembling a sphere after a little bit.


When you exit the Processing sketch as well it will print the max, min, and offset for each axis. Its quite useful and makes scaling the data easy.

The other thing I learned is how the "dots" should show up as you move things around. This enabled me to sort out the axis swapping and inverting. The information I gathered is as follows.

X Axis - Roll
- Tip front edge of board down dots go cw
- Tip up dots go ccw

Y Axis - Pitch
- Tip right edge of board down dots go ccw
- Tip up dots go cw

Z Axis - Yaw
- rotate ccw dots go cw
- rotate cw dots go ccw

So the next step is to perform the roll and pitch correction to get a valid compass reading even when the quad is pitching left and right.

The boys over in this forum thread seam to have that all organized as well.
http://aeroquad.com/showthread.php?6...hlight=HMC5843

Hope this helps anybody else who is trying to get this stuff all working together.

chris.
Attached Thumbnails Attached Files
Tags: None Add / Edit Tags
Categories
Uncategorized

Comments

  1. TCIII -
    TCIII's Avatar
    Chris,

    Are you using the DIY Drones Store magnetometer as you said that you snapped off the ends of the board before using it?

    Also there may be a problem mounting the Magnetometer directly to the IMU Shield as it may not be possible to avoid magnetic fields near the APM/IMU Shield.


    Regards,
    Tom C
    Updated 07-12-2010 at 05:02 PM by TCIII
  2. pyjamasam -
    pyjamasam's Avatar
    Ya Tom,

    I am using the DIY Drones one.

    Here is a shot of it mounted.


    I am not noticing any really bad magnetic disturbances with it mounted there, but what I am noticing is that I can't sort out its axis orientation.

    Comparing the DIYDrones board to the Sparkfun board the axis seam to be laid out in different directions (when comparing the chip its self based on the printed label). And the Datasheet shows the axis labeled from the bottom, with reference to pins, but nothing showing which way the chip is supposed to actually be (no identifying mart, no key, just pin-outs that I of course can't really sort out cause they are UNDER the chip once its soldered down.).... Sigh.

    There also doesn't seam to be any information on what way readings are supposed to go. Which way is positive, which way is negative.

    I spent a VERY frustrating weekend trying to get a tilt compensated heading out of the unit and my code and I basically just hit the wall every time.

    Re-using code from other (and I assume working) AHRS systems out there (Aeroquad, Arducoptor, ArduIMU, and the Sparkfun 9DOF unit) didn't give me any workable results. As soon as I pitched or rolled the board the compass went off on its own and gave me a silly heading..

    Those other implementations (which are all basically the same code) also seam to throw around negative signs as they feel like it. But again without some sane information about which way readings "go", its all useless.

    I am assuming that I have something wrong with respect "fixing" the orientation of the device (which axis is which and the sign's of said axis)

    At this point I am all but going to give up on this. I know there is something silly going on, but for the life of it I can't wrap my head around the math to sort it out.

    All in all a very frustrating weekend of "trying" to code.

    chris.
  3. TCIII -
    TCIII's Avatar
    Chris,

    Sorry to read about the axis orientation issue. Sometimes stepping back for a while will put a fresh perspective on the problem, especially if there is input from other interested parties.

    Regards,
    Tom C
  4. pyjamasam -
    pyjamasam's Avatar
    I made progress over the last few days. Mostly it came from giving up on the mounting and orienting the sensor in a better way.



    This orientation now matches what ArduIMU uses and the code that exists for that platform works much better now. (they invert all axis and swap X and Y).

    I managed to cobble together a working IMU now.
    I have a number of algos coded up for testing.
    So far the collection consists of:
    SimpleAccellOnlyIMUFilter,
    ComplimentryMUFilter,
    DCMIMUFilter -> this doesn't work yet. Need to sort out why,
    KalmanIMUFilter,
    and QuaternionIMUFilter -> the implementation isn't done on this one yet.

    These are all collected from around the interwebs and all the credit goes to to their original authors (comments in the code show where I got each implementation.)

    Right now I am using the KalmanIMUFilter and its working quite well.

    So far I have GPS and the IMU running now, and have started working on the Pressure sensor.

    If your interested I have checked in my code at http://code.google.com/p/aeroquad/so...asam/Aeroquad2

    Its all still a work in progress, and it isn't anywhere close to even thinking about flying. But its my stab at converting things to a purely modular and OO layout.

    Tom in your case I'd be curious to hear any comments you might have on the IMU workings. (well any part of the system so far).

    chris.
  5. TCIII -
    TCIII's Avatar
    Hi Chris,

    Nice progress. Glad to hear that you have sorted out the Magnetometer issue. I was planning on doing the kind of mount that you have adopted. I have an ArduIMU with the Magnetometer attached in the same position as you are using on the IMU Mega. I will be on PTO next week and will try to give your code and hardware setup some time on the bench.

    Regards,
    Tom C.
  6. TCIII -
    TCIII's Avatar
    Chris,

    I got the Magnetometer working with my IMU Mega, however I used connectors between the I2C four pin connector and the Magnetometer. Also, I could not get your code to compile correctly so I used the APM code and found that it worked just fine. However the readings from the Magnetometer are 180 degrees out, but no matter as it is just a coding problem that needs to be adjusted.

    Regards,
    Tom C
    Updated 07-16-2010 at 11:23 AM by TCIII (Too early in the morning to be typing!)
  7. pyjamasam -
    pyjamasam's Avatar
    Quote Originally Posted by TCIII
    Chris,

    I got the Magnetometer working with my IMU Mega, however I used connectors between the I2C four pin connector and the Magnetometer. Also, I could not get your code to compile correctly so I used the APM code and found that it worked just fine. However the readings from the Magnetometer are 180 degrees out, but no matter as it is just a coding problem that needs to be adjusted.

    Regards,
    Tom C
    Hmm. What didn't work when compiling? I did check some stuff in last night and I may have broken things. Oops. hahaha.

    As for the 180 degrees out, it might be because the APM_Compass code doesn't swap and invert all the axis the same way the ArduIMU code does.

    What I found that works is that X = Y, Y = X, Z = Z and everything needs a - before it. (these are the raw x,y,z readings as they come out of the sensor).

    chris.
  8. beez -
    beez's Avatar
    I want to mount the magnetometer remotely. I have purchased an extra six pin GPS cable to use the I2C connector on the edge of the MIMU but I dont know the pinout of that connector so I can solder the other end of the cable to the magnetometer board. Anyone have this info or a pointer to it? Thanks! Beez
  9. TCIII -
    TCIII's Avatar
    beez,

    Here are the pinouts of the IMU Mega I2C connector based on the Eagle schematic and pwb layout:


    1 DRDY
    2 GND
    3 SDA
    4 SCL
    5 VCC
    6 GND

    The I2C 6 pin connector's pin closest to the edge of the board is pin 1. However, I used a four pin connector on the pads directly behind the I2C 6 pin connector to connect to my Magnetometer so I could use the I2C connector for other devices.

    Just a thought.

    Regards,
    TCIII
    Updated 07-22-2010 at 01:52 PM by TCIII (After thoughts, always after thoughts!)
  10. beez -
    beez's Avatar
    I thank you very much! Motors and stuff just came in from Hobby King so it's getting to be arducopter time for me!