Skip to content

Commit

Permalink
Changed IO assignment to DeviceVector
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtrafford committed Jul 19, 2024
1 parent b771fd7 commit a40bfbe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.
53 changes: 25 additions & 28 deletions src/ophyd_async/epics/pmac/_pmacIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy.typing as npt
from bluesky.protocols import Flyable, Preparable

from ophyd_async.core import StandardReadable, SubsetEnum
from ophyd_async.core import DeviceVector, StandardReadable, SubsetEnum

from ..signal.signal import epics_signal_r, epics_signal_rw

Expand All @@ -14,33 +14,30 @@ def __init__(self, prefix: str, cs="", name="") -> None:
self.timeArray = epics_signal_rw(
npt.NDArray[np.float64], prefix + ":ProfileTimeArray"
)
self.a = epics_signal_rw(npt.NDArray[np.float64], prefix + ":A:Positions")
self.use_a = epics_signal_rw(bool, prefix + ":A:UseAxis")
self.a_vel = epics_signal_rw(npt.NDArray[np.float64], prefix + ":A:Velocities")
self.b = epics_signal_rw(npt.NDArray[np.float64], prefix + ":B:Positions")
self.use_b = epics_signal_rw(bool, prefix + ":B:UseAxis")
self.b_vel = epics_signal_rw(npt.NDArray[np.float64], prefix + ":B:Velocities")
self.c = epics_signal_rw(npt.NDArray[np.float64], prefix + ":C:Positions")
self.use_c = epics_signal_rw(bool, prefix + ":C:UseAxis")
self.c_vel = epics_signal_rw(npt.NDArray[np.float64], prefix + ":C:Velocities")
self.u = epics_signal_rw(npt.NDArray[np.float64], prefix + ":U:Positions")
self.use_u = epics_signal_rw(bool, prefix + ":U:UseAxis")
self.u_vel = epics_signal_rw(npt.NDArray[np.float64], prefix + ":U:Velocities")
self.v = epics_signal_rw(npt.NDArray[np.float64], prefix + ":V:Positions")
self.use_v = epics_signal_rw(bool, prefix + ":V:UseAxis")
self.v_vel = epics_signal_rw(npt.NDArray[np.float64], prefix + ":V:Velocities")
self.w = epics_signal_rw(npt.NDArray[np.float64], prefix + ":W:Positions")
self.use_w = epics_signal_rw(bool, prefix + ":W:UseAxis")
self.w_vel = epics_signal_rw(npt.NDArray[np.float64], prefix + ":W:Velocities")
self.x = epics_signal_rw(npt.NDArray[np.float64], prefix + ":X:Positions")
self.use_x = epics_signal_rw(bool, prefix + ":X:UseAxis")
self.x_vel = epics_signal_rw(npt.NDArray[np.float64], prefix + ":X:Velocities")
self.y = epics_signal_rw(npt.NDArray[np.float64], prefix + ":Y:Positions")
self.use_y = epics_signal_rw(bool, prefix + ":Y:UseAxis")
self.y_vel = epics_signal_rw(npt.NDArray[np.float64], prefix + ":Y:Velocities")
self.z = epics_signal_rw(npt.NDArray[np.float64], prefix + ":Z:Positions")
self.use_z = epics_signal_rw(bool, prefix + ":Z:UseAxis")
self.z_vel = epics_signal_rw(npt.NDArray[np.float64], prefix + ":Z:Velocities")
cs_letters = "ABCUVWXYZ"
# 1 indexed CS axes so we can index into them from the compound motor input link
self.positions = DeviceVector(
{
letter: epics_signal_rw(
npt.NDArray[np.float64], f"{prefix}:{letter}:Positions"
)
for letter in cs_letters
}
)
self.use_axis = DeviceVector(
{
letter: epics_signal_rw(bool, f"{prefix}:{letter}:UseAxis")
for letter in (cs_letters)
}
)
self.velocities = DeviceVector(
{
letter: epics_signal_rw(
npt.NDArray[np.float64], f"{prefix}:{letter}:Velocities"
)
for letter in cs_letters
}
)
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
9 changes: 4 additions & 5 deletions src/ophyd_async/epics/pmac/_pmacTrajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,13 @@ async def prepare(self, stack: list[Frames[Motor]]):
self.profile["duration"][0] += run_up_time / TICK_S
self.profile["duration"].append(int(final_time / TICK_S))

# Send trajectory to brick
for axis in scanAxes:
if axis != "DURATION":
self.profile_cs_name.set(cs_port)
self.points_to_build.set(scanSize + 1)
getattr(self, "use_" + cs_axes[axis]).set(True)
getattr(self, cs_axes[axis]).set(self.profile[cs_axes[axis]])
getattr(self, cs_axes[axis] + "_vel").set(
self.use_axis[cs_axes[axis]].set(True)
self.positions[cs_axes[axis]].set(self.profile[cs_axes[axis]])
self.velocities[cs_axes[axis]].set(
self.profile[cs_axes[axis] + "_velocity"]
)
else:
Expand Down Expand Up @@ -151,5 +150,5 @@ async def get_cs_info(self, motor: Motor):
split = output_link.split("(")[1].rstrip(")").split(",")
cs_port = split[0].strip()
assert "CS" in cs_port, f"{self.name} not in a CS. It is not a compound motor."
cs_axis = "abcuvwxyz"[int(split[1].strip()) - 1]
cs_axis = "ABCUVWXYZ"[int(split[1].strip()) - 1]
return cs_port, cs_axis
6 changes: 3 additions & 3 deletions tests/epics/pmac/test_pmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ async def test_sim_pmac_simple_trajectory(sim_x_motor) -> None:
1000000,
50000,
],
"z": [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.0125],
"z_velocity": [
"Z": [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.0125],
"Z_velocity": [
0.5,
0.5,
0.5,
Expand All @@ -58,6 +58,6 @@ async def test_sim_pmac_simple_trajectory(sim_x_motor) -> None:
}

assert await traj.points_to_build.get_value() == 10
assert traj.initial_pos["z"] == 0.9875
assert traj.initial_pos["Z"] == 0.9875

await traj.kickoff()

0 comments on commit a40bfbe

Please sign in to comment.