From 9d094d95c5ed199befe3ad61e22dc99505378910 Mon Sep 17 00:00:00 2001 From: Tom Kane Date: Thu, 5 Feb 2026 13:52:11 +0000 Subject: [PATCH 1/5] Improved simulated device and env variable handling --- src/fastcs_standa_mirror/__main__.py | 34 ++++++++++++++------ src/fastcs_standa_mirror/motor_controller.py | 2 +- src/fastcs_standa_mirror/utils.py | 12 +++---- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/fastcs_standa_mirror/__main__.py b/src/fastcs_standa_mirror/__main__.py index 1fee9ae..aaec29f 100644 --- a/src/fastcs_standa_mirror/__main__.py +++ b/src/fastcs_standa_mirror/__main__.py @@ -33,25 +33,39 @@ def main() -> None: version=__version__, ) parser.add_argument( - "--use-virtual", + "--sim", action="store_true", - dest="use_virtual", - help="Enable virtual mode", + dest="use_sim", + help="Use simulated device", ) parsed_args = parser.parse_args() - use_virtual = parsed_args.use_virtual + use_sim = parsed_args.use_sim - # initial varaiables setup - load_dotenv() + # Validate device URIs and PV_PREFIX only if not using simulation + if not use_sim: + load_dotenv() + + pv_prefix = os.getenv("PV_PREFIX") + print(pv_prefix) + if pv_prefix is None: + raise ValueError("PV_PREFIX environment variable must be set") + + device_pitch_uri = os.getenv("DEVICE_PITCH_URI") + device_yaw_uri = os.getenv("DEVICE_YAW_URI") + if device_pitch_uri is None or device_yaw_uri is None: + raise ValueError("DEVICE_PITCH_URI and DEVICE_YAW_URI must be set") + + else: + pv_prefix = f"MIRROR-SIM-{os.getpid()}" + logging.info(f"Simulated device PV_PREFIX -> {pv_prefix}") - pv_prefix = os.getenv("PV_PREFIX", "STANDA-MIRROR") home_positions = load_or_create_home_pos() - uris = load_devices(use_virtual=use_virtual) + uris = load_devices(use_sim=use_sim) - # epics setupo + # epics setup gui_options = EpicsGUIOptions( - output_path=Path(".") / "gui/Mirror.bob", title="Mirror Controller" + output_path=Path(".") / "bob/Mirror.bob", title="Mirror Controller" ) epics_ca = EpicsCATransport( diff --git a/src/fastcs_standa_mirror/motor_controller.py b/src/fastcs_standa_mirror/motor_controller.py index 1276e2c..649156a 100644 --- a/src/fastcs_standa_mirror/motor_controller.py +++ b/src/fastcs_standa_mirror/motor_controller.py @@ -30,7 +30,7 @@ def __init__(self, name: str, device_uri: str): self.motor = ximc.Axis(self._device_uri) self.motor.open_device() logging.info( - f"Successfully opened device\n'{self._name}' at {self._device_uri}" + f"Successfully opened device -> '{self._name}' at {self._device_uri}" ) except Exception as e: diff --git a/src/fastcs_standa_mirror/utils.py b/src/fastcs_standa_mirror/utils.py index f3ad35c..25a2dab 100644 --- a/src/fastcs_standa_mirror/utils.py +++ b/src/fastcs_standa_mirror/utils.py @@ -12,10 +12,10 @@ class DeviceNotFoundError(Exception): pass -def load_devices(use_virtual: bool) -> dict: +def load_devices(use_sim: bool) -> dict: """Load device uris for pitch and yaw controllers""" - return create_virtual_devices() if use_virtual else load_real_devices() + return create_simulated_devices() if use_sim else load_real_devices() def load_real_devices() -> dict: @@ -55,13 +55,13 @@ def load_real_devices() -> dict: return target_uris -def create_virtual_devices() -> dict: - """Create virtual devices and return uris""" - logging.info("Creating virtual standa devices") +def create_simulated_devices() -> dict: + """Create simulated devices and return uris""" + logging.info("Creating simulated standa devices") virt_dir = Path.cwd() / "virt" - device_uri_base = f"xi-emu:///{virt_dir}/virtual_motor_controller" + device_uri_base = f"xi-emu:///{virt_dir}/simulated_motor_controller" return { "pitch": f"{device_uri_base}_pitch.bin", From f836c85556b76c6622e18bac9d5562c97da17096 Mon Sep 17 00:00:00 2001 From: Tom Kane Date: Thu, 5 Feb 2026 13:52:39 +0000 Subject: [PATCH 2/5] rename gui folder to bob --- bob/Mirror.bob | 328 +++++++++++++++++++++++++++++++++++++++++++ bob/Mirror_Pitch.bob | 131 +++++++++++++++++ bob/Mirror_Yaw.bob | 131 +++++++++++++++++ 3 files changed, 590 insertions(+) create mode 100644 bob/Mirror.bob create mode 100644 bob/Mirror_Pitch.bob create mode 100644 bob/Mirror_Yaw.bob diff --git a/bob/Mirror.bob b/bob/Mirror.bob new file mode 100644 index 0000000..007eebf --- /dev/null +++ b/bob/Mirror.bob @@ -0,0 +1,328 @@ + + Mirror Controller + 0 + 0 + 406 + 413 + 4 + 4 + + Title + TITLE + Mirror Controller + 0 + 0 + 406 + 25 + + + + + + + + + true + 1 + + + OpenDisplay + + + Mirror_Pitch.bob + tab + Open Display + + + Pitch + 23 + 30 + 360 + 20 + $(actions) + + + OpenDisplay + + + Mirror_Yaw.bob + tab + Open Display + + + Yaw + 23 + 55 + 360 + 20 + $(actions) + + + Label + Stop Moving + 23 + 80 + 150 + 20 + No description provided + + + WritePV + MIRROR-SIM-3475409:StopMoving + + + $(pv_name) + 1 + $(name) + + + Stop Moving + 178 + 80 + 205 + 20 + MIRROR-SIM-3475409:StopMoving = 1 + + + Global + 5 + 105 + 396 + 81 + true + + Label + Jog Step + 0 + 0 + 150 + 20 + No description provided + + + TextEntry + MIRROR-SIM-3475409:JogStep + 155 + 0 + 100 + 20 + 1 + + + TextUpdate + MIRROR-SIM-3475409:JogStep_RBV + 260 + 0 + 100 + 20 + + + + + 1 + + + Label + Speed + 0 + 25 + 150 + 20 + No description provided + + + TextEntry + MIRROR-SIM-3475409:Speed + 155 + 25 + 100 + 20 + 1 + + + TextUpdate + MIRROR-SIM-3475409:Speed_RBV + 260 + 25 + 100 + 20 + + + + + 1 + + + + Jog + 5 + 191 + 396 + 131 + true + + Label + Down + 0 + 0 + 150 + 20 + No description provided + + + WritePV + MIRROR-SIM-3475409:Down + + + $(pv_name) + 1 + $(name) + + + Down + 155 + 0 + 205 + 20 + MIRROR-SIM-3475409:Down = 1 + + + Label + Left + 0 + 25 + 150 + 20 + No description provided + + + WritePV + MIRROR-SIM-3475409:Left + + + $(pv_name) + 1 + $(name) + + + Left + 155 + 25 + 205 + 20 + MIRROR-SIM-3475409:Left = 1 + + + Label + Right + 0 + 50 + 150 + 20 + No description provided + + + WritePV + MIRROR-SIM-3475409:Right + + + $(pv_name) + 1 + $(name) + + + Right + 155 + 50 + 205 + 20 + MIRROR-SIM-3475409:Right = 1 + + + Label + Up + 0 + 75 + 150 + 20 + No description provided + + + WritePV + MIRROR-SIM-3475409:Up + + + $(pv_name) + 1 + $(name) + + + Up + 155 + 75 + 205 + 20 + MIRROR-SIM-3475409:Up = 1 + + + + Home + 5 + 327 + 396 + 81 + true + + Label + Rehome + 0 + 0 + 150 + 20 + No description provided + + + WritePV + MIRROR-SIM-3475409:Rehome + + + $(pv_name) + 1 + $(name) + + + Rehome + 155 + 0 + 205 + 20 + MIRROR-SIM-3475409:Rehome = 1 + + + Label + Save + 0 + 25 + 150 + 20 + No description provided + + + WritePV + MIRROR-SIM-3475409:Save + + + $(pv_name) + 1 + $(name) + + + Save + 155 + 25 + 205 + 20 + MIRROR-SIM-3475409:Save = 1 + + + diff --git a/bob/Mirror_Pitch.bob b/bob/Mirror_Pitch.bob new file mode 100644 index 0000000..be53b5a --- /dev/null +++ b/bob/Mirror_Pitch.bob @@ -0,0 +1,131 @@ + + Pitch + 0 + 0 + 406 + 202 + 4 + 4 + + Title + TITLE + Pitch + 0 + 0 + 406 + 25 + + + + + + + + + true + 1 + + + Label + Stop Moving + 23 + 30 + 150 + 20 + No description provided + + + WritePV + MIRROR-SIM-3475409:Pitch:StopMoving + + + $(pv_name) + 1 + $(name) + + + Stop Moving + 178 + 30 + 205 + 20 + MIRROR-SIM-3475409:Pitch:StopMoving = 1 + + + Position + 5 + 55 + 396 + 81 + true + + Label + Current + 0 + 0 + 150 + 20 + No description provided + + + TextUpdate + MIRROR-SIM-3475409:Pitch:Current + 155 + 0 + 205 + 20 + + + + + 1 + + + Label + Home + 0 + 25 + 150 + 20 + No description provided + + + TextUpdate + MIRROR-SIM-3475409:Pitch:Home + 155 + 25 + 205 + 20 + + + + + 1 + + + + Status + 5 + 141 + 396 + 56 + true + + Label + Moving + 0 + 0 + 150 + 20 + No description provided + + + LED + MIRROR-SIM-3475409:Pitch:Moving + 247 + 0 + 20 + 20 + + + diff --git a/bob/Mirror_Yaw.bob b/bob/Mirror_Yaw.bob new file mode 100644 index 0000000..a42b9fd --- /dev/null +++ b/bob/Mirror_Yaw.bob @@ -0,0 +1,131 @@ + + Yaw + 0 + 0 + 406 + 202 + 4 + 4 + + Title + TITLE + Yaw + 0 + 0 + 406 + 25 + + + + + + + + + true + 1 + + + Label + Stop Moving + 23 + 30 + 150 + 20 + No description provided + + + WritePV + MIRROR-SIM-3475409:Yaw:StopMoving + + + $(pv_name) + 1 + $(name) + + + Stop Moving + 178 + 30 + 205 + 20 + MIRROR-SIM-3475409:Yaw:StopMoving = 1 + + + Position + 5 + 55 + 396 + 81 + true + + Label + Current + 0 + 0 + 150 + 20 + No description provided + + + TextUpdate + MIRROR-SIM-3475409:Yaw:Current + 155 + 0 + 205 + 20 + + + + + 1 + + + Label + Home + 0 + 25 + 150 + 20 + No description provided + + + TextUpdate + MIRROR-SIM-3475409:Yaw:Home + 155 + 25 + 205 + 20 + + + + + 1 + + + + Status + 5 + 141 + 396 + 56 + true + + Label + Moving + 0 + 0 + 150 + 20 + No description provided + + + LED + MIRROR-SIM-3475409:Yaw:Moving + 247 + 0 + 20 + 20 + + + From bd50b72acc2b54b409b915a517382d69f10cc265 Mon Sep 17 00:00:00 2001 From: Tom Kane Date: Thu, 5 Feb 2026 13:53:55 +0000 Subject: [PATCH 3/5] added env file example --- .env.example | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..cac3fef --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +PV_PREFIX= +DEVICE_PITCH_URI= # xi-com:///... +DEVICE_YAW_URI= # xi-com:///... From cf4412a23c28f1f9e2e4e9b302d2c9003c39cdf9 Mon Sep 17 00:00:00 2001 From: Tom Kane Date: Thu, 5 Feb 2026 14:50:55 +0000 Subject: [PATCH 4/5] remove generated bob files --- bob/Mirror.bob | 328 ------------------------------------------- bob/Mirror_Pitch.bob | 131 ----------------- bob/Mirror_Yaw.bob | 131 ----------------- 3 files changed, 590 deletions(-) delete mode 100644 bob/Mirror.bob delete mode 100644 bob/Mirror_Pitch.bob delete mode 100644 bob/Mirror_Yaw.bob diff --git a/bob/Mirror.bob b/bob/Mirror.bob deleted file mode 100644 index 007eebf..0000000 --- a/bob/Mirror.bob +++ /dev/null @@ -1,328 +0,0 @@ - - Mirror Controller - 0 - 0 - 406 - 413 - 4 - 4 - - Title - TITLE - Mirror Controller - 0 - 0 - 406 - 25 - - - - - - - - - true - 1 - - - OpenDisplay - - - Mirror_Pitch.bob - tab - Open Display - - - Pitch - 23 - 30 - 360 - 20 - $(actions) - - - OpenDisplay - - - Mirror_Yaw.bob - tab - Open Display - - - Yaw - 23 - 55 - 360 - 20 - $(actions) - - - Label - Stop Moving - 23 - 80 - 150 - 20 - No description provided - - - WritePV - MIRROR-SIM-3475409:StopMoving - - - $(pv_name) - 1 - $(name) - - - Stop Moving - 178 - 80 - 205 - 20 - MIRROR-SIM-3475409:StopMoving = 1 - - - Global - 5 - 105 - 396 - 81 - true - - Label - Jog Step - 0 - 0 - 150 - 20 - No description provided - - - TextEntry - MIRROR-SIM-3475409:JogStep - 155 - 0 - 100 - 20 - 1 - - - TextUpdate - MIRROR-SIM-3475409:JogStep_RBV - 260 - 0 - 100 - 20 - - - - - 1 - - - Label - Speed - 0 - 25 - 150 - 20 - No description provided - - - TextEntry - MIRROR-SIM-3475409:Speed - 155 - 25 - 100 - 20 - 1 - - - TextUpdate - MIRROR-SIM-3475409:Speed_RBV - 260 - 25 - 100 - 20 - - - - - 1 - - - - Jog - 5 - 191 - 396 - 131 - true - - Label - Down - 0 - 0 - 150 - 20 - No description provided - - - WritePV - MIRROR-SIM-3475409:Down - - - $(pv_name) - 1 - $(name) - - - Down - 155 - 0 - 205 - 20 - MIRROR-SIM-3475409:Down = 1 - - - Label - Left - 0 - 25 - 150 - 20 - No description provided - - - WritePV - MIRROR-SIM-3475409:Left - - - $(pv_name) - 1 - $(name) - - - Left - 155 - 25 - 205 - 20 - MIRROR-SIM-3475409:Left = 1 - - - Label - Right - 0 - 50 - 150 - 20 - No description provided - - - WritePV - MIRROR-SIM-3475409:Right - - - $(pv_name) - 1 - $(name) - - - Right - 155 - 50 - 205 - 20 - MIRROR-SIM-3475409:Right = 1 - - - Label - Up - 0 - 75 - 150 - 20 - No description provided - - - WritePV - MIRROR-SIM-3475409:Up - - - $(pv_name) - 1 - $(name) - - - Up - 155 - 75 - 205 - 20 - MIRROR-SIM-3475409:Up = 1 - - - - Home - 5 - 327 - 396 - 81 - true - - Label - Rehome - 0 - 0 - 150 - 20 - No description provided - - - WritePV - MIRROR-SIM-3475409:Rehome - - - $(pv_name) - 1 - $(name) - - - Rehome - 155 - 0 - 205 - 20 - MIRROR-SIM-3475409:Rehome = 1 - - - Label - Save - 0 - 25 - 150 - 20 - No description provided - - - WritePV - MIRROR-SIM-3475409:Save - - - $(pv_name) - 1 - $(name) - - - Save - 155 - 25 - 205 - 20 - MIRROR-SIM-3475409:Save = 1 - - - diff --git a/bob/Mirror_Pitch.bob b/bob/Mirror_Pitch.bob deleted file mode 100644 index be53b5a..0000000 --- a/bob/Mirror_Pitch.bob +++ /dev/null @@ -1,131 +0,0 @@ - - Pitch - 0 - 0 - 406 - 202 - 4 - 4 - - Title - TITLE - Pitch - 0 - 0 - 406 - 25 - - - - - - - - - true - 1 - - - Label - Stop Moving - 23 - 30 - 150 - 20 - No description provided - - - WritePV - MIRROR-SIM-3475409:Pitch:StopMoving - - - $(pv_name) - 1 - $(name) - - - Stop Moving - 178 - 30 - 205 - 20 - MIRROR-SIM-3475409:Pitch:StopMoving = 1 - - - Position - 5 - 55 - 396 - 81 - true - - Label - Current - 0 - 0 - 150 - 20 - No description provided - - - TextUpdate - MIRROR-SIM-3475409:Pitch:Current - 155 - 0 - 205 - 20 - - - - - 1 - - - Label - Home - 0 - 25 - 150 - 20 - No description provided - - - TextUpdate - MIRROR-SIM-3475409:Pitch:Home - 155 - 25 - 205 - 20 - - - - - 1 - - - - Status - 5 - 141 - 396 - 56 - true - - Label - Moving - 0 - 0 - 150 - 20 - No description provided - - - LED - MIRROR-SIM-3475409:Pitch:Moving - 247 - 0 - 20 - 20 - - - diff --git a/bob/Mirror_Yaw.bob b/bob/Mirror_Yaw.bob deleted file mode 100644 index a42b9fd..0000000 --- a/bob/Mirror_Yaw.bob +++ /dev/null @@ -1,131 +0,0 @@ - - Yaw - 0 - 0 - 406 - 202 - 4 - 4 - - Title - TITLE - Yaw - 0 - 0 - 406 - 25 - - - - - - - - - true - 1 - - - Label - Stop Moving - 23 - 30 - 150 - 20 - No description provided - - - WritePV - MIRROR-SIM-3475409:Yaw:StopMoving - - - $(pv_name) - 1 - $(name) - - - Stop Moving - 178 - 30 - 205 - 20 - MIRROR-SIM-3475409:Yaw:StopMoving = 1 - - - Position - 5 - 55 - 396 - 81 - true - - Label - Current - 0 - 0 - 150 - 20 - No description provided - - - TextUpdate - MIRROR-SIM-3475409:Yaw:Current - 155 - 0 - 205 - 20 - - - - - 1 - - - Label - Home - 0 - 25 - 150 - 20 - No description provided - - - TextUpdate - MIRROR-SIM-3475409:Yaw:Home - 155 - 25 - 205 - 20 - - - - - 1 - - - - Status - 5 - 141 - 396 - 56 - true - - Label - Moving - 0 - 0 - 150 - 20 - No description provided - - - LED - MIRROR-SIM-3475409:Yaw:Moving - 247 - 0 - 20 - 20 - - - From 14758481f9763ddfe913e564fd8d6a9f7d254333 Mon Sep 17 00:00:00 2001 From: Tom Kane Date: Thu, 5 Feb 2026 14:51:36 +0000 Subject: [PATCH 5/5] Don't add process number to sim pv --- .gitignore | 3 ++- pyproject.toml | 4 ++-- src/fastcs_standa_mirror/__main__.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4ef9e8c..5632b48 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,7 @@ lockfiles/ .ruff_cache/ .env -gui/ +bob/ +bob_custom/ virt/ home.yaml diff --git a/pyproject.toml b/pyproject.toml index 26418b7..5c9f90f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ version_file = "src/fastcs_standa_mirror/_version.py" [tool.pyright] typeCheckingMode = "standard" -reportMissingImports = false # Ignore missing stubs in imported modules +reportMissingImports = false # Ignore missing stubs in imported modules [tool.pytest.ini_options] # Run pytest with all our checkers, and don't spam us with massive tracebacks on error @@ -113,7 +113,7 @@ commands = [ description = "Run tests with coverage" commands = [ [ - "pytest", + "pytest", "--cov=fastcs_standa_mirror", "--cov-report", "term", diff --git a/src/fastcs_standa_mirror/__main__.py b/src/fastcs_standa_mirror/__main__.py index aaec29f..3bda0a0 100644 --- a/src/fastcs_standa_mirror/__main__.py +++ b/src/fastcs_standa_mirror/__main__.py @@ -57,7 +57,7 @@ def main() -> None: raise ValueError("DEVICE_PITCH_URI and DEVICE_YAW_URI must be set") else: - pv_prefix = f"MIRROR-SIM-{os.getpid()}" + pv_prefix = "MIRROR-SIM-001" logging.info(f"Simulated device PV_PREFIX -> {pv_prefix}") home_positions = load_or_create_home_pos()