Skip to content

Commit

Permalink
added a center offset for the calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
edyoshikun committed Dec 13, 2023
1 parent 76b6dab commit 3cccddd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
13 changes: 10 additions & 3 deletions copylot/assemblies/photom/demo/demo_photom_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
print(curr_pos)

# %%
photom_device.calibrate(mirror_index=0, rectangle_size_xy=(0.01, 0.01))

# %%
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.005+center, 0.005+center])
photom_device._calibrating = False
7 changes: 4 additions & 3 deletions copylot/assemblies/photom/photom.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ def __init__(
for i, tx_path in enumerate(affine_matrix_path):
self.mirror[i].affine_transform_obj = AffineTransform(config_file=tx_path)

def calibrate(self, mirror_index: int, rectangle_size_xy: tuple[int, int]):
def calibrate(self, mirror_index: int, rectangle_size_xy: tuple[int, int],center=[0.009,0.009]):
if mirror_index < len(self.mirror):
print("Calibrating mirror...")
rectangle_coords = calculate_rectangle_corners(rectangle_size_xy)
rectangle_coords = calculate_rectangle_corners(rectangle_size_xy,center)
#offset the rectangle coords by the center
# iterate over each corner and move the mirror
i = 0
while self._calibrating:
# Logic for calibrating the mirror
self.set_position(mirror_index, rectangle_coords[i])
time.sleep(1)
i += 1
if i == 3:
if i == 4:
i = 0
# moving the mirror in a rectangle
else:
Expand Down
20 changes: 11 additions & 9 deletions copylot/assemblies/photom/utils/scanning_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,17 @@ def generate_rect(self):
return cord_x, cord_y


def calculate_rectangle_corners(window_size):
def calculate_rectangle_corners(window_size: tuple[int, int],center=[0.0,0.0]):
# window_size is a tuple of (width, height)

# Calculate the coordinates of the rectangle corners
x0y0 = (
-window_size[0] / 2,
-window_size[1] / 2,
)
x1y0 = (x0y0[0] + window_size[0], x0y0[1])
x1y1 = (x0y0[0] + window_size[0], x0y0[1] + window_size[1])
x0y1 = (x0y0[0], x0y0[1] + window_size[1])
return x0y0, x1y0, x1y1, x0y1
x0y0 = [
-window_size[0] / 2 + center[0],
-window_size[1] / 2 + center[1],
]
x1y0 = [x0y0[0] + window_size[0], x0y0[1]]
x1y1 = [x0y0[0] + window_size[0], x0y0[1] + window_size[1]]
x0y1 = [x0y0[0], x0y0[1] + window_size[1]]


return [x0y0, x1y0, x1y1, x0y1]

0 comments on commit 3cccddd

Please sign in to comment.