Commit 773382de authored by bliss administrator's avatar bliss administrator
Browse files

XMCD ID24 magnet control via wagobox

XMCD test - typo fixes
parent 1872dace
class bcolor:
PURPLE = "\033[95m"
CYAN = "\033[96m"
DARKCYAN = "\033[36m"
BLUE = "\033[94m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RED = "\033[91m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
END = "\033[0m"
import gevent
from bliss.controllers.motors.wago import WagoMotor
from id26.bcolor import bcolor
class XMCD (WagoMotor):
def initialize(self):
super().initialize()
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
def read_position(self, axis):
pos = super().read_position(axis)
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,
)
)
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),
)
)
#TODO
#def state(self, axis):
# return AxisState("READY")
#TODO do we need it ?
def stop(self, axis):
pass
#XMCD
@property
def polarity (self):
#0 --> inverted ie -1
#1 --> normal ie +1
pol = self.wago.get(self._polkey)
if pol == 0:
return -1
elif pol == 1:
return 1
else:
raise Exception (f'{pol} not significant wago {self._polkey} value as a polarity')
@polarity.setter
def polarity (self, value):
#0 --> inverted ie -1
#1 --> normal ie +1
cur = self.wago.get(self._curkey)
if abs(cur)>0.0001:
raise Exception ("impossible to set magnet polarity, current is on {cur} : first move current to 0")
self.wago.set(self._polkey, 1 if value > 0 else 0)
def check_interlock (self):
itlck = self.wago.get(self._itlckey)
if itlck == 1:
print('MAGNET interlock is ok (SAFE)')
else:
print(f'{bcolor.RED}MAGNET interlock FAULT{bcolor.END}')
print('moving current to zero')
self.wago.set(self._curkey, 0)
raise Exception ('MAGNET interlock Fault')
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