Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] Refactor vertical movement calculation #339

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions fibsem/microscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def stable_move(self,dx: float, dy: float, beam_type: BeamType) -> FibsemStagePo
pass

@abstractmethod
def vertical_move(self, dy: float, dx: float = 0, static_wd: bool = True) -> None:
def vertical_move(self, dy: float, dx: float = 0, static_wd: bool = True, use_perspective: bool = True) -> None:
pass

def move_flat_to_beam(self, beam_type: BeamType, _safe:bool = True) -> None:
Expand Down Expand Up @@ -1194,6 +1194,7 @@ def vertical_move(
dy: float,
dx: float = 0.0,
static_wd: bool = True,
use_perspective: bool = True,
) -> None:
""" Move the stage vertically to correct coincidence point

Expand Down Expand Up @@ -1223,28 +1224,31 @@ def vertical_move(

# TODO: implement perspective correction
PERSPECTIVE_CORRECTION = 0.9
z_move = dy / np.cos(np.deg2rad(90 - self.system.ion.column_tilt)) * PERSPECTIVE_CORRECTION # TODO: MAGIC NUMBER, 90 - fib tilt
z_move = dy
if use_perspective:
z_move = dy / np.cos(np.deg2rad(90 - self.system.ion.column_tilt)) * PERSPECTIVE_CORRECTION # TODO: MAGIC NUMBER, 90 - fib tilt

# TODO: do this manually without autoscript in raw coordinates
# TODO: test if this results in the same movement
# manually calculate the dx, dy, dz
# theta = self.get_stage_position().t # rad
# dy = z_move * np.sin(theta)
# dz = z_move / np.cos(theta)
# logging.debug(f"dx: {dx}, dy: {dy}, dz: {dz}")
# stage_position = FibsemStagePosition(x=dx, y=dy, z=z_move, coordinate_system="RAW")

stage_position = FibsemStagePosition(
x=dx,
z=z_move,
coordinate_system="Specimen"
)
theta = self.get_stage_position().t # rad
dy = z_move * np.sin(theta)
dz = z_move / np.cos(theta)
stage_position = FibsemStagePosition(x=dx, y=dy, z=dz, coordinate_system="RAW")
logging.info(f"Vertical movement: {stage_position}")
self.move_stage_relative(stage_position) # NOTE: this seems to be a bit less than previous... -> perspective correction?

# stage_position = FibsemStagePosition(
# x=dx,
# z=z_move,
# coordinate_system="Specimen"
# )

# move stage
move_settings = MoveSettings(link_z_y=True)
autoscript_position = stage_position.to_autoscript_position(self.stage_is_compustage)
autoscript_position.coordinate_system = CoordinateSystem.SPECIMEN
self.stage.relative_move(autoscript_position, move_settings)
# # move stage
# move_settings = MoveSettings(link_z_y=True)
# autoscript_position = stage_position.to_autoscript_position(self.stage_is_compustage)
# autoscript_position.coordinate_system = CoordinateSystem.SPECIMEN
# self.stage.relative_move(autoscript_position, move_settings)

# restore working distance to adjust for microscope compenstation
if static_wd and not self.stage_is_compustage:
Expand Down Expand Up @@ -3796,6 +3800,7 @@ def vertical_move(
dy: float,
dx: float = 0.0,
static_wd: bool = True,
use_perspective: bool = True
) -> None:
"""
Move the stage vertically to correct eucentric point
Expand Down Expand Up @@ -5591,7 +5596,7 @@ def stable_move(self, dx: float, dy:float, beam_type: BeamType, static_wd: bool=
return stage_position


def vertical_move(self, dy: float, dx:float = 0.0, static_wd: bool=True) -> FibsemStagePosition:
def vertical_move(self, dy: float, dx:float = 0.0, static_wd: bool=True, use_perspective: bool = True) -> FibsemStagePosition:
"""Move the stage vertically by the specified amount."""
# confirm stage is enabled
_check_stage(self.system)
Expand All @@ -5607,7 +5612,10 @@ def vertical_move(self, dy: float, dx:float = 0.0, static_wd: bool=True) -> Fibs

# TODO: implement perspective correction
PERSPECTIVE_CORRECTION = 0.9
z_move = dy / np.cos(np.deg2rad(90 - self.system.ion.column_tilt)) * PERSPECTIVE_CORRECTION # TODO: MAGIC NUMBER, 90 - fib tilt
z_move = dy
if use_perspective:
z_move = dy / np.cos(np.deg2rad(90 - self.system.ion.column_tilt)) * PERSPECTIVE_CORRECTION # TODO: MAGIC NUMBER, 90 - fib tilt


# TODO: do this manually without autoscript in raw coordinates
stage_position = FibsemStagePosition(
Expand Down
17 changes: 13 additions & 4 deletions fibsem/ui/FibsemMovementWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,20 @@ def _double_click_worker(self, layer, event):

log_status_message(f"MOVING_{self.movement_mode.name}_BY_{point.x:.2e}, {point.y:.2e} | {beam_type}")
self.movement_notification_signal.emit("Moving stage ")
# eucentric is only supported for ION beam
if beam_type is BeamType.ION and self.movement_mode is MovementMode.Vertical:
self.microscope.vertical_move(dx=point.x, dy=-point.y
)

# vertical movements correct beam coincidence, stable movements maintain it
if self.movement_mode is MovementMode.Vertical:
if beam_type is BeamType.ION:
self.microscope.vertical_move(dx=point.x, dy=point.y) # only vertical movement
if beam_type is BeamType.ELECTRON:
# stable move -> vertical move
self.microscope.stable_move(
dx=point.x,
dy=point.y,
beam_type=beam_type,
)
# invert vertical movement to maintain coincidence
self.microscope.vertical_move(dx=0, dy=-point.y, use_perspective=False)
else:
# corrected stage movement
self.microscope.stable_move(
Expand Down