Commit 13af8484 authored by augustin_s's avatar augustin_s 🐍
Browse files

changed set_target_value to TaskProducer logic

parent a2fac696
......@@ -13,10 +13,9 @@ class GenericAdjustable(Adjustable):
def get_current_value(self):
return self._get()
def set_target_value(self, value, hold=False):
def set_target_value(self, value):
self._last_target = value
change = lambda: self._set(value)
return self._as_task(change, hold=hold)
self._set(value)
def is_moving(self):
return not self._wait()
......
......@@ -31,10 +31,9 @@ class PVEnumAdjustable(Adjustable):
as_string = not as_number
return self.pv.get(as_string=as_string)
def set_target_value(self, value, hold=False):
def set_target_value(self, value):
value = self.states.get(value)
change = lambda: self.pv.put(value, wait=True, use_complete=True)
return self._as_task(change, hold=hold)
self.pv.put(value, wait=True, use_complete=True)
def is_moving(self):
return not self.pv.put_complete
......
......@@ -25,6 +25,8 @@ class ETiming(Adjustable):
name="Globi Laser Electronic Timing",
units="ps"
):
self.wait_time = 0.01
super().__init__(ID, name=name, units=units)
self.pvnames = SimpleNamespace(
......@@ -43,15 +45,11 @@ class ETiming(Adjustable):
def get_current_value(self):
return self.pvs.readback.get() * 1e6 # convert from us to ps
def set_target_value(self, value, hold=False):
change = lambda: self.put_and_wait(value)
return self._as_task(change, hold=hold)
def put_and_wait(self, value, wait_time=0.01):
def set_target_value(self, value):
self.pvs.setvalue.put(value)
sleep(0.2)
while self.is_moving():
sleep(wait_time)
sleep(self.wait_time)
def is_moving(self):
waiting = self.pvs.waiting.get()
......@@ -106,9 +104,8 @@ class LXT(Adjustable):
delay = index * OSCILLATOR_PERIOD - phase_shifter
return -delay
def set_target_value(self, value, hold=False):
change = lambda: self.move(value)
return self._as_task(change, hold=hold)
def set_target_value(self, value):
self.move(value)
def is_moving(self):
raise NotImplementedError
......@@ -144,9 +141,8 @@ class PhaseShifterAramis(Adjustable):
super().__init__(ID, name=name)
self._phase_shifter = PhaseShifter(ID, base_folder)
def set_target_value(self, value, hold=False):
change = lambda: self._phase_shifter.move(value)
return self._as_task(change, hold=hold)
def set_target_value(self, value):
self._phase_shifter.move(value)
def get_current_value(self, pos_type="user"):
check_pos_type(pos_type, {"user", "dial"})
......
......@@ -6,11 +6,14 @@ from slic.utils.hastyepics import get_pv as PV
class AttenuatorAramis(Adjustable):
def __init__(self, ID, z_undulator=None, description=None, name="Attenuator Aramis"):
self.sleeptime = 5
super().__init__(ID, name=name, units=None)
self._pv_status_str = PV(ID + ":MOT2TRANS.VALD")
self._pv_status_int = PV(ID + ":IDX_RB")
def updateE(self, energy=None):
if energy == None:
energy = PV("SARUN03-UIND030:FELPHOTENE").value
......@@ -28,9 +31,6 @@ class AttenuatorAramis(Adjustable):
PV(self.ID + ":3RD_HARM_SP").put(1)
PV(self.ID + ":TRANS_SP").put(value)
def setE(self):
pass
def get_transmission(self, verbose=True):
tFun = PV(self.ID + ":TRANS_RB").value
tTHG = PV(self.ID + ":TRANS3EDHARM_RB").value
......@@ -41,14 +41,9 @@ class AttenuatorAramis(Adjustable):
def get_current_value(self, *args, **kwargs):
return self.get_transmission(*args, verbose=False, **kwargs)[0]
def set_target_value(self, value, sleeptime=5, hold=False):
def changer():
self.set_transmission(value)
sleep(sleeptime)
return self._as_task(changer, hold=hold)
def set_target_value(self, value):
self.set_transmission(value)
sleep(self.sleeptime)
def get_status(self):
s_str = self._pv_status_str.get(as_string=True)
......@@ -66,7 +61,6 @@ class AttenuatorAramis(Adjustable):
def __call__(self, *args, **kwargs):
self.set_transmission(*args, **kwargs)
def is_moving(self):
raise NotImplementedError
......
......@@ -27,6 +27,8 @@ class DoubleCrystalMono(Device):
class DoubleCrystalMonoEnergy(Adjustable):
def __init__(self, ID, name=None):
self.wait_time = 0.1
pvname_setvalue = "SAROP11-ARAMIS:ENERGY_SP"
pvname_readback = "SAROP11-ARAMIS:ENERGY"
pvname_moving = "SAROP11-ODCM105:MOVING"
......@@ -62,15 +64,11 @@ class DoubleCrystalMonoEnergy(Adjustable):
self.pvs.setvalue.put(value)
sleep(3)
def set_target_value(self, value, hold=False):
changer = lambda: self.move_and_wait(value)
return self._as_task(changer, hold=hold, stopper=self.stop)
def move_and_wait(self, value, wait_time=0.1):
def set_target_value(self, value):
self.set_current_value(value)
# while abs(self.wait_for_valid_value() - value) > accuracy:
while self.is_moving():
sleep(wait_time)
sleep(self.wait_time)
def wait_for_valid_value(self):
......@@ -98,11 +96,16 @@ class EcolEnergy:
self.readback = PV(rb)
self.dmov = PV(dmov)
self.done = False
self.wait_time = 0.01
self.accuracy = 2
def get_current_value(self):
return self.readback.get()
def move_and_wait(self, value, wait_time=0.01, accuracy=2):
def set_target_value(self, value):
wait_time = self.wait_time
accuracy = self.accuracy
curr = self.setter.get()
while abs(curr - value) > 0.1:
curr = self.setter.get()
......@@ -116,10 +119,6 @@ class EcolEnergy:
# print(self.dmov.get())
sleep(wait_time)
def set_target_value(self, value, hold=False):
changer = lambda: self.move_and_wait(value)
return Task(changer, hold=hold)
class MonoEcolEnergy:
......@@ -135,14 +134,13 @@ class MonoEcolEnergy:
def get_current_value(self):
return self.dcm.get_current_value()
def move_and_wait(self, value):
def set_target_value(self, value):
ch = [self.dcm.set_target_value(value), self.ecol.set_target_value(self.calcEcol(value))]
for tc in ch:
tc.wait()
def set_target_value(self, value, hold=False):
changer = lambda: self.move_and_wait(value)
return Task(changer, hold=hold, stopper=self.dcm.stop)
def stop(self):
self.dcm.stop()
def alignOffsets(self):
mrb = self.dcm.get_current_value()
......@@ -180,6 +178,8 @@ class CoupledDoubleCrystalMono(Device):
class CoupledDoubleCrystalMonoEnergy(Adjustable):
def __init__(self, ID, name=None):
self.wait_time = 0.1
pvname_setvalue = "SAROP11-ARAMIS:ENERGY_SP"
pvname_readback = "SAROP11-ARAMIS:ENERGY"
# pvname_moving = "SGE-OP2E-ARAMIS:MOVING" #TODO: this seems broken?
......@@ -212,16 +212,12 @@ class CoupledDoubleCrystalMonoEnergy(Adjustable):
def get_current_value(self):
return self.pvs.readback.get()
def set_target_value(self, value, hold=False):
changer = lambda: self.move_and_wait(value)
return self._as_task(changer, hold=hold, stopper=self.stop)
def move_and_wait(self, value, wait_time=0.1):
def set_target_value(self, value):
self.enable_coupling()
self.pvs.setvalue.put(value)
sleep(3)
while self.is_moving():
sleep(wait_time)
sleep(self.wait_time)
def is_moving(self):
moving = self.pvs.moving.get()
......@@ -242,6 +238,8 @@ class CoupledDoubleCrystalMonoEnergy(Adjustable):
class CoupledDoubleCrystalMonoEnergyWithTimeCorrection(Adjustable):
def __init__(self, ID="CDCMEWTC", name="Alvra DCM coupled to FEL energy with time correction", limit_low=None, limit_high=None):
self.wait_time = 0.1
self.limit_low = limit_low
self.limit_high = limit_high
......@@ -294,11 +292,9 @@ class CoupledDoubleCrystalMonoEnergyWithTimeCorrection(Adjustable):
msg = f"requested value is outside the allowed range: {value} > {lh}"
print(msg)
raise KeyboardInterrupt(msg)
changer = lambda: self.move_and_wait(value)
return self._as_task(changer, hold=hold, stopper=self.stop)
wait_time = self.wait_time
def move_and_wait(self, value, wait_time=0.1):
self.enable_coupling()
current_energy = self.get_current_value()
......
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