Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions config/example/hsfei.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# HSFEI Subsystem Configuration
group_id: hsfei
transport: rabbitmq
rabbitmq_url: amqp://hispec-rabbitmq
discovery_enabled: false

daemons:
pickoff1:
hardware:
ip_address: 192.168.29.100
tcp_port: 10001
axis: "1"
named_positions:
home: 0.0
science: 12.5
calibration: 25.0
engineering: 37.5

pickoff2:
hardware:
ip_address: 192.168.29.101
tcp_port: 10001
axis: "1"
named_positions:
home: 0.0
flat: 10.0
arc: 20.0
dark: 30.0

pickoff3:
hardware:
ip_address: 192.168.29.102
tcp_port: 10001
axis: "1"
named_positions:
home: 0.0
science: 12.5
calibration: 25.0
engineering: 37.5

pickoff4:
hardware:
ip_address: 192.168.29.103
tcp_port: 10001
axis: "1"
named_positions:
home: 0.0
test_pos_1: 10.0
28 changes: 28 additions & 0 deletions config/hsfei/hsfei_pickoff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Single Daemon Configuration Example
# For standalone daemon deployment or development/testing
#
# Usage:
# daemon = HsfeiPickoffDaemon.from_config_file("config/pickoff_single.yaml")

peer_id: pickoff
group_id: hsfei
transport: rabbitmq
rabbitmq_url: amqp://localhost
discovery_enabled: false

hardware:
ip_address: 192.168.29.100
tcp_port: 10001
axis: "1"
timeout_s: 30.0
retry_count: 3

named_positions:
home: 0.0
deployed: 25.0
science: 12.5
calibration: 37.5

logging:
level: INFO
# file: /var/log/hispec/pickoff.log
95 changes: 46 additions & 49 deletions daemons/hsfei/pickoff
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,34 @@
"""
HSFEI Pickoff MirrorDaemon

This daemon provides control and monitoring of the FEI pickoff mirrorusing Libby.
This daemon provides control and monitoring of the FEI pickoff mirror using Libby.
"""

import argparse
import logging
import sys
from typing import Dict, Any

from libby.daemon import LibbyDaemon
from hispec import HispecDaemon
from hispec.util.pi import PIControllerBase


class HsfeiPickoffDaemon(LibbyDaemon):
class HsfeiPickoffDaemon(HispecDaemon):
"""Daemon for controlling the FEI pickoff mirror position."""

# Defaults
peer_id = "pickoff"
group_id = "hsfei"
transport = "rabbitmq"
rabbitmq_url = "amqp://localhost" # RabbitMQ on hispec
discovery_enabled = False
discovery_interval_s = 5.0

# pub/sub topics
topics = {}

def __init__(self, ip_address='192.168.29.100', tcp_port=10001, axis='1'):
"""Initialize the pickoff daemon.
def __init__(self):
"""Initialize the pickoff daemon."""
super().__init__()

Args:
ip_address: IP address of the PI controller (default: 192.168.29.100)
tcp_port: TCP port for the PI controller (default: 10001)
axis: Axis identifier (default: '1')
"""
# PI controller configuration
self.ip_address = ip_address
self.tcp_port = tcp_port
self.axis = axis
# PI controller configuration from config file
self.ip_address = self.get_config("hardware.ip_address", "192.168.29.100")
self.tcp_port = self.get_config("hardware.tcp_port", 10001)
self.axis = self.get_config("hardware.axis", "1")
self.device_key = None

# PI controller instance
Expand All @@ -50,11 +41,13 @@ class HsfeiPickoffDaemon(LibbyDaemon):
'error': '',
}

# Setup logging
self.logger = logging.getLogger(self.peer_id)
def get_named_positions(self):
"""Get named positions from config (e.g., home, deployed, science)."""
return self._config.get("named_positions", {})

# Call parent __init__ first
super().__init__()
def get_named_position(self, name: str):
"""Get a specific named position value, or None if not found."""
return self.get_named_positions().get(name)

def on_start(self, libby):
"""Called when daemon starts - initialize hardware."""
Expand Down Expand Up @@ -384,6 +377,16 @@ def main():
parser = argparse.ArgumentParser(
description='HSFEI Pickoff Mirror Daemon (PI C-663 Stepper)'
)
parser.add_argument(
'-c', '--config',
type=str,
help='Path to config file (YAML or JSON)'
)
parser.add_argument(
'-d', '--daemon-id',
type=str,
help='Daemon ID (required for subsystem configs with multiple daemons)'
)
parser.add_argument(
'-i', '--ip',
type=str,
Expand All @@ -405,33 +408,27 @@ def main():

args = parser.parse_args()

# Setup logging to file and console
log_level = logging.INFO
log_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'

# Create logger
logger = logging.getLogger()
logger.setLevel(log_level)

# Console handler
console_handler = logging.StreamHandler()
console_handler.setLevel(log_level)
console_handler.setFormatter(logging.Formatter(log_format))
logger.addHandler(console_handler)

# File handler
file_handler = logging.FileHandler('hsfei_pickoff_daemon.log')
file_handler.setLevel(log_level)
file_handler.setFormatter(logging.Formatter(log_format))
logger.addHandler(file_handler)

# Create and run daemon
try:
daemon = HsfeiPickoffDaemon(
ip_address=args.ip,
tcp_port=args.tcp_port,
axis=args.axis,
)
if args.config:
# Load from config file
daemon = HsfeiPickoffDaemon.from_config_file(
args.config,
daemon_id=args.daemon_id,
)
else:
# Use CLI args - build config dict and use from_config
config = {
"peer_id": "pickoff",
"group_id": "hsfei",
"transport": "rabbitmq",
"hardware": {
"ip_address": args.ip,
"tcp_port": args.tcp_port,
"axis": args.axis,
}
}
daemon = HsfeiPickoffDaemon.from_config(config)
daemon.serve()
except KeyboardInterrupt:
print("\nDaemon interrupted by user")
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies = [
"pipython",
"pyserial",
"libximc",
"pyyaml",
"libby@git+https://github.com/CaltechOpticalObservatories/libby.git",
"hardware_device_base@git+https://github.com/COO-Utilities/hardware_device_base"
]
17 changes: 17 additions & 0 deletions src/hispec/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from .daemon import HispecDaemon
from .config import (
ConfigError,
DaemonConfigLoader,
load_file,
extract_daemon_config,
list_daemons,
)

__all__ = [
"HispecDaemon",
"ConfigError",
"DaemonConfigLoader",
"load_file",
"extract_daemon_config",
"list_daemons",
]
Loading
Loading