From 27a67b5a1f0655a79e22f9335198640e9fe13e8b Mon Sep 17 00:00:00 2001 From: x12sa Date: Tue, 3 Nov 2026 12:55:44 +0100 Subject: [PATCH] feat(aerotech): settle_time 0.3 s default, trigger calibration per settle time At the beamline 0.15 s settle left a forward / backward offset of +18 .. +28 um at 20 mm/s that changed between repeats (oscillation after the ramp); with 0.3 s it is -2 .. -5 um and reproducible, at ~0.22 s more per line. settle_time and minimal_run_up stay options. Calibration entries now carry settle_time (and optionally minimal_run_up); a scan only uses the entries of its own settle time and run-up mode, so a table measured with one settling is never applied to another. The printed entry includes settle_time. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017NrH3poJsYBCTVq2Y9fuHZ --- csaxs_bec/devices/aerotech/README.md | 8 ++- .../scans/scans_v4/aerotech_cont_grid.py | 70 ++++++++++++------- docs/developer/aerotech_stages.md | 54 ++++++++------ .../saxs/aerotech_stages/aerotech_stages.md | 66 ++++++++++------- .../test_aerotech_cont_grid_scan.py | 49 ++++++++++--- 5 files changed, 163 insertions(+), 84 deletions(-) diff --git a/csaxs_bec/devices/aerotech/README.md b/csaxs_bec/devices/aerotech/README.md index ac20b489..0862454d 100644 --- a/csaxs_bec/devices/aerotech/README.md +++ b/csaxs_bec/devices/aerotech/README.md @@ -59,7 +59,7 @@ Documentation: A3200 6.04.004 help (`A3200.chm`, topic "ASCII Command Interface" ```python scans.aerotech_cont_grid(dev.aerox, 0, 1, 0.01, dev.aeroy, 0, 1, 0.1, exp_time=0.01, - trigger_source="ddg", settle_time=0.15) + trigger_source="ddg", settle_time=0.3) ``` - fast axis X moves continuously at `fast_step_size / exp_time`, the step axis Y steps between @@ -95,8 +95,10 @@ scans.aerotech_cont_grid(dev.aerox, 0, 1, 0.01, dev.aeroy, 0, 1, 0.1, exp_time=0 output (not tested). The PandA has the same choice as device config `trigger_edge` (default `"rising"`, opto wiring). - run-up / run-out = twice the ramp distance `v^2 / (2 * acceleration)` + `v * settle_time` - (default 0.15 s, measured 2026-10-28: the following error needs ~100-200 ms after the - ramp at 1 mm/s / 10 mm/s^2). In a snake the run-out of a line is the run-up of the next. + (default 0.3 s since 2026-11-03, was 0.15 s; measured 2026-10-28: the following error + needs ~100-200 ms after the ramp at 1 mm/s / 10 mm/s^2; at 20 mm/s 0.15 s left a + forward / backward offset that changed between repeats, see the trigger calibration in + `docs/developer/aerotech_stages.md`). In a snake the run-out of a line is the run-up of the next. - at the turnarounds X does not wait for In Position (`wait_in_position` signal off during the scan); X reaches 1 um within ~60 ms but 10 nm only after 0.5-2 s - positions are always captured: device `aerocapture` (must be enabled) latches the diff --git a/csaxs_bec/scans/scans_v4/aerotech_cont_grid.py b/csaxs_bec/scans/scans_v4/aerotech_cont_grid.py index 6d61d26a..d7c3ffe6 100644 --- a/csaxs_bec/scans/scans_v4/aerotech_cont_grid.py +++ b/csaxs_bec/scans/scans_v4/aerotech_cont_grid.py @@ -60,17 +60,22 @@ centres of the fast axis (deviation from the nominal cell centres per direction, backward - forward offset and its slope along the line) and of the line times. Trigger calibration: in a snake the backward exposure centres are offset from the forward -ones, by an amount that depends on the scan velocity (DDG1 at the beamline, 2026-11-03: -backward - forward +2 um at 2 mm/s, +19 um at 10 mm/s, +26 um at 20 mm/s, -9 um at -40 mm/s; independent of exp_time within the scatter). With trigger_calibration=True the -scan shifts the trigger positions by the calibrated offset h (half of backward - forward): +ones, by an amount that depends on the scan velocity and the settling (DDG1 at the +beamline, 2026-11-03, backward - forward, independent of exp_time within the scatter): +with settle_time 0.15 s +2 / +19 / +26 / -9 um at 2 / 10 / 20 / 40 mm/s, at 20 mm/s +varying by 10 um between repeats (the oscillation after the ramp has not decayed); with +0.3 s -3 / -8 / -3 / -1 um, at 20 mm/s within 3 um. With trigger_calibration=True the scan +shifts the trigger positions by the calibrated offset h (half of backward - forward): trigger_low by +h, trigger_high by -h, so that the centres of both directions are on the same cells. h comes from the table userParameter "trigger_calibration" of the fast axis -(device config, a list of {velocity, offset [um]}): linear between the calibrated -velocities, proportional to the velocity below the lowest one, no correction above the -highest one. The statistics at the end show the applied offset and the table entry this -scan measured (applied + half of the remaining backward - forward), for new or better -calibration points; the applied offset is stored in the scan info (trigger_offset). +(device config, a list of {velocity, settle_time, offset [um]}, optionally +minimal_run_up: true): only entries of the scan's settle_time and run-up mode, linear +between their velocities, proportional to the velocity below the lowest one, no +correction above the highest one or without entries. The statistics at the end show the +applied offset and the table entry this scan measured (applied + half of the remaining +backward - forward); the trigger shift moves backward - forward by about 1.15 x 2h, so +take new entries from scans with the calibration applied. The applied offset is stored in +the scan info (trigger_offset). Run-up / run-out of each line: twice the ramp distance v^2 / (2 * acceleration) + v * settle_time beyond the trigger positions. The whole range including run-up / run-out is @@ -85,9 +90,11 @@ and the step axis starts; the next line starts when both have arrived. minimal_run_up=True reduces the run-up / run-out to the ramp distance alone (no margin, no settle_time; at least MIN_RUN_UP = 0.01 so the axis never turns at a PSO window edge), for data analysis that works with unevenly spaced (captured) positions. -settle_time stays 0.15 s also at high speed: at 20 mm/s / 500 mm/s^2 shorter values -(0.08 / 0.04 / 0.02 / 0 s) gave backward - forward offsets of -24 / +10 / +4.5 / -21 um, -a ~10 Hz oscillation after the ramp that decays within ~0.15 s (measured 2026-10-29). +settle_time is 0.3 s by default: at 20 mm/s / 500 mm/s^2 shorter values (0.08 / 0.04 / +0.02 / 0 s) gave backward - forward offsets of -24 / +10 / +4.5 / -21 um, a ~10 Hz +oscillation after the ramp (measured 2026-10-29); at the beamline (2026-11-03) 0.15 s +still left +18 .. +28 um at 20 mm/s, different in every repeat, 0.3 s -2 .. -5 um. 0.3 s +costs ~0.22-0.28 s per line compared with 0.15 s. Scan procedure: - prepare_scan @@ -137,14 +144,23 @@ DDG_EXT_FALLING_EDGE = 2 DDG_SINGLE_SHOT = 5 -def interpolate_trigger_offset(table: list[dict], velocity: float) -> float | None: +def interpolate_trigger_offset( + table: list[dict], velocity: float, settle_time: float, minimal_run_up: bool = False +) -> float | None: """ Trigger offset h [um] for a scan velocity from a calibration table of - {"velocity": ..., "offset": ...} entries: linear between the calibrated velocities, - proportional to the velocity below the lowest one (no offset at rest), None above the - highest one or without a table. + {"velocity": ..., "settle_time": ..., "offset": ...} entries (optionally + "minimal_run_up": True). Only the entries of the given settle_time and run-up mode are + used: linear between their velocities, proportional to the velocity below the lowest + one (no offset at rest), None above the highest one or without entries. """ - points = sorted((float(e["velocity"]), float(e["offset"])) for e in table) + points = sorted( + (float(e["velocity"]), float(e["offset"])) + for e in table + if bool(e.get("minimal_run_up", False)) == bool(minimal_run_up) + and e.get("settle_time") is not None + and np.isclose(float(e["settle_time"]), settle_time) + ) if not points: return None velocities, offsets = zip(*points) @@ -233,7 +249,7 @@ class AerotechContGrid(ScanBase): trigger_edge: str = "rising", trigger_device: str | None = None, shutter_delay: float | None = None, - settle_time: float = 0.15, + settle_time: float = 0.3, minimal_run_up: bool = False, capture_device: str = "aerocapture", trigger_calibration: bool = True, @@ -259,10 +275,10 @@ class AerotechContGrid(ScanBase): trigger_edge (str): DDG1 external trigger edge, "rising" (opto output, J7-6/7) or "falling" (open collector / differential output). Default is "rising". trigger_device (str | None): Name of the PandaLineTrigger device for trigger_source="panda"; ignored otherwise. Default is None ("pandatrig"). shutter_delay (float | None): Delay from the line trigger to the first exposure (time for the shutter to open) in s. Default: the value of the trigger hardware (DDG1 / PandA shutter-to-open delay, 8 ms), 0 without trigger hardware. With "ddg" a given value is set on DDG1 for this scan and restored afterwards. - settle_time (float): Run-up at constant velocity before the trigger position, in s. Default is 0.15. + settle_time (float): Run-up at constant velocity before the trigger position, in s; the trigger calibration is per settle_time. Default is 0.3. minimal_run_up (bool): Run-up / run-out only the ramp distance v^2 / (2 * acceleration), at least 0.01, without the 2x margin and settle_time: faster lines, but the exposures start right after the ramp while the fast axis may still oscillate, so the captured positions are less evenly spaced. Default is False. capture_device (str): Name of the A3200PositionCapture device (always used). Default is "aerocapture". - trigger_calibration (bool): Shift the trigger positions by the calibrated offset of the fast axis for the scan velocity, so that forward and backward exposure centres are on the same cells (userParameter "trigger_calibration"). False for training scans of new calibration points. Default is True. + trigger_calibration (bool): Shift the trigger positions by the calibrated offset of the fast axis for the scan velocity, settle_time and run-up mode, so that forward and backward exposure centres are on the same cells (userParameter "trigger_calibration"). False for training scans of new calibration points. Default is True. Returns: ScanReport @@ -665,11 +681,15 @@ class AerotechContGrid(ScanBase): table = ( parameters.get(TRIGGER_CALIBRATION_PARAMETER) if isinstance(parameters, dict) else None ) - offset = interpolate_trigger_offset(table or [], velocity) + offset = interpolate_trigger_offset( + table or [], velocity, self.settle_time, self.minimal_run_up + ) if offset is None: logger.warning( f"aerotech_cont_grid: no trigger calibration of {self.fast_axis.name} for" - f" {velocity:g} / s, forward and backward exposures are not aligned." + f" {velocity:g} / s, settle_time {self.settle_time:g} s" + f"{', minimal run-up' if self.minimal_run_up else ''}: forward and backward" + " exposures are not aligned." ) return offset @@ -681,12 +701,14 @@ class AerotechContGrid(ScanBase): if applied is not None: state = f"offset {applied:+.2f} um applied" elif self.trigger_calibration: - state = "no calibration for this velocity" + state = "no calibration for this velocity / settle_time" else: state = "off" + mode = ", minimal_run_up: true" if self.minimal_run_up else "" return ( f" trigger calibration [um]: {state}; this scan measured" - f" {{velocity: {line['target_velocity']:g}, offset: {measured:.2f}}}" + f" {{velocity: {line['target_velocity']:g}, settle_time: {self.settle_time:g}," + f" offset: {measured:.2f}{mode}}}" ) def _trigger_window(self, line_index: int) -> tuple[float, float]: diff --git a/docs/developer/aerotech_stages.md b/docs/developer/aerotech_stages.md index c1d12019..9ed09dd9 100644 --- a/docs/developer/aerotech_stages.md +++ b/docs/developer/aerotech_stages.md @@ -99,10 +99,12 @@ trigger_high = exposure_end + v * shutter_delay - v * readout_time / 2 (backwa ### Run-up, settling and limits Run-up / run-out per side: `2 * v^2 / (2 * acceleration) + v * settle_time`. In a -snake the run-out of a line is the run-up of the next. `settle_time` stays 0.15 s: at -20 mm/s and 500 mm/s^2 there is a ~10 Hz oscillation after the ramp that decays within -~0.15 s; shorter values (0.08 / 0.04 / 0.02 / 0 s) gave backward minus forward offsets -of -24 / +10 / +4.5 / -21 um (2026-10-29). +snake the run-out of a line is the run-up of the next. `settle_time` is 0.3 s by +default (was 0.15 s until 2026-11-03): at 20 mm/s and 500 mm/s^2 there is a ~10 Hz +oscillation after the ramp; shorter values (0.08 / 0.04 / 0.02 / 0 s) gave backward +minus forward offsets of -24 / +10 / +4.5 / -21 um (2026-10-29), and at the beamline +0.15 s left +18 .. +28 um at 20 mm/s, different in every repeat, 0.3 s -2 .. -5 um +(2026-11-03). 0.3 s costs ~0.22-0.28 s per line. `prepare_scan` checks the whole travel range including run-up, and the Y range, against the soft limits before anything moves. The message separates the scan range @@ -110,26 +112,38 @@ from the run-up so a user can see why a scan inside the limits does not fit. ### Trigger calibration -The backward exposure centres are offset from the forward ones by a velocity -dependent amount (DDG1 at the beamline, 2026-11-03, scans 4897-4917: backward minus -forward +0.9 / +2.1 / +9.3 / +18.6 / +25.7 / +3.0 / -8.8 um at 1 / 2 / 4 / 10 / 20 / 30 / -40 mm/s; 5 vs 20 ms exposure time the same within the scatter; repeats within 0.1 um -at 1 mm/s and 0.2 um at 40 mm/s). It is not a constant delay: about 0.5-1 ms up to -20 mm/s, then it falls and changes sign. With the PandA (2026-10-29) it was below 1 um at -20 mm/s. +The backward exposure centres are offset from the forward ones by an amount that +depends on the velocity and the settling (DDG1 at the beamline, 2026-11-03, backward +minus forward; 5 vs 20 ms exposure time the same within the scatter): + +| v [mm/s] | 1 | 2 | 4 | 10 | 20 | 30 | 40 | +|---|---|---|---|---|---|---|---| +| settle 0.15 s | +0.9 | +2.1 | +9.3 | +18.6 | +18 .. +28 | +3.0 | -8.8 | +| settle 0.3 s | | -3.2 | -5.8 | -8.2 | -4.6 / -1.7 | -1.1 / -1.6 | -0.7 | + +With 0.15 s it repeats within 0.5 um up to 10 mm/s and at 40 mm/s, but not at 20 mm/s: +the oscillation after the ramp has not decayed. It is not a constant delay (about +0.5-1 ms up to 20 mm/s at 0.15 s, then it changes sign). With the PandA (2026-10-29) it +was below 1 um at 20 mm/s. `trigger_calibration=True` (default) shifts `trigger_low` by `+h` and `trigger_high` by `-h` (later in the direction of motion), with `h` = half of backward minus forward from the table `userParameter.trigger_calibration` of the fast axis -(`interpolate_trigger_offset`: linear between the points, proportional to the velocity -below the lowest one, `None` above the highest one). The device config is read from -`_config` of the fast axis (the scan server's devices are `DeviceBaseWithConfig`, -whose `user_parameter` reads the same). The applied `h` is in the scan info -(`trigger_offset`, with `scan_velocity`); the statistics print the entry the scan -measured, `h_applied + (backward - forward) / 2`. Only the mean offset per direction is -corrected; the variation along the line at high velocity (oscillation after the ramp) -remains. The calibration is for the configured acceleration (500 mm/s^2) and -`settle_time` 0.15 s. +(`interpolate_trigger_offset`): only the entries of the scan's `settle_time` (and +`minimal_run_up: true` entries only with `minimal_run_up`), linear between their +velocities, proportional to the velocity below the lowest one, `None` above the +highest one or without entries. The device config is read from `_config` of the fast +axis (the scan server's devices are `DeviceBaseWithConfig`, whose `user_parameter` +reads the same). The applied `h` is in the scan info (`trigger_offset`, with +`scan_velocity`); the statistics print the entry the scan measured, +`h_applied + (backward - forward) / 2`. + +The shift acts slightly more than 1:1: backward minus forward changed by about +1.15 x 2h at 8 and 10 mm/s. New entries are therefore taken from scans with the +calibration applied, or as the zero crossing of two calibrated scans. Only the mean +offset per direction is corrected; the variation along the line (rms 3-6 um per +direction from 10 mm/s on, peak-to-peak 13-16 um) does not change with the settle time +or the trigger shift. The calibration is for the configured acceleration (500 mm/s^2). ### Step during the run-out diff --git a/docs/user/saxs/aerotech_stages/aerotech_stages.md b/docs/user/saxs/aerotech_stages/aerotech_stages.md index f5d22ede..6057732f 100644 --- a/docs/user/saxs/aerotech_stages/aerotech_stages.md +++ b/docs/user/saxs/aerotech_stages/aerotech_stages.md @@ -71,7 +71,7 @@ scans.aerotech_cont_grid( | `exp_time` | exposure time per cell in s; the X velocity is `fast_step_size / exp_time` | | `relative` | `True`: positions are offsets from the current X / Y position, and both axes return there after the scan | | `trigger_source` | `"ddg"` (default, beamline timing) | -| `settle_time` | constant velocity time before the first exposure of a line, default 0.15 s (leave it) | +| `settle_time` | constant velocity time before the first exposure of a line, default 0.3 s; 0.15 s is faster but less precise at high velocity (see below) | | `shutter_delay` | time from the line trigger to the first exposure, for the shutter to open. Default: the value of DDG1 (8 ms); a given value is set on DDG1 for this scan only | | `minimal_run_up` | `True`: run-up only the acceleration distance (at least 10 um), no settling. Faster lines, but the exposures are less evenly spaced; use the captured positions. Default `False` | | `trigger_calibration` | `True` (default): forward and backward lines are aligned with the calibration of `aerox` (see below). `False` only for training scans of new calibration points | @@ -101,42 +101,54 @@ colours alternate in Y by one line spacing. ### Forward and backward alignment (trigger calibration) Without correction the backward lines are offset from the forward lines along X, by -an amount that depends on the scan velocity (measured 2026-11-03 at the beamline, -backward minus forward): +an amount that depends on the scan velocity and on the settle time (measured +2026-11-03 at the beamline, backward minus forward in um): -| Velocity [mm/s] | 0.5 | 1 | 2 | 4 | 8 | 10 | 20 | 30 | 40 | -|---|---|---|---|---|---|---|---|---|---| -| Offset [um] | -0.6 | +0.9 | +2.1 | +9.3 | +15.8 | +18.6 | +25.7 | +3.0 | -8.8 | +| Velocity [mm/s] | 2 | 4 | 10 | 20 | 30 | 40 | +|---|---|---|---|---|---|---| +| `settle_time=0.3` (default) | -3.2 | -5.8 | -8.2 | -4.6 / -1.7 | -1.1 / -1.6 | -0.7 | +| `settle_time=0.15` | +2.1 | +9.3 | +18.6 | +18 .. +28 | +3.0 | -8.8 | -It does not depend on the exposure time and is reproducible. The scan therefore moves -the trigger positions of both directions by half of it, so that forward and backward -exposures land on the same cells. The calibration is a table in the device config of -`aerox` (`userParameter` `trigger_calibration`, velocity and offset), interpolated -between the calibrated velocities. Above 40 mm/s there is no calibration: the scan -runs uncorrected and says so in its summary. +It does not depend on the exposure time. With 0.15 s the offset is larger and, from +20 mm/s on, different in every repeat: X still oscillates after the acceleration when +the exposures start. With 0.3 s it is small and reproducible; this costs about 0.22 s +more per line (about 27 % on fast scans, negligible on slow high-resolution scans). + +The scan moves the trigger positions of both directions by half of the offset, so that +forward and backward exposures land on the same cells. The calibration is a table in +the device config of `aerox` (`userParameter` `trigger_calibration`: velocity, settle +time, offset), with entries for 0.3 s and 0.15 s. A scan uses the entries of its own +`settle_time`, interpolated between the calibrated velocities. Without entries for its +settle time, with `minimal_run_up=True`, or above 40 mm/s the scan runs uncorrected and +says so in its summary. The summary of each scan shows the applied offset and the table entry the scan measured, for example: ```text -trigger calibration [um]: offset +9.29 um applied; this scan measured {velocity: 10, offset: 9.41} +trigger calibration [um]: offset -4.09 um applied; this scan measured {velocity: 10, settle_time: 0.3, offset: -3.80} ``` A calibrated scan should show a backward - forward mean of a few um at most. What -remains along a line at high velocity (rms per direction 4-7 um from 10 mm/s on) is -the motion of X and cannot be corrected by the trigger. +remains along a line at high velocity (rms per direction 3-6 um from 10 mm/s on) is +the motion of X and cannot be corrected by the trigger or the settle time. -**New calibration point** (other acceleration, settle time, or a velocity outside the -table): run a short scan with `trigger_calibration=False` at that velocity, for example -X +-1 mm, 6 lines: +**Other settings:** `settle_time` and `minimal_run_up` stay available as options. For a +faster scan use `settle_time=0.15` (calibrated, but at 20-30 mm/s only to about ++-5 um). For any other settle time or `minimal_run_up=True` there is no calibration: +the lines are offset as in the table above. + +**New calibration point** (other settle time, acceleration, or velocity): run a short +scan at that velocity and settle time, for example X +-1 mm, 6 lines: ```python scans.aerotech_cont_grid(dev.aerox, -1.0, 1.0, 0.1, dev.aeroy, -0.1, 0.1, 0.04, exp_time=0.005, relative=True, trigger_calibration=False) # 20 mm/s ``` -and add the printed `{velocity: ..., offset: ...}` to `trigger_calibration` of `aerox` -in `sastt_aerotech.yaml` (ask the beamline staff to commit it). For a quick test without -a config change: `dev.aerox.update_user_parameter({...})`. +and add the printed `{velocity: ..., settle_time: ..., offset: ...}` to +`trigger_calibration` of `aerox` in `sastt_aerotech.yaml` (ask the beamline staff to +commit it). Then repeat the scan with the calibration on and take the entry it prints: +the trigger shift acts slightly more than 1:1, so the second value is the better one. ### Examples @@ -164,12 +176,12 @@ scans.aerotech_cont_grid(dev.aerox, -1.75, 1.75, 0.01, dev.aeroy, -1.5, 1.5, 0.0 ### Run-up and soft limits To pass through the field of view at constant velocity, X travels beyond it on both -sides: twice the acceleration distance `v^2 / (2 * 500 mm/s^2)` plus `v * 0.15 s` to -settle. The run-up per side is +sides: twice the acceleration distance `v^2 / (2 * 500 mm/s^2)` plus `v * settle_time` +(0.3 s) to settle. The run-up per side is -| Scan velocity | 0.5 mm/s | 2 mm/s | 20 mm/s | -|---------------|----------|--------|---------| -| Run-up per side | 0.08 mm | 0.31 mm | 3.8 mm | +| Scan velocity | 0.5 mm/s | 2 mm/s | 20 mm/s | 40 mm/s | +|---------------|----------|--------|---------|---------| +| Run-up per side | 0.15 mm | 0.61 mm | 6.8 mm | 15.2 mm | Before anything moves, the scan checks the whole range including the run-up against the soft limits. If it does not fit, the scan stops with a message that says by how @@ -177,7 +189,7 @@ much and on which side, for example ```text The scan range of aerox 146.5000 .. 150.0000 is within the limits, but aerox needs -3.8400 extra travel on each side to accelerate to the scan velocity 20 / s and settle +6.9580 extra travel on each side to accelerate to the scan velocity 20 / s and settle ... ``` diff --git a/tests/tests_scans/test_aerotech_cont_grid_scan.py b/tests/tests_scans/test_aerotech_cont_grid_scan.py index b8bcae7d..6fcc475a 100644 --- a/tests/tests_scans/test_aerotech_cont_grid_scan.py +++ b/tests/tests_scans/test_aerotech_cont_grid_scan.py @@ -206,10 +206,21 @@ def test_velocity_above_configured_velocity_aborts(v4_scan_assembler, device_man def test_scan_faster_than_move_velocity_restores_move_velocity(v4_scan_assembler, device_manager): - # 20 mm/s scan, move velocity 10 mm/s, max_scan_velocity 50 mm/s + # 20 mm/s scan, move velocity 10 mm/s, max_scan_velocity 50 mm/s; settle_time 0.15 s + # so that the run-up fits the +-10 limits at 100 mm/s^2 _add_devices(device_manager, max_scan_velocity=50.0) scan = v4_scan_assembler( - "aerotech_cont_grid", "aerox", -1.0, 1.0, 0.1, "aeroy", -2.0, 2.0, 2, exp_time=0.005 + "aerotech_cont_grid", + "aerox", + -1.0, + 1.0, + 0.1, + "aeroy", + -2.0, + 2.0, + 2, + exp_time=0.005, + settle_time=0.15, ) scan.prepare_scan() assert scan._line["target_velocity"] == pytest.approx(20.0) @@ -222,7 +233,7 @@ def test_scan_faster_than_move_velocity_restores_move_velocity(v4_scan_assembler def test_run_up_outside_limits_aborts(v4_scan_assembler, device_manager): - # 20 mm/s at 100 mm/s^2: 2 * 2 mm ramp + 3 mm settle run-up, beyond the +-10 limits + # 20 mm/s at 100 mm/s^2: 2 * 2 mm ramp + 6 mm settle run-up, beyond the +-10 limits _add_devices(device_manager, max_scan_velocity=50.0) scan = v4_scan_assembler( "aerotech_cont_grid", "aerox", -4.0, 4.0, 0.1, "aeroy", -2.0, 2.0, 2, exp_time=0.005 @@ -691,9 +702,12 @@ def test_progress_bar_from_the_capture_without_mcs(v4_scan_assembler, device_man CALIBRATION = [ - {"velocity": 10.0, "offset": 4.0}, - {"velocity": 2.0, "offset": 1.0}, - {"velocity": 20.0, "offset": -2.0}, + {"velocity": 10.0, "settle_time": 0.3, "offset": 4.0}, + {"velocity": 2.0, "settle_time": 0.3, "offset": 1.0}, + {"velocity": 20.0, "settle_time": 0.3, "offset": -2.0}, + # other settling and run-up mode: never mixed into the 0.3 s entries + {"velocity": 5.0, "settle_time": 0.15, "offset": 50.0}, + {"velocity": 5.0, "settle_time": 0.3, "minimal_run_up": True, "offset": 60.0}, ] @@ -711,7 +725,7 @@ CALIBRATION = [ ], ) def test_interpolate_trigger_offset(velocity, expected): - offset = interpolate_trigger_offset(CALIBRATION, velocity) + offset = interpolate_trigger_offset(CALIBRATION, velocity, 0.3) if expected is None: assert offset is None else: @@ -719,7 +733,20 @@ def test_interpolate_trigger_offset(velocity, expected): def test_interpolate_trigger_offset_without_table(): - assert interpolate_trigger_offset([], 5.0) is None + assert interpolate_trigger_offset([], 5.0, 0.3) is None + + +def test_interpolate_trigger_offset_per_settle_time_and_run_up_mode(): + assert interpolate_trigger_offset(CALIBRATION, 5.0, 0.15) == pytest.approx(50.0) + assert interpolate_trigger_offset(CALIBRATION, 5.0, 0.3, minimal_run_up=True) == 60.0 + assert interpolate_trigger_offset(CALIBRATION, 5.0, 0.2) is None + # entries without settle_time are not used + assert interpolate_trigger_offset([{"velocity": 5.0, "offset": 1.0}], 5.0, 0.3) is None + + +def test_default_settle_time_is_0p3(v4_scan_assembler, device_manager): + scan = _assemble(v4_scan_assembler, device_manager) + assert scan.settle_time == 0.3 def _trigger_positions(v4_scan_assembler, device_manager, **kwargs): @@ -771,7 +798,9 @@ def test_calibration_summary_reports_the_measured_entry(v4_scan_assembler, devic # applied 2.125 um, still +1 um backward - forward: the entry is 2.625 um summary = scan._calibration_summary(1.0) assert "offset +2.12 um applied" in summary - assert "{velocity: 5, offset: 2.62}" in summary + assert "{velocity: 5, settle_time: 0.3, offset: 2.62}" in summary scan.trigger_calibration = False scan._line["trigger_offset"] = None - assert "off; this scan measured {velocity: 5, offset: 0.50}" in scan._calibration_summary(1.0) + assert "off; this scan measured {velocity: 5, settle_time: 0.3, offset: 0.50}" in ( + scan._calibration_summary(1.0) + )