Commit 6858283e authored by bliss administrator's avatar bliss administrator
Browse files

fscan_controller remove unused code and comments, add logging tags where missing

parent 218ac1a7
Pipeline #59372 failed
......@@ -6,8 +6,6 @@ import logging
from contextlib import contextmanager
#from bliss import setup_globals
from bliss.shell.standard import bench
from bliss.physics import trajectory
from bliss.common.axis import CyclicTrajectory
from bliss.common.cleanup import cleanup, axis as cleanup_axis
......@@ -191,7 +189,7 @@ class ID26FScanController:
try:
yield
#except KeyboardInterrupt:
except:
if self.greenlet_move_back is not None:
self.greenlet_move_back.kill()
......@@ -285,11 +283,6 @@ class ID26FScanController:
scan_meta_obj.instrument.set(self, lambda _: {self.name: self.metadata()})
def metadata(self):
"""
this is about metadata publishing to the h5 file AND ICAT
#thickness = self.thickness()
#factor = self.factor()
"""
log_debug(
self,
......@@ -313,7 +306,6 @@ class ID26FScanController:
@property
def synchro_delay (self):
delay = self.fscan_par["pm600_wp_delay"]
#if self.fscan_par['id_linked'] == 1 and self.fshutter.state() == "AUTO":
if self.fshutter.state() == "AUTO":
delay += self.fshutter.delay
return delay
......@@ -346,20 +338,20 @@ class ID26FScanController:
if energy_start >= energy_end:
raise ValueError(
f"Energy must go incrementing. start ({energy_start}) end ({energy_end})"
f"FSCAN: Energy must go incrementing. start ({energy_start}) end ({energy_end})"
)
if energy_step == 0:
raise ValueError("energy_step cannot be 0.")
raise ValueError("FSCAN: energy_step cannot be 0.")
#MONO
if self._check_limits(self.mono, self.dcm.energy2bragg(energy_end)) < 0:
raise ValueError(
f"move to {energy_end} keV would exceed low limit on {self.mono.name} ({self.mono.limits[0]} deg.)"
f"FSCAN: move to {energy_end} keV would exceed low limit on {self.mono.name} ({self.mono.limits[0]} deg.)"
)
elif self._check_limits(self.mono, self.dcm.energy2bragg(energy_end)) > 0:
raise ValueError(
f"move to {energy_end} keV would exceed high limit on {self.mono.name} ({self.mono.limits[1]} deg.)"
f"FSCAN: move to {energy_end} keV would exceed high limit on {self.mono.name} ({self.mono.limits[1]} deg.)"
)
self.mono.velocity = self.fscan_par["mono_move_back_speed_steps"] / self.mono.steps_per_unit
......@@ -371,8 +363,6 @@ class ID26FScanController:
if self.fscan_par["id_linked"] == 1:
try:
#get rid of setup_globals
#master_id = getattr(setup_globals, self.fscan_par.get("id_master"))
master_id = self.dcm.energy_undulator_motor.controller.axes[self.fscan_par.get("id_master")]
print(f"MASTER ID is {master_id.name}")
except:
......@@ -482,7 +472,6 @@ class ID26FScanController:
id, duration, energy_start, energy_end
)
#elif master_id is not None and id.name != master_id.name:
elif master_id is not None and id != master_id:
if self.greenlet_authorised:
self.greenlet_id_set_vel [id] = gevent.spawn(self._id_prepare_velocity,
......@@ -584,7 +573,7 @@ class ID26FScanController:
minspeed = self.fscan_par.get(f"{id.name}_min_speed")
if not minspeed:
raise ValueError(f"{id.name} min speed not defined")
raise ValueError(f"FSCAN: {id.name} min speed not defined")
maxspeed = self.fscan_par["id_max_speed"]
if master_speed is None:
......@@ -605,7 +594,7 @@ class ID26FScanController:
id.controller.set_velocity(id, speed)
time.sleep(self.fscan_par["id_setvel_sleep_time"])
else:
raise RuntimeError(f"State of axis {id} is {id.state} ! cannot change velocity.")
raise RuntimeError(f"FSCAN: State of axis {id} is {id.state} ! cannot change velocity.")
set_velocity = getattr(
id.controller.device, f"{id.name}_GAP_velocity"
......@@ -629,7 +618,7 @@ class ID26FScanController:
break
if not ok:
raise RuntimeError(
f"could not set velocity {speed} (current: {set_velocity})"
f"FSCAN: could not set velocity {speed} (current: {set_velocity})"
)
log_debug(
......@@ -766,7 +755,7 @@ class ID26FScanController:
group.prepare() # the program is loaded in PM600 here
else:
raise RuntimeError(f"{MONO.name} is {MONO.state}. cannot load trajectory.")
raise RuntimeError(f"FSCAN: {MONO.name} is {MONO.state}. cannot load trajectory.")
if self.fscan_par['id_linked'] == 2:
self.idtraj._id_load_trajectory(_idtimebase, _idpositions)
......@@ -799,9 +788,6 @@ class ID26FScanController:
)
print("Programming trajectory on PM600")
#print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
#print("!!! WARNING: DO NOT CTR-C !!!")
#print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
nintervals = self.fscan_par['pm600_prf_intervals']
......@@ -834,9 +820,6 @@ class ID26FScanController:
pre_xp = []
#if self.fscan_par['id_linked']==1:
# if self.fscan_par['id_sync']:
# pre_xp.append("WA0") # wait for last bit to be 0,= ID_moving
if self.fscan_par['id_linked']:
pre_xp.append("WA0") # wait for last bit to be 0,= ID_moving
pre_xp.append(
......@@ -852,7 +835,7 @@ class ID26FScanController:
post_xp = ["WE", "WP22222221"]
# post_xp = ['WP22222222'] #just to read the OK after 1XS2
# do not move WP command to fscan_cleanup - that would make XS command not returning OK probably ...
# do not move WP command to fscan_cleanup - that would make XS command not returning OK
# 1DExx set delay to wait acq finishes -> post_xp.add('DE{0}'.format(delay2))
# 1MAxx go back to steps0 if requested -> done by cleanup
......@@ -881,7 +864,7 @@ class ID26FScanController:
)
if vel > mxv:
raise RuntimeError(f"above Max speed limit on PM600: {vel} (max: {mxv})")
raise RuntimeError(f"FSCAN: above Max speed limit on PM600: {vel} (max: {mxv})")
log_debug(
self,
......@@ -1117,7 +1100,7 @@ class ID26FScanController:
)
)
raise RuntimeError("no compatible clock frq on MUSST")
raise RuntimeError("FSCAN: no compatible clock frq on MUSST")
def _move_back(self):
......@@ -1134,7 +1117,6 @@ class ID26FScanController:
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():
......@@ -1173,33 +1155,17 @@ class ID26FScanController:
print("FSCAN ENDING")
if self.event_trajectory_started.is_set():
#MCL 20210325 - that takes about 567μs
#self.pm600.sock.flush()
#MCL 20210325 - that takes about 100ms
#try:
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,
"PM600 _cleanup : nothing (no OK) on serial line",
"_cleanup : nothing (no OK) on serial line",
)
self.energy.sync_hard()
#except KeyboardInterrupt as e:
# raise e
#except Exception as e:
# log_warning(
# self,
# "Error during mono.sync_hard() ({0}) - retry once...".format(e)
# )
#time.sleep(1)
#self.pm600.sock.flush()
#self.pm600.stop_trajectory()
#self.pm600.raw_write_read(f"{self.mono.channel}WP22222221\r")
#self.pm600.io_command("WP22222221",self.mono.channel)
#self.energy.sync_hard()
#MCL 20210325 - that takes about 160ms
self.mono.velocity = self.mono.config_velocity
......@@ -1236,15 +1202,7 @@ class ID26FScanController:
self._last_scan [key] = self.fscan_par.get(key)
self._last_scan ['synchro_delay'] = self.synchro_delay
#_skip_id_set_vel ():
#self._same_as_last_scan('energy_start', 'energy_stop', 'energy_step', 'id_linked', 'id_master','init_duration')
#requires keeping gap_starting_position, id_parameters and duration (or move back should go to gap_starting_position ????)
#_skip_prog_traj ():
#self._same_as_last_scan('energy_start', 'energy_stop', 'energy_step', 'id_linked', 'id_master','duration', 'pm600_prf_intervals', 'synchro_delay')
#take care to always call mono_wait_move(): put scan.run() call in to fscan_controller.
#DISCARDED I need group to program acquisition chain - cannot skip pm600, maybe would be useful for idtraj
def _same_as_last_scan (self, *keys):
keys = list(keys)
......@@ -1293,10 +1251,11 @@ class ID26FScanController:
#except:
# log_warning(
# self,
# "PM600 _error_cleanup : nothing on serial line",
# "_error_cleanup : nothing on serial line",
# )
#self.pm600.raw_write_read(f"{self.mono.channel}WP22222221\r")
self.pm600.io_command("WP22222221",self.mono.channel)
#no need - already in acquisition_master
#if self.idtraj is not None:
# self.idtraj._stop_trajectory()
......@@ -1460,7 +1419,7 @@ class ID26FscanCyclicTrajectory(CyclicTrajectory):
check1 = delta > 0 if self.backlash < 0 else delta < 0
if check1[-1] is True:
raise RuntimeError(
"backlash cannot be completed at the end of such a scan"
"FSCAN: backlash cannot be completed at the end of such a scan"
)
pos[1:] -= check1 * self.backlash
pvt["position"] = pos
......@@ -1624,7 +1583,7 @@ class IDlinkedConstantVelocity():
time.sleep(5)
cnt += 1
if cnt > 10:
raise RuntimeError("ID not ready for synchro mode triggering")
raise RuntimeError("FSCAN: ID not ready for synchro mode triggering")
ready = max(
list(
map(
......
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