Skip to content

Commit

Permalink
#26 Value changes to PVs
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Dec 5, 2022
1 parent bdfb098 commit ab97294
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
2 changes: 2 additions & 0 deletions tickit_devices/oav/db_files/DI-OAV.db
Original file line number Diff line number Diff line change
Expand Up @@ -5621,6 +5621,7 @@ record(bi, "BL03S-DI-OAV-01:OVER:1:Use_RBV")

record(longin, "BL03S-DI-OAV-01:MJPG:ArraySize1_RBV")
{
field(VAL, "1024")
field(INP, "BL03S-DI-OAV-01:MJPG:Dim1SA_RBV")
field(FLNK, "BL03S-DI-OAV-01:MJPG:Dim2SA_RBV")
}
Expand All @@ -5634,6 +5635,7 @@ record(longin, "BL03S-DI-OAV-01:MJPG:ArraySize2_RBV")
{
field(INP, "BL03S-DI-OAV-01:MJPG:Dim2SA_RBV")
field(FLNK, "BL03S-DI-OAV-01:MJPG:Dim3SA_RBV")
field(VAL, "768")
}
record(stringout, "BL03S-DI-OAV-01:MJPG:NDArrayPort")
{
Expand Down
46 changes: 28 additions & 18 deletions tickit_devices/oav/oav_edge_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class OAVDevice(Device):
def __init__(self):
pass

def update(self, time: SimTime, inputs: Inputs) -> DeviceUpdate[Outputs]:
def update(
self, time: SimTime, inputs: Inputs, callback_period=int(1e9)
) -> DeviceUpdate[Outputs]:
"""
The device is only altered by adapters so take no inputs.
Expand All @@ -37,7 +39,7 @@ def update(self, time: SimTime, inputs: Inputs) -> DeviceUpdate[Outputs]:
DeviceUpdate[Outputs]:
The produced update event.
"""
return DeviceUpdate(OAVDevice.Outputs(), None)
return DeviceUpdate(OAVDevice.Outputs(), SimTime(time + callback_period))


class OAVDeviceMXSC(Device):
Expand Down Expand Up @@ -71,8 +73,10 @@ def __init__(self, callback_period=1e9):
self.tip_y = int(random.uniform(300, 500))
self.top = np.zeros(1024)
ln = np.log(np.arange(1, 1025 - self.tip_x))
self.top[self.tip_x : 1024] = ln + self.tip_y
self.top[self.tip_x : 1024] = ln
self.bottom = -self.top
self.top[self.tip_x :] += self.tip_y
self.bottom[self.tip_x :] += self.tip_y

self.set_waveform_based_on_omega()

Expand Down Expand Up @@ -106,15 +110,19 @@ def get_low_limit_travel(self):
return self.high_limit_travel

def get_top(self) -> np.ndarray:
"""Getter for pv."""
return self.top

def get_bottom(self) -> np.ndarray:
"""Getter for pv."""
return self.bottom

def get_tip_x(self):
def get_tip_x(self) -> int:
"""Getter for pv."""
return self.tip_x

def get_tip_y(self):
def get_tip_y(self) -> int:
"""Getter for pv."""
return self.tip_y

def set_waveform_based_on_omega(self):
Expand All @@ -126,12 +134,10 @@ def set_waveform_based_on_omega(self):
abs(self.omega - self.widest_points[0]) % 180,
abs(self.omega - self.widest_points[1]) % 180,
)

self.top[self.tip_x : self.tip_x + 340] = (
self.widest_point_polynomial * (95 - distance_to_widest) / 90
) + self.tip_y

self.bottom = -self.top
distance_to_widest = 0
bulge = self.widest_point_polynomial * (95 - distance_to_widest) / 90
self.top[self.tip_x : self.tip_x + 340] = bulge + self.tip_y
self.bottom[self.tip_x : self.tip_x + 340] = -bulge + self.tip_y


class OAVTCPAdapter(ComposedAdapter):
Expand Down Expand Up @@ -174,7 +180,7 @@ def __init__(
)

@RegexCommand(r"C=(\d+\.?\d*)", interrupt=True, format="utf-8")
async def set_top(self, value: float) -> None:
async def set_top(self, value: np.ndarray) -> None:
"""Regex string command that sets the value of beam_current.
Args:
Expand All @@ -192,7 +198,7 @@ async def get_top(self) -> bytes:
return str(self.device.top).encode("utf-8")

@RegexCommand(r"C=(\d+\.?\d*)", interrupt=True, format="utf-8")
async def set_bottom(self, value: float) -> None:
async def set_bottom(self, value: np.ndarray) -> None:
"""Regex string command that sets the value of beam_current.
Args:
Expand Down Expand Up @@ -256,11 +262,15 @@ class OAVEpicsAdapterMXSC(EpicsAdapter):
# Put all the PVs on EPICS
def on_db_load(self) -> None:
"""Epics adapter for reading device values as a PV through channel access."""
# self.device.set_waveform_based_on_omega()
self.link_input_on_interrupt(builder.aIn("MXSC:Top"), self.device.get_top)
self.link_input_on_interrupt(builder.aIn("MXSC:Bottom"), self.device.get_bottom)
self.link_input_on_interrupt(builder.aIn("MXSC:TipX"), self.device.get_tip_x)
self.link_input_on_interrupt(builder.aIn("MXSC:TipY"), self.device.get_tip_y)
self.link_input_on_interrupt(
builder.WaveformOut("MXSC:Top", self.device.top), self.device.get_top
)
self.link_input_on_interrupt(
builder.WaveformOut("MXSC:Bottom", self.device.bottom),
self.device.get_bottom,
)
self.link_input_on_interrupt(builder.aOut("MXSC:TipX"), self.device.get_tip_x)
self.link_input_on_interrupt(builder.aOut("MXSC:TipY"), self.device.get_tip_y)


class OAVEpicsAdapter(EpicsAdapter):
Expand Down

0 comments on commit ab97294

Please sign in to comment.