Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve FakeEpicsMotor enough to get mv working #1135

Open
DominicOram opened this issue Jul 18, 2023 · 0 comments
Open

Improve FakeEpicsMotor enough to get mv working #1135

DominicOram opened this issue Jul 18, 2023 · 0 comments

Comments

@DominicOram
Copy link
Contributor

DominicOram commented Jul 18, 2023

Currently if we do a bps.mv on a FakeEpicsMotor the plan will fail:

from unittest.mock import MagicMock

import bluesky.plan_stubs as bps
from bluesky import RunEngine
from ophyd import Component, Device, EpicsMotor
from ophyd.sim import make_fake_device
from ophyd.status import Status


class MyDevice(Device):
    x = Component(EpicsMotor, "")


FakeDevice = make_fake_device(MyDevice)
my_fake_device = FakeDevice(name="")

RE = RunEngine()

try:
    RE(bps.mv(my_fake_device.x.get(), 10))
except:
    print(f"Move failed: {my_fake_device.x}")

We can fix this doing something like:

my_fake_device.x.user_setpoint._use_limits = False

def mock_set_position(val: int):
    my_fake_device.x.user_readback.sim_put(val)
    return Status(done=True, success=True)


my_fake_device.x.set =  MagicMock(side_effect=mock_set_position)

RE(bps.mv(my_fake_device.x, 10))

print(f"Success {my_fake_device.x.get()}")

Which will remove trying to get the limits from the PV and make the motor appear to immediately move to the setpoint. I propose that we put something like this in as default behaviour in FakeEpicsMotor. Obviously generally simulating motion could be a pandoras box but this will at least allow plans with a basic mv in them to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant