Skip to content

Commit 9300a2c

Browse files
authored
Fix prepare motor path (#892)
* Fix prepare_motor_path for negative direction * Fix other motor tests
1 parent 147fd94 commit 9300a2c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/ophyd_async/epics/motor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ async def _prepare_motor_path(
260260
(await self.acceleration_time.get_value()) * fly_velocity * 0.5
261261
)
262262

263-
self._fly_completed_position = end_position + run_up_distance
263+
direction = 1 if end_position > start_position else -1
264+
self._fly_completed_position = end_position + (run_up_distance * direction)
264265

265266
# Prepared position not used after prepare, so no need to store in self
266-
fly_prepared_position = start_position - run_up_distance
267+
fly_prepared_position = start_position - (run_up_distance * direction)
267268

268269
motor_lower_limit, motor_upper_limit, egu = await asyncio.gather(
269270
self.low_limit_travel.get_value(),

tests/epics/test_motor.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ async def test_valid_prepare_velocity(sim_motor: motor.Motor):
195195
[
196196
(1, 10, 0, 10, 30, -4.999), # Goes below lower_limit, +ve direction
197197
(1, 10, 0, 10, 14.99, -10), # Goes above upper_limit, +ve direction
198-
(1, -10, 10, 0, -30, -9.999), # Goes below lower_limit, -ve direction
199-
(1, -10, 10, 0, 14.99, -10), # Goes above upper_limit, -ve direction
198+
(1, 10, 10, 0, -30, -9.999), # Goes below lower_limit, -ve direction
199+
(1, 10, 10, 0, 14.99, -10), # Goes above upper_limit, -ve direction
200200
],
201201
)
202202
async def test_prepare_motor_path_errors(
@@ -231,6 +231,18 @@ async def test_prepare_motor_path(sim_motor: motor.Motor):
231231
== -5
232232
)
233233
assert sim_motor._fly_completed_position == 15
234+
fly_info = motor.FlyMotorInfo(
235+
start_position=12,
236+
end_position=2,
237+
time_for_move=1,
238+
)
239+
assert (
240+
await sim_motor._prepare_motor_path(
241+
10, fly_info.start_position, fly_info.end_position
242+
)
243+
== 17
244+
)
245+
assert sim_motor._fly_completed_position == -3
234246

235247

236248
@pytest.mark.parametrize(
@@ -244,7 +256,7 @@ async def test_prepare(
244256
sim_motor: motor.Motor, target_position: float, expected_velocity: float
245257
):
246258
set_mock_value(sim_motor.acceleration_time, 1)
247-
set_mock_value(sim_motor.low_limit_travel, -10)
259+
set_mock_value(sim_motor.low_limit_travel, -15)
248260
set_mock_value(sim_motor.high_limit_travel, 20)
249261
set_mock_value(sim_motor.max_velocity, 10)
250262
fake_set_signal = soft_signal_rw(float)

0 commit comments

Comments
 (0)