Bearing calculation out of 2 nmea strings


Results 1 to 10 of 10

Threaded View

  1. #3
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default

    Quote Originally Posted by RFsolution View Post
    Did anyone ever tried to calculate bearing and distance between
    set of 2 cordinates ?

    1 fixed (lat, lon), 1 comming in from a GPS NMEA 4800,8N1 GMRC string ?

    thansk you
    I used the Cordic to get the heading and distance. To get this to work, you need to calculate the difference between the two waypoints

    lathome_hi = the 37 part of the 37.12345 degrees
    lathome_low = the 0.1234 (as a whole number 1234) part of 37.1234 degrees

    This allows you to have a 3 degree difference in distance, or about 180 miles, although you could add some math division to allow further distances.

    Code:
    GPSMath:
        latlow_dif = lathome_low - latdest_low   'find difference in present loc and destination
        lathi_dif = lathome_hi - latdest_hi
        
        lathi_dif = lathi_dif * 10000        'multiply integer degree difference by 10000 
        lat_dif = lathi_dif + latlow_dif     'so we can add decimal degrees to 16 bit number
        
        lonlow_dif = lonhome_low - londest_low
        lonhi_dif = lonhome_hi - londest_hi
        
        lonhi_dif = lonhi_dif * 10000
        lon_dif = lonhi_dif + lonlow_dif    
              
        if west = 0 then toggle lon_dif.15       'inverse negative bit for east europe
        if north = 0 then toggle lat_dif.15      'inverse negative bit for southern hemisphere
        quadrant = 1   'if lat_dif.15 = 1 and lon_dif.15 = 0 then quadrant =1
        if lat_dif.15 = 0 and lon_dif.15 = 0 then quadrant =2  'see which results are negative
        if lat_dif.15 = 0 and lon_dif.15 = 1 then quadrant =3
        if lat_dif.15 = 1 and lon_dif.15 = 1 then quadrant =4
        if north = 0 then toggle lat_dif.15      'get rid of falsing for S hem so we can do math
            
            
            gosub do_cordic   'perform cos and atan functions to determine bearing and distance to waypoint    
    
             
       'adds angle of triange to quadrant angle. (Yeah, my quads don't match what you learned in school)
            if quadrant = 1 then b2dest = 900 - b2dest                  
            if quadrant = 2 then b2dest = 900 + b2dest                         
            if quadrant = 3 then b2dest = 2700 - b2dest             
            if quadrant = 4 then b2dest = 2700 + b2dest     
         
    '    my quadrants
    '            N          
    '           |            
    '       4   |   1
        'W______|________E    
    '           |
    '       3   |   2
    '           |
    '            S
    The above code was for the cordic made for a Pic16f device. The PIC18 cordic allows positive and negative numbers, so it figures the quadrant for you.

    See the cordic and the last post here:

    http://www.picbasic.co.uk/forum/show...ghlight=cordic
    Last edited by ScaleRobotics; - 10th March 2009 at 09:50.

Similar Threads

  1. GPS decoding problems
    By vladimir059@hot in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 25th February 2012, 10:57
  2. Replies: 1
    Last Post: - 26th June 2009, 23:33
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  4. Replies: 20
    Last Post: - 13th May 2007, 05:10
  5. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts