init function first version, untested

This commit is contained in:
x01dc
2025-11-18 16:43:19 +01:00
committed by x12sa
parent c7070d3cff
commit bfe84c4eff

View File

@@ -0,0 +1,114 @@
import builtins
import time
from pathlib import Path
from bec_lib import bec_logger
# Logger initialization
logger = bec_logger.logger
if builtins.__dict__.get("bec") is not None:
bec = builtins.__dict__.get("bec")
dev = builtins.__dict__.get("dev")
umv = builtins.__dict__.get("umv")
umvr = builtins.__dict__.get("umvr")
class cSAXSInitError(Exception):
pass
class cSAXSError(Exception):
pass
class cSAXSInitStagesMixin:
# Class-level mappings for axes and devices
AXIS_MAP = {c: i for i, c in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZ")}
devices = {
"xbpm3x": "A",
"xbpm3y": "B",
"sl3trxi": "C",
"sl3trxo": "D",
"sl3trxb": "E",
"sl3trxt": "F",
"fast_shutter_n1_x": "H",
"fast_shutter_o1_x": "G",
"fast_shutter_o2_x": "F",
"filter_array_1_x": "B",
"filter_array_2_x": "C",
"filter_array_3_x": "D",
"filter_array_4_x": "E",
"sl4trxi": "G",
"sl4trxo": "H",
"sl4trxb": "I",
"sl4trxt": "A",
"sl5trxi": "C",
"sl5trxo": "D",
"sl5trxb": "E",
"sl5trxt": "F",
"xbimtrx": "A",
"xbimtry": "B",
}
def __init__(self):
"""
Initializes the class. No need to pass 'dev' since it's globally available.
"""
pass # No need for 'dev' parameter anymore
def _cSAXS_smaract_stages_init(self):
"""
Initialize all Smaract stages by setting speed, finding the reference mark, and sleeping.
"""
for dev_name, axis_letter in self.devices.items():
ch = self.AXIS_MAP[axis_letter] # Get the channel number for the axis
d = getattr(dev, dev_name) # Access the device instance using `getattr`
try:
# Set the speed (this is an example, adjust as needed)
print(f"Setting speed for {dev_name} (axis {ch})...")
d.controller.set_closed_loop_move_speed(ch, 1) # Example speed value (1)
# Find the reference mark for the axis
print(f"Finding reference mark for {dev_name} (axis {ch})...")
d.controller.find_reference_mark(ch, 0, 1000, 1) # Example reference find parameters
# Sleep after the operation
print(f"Sleeping for 0.1s after initializing {dev_name} (axis {ch})...")
time.sleep(0.1)
except AttributeError:
print(f"Device {dev_name} does not have a controller or method to initialize.")
except Exception as e:
print(f"Error initializing device {dev_name} (axis {ch}): {e}")
def _cSAXS_smaract_stages_check_all_referenced(self):
"""
Check if all axes of the devices are referenced.
"""
for dev_name, axis_letter in self.devices.items():
ch = self.AXIS_MAP[axis_letter] # Get the channel number for the axis
d = getattr(dev, dev_name) # Access the device instance using `getattr`
try:
# Check if the axis is referenced on the device controller
if not d.controller.axis_is_referenced(ch):
print(f"Device {dev_name} (axis {ch}) is NOT referenced.")
else:
print(f"Device {dev_name} (axis {ch}) is referenced.")
except AttributeError:
print(f"Device {dev_name} does not have a controller or axis_is_referenced method.")
except Exception as e:
print(f"Error checking device {dev_name} (axis {ch}): {e}")
# Usage example:
# Assuming `dev` is a globally available device manager containing all the device instances
# Create an instance of the mixin class
#cSAXS_init = cSAXSInitStagesMixin()
# To initialize all stages:
#cSAXS_init._cSAXS_smaract_stages_init()
# To check if all axes are referenced:
#cSAXS_init._cSAXS_smaract_stages_check_all_referenced()