]> wolfpit.net Git - hardware/fuck_tomatoes/.git/commitdiff
Added position saving and big structure refactoring
authorMichael Reeves <michaelreeves808@gmail.com>
Thu, 14 Feb 2019 07:53:52 +0000 (23:53 -0800)
committerMichael Reeves <michaelreeves808@gmail.com>
Thu, 14 Feb 2019 07:53:52 +0000 (23:53 -0800)
14 files changed:
FuckTomato.py
Printer.py
Settings.json [new file with mode: 0644]
User_Interface/Buttons.py [new file with mode: 0644]
User_Interface/Draw.py
User_Interface/MouseManager.py
User_Interface/__pycache__/Buttons.cpython-37.pyc [new file with mode: 0644]
User_Interface/__pycache__/Draw.cpython-37.pyc
User_Interface/__pycache__/MouseManager.cpython-37.pyc
__pycache__/Printer.cpython-37.pyc
settings/__init__.py [new file with mode: 0644]
settings/__pycache__/__init__.cpython-37.pyc [new file with mode: 0644]
settings/__pycache__/frameSettings.cpython-37.pyc [new file with mode: 0644]
settings/frameSettings.py [new file with mode: 0644]

index 03626aa8a9ab85505cdea0e0513cb8177ab67ff8..536cf0e41191cd07b336dfdb201db2223458b9f0 100644 (file)
@@ -1,42 +1,20 @@
 import cv2, sys, Printer
-from utils import MatrixConversion
-from User_Interface import BoxFrame, Draw, MouseManager
+from User_Interface import Draw, MouseManager, Buttons
 
 cap = cv2.VideoCapture(1)
 ret, frame = cap.read()
 cv2.namedWindow('image')
 
-galvo_corners = [(50, 50), (100, 50), (100, 100), (50, 100)]
-image_corners = galvo_corners[:]
-enableDots = True
-
-laser_frame = BoxFrame.BoxFrame(galvo_corners)
-image_frame = BoxFrame.BoxFrame(image_corners)
-coeffs = MatrixConversion.find_coeffs(image_corners, galvo_corners)            
-
-printer = Printer.Printer('COM3', coeffs)
+printer = Printer.Printer('COM3')
 printer.begin()
-
-mouse = MouseManager.MouseManager(laser_frame, image_frame, printer)
-cv2.setMouseCallback('image', mouse.mouse_event)
+mouse = MouseManager.MouseManager(printer)
 
 while(True):
        ret, frame = cap.read()
-       Draw.drawImage(frame, laser_frame, coeffs, printer, enableDots)
+       Draw.drawImage(frame, printer)
        cv2.imshow('image', frame)
-       
-       command = cv2.waitKey(10) & 0xFF
-       if command == ord('q'):
-               printer.home()
-               break
-       elif command == ord('d'):
-               enableDots = not enableDots
-       elif command == ord('f'):
-               printer.sendSerial = not printer.sendSerial
-       elif command == ord('h'):
-               printer.home()
-       elif command == ord('c'):
-               printer.callibrate()
+
+       if Buttons.checkButtons(printer, printer.settings): break
 
 cap.release()
 cv2.destroyAllWindows()
\ No newline at end of file
index 728ce23b526902c6cec00ce908368284361025c7..835439584b26a4c3125dc74d101eaf4a104b90e7 100644 (file)
@@ -1,15 +1,17 @@
-import serial, time
+import serial
+from settings import frameSettings
 from utils import MatrixConversion
 
 class Printer():
-       def __init__(self, COM, coeffs):
+       def __init__(self, COM):
                self.COM = COM
-               self.coeffs = coeffs 
                self.max_X = 250
                self.max_Y = 200
                self.ser = None
                self.position = (0,0)
                self.sendSerial = False
+               self.settings = frameSettings.frameSettings()
+               self.coeffs = MatrixConversion.find_coeffs(self.settings.image_frame.corners, self.settings.laser_frame.corners) 
 
        def begin(self):
                print("Connecting")
@@ -26,10 +28,9 @@ class Printer():
                x,y = xy
                x = self.max_X - x
                self.position = xy
-               command = 'G0 F5000 X%d Y%d\n'%(x, y) + 'G0 F5000 X0 Y0\n'
+               command = 'G0 F5000 X%d Y%d\n'%(x, y) + 'G4 P1000\n' + 'G0 F5000 X0 Y0\n'
 
                if self.sendSerial and self.ser is not None and self.withinBounds(xy):
-                       print(command)
                        self.ser.write(command.encode())
                        return 1
                else:
diff --git a/Settings.json b/Settings.json
new file mode 100644 (file)
index 0000000..cdaf1ce
--- /dev/null
@@ -0,0 +1 @@
+{"laser_frame": [[207, 99], [479, 95], [516, 257], [162, 259]], "image_frame": [[50, 50], [100, 50], [100, 100], [50, 100]]}
\ No newline at end of file
diff --git a/User_Interface/Buttons.py b/User_Interface/Buttons.py
new file mode 100644 (file)
index 0000000..5a9b5cc
--- /dev/null
@@ -0,0 +1,17 @@
+import cv2
+
+def checkButtons(printer, boxes):
+       command = cv2.waitKey(10) & 0xFF
+       if command == ord('q'):
+               boxes.saveSettings()
+               printer.home()
+               return True
+       elif command == ord('d'):
+               enableDots = not enableDots
+       elif command == ord('f'):
+               printer.sendSerial = not printer.sendSerial
+       elif command == ord('h'):
+               printer.home()
+       elif command == ord('c'):
+               printer.callibrate()
+       return False
\ No newline at end of file
index d4e44df499b3a52eeb740d72ca8f2bf3279f3062..402f9c83b9faef67be76a4e1eb12f499a8f90d43 100644 (file)
@@ -12,12 +12,11 @@ def drawDots(image, points, size, color, thickness):
        #Mark TopLeft corner with white dot
        cv2.circle(image,points[0], 2, (255,255,255),-1)
 
-def drawImage(frame, laser_frame, coeffs, printer, enableDots):
-       drawBox(frame, laser_frame.corners, (255, 255, 255), 1)
-       if enableDots == True:
-               drawDots(frame, laser_frame.corners, 10, (255, 0, 0), -1)
-               x,y = laser_frame.getCenter()
-               cv2.circle(frame, (int(x), int(y)), 4, (0, 255, 0), 1)
+def drawImage(frame, printer):
+       drawBox(frame, printer.settings.laser_frame.corners, (255, 255, 255), 1)
+       drawDots(frame, printer.settings.laser_frame.corners, 10, (255, 0, 0), -1)
+       x,y = printer.settings.laser_frame.getCenter()
+       cv2.circle(frame, (int(x), int(y)), 4, (0, 255, 0), 1)
        cx,cy = printer.position
        cv2.putText(frame, str((round(cx),round(cy))), (20, 450), cv2.FONT_HERSHEY_COMPLEX, 0.5, (255, 255, 255))
        if printer.sendSerial:
index 160161ad36c46ffe6246c858c984dad4548d4f13..f0ab7ed7e8ad0f7f36e89d7c070f45e07c9fe426 100644 (file)
@@ -1,9 +1,10 @@
 import cv2
 
 class MouseManager:
-       def __init__(self, laser_frame, image_frame, printer):
-               self.laser_frame = laser_frame
-               self.image_frame = image_frame
+       def __init__(self, printer):
+               cv2.setMouseCallback('image', self.mouse_event)
+               self.laser_frame = printer.settings.laser_frame
+               self.image_frame = printer.settings.image_frame
                self.printer = printer
                self.mouseDrag = False
                self.activeFrame = None
diff --git a/User_Interface/__pycache__/Buttons.cpython-37.pyc b/User_Interface/__pycache__/Buttons.cpython-37.pyc
new file mode 100644 (file)
index 0000000..551fec6
Binary files /dev/null and b/User_Interface/__pycache__/Buttons.cpython-37.pyc differ
index 95c4508155526b68ddb16030f70042a445ebfcb2..17073c8d09219f4fff1929be585cc27bef69fe52 100644 (file)
Binary files a/User_Interface/__pycache__/Draw.cpython-37.pyc and b/User_Interface/__pycache__/Draw.cpython-37.pyc differ
index dcfe9e807140a36778e5f25ee5a3cb5f0280fe45..c281228801a99ed1b95666d983b8788716023540 100644 (file)
Binary files a/User_Interface/__pycache__/MouseManager.cpython-37.pyc and b/User_Interface/__pycache__/MouseManager.cpython-37.pyc differ
index 0d49321698ccbda7b7e6d29b7f0b23a4fcc905b7..bdf60913e765420d03da43aa4c04b6c3550c3d7d 100644 (file)
Binary files a/__pycache__/Printer.cpython-37.pyc and b/__pycache__/Printer.cpython-37.pyc differ
diff --git a/settings/__init__.py b/settings/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/settings/__pycache__/__init__.cpython-37.pyc b/settings/__pycache__/__init__.cpython-37.pyc
new file mode 100644 (file)
index 0000000..47fc574
Binary files /dev/null and b/settings/__pycache__/__init__.cpython-37.pyc differ
diff --git a/settings/__pycache__/frameSettings.cpython-37.pyc b/settings/__pycache__/frameSettings.cpython-37.pyc
new file mode 100644 (file)
index 0000000..a011fda
Binary files /dev/null and b/settings/__pycache__/frameSettings.cpython-37.pyc differ
diff --git a/settings/frameSettings.py b/settings/frameSettings.py
new file mode 100644 (file)
index 0000000..fcc291b
--- /dev/null
@@ -0,0 +1,24 @@
+import json
+from User_Interface import BoxFrame
+SettingsName = 'Settings.json'
+
+class frameSettings:
+    def __init__(self):
+        with open(SettingsName, 'r') as file:
+            data = json.load(file)
+        
+        laser_frame = [tuple(l) for l in data['laser_frame']]
+        image_frame = [tuple(l) for l in data['image_frame']]
+
+        self.laser_frame = BoxFrame.BoxFrame(laser_frame)
+        self.image_frame =  BoxFrame.BoxFrame(image_frame)
+    
+
+    def saveSettings(self):
+        jsonDict = {
+            "laser_frame": self.laser_frame.corners,
+            "image_frame": self.image_frame.corners 
+        }
+
+        with open(SettingsName, 'w') as file:
+            json.dump(jsonDict, file)