4666 |
jacho |
1 |
#!/usr/bin/python |
|
|
2 |
|
|
|
3 |
# plot with >> plot 'last.txt' u 1:2 w l axes x1y1, 'last.txt' u 1:4 w l axes x1y2, 'last.txt' u 1:3 |
|
|
4 |
|
|
|
5 |
import os |
|
|
6 |
import time |
|
|
7 |
import datetime |
|
|
8 |
import sys |
|
|
9 |
import numpy as np |
|
|
10 |
from gps import * |
|
|
11 |
from pymlab import config |
|
|
12 |
import threading |
|
|
13 |
|
|
|
14 |
gpsd = None |
|
|
15 |
|
|
|
16 |
class GpsPoller(threading.Thread): |
|
|
17 |
def __init__(self): |
|
|
18 |
threading.Thread.__init__(self) |
|
|
19 |
global gpsd #bring it in scope |
|
|
20 |
gpsd = gps(mode=WATCH_ENABLE) |
|
|
21 |
self.current_value = None |
|
|
22 |
self.running = True |
4702 |
roman |
23 |
|
4666 |
jacho |
24 |
def run(self): |
|
|
25 |
global gpsd |
|
|
26 |
while gpsp.running: |
|
|
27 |
gpsd.next() |
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
4702 |
roman |
31 |
|
4666 |
jacho |
32 |
cfg = config.Config( |
|
|
33 |
i2c = { |
|
|
34 |
"port": 1, |
|
|
35 |
}, |
|
|
36 |
bus = [ |
|
|
37 |
{ |
|
|
38 |
"name": "rps", |
|
|
39 |
"type": "rps01", |
|
|
40 |
}, |
|
|
41 |
], |
|
|
42 |
) |
|
|
43 |
|
|
|
44 |
|
|
|
45 |
cfg.initialize() |
|
|
46 |
|
|
|
47 |
print "RPS01A logger" |
|
|
48 |
sensor = cfg.get_device("rps") |
|
|
49 |
|
|
|
50 |
|
|
|
51 |
try: |
|
|
52 |
filen = 'log%0.0f.txt'%time.time() |
|
|
53 |
f = open(filen,'w') |
|
|
54 |
os.remove("last.txt") |
|
|
55 |
os.symlink(filen, "last.txt") |
4702 |
roman |
56 |
|
4666 |
jacho |
57 |
gpsp = GpsPoller() |
|
|
58 |
gpsp.start() |
|
|
59 |
|
|
|
60 |
while True: |
4702 |
roman |
61 |
w_spd = abs(sensor.get_speed()) |
|
|
62 |
g_spd = abs(gpsd.fix.speed()) |
4666 |
jacho |
63 |
|
4702 |
roman |
64 |
print "W_Spd: %.3f \t G_Spd %.3f \t multiplayer: %.3f \t multiplayer: %.3f" % (w_spd, g_spd, w_spd/g_spd, g_spd/w_spd) |
|
|
65 |
f.write("%.3f %.3f %.3f\r\n" %(time.time(), w_spd, g_spd)) |
|
|
66 |
f.flush() |
4666 |
jacho |
67 |
|
|
|
68 |
|
|
|
69 |
except KeyboardInterrupt: |
|
|
70 |
gpsp.running = False |
|
|
71 |
gpsp.join() |
|
|
72 |
sys.exit(0) |