|
| 1 | +""" |
| 2 | +MCT Optics Ophyd Device Classes and Usage Documentation |
| 3 | +
|
| 4 | +This module defines device classes for managing MCT optics via EPICS. |
| 5 | +Each class is designed to interact with specific subsystems, |
| 6 | +facilitating ease of use and configurability. |
| 7 | +
|
| 8 | +Example Usage: |
| 9 | +``` |
| 10 | +# Initialize the MCTOptics device |
| 11 | +optics = MCTOptics("2bm:MCTOptics:", name="optics") |
| 12 | +
|
| 13 | +# Access lens information |
| 14 | +lens_names = optics.lens_info.name_0.get() |
| 15 | +motor_name = optics.lens_info.motor_name.get() |
| 16 | +``` |
| 17 | +""" |
| 18 | + |
| 19 | +from ophyd import Component as Cpt |
| 20 | +from ophyd import Device |
| 21 | +from ophyd import EpicsSignal |
| 22 | +from ophyd import EpicsSignalRO |
| 23 | +from ophyd import FormattedComponent as FCpt |
| 24 | + |
| 25 | + |
| 26 | +class MCTOpticsLensInfo(Device): |
| 27 | + """ |
| 28 | + Class for managing lens metadata, motor, and focus-related PVs. |
| 29 | +
|
| 30 | + Attributes: |
| 31 | + name_0 (EpicsSignal): PV for the name of lens 0. |
| 32 | + name_1 (EpicsSignal): PV for the name of lens 1. |
| 33 | + name_2 (EpicsSignal): PV for the name of lens 2. |
| 34 | + motor_name (EpicsSignal): PV for the motor controlling the lens. |
| 35 | + sample_x_name (EpicsSignal): PV for the X-axis sample motor. |
| 36 | + sample_y_name (EpicsSignal): PV for the Y-axis sample motor. |
| 37 | + sample_z_name (EpicsSignal): PV for the Z-axis sample motor. |
| 38 | + focus_name_0 (EpicsSignal): PV for the focus of lens 0. |
| 39 | + focus_name_1 (EpicsSignal): PV for the focus of lens 1. |
| 40 | + focus_name_2 (EpicsSignal): PV for the focus of lens 2. |
| 41 | + """ |
| 42 | + |
| 43 | + name_0 = Cpt(EpicsSignal, "Name0") |
| 44 | + name_1 = Cpt(EpicsSignal, "Name1") |
| 45 | + name_2 = Cpt(EpicsSignal, "Name2") |
| 46 | + |
| 47 | + # Lens Motor PVs |
| 48 | + motor_name = Cpt(EpicsSignal, "MotorPVName") |
| 49 | + sample_x_name = Cpt(EpicsSignal, "SampleXPVName") |
| 50 | + sample_y_name = Cpt(EpicsSignal, "SampleYPVName") |
| 51 | + sample_z_name = Cpt(EpicsSignal, "SampleZPVName") |
| 52 | + |
| 53 | + # Lens Focus PVs |
| 54 | + focus_name_0 = Cpt(EpicsSignal, "0FocusPVName") |
| 55 | + focus_name_1 = Cpt(EpicsSignal, "1FocusPVName") |
| 56 | + focus_name_2 = Cpt(EpicsSignal, "2FocusPVName") |
| 57 | + |
| 58 | + |
| 59 | +class MCTOpticsLensOffset(Device): |
| 60 | + """ |
| 61 | + Class for defining lens offsets. |
| 62 | +
|
| 63 | + Attributes: |
| 64 | + x_offset (EpicsSignal): X-axis offset PV. |
| 65 | + y_offset (EpicsSignal): Y-axis offset PV. |
| 66 | + z_offset (EpicsSignal): Z-axis offset PV. |
| 67 | + rotation (EpicsSignal): Rotation offset PV. |
| 68 | + focus (EpicsSignal): Focus offset PV. |
| 69 | + """ |
| 70 | + |
| 71 | + # Lens Offset |
| 72 | + x_offset = Cpt(EpicsSignal, "XOffset") |
| 73 | + y_offset = Cpt(EpicsSignal, "YOffset") |
| 74 | + z_offset = Cpt(EpicsSignal, "ZOffset") |
| 75 | + rotation = Cpt(EpicsSignal, "Rotation") |
| 76 | + focus = Cpt(EpicsSignal, "Focus") |
| 77 | + |
| 78 | + |
| 79 | +class MCTOpticsLensControl(Device): |
| 80 | + """ |
| 81 | + Class for managing lens positions and offsets. |
| 82 | +
|
| 83 | + Attributes: |
| 84 | + pos_0 (EpicsSignal): Position of lens 0. |
| 85 | + pos_1 (EpicsSignal): Position of lens 1. |
| 86 | + pos_2 (EpicsSignal): Position of lens 2. |
| 87 | + lens_1 (MCTOpticsLensOffset): Offset information for lens 1. |
| 88 | + lens_2 (MCTOpticsLensOffset): Offset information for lens 2. |
| 89 | + """ |
| 90 | + |
| 91 | + # Lens Positions |
| 92 | + pos_0 = Cpt(EpicsSignal, "Pos0") |
| 93 | + pos_1 = Cpt(EpicsSignal, "Pos1") |
| 94 | + pos_2 = Cpt(EpicsSignal, "Pos2") |
| 95 | + lens_1 = Cpt(MCTOpticsLensOffset, "1") |
| 96 | + lens_2 = Cpt(MCTOpticsLensOffset, "2") |
| 97 | + |
| 98 | + |
| 99 | +class MCTOpticsCameraControl(Device): |
| 100 | + """ |
| 101 | + Class for managing camera control parameters. |
| 102 | +
|
| 103 | + Attributes: |
| 104 | + pos (EpicsSignal): Position of the camera. |
| 105 | + pv_name (EpicsSignal): PV name of the camera. |
| 106 | + rotation_name (EpicsSignal): PV for camera rotation. |
| 107 | + lens_ctrl (MCTOpticsLensControl): Lens control associated with the camera. |
| 108 | + """ |
| 109 | + |
| 110 | + def __init__( |
| 111 | + self, |
| 112 | + prefix: str, |
| 113 | + *args, |
| 114 | + **kwargs, |
| 115 | + ): |
| 116 | + """ |
| 117 | + Initializes the camera control device. It extracts the base prefix |
| 118 | + and a trailing number from the provided prefix. |
| 119 | +
|
| 120 | + Args: |
| 121 | + prefix (str): The EPICS prefix for the device. |
| 122 | + *args: Additional arguments for the Device initializer. |
| 123 | + **kwargs: Additional keyword arguments for the Device initializer. |
| 124 | + """ |
| 125 | + |
| 126 | + # Identify the position where the trailing number starts |
| 127 | + split_index = len(prefix.rstrip("0123456789")) |
| 128 | + |
| 129 | + # Separate the base prefix and the trailing number |
| 130 | + self.base_prefix = prefix[:split_index] |
| 131 | + self.last_number = prefix[split_index:] |
| 132 | + |
| 133 | + super().__init__(prefix, *args, **kwargs) |
| 134 | + |
| 135 | + # Name |
| 136 | + pos = FCpt(EpicsSignal, "{base_prefix}Pos{last_number}") |
| 137 | + pv_name = FCpt(EpicsSignal, "{base_prefix}Name{last_number}") |
| 138 | + |
| 139 | + # Camera Rotation PV Name |
| 140 | + rotation_name = Cpt(EpicsSignal, "RotationPVName") |
| 141 | + |
| 142 | + # Lens Control |
| 143 | + lens_ctrl = Cpt(MCTOpticsLensControl, "Lens") |
| 144 | + |
| 145 | + |
| 146 | +class MCTOptics(Device): |
| 147 | + """ |
| 148 | + Ophyd Device Class for controlling MCT optics via EPICS. |
| 149 | +
|
| 150 | + Attributes: |
| 151 | + lens_select (EpicsSignal): Select the lens (0-2). |
| 152 | + camera_select (EpicsSignal): Select the camera (0-1). |
| 153 | + camera_selected (EpicsSignalRO): Currently selected camera. |
| 154 | + cross_select (EpicsSignal): Crosshair selection. |
| 155 | + sync (EpicsSignal): Synchronization status. |
| 156 | + server_running (EpicsSignal): Server status. |
| 157 | + mct_status (EpicsSignal): MCT status indicator. |
| 158 | + scintillator_type (EpicsSignal): Scintillator material type. |
| 159 | + scintillator_thickness (EpicsSignal): Thickness of the scintillator. |
| 160 | + image_pixel_size (EpicsSignal): Size of image pixels. |
| 161 | + detector_pixel_size (EpicsSignal): Size of detector pixels. |
| 162 | + camera_objective (EpicsSignal): Camera objective configuration. |
| 163 | + camera_tube_length (EpicsSignal): Camera tube length. |
| 164 | + lens_info (MCTOpticsLensInfo): Information about the lenses. |
| 165 | + camera_0 (MCTOpticsCameraControl): Camera 0 control. |
| 166 | + camera_1 (MCTOpticsCameraControl): Camera 1 control. |
| 167 | + """ |
| 168 | + |
| 169 | + # Configurable PVs |
| 170 | + lens_select = Cpt(EpicsSignal, "LensSelect") # Use numbers 0-2 |
| 171 | + |
| 172 | + camera_select = Cpt(EpicsSignal, "CameraSelect") # Use number 0-1 |
| 173 | + camera_selected = Cpt(EpicsSignalRO, "CameraSelected", string="true") |
| 174 | + |
| 175 | + cross_select = Cpt(EpicsSignal, "CrossSelect") |
| 176 | + sync = Cpt(EpicsSignal, "Sync", string="true") |
| 177 | + server_running = Cpt(EpicsSignal, "ServerRunning", string="true") |
| 178 | + mct_status = Cpt(EpicsSignal, "MCTStatus", string="true") |
| 179 | + |
| 180 | + # Scintillator Information |
| 181 | + scintillator_type = Cpt(EpicsSignal, "ScintillatorType") |
| 182 | + scintillator_thickness = Cpt(EpicsSignal, "ScintillatorThickness") |
| 183 | + |
| 184 | + # Image and Detector Pixel Size |
| 185 | + image_pixel_size = Cpt(EpicsSignal, "ImagePixelSize") |
| 186 | + detector_pixel_size = Cpt(EpicsSignal, "DetectorPixelSize") |
| 187 | + |
| 188 | + # Camera Objectives |
| 189 | + camera_objective = Cpt(EpicsSignal, "CameraObjective") |
| 190 | + camera_tube_length = Cpt(EpicsSignal, "CameraTubeLength") |
| 191 | + |
| 192 | + # # Lens Names |
| 193 | + lens_info = Cpt(MCTOpticsLensInfo, "Lens") |
| 194 | + |
| 195 | + # Camera Lens Positions, Offsets, & Movement |
| 196 | + camera_0 = Cpt(MCTOpticsCameraControl, "Camera0") |
| 197 | + camera_1 = Cpt(MCTOpticsCameraControl, "Camera1") |
| 198 | + |
| 199 | + |
| 200 | +# Example initialization |
| 201 | +optics = MCTOptics("2bm:MCTOptics:", name="optics") |
0 commit comments