BCDA-APS / use_bluesky

Tools to help APS use the Bluesky Framework (https://blueskyproject.io/)
8 stars 3 forks source link

Monitoring custom motor instrument #61

Closed hududed closed 4 years ago

hududed commented 4 years ago

I am new to EPICS instruments and I am not sure if this is the right place to ask this question.

I have a Newport XPS-D4 control stage and I wish to monitor the positions continuously. I control the stage according to here. The code is like this:

from newportxps import NewportXPS
from newportxps.XPS_C8_drivers import XPS, XPSException
import pysftp
from ophyd import EpicsSignal

hostname = 'XPS-1b81'
xps = NewportXPS(hostname)

for sname, info in xps.stages.items():
    print(sname, xps.get_stage_position(sname), info)

Output:

Z.Z-MFA 0.9999984006 {'stagetype': 'MFA@MFA-CC@XPS-DRV11', 'max_velo': 2.5, 'max_accel': 3.3333333333333335, 'low_limit': -0.0001, 'high_limit': 25}
XY.X-MFA 0 {'stagetype': 'MFA@MFA-CC@XPS-DRV11', 'max_velo': 2.5, 'max_accel': 3.3333333333333335, 'low_limit': -0.0001, 'high_limit': 25}
XY.Y-MFA 0 {'stagetype': 'MFA@MFA-CC@XPS-DRV11', 'max_velo': 2.5, 'max_accel': 3.3333333333333335, 'low_limit': -0.0001, 'high_limit': 25}

I can follow tutorial codes using simulated hardware, but how can I add e.g. this stage controller instrument to monitor the positions of all the axes in here:

x = EpicsSignal(XXX, name='x')

def callback(value, old_value, **kwargs):
    print(f"Value changed from {old_value} to {value}.")

token = x.subscribe(callback)
prjemian commented 4 years ago

Did you get your question answered yet in some other chat forum? The ophyd repository issue tracker is far better (more visibility for your question and any responses) than this repo, which is for the installation and administration of the Bluesky framework.

hududed commented 4 years ago

Yes, my problem is small-scale and am working to interface with bluesky through yaq. Thanks

prjemian commented 4 years ago

You're on the right track with your example code but need to dig a little deeper. Your callback needs to know which object to describe. To do this, I usually subclass EpicsSignal:

class MyEpicsSignal(EpicsSignal):

    def reporter(self, value, old_value, **kwargs):
        print(f"{self.name}: Value changed from {old_value} to {value}.")

x = MyEpicsSignal(XXX, name='x')
x.subscribe(x.reporter)

Then, you get a separate reporter for each instance of MyEpicsSignal.