PDA

View Full Version : Using Objects FSRW and GPS_Float to make a Google Earth .kml file



Thomas Fletcher
05-19-2010, 08:47 PM
I am trying to Use the objects FSRW and GPS_Float to make a Google Earth .kml file,
but I am having trouble writing the real numbers Float_Longitude_Deg and Float_Latitude_Deg
to the file on the sd card.

I believe the problem is at
sdcard.sdstr(gps.Float_Longitude_Deg)
sdcard.sdstr(string(","))
sdcard.sdstr(gps.Float_Latitude_Deg)
sdcard.sdstr(string(","))
sdcard.sdstr(string("155"))
sdcard.sdstr(string(13,10))

It writes
0,0,155
0,0,155
0,0,155
to the file.

I am sure this has been discussed before, but I can't find a thread with search.



CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000

obj
sdcard: "fsrw"
gps: "GPS_Float"

var
long start

pub main

sdcard.mount(3)
sdcard.popen(string("text.kml"),"w")


if gps.init

sdcard.SDStr(string("<?xml version='1.0' encoding='UTF-8'?>",13,10))
sdcard.SDStr(string("<kml xmlns='http://www.opengis.net/kml/2.2'>",13,10))
sdcard.SDStr(string(" <Document>",13,10))
sdcard.SDStr(string(" <name>Paths</name>",13,10))
sdcard.SDStr(string("<description>This is a test run of collecting GPS data</description>",13,10))
sdcard.SDStr(string("<Style id='yellowLineGreenPoly'>",13,10))
sdcard.SDStr(string(" <LineStyle>",13,10))
sdcard.SDStr(string(" <color>7f00ffff</color>",13,10))
sdcard.SDStr(string(" <width>4</width>",13,10))
sdcard.SDStr(string(" </LineStyle>",13,10))
sdcard.SDStr(string(" <PolyStyle>",13,10))
sdcard.SDStr(string(" <color>7f00ff00</color>",13,10))
sdcard.SDStr(string(" </PolyStyle>",13,10))
sdcard.SDStr(string(" </Style>",13,10))
sdcard.SDStr(string(" <Placemark>",13,10))
sdcard.SDStr(string(" <name>Absolute Extruded</name>",13,10))
sdcard.SDStr(string(" <description>Transparent green wall with yellow outlines</description>",13,10))
sdcard.SDStr(string(" <styleUrl>#yellowLineGreenPoly</styleUrl>",13,10))
sdcard.SDStr(string(" <LineString>",13,10))
sdcard.SDStr(string(" <extrude>1</extrude>",13,10))
sdcard.SDStr(string(" <tessellate>1</tessellate>",13,10))
sdcard.SDStr(string(" <altitudeMode>absolute</altitudeMode>",13,10))
sdcard.SDStr(string("<coordinates>"))

repeat 10000
sdcard.sdstr(gps.Float_Longitude_Deg)
sdcard.sdstr(string(","))
sdcard.sdstr(gps.Float_Latitude_Deg)
sdcard.sdstr(string(","))
sdcard.sdstr(string("155"))
sdcard.sdstr(string(13,10))

sdcard.SDStr(string("</coordinates>",13,10))
sdcard.SDStr(string(" </LineString>",13,10))
sdcard.SDStr(string(" </Placemark>",13,10))
sdcard.SDStr(string(" </Document>",13,10))
sdcard.SDStr(string("</kml>",13,10))
else
sdcard.SDStr(string("GPS failed to start",13,10))

sdcard.pclose
Lightblink

Pub Lightblink
dira~~
repeat 9
!outa
waitcnt(9_000_000 + cnt)



The file created


<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://www.opengis.net/kml/2.2'>
<Document>
<name>Paths</name>
<description>This is a test run of collecting GPS data</description>
<Style id='yellowLineGreenPoly'>
<LineStyle>
<color>7f00ffff</color>
<width>4</width>
</LineStyle>
<PolyStyle>
<color>7f00ff00</color>
</PolyStyle>
</Style>
<Placemark>
<name>Absolute Extruded</name>
<description>Transparent green wall with yellow outlines</description>
<styleUrl>#yellowLineGreenPoly</styleUrl>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<coordinates>0,0,155
0,0,155
0,0,155
0,0,155
.......many more
</coordinates>
</LineString>
</Placemark>
</Document>
</kml>

Thomas Fletcher
05-19-2010, 10:18 PM
Turns out I had two mistakes. I made the receive and transmit pin for the GPS the same number.

Also looking at GPS_Float_Demo I needed to add the object FloatString to convert the float number to string.

WBA Consulting
05-19-2010, 11:28 PM
Here's a thread on the same topic you might want to look at. I started with a KML GPS logger to learn how to use the GPS for my Propeller based Reverse-GeoCache project.

http://forums.parallax.com/showthread.php?p=729953

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Williams
WBA Consulting
WBA-TH1M Sensirion SHT11 Module (http://www.aestheticacoustics.com/sht11_01.htm)
My Prop projects: Reverse Geo-Cache Box (http://forums.parallax.com/showthread.php?p=869153), Custom Metronome (http://forums.parallax.com/showthread.php?p=906277), Micro Plunge Logger (http://forums.parallax.com/showthread.php?p=875698)

Thomas Fletcher
05-20-2010, 12:09 AM
Thank you!

Thomas Fletcher
05-20-2010, 03:42 AM
http://www.ragtopvideo.com/me/track.jpg

fixmax
05-20-2010, 03:56 AM
I think that is amazing! I actually am working on an application that would really benefit with that. Thanks for the pictures.

Brian Riley
05-21-2010, 02:32 AM
Should not this line




sdcard.SDStr(string("<coordinates>"))




have a CR LF sequence ???? like this




sdcard.SDStr(string("<coordinates>"),13,10)




cheers ... BBR

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhill center, vermont
The Shoppe at Wulfden
www.wulfden.org/TheShoppe/ (http://www.wulfden.org/TheShoppe/)
www.wulfden.org/TheShoppe/prop/ (http://www.wulfden.org/TheShoppe/prop/) - Propeller Products
www.wulfden.org/TheShoppe/k107/ (http://www.wulfden.org/TheShoppe/k107/) - Serial LCD Display Gear

WBA Consulting
05-21-2010, 02:48 AM
It works both ways, as with basic HTML. An entire HTML page can be completely free of carriage returns because they are not part of the HTML format structure. They only exist for ease of reading and a browser doesn't care if they exist.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andrew Williams
WBA Consulting
WBA-TH1M Sensirion SHT11 Module (http://www.aestheticacoustics.com/sht11_01.htm)
My Prop projects: Reverse Geo-Cache Box (http://forums.parallax.com/showthread.php?p=869153), Custom Metronome (http://forums.parallax.com/showthread.php?p=906277), Micro Plunge Logger (http://forums.parallax.com/showthread.php?p=875698)

Thomas Fletcher
05-21-2010, 07:06 AM
Current code. I have added a wait for Fix and a toggle button. Press button to open file and start recording. Again to close file. Each
time saving a different track into one of ten files.

Disappointed that I am already out of cogs. I was hoping to add some sensors to the mix.




CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000


obj
sdcard: "fsrw"
gps : "GPS_Float"
DEBUG : "Parallax Serial Terminal"
FS : "FloatString"
F : "Float32Full"

var
long lat1, long1, longavg, latavg
long x, filenum, open
long Stack[16], buttonpressed

pub main
dira[16]~~
sdcard.mount(3)
'DEBUG.start(57600)
gps.init

initButton

filenum := 1
open := 0
repeat
repeat while buttonpressed == 0
shortblink
buttonpressed := 0
if open == 1
Endfile
else
Openfile

Pub Openfile
case filenum
1: sdcard.popen(string("track1.kml"),"w")
2: sdcard.popen(string("track2.kml"),"w")
3: sdcard.popen(string("track3.kml"),"w")
4: sdcard.popen(string("track4.kml"),"w")
5: sdcard.popen(string("track5.kml"),"w")
6: sdcard.popen(string("track6.kml"),"w")
7: sdcard.popen(string("track7.kml"),"w")
8: sdcard.popen(string("track8.kml"),"w")
9: sdcard.popen(string("track9.kml"),"w")
10: sdcard.popen(string("track10.kml"),"w")

'term1
WriteFileHeader
filenum++
open := 1
CheckSatFix
WriteLineCoors
Pub EndFile
sdcard.SDStr(string(" </LineString>",13,10))
sdcard.SDStr(string(" </Placemark>",13,10))
sdcard.SDStr(string(" </Document>",13,10))
sdcard.SDStr(string("</kml>",13,10))
sdcard.pclose
open := 0

PUB InitButton
cognew(button(@buttonpressed), @stack)

Pub button(bp)
dira~
long[bp] := 0
repeat

if ina == 1
long[bp] := 1


Pub CheckSatFix
repeat while gps.Long_Fix_Quality < 1 or gps.Long_Fix_Quality > 8
FixIndicatoroff
FixIndicatorOn

Pub FixIndicatorOn
outa[16] := 1
Pub FixIndicatorOff
outa[16] := 0

Pub WriteFileHeader
sdcard.SDStr(string("<?xml version='1.0' encoding='UTF-8'?>",13,10))
sdcard.SDStr(string("<kml xmlns='http://www.opengis.net/kml/2.2'>",13,10))
sdcard.SDStr(string(" <Document>",13,10))
sdcard.SDStr(string(" <name>Paths</name>",13,10))
sdcard.SDStr(string("<description>This track was started on "))
sdcard.sddec(gps.Long_Month)
sdcard.SDStr(string("/"))
sdcard.sddec(gps.Long_Day)
sdcard.SDStr(string("/"))
sdcard.sddec(gps.Long_year)
sdcard.SDStr(string(" at "))
sdcard.sddec(gps.Long_Hour - 4)
sdcard.SDStr(string("|"))
sdcard.sddec(gps.Long_minute)
sdcard.SDStr(string(".</description>",13,10))



sdcard.SDStr(string("<Style id='yellowLineGreenPoly'>",13,10))
sdcard.SDStr(string(" <LineStyle>",13,10))
sdcard.SDStr(string(" <color>7f00ffff</color>",13,10))
sdcard.SDStr(string(" <width>4</width>",13,10))
sdcard.SDStr(string(" </LineStyle>",13,10))
sdcard.SDStr(string(" <PolyStyle>",13,10))
sdcard.SDStr(string(" <color>7f00ff00</color>",13,10))
sdcard.SDStr(string(" </PolyStyle>",13,10))
sdcard.SDStr(string(" </Style>",13,10))
sdcard.SDStr(string(" <Placemark>",13,10))
sdcard.SDStr(string(" <name>Absolute Extruded</name>",13,10))
sdcard.SDStr(string(" <description>Transparent green wall with yellow outlines</description>",13,10))
sdcard.SDStr(string(" <styleUrl>#yellowLineGreenPoly</styleUrl>",13,10))
sdcard.SDStr(string(" <LineString>",13,10))
sdcard.SDStr(string(" <extrude>1</extrude>",13,10))
sdcard.SDStr(string(" <tessellate>1</tessellate>",13,10))
sdcard.SDStr(string(" <altitudeMode>absolute</altitudeMode>",13,10))
Pub WriteLineCoors
sdcard.SDStr(string("<coordinates>"))
x := 0
repeat while buttonpressed == 0
x++
CheckSatFix
TakeReading
'term2
sdcard.sdstr(fs.floattostring(longavg))
sdcard.sdstr(string(","))
sdcard.sdstr(fs.floattostring(latavg))
sdcard.sdstr(string(","))
sdcard.sdstr(fs.floattostring(gps.Float_Altitude_A bove_MSL))
sdcard.sdstr(string(13,10))

waitcnt (clkfreq * 4 + cnt)

sdcard.SDStr(string("</coordinates>",13,10))



Pub ShortBlink
repeat 8
!outa[16]
waitcnt(9000_000 + cnt)

PUB TakeReading
latavg := gps.Float_Latitude_Deg
longavg := gps.Float_Longitude_Deg
{ -======Not working. Locks up========-
long1 := lat1 := 0.0
repeat 10
lat1 := f.fadd(lat1,gps.Float_Latitude_Deg)
long1 := f.fadd(long1,gps.Float_Longitude_Deg)

latavg := f.fdiv(lat1,10.0)
longavg := f.fdiv(long1,10.0)
}

Pub Term1
DEBUG.Position(20,10)
DEBUG.str(string("Fix Quality: "))
DEBUG.Position(20,12)
DEBUG.str(string("Number of Sats: "))
DEBUG.Position(20,14)
DEBUG.str(string("Reading Number: "))
DEBUG.Position(20,16)
DEBUG.str(string("Long: "))
DEBUG.Position(20,18)
DEBUG.str(string("Lat: "))

Pub Term2
DEBUG.Position(34,10)
DEBUG.clearend
DEBUG.dec(gps.Long_Fix_Quality)
DEBUG.Position(37,12)
DEBUG.clearend
DEBUG.dec(gps.Long_SatID_In_Fix(0))
DEBUG.Position(37,14)
DEBUG.clearend
DEBUG.dec(x)
DEBUG.Position(27,16)
DEBUG.clearend
DEBUG.str(fs.floattostring(longavg))
DEBUG.Position(27,18)
DEBUG.clearend
DEBUG.str(fs.floattostring(latavg))

max72
05-21-2010, 06:51 PM
If you only want to save to SD card you don't need the float routines. You can simply get the strings from the GPS, and parse the fields you are interested in in the SD card.

Check
obex.parallax.com/objects/579/ (http://obex.parallax.com/objects/579/)
(only one cog, I haven't tested it yet)

and

obex.parallax.com/objects/225/ (http://obex.parallax.com/objects/225/)
(2 cogs, the GPS parsing engine works very well)

Massimo