Commit 80f65d36 authored by bliss administrator's avatar bliss administrator
Browse files

xmcd magnet ramping

parent 773382de
Pipeline #75002 failed
......@@ -11,43 +11,49 @@ class XMCD (WagoMotor):
self._polkey = self.config.get("polarity_key")
self._itlckey = self.config.get("interlock_key")
self._curkey = self.config.get("current_key")
self.scale = self.config.get("scale", 1)
if self.scale == 0:
self.scale = 1
self._scale = self.config.get("wago_scale", 1)
ramp = self.config.get("wago_ramp")
self.ramp_step = ramp.get('step', 0.05)
self.ramp_period = ramp.get('period', 0.25)
if self._scale == 0:
self._scale = 1
def read_position(self, axis):
pos = super().read_position(axis)
return pos*self.polarity*self.scale
return pos*self.polarity*self._scale
def start_one(self, motion):
self.check_interlock()
logical_name = motion.axis.config.get("logical_name")
logical_channel = int(motion.axis.config.get("logical_channel"))
polarity = self.polarity
if (motion.target_pos < 0 and polarity > 0) or (motion.target_pos > 0 and polarity < 0):
print ("need to switch polarity, first go to 0")
self.wago.controller.devwritephys(
(
self.wago.controller.devname2key(logical_name),
logical_channel,
0,
)
)
self._ramp_wago_voltage (0)
gevent.sleep(0.5)
self.polarity = -polarity
self.wago.controller.devwritephys(
(
self.wago.controller.devname2key(logical_name),
logical_channel,
abs(motion.target_pos/self.scale),
)
)
self._ramp_wago_voltage(abs(motion.target_pos/self._scale))
def _ramp_wago_voltage (self, target):
curval = self.wago.get (self._curkey)
delta = target-curval
if (abs(delta) > self.ramp_step) :
nsteps = abs(int(delta/self.ramp_step))
print (f"too big change in current, will ramp {nsteps} steps")
sign = 1 if delta > 0 else -1
for ii, value in enumerate(map(lambda x:curval+x*self.ramp_step*sign, range(nsteps))):
gevent.sleep(self.ramp_period)
print (f"- step {ii+1}: {value*self._scale:.3f} A")
self.wago.set(self._curkey, value)
print (f"- target: {target*self._scale:.3f} A")
self.wago.set(self._curkey, target)
#TODO
#def state(self, axis):
......
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