Skip to content

Commit

Permalink
Implement trajectory scanning on raw Motors
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtrafford committed Oct 10, 2024
1 parent 79d1086 commit 057083d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/ophyd_async/epics/pmac/_pmacIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
class Pmac(StandardReadable):
"""Device that moves a PMAC Motor record"""

def __init__(self, prefix: str, name="") -> None:
def __init__(self, prefix: str, axes_on_brick: list[int], name: str = "") -> None:
self.prefix = prefix
self.time_array = epics_signal_rw(
npt.NDArray[np.float64], prefix + ":ProfileTimeArray"
)
Expand Down Expand Up @@ -37,6 +38,12 @@ def __init__(self, prefix: str, name="") -> None:
for i, letter in enumerate(cs_letters)
}
)
self.CsAxisAssignment = DeviceVector(
{i: epics_signal_r(str, f"{prefix}:M{i}:CsAxis_RBV") for i in axes_on_brick}
)
self.CsPortAssignment = DeviceVector(
{i: epics_signal_r(str, f"{prefix}:M{i}:CsPort_RBV") for i in axes_on_brick}
)
self.points_to_build = epics_signal_rw(int, prefix + ":ProfilePointsToBuild")
self.build_profile = epics_signal_rw(bool, prefix + ":ProfileBuild")
self.execute_profile = epics_signal_rw(bool, prefix + ":ProfileExecute")
Expand Down
12 changes: 10 additions & 2 deletions src/ophyd_async/epics/pmac/_pmacTrajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,16 @@ async def get_cs_info(self, motor: motor.Motor) -> tuple[str, int]:
# Split "@asyn(PORT,num)" into ["PORT", "num"]
split = output_link.split("(")[1].rstrip(")").split(",")
cs_port = split[0].strip()
assert "CS" in cs_port, f"{motor.name} not in a CS. It is not a compound motor."
cs_index = int(split[1].strip()) - 1
if "CS" in cs_port:
# Motor is compound
cs_index = int(split[1].strip()) - 1
else:
# Raw Motor, CS 1 to be used - Straight through mapping
axis = int(split[1].strip())
cs_port = await self.pmac.CsPortAssignment[axis].get_value()
cs_axis = await self.pmac.CsAxisAssignment[axis].get_value()
cs_index = "ABCUVWXYZ".index(cs_axis)

return cs_port, cs_index

def _calculate_gaps(self, chunk: Frames[motor.Motor]):
Expand Down
20 changes: 13 additions & 7 deletions tests/epics/pmac/test_pmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,25 @@ async def sim_y_motor():
set_mock_value(sim_motor.acceleration_time, 0.5)
set_mock_value(sim_motor.max_velocity, 5)
set_mock_value(sim_motor.velocity, 0.5)
set_mock_value(sim_motor.output_link, "@asyn(BRICK1.CS3,8)")
set_mock_value(sim_motor.output_link, "@asyn(BRICK1,8)")

yield sim_motor


@pytest.fixture
async def sim_pmac():
async with DeviceCollector(mock=True):
sim_pmac = Pmac("BLxxI-MO-STEP-01", axes_on_brick=[7, 8], name="sim_pmac")
set_mock_value(sim_pmac.CsAxisAssignment[8], "Y")
set_mock_value(sim_pmac.CsPortAssignment[8], "BRICK1.CS3")
yield sim_pmac


async def test_sim_pmac_simple_trajectory(sim_x_motor) -> None:
# Test the generated Trajectory profile from a scanspec
prefix = "BLxxI-MO-STEP-01"
async with DeviceCollector(mock=True):
pmac = Pmac(prefix, name="sim_pmac")
pmac = Pmac(prefix, axes_on_brick=[7, 8], name="sim_pmac")
spec = fly(Line(sim_x_motor, 1, 5, 9), 1)
info = PmacTrajInfo(spec=spec)
trigger_logic = PmacTrajectoryTriggerLogic(pmac)
Expand Down Expand Up @@ -122,14 +131,11 @@ async def test_sim_pmac_simple_trajectory(sim_x_motor) -> None:
await trigger_logic.kickoff()


async def test_sim_grid_trajectory(sim_x_motor, sim_y_motor) -> None:
async def test_sim_grid_trajectory(sim_x_motor, sim_y_motor, sim_pmac) -> None:
# Test the generated Trajectory profile from a scanspec
prefix = "BLxxI-MO-STEP-01"
async with DeviceCollector(mock=True):
pmac = Pmac(prefix, name="sim_pmac")
spec = fly(Line(sim_y_motor, 10, 12, 3) * ~Line(sim_x_motor, 1, 5, 5), 1)
info = PmacTrajInfo(spec=spec)
trigger_logic = PmacTrajectoryTriggerLogic(pmac)
trigger_logic = PmacTrajectoryTriggerLogic(sim_pmac)
await trigger_logic.prepare(info)
assert await trigger_logic.pmac.positions[9].get_value() == pytest.approx(
[
Expand Down

0 comments on commit 057083d

Please sign in to comment.