Skip to content

Commit

Permalink
make motor locatable (#541)
Browse files Browse the repository at this point in the history
* make motor locatable

* trying to get the test right

* update the test
  • Loading branch information
stan-dot committed Aug 27, 2024
1 parent d7f0748 commit 025bc54
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/ophyd_async/epics/motor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import asyncio
from typing import Optional

from bluesky.protocols import Flyable, Movable, Preparable, Stoppable
from bluesky.protocols import (
Flyable,
Locatable,
Location,
Preparable,
Stoppable,
)
from pydantic import BaseModel, Field

from ophyd_async.core import (
Expand Down Expand Up @@ -51,7 +57,7 @@ class FlyMotorInfo(BaseModel):
timeout: CalculatableTimeout = Field(frozen=True, default=CalculateTimeout)


class Motor(StandardReadable, Movable, Stoppable, Flyable, Preparable):
class Motor(StandardReadable, Locatable, Stoppable, Flyable, Preparable):
"""Device that moves a motor record"""

def __init__(self, prefix: str, name="") -> None:
Expand Down Expand Up @@ -193,6 +199,13 @@ async def _prepare_velocity(
await self.velocity.set(abs(max_speed))
return fly_velocity

async def locate(self) -> Location[float]:
location: Location = {
"setpoint": await self.user_setpoint.get_value(),
"readback": await self.user_readback.get_value(),
}
return location

async def _prepare_motor_path(
self, fly_velocity: float, start_position: float, end_position: float
) -> float:
Expand Down
15 changes: 15 additions & 0 deletions tests/epics/test_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
MockSignalBackend,
SignalRW,
callback_on_mock_put,
mock_puts_blocked,
observe_value,
set_mock_put_proceeds,
set_mock_value,
Expand Down Expand Up @@ -317,3 +318,17 @@ async def test_complete(sim_motor: motor.Motor) -> None:
assert not sim_motor._fly_status.done
await sim_motor.complete()
assert sim_motor._fly_status.done


async def test_locatable(sim_motor: motor.Motor) -> None:
callback_on_mock_put(
sim_motor.user_setpoint,
lambda x, *_, **__: set_mock_value(sim_motor.user_readback, x),
)
assert (await sim_motor.locate())["readback"] == 0
async with mock_puts_blocked(sim_motor.user_setpoint):
move_status = sim_motor.set(10)
assert (await sim_motor.locate())["readback"] == 0
await move_status
assert (await sim_motor.locate())["readback"] == 10
assert (await sim_motor.locate())["setpoint"] == 10

0 comments on commit 025bc54

Please sign in to comment.