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:///... 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 1fee9ae..3bda0a0 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 = "MIRROR-SIM-001" + 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",