diff --git a/cfg/main/flamemag_cfg.py b/cfg/main/flamemag_cfg.py index a42c2d15..60161336 100644 --- a/cfg/main/flamemag_cfg.py +++ b/cfg/main/flamemag_cfg.py @@ -224,3 +224,14 @@ Mod('T_main_switch', channel='Main Coil Switch', main='main', ) + +Mod('Calib', + 'frappy_psi.cryoltd.Absfield', '', + main='B', + bx='Bx', + by='By', + bz='Bz', + bx_offset=0.0, + by_offset=0.0, + bz_offset=0.0, +) diff --git a/frappy_psi/cryoltd.py b/frappy_psi/cryoltd.py index 98bc6f1f..2db87cd7 100644 --- a/frappy_psi/cryoltd.py +++ b/frappy_psi/cryoltd.py @@ -27,7 +27,7 @@ changed from the client is fixed for at least 10 seconds. """ import re import time -from math import copysign +from math import copysign, sqrt from frappy.core import HasIO, StringIO, Readable, Drivable, Parameter, Command, \ Module, Property, Attached, Enum, IDLE, BUSY, ERROR from frappy.errors import ConfigError, BadValueError, HardwareError @@ -603,3 +603,32 @@ class Compressor(Channel, Drivable): """reset error""" self.sendcmd('Set:Compressor:Reset ') self._error_text = '' + +class Absfield(Readable): + """ + Keep track of the magnet hysteresis and provide corrected readbacks + """ + main = Attached() + bx = Attached() + by = Attached() + bz = Attached() + + bx_offset = Parameter('Hysteresis offset for Bx', FloatRange(unit='G'), + readonly=False, default=0.0) + by_offset = Parameter('Hysteresis offset for By', FloatRange(unit='G'), + readonly=False, default=0.0) + bz_offset = Parameter('Hysteresis offset for Bz', FloatRange(unit='G'), + readonly=False, default=0.0) + + + calib_bx = Parameter('hysteresis-corrected Bx', FloatRange(unit='G')) + calib_by = Parameter('hysteresis-corrected By', FloatRange(unit='G')) + calib_bz = Parameter('hysteresis-corrected Bz+B', FloatRange(unit='G')) + value = Parameter('hysteresis-corrected total magnitude of the field', FloatRange(unit='G')) + + def read_value(self): + self.calib_bx = self.bx.value - self.bx_offset + self.calib_by = self.by.value - self.by_offset + self.calib_bz = self.bz.value+self.main.value - self.bz_offset + + return sqrt(self.calib_bz ** 2 + self.calib_by** 2 + self.calib_bx** 2)