APS-4ID-POLAR / ipython-polar

4-ID-Polar ipython configuration for bluesky (and other)
1 stars 3 forks source link

Create stop method to energy #111

Closed gfabbris closed 3 years ago

gfabbris commented 3 years ago

Closes #97.

Creates adds stop methods to EnergySignal, MyUndulator, and Monochromator. The mono is the trickiest and ugliest solution. The EPICS Kohzu screen exposes the mono.th PV in a PV. So the critical part (and perhaps problematic) part is this:

class KohzuPositioner(PVPositionerSoftDone):
    stop_signal = FormattedComponent(EpicsSignal, "{_theta_pv}.STOP",
                                     kind="omitted")
    stop_value = 1

    def __init__(self, prefix, *, limits=None, readback_pv="", setpoint_pv="",
                 name=None, read_attrs=None, configuration_attrs=None,
                 parent=None, egu="", **kwargs):

        # TODO: Ugly... but works.
        _theta_pv_signal = EpicsSignalRO(f"{prefix}KohzuThetaPvSI", name="tmp")
        _theta_pv_signal.wait_for_connection()
        self._theta_pv = _theta_pv_signal.get(as_string=True)
        _theta_pv_signal.destroy()
        _theta_pv_signal = None

        super().__init__(
            prefix, limits=limits, readback_pv=readback_pv,
            setpoint_pv=setpoint_pv, name=name, read_attrs=read_attrs,
            configuration_attrs=configuration_attrs, parent=parent, egu=egu,
            **kwargs
        )

@prjemian: any alternative solution?

lgtm-com[bot] commented 3 years ago

This pull request introduces 1 alert when merging 1dd24a123567e0bcdf2bcce4ac5d7cd9a641b3e2 into 96012112d267310b39fd122794802b61bb9ca539 - view on LGTM.com

new alerts:

lgtm-com[bot] commented 3 years ago

This pull request introduces 1 alert when merging 353c7d0687b514cbf814c284a2b63345eb2a21d7 into 96012112d267310b39fd122794802b61bb9ca539 - view on LGTM.com

new alerts:

gfabbris commented 3 years ago

Move this section to a function inside the init so that it dispose it after running once.

        # TODO: Ugly... but works.
        _theta_pv_signal = EpicsSignalRO(f"{prefix}KohzuThetaPvSI", name="tmp")
        _theta_pv_signal.wait_for_connection()
        self._theta_pv = _theta_pv_signal.get(as_string=True)
        _theta_pv_signal.destroy() # This won't be needed.
        _theta_pv_signal = None # This won't be needed
def get_theta_pv(...):
        _theta_pv_signal = EpicsSignalRO(f"{prefix}KohzuThetaPvSI", name="tmp")
        _theta_pv_signal.wait_for_connection()
        return _theta_pv_signal.get(as_string=True)
gfabbris commented 3 years ago

Test this - particularly the undulator- in the virtual machine

gfabbris commented 3 years ago

Implemented all energy related stuff in the virtual machine (mono, undulator, phase retarder). Comments:

https://github.com/APS-4ID-POLAR/ipython-polar/blob/b0c57ed90ee1891c54d78c849140a82d6e28caa8/profile_bluesky/startup/instrument/devices/aps_source.py#L78

  but that is not handled bu the Run Engine, so it doesn't handle control+c well.

https://github.com/APS-4ID-POLAR/ipython-polar/blob/b0c57ed90ee1891c54d78c849140a82d6e28caa8/profile_bluesky/startup/instrument/devices/util_components.py#L115

  But maybe this is a more general problem that should be fixed in `ophyd`.
gfabbris commented 3 years ago

@prjemian: This seems to be working now (as tested in the VM). The undulator backlash is handled using threading.Thread, but I'm not quite familiar with threading, so this potentially not the best way to do this...