Skip to content

Commit

Permalink
move devices from i18-bluesky
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Aug 2, 2024
1 parent c5a6067 commit 5451d3c
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/dodal/beamlines/i18.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from dodal.common.crystal_metadata import CrystalMetadata
from dodal.common.visit import DirectoryServiceClient, StaticVisitDirectoryProvider
from dodal.devices.focusing_mirror import FocusingMirror
from dodal.devices.i18.diode import Diode
from dodal.devices.i18.table import Table
from dodal.devices.i22.dcm import DoubleCrystalMonochromator
from dodal.devices.slits import Slits
from dodal.devices.synchrotron import Synchrotron
Expand Down Expand Up @@ -198,3 +200,23 @@ def hfm(
wait_for_connection,
fake_with_ophyd_sim,
)


def diode(wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False) -> Diode:
return device_instantiation(
Diode,
"diodad7bdiode",
"-DI-PHDGN-07:",
wait_for_connection,
fake_with_ophyd_sim,
)


def table(wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False) -> Table:
return device_instantiation(
Table,
"table",
"-MO-TABLE-01:",
wait_for_connection,
fake_with_ophyd_sim,
)
20 changes: 20 additions & 0 deletions src/dodal/devices/i18/diode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from ophyd_async.core import (
StandardReadable,
)
from ophyd_async.epics.signal import epics_signal_r


class Diode(StandardReadable):
def __init__(
self,
prefix: str,
name: str = "",
):
self._prefix = prefix
with self.add_children_as_readables():
self.signal = epics_signal_r(float, prefix + "B:DIODE:I")

super().__init__(name=name)


# todo should add 'read' override?
88 changes: 88 additions & 0 deletions src/dodal/devices/i18/sim_motor_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import os

from ophyd import EpicsMotor
from ophyd.sim import Syn2DGauss, SynAxis, SynGauss


def create_epics_motor(motor_name="epics_motor", motor_base_pv="ws416-MO-SIM-01:M1"):
print(f"Creating Epics motor for {motor_base_pv}")
epics_motor = EpicsMotor(motor_base_pv, name=motor_name)
# epics_motor.wait_for_connection(timeout=5) # blueapi fails to connect any PVs!
return epics_motor


def create_dummy_motor(motor_name="dummy_motor"):
print(f"Creating dummy motor {motor_name}")
return SynAxis(name=motor_name, labels={"motors"})


def create_syn_gaussian(det_name, motor, motor_field, noise="none", noise_multiplier=1):
print(f"Creating synthetic Gaussian detector {det_name}")
syn_gauss = SynGauss(
det_name, motor, motor_field, center=0, Imax=5, sigma=0.5, labels={"detectors"}
)
syn_gauss.noise.put(noise)
syn_gauss.noise_multiplier.put(noise_multiplier)
return syn_gauss


def create_syn_2d_gaussian(
det_name,
motor1,
motor1_field,
motor2,
motor2_field,
noise="none",
noise_multiplier=1,
):
print(f"Creating synthetic 2d Gaussian detector {det_name}")

syn_gauss = Syn2DGauss(
det_name,
motor1,
motor1_field,
motor2,
motor2_field,
center=0,
Imax=1,
labels={"detectors"},
)
syn_gauss.noise.put(noise)
syn_gauss.noise_multiplier.put(noise_multiplier)
return syn_gauss


dummy_mot1 = create_dummy_motor("dummy_motor1")
dummy_mot2 = create_dummy_motor("dummy_motor2")
dummy_mot1.delay = 0.05


def dummy_motor1(name: str = "dummy_motor1") -> SynAxis:
return dummy_mot1


def dummy_motor2(name: str = "dummy_motor2") -> SynAxis:
return dummy_mot2


def sim_gauss_det(name: str = "sim_gauss_det") -> SynGauss:
return create_syn_gaussian(name, dummy_mot1, "dummy_motor1")


def sim_2d_gauss_det(name: str = "sim_2d_gauss_det") -> Syn2DGauss:
return create_syn_2d_gaussian(
name, dummy_mot1, "dummy_motor1", dummy_mot2, "dummy_motor2"
)


# Make sure EPICS_CA_SERVER_PORT is set to correct value (6064 for DLS sim area detector and motors, 5064 on beamlines)
os.environ["EPICS_CA_SERVER_PORT"] = "6064"


# def sim_x(name : str, pv_name : str) -> EpicsMotor:
def sim_x(name: str = "sim_x", pv_name: str = "ws416-MO-SIM-01:M1") -> EpicsMotor:
return create_epics_motor(name, pv_name)


def sim_y(name: str = "sim_y", pv_name: str = "ws416-MO-SIM-01:M2") -> EpicsMotor:
return create_epics_motor(name, pv_name)
14 changes: 14 additions & 0 deletions src/dodal/devices/i18/table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from bluesky.protocols import Movable
from ophyd_async.core import (
StandardReadable,
)
from ophyd_async.epics.motion import Motor


class Table(StandardReadable, Movable):
def __init__(self, motion_prefix: str, prefix: str = "", name: str = "") -> None:
with self.add_children_as_readables():
self.x = Motor(motion_prefix + "X")
self.y = Motor(motion_prefix + "Y")
self.z = Motor(motion_prefix + "Z")
self.theta = Motor(motion_prefix + "THETA")

0 comments on commit 5451d3c

Please sign in to comment.