Commit 6233ecb7 authored by bliss administrator's avatar bliss administrator
Browse files

fscan cleanup refactored

parent 2f31e0ea
......@@ -135,7 +135,6 @@ class ID26FScanController:
self.greenlet_move_back = None
self.greenlet_id_set_vel = dict()
self.event_trajectory_started = gevent.event.Event()
self.event_runtime_error = gevent.event.Event()
self._last_scan = dict()
self.gap_starting_position = dict()
self.id_parameters = dict()
......@@ -1119,24 +1118,20 @@ class ID26FScanController:
energy_start = self.fscan_par['energy_start']
print (f'\nMOVE BACK: move motors back to starting energy, {energy_start} keV')
self.mono.velocity = self.fscan_par["mono_move_back_speed_steps"] / self.mono.steps_per_unit
movement = [self.energy, energy_start]
motlist = [self.energy]
if self.fscan_par['id_linked']:
for axis in self._get_id_tracked():
for axis in self._get_id_tracked():
motlist.append(axis)
movement.append(axis)
movement.append(self.idtracker.energy2undulator(axis, energy_start))
#self.idtracker.move(energy_start)
#print (movement)
self.mono.velocity = self.fscan_par["mono_move_back_speed_steps"] / self.mono.steps_per_unit
group = Group(*motlist)
group.move(*movement)
self.mono.velocity = self.mono.config_velocity
print("- PM600 position:", self.mono.position)
print("- PM600 velocity:", self.mono.velocity)
print("- musst_enc_pm.energy() : ", self.enc_pm.energy())
......@@ -1158,58 +1153,49 @@ class ID26FScanController:
)
print("FSCAN ENDING")
if self.event_trajectory_started.is_set():
#MCL 20210325 - that takes about 100ms
if not self.event_runtime_error.is_set():
try:
self.pm600.sock.readline() #readsacknoledge of XS command that is delayed always
except:
log_debug(
self,
"_cleanup : nothing (no OK) on serial line",
)
self.energy.sync_hard()
#MCL 20210325 - that takes about 160ms
if self.fscan_par['mono_move_back'] == 0 or self.event_runtime_error.is_set() or not self.event_trajectory_started.is_set():
self.mono.velocity = self.mono.config_velocity
#MCL 20210325 - that s only for u35a variable speed trajectories
if self.fscan_par["id_linked"] == 2:
for axis in self._get_id_tracked():
axis.sync_hard()
axis.velocity = self.fscan_par["id_max_speed"]
# === self.mono MOVE BACK
#does not happen after a controlC ...
if self.fscan_par['mono_move_back'] == 1 and self.event_trajectory_started.is_set() and not self.event_runtime_error.is_set():
self.event_trajectory_started.clear()
#readsacknoledge of XS command that is delayed always
try:
self.pm600.sock.readline()
except:
log_debug(
self,
'EVENT Trajectory Started CLEARED',
"_cleanup : nothing (no OK) on serial line",
)
self._cleanup_sync()
if self.fscan_par['mono_move_back'] == 1:
if self.greenlet_authorised:
self.greenlet_move_back = gevent.spawn(self._move_back)
else:
self._move_back()
else:
self.event_runtime_error.clear()
self.event_trajectory_started.clear()
log_debug(
self,
'EVENT Trajectory Started AND Runtime Error CLEARED',
)
self.mono.velocity = self.mono.config_velocity
log_debug(
self,
"_cleanup done"
)
def _cleanup_sync (self):
self.energy.sync_hard()
if self.fscan_par["id_linked"] == 2:
for axis in self._get_id_tracked():
axis.sync_hard()
axis.velocity = self.fscan_par["id_max_speed"]
self.event_trajectory_started.clear()
log_debug(
self,
'EVENT Trajectory Started CLEARED',
)
def _save_last_scan (self):
for key in ('energy_start', 'energy_stop', 'energy_step', 'duration', 'pm600_prf_intervals', 'id_linked', 'id_master' ):
......@@ -1253,39 +1239,25 @@ class ID26FScanController:
"_error_cleanup ..."
)
self.event_runtime_error.set()
log_debug(
self,
'EVENT Runtime Error SET',
)
if self.event_trajectory_started.is_set():
print(
"FSCAN ERROR CLEANUP - aborting trajectories and resetting controller ports"
)
self.pm600.stop_trajectory()
#sends \003 to the controller -> command buffer is cleared
self.pm600.flush()
#try:
# self.pm600.sock.readline() #readsacknoledge of XS command that is delayed always
#except:
# log_debug(
# self,
# "_cleanup : nothing on serial line",
# )
self.pm600.io_command("WP22222221",self.mono.channel)
#no need - already in acquisition_master
#if self.idtraj is not None:
# self.idtraj._stop_trajectory()
self._cleanup_sync()
self.mono.velocity = self.mono.config_velocity
if self.fscan_par['id_sync']:
self._reset_id_sync()
#self.event_trajectory_started.clear()
#self._last_scan = {} this is only meant to skip preparation phase, so can be kept
log_debug(
......@@ -1347,7 +1319,6 @@ class ID26FScanController:
self.mono.velocity = self.mono.config_velocity
self.event_trajectory_started.clear()
self.event_runtime_error.clear()
self._last_scan = {}
self.mono.trajectory_prog.clear()
......
......@@ -178,13 +178,13 @@ def fscan(
print(f"Ready to run scan @{time.time()-time0:.3f}s")
with cleanup(FSCAN._cleanup):
with cleanup(FSCAN._error_cleanup, error_cleanup=True):
with cleanup(FSCAN._error_cleanup, error_cleanup=True):
print('before scan.run.')
print(f"@{time.time()-time0:.3f}s")
scan.run()
print('after scan.run.')
print(f"@{time.time()-time0:.3f}s")
FSCAN._cleanup()
return scan
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment