-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from spc-group/async-ad
Async ad
- Loading branch information
Showing
18 changed files
with
302 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
Adding Devices in Haven | ||
======================= | ||
|
||
This guide encompasses two concepts: | ||
|
||
- adding a new instance of a device that already has Haven support | ||
- adding a new category of device that does not have Haven support | ||
|
||
Existing Haven Support | ||
---------------------- | ||
|
||
If the device you are using already has a device class created for it, | ||
then using the device only requires a suitable entry in the iconfig | ||
file. By inspecting the environmental variable HAVEN_CONFIG_FILES we | ||
can see that in this case the configuration file is | ||
``~/bluesky/iconfig.toml``, though your beamline may be different. | ||
|
||
.. code-block:: bash | ||
$ echo $HAVEN_CONFIG_FILES | ||
/home/beams/S255IDCUSER/bluesky/iconfig.toml | ||
Next, add a new section for this device. The TOML section name should | ||
be the device category, often a lower-case version of the device | ||
class. Most devices also accept at least the parameter *name*, which | ||
will be used to retrieve the device later from the instrument | ||
registry. | ||
|
||
In most cases the key "prefix" should list the IOC prefix, including | ||
the trailing ":". For this example, we will add a simple motor. | ||
|
||
.. code-block:: toml | ||
[[ motor ]] | ||
prefix = "255idc:m1" | ||
name = "bpm" | ||
Once this section has been added to ``iconfig.toml``, then the device | ||
can be loaded from the instrument registry. No special configuration | ||
is generally necessary. | ||
|
||
This device will be loaded once the beamline's load method is called, | ||
though this **usually done automatically** during startup. | ||
|
||
.. code-block:: | ||
from haven.instrument import beamline | ||
await beamline.load() | ||
bpm_motor = beamline.registry['bpm'] | ||
New Haven Support | ||
----------------- | ||
|
||
If Haven does not already have support for the device, this will need | ||
to be added. Details on how to create Ophyd and Ophyd-async devices is | ||
beyond the scope of this guide. Assume for this example that there is | ||
a file ``src/haven/devices/toaster.py`` which contains a device class | ||
``Toaster()`` that accepts the parameters *max_power*, *num_slots*, | ||
*prefix*, and *name*. | ||
|
||
To let the Haven instrument loader know about this device, edit the | ||
file ``src/haven/instrument.py`` and look for the line like ``beamline | ||
= Instrument({``. Following this line is a mapping of device classes | ||
to their TOML section names. We will now add our new device to this mapping: | ||
|
||
.. code-block:: python | ||
beamline = Instrument({ | ||
... | ||
"toaster": Toaster, | ||
... | ||
}) | ||
The order does not usually matter, though device classes will be | ||
created in the order they are retrieved from this dictionary. | ||
|
||
Now the following section can be added to the ``iconfig.toml`` file. | ||
|
||
.. code-block:: toml | ||
[[ toaster ]] | ||
name = "sunbeam" | ||
prefix = "255idc:toast:" | ||
num_slots = 2 # 2-slot toaster | ||
max_power = 1200 # Watts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
############## | ||
How-To Guides | ||
############## | ||
|
||
These guides provide a step-by-step guide for performing specific | ||
tasks. In contrast with tutorials, these guides assume a basic level | ||
of understanding of topics like Haven, Ophyd, Ophyd-async, and | ||
Bluesky. | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:caption: Contents: | ||
|
||
adding_devices.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from ophyd_async.core import SubsetEnum | ||
from ophyd_async.epics.adaravis import AravisDetector as DetectorBase | ||
from ophyd_async.epics.signal import epics_signal_rw_rbv | ||
|
||
from .area_detectors import HavenDetector | ||
|
||
AravisTriggerSource = SubsetEnum["Software", "Line1"] | ||
|
||
|
||
class AravisDetector(HavenDetector, DetectorBase): | ||
_ophyd_labels_ = {"cameras", "detectors"} | ||
|
||
def __init__(self, prefix, *args, **kwargs): | ||
super().__init__(*args, prefix=prefix, **kwargs) | ||
# Replace a signal that has different enum options | ||
self.drv.trigger_source = epics_signal_rw_rbv( | ||
AravisTriggerSource, # type: ignore | ||
f"{prefix}cam1:TriggerSource", | ||
) | ||
self.set_name(self.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from pathlib import Path | ||
|
||
from ophyd_async.core import UUIDFilenameProvider, YMDPathProvider | ||
|
||
from ..._iconfig import load_config | ||
|
||
|
||
class HavenDetector: | ||
def __init__(self, *args, writer_path=None, **kwargs): | ||
# Create a path provider based on the path given | ||
if writer_path is None: | ||
writer_path = default_path() | ||
path_provider = YMDPathProvider( | ||
filename_provider=UUIDFilenameProvider(), | ||
base_directory_path=writer_path, | ||
create_dir_depth=-4, | ||
) | ||
super().__init__(*args, path_provider=path_provider, **kwargs) | ||
|
||
|
||
def default_path(config=None): | ||
if config is None: | ||
config = load_config() | ||
# Generate a default path provider | ||
root_dir = Path(config.get("area_detector_root_path", "/tmp")) | ||
return root_dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from ophyd_async.epics.adsimdetector import SimDetector as SimDetectorBase | ||
|
||
from .area_detectors import HavenDetector | ||
|
||
|
||
class SimDetector(HavenDetector, SimDetectorBase): | ||
_ophyd_labels_ = {"area_detectors", "detectors"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.