add magnets.py and sfop.py
This commit is contained in:
58
magnets.py
Normal file
58
magnets.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
from slic.core.adjustable import Adjustable, PVAdjustable
|
||||||
|
from slic.core.device import SimpleDevice
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MagnetsScaler(Adjustable):
|
||||||
|
|
||||||
|
def __init__(self, ID="MAGNETS-SCALER", factor=1):
|
||||||
|
super().__init__(ID)
|
||||||
|
self.factor = factor
|
||||||
|
mag1 = Magnet("SINEG01-MSOL010")
|
||||||
|
# mag2 = Magnet("SINEG01-MSOL010")
|
||||||
|
self.magnets = SimpleDevice(
|
||||||
|
ID,
|
||||||
|
m1=mag1,
|
||||||
|
# m2=mag2
|
||||||
|
)
|
||||||
|
self._magnets = [
|
||||||
|
mag1,
|
||||||
|
# mag2
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def get_current_value(self):
|
||||||
|
return self.factor
|
||||||
|
|
||||||
|
def set_target_value(self, factor):
|
||||||
|
old_factor = self.factor
|
||||||
|
self.factor = factor
|
||||||
|
print(old_factor, factor)
|
||||||
|
tasks = [] # we collect tasks to run in parallel, ...
|
||||||
|
for m in self._magnets:
|
||||||
|
current = m.get()
|
||||||
|
print(current, current / old_factor * factor)
|
||||||
|
t = m.set(current / old_factor * factor)
|
||||||
|
for t in tasks: # ... then we need to wait for all tasks to finish
|
||||||
|
t.wait()
|
||||||
|
|
||||||
|
def is_moving(self):
|
||||||
|
return any(m.is_moving() for m in self.magnets)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Magnet(PVAdjustable):
|
||||||
|
|
||||||
|
def __init__(self, ID):
|
||||||
|
pvn_set = ID + ":I-SET"
|
||||||
|
pvn_read = ID + ":I-READ"
|
||||||
|
# pvn_comp = ID + ":I_COMP"
|
||||||
|
# super().__init__(pvn_set, pvn_read, pvname_moving=pvn_comp) # COMP updates only once per second, so we cannot use it.
|
||||||
|
super().__init__(pvn_set, pvn_read, accuracy=0.01)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user