Why use a magnetometerNote: APM 2 has a magnetometer built in, but it needs to be enabled and declination set as part of the setup process. With APM 1, the magnetometer is an optional addition (see below) Current orientation of the aircraft and the direction the airframe is moving in (not necessarily the same) is an important input for navigation and stabilisation in ArduPlane. Without a magnetometer, the orientation of the plane is calculated using successive GPS fixes plus the inertial sensors: Sensor drift is compensated by reference to the GPS ground course, as that should fix the current compass point for the nose of the plane (assuming no wind or opposite rudder). With a magnetometer, we no longer have to rely on the GPS ground course to correct for sensor drift, and the orientation of the plane becomes more accurate. If you fly with a cross wind, either manually or under full autopilot control, then the magnetometer will provide more accurate fixes for sensor drift. At present ArduPlane navigation is not done by crabbing a straight ground track in a crosswind. Since this would confuse sensor drift correction over longer periods, flying without a magnetometer is less of a potential issue. Connecting the DIYDrones magnetometer (only needed for APM 1)
Method One: Using a cableYou can attach the HMC5843 magnetometer to the APM IMU shield's I2C sensor port, which looks like a GPS connector but says "No GPS". One reason to do this is you intend to daisy-chain other I2C sensors to your board. One way to do this is to modify a GPS cable, cutting off the connector on one side and soldering the wires to the right pads on the magnetometer board. You'll only be using four of the six wires; the other two can be cut off. Plug the connector into the shield and look at the bottom of the shield where you should see "SCL", "SDA", "+5V", "GND" written, corresponding to the four wires. These should be matched up to the same pins on the magnetometer, as shown below
Here's a picture of how it should look (we recommend threading the cable through the hole before soldering for strain relief):
Plug it in here:
Ensure that the small solder blob jumper on the magnetometer is set to 5V before connecting it. If it isn't, you should switch it as shown below:
Method Two: Mounted on the boardIf you don't plan on using the 4-pin I2C connector on the shield for anything else, you can mount the magnetometer directly on top. Again, check that the voltage solder jumper is in the 5V position, as discussed above. You can use a 4 pin breakaway header as a standoff. Take care to align the magnetometer and shield edges. Precision here will reduce the amount of trimming you have to do later. First, snap off the mounting area of the magnetometer:
Now, solder in the four pin header (example of the header shown on the table next to the board). It's best to solder the header with the long pins down, going through the board.
Finally, solder on the magnetometer component side down, as shown here:
To enable the magnetometer in the APM code, use the CLI and in setup mode, enter "compass on", as shown here:
You can test it in the CLI by going to the Test menu and typing Compass. Or you can load and run the APM_Compass_test in the Examples folder of the APM_Compass libraries of the APM code. Just load the sketch and view the data in the Serial Monitor of the Arduino IDE (38,400 baud). Sample data looks like this (when moving the board around a bit): Heading:23.04 (174,-74,4096) offsets(-87.00,37.00,-2048.00) Heading:22.82 (145,-61,4096) offsets(-87.00,37.00,-2048.00) Heading:9.62 (177,-30,4096) offsets(-88.50,37.00,-2048.00) Heading:7.50 (167,-22,4096) offsets(-88.50,37.00,-2048.00) Heading:31.54 (145,-89,4096) offsets(-88.50,44.50,-2048.00) Heading:28.94 (132,-73,4096) offsets(-88.50,44.50,-2048.00) Heading:15.85 (162,-46,4096) offsets(-88.50,44.50,-2048.00) Heading:22.88 (173,-73,4096) offsets(-88.50,44.50,-2048.00) Heading:-0.38 (152,1,4096) offsets(-88.50,44.00,-2048.00) Heading:15.84 (148,-42,4096) offsets(-88.50,44.00,-2048.00) Heading:10.28 (171,-31,4096) offsets(-88.50,44.00,-2048.00) Heading:24.47 (145,-66,4096) offsets(-88.50,44.00,-2048.00) Heading:40.25 (163,-138,4096) offsets(-88.50,68.50,-2048.00) Heading:34.28 (157,-107,4096) offsets(-88.50,68.50,-2048.00) Heading:26.72 (147,-74,4096) offsets(-88.50,68.50,-2048.00) Heading:51.87 (84,-107,4096) offsets(-88.50,68.50,-2048.00) Heading:49.44 (89,-104,4096) offsets(-88.50,68.50,-2048.00) Otherwise, you can test the sensor in the APM CLI, by selecting "compass" in the "test" menu. | |
Is there any way to connect magnetometer with GPS ?
Do you mean directly? No. You need some cotroller (like the ardupilot) between both components that merges the information into some output. This can be done by code on the ardupilot.
Thanx, I mean can we connect Magnetometer with APM without breaking GPS connection...
Heelo, since the Magnetometer is out of stock on DIY Drones, is this product ( http://www.coolcomponents.co.uk/catalog/product_info.php?products_id=407 ) fully compatible with the one you suggest? Thank you for your reply, Emile
Heelo, since the Magnetometer is out of stock on DIY Drones, is this product ( http://www.coolcomponents.co.uk/catalog/product_info.php?products_id=407 ) fully compatible with the one you suggest? Thank you for your reply, Emile
No, the Cool Components Magnetometer (CCM) is not fully compatible because (unlike the DIYDrones Magnetometer) it has no voltage regulator on board to convert 5V to 3.3V. The shield provides +5V on the I2C pad. So if you would connect the CCM directly, it would probably break down.
If you use an oilpan shield, the good news is that it has a 3.3V pad and uses 3.3V levels on SDA and SCL. You can connect GND, SCL and SCA from CCM to the shield, and the 3.3V pad on the shield to VCC of the CCM. With the alternative mounting option above: cut off or do not mount the VCC header pin and route a wire from 3V3 on the oilpan shield to the CCM.
I tested it using the arduino APM_Compass example, and it works fine.
@gumush - Yes you can use both gps and magnetometer with APM.
the gps cable has 6 wires, the magnetometer has only 4 the red cable stays in the corner I should remove the unused 2 cables I guess, but my question is 1 is red (corner) other 5 are black - witch wire goes where in the magnetometer board?
Also using the gps cable the voltage jumper needs to be in 5volts? I think that mine came with the jumper in 3volts - I never change any solder jump, should we pump the old solder first?
Do the SCL and SDA lines have pull-up resistors connected to them?
Looking at the schematics, it doesn't look like there are any pull-up resistors. There are some on the other side of the PCA9306, for the BMP085 pressure sensor.
The DIYDrones magnetometer is back in stock (on and off) so that option is available again: http://store.diydrones.com/HMC5843_Triple_Axis_Magnetometer_p/br-hmc5843-01.htm
But if you want to hitch up the sparkfun version you can find a very similar page to the one above on the arduCopter page including instructions on how to use the Sparkfun level converter:
@gumush - the connectors for the gps and the magnetometer are separate although they both use a JST connector so they look very similar. The GPS connects to the APM Board, the Magnetometer connects to the OilPan? near where it says "No GPS!".
Warning: after reading this post http://www.rcgroups.com/forums/showpost.php?p=16060851&postcount=707 I retested the SCL/SDA signals and while they are 3.3V at idle, they indeed swing to 5V in operation which exceeds the specs.
While I have not had any problems, I decided to be prudent and connect the Sparkfun magnetometer as suggested by peejay1981. After soldering 4 wires to the 50 mil pitch pins and going out in cold and snow to recalibrate the offsets, the mag still works as good as before.
I just got my magnetometer from the DIYDRONES store and soldered it on the SHIELD/OIL PAN as per the instructions above. The voltage jumper was already in the 5V position. When I run "test" in ArduPilotMega? 1.0-Beta, then "compass" the response I get is "Compass disabled". My ideas as to what is wrong. Can't see that there is anything in the header file that needs to be changed. Any help would be appreciated.
@esmith289, I see that in config.h (http://code.google.com/p/ardupilot-mega/source/browse/ArduPilotMega/trunk/config.h?r=1840) around line 151 it says that mags aren't supported in v1.0 but I'm sure they're working on supporting mags (if they don't already). // MAGNETOMETER // NOTE - There is no support for using the magnetometer in v1.0 #ifndef MAGNETOMETER # define MAGNETOMETER DISABLED #endif
If you just want to check if your mag works or not, how about loading the test sketch from the AP_Compass library? from Arduino IDE select: File, Example, AP_Compass OR alternatively you can find the sketch in subversion here: http://code.google.com/p/arducopter/source/browse/trunk/libraries/AP_Compass/examples/AP_Compass_test/AP_Compass_test.pde?r=1108
-Randy
Yeah, thanks. I just found the note that the magnetometer is not supported in 1.0. I uploaded the test and it looks like it works. Thanks for your response.
Hi today I install APM V1.01 I have the sparkfun magnetometer so I have 2 question, this version support magnetometer? if the answer is affirmative how I should set up/config I tried to obtain data via console but the message was "magnetometer is inactive" or something like that. I will appreciate any help.
Remessino: it is supported in the quadcopter code, but not the aircraft code (APM 1.0) yet.
Does anyone have any idea how to interface the Ardupilot Mega with the PNI MicroMag? 3-axis?
We don't have a ready made library to do that so it will take some work. It looks that mag uses a 3.3V SPI interface. I think this means you would need to connect it to the same SPI bus as we use for the Analog to Digital converters which is apparently pins PH1, PH2, PH3 and then another pin for chip select (PH6?).
You can see the AP_ADC library that does the current communication with the analog to digital converters to see how to do it.
This would require some serious work though...
I'm working on MicroMag3? support: http://www.diydrones.com/forum/topics/micromag3-support
In terms of the Accuracy of the device, is there an advantage to having the magnetometer on a cable versus soldered directly onboard?
@Jim,
So now that we are at Version 2.x, is the magnetometer supported? Also, the reference above to setting the offsets in the CLI... I can't see any way to do that. I also don't see anything in the code itself. How do I set the offsets.... if it is supported at all.
Yes, the magnetometer is supported in 2.X, with the enhanced feature that offsets are set automatically. A calculation is made based on movement of the airframe as sensed by the IMU and corresponding change in the magnetic field vector. Every minute the estimated offsets are stored to EEPROM. It will take several minutes of flight time for the estimated offsets to converge to the proper values, so you should not expect the heading data to be accurate during your first fight while this is occurring. This method allows for more accurate offset measurement as the measurement takes place during flight and accounts for magnetic fields produced by the propulsion system.
We have intended to use the magnetometer to calibrate the gyros and accelerators in flight, is this possible? The planned flight time is around one hour, will the gyros and accelerators be messed up during this time?
@Marvel,
-Ramdy
I have a problem with the magnetometer. I have it mounted directly on the board. When I test it, turning the plate around its x axis (axis facing the GPS) magnetometer signal interprets the plate is rotating clockwise about 90 degrees. If I rotate the board around it X axis, magnetometer signal shouldn't change. I have tested it with version 2.01 and 2.012 and got the same problem.
JM: actually, all magnetomters are affected by tilt, as you describe. The better question is does it correctly respond to rotation around the Z axis (the normal yaw axis). If not, it may be a bad board and you should contact DIY Drones customer support.
@JM - as analogue says - all mags are affected by tilt...in fact, the Z component of magnetic north is much much bigger than the x/y components so they're affected a lot. Still, if you tilt your plane 45 degrees, you shouldn't see more than 10~15 deg variation. If you see 80 deg variation then something is wrong...perhaps the orientation isn't set correctly in your APM_Config.h. It should like like below: #define MAG_ORIENTATION AP_COMPASS_COMPONENTS_DOWN_PINS_FORWARD
It sounds like you're getting values out of your mag so I suspect it's working a-ok. In the dozens of mag problems I've seen people have, invariably it either works (i.e. you get numbers) or it doesn't (you get all zeros).
Last thing is the mag offsets. I believe the latest version of the arduPilot code calculates these automatically for you and saved automatically to the EEPROM...this calculation happens quietly in the background meaning that your first flight might have less than perfect mag offsets. Maybe waving your plane around for a few minutes while on the ground will allow the offsets to be calculated correctly in the background.
-Randy
Thanks for your response! I have reloaded a new version of the code and now it is working propertly. I still dont`t know that went wrong.
Hi,
I have a look at the board layout and here is what i can see : https://docs.google.com/leaf?id=0B3iXljcenXytNjZmODIzMmYtOTkwYi00ZjEzLWExODEtOWRmZmM1Nzg1YTZk&hl=fr&authkey=CJas4JkJ .
It seems that the cable method doesn't match with the board layout. Am I wrong :-/ ?
greg: I'm afraid I don't understand your question. Can you please explain further?
I should apologize for my really bad english...
So, i want to use the "Method One: Using a cable". This method use the first four right pins of the em406 connector. On the eaglecad board layout, only the pins 1,3,4 and 5 (left to right) seems to be wired.
That's why i'm a little confused.
Sorry, but I don't have the hardware in front of me. But many hundreds of people have done this already without any reports of issues, so I'm assuming it's right. Have you checked with a multimeter?
I have checked with my multimeter and it seems you're right : gnd on the pin 6, +5V on the 5, sda and scl on 4 and 3...
But, i bought two of these board : http://store.diydrones.com/I2C_Splitter_p/br-0009-02.htm Only four pins are distributed and pin 1 is surely one of them. I want to check before I cut my EM-406 cables and at first sight it can't run with the i2c splitter.
I have to try anyway. thanks for your replies.
greg, you know, you don't actually need to cut the EM-406 cable. If you look closely on the underside of the white connectors you'll see a tiny little flap, if you pull it up with a toothpick you can pull out the wire cleanly. I do this whenever I need to modify a GPS cable to work with the mag.
I have mounted the HC5883 on my APM and the bridge was already soldered on 5V!
the compass worked for one start and now he is only answers: !!initialisation failed!!
i have already made a reset and flashed the ardupilot mega 2.2.1 but nothing helps
maybe someone has an idea
thanks
I want to estimate Euler angles from the magnetometer readings. But, I'm not able to understand the readings from magnetometer. Magnetometer should give magnetic field strength in x,y, and z directions(Mx, My, Mz). Are the three numbers printed beside heading in braces are Mx, My and Mz values. If so, the absolute value of magnitude of the three values(sqrt(Mx*Mx + My*My + Mz*Mz)) should not change during rotations. When I'm printing this magnitude, the value changes drastically even for small rotations. I just want to measure Mx, My and Mz. How do I get these from the magnetometer?
Thanks Mohan
Hi :-) I've HMC5843, mounted upside down via header pins (as advised above) and APM 2.21. When I place APM on 0 deg course, APM Planner shows about 180 deg. What's wrong?
regards Marcin
mkraw: have you enabled the mag and set the declination as part of the config process?
Yes, all set according to docs. Declination in Warsaw/Poland seems to be +4,52 :-)
And you're sure your APM board is pointing the right direction?
If Google maps isn't wrong.. :-)
Hi; I can not see data from my compass, It says Initailisation Failed. any idea?. the borad is faulty or software problem?. I checked by APM also no luck, i checked the box on harware APM menu. is the board blown?
@rmackay9@yahoo.com
I have the same board. I think that the axes are reversed for x or y (depending on which you make right:))I was wondering the same thing, and am hoping that there is some adjustment that can be made in the software. There is no way to mount it so that all three axes coincide witht the DIY version.
Here is what i found http://code.google.com/p/arducopter/wiki/Quad_Magnetos
Folks, get a 3.3V unregulated version on ebay. It's only $15.00 as opposed to this one for $44. Can't believe a voltage regulator can inflate the price by that much. (Use the method mentioned above to get it working)
http://www.ebay.com/itm/HMC5883L-HMC5883-Triple-Axis-Magnetometer-Sensor-board-/260770948278?pt=Radio_Control_Vehicles&hash=item3cb728e4b6#ht_998wt_850
Seems that FW 2.23 fixed my problem. Great work, guys :-)
@mkraw - ok, you can thank Tridge for that. He found a few problems in the initialisation code.
I've seen his "investigation" before - great work, so I was waiting for new F/W release impatiently ;-)
So, I just installed $15 version of the HMC5883L board I bought on ebay, and did the trick to use the 3.3v on the IMU, instead of the I2C bus. All seems to be working with the compass test. So, the heading is supposed to read zero when the front of my quad is pointing to north. Is this right?
well done. zero is north, 90 is east.
also bought new item from ebay, i already replaced magnetometer from diydrones it worked some time and died again. 5v switch is correct of course. very strange and nastily :)
The wiki says: "At present ArduPlane? navigation is not done by crabbing a straight ground track in a crosswind." However, I've noticed the autopilot will grab to maintain a ground track towards the waypoint in HIL mode. Is something implemented differently in HIL mode?
did any1 ever used the DIY drones i2c level converter http://store.diydrones.com/I2C_SMBus_Voltage_Traslator_I2C_Level_Shifter_p/br-0009-01.htm to connect the Sparkfun 10530 magnetometer? As my system crashes all the time I connect this combo.
My magnetometer (HMC5843) is working fine when checked with AP_Compass_test. But if I load the ArduPlane? code, Mx, My, Mz values don't change as much as they should, and the indicated heading is always 40 deg +/-few degrees. This problem started happening during the last flight. The mag heading was working fine with APM 2.28 before that. Any idea what's going on?
Problem got fixed by erasing EEPROM.
Intersting question: IF: magnetometer is completely bananas, influenced by a power cable or completely wrong declination is entered: is it possible that the airplane/quad/etc will fail to get home, or to a desired position (but fly in completely wrong direction) - or is there GPS verification ?
the reason I am asking - is that MikroKopter? is totally unreliable because of it's blind dependency on magnetism, and any bad calibration on new spot, or too far from the spot, can make it run away - badly.
In the plane code you can rely on just GPS (I think but not 100% sure) without the mag because planes tend to fly straight ahead. On a quad/heli though you definitely need a mag - we don't do any comparison of the GPS vs Mag heading to figure out if one of them is wrong. We have some pretty fancy magnetometer code though in the form of automatic nulling of offsets..so normally it works ok.
Can anybody explain what's going on here ? : http://code.google.com/p/ardupilot-mega/issues/detail?id=537&q=magnetometer
I've never got the compass to act reliably, mounted on APM, away from power cables.
I've put comments in the issue you've linked to above. It's just mag offsets.