Release lock at end of ROM test

This commit is contained in:
Julian Stirling 2025-10-22 09:57:01 +01:00
parent b8eb1907c3
commit 82f435256b

View file

@ -152,40 +152,44 @@ class RangeofMotionThing(lt.Thing):
if not got_lock: if not got_lock:
raise RuntimeError("Trying to run ROM test when a test is already running.") raise RuntimeError("Trying to run ROM test when a test is already running.")
rom_deps = RomDeps( try:
autofocus=autofocus, stage=stage, csm=csm, cam=cam, logger=logger rom_deps = RomDeps(
) autofocus=autofocus, stage=stage, csm=csm, cam=cam, logger=logger
logger.info( )
"Using the stage to measure the Range of Motion. " logger.info(
"Please ensure you are using a big enough sample." "Using the stage to measure the Range of Motion. "
) "Please ensure you are using a big enough sample."
start_time = time.time() )
start_time = time.time()
self._set_stream_resolution(cam) self._set_stream_resolution(cam)
# The total range for the two axes under test # The total range for the two axes under test
step_range = [] step_range = []
# Strictly typed definitions to iterate over for MyPys sake. # Strictly typed definitions to iterate over for MyPys sake.
axes: tuple[Literal["x"], Literal["y"]] = ("x", "y") axes: tuple[Literal["x"], Literal["y"]] = ("x", "y")
directions: tuple[Literal[1], Literal[-1]] = (1, -1) directions: tuple[Literal[1], Literal[-1]] = (1, -1)
for axis in axes: for axis in axes:
# The final position of the axis under test in the given direction # The final position of the axis under test in the given direction
axis_limits = [] axis_limits = []
for axis_dir in directions: for axis_dir in directions:
# Create a new tracker at start of measurement. # Create a new tracker at start of measurement.
self._rom_data = RomDataTracker() self._rom_data = RomDataTracker()
self._move_until_edge(axis=axis, direction=axis_dir, rom_deps=rom_deps) self._move_until_edge(
# Append final position from tracker axis=axis, direction=axis_dir, rom_deps=rom_deps
axis_limits.append(self._rom_data.final_position[axis]) )
# Calculate step range. # Append final position from tracker
step_range.append(abs(axis_limits[0] - axis_limits[1])) axis_limits.append(self._rom_data.final_position[axis])
# Calculate step range.
total_time = time.time() - start_time step_range.append(abs(axis_limits[0] - axis_limits[1]))
logger.info(f"Range of motion is {step_range[0]} x {step_range[1]} steps")
self.calibrated_range = step_range
total_time = time.time() - start_time
logger.info(f"Range of motion is {step_range[0]} x {step_range[1]} steps")
self.calibrated_range = step_range
finally:
self._lock.release()
return { return {
"Time": total_time, "Time": total_time,
"CSM Matrix": csm.image_to_stage_displacement_matrix, "CSM Matrix": csm.image_to_stage_displacement_matrix,