Skip to content

Commit 22a2ad8

Browse files
committed
Get CS info from motor link field. Only works for compound motors
1 parent e4aa5f0 commit 22a2ad8

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

src/ophyd_async/epics/pmac/_pmacMotor.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22

33
from ophyd_async.epics.motion import Motor
44

5+
from ..signal.signal import epics_signal_r
6+
57

68
class PmacCSMotor(Motor, Movable, Stoppable):
7-
def __init__(self, prefix: str, csNum: int, csAxis: str, name="") -> None:
8-
self.csNum = csNum
9-
self.csAxis = csAxis
9+
def __init__(self, prefix: str, name="") -> None:
10+
self.output_link = epics_signal_r(str, prefix + ".OUT")
11+
self.cs_axis = ""
12+
self.cs_port = ""
1013
super().__init__(prefix=prefix, name=name)
14+
15+
async def get_cs_info(self):
16+
output_link = await self.output_link.get_value()
17+
# Split "@asyn(PORT,num)" into ["PORT", "num"]
18+
split = output_link.split("(")[1].rstrip(")").split(",")
19+
self.cs_port = split[0].strip()
20+
assert (
21+
"CS" in self.cs_port
22+
), f"{self.name} not in a CS. It is not a compound motor."
23+
self.cs_axis = "abcuvwxyz"[int(split[1].strip()) - 1]

src/ophyd_async/epics/pmac/_pmacTrajectory.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,37 @@ async def prepare(self, stack: list[Frames[PmacCSMotor]]):
3737
scanSize = len(stack[0])
3838
scanAxes = stack[0].axes()
3939

40+
cs_ports = set()
4041
self.profile = {}
4142
for axis in scanAxes:
4243
if axis != "DURATION":
43-
self.profile[axis.csAxis] = []
44-
self.profile[axis.csAxis + "_velocity"] = []
44+
await axis.get_cs_info()
45+
self.profile[axis.cs_axis] = []
46+
self.profile[axis.cs_axis + "_velocity"] = []
47+
cs_ports.add(axis.cs_port)
4548
else:
4649
self.profile[axis.lower()] = []
50+
cs_port = cs_ports.pop()
4751

4852
# Calc Velocity
4953

5054
for axis in scanAxes:
5155
for i in range(scanSize - 1):
5256
if axis != "DURATION":
53-
self.profile[axis.csAxis + "_velocity"].append(
57+
self.profile[axis.cs_axis + "_velocity"].append(
5458
(stack[0].midpoints[axis][i + 1] - stack[0].midpoints[axis][i])
5559
/ (stack[0].midpoints["DURATION"][i])
5660
)
57-
self.profile[axis.csAxis].append(stack[0].midpoints[axis][i])
61+
self.profile[axis.cs_axis].append(stack[0].midpoints[axis][i])
5862
else:
5963
self.profile[axis.lower()].append(
6064
int(stack[0].midpoints[axis][i] / TICK_S)
6165
)
6266
if axis != "DURATION":
63-
self.profile[axis.csAxis].append(stack[0].midpoints[axis][scanSize - 1])
64-
self.profile[axis.csAxis + "_velocity"].append(0)
67+
self.profile[axis.cs_axis].append(
68+
stack[0].midpoints[axis][scanSize - 1]
69+
)
70+
self.profile[axis.cs_axis + "_velocity"].append(0)
6571
else:
6672
self.profile[axis.lower()].append(
6773
int(stack[0].midpoints[axis][scanSize - 1] / TICK_S)
@@ -75,30 +81,30 @@ async def prepare(self, stack: list[Frames[PmacCSMotor]]):
7581
run_up_disp, run_up_time = await self._ramp_up_velocity_pos(
7682
0,
7783
axis,
78-
self.profile[axis.csAxis + "_velocity"][0],
84+
self.profile[axis.cs_axis + "_velocity"][0],
7985
)
80-
self.initial_pos[axis.csAxis] = (
81-
self.profile[axis.csAxis][0] - run_up_disp
86+
self.initial_pos[axis.cs_axis] = (
87+
self.profile[axis.cs_axis][0] - run_up_disp
8288
)
8389
self.profile["duration"][0] += run_up_time / TICK_S
8490

8591
# Send trajectory to brick
8692
for axis in scanAxes:
8793
if axis != "DURATION":
88-
self.profile_cs_name.set(self.cs)
94+
self.profile_cs_name.set(cs_port)
8995
self.points_to_build.set(scanSize)
90-
getattr(self, "use_" + axis.csAxis).set(True)
91-
getattr(self, axis.csAxis).set(self.profile[axis.csAxis])
92-
getattr(self, axis.csAxis + "_vel").set(
93-
self.profile[axis.csAxis + "_velocity"]
96+
getattr(self, "use_" + axis.cs_axis).set(True)
97+
getattr(self, axis.cs_axis).set(self.profile[axis.cs_axis])
98+
getattr(self, axis.cs_axis + "_vel").set(
99+
self.profile[axis.cs_axis + "_velocity"]
94100
)
95101
else:
96102
self.timeArray.set(self.profile["duration"])
97103

98104
# MOVE TO START
99105
for axis in scanAxes:
100106
if axis != "DURATION":
101-
await axis.set(self.initial_pos[axis.csAxis])
107+
await axis.set(self.initial_pos[axis.cs_axis])
102108

103109
# Set No Of Points
104110

tests/epics/pmac/test_pmac.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
@pytest.fixture
99
async def sim_x_motor():
1010
async with DeviceCollector(mock=True):
11-
sim_motor = PmacCSMotor(
12-
"BLxxI-MO-STAGE-01:X", "BRICK1.CS3", "z", name="sim_x_motor"
13-
)
11+
sim_motor = PmacCSMotor("BLxxI-MO-STAGE-01:X", name="sim_x_motor")
1412

1513
set_mock_value(sim_motor.motor_egu, "mm")
1614
set_mock_value(sim_motor.precision, 3)
1715
set_mock_value(sim_motor.acceleration_time, 0.5)
1816
set_mock_value(sim_motor.max_velocity, 5)
1917
set_mock_value(sim_motor.velocity, 0.5)
18+
set_mock_value(sim_motor.output_link, "@asyn(BRICK1.CS3,9)")
2019

2120
yield sim_motor
2221

0 commit comments

Comments
 (0)