|
| 1 | +from typing import Generic, TypeVar |
| 2 | + |
| 3 | +from ophyd_async.core import ( |
| 4 | + StandardReadable, |
| 5 | +) |
| 6 | +from ophyd_async.epics.core import epics_signal_r |
| 7 | +from ophyd_async.epics.motor import Motor |
| 8 | + |
| 9 | + |
| 10 | +class StationaryCrystal(StandardReadable): |
| 11 | + def __init__(self, prefix): |
| 12 | + super().__init__(prefix) |
| 13 | + |
| 14 | + |
| 15 | +class RollCrystal(StationaryCrystal): |
| 16 | + def __init__(self, prefix): |
| 17 | + with self.add_children_as_readables(): |
| 18 | + self.roll_in_mrad = Motor(prefix + "ROLL") |
| 19 | + super().__init__(prefix) |
| 20 | + |
| 21 | + |
| 22 | +class PitchAndRollCrystal(StationaryCrystal): |
| 23 | + def __init__(self, prefix): |
| 24 | + with self.add_children_as_readables(): |
| 25 | + self.pitch_in_mrad = Motor(prefix + "PITCH") |
| 26 | + self.roll_in_mrad = Motor(prefix + "ROLL") |
| 27 | + super().__init__(prefix) |
| 28 | + |
| 29 | + |
| 30 | +Xtal_1 = TypeVar("Xtal_1", bound=StationaryCrystal) |
| 31 | +Xtal_2 = TypeVar("Xtal_2", bound=StationaryCrystal) |
| 32 | + |
| 33 | + |
| 34 | +class BaseDCM(StandardReadable, Generic[Xtal_1, Xtal_2]): |
| 35 | + """ |
| 36 | + Common device for the double crystal monochromator (DCM), used to select the energy of the beam. |
| 37 | +
|
| 38 | + Features common across all DCM's should include virtual motors to set energy/wavelength and contain two crystals, |
| 39 | + each of which can be movable. Some DCM's contain crystals with roll motors, and some contain crystals with roll and pitch motors. |
| 40 | + This base device accounts for all combinations of this. |
| 41 | +
|
| 42 | + This device should act as a parent for beamline-specific DCM's, in which any other missing signals can be added. |
| 43 | +
|
| 44 | + Bluesky plans using DCM's should be typed to specify which types of crystals are required. For example, a plan |
| 45 | + which only requires one crystal which can roll should be typed 'def my_plan(dcm: BaseDCM[RollCrystal, StationaryCrystal])` |
| 46 | + """ |
| 47 | + |
| 48 | + def __init__( |
| 49 | + self, prefix: str, xtal_1: type[Xtal_1], xtal_2: type[Xtal_2], name: str = "" |
| 50 | + ) -> None: |
| 51 | + with self.add_children_as_readables(): |
| 52 | + # Virtual motor PV's which set the physical motors so that the DCM produces requested |
| 53 | + # wavelength/energy |
| 54 | + self.energy_in_kev = Motor(prefix + "ENERGY") |
| 55 | + self.wavelength_in_a = Motor(prefix + "WAVELENGTH") |
| 56 | + |
| 57 | + # Real motors |
| 58 | + self.bragg_in_degrees = Motor(prefix + "BRAGG") |
| 59 | + # Offset ensures that the beam exits the DCM at the same point, regardless of energy. |
| 60 | + self.offset_in_mm = Motor(prefix + "OFFSET") |
| 61 | + |
| 62 | + self.crystal_metadata_d_spacing_a = epics_signal_r( |
| 63 | + float, prefix + "DSPACING:RBV" |
| 64 | + ) |
| 65 | + |
| 66 | + self._make_crystals(prefix, xtal_1, xtal_2) |
| 67 | + |
| 68 | + super().__init__(name) |
| 69 | + |
| 70 | + # Prefix convention is different depending on whether there are one or two controllable crystals |
| 71 | + def _make_crystals(self, prefix: str, xtal_1: type[Xtal_1], xtal_2: type[Xtal_2]): |
| 72 | + if StationaryCrystal not in [xtal_1, xtal_2]: |
| 73 | + self.xtal_1 = xtal_1(f"{prefix}XTAL1:") |
| 74 | + self.xtal_2 = xtal_2(f"{prefix}XTAL2:") |
| 75 | + else: |
| 76 | + self.xtal_1 = xtal_1(prefix) |
| 77 | + self.xtal_2 = xtal_2(prefix) |
0 commit comments