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

Fix scan deadlock #178

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 13 additions & 11 deletions src/qudi/logic/scanning_probe_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def back_scan_resolution(self) -> Dict[str, int]:
"""Resolution for the backwards scan of the fast axis."""
with self._thread_lock:
# use value of forward scan if not configured otherwise (merge dictionaries)
return {**self._scan_resolution, **self._back_scan_resolution}
return {**self._scan_resolution.copy(), **self._back_scan_resolution.copy()}

@property
def scan_frequency(self) -> Dict[str, float]:
Expand All @@ -192,7 +192,7 @@ def scan_frequency(self) -> Dict[str, float]:
def back_scan_frequency(self) -> Dict[str, float]:
with self._thread_lock:
# use value of forward scan if not configured otherwise (merge dictionaries)
return {**self._scan_frequency, **self._back_scan_frequency}
return {**self._scan_frequency.copy(), **self._back_scan_frequency.copy()}

@property
def use_back_scan_settings(self) -> bool:
Expand Down Expand Up @@ -376,11 +376,10 @@ def set_target_position(self, pos_dict, caller_id=None, move_blocking=False):
return new_pos

def toggle_scan(self, start, scan_axes, caller_id=None):
with self._thread_lock:
if start:
self.start_scan(scan_axes, caller_id)
else:
self.stop_scan()
if start:
self.start_scan(scan_axes, caller_id)
else:
self.stop_scan()

def toggle_tilt_correction(self, enable=True):
target_pos = self._scanner().get_target()
Expand Down Expand Up @@ -532,12 +531,14 @@ def start_scan(self, scan_axes, caller_id=None):
self.sigScanStateChanged.emit(False, None, None, self._curr_caller_id)
self.log.error('Could not set scan settings on scanning probe hardware.', exc_info=e)
return
self.log.debug('Successfully configured scanner.')

# Calculate poll time to check for scan completion. Use line scan time estimate.
line_points = self._scan_resolution[scan_axes[0]] if len(scan_axes) > 1 else 1
self.__scan_poll_interval = max(self._min_poll_interval, line_points / self._scan_frequency[scan_axes[0]])
self.__scan_poll_timer.setInterval(int(round(self.__scan_poll_interval * 1000)))
t_poll_ms = max(1, int(round(self.__scan_poll_interval * 1000)))

self.log.debug(f'Successfully configured scanner and logic scan poll timer: {t_poll_ms} ms')
self.__scan_poll_timer.setInterval(t_poll_ms)

try:
self._scanner().start_scan()
Expand All @@ -547,8 +548,9 @@ def start_scan(self, scan_axes, caller_id=None):
self.log.error("Couldn't start scan.", exc_info=e)

self.sigScanStateChanged.emit(True, self.scan_data, self.back_scan_data, self._curr_caller_id)
self.__start_timer()
return

self.__start_timer()


def stop_scan(self):
with self._thread_lock:
Expand Down