Shop OBEX P1 Docs P2 Docs Learn Events
UAV Guidance — Parallax Forums

UAV Guidance

josefvsjosefvs Posts: 1
edited 2007-09-05 12:51 in Robotics
I am trying to find a working algorithm to convert LAT/LONG to UTM, much the same as in a Garmin GPS. This so my autopilot can calculate it’s waypoints internally and not use the GPS itself.
·
Can anybody help?
·
Thanks, Yossi

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2007-09-03 15:04
    Here is a link to Java code and also has links to information

    http://www.ibm.com/developerworks/java/library/j-coordconvert/
  • CCraigCCraig Posts: 163
    edited 2007-09-04 16:06
    Yossi,

    The formulas are really long. I even bought a few um-FPUs to try to put it all in there. I won't say I gave up, but I have put that project on the back burner. I think it will take a lot of work. I'd like to see what you come up with. It was beyond me.

    Here's another link:

    www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM

    HTH, Chris

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not scared of your robot. I'm covered by Old Glory (youtube)
  • John AbshierJohn Abshier Posts: 1,116
    edited 2007-09-04 16:13
    Instead of going all the way to UTM. There are formulas that take two lat/long points and give the distance and direction from one to the other. I was able to find some AWK code.

    # input is lat1 long1 lat2 long2
    # lat1 is [noparse][[/noparse]NS] deg min sec if using deg and min sec must = 0
    # likewise if only deg then min and sec = 0
    # long1 is [noparse][[/noparse]EW] deg min sec
    # the 2's are like the 1's
    # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
    # Example: N 53 09 02 W 01 50.75 0 N 52 12 19 W 0.25 0 0
    # if the [noparse][[/noparse]NS] or [noparse][[/noparse]EW] don't match returns an error
    BEGIN { r = 6371
    kmToFeet = 3280.839895
    degToRadians = 3.14159/180.0 }
    {if ($1 != $9) {print "Error in lat ", $0 ; next}}
    {if ($5 != $13) { print "Error in long ", $0; next}}
    {lat1 = $2 + $3/60.0 + $4/3600.0
    lat2 = $10 + $11/60.0 + $12/3600.0
    long1 = $6 + $7/60.0 + $8/3600.0
    long2 = $14 + $15/60.0 + $16/3600.0
    deltaLat = lat2 - lat1
    deltaLong = long2 - long1
    deltaLat = deltaLat * degToRadians
    deltaLong = deltaLong * degToRadians
    lat1 = lat1 * degToRadians
    lat2 = lat2 * degToRadians
    a = sin(deltaLat/2)^2 + cos(lat1) * cos(lat2) * sin(deltaLong/2)^2
    print a
    dx = 2.0 * r * atan2(sqrt(a), sqrt(1-a))
    bearing = atan2((-sin(deltaLong)*cos(lat2)), (cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(deltaLong)))
    print $0
    print "distance = ", dx, "bearing = ", bearing/degToRadians }
  • W9GFOW9GFO Posts: 4,010
    edited 2007-09-04 22:48
    It's been a while since I looked at my code but what I did was take the difference between the target lat/long and current lat/long to give me an X/Y position and then perform a couple of trig calculations to give me distance and bearing.
  • CCraigCCraig Posts: 163
    edited 2007-09-05 00:59
    W9GFO,

    Any chance to did up your formulas? Don't need the whole code just the trig. If you can find it. No big deal if not.

    Thanks, Chris KE6GS

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not scared of your robot. I'm covered by Old Glory (youtube)
  • W9GFOW9GFO Posts: 4,010
    edited 2007-09-05 01:50
    CCraig said...
    W9GFO,

    Any chance to did up your formulas? Don't need the whole code just the trig. If you can find it. No big deal if not.

    Here is my solution;

    dir = distE ATN distN
    
      IF dir < 64 THEN                             ' rotate so that 0 is north
      dir = dir - 64
      ELSE
      dir = dir + 192
      ENDIF
    
      dist = ((distE HYP distN)*workVal)
    



    The difference in lat/long from where you are to where you want to be are stored in values distN and DistE

    I'll attach the whole program so you can check it out further.
  • CCraigCCraig Posts: 163
    edited 2007-09-05 12:51
    Thank you very much, Chris

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm not scared of your robot. I'm covered by Old Glory (youtube)
Sign In or Register to comment.