More GPS goodness

sorry for the double post... I realized that if you trim the sertxd stuff this fits on a 08M, so I guess it's good for almost all the picaxes :)

again, just trim out the sertxd.



'
'
' Simplified version of gps navigation to just get to a waypoint and just do bearing->tracking.
' Can be used with a route by checking the proximity warning and nav ID.
' Requires navpoint names to be numbers in the format 000..255 (use leading zeros please).
'
' gps is hooked up to this pin.
symbol GPS_IN = 0

'navigation temporary memory map when grabbing string, let's try to fit everything in one place
symbol Bear1 = w0 ' 0 1
symbol Track1 = w1 ' 2 3
symbol Steer = b4 '2
symbol Prox = b5 '2
symbol Range1 = b6 '3
symbol Range2 = b7 '3
symbol OffTrk1= b8 '4
symbol OffTrk2= b10 '4
symbol NavName=b9 '5
symbol Track2 =b11 '5
symbol Unused = w6
symbol Unused1= b12
symbol Bear2 = b13

' calculated vars memory map for actual use
symbol Bear = w0
symbol Track = w1
' w2 is prox alert and steering, they stay the same
symbol Range = w3
symbol OffTrk = b8
' NavName gets preserved
' 10, 11, 12, 13 should be preserved

getgps:
gosub preservevars

serin GPS_IN, N4800, ("$GPRMC") ' lose UTC time coz we don't care
serin GPS_IN, N4800, (",A,"),#Unused,#Unused,Unused1,#Unused,#Unused,Unused1,#Unused,#Unused,#Bear1,#Bear2
serin GPS_IN, N4800, ("RMB,A,"),#OffTrk1,#OffTrk2,Steer

poke $C0, Bear2 ' bear2 is part of scratch, so let's deal with that
poke $C1, Unused ' do this 3 times at 4Mhz to insert correct delay
poke $C2, Bear2 ' do this 3 times at 4Mhz to insert correct delay

' LIMITATION: Navpoint names must be numbers right now. Fix it later!
serin GPS_IN, N4800, (","), #NavName, #Unused, #Unused, Unused1, #Unused, #Unused, Unused1, #Range1, #Range2, #Track1, #Track2, Unused1, Prox
peek $C0, Bear2 ' restore since we're done with scratch vars

calculate:

' calculations go here; use w2 as scratch var

poke $C4, Steer
poke $C5, Prox

w2 = Bear1
w2 = w2 * 10
w2 = w2 + Bear2
Bear = w2


w2 = Track1
w2 = w2 * 10
w2 = w2 + Track2
Track = w2

w2 = Range1
w2 = w2 * 10
w2 = w2 + Range2
Range = w2

w2 = OffTrk1
w2 = w2 * 10
w2 = w2 + OffTrk2
OffTrk = w2

peek $C4, Steer
peek $C5, Prox


gosub restorevars ' if we were using them for other stuff

' do whatever you need here, memory map should be:
'bearing
'bearing
'tracking
'tracking
'steer l/r
'prox alert
'range
'range
'offtrack
'navpoint #
'stuff from before getgps
'stuff from before getgps
'stuff from before getgps
'stuff from before getgps

' just printing the data -- note that everything must be divided by 10, i'm not doing it here to show the format

sertxd ("Destination ID: ",#NavName, " Offtrack: ",#OffTrk," - Steer ")
gosub printdir
sertxd (13,10)
sertxd ("Distance: ",#Range," - Head/Track: ",#Bear,"/",#Track," Arrived: ")
gosub printarr
sertxd (13,10)


goto getgps
end
' subroutines start here

printdir:
if Steer = "R" then printright
sertxd("Left ")
return
printright:
sertxd("Right")
return

printarr:
if Prox = "A" then printyes
sertxd("No ")
return
printyes:
sertxd("Yes")
return

preservevars:
poke $CA,b10
poke $CB,b11
poke $CC,b12
poke $CD,b13
return

restorevars:
peek $CA,b10
peek $CB,b11
peek $CC,b12
peek $CD,b13
return

 

hippy

Technical Support
Staff member
If you single-line your calculations, that will save even more program space and speed up the program ...

- w2 = Bear1
- w2 = w2 * 10
- w2 = w2 + Bear2
- Bear = w2

can be ...

- Bear = Bear1 * 10 + Bear2

If you store the read value for Bear1 into Bear instead ( ditto for Track1, Range1 and OffTrk1 ), you can end up with an even smaller program of ...

- Bear = Bear * 10 + Bear2
- Track = Track * 10 + Track2
- Range = Range * 10 + Range2
- OffTrk = OffTrk * 100 + OffTrk2 MAX 255

Edited by - hippy on 18/06/2006 21:41:34
 
True, but I wasn't sure about the truncating, and I'd rather this be very readable since I put it on a forum :) hence why the lots of comments.

thanks!
 
' thanks for the tips!!! Rewrote for less memory use.
'
'
' okay, it officially fits on a picaxe-8M!
'
' Simplified version of gps navigation to just get to a waypoint and just do bearing->tracking.
' Can be used with a route by checking the proximity warning and nav ID.
' Requires navpoint names to be numbers in the format 000..255 (use leading zeros please).
'
' by spiritplumber at gmail.com -- please give credit if you use substantial portions of this, I need a job :)
'
'
' gps is hooked up to this pin.
symbol GPS_IN = 3

'navigation temporary memory map when grabbing string, let's try to fit everything in one place
symbol Bear1 = w0 ' 0 1
symbol Track1 = w1 ' 2 3
symbol Steer = b4 '2
symbol Prox = b5 '2
symbol Range1 = b6 '3
symbol Range2 = b7 '3
symbol OffTrk1= b8 '4
symbol OffTrk2= b10 '4
symbol NavName=b9 '5
symbol Track2 =b11 '5
symbol Unused = w6
symbol Unused1= b12
symbol Bear2 = b13

' calculated vars memory map for actual use
' w0 should be preserved
' w1 should be preserved
' w2 is prox alert and steering, they stay the same
symbol Range = w3
symbol OffTrk = b8 ' w4
' NavName is b9 (w4) and stays the same
symbol Track = w5
symbol Bear = w6



getgps:
gosub preservevars

serin GPS_IN, N4800, ("MC,") ' lose UTC time coz we don't care
serin GPS_IN, N4800, (",A,"),#Unused,#Unused,Unused1,#Unused,#Unused,Unused1,#Unused,#Unused,#Bear1,#Bear2
serin GPS_IN, N4800, ("MB,A,"),#OffTrk1,#OffTrk2,Steer

poke $60, Bear2 ' bear2 is part of scratch, so let's deal with that
peek $61, Unused ' do this at 4Mhz to insert correct delay
poke $61, Unused ' do this at 4Mhz to insert correct delay

' LIMITATION: Navpoint names must be numbers right now. Fix it later!
serin GPS_IN, N4800, (","), #NavName, #Unused, #Unused, Unused1, #Unused, #Unused, Unused1, #Range1, #Range2, #Track1, #Track2, Unused1, Prox
peek $60, Bear2 ' restore since we're done with scratch vars

calculate:

Bear = Bear1 * 10 + Bear2
Range = Range1 * 10 + Range2
OffTrk = OffTrk1 * 100 + OffTrk2 max 255
Track = Track1 * 10 + Track2

gosub restorevars ' if we were using them for other stuff

'do whatever you need here, memory map at this point should be:

' 0 stuff poked back in from before getgps
' 1 stuff poked back in from before getgps
' 2 stuff poked back in from before getgps
' 3 stuff poked back in from before getgps
' 4 steer L/R in ascii
' 5 prox alert in ascii (do we need this?)
' 6 range in tenths of whatever unit is specified on the gps
' 7 range in tenths of whatever unit is specified on the gps
' 8 offtrack in tenths of whatever unit is specified on the gps
' 9 navpoint # in decimal
' 10 tracking in tenths of a degree (L)
' 11 tracking in tenths of a degree (H)
' 12 bearing in tenths of a degree (L)
' 13 bearing in tenths of a degree (H)

' just printing the data -- note that everything must be divided by 10, i'm not doing it here to show the format

sertxd ("Dest ID: ",#NavName, ",XTE: ",#OffTrk,", Steer ", Steer, 13, 10, "Distance: ",#Range,", Bear/Track: ",#Bear,"/",#Track,", ", Prox, 13, 10, 13, 10)

goto getgps
end

' subroutines start here


preservevars:
poke $50,b0
poke $51,b1
poke $52,b2
poke $53,b3
return

restorevars:
peek $50,b0
peek $51,b1
peek $52,b2
peek $53,b3
return




Edited by - spiritplumber on 19/06/2006 02:55:46
 
Top