Shop OBEX P1 Docs P2 Docs Learn Events
GPS Module Commands (Smart Mode) — Parallax Forums

GPS Module Commands (Smart Mode)

OneCoolCatOneCoolCat Posts: 11
edited 2010-01-03 02:16 in Accessories
For some reason for which I can't figure out, the demo program written for the GPS module works and the brief code that I wrote to just·find altitude does not.

I'm just using the SEROUT, SERIN commands and the data I get back is not accurate.

What's the trick?

Comments

  • sylvie369sylvie369 Posts: 1,622
    edited 2009-12-31 12:04
    Two quick comments:

    You should post your code to get better help.

    How inaccurate are the data? GPS altitude is notoriously inaccurate.
  • OneCoolCatOneCoolCat Posts: 11
    edited 2009-12-31 17:20
    The lines I'm using are...

    SEROUT Sio, Baud, [noparse][[/noparse]"!GPS", GetAlt]
    SERIN Sio, Baud, 3000, noResponse, [noparse][[/noparse]token.HIGHBYTE, token.LOWBYTE]
    PAUSE 500
    DEBUG token

    I've verified that the 'token' variable is a WORD.

    The altitude is way off.· I'm at about 125 m and it gives me about 3000 m.··And again,·if I run the demo·program downloaded from the web, the reading is accurate.

    Thanks!·
  • FranklinFranklin Posts: 4,747
    edited 2009-12-31 20:53
    Could you attach the actual program you are running? There seems to be nothing wrong with the snippet of code and if the demo works the gps is working so something in the program is wrong.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • DufferDuffer Posts: 374
    edited 2009-12-31 22:42
    If the code snippet that you posted is complete, your DEBUG value will be off by a factor of 10. The value returned by the GPS is in tenths of a meter (0.1 meter). As was done in the GPS demo code, you need to divide by 10 to get whole meters. All that being said, the altitude value is notoriously inaccurate in most GPS units. GPS units that display accurate altitude employ an absolute barometric pressure sensor to calculate altitude.

    Duffer





    ·
  • hover1hover1 Posts: 1,929
    edited 2010-01-01 00:49
    What Duffer said. Altitude readings on GPS are almost unusable. You need to have barometric readings to get an accurate reading. (Unless your military)

    Been there, done that.

    Jim
  • OneCoolCatOneCoolCat Posts: 11
    edited 2010-01-02 01:28
    I'm getting between 2800.0 and 3000.0 meters for my altitude and I do understand the output from the module is in tenths of of a meter.· According to Google Earth,·my location is at·about 140 meters.

    It's definitely something quirky with my program or the Stamp BS2.· Get this, if I delete a PAUSE 500 line, the altitude and satellite numbers·become accurate!··Theoretically the line·should have nothing to do with this issue.

    Any idea what's going on here?

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    'Test compass and GPS receiver test plate
    token           VAR     Word
    line            VAR     Byte
    alt             VAR     Word
    sats            VAR     Byte
    tPin            PIN     0
    fPin            PIN     1
    Sio             PIN     12
    T4800           CON     188
    Open            CON     $8000
    Baud            CON     Open | T4800    ' Open mode to allow daisy chaining
     
    ' GPS Module Commands
    GetInfo         CON     $00
    GetValid        CON     $01
    GetSats         CON     $02
    GetTime         CON     $03
    GetDate         CON     $04
    GetLat          CON     $05
    GetLong         CON     $06
    GetAlt          CON     $07
    GetSpeed        CON     $08
    GetHead         CON     $09
     
    DO
    GOSUB Get_Valid
    GOSUB Get_Alt
    GOSUB Get_Sats
    LOOP
    
    Get_Valid:
      line = 1
      SEROUT Sio, 188, [noparse][[/noparse]"!GPS", GetValid]
      SERIN  Sio, 188, 3000, noResponse, [noparse][[/noparse]token]
      SEROUT tPin\fPin, 16468, [noparse][[/noparse]"XYZ", DEC line, CR, DEC token, CR]
    [b]  'PAUSE 500 <--- if I omit this line, all readings are reasonably accurate.
                     'if I run this line, alt and sats values are way off![/b]
      RETURN
     
    Get_Alt:
      line = 2
      SEROUT Sio, 188, [noparse][[/noparse]"!GPS", GetAlt]
      SERIN  Sio, 188, 3000, noResponse, [noparse][[/noparse]alt.HIGHBYTE, alt.LOWBYTE]
      SEROUT tPin\fPin, 16468, [noparse][[/noparse]"XYZ", DEC line, CR, DEC alt, CR]
      PAUSE 500
      RETURN
     
    Get_Sats:
      line = 3
      SEROUT Sio, 188, [noparse][[/noparse]"!GPS", GetSats]
      SERIN  Sio, 188, 3000, noResponse, [noparse][[/noparse]sats]
      SEROUT tPin\fPin, 16468, [noparse][[/noparse]"XYZ", DEC line, CR, DEC sats, CR]
      RETURN
     
    noResponse:
      RETURN
    
  • DufferDuffer Posts: 374
    edited 2010-01-02 03:12
    From your code, it·looks like you get the altitude and sats regardless of the value returned by the request for Valid.

    Until Valid is 1 (true), the number of Sats and altitude are zero and garbage respectively.

    GPS Startup - Valid = False
    $GPGGA,000056,,N,,E,0,00,,,M,,M,,*6E<CR><LF>
    $GPRMC,000056,V,,N,,E,,,010303,,,N*5A<CR><LF>
    Sats fixed - Valid = True
    $GPGGA,013620,4034.8983,N,07439.6939,W,1,04,04.0,00039.2,M,-034.0,M,,*71<CR><LF>
    $GPRMC,013620,A,4034.8983,N,07439.6939,W,000.0,000.0,271109,,,A*6D<CR><LF>


    The NMEA sentences above represent what the SX processor is parsing from the GPS module in Smart mode(the GSA and GSV sentences are ignored by Smart mode).

    Notice that while Valid is false (second field in RMC sentence is "V"), the number of sats (7th field in GGA sentence) is "00" and the Altitude (the 9th field in GGA sentence) is null, The parser counts commas to locate a field and then reads a number of bytes of what it thinks is valid data. In the case of·Altitude, before a valid fix, the parser would read garbage (",M,,M" instead of "00039.2 in the "valid" GGA sentence).

    Contrast that to the GGA and RMC sentences when Valid (second field in RMC = "A").

    You could try something like:

    DO 
    GOSUB Get_Valid 
    IF(token) THEN          'token (Valid) = 1 or bolean true 
       GOSUB Get_Alt 
       GOSUB Get_Sats
       PAUSE 1000           'GPS data rate is 1Hz. No point in checking more often
    ELSE 
       PAUSE 2000 
    ENDIF 
    LOOP
    


    This would continue to test for a valid signal at 2 second intervals until a valid signal was acquired (the red LED on the GPS is on solid when the GPS unit has a fix). Untill Valid is true, all data from the GPS is suspect. That's why the demo program·for Smart mode checks for Valid and if it's not, it outputs "?" to all the fields and tries again.

    Duffer




    Post Edited (Duffer) : 1/2/2010 3:22:28 AM GMT
  • OneCoolCatOneCoolCat Posts: 11
    edited 2010-01-02 06:04
    Yes you are right. I forgot to mention that for this discussion I've only mentioned data collected when the signal was valid. I've ignored the numbers when the signal is not valid.
  • DufferDuffer Posts: 374
    edited 2010-01-03 02:16
    Using the following code, I got the responses shown in the DEBUG terminal attached below. The only difference is that I used a BS2p24 (on a BOE) instead of the BS2 that you used (baud is 500 instead of 188). With a range of 64.6-45.2 Meters, it's not very stable (or accurate; my altitude is 29M), but it's about what I would expect using GPS data rather than barometric pressure to get altitude. TTFF (Time To First Fix) was only about 14 seconds, which is not bad. BTW, I have the GPS unit connected to a 4ft 4-wire cable so that I can place the GPS receiver in a south facing window with no metal screen.

    Duffer

    ' {$STAMP BS2p} 
    ' {$PBASIC 2.5}
     
    'Test compass and GPS receiver test plate
     
    token VAR Word 
    line  VAR Byte 
    alt   VAR Word 
    sats  VAR Byte
     
    tPin PIN 0 
    fPin PIN 1 
    Sio  PIN 12 
    T4800 CON 188 
    Open  CON $8000 
    Baud  CON Open | T4800 ' Open mode to allow daisy chaining
     
    ' GPS Module Commands 
    GetInfo  CON $00 
    GetValid CON $01 
    GetSats  CON $02 
    GetTime  CON $03 
    GetDate  CON $04 
    GetLat   CON $05 
    GetLong  CON $06 
    GetAlt   CON $07 
    GetSpeed CON $08 
    GetHead  CON $09
     
    DO 
     GOSUB Get_Valid 
      IF(token) THEN 'token (Valid) = 1 or bolean true 
       GOSUB Get_Alt 
       GOSUB Get_Sats 
       PAUSE 1000 'GPS data rate is 1Hz. No point in checking more often 
     ELSE 
       DEBUG CR 
       PAUSE 2000 
     ENDIF
    LOOP
     
    Get_Valid: 
     line = 1 
     SEROUT Sio, 500, [noparse][[/noparse]"!GPS", GetValid] 
     SERIN Sio, 500, 3000, noResponse, [noparse][[/noparse]token] 
     DEBUG "Valid=", DEC token, " " 
     'PAUSE 500 <--- if I omit this line, all readings are reasonably accurate. 
     'if I run this line, alt and sats values are way off! 
    RETURN
     
    Get_Alt: 
     line = 2 
     SEROUT Sio, 500, [noparse][[/noparse]"!GPS", GetAlt] 
     SERIN Sio, 500, 3000, noResponse, [noparse][[/noparse]alt.HIGHBYTE, alt.LOWBYTE] 
     DEBUG "Alt=",DEC alt," " 
     'PAUSE 500 
    RETURN
     
    Get_Sats: 
     line = 3 
     SEROUT Sio, 500, [noparse][[/noparse]"!GPS", GetSats] 
     SERIN Sio, 500, 3000, noResponse, [noparse][[/noparse]sats] 
     DEBUG "Sats=",DEC sats, CR 
    RETURN
     
    noResponse: 
    RETURN
    
    593 x 698 - 69K
Sign In or Register to comment.