Pages: [1] 2   Go Down
Author Topic: [SOLVED] Obtaining Magnetic Declination  (Read 2904 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been working on a mobile project that needs to know the direction of true north.

I am using the Venus GPS from Sparkfun which according to the datasheet does not populate the declination field.

The alternative seems to be to try to compute the declination and then use a compass to find magnetic north. I own the Pololu LSM303DLH. I am using an Arduino Mega 2560 so I imagine I have enough room to do this quite accurately even with the rest of the code for the project. Does a library for computing magnetic declination exist for the Arduino?

Failing that I notice that there are libraries for this written in C, for example, NOAA's World Magnetic Model software. The code itself does not seem to vast, 4000 lines of mostly comments and printf statements along with a 2kb coefficient file. Would it be unrealistic to try to include this library directly in an Arduino sketch (perhaps with some wrapping)?

I'm really not sure the best way to approach this but I would like to be able to reasonably accurately compute magnetic declination in and around Europe and Northern Africa for the next 3 -5 years and in a way that will be easy to update in the future. Any guidance?
« Last Edit: October 21, 2012, 05:26:50 pm by Bob101 » Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2313
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
4000 lines of mostly comments and printf statements along with a 2kb coefficient file.

You only have 2k of data space in the uno so no chance. But the mega should be able to do this. You will need to strip out all the printfs and some /all the includes. You can't use stdio.h for example.

For the UK the difference between true and magnetic north is give on the OS maps and does not change over the 3/5 years you want.

Mark
Logged

0
Offline Offline
Shannon Member
****
Karma: 207
Posts: 12194
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the GPS can be oriented in line with the vehicle's axis and a magnetometer/compass (is there a vehicle?) then heading bearings can be used to calibrate the declination.  Assuming the compass has compensation for nearby iron masses...
Logged

[ I won't respond to messages, use the forum please ]

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You only have 2k of data space in the uno so no chance.

Wrong.  You have 32kb of program flash and the PROGMEM macro, so if your program will fit in the 30k left, no problem.

-j
Logged

Leighton Buzzard, UK
Offline Offline
Edison Member
*
Karma: 21
Posts: 1339
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suspect you mean magnetic deviation (difference between true and magnetic North)
declination is the angle the local magnetic field makes with the horizontal
(I theenk!)
Logged

there are only 10 types of people
them that understands binary
and them that doesn't

0
Offline Offline
Shannon Member
****
Karma: 207
Posts: 12194
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Magnetic variation or declination is the difference between magnetic and true north at a particular place and time.  Magnetic deviation is the difference between the magnetic field in a particular situation compared to the background field, caused by magnetic objects near to the observer including man-made magnetic materials and magnetic rocks in the crust.
Logged

[ I won't respond to messages, use the forum please ]

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you consider the option to use external storage for data like the cof file. (e.g. I2C EEPROM or SD CARD)

Advantage of the SD CARD is that you could log some readings too...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suspect you mean magnetic deviation (difference between true and magnetic North)
declination is the angle the local magnetic field makes with the horizontal
(I theenk!)

Magnetic declination is the angle between magnetic north and true north. Magnetic deviation is the error introduced in a compass by local magnetic fields (eg... by nearby iron or electromagnets). I was, as I originally stated, interested in declination.

If the GPS can be oriented in line with the vehicle's axis and a magnetometer/compass (is there a vehicle?) then heading bearings can be used to calibrate the declination.  Assuming the compass has compensation for nearby iron masses...

The unit will be used on a vehicle although only when the vehicle is stationary. I suppose that the unit could detect when the vehicle is moving quickly in a straight line (using the GPS) then attempt to calibrate the compass. I hadn't really considered that. Quite a neat idea.

I have thought a bit more about this and I am starting to get cold feet. The project I am interested in is a vehicle mounted solar tracker that will be used in Europe and northern Africa to keep our leisure batteries topped up. Looking at the magnetic declination currently I see that from Agadir (western Morocco) to Istanbul (eastern Europe) and from Oslo (northern Europe) down to Nairobi (central Africa) the magnetic declination only varies from -8 deg to +4 deg. If we didn't correct for it at all our panel would be 8 degrees out in its positioning which would still provide very nearly cos(8 deg) = 0.990... of the energy falling on it.

On the other hand... it would be cool to just have an Arduino compatible magnetic declination library (especially something like a port of the NOAA library). In North America you have it a lot worse with declinations ranging from -14 deg to +18 deg, cos(18 deg) = 0.951... still not terrible actually but it would visually look like it was facing the wrong direction at nearly 20 degrees out!

Thanks so much for all these ideas and it does certainly look like creating such a library would be possible. I'm just not sure if I REALLY need it  smiley-confuse.
Logged

Nice, France
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe magnetic declination is indeed the correct term.

this article on the HMC5843 three axis magnetometer may be helpful, as it mentions adjusting for magnetic declination.

The Ardupilot community deal with this stuff, so I suggest looking at their (extensive) libraries. Indeed they have an AP_Declination library on their github.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nantonos, you gem.

The article you link to is a bit general and essentially tells you how to find out a single declination for where you are currently so that is not so helpful.

HOWEVER, the library you link to is based on this post (says so in the comments of the code). This guy has tried to do exactly what I was going to attempt. This didn't work so well so he wrote his own software that he can update using the NOAA tables. It looks like he has updated it since the last table was released so I should be good for the next 3 years. I am going to give this library a go.

Thank you so much!
Logged

0
Offline Offline
Full Member
***
Karma: 5
Posts: 238
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe the easiest thing to do is to get g different GPS that outputs the declination.
Logged

Leighton Buzzard, UK
Offline Offline
Edison Member
*
Karma: 21
Posts: 1339
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oops
sorry for mis-information
better to have everyone think you're a fool than to open your mouth and prove it smiley-sad
Logged

there are only 10 types of people
them that understands binary
and them that doesn't

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 208
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why not just find out what the magnetic declination is for your area and adjust for it in your code? For example: my location in Ohio is 8 degrees 15 minutes west of grid or true north so I would just add 8 to my azimuth to find grid north. Depending you exact your direction needs to be, you could use decimals. Don't forget to convert minutes to a decimal. multiply by 1/60

This will use your ip address to give your magnetic declination:
http://magnetic-declination.com/
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nantonos: That library looks like the best way to go. I haven't had chance to try it out yet and as it happens I'm probably not going to get time for at least 2-5 days. I will update when I have had chance.

Maybe the easiest thing to do is to get g different GPS that outputs the declination.
Easiest and most accurate, true. I've already soldered up my GPS unit and it wasn't too cheap. If I was to start out again I'd probably go for a unit that can output declination.

oops
sorry for mis-information
better to have everyone think you're a fool than to open your mouth and prove it smiley-sad
Hardly! I've done far worse things smiley-yell.

Why not just find out what the magnetic declination is for your area and adjust for it in your code? For example: my location in Ohio is 8 degrees 15 minutes west of grid or true north so I would just add 8 to my azimuth to find grid north. Depending you exact your direction needs to be, you could use decimals. Don't forget to convert minutes to a decimal. multiply by 1/60

This will use your ip address to give your magnetic declination:
http://magnetic-declination.com/
The unit will be mounted on a vehicle without internet access and toured all over Europe. As I said earlier though: "Looking at the magnetic declination currently I see that from Agadir (western Morocco) to Istanbul (eastern Europe) and from Oslo (northern Europe) down to Nairobi (central Africa) the magnetic declination only varies from -8 deg to +4 deg. If we didn't correct for it at all our panel would be 8 degrees out in its positioning which would still provide very nearly cos(8 deg) = 0.990... of the energy falling on it."
Logged

Leighton Buzzard, UK
Offline Offline
Edison Member
*
Karma: 21
Posts: 1339
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

me again!

+12 degrees in Northern Finland
Botswana -11 degrees

trouble is magnetic substrata can have a massive local effect

I recall seeing aeronautical isocline charts for Scandinavia with loops and whorls like a fingerprint
Logged

there are only 10 types of people
them that understands binary
and them that doesn't

Pages: [1] 2   Go Up
Jump to: