From 11c81b887f4d0d5bcec73bf3da363aeb5ff898ca Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Mon, 7 Aug 2023 10:45:44 +0100 Subject: [PATCH] (#836) Rotation scan plan gets accl from motor --- .../experiment_plans/rotation_scan_plan.py | 11 ++--- .../tests/test_rotation_scan_plan.py | 45 +++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/artemis/experiment_plans/rotation_scan_plan.py b/src/artemis/experiment_plans/rotation_scan_plan.py index 1692249f7..280a480bb 100644 --- a/src/artemis/experiment_plans/rotation_scan_plan.py +++ b/src/artemis/experiment_plans/rotation_scan_plan.py @@ -52,7 +52,8 @@ def create_devices() -> dict[str, Device]: DEFAULT_DIRECTION = RotationDirection.NEGATIVE DEFAULT_MAX_VELOCITY = 120 -TIME_TO_VELOCITY_S = 0.15 +# Use a slightly larger time to accceleration than EPICS as it's better to be cautious +ACCELERATION_MARGIN = 1.5 def setup_sample_environment( @@ -180,12 +181,12 @@ def rotation_scan_plan( speed_for_rotation_deg_s = image_width_deg / exposure_time_s LOGGER.info(f"calculated speed: {speed_for_rotation_deg_s} deg/s") - # TODO get this from epics instead of hardcoded - time to velocity - # https://github.com/DiamondLightSource/python-artemis/issues/836 - acceleration_offset = TIME_TO_VELOCITY_S * speed_for_rotation_deg_s + motor_time_to_speed = yield from bps.rd(smargon.omega.acceleration) + motor_time_to_speed *= ACCELERATION_MARGIN + acceleration_offset = motor_time_to_speed * speed_for_rotation_deg_s LOGGER.info( f"calculated rotation offset for acceleration: at {speed_for_rotation_deg_s} " - f"deg/s, to take {TIME_TO_VELOCITY_S} s = {acceleration_offset} deg" + f"deg/s, to take {motor_time_to_speed} s = {acceleration_offset} deg" ) shutter_opening_degrees = ( diff --git a/src/artemis/experiment_plans/tests/test_rotation_scan_plan.py b/src/artemis/experiment_plans/tests/test_rotation_scan_plan.py index 367c4bd29..53a993ce7 100644 --- a/src/artemis/experiment_plans/tests/test_rotation_scan_plan.py +++ b/src/artemis/experiment_plans/tests/test_rotation_scan_plan.py @@ -517,3 +517,48 @@ def test_ispyb_deposition_in_plan( assert beamsize_x == test_bs_x assert beamsize_y == test_bs_y assert exposure == test_exp_time + + +@patch( + "artemis.experiment_plans.rotation_scan_plan.move_to_start_w_buffer", autospec=True +) +def test_acceleration_offset_calculated_correctly( + mock_move_to_start: MagicMock, + RE: RunEngine, + test_rotation_params: RotationInternalParameters, + smargon: Smargon, + zebra: Zebra, + eiger: EigerDetector, + attenuator: Attenuator, + detector_motion: DetectorMotion, + backlight: Backlight, + mock_rotation_subscriptions: RotationCallbackCollection, + synchrotron: Synchrotron, + s4_slit_gaps: S4SlitGaps, + undulator: Undulator, + flux: Flux, +): + smargon.omega.acceleration.sim_put(0.2) + setup_and_run_rotation_plan_for_tests( + RE, + test_rotation_params, + smargon, + zebra, + eiger, + attenuator, + detector_motion, + backlight, + mock_rotation_subscriptions, + synchrotron, + s4_slit_gaps, + undulator, + flux, + ) + + expected_start_angle = ( + test_rotation_params.artemis_params.detector_params.omega_start + ) + + mock_move_to_start.assert_called_once_with( + smargon.omega, expected_start_angle, pytest.approx(0.3) + )