2 Revīzijas de61b5b541 ... 7fedbe4f27

Autors SHA1 Ziņojums Datums
  Janek 7fedbe4f27 Merge branch 'master' of https://gogs.es-lab.de/wokoeck_ch/lern-tracking-system 3 gadi atpakaļ
  Janek cd11a07c96 mainWindow + magnetic Sensor 3 gadi atpakaļ
2 mainītis faili ar 60 papildinājumiem un 7 dzēšanām
  1. 18 6
      raspberry-pi/mainWindow.py
  2. 42 1
      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()
     

+ 42 - 1
raspberry-pi/sensors/magneticSensor.py

@@ -1,5 +1,10 @@
 import queue
 import time
+<<<<<<< HEAD
+import threading
+import random
+=======
+>>>>>>> de61b5b54174156bc78823188e70ac7b94fdde66
 
 from sensors.connection import globalArduinoSlave
 import logHandler
@@ -11,6 +16,18 @@ class MagneticSensor:
   def __init__(self, conf):
     self.conf = conf
     self.queue = queue.Queue()
+<<<<<<< HEAD
+    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"])
+
+    self.n = 0
+  
+    #pass
+=======
     self.log_handler = logHandler.get_log_handler()
     self.gyro_x = []
     self.gyro_y = []
@@ -18,11 +35,31 @@ class MagneticSensor:
     self.offset_x = 0 #
     self.offset_y = 0 #
     self.offset_z = 0 #
+>>>>>>> de61b5b54174156bc78823188e70ac7b94fdde66
 
   def start(self):
     if not conn.isConnected():
       conn.open()
     conn.addRecvCallback(self._readCb)
+<<<<<<< HEAD
+    self.dummyActive = True
+    dummyThread = threading.Thread(target=self._readCb_dummy)
+    dummyThread.start()
+
+  def _readCb(self, raw):
+    print("mag: ", conn.getMagneticField())
+
+  def _readCb_dummy(self):
+    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
+=======
     self.calibrate() #
 
   def _readCb(self, raw):
@@ -46,10 +83,14 @@ class MagneticSensor:
         #pass
     # Accelerometer Calibration
     # Magnetometer Calibration
+>>>>>>> de61b5b54174156bc78823188e70ac7b94fdde66
 
   def read(self):
     return conn.getMagneticField()
 
   def stop(self):
     self.log_handler.log_and_print("stop magnetic sensor")
-    conn.close
+    conn.close()
+
+  def pass_to_gui(self, data):
+    self.queue.put(("data", data))