diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-05-05 12:06:55 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-05-05 12:06:55 +0100 |
| commit | 421cdd72c6395719b56191c187d9f2ba31664670 (patch) | |
| tree | ab216b9573196f898b8c0e0770a46015deeec03e | |
| parent | b5914dd492fa4716737bbe43f4abcad5258b6396 (diff) | |
scale layers test
| -rw-r--r-- | TimelabTestAreaGRADIENT.png | bin | 0 -> 35814 bytes | |||
| -rw-r--r-- | TimelabTestAreaGUI.jpg | bin | 0 -> 63727 bytes | |||
| -rw-r--r-- | gps_serial.py~ | 80 | ||||
| -rw-r--r-- | gpspoller.pyc | bin | 2696 -> 0 bytes | |||
| -rw-r--r-- | latLng.pyc | bin | 1095 -> 0 bytes | |||
| -rw-r--r-- | layers.py | 31 | ||||
| -rw-r--r-- | layers.pyc | bin | 3862 -> 0 bytes | |||
| -rw-r--r-- | testreceive.pd | 16 | ||||
| -rw-r--r-- | timelabtest.xml | 11 | ||||
| -rwxr-xr-x | tomorrowtheground.py | 56 | ||||
| -rw-r--r-- | tomorrowthegroundGUI/data/TimelabTestAreaGRADIENT.png | bin | 0 -> 35814 bytes | |||
| -rw-r--r-- | tomorrowthegroundGUI/data/TimelabTestAreaGUI.jpg | bin | 0 -> 63727 bytes | |||
| -rw-r--r-- | tomorrowthegroundGUI/tomorrowthegroundGUI.pde | 28 | ||||
| -rw-r--r-- | ttg01.xml | 2 | ||||
| -rw-r--r-- | xml2obj.pyc | bin | 3905 -> 0 bytes |
15 files changed, 106 insertions, 118 deletions
diff --git a/TimelabTestAreaGRADIENT.png b/TimelabTestAreaGRADIENT.png Binary files differnew file mode 100644 index 0000000..f76c9f5 --- /dev/null +++ b/TimelabTestAreaGRADIENT.png diff --git a/TimelabTestAreaGUI.jpg b/TimelabTestAreaGUI.jpg Binary files differnew file mode 100644 index 0000000..200e5ad --- /dev/null +++ b/TimelabTestAreaGUI.jpg diff --git a/gps_serial.py~ b/gps_serial.py~ deleted file mode 100644 index c25581b..0000000 --- a/gps_serial.py~ +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/python
-
-# Copyright (C) 2007 by Jaroslaw Zachwieja
-# Published under the terms of GNU General Public License v2 or later.
-# License text available at http://www.gnu.org/licenses/licenses.html#GPL
-
-import serial
-import string
-
-gps = serial.Serial('/dev/ttyUSB0', 4800, timeout=1)
-file = '/tmp/nmea.kml'
-
-print "Serving data"
-
-latitude = 0
-longitude = 0
-speed = 0
-heading = 0
-altitude = 0
-range = 1000
-tilt = 30
-
-while 1:
- line = gps.readline()
- datablock = line.split(',')
-
- if line[0:6] == '$GPRMC':
- latitude_in = string.atof(datablock[3])
- longitude_in = string.atof(datablock[5])
- altitude = string.atof(datablock[8])
- speed_in = string.atof(datablock[7])
- heading = string.atof(datablock[8])
-
- if datablock[4] == 'S':
- latitude_in = -latitude_in
- if datablock[6] == 'W':
- longitude_in = -longitude_in
-
- latitude_degrees = int(latitude_in/100)
- latitude_minutes = latitude_in - latitude_degrees*100
-
- longitude_degrees = int(longitude_in/100)
- longitude_minutes = longitude_in - longitude_degrees*100
-
- latitude = latitude_degrees + (latitude_minutes/60)
- longitude = longitude_degrees + (longitude_minutes/60)
-
- speed = int(speed_in * 1.852)
- range = ( ( speed / 100 ) * 350 ) + 650
- tilt = ( ( speed / 120 ) * 43 ) + 30
-
- if speed < 10:
- range = 200
- tilt = 30
- heading = 0
-
- output = """<?xml version="1.0" encoding="UTF-8"?>
-<kml xmlns="http://earth.google.com/kml/2.0">
- <Placemark>
- <name>%s km/h</name>
- <description>^</description>
- <LookAt>
- <longitude>%s</longitude>
- <latitude>%s</latitude>
- <range>%s</range>
- <tilt>%s</tilt>
- <heading>%s</heading>
- </LookAt>
- <Point>
- <coordinates>%s,%s,%s</coordinates>
- </Point>
- </Placemark>
-</kml>""" % (speed,longitude,latitude,range,tilt,heading,longitude,latitude,altitude)
-
- f=open(file, 'w')
- f.write(output)
- f.close()
-
-ser.close()
-
diff --git a/gpspoller.pyc b/gpspoller.pyc Binary files differdeleted file mode 100644 index e8cda43..0000000 --- a/gpspoller.pyc +++ /dev/null diff --git a/latLng.pyc b/latLng.pyc Binary files differdeleted file mode 100644 index 11ac9e8..0000000 --- a/latLng.pyc +++ /dev/null @@ -2,10 +2,10 @@ from PIL import Image from latLng import latLng class layer: - """a generic GPS image layer""" + """template for a GPS image layer""" tl=latLng() br=latLng() - pixel=latLng() + pixel=(0,0) def __init__(self,file,ll1,ll2): try: self.image=Image.open(file) @@ -17,8 +17,6 @@ class layer: self.pixsize=latLng(abs(self.tl.lat-self.br.lat)/self.image.size[1],abs(self.tl.lng-self.br.lng)/self.image.size[0]) except: print "gps layer: failed to parse", file - def findpixel(self,pos): - return (int((pos.lng-self.tl.lng)/self.pixsize.lng),int((pos.lat-self.br.lat)/self.pixsize.lat)) def checkcoord(self,pos): p=self.findpixel(pos) if p!=self.pixel: @@ -26,11 +24,13 @@ class layer: return self.setcoord(p) else: return None + def findpixel(self,pos): + return (int((pos.lng-self.tl.lng)/self.pixsize.lng),int((pos.lat-self.br.lat)/self.pixsize.lat)) def setcoord(self,pos): - """constructs a list of messages when values change" + """to be overwritten: + gets a messages when values change" returns None otherwise""" - result=None - return r + return None class trigger(): """a generic trigger - @@ -66,6 +66,19 @@ class scalelayer(layer): """generates a varying signal based on interpolating a greyscale image uses sub pixel position""" def findpixel(self,pos): - return (int((pos.lng-self.tl.lng)/self.pixsize.lng),int((pos.lat-self.br.lat)/self.pixsize.lat)) + #float version + return ((pos.lng-self.tl.lng)/self.pixsize.lng,(pos.lat-self.br.lat)/self.pixsize.lat) + def setcommand(self,command): + self.command=command def setcoord(self,pos): - result=None
\ No newline at end of file + px=int(pos[0]) + py=int(pos[1]) + c=float(self.image.getpixel((px,py)))/255.0 + c1=float(self.image.getpixel((px+1,py)))/255.0 + c2=float(self.image.getpixel((px,py+1)))/255.0 + c3=float(self.image.getpixel((px+1,py+1)))/255.0 + xf=pos[0]-px + yf=pos[1]-py + #lerp sub-pixel value + return (self.command,(((c*(1.0-xf))+(c1*xf))*(1.0-yf))+(((c2*(1.0-xf))+(c3*xf))*yf)) +
\ No newline at end of file diff --git a/layers.pyc b/layers.pyc Binary files differdeleted file mode 100644 index e95e372..0000000 --- a/layers.pyc +++ /dev/null diff --git a/testreceive.pd b/testreceive.pd index d53a273..4cab815 100644 --- a/testreceive.pd +++ b/testreceive.pd @@ -1,14 +1,14 @@ -#N canvas 915 509 450 300 10; +#N canvas 886 488 450 300 10; #X obj 169 92 print udp; #X msg 29 61 /pd 1; #X msg 82 26 /other 1; #X obj 169 50 netreceive 5401 1; -#X obj 148 141 OSCroute /play; #X obj 145 210 print play; -#X obj 230 204 print other; -#X connect 1 0 4 0; -#X connect 2 0 4 0; +#X obj 266 211 print other; +#X obj 148 140 route play cc01; +#X connect 1 0 6 0; +#X connect 2 0 6 0; #X connect 3 0 0 0; -#X connect 3 0 4 0; -#X connect 4 0 5 0; -#X connect 4 1 6 0; +#X connect 3 0 6 0; +#X connect 6 0 4 0; +#X connect 6 2 5 0; diff --git a/timelabtest.xml b/timelabtest.xml new file mode 100644 index 0000000..03e1af9 --- /dev/null +++ b/timelabtest.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<tomorrowtheground gpsdevice="/dev/ttO0"> + <gps> + <scale file="TimelabTestAreaGRADIENT.png" ll1="51.043293,3.737025" ll2="51.042154,3.739584" freq="1.0" command="cc01"> + </scale> + </gps> + <bt freq="10"> + <trigger id="00:11:95:00:1A:CF" command="play" param="i01.wav"> + </trigger> + </bt> +</tomorrowtheground>
\ No newline at end of file diff --git a/tomorrowtheground.py b/tomorrowtheground.py index 5553b42..8ab6383 100755 --- a/tomorrowtheground.py +++ b/tomorrowtheground.py @@ -10,25 +10,55 @@ def signal_handler(signal, frame): signal.signal(signal.SIGINT, signal_handler) -import gpspoller -gpsp="" -if len(sys.argv)>1: - gpsp = GpsPoller(sys.argv[1]) - gpsp.start() - from latLng import * from layers import * from xml2obj import * -doc=xml2obj(open("ttg01.xml")) + +if len(sys.argv)<2: + print "usage: tomorrowtheground {configfile}" + +doc=xml2obj(open(sys.argv[1])) gpslayers=[] -for i in doc.gps.index: - #catch invalid xml - g=indexlayer(i.file,i.ll1,i.ll2) - for t in i.trigger: - g.triggers.append(trigger(int(t.id),t.command,t.param)) - gpslayers.append(g) + +#catch invalid xml +try: + for i in doc.gps.index: + #catch invalid xml + try: + g=indexlayer(i.file,i.ll1,i.ll2) + for t in i.trigger: + g.triggers.append(trigger(int(t.id),t.command,t.param)) + gpslayers.append(g) + except: + print "error parsing xml index entry" +except: + print "no index layers found" + +#catch invalid xml +try: + for i in doc.gps.scale: + #catch invalid xml + try: + g=scalelayer(i.file,i.ll1,i.ll2) + g.setcommand(i.command) + gpslayers.append(g) + except: + print "error parsing xml index entry" +except: + print "no scale layers found" +import gpspoller +gpsp="" + +try: + if len(sys.argv)>1: + gpsp = GpsPoller(doc.gpsdevice) + gpsp.start() +except: + print "gps device not found" + + import socket GUI_IP="127.0.0.1" diff --git a/tomorrowthegroundGUI/data/TimelabTestAreaGRADIENT.png b/tomorrowthegroundGUI/data/TimelabTestAreaGRADIENT.png Binary files differnew file mode 100644 index 0000000..f76c9f5 --- /dev/null +++ b/tomorrowthegroundGUI/data/TimelabTestAreaGRADIENT.png diff --git a/tomorrowthegroundGUI/data/TimelabTestAreaGUI.jpg b/tomorrowthegroundGUI/data/TimelabTestAreaGUI.jpg Binary files differnew file mode 100644 index 0000000..200e5ad --- /dev/null +++ b/tomorrowthegroundGUI/data/TimelabTestAreaGUI.jpg diff --git a/tomorrowthegroundGUI/tomorrowthegroundGUI.pde b/tomorrowthegroundGUI/tomorrowthegroundGUI.pde index b359409..ae035b1 100644 --- a/tomorrowthegroundGUI/tomorrowthegroundGUI.pde +++ b/tomorrowthegroundGUI/tomorrowthegroundGUI.pde @@ -9,18 +9,32 @@ float lat1,lng1,lat2,lng2,fw,fh; void setup() { bgmaps=new PImage[2]; - bgmaps[0] = loadImage("gentmap.png"); - bgmaps[1] = loadImage("indexmapV1.gif"); + int map=2; + switch (map) { + case 1: + bgmaps[0] = loadImage("gentmap.png"); + bgmaps[1] = loadImage("indexmapV1.gif"); + lat1=51.050608; + lng1=3.724698; + lat2=51.046878; + lng2=3.732852; + break; + case 2: + bgmaps[0] = loadImage("TimelabTestAreaGUI.jpg"); + bgmaps[1] = loadImage("TimelabTestAreaGRADIENT.png"); + lat1=51.043293; + lng1=3.737025; + lat2=51.042154; + lng2=3.739584; + break; + } usemap=0; - size(bgmap.width,bgmap.height); + size(bgmaps[0].width,bgmaps[0].height); frameRate(15); udp = new UDP(this); x=width/2; y=height/2; - lat1=51.050608; - lng1=3.724698; - lat2=51.046878; - lng2=3.732852; + fw=lng2-lng1; fh=lat1-lat2; } @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<tomorrowtheground> +<tomorrowtheground gpsdevice="/dev/ttO0"> <gps> <index file="indexmapV1.gif" ll1="51.050608,3.724698" ll2="51.046878,3.732852"> <trigger id="01" command="play" param="b01.wav"> diff --git a/xml2obj.pyc b/xml2obj.pyc Binary files differdeleted file mode 100644 index 180a0bb..0000000 --- a/xml2obj.pyc +++ /dev/null |
