Thread Tools
This thread is privately moderated by FredericG, who may elect to delete unwanted replies.
Jan 20, 2007, 09:20 AM
Registered User
FredericG's Avatar
Thread OP
Build Log

Distance and direction calculations ready

The code for parsing the NMEA and calculating distance and direction to a waypoint (the pilot) is now ready!

The code was first debugged on a PC and afterwards copy/pasted into a PIC project. A problem I had was that on the PC variables where easily promoted to 32 bit while it was not the case with the PIC compiler. I must say I am very impressed with the SourceBoost IDE. At first I was printf-debugging but than I discovered the simulator/debugger and that helped me a lot.

At first the code was too big to fit but after optimising the code a bit, it worked. There is still room for improvement and the biggest code is written, but for sure, I will have to switch to a PIC with more memory.

For testing I use a GPS for hiking. It has a demo mode in which it simulates traveling a route. I use the wisp628 programmer as pass-trough for interfacing between RS232 and TTL levels. The PIC parses the NMEA messages and calculates the distance and direction to a (still hardcoded) waypoint. The PIC than send the calculated data on its serial point. The message is transformed to RS232 and captured by a PC.

In the meantime the OSD module arrived. I will now start experimenting with that...

Sign up now
to remove ads between posts
Mar 26, 2007, 09:42 PM
UAVPilot - Almost...

MNEA, OSD and Navigation

Hello Fredric,

I've been following the several FPV OSD threads with much interest as as too am in the process of building my own as part of a return-to-home failsafe feature for my Easystar. In am emergency or out-of-video-range situation, I will enable the return to home feature to come back into video range. I am using the Propeller chip which seems to be quite capable of doing all the separate jobs at once - NMEA collection and parsing, 32bit Navigation calcs, Video overlay/OSD, and servo passthrough and control.

While I'd like to improve the graphics quality of my system, I am limited presently by the various libraries available for my platform to about a 256x240 overlay (text) for now -- I do like your display layout

I have a decent idea of how to calculate the current heading and bearing needed to "return-home" using a stored GPS start location, current info and the ATAN2() math function. I've worked it out in Excel and as time permits, I'll be moving it to the Propeller in SPIN (the chip's language).

May I request a copy of you code for comparison? It's always good to have a reference to compare to, and I'll be happy to share with you mine once its in a language not excel!

thanks, and best of luck to you,

Paul Hubner
Jul 26, 2008, 08:07 AM
Old retired Electronics Fart
Charles B's Avatar
Very Good project . Your making it a number one project.

On you degrees calculation .

I have some JavaScript code that mite help you. We have a Google map

for Ham radio use. It has 1000 + markers on the map. The JavaScript code

tell the distance and heading to and from any two markers. You can look at

it use at the Link note (There is a scrolling text near the bottom of the page that tells you how to use the web page)

To look at the JavaScript use

There is a Doc. line to tell you what the next routine is trying to do.

The position is in Lat & Lon Degrees.

Here is the main part of the code for Degrees. The distance is a built in
function of Google maps.

from = (degrees Lat, degrees Lon) rem from one marker
to = (degrees Lat, degrees Lon) rem to another marker

function bearingto( from, to ) {
// See T. Vincenty, Survey Review, 23, No 176, p 88-93,1975.
// Convert to radians.
var lat1 = from.latRadians();
var lon1 = from.lngRadians();
var lat2 = to.latRadians();
var lon2 = to.lngRadians();

// Compute the angle.
var angle = - Math.atan2( Math.sin( lon1 - lon2 ) * Math.cos( lat2 ), Math.cos( lat1 ) * Math.sin( lat2 ) - Math.sin( lat1 ) * Math.cos( lat2 ) * Math.cos( lon1 - lon2 ) );
if ( angle < 0.0 )
angle += Math.PIE * 2.0;

// And convert result to degrees.
angle = angle * degreesPerRadian;
angle = angle.toFixed(1);
return angle;

I hope this helps you. It always good to look at someone else code to get
a fresh look at things.


Quick Reply
Thread Tools