large reorganization, part 1 done

This commit is contained in:
2024-05-27 16:09:46 +02:00
parent ffbfa2ba92
commit 90e12fc814
42 changed files with 1371 additions and 43856 deletions

50
crq_exp/diffractometer.py Normal file
View File

@ -0,0 +1,50 @@
""" Diffractometer
motorized axis:
SARES30-CPCL-ECMC02:ROT2THETA
SARES30-CPCL-ECMC02:ROTTHETA
SARES30-CPCL-ECMC02:TRXBASE
SARES30-CPCL-ECMC02:TRYBASE
"""
from slic.core.adjustable import Adjustable, Linked
from slic.core.device import Device, SimpleDevice
from slic.devices.general.motor import Motor
class Diffractometer(Device):
def __init__(self, ID, motor_naming="MOTOR", **kwargs):
super().__init__(ID, **kwargs)
self.twotheta = Motor("SARES30-CPCL-ECMC02:ROT2THETA") # , ID=None, name=None, units=None, internal=False):
self.theta = Motor("SARES30-CPCL-ECMC02:ROTTHETA") # , ID=None, name=None, units=None, internal=False):
self.trx_base = Motor("SARES30-CPCL-ECMC02:TRXBASE") # , ID=None, name=None, units=None, internal=False):
self.try_base = Motor("SARES30-CPCL-ECMC02:TRYBASE") # , ID=None, name=None, units=None, internal=False):
self.tr_x = Motor("SARES30-CPCL-ECMC02:TRX")
self.tr_y = Motor("SARES30-CPCL-ECMC02:TRY")
self.tr_z = Motor("SARES30-CPCL-ECMC02:TRZ")
self.td = Motor("SARES30-CPCL-ECMC02:TD")
# Set speed:
# diffractometer.theta._motor.VELO = 0.25
class ThetasCombined(Linked):
def __init__(self, *args, **kwargs):
super().__init__(self, *args, **kwargs)
def connect_axis(self):
"""
calculate offset to match scale factor
"""
offset = self.secondary.get_current_value() - self.primary.get_current_value() * self.scale_factor
self.offset = offset

125
crq_exp/dilsc.py Normal file
View File

@ -0,0 +1,125 @@
""" DilSc prototype
"""
from slic.core.adjustable import Adjustable
from slic.core.device import Device, SimpleDevice
from frappy.client import SecopClient
from frappy import states
from frappy.datatypes import StatusType
class Dilution(Device):
def __init__(self, **kwargs):
self.name = 'DilSc'
ID = self.name
super().__init__(ID, **kwargs)
self.address = 'dilsc.psi.ch:5000'
self.dilsc = SecopClient(self.address)
self.dilsc.connect()
self.x = MagnetCoil("X", self.dilsc, 'x', limit_low=-0.6, limit_high=0.6)
self.y = MagnetCoil("Y", self.dilsc, 'y', limit_low=-0.6, limit_high=0.6)
self.z = MagnetCoil("Z", self.dilsc, 'z', limit_low=-5.2, limit_high=5.2)
self.T_plato = Thermometer('T_plato', self.dilsc, limit_low=0, limit_high=300)
self.T_pucksensor = Thermometer('T_pucksensor', self.dilsc, limit_low=0, limit_high=300)
class Thermometer(Adjustable):
def __init__(self, name, dilsc_connection, limit_low=-0.0001, limit_high=0.0001):
super().__init__(name, limit_low=limit_low, limit_high=limit_high)
self.dilsc = dilsc_connection
def _check_connection(func):
def checker(self, *args, **kwargs):
if not self.dilsc.online:
raise ConnectionError(f'No connection to dilsc at {self.address}')
else:
return func(self, *args, **kwargs)
return checker
@_check_connection
def get_current_value(self):
cacheitem = self.dilsc.getParameter(f'{self.name}', 'value', trycache=False)
return cacheitem.value
@_check_connection
def set_target_value(self, value):
self.dilsc.setParameter(f'{self.name}', 'target', value)
@_check_connection
def get_target_value(self):
cacheitem = self.dilsc.getParameter(f'{self.name}', 'target', trycache=False)
return cacheitem.value
@_check_connection
def is_moving(self):
response = self.dilsc.getParameter(f'{self.name}','status', trycache=False)
return response[0][0] > StatusType.PREPARED
@_check_connection
def get_PID_parameters(self):
""" Returns the current PID parameters associated with the control loop for
this thermometer.
"""
response = self.dilsc.getParameter(f'{self.name}','ctrlpars', trycache=False)
return response
@_check_connection
def set_PID_parameters(self, p, i, d):
""" Sets the PID parameters for the associated control loop.
TODO:
- This still returns a timeout error but sets the correct values.
- The range is limited to less than the Lakeshore range allows, this needs
to be fixed in frappy.
"""
self.dilsc.setParameter(f'{self.name}', 'ctrlpars', {'p': p, 'i': i, 'd': d})
class MagnetCoil(Adjustable):
def __init__(self, name, dilsc_connection, direction, limit_low=-0.0001, limit_high=0.0001):
super().__init__(name, limit_low=-0.0001, limit_high=0.0001)
self.direction = direction.lower()
if self.direction not in ["x", "y", "z"]:
raise ValueError("Direction must be either x, y or z.")
self.dilsc = dilsc_connection
def _check_connection(func):
def checker(self, *args, **kwargs):
if not self.dilsc.online:
raise ConnectionError(f'No connection to dilsc at {self.address}')
else:
return func(self, *args, **kwargs)
return checker
@_check_connection
def get_current_value(self):
cacheitem = self.dilsc.getParameter(f'mf{self.direction}', 'value', trycache=False)
return cacheitem.value
@_check_connection
def set_target_value(self, value):
self.dilsc.setParameter(f'mf{self.direction}', 'target', value)
@_check_connection
def is_moving(self):
response = self.dilsc.getParameter(f'mf{self.direction}','status', trycache=False)
return response[0][0] > StatusType.PREPARED

View File

@ -0,0 +1,13 @@
import requests
import numpy as np
from loguru import logger
def start_sequence(n: int = 100, pulse_phase: float = np.pi/8):
parameters = {"n":n, "pulse_phase":pulse_phase}
url = "http://oscillations.psi.ch:8000/pulse"
r = requests.get(url, params=parameters)
d = r.json()
return d['pids']