Skip to content

Commit

Permalink
Change PmacTrajectoryPart to use 1us ticks and limit move timer to 4s
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Oct 13, 2016
1 parent 5d63bdb commit f397f02
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
35 changes: 32 additions & 3 deletions malcolm/parts/pmac/pmactrajectorypart.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from malcolm.parts.builtin.layoutpart import LayoutPart

# Number of seconds that a trajectory tick is
TICK_S = 0.00025
TICK_S = 0.000001

# velocity modes
PREV_TO_NEXT = 0
Expand Down Expand Up @@ -181,7 +181,7 @@ def build_profile(self, task, time_array, velocity_mode, trajectory,
time_array (list): List of times in ms
velocity_mode (list): List of velocity modes like PREV_TO_NEXT
trajectory (dict): {axis_name: [positions in EGUs]}
task (dict): Task for running
task (Task): Task for running
user_programs (list): List of user programs like TRIG_LIVE_FRAME
"""
# Work out which axes should be used and set their resolutions and
Expand All @@ -198,9 +198,38 @@ def build_profile(self, task, time_array, velocity_mode, trajectory,
attr_dict["use%s" % cs_axis] = cs_axis in use
task.put({self.child[k]: v for k, v in attr_dict.items()})

# Start adding points, padding if the move time exceeds 4s
i = 0
while i < len(time_array):
t = time_array[i]
if t > 4:
# split
nsplit = int(t / 4.0 + 1)
new_time_array = time_array[:i]
new_velocity_mode = velocity_mode[:i]
new_user_programs = user_programs[:i]
for _ in range(nsplit):
new_time_array.append(t / nsplit)
new_velocity_mode.append(1)
new_user_programs.append(0)
time_array = new_time_array + time_array[i+1:]
user_programs = new_user_programs[:-1] + user_programs[i:]
velocity_mode = new_velocity_mode[:-1] + velocity_mode[i:]

for k, traj in trajectory.items():
new_traj = traj[:i]
per_section = float(traj[i] - traj[i-1]) / nsplit
for j in range(1, nsplit+1):
new_traj.append(traj[i-1] + j * per_section)
trajectory[k] = new_traj + traj[i+1:]

i += nsplit
else:
i += 1

# Process the time in ticks
time_array_ticks = []
overflow = 0
time_array_ticks = []
for t in time_array:
ticks = t / TICK_S
overflow += (ticks % 1)
Expand Down
24 changes: 19 additions & 5 deletions tests/test_parts/test_pmac/test_pmactrajectorypart.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_configure(self):
self.assertEqual(task.post_async.call_count, 1)
self.check_resolutions_and_use(task.put.call_args_list[0][0][0])
self.assertEqual(task.put.call_args_list[1][0][0], {
self.child["time_array"]: [400, 1750, 400],
self.child["time_array"]: [100000, 437500, 100000],
self.child["velocity_mode"]: [2, 1, 3],
self.child["user_programs"]: [0, 0, 0],
self.child["num_points"]: 3,
Expand All @@ -109,8 +109,8 @@ def test_configure(self):
self.check_resolutions_and_use(task.put.call_args_list[2][0][0])
self.assertEqual(task.put.call_args_list[3][0][0], {
self.child["time_array"]: [
400, 2000, 2000, 2000, 2000, 2000, 2000, 400,
400, 2000, 2000, 2000, 2000, 2000, 2000, 400],
100000, 500000, 500000, 500000, 500000, 500000, 500000, 100000,
100000, 500000, 500000, 500000, 500000, 500000, 500000, 100000],
self.child["velocity_mode"]: [
2, 0, 0, 0, 0, 0, 1, 0,
2, 0, 0, 0, 0, 0, 1, 3],
Expand Down Expand Up @@ -145,15 +145,29 @@ def test_multi_run(self):
self.check_resolutions_and_use(task.put.call_args_list[0][0][0],
useB=False)
self.assertEqual(task.put.call_args_list[1][0][0], {
self.child["time_array"]: [400, 2000, 2000, 2000, 2000, 2000, 2000,
400],
self.child["time_array"]: [
100000, 500000, 500000, 500000, 500000, 500000, 500000, 100000],
self.child["velocity_mode"]: [2, 0, 0, 0, 0, 0, 1, 3],
self.child["user_programs"]: [3, 4, 3, 4, 3, 4, 2, 8],
self.child["num_points"]: 8,
self.child["positionsA"]: [0.625, 0.5, 0.375, 0.25, 0.125, 0.0,
-0.125, -0.1375],
})

def test_long_move(self):
task = self.do_configure(axes_to_scan=["x"], x_pos=-10.1375)
self.assertEqual(task.put.call_args_list[1][0][0], {
self.child["time_array"]: [
100000, 3266667, 3266666, 3266667, 100000],
self.child["velocity_mode"]: [
2, 1, 1, 1, 3],
self.child["user_programs"]: [
0, 0, 0, 0, 0],
self.child["num_points"]: 5,
self.child["positionsA"]: [
-10.087499999999999, -6.7875, -3.4875, -0.1875, -0.1375],
})


if __name__ == "__main__":
unittest.main(verbosity=2)

0 comments on commit f397f02

Please sign in to comment.