Skip to content

Commit

Permalink
calibration and mouse events fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
edyoshikun committed Jan 19, 2024
1 parent 56a487e commit 2879bce
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 98 deletions.
43 changes: 43 additions & 0 deletions copylot/assemblies/photom/demo/demo_mouse_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter, QPen
import sys

class CustomWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
self.setMouseTracking(True)
self.mouseX = None
self.mouseY = None
self.setWindowOpacity(0.7)

def initUI(self):
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Mouse Tracker')

self.show()

def mouseMoveEvent(self, event):
self.mouseX = event.x() / 100
self.mouseY = event.y() / 100
print('Mouse coords: ( %d : %d )' % (event.x(), event.y()))

def mousePressEvent(self, event):
print('mouse pressed')

def mouseReleaseEvent(self, event):
print('mouse released')

def paintEvent(self, event=None):
painter = QPainter(self)

# painter.setOpacity(0.5)
painter.setBrush(Qt.white)
painter.setPen(QPen(Qt.white))
painter.drawRect(self.rect())

if __name__ == "__main__":
app = QApplication(sys.argv)
window = CustomWindow()
app.exec_()
50 changes: 31 additions & 19 deletions copylot/assemblies/photom/demo/demo_photom_assembly.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@

#%%
# %%
from copylot.assemblies.photom.photom import PhotomAssembly
from copylot.assemblies.photom.utils import affine_transform
from copylot.hardware.mirrors.optotune.mirror import OptoMirror
from copylot.assemblies.photom.photom_mock_devices import MockLaser, MockMirror
import time

#%%

# %%
# Mock imports for the mirror and the lasers
laser = MockLaser('Mock Laser', power=0)
mirror = OptoMirror(com_port='COM8')

#%%
mirror.position = (0.009,0.0090)
# %%
mirror.position = (0.000,0.000)

# %%
photom_device = PhotomAssembly(laser=[laser], mirror=[mirror],
affine_matrix_path=[r'C:\Users\ZebraPhysics\Documents\GitHub\coPylot\copylot\assemblies\photom\demo\affine_T.yml'],
)
# %%
photom_device?
# %%
# Test the moving of the mirrors
mirror.position = (0.009, 0.0090)
time.sleep(1)
mirror.position = (0.000, 0.000)

curr_pos = photom_device.get_position(mirror_index=0)
print(curr_pos)
#%%
photom_device.set_position(mirror_index=0,position=[0.009,0.009])
assert curr_pos == (0.000, 0.000)
# %%
## Test using the photom_device
camera_sensor_width = 1280
camera_sensor_height = 1280

photom_device = PhotomAssembly(
laser=[laser],
mirror=[mirror],
affine_matrix_path=[
r'C:\Users\ZebraPhysics\Documents\GitHub\coPylot\copylot\assemblies\photom\demo\test_tmp.yml'
],
)
photom_device.set_position(
mirror_index=0, position=[camera_sensor_width // 2, camera_sensor_height // 2]
)
curr_pos = photom_device.get_position(mirror_index=0)
print(curr_pos)


# %%
# TODO: Test the calibration without GUI
import time

start_time = time.time()
center = 0.009
photom_device._calibrating = True
while time.time() - start_time < 5:
# Your code here
elapsed_time = time.time() - start_time
print(f'starttime: {start_time} elapsed_time: {elapsed_time}')
photom_device.calibrate(mirror_index=0, rectangle_size_xy=[0.002, 0.002], center=[0.000,0.000])
photom_device.calibrate(
mirror_index=0, rectangle_size_xy=[0.002, 0.002], center=[0.000, 0.000]
)
photom_device._calibrating = False

# %%
Loading

0 comments on commit 2879bce

Please sign in to comment.