3 Commits ced877ce09 ... 94a864b40a

Author SHA1 Message Date
  subDesTagesMitExtraKaese 94a864b40a added graph axis labels 3 years ago
  subDesTagesMitExtraKaese 0fa79e40f0 Merge branch 'master' of ssh://gitlab.justprojects.de:4724/hochschule/lern-tracking-system 3 years ago
  subDesTagesMitExtraKaese 60cf6bd580 minor QoL changes 3 years ago

File diff suppressed because it is too large
+ 26 - 1
README.md


+ 5 - 1
raspberry-pi/config.ini

@@ -38,4 +38,8 @@
 
 
 [mag_sensor]
 [mag_sensor]
 
 
-[opt_sensor]
+[opt_sensor]
+
+[gui]
+  fullscreen = yes
+  log_lines  = 100

+ 5 - 2
raspberry-pi/gui/graph.py

@@ -39,6 +39,9 @@ class Graph(tk.Canvas):
     begin = math.floor(self.scale[0] / step) * step
     begin = math.floor(self.scale[0] / step) * step
     end   = math.ceil(self.scale[1] / step) * step
     end   = math.ceil(self.scale[1] / step) * step
     halfStep = int(step / 2)
     halfStep = int(step / 2)
+    # label x and y axis
+    draw.text(self.pointToCoord(((end+begin)/2+25, -30)), "x in mm", font=self.font, align='center')
+    draw.text(self.pointToCoord((-45, (end+begin)/2+25)), "y in mm", font=self.font, align='left')
     for p in range(begin, end, halfStep):
     for p in range(begin, end, halfStep):
       tickPosX = self.pointToCoord((p, 0))
       tickPosX = self.pointToCoord((p, 0))
       tickPosY = self.pointToCoord((0, p))
       tickPosY = self.pointToCoord((0, p))
@@ -52,9 +55,9 @@ class Graph(tk.Canvas):
       draw.line([(tickPosX[0], tickPosX[1]+self.lineWidth*3), (tickPosX[0], tickPosX[1]-self.lineWidth*3)], (60,127,100), int(self.lineWidth/2))
       draw.line([(tickPosX[0], tickPosX[1]+self.lineWidth*3), (tickPosX[0], tickPosX[1]-self.lineWidth*3)], (60,127,100), int(self.lineWidth/2))
       draw.line([(tickPosY[0]+self.lineWidth*3, tickPosY[1]), (tickPosY[0]-self.lineWidth*3, tickPosY[1])], (60,127,100), int(self.lineWidth/2))
       draw.line([(tickPosY[0]+self.lineWidth*3, tickPosY[1]), (tickPosY[0]-self.lineWidth*3, tickPosY[1])], (60,127,100), int(self.lineWidth/2))
       # draw tick labels
       # draw tick labels
-      draw.text((tickPosX[0]+3, tickPosX[1]+self.lineWidth*4), str(p) + " mm", font=self.font)
+      draw.text((tickPosX[0]+3, tickPosX[1]+self.lineWidth*1), str(p), font=self.font)
       if p != 0:
       if p != 0:
-        draw.text((tickPosY[0]-self.lineWidth*4-35, tickPosY[1]), str(p) + " mm", font=self.font)
+        draw.text((tickPosY[0]+self.lineWidth*2, tickPosY[1]), str(p), font=self.font, align='right')
 
 
   def on_resize(self,event):
   def on_resize(self,event):
     self.width = max(100, event.width-4)
     self.width = max(100, event.width-4)

+ 3 - 3
raspberry-pi/gui/logScreen.py

@@ -30,7 +30,7 @@ class LogScreen(tk.Frame):
     self.quit_button = tk.Button(self, text="Close", command=self.close, height=2, width = 10)
     self.quit_button = tk.Button(self, text="Close", command=self.close, height=2, width = 10)
     self.quit_button.pack(side="right", fill="both")
     self.quit_button.pack(side="right", fill="both")
 
 
-    self.disable_refresh_button = tk.Button(self,text="disable refreshing", command=self.toggle_refreshing, height=2, width=20, relief="raised", bg="green", fg="white")
+    self.disable_refresh_button = tk.Button(self,text="disable refreshing", command=self.toggle_refreshing, height=2, width=20, relief="raised", bg="green", activebackground="#00dd00", fg="white")
     self.disable_refresh_button.pack(side="right", fill="both")
     self.disable_refresh_button.pack(side="right", fill="both")
 
 
     for element in self.log_handler.get_log_list():
     for element in self.log_handler.get_log_list():
@@ -56,6 +56,6 @@ class LogScreen(tk.Frame):
   def toggle_refreshing(self):
   def toggle_refreshing(self):
     self.disable_refresh = not self.disable_refresh
     self.disable_refresh = not self.disable_refresh
     if self.disable_refresh:
     if self.disable_refresh:
-      self.disable_refresh_button.config(text="Enable refresh", relief="sunken", bg="red")
+      self.disable_refresh_button.config(text="Enable refresh", relief="sunken", background="#ee0000", activebackground="#ff0000")
     else:
     else:
-      self.disable_refresh_button.config(text="Disable refresh", relief="raised", bg="green")
+      self.disable_refresh_button.config(text="Disable refresh", relief="raised", background="green", activebackground="#00dd00")

+ 3 - 4
raspberry-pi/gui/mainWindow.py

@@ -11,13 +11,12 @@ import logHandler
 
 
 
 
 class MainWindow(tk.Frame):
 class MainWindow(tk.Frame):
-  def __init__(self, root, ac_sensor, ac_queue, ac_cal_state, conf):
+  def __init__(self, root, ac_sensor, ac_cal_state, conf):
     self.root = root
     self.root = root
     self.popup = None
     self.popup = None
     self.log_window = None
     self.log_window = None
     self.ac_cal_state = ac_cal_state
     self.ac_cal_state = ac_cal_state
     self.ac_sensor = ac_sensor
     self.ac_sensor = ac_sensor
-    self.ac_queue = ac_queue
     self.log_handler = logHandler.get_log_handler()
     self.log_handler = logHandler.get_log_handler()
     self.conf = conf
     self.conf = conf
 
 
@@ -61,8 +60,8 @@ class MainWindow(tk.Frame):
 
 
     ac_positions = []
     ac_positions = []
     # aggregate measurements
     # aggregate measurements
-    while self.ac_queue.qsize() > 0:
-      name, data = self.ac_queue.get()
+    while self.ac_sensor.queue.qsize() > 0:
+      name, data = self.ac_sensor.queue.get()
       if name == "data":
       if name == "data":
         ac_positions.append(data[0:2])
         ac_positions.append(data[0:2])
         self.ac_dro_val_sums += data
         self.ac_dro_val_sums += data

+ 5 - 4
raspberry-pi/logHandler.py

@@ -1,15 +1,16 @@
 import datetime
 import datetime
 
 
 class LogList():
 class LogList():
-  def __init__(self):
+  def __init__(self, line_count):
     self.log_list = list()
     self.log_list = list()
     self.read_index = 0
     self.read_index = 0
     self.write_index = 0
     self.write_index = 0
+    self.line_count = line_count
 
 
   def add_item(self, item):
   def add_item(self, item):
     self.log_list.append(item)
     self.log_list.append(item)
     self.write_index += 1
     self.write_index += 1
-    if len(self.log_list) > 100:
+    if len(self.log_list) > self.line_count:
       self.log_list.pop(0)
       self.log_list.pop(0)
 
 
   def log_and_print(self, *args):
   def log_and_print(self, *args):
@@ -30,8 +31,8 @@ class LogList():
 
 
 _log_handler = None
 _log_handler = None
 
 
-def get_log_handler():
+def get_log_handler(line_count = 100):
   global _log_handler
   global _log_handler
   if not _log_handler:
   if not _log_handler:
-    _log_handler = LogList()
+    _log_handler = LogList(line_count)
   return _log_handler
   return _log_handler

+ 7 - 7
raspberry-pi/main.py

@@ -1,8 +1,9 @@
+#!/usr/bin/env python3
+
 from sensors.acousticSensor import AcousticSensor
 from sensors.acousticSensor import AcousticSensor
 from sensors.calibration import CalibrationStateMashine
 from sensors.calibration import CalibrationStateMashine
 from gui.mainWindow import MainWindow
 from gui.mainWindow import MainWindow
 
 
-import queue
 import configparser
 import configparser
 import tkinter as tk
 import tkinter as tk
 import traceback
 import traceback
@@ -12,17 +13,16 @@ conf = configparser.ConfigParser()
 conf.read('config.ini')
 conf.read('config.ini')
 
 
 def main():
 def main():
-  log_handler = logHandler.get_log_handler()
-  ac_queue = queue.Queue()
-  ac_calibration_state = CalibrationStateMashine(log_handler)
-  ac_sensor = AcousticSensor(conf, ac_queue, ac_calibration_state)
+  log_handler = logHandler.get_log_handler(int(conf['gui']['log_lines']))
+  ac_calibration_state = CalibrationStateMashine()
+  ac_sensor = AcousticSensor(conf, ac_calibration_state)
 
 
   try:
   try:
     ac_sensor.start()
     ac_sensor.start()
     root = tk.Tk()
     root = tk.Tk()
     root.title("Tracking System")
     root.title("Tracking System")
-    root.attributes('-fullscreen', True)
-    view = MainWindow(root, ac_sensor, ac_queue, ac_calibration_state, conf)
+    root.attributes('-fullscreen', conf['gui']['fullscreen'] == "yes")
+    view = MainWindow(root, ac_sensor, ac_calibration_state, conf)
     view.pack(side="top", fill="both", expand=True)
     view.pack(side="top", fill="both", expand=True)
     view.update()
     view.update()
     root.mainloop()
     root.mainloop()

+ 5 - 0
raspberry-pi/requirements.txt

@@ -0,0 +1,5 @@
+numpy==1.17.4
+pyglet==1.5.15
+opencv_python==4.4.0.44
+Pillow==8.3.1
+pyserial==3.5

+ 4 - 3
raspberry-pi/sensors/acousticSensor.py

@@ -4,6 +4,7 @@ import math
 import threading
 import threading
 import random
 import random
 import traceback
 import traceback
+import queue
 
 
 from sensors.connection import globalArduinoSlave
 from sensors.connection import globalArduinoSlave
 import logHandler
 import logHandler
@@ -12,9 +13,9 @@ conn = globalArduinoSlave()
 
 
 
 
 class AcousticSensor:
 class AcousticSensor:
-  def __init__(self, conf, ac_queue, calibration_state):
+  def __init__(self, conf, calibration_state):
     self.conf = conf
     self.conf = conf
-    self.ac_queue               = ac_queue
+    self.queue                  = queue.Queue()
     self.calibration_state      = calibration_state
     self.calibration_state      = calibration_state
     self.field_height           = float(conf["field"]["y"])
     self.field_height           = float(conf["field"]["y"])
     self.field_width            = float(conf["field"]["x"])
     self.field_width            = float(conf["field"]["x"])
@@ -183,4 +184,4 @@ class AcousticSensor:
     return (distance_left / sonic_speed + overhead_left, distance_right / sonic_speed + overhead_right)
     return (distance_left / sonic_speed + overhead_left, distance_right / sonic_speed + overhead_right)
 
 
   def pass_to_gui(self, data):
   def pass_to_gui(self, data):
-    self.ac_queue.put(("data", data))
+    self.queue.put(("data", data))

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

@@ -1,7 +1,8 @@
+import logHandler
 
 
 class CalibrationStateMashine():
 class CalibrationStateMashine():
 
 
-  def __init__(self,log_handler):
+  def __init__(self):
     self.state = 0
     self.state = 0
     self.progress = 0
     self.progress = 0
 
 
@@ -12,7 +13,7 @@ class CalibrationStateMashine():
     self.ACCUMULATING_2 = 4
     self.ACCUMULATING_2 = 4
     self.CALIBRATION_DONE = 5
     self.CALIBRATION_DONE = 5
 
 
-    self.log_handler = log_handler
+    self.log_handler = logHandler.get_log_handler()
     
     
   def state_clearname(self):
   def state_clearname(self):
     if self.state == self.NOT_CALIBRATED:
     if self.state == self.NOT_CALIBRATED: