Commit 7a7ea13e authored by augustin_s's avatar augustin_s 🐍
Browse files

distinguish between limits in slic and in epics

parent 35c1aaa4
......@@ -2,6 +2,7 @@ import subprocess
from types import SimpleNamespace
from contextlib import contextmanager
import colorama
import numpy as np
from slic.core.adjustable import Adjustable, AdjustableError
from slic.core.adjustable.convenience import SpecConvenienceProgress
......@@ -81,7 +82,7 @@ class Motor(Adjustable, SpecConvenienceProgress):
def set_target_value(self, value, check_limits=True, show_progress=False):
ignore_limits = not check_limits
low, high = self.get_limits()
low, high = self.get_epics_limits()
if low == high == 0:
ignore_limits = True
......@@ -117,14 +118,21 @@ class Motor(Adjustable, SpecConvenienceProgress):
self._motor.stop()
def get_limits(self, pos_type="user"):
def get_epics_limits(self, pos_type="user"):
check_pos_type(pos_type)
low_name, high_name = POS_TYPE_LIMIT_NAMES[pos_type]
low = self._motor.get(low_name)
high = self._motor.get(high_name)
return low, high
def set_limits(self, low, high, relative_to_current=False, pos_type="user"):
def set_epics_limits(self, low, high, relative_to_current=False, pos_type="user"):
if low is None and high is None:
low = high = 0
self._motor.put(low_name, low)
self._motor.put(high_name, high)
return
low = -np.inf if low is None else low
high = +np.inf if high is None else high
check_pos_type(pos_type)
low_name, high_name = POS_TYPE_LIMIT_NAMES[pos_type]
if relative_to_current:
......@@ -134,8 +142,8 @@ class Motor(Adjustable, SpecConvenienceProgress):
self._motor.put(low_name, low)
self._motor.put(high_name, high)
def print_limits(self):
low, high = self.get_limits()
def print_epics_limits(self):
low, high = self.get_epics_limits()
val = self.get_current_value()
res = RangeBar(low, high).get(val)
print(res)
......
......@@ -132,16 +132,18 @@ class SmarActAxis(Adjustable):
return self.pvs.status.get()
def within_limits(self, val):
low, high = self.get_limits()
def within_epics_limits(self, val):
low, high = self.get_epics_limits()
return low <= val <= high
def get_limits(self):
def get_epics_limits(self):
low = self.pvs.llm.get()
high = self.pvs.hlm.get()
return low, high
def set_limits(self, low, high, relative_to_current=False):
def set_epics_limits(self, low, high, relative_to_current=False):
low = -np.inf if low is None else low
high = +np.inf if high is None else high
if relative_to_current:
val = self.get_current_value()
low += val
......@@ -201,7 +203,7 @@ class SmarActAxis(Adjustable):
val += self.pvs.drive.get()
if not ignore_limits:
if not self.within_limits(val):
if not self.within_epics_limits(val):
return OUTSIDE_LIMITS
put_stat = self.pvs.drive.put(val, wait=wait, timeout=timeout)
......
......@@ -56,10 +56,10 @@ class DelayTime(AdjustableVirtual):
def get_limits(self):
return [self._mm_to_s(tl) for tl in self._stage.get_limits()]
def set_limits(self, low_limit, high_limit):
def set_epics_limits(self, low_limit, high_limit):
lims_stage = [self._s_to_mm(tl) for tl in [low_limit, high_limit]]
lims_stage.sort()
self._stage.set_limits(*lims_stage)
self._stage.set_epics_limits(*lims_stage)
return [self._mm_to_s(tl) for tl in self._stage.get_limits()]
......
......@@ -66,8 +66,8 @@ class SolidTargetDetectorPBPS_new:
PV(tc).put(bytes(str(tv), "utf8"))
def get_calibration_values_position(self, calib_intensities, seconds=5, motion_range=0.2):
self.x_diodes.set_limits(-motion_range / 2 - 0.1, +motion_range / 2 + 0.1)
self.y_diodes.set_limits(-motion_range / 2 - 0.1, +motion_range / 2 + 0.1)
self.x_diodes.set_epics_limits(-motion_range / 2 - 0.1, +motion_range / 2 + 0.1)
self.y_diodes.set_epics_limits(-motion_range / 2 - 0.1, +motion_range / 2 + 0.1)
self.x_diodes.set_target_value(0).wait()
self.y_diodes.set_target_value(0).wait()
raw = []
......
......@@ -7,7 +7,7 @@ from slic.utils.hastyepics import get_pv as PV
class AttenuatorAramis:
def __init__(self, ID, E_min=1500, sleeptime=1, name=None, set_limits=[-52, 2], pulse_picker=None):
def __init__(self, ID, E_min=1500, sleeptime=1, name=None, limits=[-52, 2], pulse_picker=None):
self.ID = ID
self._pv_status_str = PV(ID + ":MOT2TRANS.VALD")
self._pv_status_int = PV(ID + ":IDX_RB")
......@@ -21,8 +21,8 @@ class AttenuatorAramis:
for n, mot in enumerate(self.motors):
self.__dict__[f"motor_{n+1}"] = mot
self.alias.append(mot.alias)
if set_limits:
mot.set_limits(*set_limits)
if limits:
mot.set_epics_limits(*limits)
def updateE(self, energy=None):
......
Markdown is supported
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