Step range and all other data is saved to stage_measure thing
This commit is contained in:
parent
e0b086bdc8
commit
71e21d1e72
1 changed files with 59 additions and 35 deletions
|
|
@ -138,20 +138,20 @@ class RangeofMotionThing(Thing):
|
||||||
parasitic_motion = True
|
parasitic_motion = True
|
||||||
break
|
break
|
||||||
|
|
||||||
pixel_per_step = ((1/abs(csm.image_to_stage_displacement_matrix[0][1]))
|
|
||||||
+ (1/abs(csm.image_to_stage_displacement_matrix[1][0])))/4
|
|
||||||
lateral_positions = [i[axis] for i in focused_positions]
|
|
||||||
z_positions = [i['z'] for i in focused_positions]
|
|
||||||
parameters, covariance = curve_fit(quadratic, lateral_positions, z_positions)
|
|
||||||
relative_move = direction * 2 * res_dic[axis]/(2*pixel_per_step) # This is the number of steps to cover 200% of the FOV.
|
|
||||||
z_dest = quadratic(stage.position[axis] + relative_move, *parameters)
|
|
||||||
z_diff = z_dest - stage.position['z']
|
|
||||||
|
|
||||||
logger.info(f"Z calibration complete.")
|
|
||||||
|
|
||||||
# 1 big step followed by 3 small steps
|
# 1 big step followed by 3 small steps
|
||||||
while np.abs(delta[axis]) > np.abs(minimum_offset_small[axis]) and parasitic_motion == False:
|
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]))
|
||||||
|
+ (1/abs(csm.image_to_stage_displacement_matrix[1][0])))/4
|
||||||
|
lateral_positions = [i[axis] for i in focused_positions]
|
||||||
|
z_positions = [i['z'] for i in focused_positions]
|
||||||
|
parameters, covariance = curve_fit(quadratic, lateral_positions, z_positions)
|
||||||
|
relative_move = direction * 2 * res_dic[axis]/(2*pixel_per_step) # This is the number of steps to cover 200% of the FOV.
|
||||||
|
z_dest = quadratic(stage.position[axis] + relative_move, *parameters)
|
||||||
|
z_diff = z_dest - stage.position['z']
|
||||||
|
|
||||||
|
logger.info(f"Z calibration complete.")
|
||||||
|
|
||||||
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()
|
||||||
autofocus,
|
rom_results = {}
|
||||||
stage,
|
|
||||||
cam,
|
for axis_dir in [['x', 1],['x', -1],['y', 1],['y', -1]]:
|
||||||
csm,
|
axis_dir_results = self.rom_axis(
|
||||||
cancel,
|
autofocus,
|
||||||
logger,
|
stage,
|
||||||
axis = 'x',
|
cam,
|
||||||
direction = 1
|
csm,
|
||||||
)
|
cancel,
|
||||||
# for axis_dir in [['x', 1],['x', -1],['y', 1],['y', -1]]:
|
logger,
|
||||||
# axis_dir_results = self.rom_axis(
|
axis = axis_dir[0],
|
||||||
# autofocus,
|
direction = axis_dir[1]
|
||||||
# stage,
|
)
|
||||||
# cam,
|
rom_results[f"{axis_dir}"] = axis_dir_results
|
||||||
# csm,
|
|
||||||
# cancel,
|
end_time = time.time()
|
||||||
# logger,
|
total_time = (end_time - start_time)/60
|
||||||
# axis = axis_dir[0],
|
|
||||||
# direction = axis_dir[1]
|
x_range = abs(rom_results["['x', 1]"]["final_position"]["x"] - rom_results["['x', -1]"]["final_position"]["x"])
|
||||||
# )
|
y_range = abs(rom_results["['y', 1]"]["final_position"]["y"] - rom_results["['y', -1]"]["final_position"]["y"])
|
||||||
return x_pos_results
|
|
||||||
|
step_range = [x_range, y_range]
|
||||||
|
|
||||||
|
logger.info(f"Range of motion is {x_range} X {y_range}")
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue