Step range and all other data is saved to stage_measure thing

This commit is contained in:
Chish36 2025-07-22 15:26:02 +01:00 committed by Julian Stirling
parent e0b086bdc8
commit 71e21d1e72

View file

@ -138,6 +138,9 @@ class RangeofMotionThing(Thing):
parasitic_motion = True parasitic_motion = True
break break
# 1 big step followed by 3 small steps
while np.abs(delta[axis]) > np.abs(minimum_offset_small[axis]) and parasitic_motion == False:
pixel_per_step = ((1/abs(csm.image_to_stage_displacement_matrix[0][1])) pixel_per_step = ((1/abs(csm.image_to_stage_displacement_matrix[0][1]))
+ (1/abs(csm.image_to_stage_displacement_matrix[1][0])))/4 + (1/abs(csm.image_to_stage_displacement_matrix[1][0])))/4
lateral_positions = [i[axis] for i in focused_positions] lateral_positions = [i[axis] for i in focused_positions]
@ -149,9 +152,6 @@ class RangeofMotionThing(Thing):
logger.info(f"Z calibration complete.") logger.info(f"Z calibration complete.")
# 1 big step followed by 3 small steps
while np.abs(delta[axis]) > np.abs(minimum_offset_small[axis]) and parasitic_motion == False:
stage.move_relative(z = z_diff) stage.move_relative(z = z_diff)
logger.info(f"Moved in z by {z_diff}") logger.info(f"Moved in z by {z_diff}")
@ -243,8 +243,6 @@ class RangeofMotionThing(Thing):
stage.move_absolute(x = starting_position[0], y = starting_position[1], z = starting_position[2], block_cancellation=True) stage.move_absolute(x = starting_position[0], y = starting_position[1], z = starting_position[2], block_cancellation=True)
except: except:
logger.error("Stopping measurement because it was cancelled by the user") logger.error("Stopping measurement because it was cancelled by the user")
stage.move_absolute(x = starting_position[0], y = starting_position[1], z = starting_position[2], block_cancellation=True) stage.move_absolute(x = starting_position[0], y = starting_position[1], z = starting_position[2], block_cancellation=True)
@ -265,27 +263,53 @@ class RangeofMotionThing(Thing):
Measures the range of motion of the stage across the x and y axes. Measures the range of motion of the stage across the x and y axes.
""" """
logger.info("Using the stage to measure the Range of Motion. Please ensure you are using a big enough sample.") logger.info("Using the stage to measure the Range of Motion. Please ensure you are using a big enough sample.")
x_pos_results = self.rom_axis( start_time = time.time()
rom_results = {}
for axis_dir in [['x', 1],['x', -1],['y', 1],['y', -1]]:
axis_dir_results = self.rom_axis(
autofocus, autofocus,
stage, stage,
cam, cam,
csm, csm,
cancel, cancel,
logger, logger,
axis = 'x', axis = axis_dir[0],
direction = 1 direction = axis_dir[1]
) )
# for axis_dir in [['x', 1],['x', -1],['y', 1],['y', -1]]: rom_results[f"{axis_dir}"] = axis_dir_results
# axis_dir_results = self.rom_axis(
# autofocus, end_time = time.time()
# stage, total_time = (end_time - start_time)/60
# cam,
# csm, x_range = abs(rom_results["['x', 1]"]["final_position"]["x"] - rom_results["['x', -1]"]["final_position"]["x"])
# cancel, y_range = abs(rom_results["['y', 1]"]["final_position"]["y"] - rom_results["['y', -1]"]["final_position"]["y"])
# logger,
# axis = axis_dir[0], step_range = [x_range, y_range]
# direction = axis_dir[1]
# ) logger.info(f"Range of motion is {x_range} X {y_range}")
return x_pos_results
rom_results["Time"] = total_time
rom_results["CSM Matrix"] = csm.image_to_stage_displacement_matrix
rom_results["Step Range"] = step_range
self.thing_settings["rom_data"] = DenumpifyingDict(rom_results).model_dump()
with open("/var/openflexure/ROM_Test_Results.json", 'w') as file_object:
json.dump(rom_results, file_object, indent = 3)
return rom_results
@thing_property
def rom_data(self) -> Optional[Dict]:
"""
The results of the last range of motion calibration that was run.
"""
filename = '/var/openflexure/settings/range_of_motion/settings.json'
with open(filename) as f:
rom_object = json.load(f)
return rom_object