소스 검색

deleted more duplicates + gyroscope calibration ready for testing

wokoeck_ch 3 년 전
부모
커밋
2d862d9048
5개의 변경된 파일11개의 추가작업 그리고 214개의 파일을 삭제
  1. 4 3
      raspberry-pi/config.ini
  2. 0 99
      raspberry-pi/graph.py
  3. 0 61
      raspberry-pi/logScreen.py
  4. 0 46
      raspberry-pi/popup.py
  5. 7 5
      raspberry-pi/sensors/magneticSensor.py

+ 4 - 3
raspberry-pi/config.ini

@@ -37,8 +37,9 @@
   overhead_right = 20
 
 [mag_sensor]
-measurements_gyro = 500   # amount of measurements used for the calibration of the Gyroscope
-measurements_accel = 1000 # amount of measurements used for the calibration of the Accelerometer
+# amount of measurements used for the calibration of the Gyroscope and the Accelerometer
+measurements_gyro = 500
+measurements_accel = 1000
 
 
 [opt_sensor]
@@ -56,5 +57,5 @@ measurements_accel = 1000 # amount of measurements used for the calibration of t
   fov = 53.50
 
 [gui]
-  fullscreen = no
+  fullscreen = yes
   log_lines  = 100

+ 0 - 99
raspberry-pi/graph.py

@@ -1,99 +0,0 @@
-import time, math
-
-import tkinter as tk
-from PIL import Image, ImageDraw, ImageTk, ImageFont
-
-
-class Graph(tk.Canvas):
-  def __init__(self, root, scale=(-50, 450), **kwargs):
-    self.root = root
-    tk.Canvas.__init__(self, root, **kwargs)
-    self.image = self.create_image(0, 0, image=None, anchor='nw')
-    self.height = self.winfo_reqheight()
-    self.width = self.winfo_reqwidth()
-    # store last point of plot to connect the lines
-    self.lastPoints = [(0, 0)] * 3
-    # scale contains the (min, max) values of both axes
-    self.scale = scale
-    # appearance of the plots
-    self.colors = [(100, 255, 100, 255), (255, 100, 100, 255) ,(100, 100, 255, 255)]
-    self.font = ImageFont.truetype("gui/SourceSansPro-Semibold.otf", 12)
-    self.lineWidth = 1
-    
-    # the background contains all static elements
-    self.drawBackground()
-    # the plots will be drawn on a separate canvas
-    self.canvas = self.bg.copy()
-
-    self.bind("<Configure>", self.on_resize)
-
-  def drawBackground(self):
-    self.bg = Image.new('RGB', (self.width, self.height), (0,10,0))
-    draw = ImageDraw.Draw(self.bg)
-    # draw x and y axis
-    axes = self.pointToCoord((0, 0))
-    draw.line([(0, axes[1]), (self.width, axes[1])], (60,127,127), self.lineWidth)
-    draw.line([(axes[0], 0), (axes[0], self.height)], (60,127,127), self.lineWidth)
-
-    step  = 10**int(math.log10(self.scale[1]-self.scale[0]))
-    begin = math.floor(self.scale[0] / step) * step
-    end   = math.ceil(self.scale[1] / step) * step
-    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):
-      tickPosX = self.pointToCoord((p, 0))
-      tickPosY = self.pointToCoord((0, p))
-      #draw grid
-      draw.line([(tickPosX[0], self.height), (tickPosX[0], 0)], (60,127,60), 1)
-      draw.line([(self.width, tickPosY[1]), (0, tickPosY[1])], (60,127,60), 1)
-    for p in range(begin, end, step):
-      tickPosX = self.pointToCoord((p, 0))
-      tickPosY = self.pointToCoord((0, p))
-      # draw ticks
-      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 tick labels
-      draw.text((tickPosX[0]+3, tickPosX[1]+self.lineWidth*1), str(p), font=self.font)
-      if p != 0:
-        draw.text((tickPosY[0]+self.lineWidth*2, tickPosY[1]), str(p), font=self.font, align='right')
-
-  def on_resize(self,event):
-    self.width = max(100, event.width-4)
-    self.height = max(100, event.height-4)
-    self.lineWidth = int(max(min(self.width,self.height) / 100, 1))
-    # resize the canvas 
-    self.canvas = self.canvas.resize((self.width, self.height))
-    self.drawBackground()
-    self.canvas = Image.blend(self.canvas, self.bg, 1)
-
-  # convert physical space to screen space
-  def pointToCoord(self, point):
-    return ((point[0] - self.scale[0]) / (self.scale[1]-self.scale[0]) * self.width, 
-      self.height - (point[1] - self.scale[0]) / (self.scale[1]-self.scale[0]) * self.height - 1)
-
-  def update(self, data):
-    # load first point of line
-    coord = [[self.pointToCoord(p)] for p in self.lastPoints if p]
-    newPoints = False
-    # append new points
-    for i in range(len(data)):
-      for point in data[i]:
-        coord[i].append(self.pointToCoord(point))
-        self.lastPoints[i] = point
-        newPoints = True
-
-    self.canvas = Image.blend(self.canvas, self.bg, 1/100)
-    if newPoints:
-      #fade out old lines by mixing with background
-      draw = ImageDraw.Draw(self.canvas)
-      for i in range(len(coord)):
-        draw.line(coord[i], fill=self.colors[i], width=self.lineWidth+2, joint='curve')
-
-    # draw to tk.Canvas
-    self.photo = ImageTk.PhotoImage(self.canvas)
-    self.itemconfig(self.image, image=self.photo)
-
-  def clear(self):
-    self.canvas = self.bg.copy()

+ 0 - 61
raspberry-pi/logScreen.py

@@ -1,61 +0,0 @@
-import tkinter as tk
-from tkinter.ttk import Progressbar
-
-import logHandler
-
-class LogScreen(tk.Frame):
-  def __init__(self, root):
-    self.root = root
-    tk.Frame.__init__(self, root)
-
-    self.log_handler = logHandler.get_log_handler()
-
-    self.text = tk.Frame(self,relief="sunken",borderwidth=1)
-    self.text.pack(expand=True,fill=tk.BOTH)
-
-    self.disable_refresh = False
-
-    self.y_scroll = tk.Scrollbar(self.text, width=32)
-    self.y_scroll.pack(side="right", fill="y")
-
-    self.x_scroll = tk.Scrollbar(self.text, orient='horizontal', width=32)
-    self.x_scroll.pack(side="bottom", fill="x")
-
-    self.textfield = tk.Listbox(self.text, yscrollcommand=self.y_scroll.set, xscrollcommand=self.x_scroll.set)
-    self.textfield.pack(side="left",expand=True, fill=tk.BOTH)
-
-    self.y_scroll.config(command=self.textfield.yview)
-    self.x_scroll.config(command=self.textfield.xview)
-
-    self.quit_button = tk.Button(self, text="Close", command=self.close, height=2, width = 10)
-    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", activebackground="#00dd00", fg="white")
-    self.disable_refresh_button.pack(side="right", fill="both")
-
-    for element in self.log_handler.get_log_list():
-      self.textfield.insert(tk.END, element)
-    self.log_handler.get_new_items()
-
-    root.bind('<Escape>', self.close)
-
-  def update(self):
-    if not self.root.winfo_exists():
-      return
-    if not self.disable_refresh:
-      lines = self.log_handler.get_new_items()
-      if lines:
-        for element in lines:
-          self.textfield.insert(tk.END, element)
-        self.textfield.see("end")
-
-  def close(self):
-    if self.root.winfo_exists():
-      self.root.destroy()
-
-  def toggle_refreshing(self):
-    self.disable_refresh = not self.disable_refresh
-    if self.disable_refresh:
-      self.disable_refresh_button.config(text="Enable refresh", relief="sunken", background="#ee0000", activebackground="#ff0000")
-    else:
-      self.disable_refresh_button.config(text="Disable refresh", relief="raised", background="green", activebackground="#00dd00")

+ 0 - 46
raspberry-pi/popup.py

@@ -1,46 +0,0 @@
-import tkinter as tk
-from tkinter.ttk import Progressbar
-import pyglet
-
-class CalibrationPopUp(tk.Frame):
-  def __init__(self, root, calibration_state, conf):
-    self.root = root
-    self.font = pyglet.font.add_file("gui/SourceSansPro-Semibold.otf")
-    self.calibration_state = calibration_state
-    tk.Frame.__init__(self, root)
-    self.pendingClose = False
-    self.conf = conf
-
-
-    self.instruction = tk.Label(self,text="Start Calibration", anchor="c",font=("SourceSansPro-Semibold", 18))
-    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.pack(side="top", fill="both", expand=True)
-    self.cs = Progressbar(self, orient='horizontal', mode='determinate')
-    self.cs.pack(side="top", fill="both", expand=True)
-
-    root.bind('<Escape>', self.close)
-  
-  def update(self):
-    if not self.root.winfo_exists():
-      return
-    # display captured value count as progress
-    self.cs['value'] = self.calibration_state.progress
-    # read state from state machine
-    if self.calibration_state.get_state() == self.calibration_state.WAITING_POS_1:
-      text = "Move gondola to [" + self.conf["ac_sensor"]["calibration_x_offset"] + " , " + self.conf["ac_sensor"]["calibration_y_offset_1"] + "]!"
-      self.instruction["text"] = text
-    elif self.calibration_state.get_state() == self.calibration_state.WAITING_POS_2:
-      text = "Move gondola to [" + self.conf["ac_sensor"]["calibration_x_offset"] + " , " + self.conf["ac_sensor"]["calibration_y_offset_2"] + "]!"
-      self.instruction["text"] = text
-    elif self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE:
-      self.instruction["text"] = "Calibration Done!"
-      if not self.pendingClose:
-        self.pendingClose = True
-        self.root.after(1500, self.close)
-    else:
-      self.instruction["text"] = "Processing..."
-
-  def close(self):
-    if self.root.winfo_exists():
-      self.root.destroy()

+ 7 - 5
raspberry-pi/sensors/magneticSensor.py

@@ -17,6 +17,8 @@ class MagneticSensor:
     self.queue = queue.Queue()
     self.success = False
     self.mpu_array = []
+    self.measurements_gyro = float(conf["mag_sensor"]["measurements_gyro"])
+    self.measurements_accel = float(conf["mag_sensor"]["measurements_accel"])
     self.mpu_gyro_offsets = [0.0,0.0,0.0]
     self.log_handler = logHandler.get_log_handler()
   
@@ -24,7 +26,6 @@ class MagneticSensor:
     if not conn.isConnected():
       conn.open()
     conn.addRecvCallback(self._readCb)
-    self.calibrate()
     #self.dummyActive = True
     #dummyThread = threading.Thread(target=self._readCb_dummy)
     #dummyThread.start()
@@ -34,8 +35,8 @@ class MagneticSensor:
     #print("accel: ", conn.getAccelValues())
     print("gyro: ", conn.getGyroValues())
 
-  def calibrate(self, conf):
-    # Gyroscope Calibration
+  def calibrate(self):
+    # Gyroscope Calibration (TESTING!)
     self.mpu_array = [] # clear Array for next calibration
     while True:
       try:
@@ -43,13 +44,14 @@ class MagneticSensor:
       except:  
         continue
       
-      self.mpu_gyro_array.append([gyro_x,gyro_y,gyro_z])
+      self.mpu_array.append([gyro_x,gyro_y,gyro_z])
       
-      if np.shape(self.mpu_array)[0] == conf.measurements_gyro:
+      if np.shape(self.mpu_array)[0] == self.measurements_gyro:
             for qq in range(0,3):
                 self.mpu_gyro_offsets[qq] = np.mean(np.array(self.mpu_array)[:,qq]) # average
             break
       print('Gyro Calibration Complete')
+      print(self.mpu_gyro_offsets)
       return self.mpu_gyro_offsets
     
     # Accelerometer Calibration