How do I discern Maidenhead Locator from GPS lat long info.


Closed Thread
Results 1 to 40 of 126

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: How do I discern Maidenhead Locator from GPS lat long info.

    Nope, it's 24x24.
    And your 10-digit locator is IO93ok03kh.

    This version is quite different from the last one.
    I've tossed out the stuff that came from the pearl script and did it like the PDF mentioned above.

    It has to use the 32-bit floating point routines now. 24-bits just didn't have enough resolution for the sub-squares.
    While this version is more efficient, it's also harder to understand, sorry.

    Code:
    ; Filename    : Maidenhead_10.pbp
    ; Compiler    : PICBASIC PRO Compiler
    ; Target PIC  : 16F1937, but will work with most any chip
    ; Oscillator  : ANY
    ; Keywords    : Maidenhead, Locator, GPS, Amateure Radio
    ; Description : PICBASIC PRO program to convert between
    ;             : GPS Sexagesimal to Maidenhead coordinate systems
    ;-------------------------------------------------------------------------------
                           ; Must use the 32-bit Floating Point routines
    INCLUDE "FP2032.bas"   ; 32-bit Floating Point for 14-bit cores with RAM at $20
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 25  ' 19200 Baud @ 32MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    HSEROUT [27,"[2J","Maidenhead Locator",13,10]
    HSEROUT ["16F1937, 32-bit Floating Point",13,10,13,10]
    
    MH        VAR BYTE[10]
    LonStr    VAR BYTE[12]
    LatStr    VAR BYTE[12]
    LonDeg    VAR BYTE
    LonMin    VAR BYTE
    LonMinDec VAR BYTE
    LonDir    VAR BYTE
    LatDeg    VAR BYTE
    LatMin    VAR BYTE
    LatMinDec VAR BYTE
    LatDir    VAR BYTE
    Idx       VAR BYTE
    AddChar   VAR BYTE
    Divisor   VAR BYTE[4]
    AARG_SAVE VAR BYTE[4]
    
    ;-------------------------------------------------------------------------------
    ASM
    MOVE?CF32  macro C, F       ; put a Floating Point Constant in an FP variable
        MOVE?CW  (C & 0xFFFF), F
        MOVE?CW  (C >> 16), F + 2
      endm
    
    MOVE?FF32  macro Fin, Fout  ; Copy an FP var to another FP var
        MOVE?WW  Fin, Fout
        MOVE?WW  Fin + 2, Fout + 2
      endm
    ENDASM
    ;-------------------------------------------------------------------------------
    
    ARRAYWRITE LonStr,["00049.77,W",0]  ;  0° 47.70'  ;<-- enter GPS location here
    ARRAYWRITE LatStr,["5325.83,N",0]   ; 53° 26.20'
    
    HSEROUT ["LonStr  = ", STR LonStr,13,10]          ; display manual input
    HSEROUT ["LatStr  = ", STR LatStr,13,10]
    
    ;----[parse strings as if they came from a GPS]---------------------------------
    ARRAYREAD LonStr,[DEC3 LonDeg, DEC2 LonMin, Dec LonMinDec, LonDir]
    ARRAYREAD LatStr,[DEC2 LatDeg, DEC2 LatMin, Dec LatMinDec, LatDir]
    
    
    ;----[convert Longitude Sexagesimal to Decimal Degrees]-------------------------
    Aint = LonMinDec : GOSUB ItoFA    ; decimal portion of Minutes
    Bint = 100 : GOSUB ItoFB          ; divided by 100
    GOSUB fpdiv
    Bint = LonMin : GOSUB ItoFB       ; add whole portion of Minutes
    GOSUB fpadd
    Bint = 60 : GOSUB ItoFB           ; divide by 60
    GOSUB fpdiv
    Bint = LonDeg : GOSUB ItoFB       ; add degrees
    GOSUB fpadd
    IF LonDir = "W" THEN              ; if west of Prime Meridian
        @ MOVE?FF32 AARGB2, BARGB2    ; copy Float AARG to BARG
        Aint = 0    : GOSUB ItoFA     ; subtract from 0 to negate
        GOSUB fpsub
    ENDIF
    
    Bint = 180  : GOSUB ItoFB         ; add 180
    GOSUB fpadd
    
    ;----[Have Longitude in AARG as Float]------------------------------------------
    FOR Idx = 0 TO 8 STEP 2
        SELECT CASE Idx
          CASE 0 : AddChar = "A"
                   @ MOVE?CF32 0x83200000, _Divisor   ; 20
          CASE 2 : AddChar = "0"
                   @ MOVE?CF32 0x80000000, _Divisor   ; 2
          CASE 4 : AddChar = "a"
                   @ MOVE?CF32 0x7B2AAAAB, _Divisor   ; 0.0833333
          CASE 6 : AddChar = "0"
                   @ MOVE?CF32 0x78088889, _Divisor   ; 0.00833333
          CASE 8 : AddChar = "a"
                   @ MOVE?CF32 0x73360B61, _Divisor   ; 0.000347222
        END SELECT
        GOSUB MH_Digit
    NEXT Idx
    
    ;----[convert Latitude Sexagesimal to Decimal Degrees]--------------------------
    Aint = LatMinDec : GOSUB ItoFA    ; decimal portion of Minutes
    Bint = 100 : GOSUB ItoFB          ; divided by 100
    GOSUB fpdiv
    Bint = LatMin : GOSUB ItoFB       ; add whole portion of Minutes
    GOSUB fpadd
    Bint = 60 : GOSUB ItoFB           ; divide by 60
    GOSUB fpdiv
    Bint = LatDeg : GOSUB ItoFB       ; add degrees
    GOSUB fpadd
    IF LatDir = "S" THEN              ; if south of equator
        @ MOVE?FF32 AARGB2, BARGB2    ; copy Float AARG to BARG
        Aint = 0    : GOSUB ItoFA     ; subtract from 0 to negate
        GOSUB fpsub
    ENDIF
    
    Bint = 90  : GOSUB ItoFB          ; add 90
    GOSUB fpadd
    
    ;----[Have Latitude  in AARG as Float]------------------------------------------
    FOR Idx = 1 TO 9 STEP 2
        SELECT CASE Idx
          CASE 1 : AddChar = "A"
                   @ MOVE?CF32 0x82200000, _Divisor   ; 10
          CASE 3 : AddChar = "0"
                   @ MOVE?CF32 0x7F000000, _Divisor   ; 1
          CASE 5 : AddChar = "a"
                   @ MOVE?CF32 0x7A2AAAAB, _Divisor   ; 0.0416666
          CASE 7 : AddChar = "0"
                   @ MOVE?CF32 0x770882F1, _Divisor   ; 0.00416666
          CASE 9 : AddChar = "a"
                   @ MOVE?CF32 0x723603EC, _Divisor   ; 0.000173583
        END SELECT
        GOSUB MH_Digit
    NEXT Idx
    ;----[Maidenhead conversion complete]-------------------------------------------
    
    HSEROUT ["LOC ",STR MH\10,13,10,13,10] ; show final result
    
    Main:                             ; blink an LED when done
        HIGH PORTA.0
        PAUSE 500
        LOW PORTA.0
        PAUSE 500
    GOTO Main
    
    ;----[Calculate one digit of the Maidenhead Locator]----------------------------
    MH_Digit:
        @ MOVE?FF32 _Divisor, BARGB2      ; put divisor in BARG
        GOSUB fpdiv                       ; do the divide
        @ MOVE?FF32 AARGB2, _AARG_SAVE    ; save AARG for modulus
    
        GOSUB FtoIA                       ; get integer
        MH(Idx) = Aint + AddChar          ; The Character
        Bint = Aint                       ; copy integer result to BARG
        GOSUB ItoFB                       ; convert it to float
        @ MOVE?FF32 _AARG_SAVE, AARGB2    ; restore previous AARG
        GOSUB fpsub                       ; subtract integer
    
        @ MOVE?FF32 _Divisor, BARGB2      ; multiply times original divisor
        GOSUB fpmul                       ; AARG now contains the remainder
    RETURN
    The output of the program looks like this ...
    Code:
    Maidenhead Locator
    16F1937, 32-bit Floating Point
    
    LonStr  = 00049.77,W
    LatStr  = 5325.83,N
    LOC IO93ok03kh
    BTW: Those are really small squares (in red).

    Name:  IO93ok03kh.jpg
Views: 11588
Size:  18.5 KB
    Last edited by Darrel Taylor; - 20th April 2014 at 08:05.
    DT

  2. #2
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190

    Default Re: How do I discern Maidenhead Locator from GPS lat long info.

    Wow, wow and WOW. What can I say? That is your usual brilliant stuff.

    I use DT_Ints, Big Digits, ADC Average and now your Locator code.

    Many many thanks. I tried but just can't follow it through as you expected

    I never realised just how small the final location square was. That's half my plot. Reason is, the gps antenna is on the window ledge on a back room!
    If I move to front room it would change !! Stunning.

    Now I need to re-organise the screen layout. I didn't think I would run out of room on a 20x4 display.

    I will post a picture of the completed item, it's boxed but not quite complete.

    Once again, many thanks.
    Rob.

    The moment after you press "Post" is the moment you actually see the typso

  3. #3
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190

    Default Re: How do I discern Maidenhead Locator from GPS lat long info.

    Hmmm, I've transferred the code over into my program but I must have done something wrong as the locator is incorrect.

    I'm getting 10 and kd instead of 03 and kh which is correct at back of house. kg at front of house

    I will check it over again.

    Here's a screenshot of the Android app.

    Name:  Maidgps.jpg
Views: 11082
Size:  34.8 KB
    Last edited by tasmod; - 20th April 2014 at 14:17. Reason: add pic
    Rob.

    The moment after you press "Post" is the moment you actually see the typso

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: How do I discern Maidenhead Locator from GPS lat long info.

    Quote Originally Posted by tasmod View Post
    I'm getting 10 and kd instead of 03 and kh which is correct at back of house. kg at front of house
    These are some of the results I get ...
    Code:
        LAT           LON       Maidenhead   
    Deg Min.Min   Deg Min.Min   1234567890
    ------------  ------------  ----------
     53° 25.83'    -0° 49.77'   IO93ok03kh  Back Yard
     53° 25.82'    -0° 49.77'   IO93ok03kg  Front Yard
    
     53° 25.04'    -0° 49.29'   IO93ok10kd  Wrong Place
    Since the main difference is the decimal portion of the Minutes, you might want to look at the values in the LonMinDec and LatMinDec variables.

    They should come from the latsecs and lonsecs variables you parsed from the GPS.
    Although, it's not seconds ... it's the decimal portion of the Minutes.
    DT

  5. #5
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190

    Default Re: How do I discern Maidenhead Locator from GPS lat long info.

    That was it Darrel. I had aliased the wrong variables to save renaming.

    Gives correct code at 'back yard' 90% of time. Why 90% ? Well, it faces North and the number of satellites it will lock to for a precise fix varies quite a lot. This is due to antenna position and satellite positions. If I lift antenna slightly, it will improve.
    The gps gives a slightly changing fix as it recalculates. According to manual it outputs a 'Fix' in sentence when it has aquired 4 satellites

    At the South facing 'front yard' it is 100%, as it will fix 12 satellites, the limit of this gps module.


    I'm going to try inputting an initialisation string at start up. This will turn off all sentences except the RMC sentence. This should stop the occasional random catchup 'seconds' jump as another sentence is output. There are four other defaults, GGA , GSV , GSA and ZCH. The latter is the unit channel status.
    It appears that they are output randomly according to PC gps serial monitoring program, whilst RMC is per second.
    Last edited by tasmod; - 21st April 2014 at 11:34.
    Rob.

    The moment after you press "Post" is the moment you actually see the typso

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: How do I discern Maidenhead Locator from GPS lat long info.

    Does your GPS module put out more decimal places in the LAT/LON fields?

    Since the edge of the square runs through the middle of the house, whether you're at the front window or rear window inside, you're always near the edge.
    I imagine that if you were standing in the middle of your back yard, the reading would be more consistent.

    One or two more decimals may improve the resolution considerably.
    With only two decimals, a difference of .01 is a whole square.
    Code:
        LAT           LON       Maidenhead   
    Deg Min.Min   Deg Min.Min   1234567890
    ------------  ------------  ----------
     53° 25.83'    -0° 49.77'   IO93ok03kh  Back Yard
     53° 25.82'    -0° 49.77'   IO93ok03kg  Front Yard
    It depends on whether your GPS gives enough data or not.
    When recording NMEA sentences from my Android, it gives 6 decimals.
    DT

  7. #7
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190

    Default Re: How do I discern Maidenhead Locator from GPS lat long info.

    Again you come to my aid Darrel.

    I had limited the output by declaring the lat/lon secs as byte. Changed them to word and it becomes much more stable now. Datasheet says the decimal part is of variable length not fixed, so word should cover it.

    I have also improved the start time to fix by finally fitting the Supercap to the gps module, something I should have done a while ago. This gives 48hr backup.

    Don't groan but I now have another problem I'm going to look at. The time is now 2 seconds slow. Probably all the code plus the NMEA being slow too.
    I'm looking at adding 2 secs then trigger display using DT_Ints on the next PPS pulse rise time. Feasible ??
    Rob.

    The moment after you press "Post" is the moment you actually see the typso

Similar Threads

  1. LAT replaces PORT command?
    By markscotford in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd December 2011, 16:37
  2. Need Info for PBP?
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 30th January 2009, 07:44
  3. Replies: 1
    Last Post: - 27th July 2008, 06:14
  4. dmx info.
    By oscar in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th May 2005, 11:54

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