Commit 6fc47c13 authored by bliss administrator's avatar bliss administrator

ID26FScanController event_runtime_error, sleep time reduced, _move_back...

ID26FScanController event_runtime_error, sleep time reduced, _move_back try/except, cleanup improved
parent e1ce0408
Pipeline #45159 failed
......@@ -137,6 +137,7 @@ 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()
......@@ -767,11 +768,12 @@ class ID26FScanController:
except RuntimeError: #serial.SerialTimeout.mro()
log_warning(
self,
'Timeout from PM600 controller while programming the trajectory sequence - will retry once after 1 sec.'
'Timeout from PM600 controller while programming the trajectory sequence - will retry once.'
)
time.sleep(1)
time.sleep(0.1)
self.pm600.stop_trajectory(*traj) #replaces EP ES commands
group.prepare()
group.prepare()
else:
raise RuntimeError(f"{MONO.name} is {MONO.state}. cannot load trajectory.")
......@@ -1133,31 +1135,38 @@ 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
try:
self.mono.velocity = self.fscan_par["mono_move_back_speed_steps"] / self.mono.steps_per_unit
movement = [self.energy, energy_start]
motlist = [self.energy]
#self.energy.move(energy_start)
movement = [self.energy, energy_start]
motlist = [self.energy]
#self.energy.move(energy_start)
if self.fscan_par['id_linked']:
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)
group = Group(*motlist)
group.move(*movement)
if self.fscan_par['id_linked']:
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)
group = Group(*motlist)
group.move(*movement)
self.mono.velocity = self.mono.config_velocity
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())
print("- musst_enc_hdh.energy() : ", self.enc_hdh.energy())
print("- PM600 position:", self.mono.position)
print("- PM600 velocity:", self.mono.velocity)
print("- musst_enc_pm.energy() : ", self.enc_pm.energy())
print("- musst_enc_hdh.energy() : ", self.enc_hdh.energy())
print ('\nMOVE BACK: fscan motors have arrived at starting position - READY for next fscan')
print ('\nMOVE BACK: fscan motors have arrived at starting position - READY for next fscan')
except Exception as e:
log_warning(
self,
'MOVE BACK interrupted due to {0} exception'.format(e),
)
log_debug(
self,
......@@ -1175,72 +1184,51 @@ class ID26FScanController:
print("FSCAN ENDING")
#MCL 20210325 - that takes about 567μs
self.pm600.sock.flush()
#done by acquisition master
#if self.fscan_par["id_linked"] == 2:
# self.idtraj._stop_trajectory()
if self.event_trajectory_started.is_set():
#MCL 20210325 - that takes about 567μs
self.pm600.sock.flush()
#done by acquisition master
#if self.fscan_par["id_linked"] == 1:
# for axis in self._get_id_tracked():
# axis.stop() #stop and reset bliss motions
# axis.controller.device.Abort() #abort cabled sync motions
# axis.velocity = self.fscan_par["id_max_speed"]
#if self.fscan_par["id_sync"]:
# self._reset_id_sync()
#MCL 20210325 - it happended that some characters remain after the flush ..., but today it works...
# - so today there is a 5s timeout !!!
#TODO put that in a greenlet - next week
#try:
# log_debug(
# self,
# 'after flush, pm600 serial line still holds: {0}'.format(
# self.pm600.sock.raw_read()
# )
# )
#except:
# log_debug(
# self,
# 'pm600 serial line is empty'
# )
#MCL 20210325 - that takes about 100ms
try:
self.energy.sync_hard()
except RuntimeError:
log_error(
self,
"Timeout while communicating with PM600 - wait 5 more second and retry once..."
#MCL 20210325 - that takes about 100ms
try:
self.energy.sync_hard()
except KeyboardInterrupt as e:
raise e
except:
log_error(
self,
"Error during mono.sync_hard() - flush once more pm600 and retry once..."
)
time.sleep(5)
self.pm600.sock.flush()
self.energy.sync_hard()
#time.sleep(1)
#self.pm600.sock.flush()
self.pm600.stop_trajectory()
self.pm600.raw_write_read(f"{self.mono.channel}WP22222221\r")
self.energy.sync_hard()
#MCL 20210325 - that takes about 160ms
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"]
#MCL 20210325 - that takes about 160ms
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():
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()
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,
"_cleanup done"
......@@ -1296,17 +1284,21 @@ class ID26FScanController:
"_error_cleanup ..."
)
print(
"FSCAN ERROR CLEANUP - aborting trajectories and resetting controller ports"
)
self.pm600.stop_trajectory()
self.pm600.raw_write_read(f"{self.mono.channel}WP22222221\r")
#no need - already n acquisition_master
#if self.idtraj is not None:
# self.idtraj._stop_trajectory()
if self.event_trajectory_started.is_set():
print(
"FSCAN ERROR CLEANUP - aborting trajectories and resetting controller ports"
)
self.pm600.stop_trajectory()
self.pm600.raw_write_read(f"{self.mono.channel}WP22222221\r")
#no need - already n acquisition_master
#if self.idtraj is not None:
# self.idtraj._stop_trajectory()
self.event_runtime_error.set()
self._reset_id_sync()
self.event_trajectory_started.clear()
#self.event_trajectory_started.clear()
#self._last_scan = {} this is only meant to skip preparation phase, so can be kept
log_debug(
......@@ -1361,7 +1353,8 @@ class ID26FScanController:
)
self.pm600.stop_trajectory()
self.energy.sync_hard()
self._last_scan = {}
self.mono.trajectory_prog.clear()
self._reset_id_sync()
......@@ -1617,6 +1610,10 @@ class IDlinkedConstantVelocity():
)
while ready > 0:
print(f"wago u*_ready: {ready} axis not ready")
log_warning (
self,
"wago u*_ready: {0} axis not ready - wait 5 sec.".format(ready),
)
time.sleep(5)
cnt += 1
if cnt > 10:
......
Markdown is supported
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