|
@@ -1,6 +1,7 @@
|
|
import tkinter as tk
|
|
import tkinter as tk
|
|
import time
|
|
import time
|
|
import queue
|
|
import queue
|
|
|
|
+import numpy as np
|
|
|
|
|
|
from gui.popup import CalibrationPopUp
|
|
from gui.popup import CalibrationPopUp
|
|
from gui.graph import Graph
|
|
from gui.graph import Graph
|
|
@@ -17,34 +18,58 @@ class MainWindow(tk.Frame):
|
|
self.graph = Graph(self)
|
|
self.graph = Graph(self)
|
|
self.graph.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
|
|
self.graph.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
|
|
|
|
|
|
- self.controls = tk.Frame(self)
|
|
|
|
|
|
+ self.controls = tk.Frame(self, borderwidth=4)
|
|
self.controls.pack(fill=tk.BOTH, side=tk.RIGHT)
|
|
self.controls.pack(fill=tk.BOTH, side=tk.RIGHT)
|
|
|
|
+ self.controlsUpdateTime = 0
|
|
|
|
|
|
|
|
+ self.ac_dro_val_sums = np.ndarray((4), dtype=np.float)
|
|
|
|
+ self.ac_dro_val_count = 0
|
|
self.ac_dro_x = tk.StringVar()
|
|
self.ac_dro_x = tk.StringVar()
|
|
self.ac_dro_y = tk.StringVar()
|
|
self.ac_dro_y = tk.StringVar()
|
|
- tk.Label(self.controls, text="Acustic Sensor", anchor="c").pack(side="top", fill="both", expand=False)
|
|
|
|
|
|
+ self.ac_dro_t1 = tk.StringVar()
|
|
|
|
+ self.ac_dro_t2 = tk.StringVar()
|
|
|
|
+ tk.Label(self.controls, text="Acustic Sensor", anchor="c", font=("Helvatica", 10, 'bold')).pack(side="top", fill="both", expand=False)
|
|
tk.Label(self.controls, textvariable=self.ac_dro_x, anchor="nw").pack(side="top", fill="both", expand=False)
|
|
tk.Label(self.controls, textvariable=self.ac_dro_x, anchor="nw").pack(side="top", fill="both", expand=False)
|
|
tk.Label(self.controls, textvariable=self.ac_dro_y, anchor="nw").pack(side="top", fill="both", expand=False)
|
|
tk.Label(self.controls, textvariable=self.ac_dro_y, anchor="nw").pack(side="top", fill="both", expand=False)
|
|
|
|
+ tk.Label(self.controls, textvariable=self.ac_dro_t1, anchor="nw").pack(side="top", fill="both", expand=False)
|
|
|
|
+ tk.Label(self.controls, textvariable=self.ac_dro_t2, anchor="nw").pack(side="top", fill="both", expand=False)
|
|
|
|
|
|
- calibrate_button = tk.Button(self.controls,text="calibrate",command=self.calibrate)
|
|
|
|
- calibrate_button.pack(side="top", fill="both")
|
|
|
|
|
|
+ calibrate_button = tk.Button(self.controls, text="Calibrate", command=self.calibrate, height=3)
|
|
|
|
+ calibrate_button.pack(side="bottom", fill="both")
|
|
|
|
+
|
|
|
|
+ clear_button = tk.Button(self.controls, text="Clear graph", command=self.graph.clear)
|
|
|
|
+ clear_button.pack(side="bottom", fill="both")
|
|
|
|
|
|
def update(self):
|
|
def update(self):
|
|
if not self.root.winfo_exists():
|
|
if not self.root.winfo_exists():
|
|
return
|
|
return
|
|
|
|
|
|
ac_positions = []
|
|
ac_positions = []
|
|
- ac_raw_vals = (0, 0)
|
|
|
|
|
|
+
|
|
while self.ac_queue.qsize() > 0:
|
|
while self.ac_queue.qsize() > 0:
|
|
name, data = self.ac_queue.get()
|
|
name, data = self.ac_queue.get()
|
|
if name == "data":
|
|
if name == "data":
|
|
ac_positions.append(data[0:2])
|
|
ac_positions.append(data[0:2])
|
|
- ac_raw_vals = data[2:4]
|
|
|
|
|
|
+ self.ac_dro_val_sums += data
|
|
|
|
+ self.ac_dro_val_count += 1
|
|
|
|
|
|
if len(ac_positions) > 0:
|
|
if len(ac_positions) > 0:
|
|
self.graph.update([ac_positions])
|
|
self.graph.update([ac_positions])
|
|
- self.ac_dro_x.set("X: {:3.1f} mm".format(ac_positions[-1][0]))
|
|
|
|
- self.ac_dro_y.set("Y: {:3.1f} mm".format(ac_positions[-1][1]))
|
|
|
|
|
|
+
|
|
|
|
+ if self.controlsUpdateTime + 0.4 < time.time():
|
|
|
|
+ self.controlsUpdateTime = time.time()
|
|
|
|
+ if self.ac_dro_val_count > 0:
|
|
|
|
+ self.ac_dro_val_sums /= self.ac_dro_val_count
|
|
|
|
+ else:
|
|
|
|
+ self.ac_dro_val_sums.fill(0)
|
|
|
|
+
|
|
|
|
+ self.ac_dro_x.set("X: {:.1f} mm".format(self.ac_dro_val_sums[0]))
|
|
|
|
+ self.ac_dro_y.set("Y: {:.1f} mm".format(self.ac_dro_val_sums[1]))
|
|
|
|
+ self.ac_dro_t1.set("t1: {:.3f} ms".format(self.ac_dro_val_sums[2]/1000))
|
|
|
|
+ self.ac_dro_t2.set("t2: {:.3f} ms".format(self.ac_dro_val_sums[3]/1000))
|
|
|
|
+
|
|
|
|
+ self.ac_dro_val_sums.fill(0)
|
|
|
|
+ self.ac_dro_val_count = 0
|
|
|
|
|
|
if self.popup:
|
|
if self.popup:
|
|
self.popup.update()
|
|
self.popup.update()
|