From 811822f9d7588648552715640de6b47230031bbe Mon Sep 17 00:00:00 2001 From: Bryn <31349775+8ryn@users.noreply.github.com> Date: Wed, 5 Jul 2023 17:53:07 +0100 Subject: [PATCH 1/3] Added step time functions --- src/tomoscan/ophyd_inter_setup.py | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/tomoscan/ophyd_inter_setup.py b/src/tomoscan/ophyd_inter_setup.py index 475c37a..5711cd1 100644 --- a/src/tomoscan/ophyd_inter_setup.py +++ b/src/tomoscan/ophyd_inter_setup.py @@ -16,10 +16,51 @@ from bluesky.plan_stubs import mv import bluesky.plan_stubs as bps +import math + from bluesky.callbacks.best_effort import BestEffortCallback from databroker import Broker +def stepTime(dist: float, accl: float, vel: float, add_time=0.0) -> float: + """ + Estimates step time of motor + + Parameters: + dist (float): Step distance + accl (float): Time to accelerate to target velocity + vel (float): Target velocity + add_time (float): Optional additional time to add to step + + Returns: + float: Time to travel step distance + """ + if vel * accl < dist: # Reaches target velocity, velocity is trapesium + return accl + dist / vel + add_time + else: + return 2 * math.sqrt(dist * accl / vel) + add_time + + +def motorStepTime( + motor: EpicsMotor, start: float, stop: float, steps: int, add_time=0.0 +) -> float: + """ + Estimates step time of motor in scan + + Parameters: + motor (EpicsMotor): motor being moved + start (float): motor start positon + stop (float): motor end position + steps (int): number of steps in scan + add_time (float): Optional additional time to add to step + + Returns: + float: Time to travel step distance + """ + step_size = abs((stop - start) / (steps - 1)) + return stepTime(step_size, motor.acceleration.get(), motor.velocity.get(), add_time) + + class MyHDF5Plugin(FileStoreHDF5IterativeWrite, HDF5Plugin_V34): ... From 61f536c7a99568f8d04c45c4540a18bb51822e60 Mon Sep 17 00:00:00 2001 From: Bryn <31349775+8ryn@users.noreply.github.com> Date: Wed, 23 Aug 2023 12:12:15 +0100 Subject: [PATCH 2/3] Addition of logging min motor step time for passive scan --- src/tomoscan/ophyd_inter_setup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tomoscan/ophyd_inter_setup.py b/src/tomoscan/ophyd_inter_setup.py index 68bc967..ebaf0c0 100644 --- a/src/tomoscan/ophyd_inter_setup.py +++ b/src/tomoscan/ophyd_inter_setup.py @@ -1,5 +1,6 @@ # Designed to be used with iocs and simulators all running in docker compose +import logging import math import time as ttime @@ -127,6 +128,13 @@ def pulse_sync(detectors, motor, laser, start, stop, steps): # Custom plan to move motor based on detector status # designed for when detector is being triggered outside of bluesky def passive_scan(detectors, motor, start, stop, steps, adStatus, pulse_ID): + min_step_time = motorStepTime(motor, start, stop, steps) + logging.info( + "Minimum motor step time is %f. If this is greater than or close to the laser \ +period, multiple frames may be captured at one motor position.", + min_step_time, + ) + step_size = (stop - start) / (steps - 1) yield from mv(motor, start) # Move motor to starting position since may take time @@ -182,7 +190,6 @@ def passive_scan(detectors, motor, start, stop, steps, adStatus, pulse_ID): # Insert all metadata/data captured into the catalog. RE.subscribe(catalog.v1.insert) - # Examples of how to run both scans: # uids = RE(pulse_sync([det], motor1, laser1, -10, 10, 11)) # uids = RE(passive_scan([det], motor1, -10, 10, 11, adStatus , pulse_ID)) From f975b4cc934e90d4bbe5f50fba3ac4d9a8bd483d Mon Sep 17 00:00:00 2001 From: Bryn <31349775+8ryn@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:48:00 +0100 Subject: [PATCH 3/3] Correction of logging text --- src/tomoscan/ophyd_inter_setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tomoscan/ophyd_inter_setup.py b/src/tomoscan/ophyd_inter_setup.py index ebaf0c0..7c38349 100644 --- a/src/tomoscan/ophyd_inter_setup.py +++ b/src/tomoscan/ophyd_inter_setup.py @@ -131,7 +131,7 @@ def passive_scan(detectors, motor, start, stop, steps, adStatus, pulse_ID): min_step_time = motorStepTime(motor, start, stop, steps) logging.info( "Minimum motor step time is %f. If this is greater than or close to the laser \ -period, multiple frames may be captured at one motor position.", +period, additional frames are likely to be captured while the motor moves.", min_step_time, )