Browse Source

added gui elements

subDesTagesMitExtraKaese 3 years ago
parent
commit
e8c9db2704

+ 1 - 1
raspberry-pi/gui/Popup.py

@@ -11,7 +11,7 @@ class CalibrationPopUp(tk.Frame):
     tk.Frame.__init__(self, root)
     tk.Frame.__init__(self, root)
     self.pendingClose = False
     self.pendingClose = False
 
 
-    self.instruction = tk.Label(self,text="Start Calibration", anchor="c",font=("Courier",18))
+    self.instruction = tk.Label(self,text="Start Calibration", anchor="c",font=("Helvatica", 18, 'bold'))
     self.instruction.pack(side="top", fill="both", expand=True)
     self.instruction.pack(side="top", fill="both", expand=True)
     button = tk.Button(self,text="OK", command=self.calibration_state.next_state_gui, anchor="c",height=1,width=5)
     button = tk.Button(self,text="OK", command=self.calibration_state.next_state_gui, anchor="c",height=1,width=5)
     button.pack(side="top", fill="both", expand=True)
     button.pack(side="top", fill="both", expand=True)

+ 3 - 0
raspberry-pi/gui/graph.py

@@ -70,3 +70,6 @@ class Graph(tk.Canvas):
 
 
     self.photo = ImageTk.PhotoImage(self.canvas)
     self.photo = ImageTk.PhotoImage(self.canvas)
     self.itemconfig(self.image, image=self.photo)
     self.itemconfig(self.image, image=self.photo)
+
+  def clear(self):
+    self.canvas = self.bg.copy()

+ 33 - 8
raspberry-pi/gui/mainWindow.py

@@ -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()

+ 2 - 3
raspberry-pi/sensors/acusticSensor.py

@@ -60,7 +60,7 @@ class AcusticSensor:
         value = (2076+random.randint(-50,50),1541+random.randint(-50,50))
         value = (2076+random.randint(-50,50),1541+random.randint(-50,50))
 
 
       self.calibrate(value)
       self.calibrate(value)
-      self.pass_to_gui(self.calculate_position(value))
+      self.pass_to_gui(self.calculate_position(value) + value)
       time.sleep(0.01)
       time.sleep(0.01)
 
 
   def _readCb(self, raw):
   def _readCb(self, raw):
@@ -71,8 +71,7 @@ class AcusticSensor:
 
 
     if value[0] >= 0 and value[1] >= 0:
     if value[0] >= 0 and value[1] >= 0:
       self.calibrate(value)
       self.calibrate(value)
-      x, y = self.calculate_position(value)
-      self.pass_to_gui((x, y, *value))
+      self.pass_to_gui(self.calculate_position(value) + value)
 
 
   def calibrate(self, value):
   def calibrate(self, value):
 
 

+ 12 - 8
raspberry-pi/sensors/connection.py

@@ -52,6 +52,8 @@ class SerialConnection:
     if self._ser:
     if self._ser:
       try:
       try:
         return self._ser.read(n)
         return self._ser.read(n)
+      except AttributeError:
+        return None
       except serial.SerialException:
       except serial.SerialException:
         self._ser = None
         self._ser = None
         return None
         return None
@@ -64,6 +66,8 @@ class SerialConnection:
     if self._ser:
     if self._ser:
       try:
       try:
         return self._ser.readline()
         return self._ser.readline()
+      except AttributeError:
+        return None
       except serial.SerialException:
       except serial.SerialException:
         self._ser = None
         self._ser = None
         return None
         return None
@@ -97,31 +101,31 @@ class ArduinoSlave(SerialConnection):
     super().close()
     super().close()
 
 
   def getAcusticRTTs(self): # in microseconds
   def getAcusticRTTs(self): # in microseconds
-    return [
+    return (
       int(self.sensorData[0]) / 16,
       int(self.sensorData[0]) / 16,
       int(self.sensorData[1]) / 16
       int(self.sensorData[1]) / 16
-    ]
+    )
 
 
   def getMagneticField(self): # in mT
   def getMagneticField(self): # in mT
-    return [
+    return (
       int(self.sensorData[2]) / 1000,
       int(self.sensorData[2]) / 1000,
       int(self.sensorData[3]) / 1000,
       int(self.sensorData[3]) / 1000,
       int(self.sensorData[4]) / 1000
       int(self.sensorData[4]) / 1000
-    ]
+    )
   
   
   def getAccelValues(self):
   def getAccelValues(self):
-    return [
+    return (
       int(self.sensorData[5]) / 1000,
       int(self.sensorData[5]) / 1000,
       int(self.sensorData[6]) / 1000,
       int(self.sensorData[6]) / 1000,
       int(self.sensorData[7]) / 1000
       int(self.sensorData[7]) / 1000
-    ]
+    )
   
   
   def getGyroValues(self):
   def getGyroValues(self):
-    return [
+    return (
       int(self.sensorData[8])  / 1000,
       int(self.sensorData[8])  / 1000,
       int(self.sensorData[9])  / 1000,
       int(self.sensorData[9])  / 1000,
       int(self.sensorData[10]) / 1000
       int(self.sensorData[10]) / 1000
-    ]
+    )
   
   
   def getTemperature(self): # in °C
   def getTemperature(self): # in °C
     return int(self.sensorData[11]) / 1000
     return int(self.sensorData[11]) / 1000