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

Ensure motors can be stopped #688

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ophyd_async/epics/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
observe_value,
)
from ophyd_async.core import StandardReadableFormat as Format
from ophyd_async.epics.core import epics_signal_r, epics_signal_rw, epics_signal_x
from ophyd_async.epics.core import epics_signal_r, epics_signal_rw, epics_signal_w


class MotorLimitsException(Exception):
Expand Down Expand Up @@ -76,7 +76,10 @@ def __init__(self, prefix: str, name="") -> None:
self.low_limit_travel = epics_signal_rw(float, prefix + ".LLM")
self.high_limit_travel = epics_signal_rw(float, prefix + ".HLM")

self.motor_stop = epics_signal_x(prefix + ".STOP")
# Note:cannot use epics_signal_x here, as the motor record specifies that
# we must write 1 to stop the motor. Simply processing the record is not
# sufficient.
self.motor_stop = epics_signal_w(int, prefix + ".STOP")
# Whether set() should complete successfully or not
self._set_success = True

Expand Down Expand Up @@ -178,7 +181,7 @@ async def stop(self, success=False):
self._set_success = success
# Put with completion will never complete as we are waiting for completion on
# the move above, so need to pass wait=False
await self.motor_stop.trigger(wait=False)
await self.motor_stop.set(1, wait=False)

async def _prepare_velocity(
self, start_position: float, end_position: float, time_for_move: float
Expand Down
6 changes: 6 additions & 0 deletions tests/epics/test_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
AsyncStatus,
DeviceCollector,
callback_on_mock_put,
get_mock_put,
mock_puts_blocked,
observe_value,
set_mock_put_proceeds,
Expand Down Expand Up @@ -164,6 +165,11 @@ async def test_motor_moving_stopped(sim_motor: motor.Motor):
await asyncio.sleep(0.2)
assert not s.done
await sim_motor.stop()

# Note: needs to explicitly be called with 1, not just processed.
# See https://epics.anl.gov/bcda/synApps/motor/motorRecord.html#Fields_command
get_mock_put(sim_motor.motor_stop).assert_called_once_with(1, wait=False)

set_mock_put_proceeds(sim_motor.user_setpoint, True)
await wait_for_wakeups()
assert s.done
Expand Down