Bladeren bron

mainWindow + magnetic Sensor

Janek 3 jaren geleden
bovenliggende
commit
cd11a07c96
3 gewijzigde bestanden met toevoegingen van 32 en 9 verwijderingen
  1. 18 6
      raspberry-pi/mainWindow.py
  2. 1 1
      raspberry-pi/sensors/acousticSensor.py
  3. 13 2
      raspberry-pi/sensors/magneticSensor.py

+ 18 - 6
raspberry-pi/mainWindow.py

@@ -58,12 +58,14 @@ class MainWindow(tk.Frame):
     tk.Label(self.controls, textvariable=self.opt_dro_offset, anchor="nw").pack(side="top", fill="both", expand=False)
     tk.Label(self.controls, textvariable=self.opt_dro_size, anchor="nw").pack(side="top", fill="both", expand=False)
 
+    self.mag_dro_val_sums = np.ndarray((4), dtype=np.float)
+    self.mag_dro_val_count = 0
     self.mag_label = tk.Label(self.controls, text="Magnetic Sensor", anchor="c", font=("Helvatica", 10, 'bold'))
     self.mag_label.pack(side="top", fill="both", expand=False)
     self.mag_dro_x = tk.StringVar()
     self.mag_dro_y = tk.StringVar()
-    self.mag_dro_val_sums = tk.StringVar()
-    self.mag_dro_val_count = tk.StringVar()
+    self.mag_dro_offset_x = tk.StringVar()
+    self.mag_dro_offset_y = tk.StringVar()
     tk.Label(self.controls, textvariable=self.mag_dro_x, anchor = "nw").pack(side = "top", fill = "both", expand = False)
     tk.Label(self.controls, textvariable=self.mag_dro_y, anchor = "nw").pack(side = "top", fill = "both", expand = False)
     tk.Label(self.controls, textvariable=self.mag_dro_x, anchor = "nw").pack(side = "top", fill = "both", expand = False)
@@ -138,7 +140,7 @@ class MainWindow(tk.Frame):
     else:
       self.opt_label.config(fg="black", bg="yellow")
 
-    if not self.mag_sensor.:
+    if not self.mag_sensor.success:
      self.mag_label.config(fg="white", bg="red")
     elif len(mag_positions) > 0:
      self.mag_label.config(fg="white", bg="green")
@@ -160,7 +162,7 @@ class MainWindow(tk.Frame):
       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_sums.fill(0)    
       self.ac_dro_val_count = 0
 
       if self.opt_dro_val_count > 0:
@@ -170,12 +172,22 @@ class MainWindow(tk.Frame):
 
       self.opt_dro_x.set("X: {:.1f} mm".format(self.opt_dro_val_sums[0]))
       self.opt_dro_y.set("Y: {:.1f} mm".format(self.opt_dro_val_sums[1]))
-      self.opt_dro_offset.set("offset: {:.1f} %".format(self.opt_dro_val_sums[2]*100))
-      self.opt_dro_size.set("size: {:.1f} %".format(self.opt_dro_val_sums[3]*100))
+      self.opt_dro_offset.set("X Offset: {:.1f} %".format(self.opt_dro_val_sums[2]*100))
+      self.opt_dro_size.set("Y Offset: {:.1f} %".format(self.opt_dro_val_sums[3]*100))
 
       self.opt_dro_val_sums.fill(0)
       self.opt_dro_val_count = 0
 
+      if self.mag_dro_val_count > 0:
+        self.mag_dro_val_sums /= self.mag_dro_val_count
+      else:
+        self.mag_dro_val_sums.fill(0)
+
+      self.mag_dro_x.set("X: {:.1f} mm".format(self.opt_dro_val_sums[0]))
+      self.mag_dro_y.set("Y: {:.1f} mm".format(self.opt_dro_val_sums[1]))
+      self.mag_dro_offset_x.set("offset: {:.1f} %".format(self.opt_dro_val_sums[2]*100))
+      self.mag_dro_offset_y.set("size: {:.1f} %".format(self.opt_dro_val_sums[3]*100))
+
     if self.popup_window:
       self.popup_window.update()
     

+ 1 - 1
raspberry-pi/sensors/acousticSensor.py

@@ -158,7 +158,7 @@ class AcousticSensor:
         self.log_handler.log_and_print("  overhead_left:  {:8.3f} us".format(self.overhead_left))
         self.log_handler.log_and_print("  overhead_right: {:8.3f} us".format(self.overhead_right))
 
-        self.calibrathttps://gogs.es-lab.de/wokoeck_ch/lern-tracking-systemion_state.next_state()
+        self.calibration_state.next_state()
 
   def read(self):
     value = conn.getAcousticRTTs()

+ 13 - 2
raspberry-pi/sensors/magneticSensor.py

@@ -1,6 +1,7 @@
 import queue
 import time
 import threading
+import random
 
 from sensors.calibration import CalibrationStateMashine
 from sensors.connection import globalArduinoSlave
@@ -15,6 +16,7 @@ class MagneticSensor:
     self.queue = queue.Queue()
     self.calibration_state  = CalibrationStateMashine()
     self.log_handler = logHandler.get_log_handler() # neu
+    self.success = False
 
     self.field_height = float(conf["field"]["y"])
     self.field_width = float(conf["field"]["x"])
@@ -30,12 +32,18 @@ class MagneticSensor:
     conn.addRecvCallback(self._readCb)
     self.dummyActive = True
     dummyThread = threading.Thread(target=self._readCb_dummy)
+    dummyThread.start()
 
   def _readCb(self, raw):
     print("mag: ", conn.getMagneticField())
 
   def _readCb_dummy(self):
-    pass
+    self.log_handler.log_and_print("acoustic sensor: generating test values")
+    while self.dummyActive:
+      dummyValue = 250
+      position = 20
+
+      self.pass_to_gui(position + dummyValue)
 
   def calibrate(self, x, y):
     pass
@@ -45,4 +53,7 @@ class MagneticSensor:
 
   def stop(self): # neu
     self.log_handler.log_and_print("stop magnetic sensor")
-    conn.close
+    conn.close()
+
+  def pass_to_gui(self, data):
+    self.queue.put(("data", data))