I have been playing with avr for some years now and have become quite proficient at assembler language.

I have a new project that I am working on. It uses 2 gps units that are at a distance of no more than 1 mile apart. gps A receives the co ordinates of gps B via a radio link. gps A then needs to calculate a bearing and distance to gpsB. I intend to use a separate micro at gpsA to parse gpsA"s position and receive B's position. then feed the 2 lat longs to an atmega 162 via usart to do the math. I have looked at the math required and its way beyond what I can do in assembler.The final output only has to be accurate to 5 or 10 degrees and distance to 200 feet, therefor if there is a shortcut in the math that would also work

Does anyone have a c file that can do this or point me in the right direction.

Many thanks Bazza.

## gps angle

Do it in C.

I am reasonably proficient in assembler, and this is something I would never attempt in assembler.

Jim

http://www.movable-type.co.uk/sc...

Should be easy to use the basic formulae given there or the example Javascript in C.

Try doing a haversine in assembler! I think his problem is not the equations, but the fact that he can't figure out how to do it in assembler.

Jim

My problem is I do not know "C"

I am intending on learning C but I think this will be too complicated a project to learn a new language on.

Bazza

If your not talking about very great distances, just join the 'Flat Earth Society'. :D

Ignoring the sphericity, given positions A and B, subtract the two from each other to obtain the difference in latitude and longitude... Dx Dy.

Bearing is then atan2( Dy, Dx)... rotated 90 degrees, of course

Distance is sqrt( Dx^2 + Dy^2 )

EDIT

I just saw you don't know C. I think this could be a great project to become familiar with it!

I am intending on learning C but I think this will be too complicated a project to learn a new language on.

You could turn that the other way around.. Since this project obviously involves some "advanced" math operations, this would be an excellent opportunity to see one of C's advantages over assembler.

Here's my program that calculates distance between two lat longs using the haversine formula. My goal was to test the 64bit double prescision floating point routines in the imagecraft v8.11 c compiler and time how long the calcs take. You could look at the jpl haversine formula in the comments, then look at the subroutine that calculates it and see if it looks enough like regular old algebra that its not terrifying and scary, then step 3 would be dl the iccv8 compiler which has a free 45 day demo and compile it and run it, and step 4 might be dl AtmelStudio and recompile the whole thing using single precision fp and see if it still has sufficient accuracy. Probably will.

## Attachment(s):

Ed William's Aviation Formulary is a must have link for anyone doing Great Circle Route, (or flat earth approimations), calculations.

JC

Novatel do have receivers that will do this for you- but you'll pay for the privelege.

**mikericetga wrote:**

If your not talking about very great distances, just join the 'Flat Earth Society'. :DIgnoring the sphericity, given positions A and B, subtract the two from each other to obtain the difference in latitude and longitude... Dx Dy.

Bearing is then atan2( Dy, Dx)... rotated 90 degrees, of course

Distance is sqrt( Dx^2 + Dy^2 )

The resulting distance is in the same units as the latitude.

Also, hypot is easier.

Bearing, from north, is atan2(Dy*cos(lat), Dx) radians.

The formula given also has a sign issue.

EDITI just saw you don't know C. I think this could be a great project to become familiar with it!

I only see only two ways around doing at least some floating point computation outside a library function:

One is to convert the data to fixed point and write most of your own math functions.

Not pretty.

The other is to find the avr-gcc functions that do fp arithmetic.

'Tis probably simpler to learn enough C to write single-statement functions.

Thanks everyone. It looks like a crash course in C for my near future.

Bazza