add graph_imu.py
authorOlivier Matz <zer0@droids-corp.org>
Thu, 26 Jun 2014 18:43:01 +0000 (20:43 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 26 Jun 2014 18:43:38 +0000 (20:43 +0200)
graph_imu.py [new file with mode: 0644]

diff --git a/graph_imu.py b/graph_imu.py
new file mode 100644 (file)
index 0000000..e32716d
--- /dev/null
@@ -0,0 +1,83 @@
+import sys, re
+import matplotlib
+matplotlib.use('QT4Agg')
+import numpy as np
+import matplotlib.pyplot as plt
+
+FLOAT = "([-+]?[0-9]*\.?[0-9]+)"
+INT = "([-+]?[0-9][0-9]*)"
+
+FILTER = 1
+
+tab_t = []
+tab_g1 = []
+tab_g2 = []
+tab_g3 = []
+tab_a1 = []
+tab_a2 = []
+tab_a3 = []
+tab_m1 = []
+tab_m2 = []
+tab_m3 = []
+
+f = open(sys.argv[1])
+while True:
+    l = f.readline()
+    if l == "":
+        break
+
+    regex = "%s.*gyro\s*%s\s*%s\s*%s\s*"%(INT, FLOAT, FLOAT, FLOAT)
+    regex += "accel\s*%s\s*%s\s*%s\s*"%(FLOAT, FLOAT, FLOAT)
+    regex += "magnet\s*%s\s*%s\s*%s\s*"%(FLOAT, FLOAT, FLOAT)
+
+    m = re.match(regex, l)
+    if m:
+        t, g1, g2, g3, a1, a2, a3, m1, m2, m3 = map(lambda x: float(x), m.groups())
+        tab_t.append(t)
+        tab_g1.append(g1)
+        tab_g2.append(g2)
+        tab_g3.append(g3)
+        tab_a1.append(a1)
+        tab_a2.append(a2)
+        tab_a3.append(a3)
+        tab_m1.append(m1)
+        tab_m2.append(m2)
+        tab_m3.append(m3)
+        print t, g1, g2, g3, a1, a2, a3, m1, m2, m3
+
+def mean(tab, n):
+    ret = []
+    for i in range(len(tab)-n):
+        s = reduce(lambda x,y:x+y, tab[i:i+n], 0)
+        ret.append(s/n)
+    return ret
+
+tab_a1 = mean(tab_a1, FILTER)
+tab_a2 = mean(tab_a2, FILTER)
+tab_a3 = mean(tab_a3, FILTER)
+tab_g1 = mean(tab_g1, FILTER)
+tab_g2 = mean(tab_g2, FILTER)
+tab_g3 = mean(tab_g3, FILTER)
+tab_m1 = mean(tab_m1, FILTER)
+tab_m2 = mean(tab_m2, FILTER)
+tab_m3 = mean(tab_m3, FILTER)
+
+# line, = plt.plot(tab_t[:-FILTER], tab_a1, 'r-')
+# line, = plt.plot(tab_t[:-FILTER], tab_a2, 'g-')
+# line, = plt.plot(tab_t[:-FILTER], tab_a3, 'b-')
+
+line, = plt.plot(tab_t[:-FILTER], tab_g1, 'r-')
+line, = plt.plot(tab_t[:-FILTER], tab_g2, 'g-')
+line, = plt.plot(tab_t[:-FILTER], tab_g3, 'b-')
+
+# line, = plt.plot(tab_t[:-FILTER], tab_m1, 'r-')
+# line, = plt.plot(tab_t[:-FILTER], tab_m2, 'g-')
+# line, = plt.plot(tab_t[:-FILTER], tab_m3, 'b-')
+
+
+#dashes = [10, 5, 100, 5] # 10 points on, 5 off, 100 on, 5 off
+#line.set_dashes(dashes)
+
+plt.show()
+
+