interface upd
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import logging
|
||||
import time
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Optional, Dict, Any
|
||||
from datetime import datetime
|
||||
|
||||
@ -26,7 +28,7 @@ class LaserController:
|
||||
TaskType format: String-based ("TT_CHANGE_CURR_1", "TT_CHANGE_CURR_2")
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, config_path: Optional[str] = None):
|
||||
self.prt = None # Serial port object
|
||||
self.is_connected = False
|
||||
self.is_running = False
|
||||
@ -34,14 +36,78 @@ class LaserController:
|
||||
self.current_status = LaserStatus()
|
||||
self.last_data: Optional[Dict[str, Any]] = None
|
||||
|
||||
# Default PI coefficients (multiplied by 256 as per device protocol)
|
||||
# Load default parameters from JSON
|
||||
self._load_default_parameters(config_path)
|
||||
|
||||
logger.info("LaserController initialized")
|
||||
|
||||
def _load_default_parameters(self, config_path: Optional[str] = None) -> None:
|
||||
"""
|
||||
Load default parameters from JSON configuration file.
|
||||
|
||||
Args:
|
||||
config_path: Path to JSON config file. If None, uses default location.
|
||||
"""
|
||||
try:
|
||||
# Determine config file path
|
||||
if config_path is None:
|
||||
# Default path relative to this file
|
||||
current_dir = Path(__file__).parent
|
||||
config_path = current_dir / "RadioPhotonic_PCB_PC_software" / "init_params.json"
|
||||
else:
|
||||
config_path = Path(config_path)
|
||||
|
||||
# Load JSON file
|
||||
if not config_path.exists():
|
||||
logger.warning(f"Config file not found: {config_path}, using hardcoded defaults")
|
||||
self._set_hardcoded_defaults()
|
||||
return
|
||||
|
||||
with open(config_path, 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
# Set parameters from config
|
||||
self.initial_temperature_1 = config.get("INITIAL_TEMPERATURE_1", 28)
|
||||
self.initial_temperature_2 = config.get("INITIAL_TEMPERATURE_2", 28.9)
|
||||
self.initial_current_1 = config.get("INITIAL_CURRENT_1", 33)
|
||||
self.initial_current_2 = config.get("INITIAL_CURRENT_2", 35)
|
||||
|
||||
# PI coefficients (multiplied by 256 as per device protocol)
|
||||
self.proportional_coeff_1 = int(config.get("PROPORTIONAL_COEFF_1", 10) * 256)
|
||||
self.proportional_coeff_2 = int(config.get("PROPORTIONAL_COEFF_2", 10) * 256)
|
||||
self.integral_coeff_1 = int(config.get("INTEGRAL_COEFF_1", 0.5) * 256)
|
||||
self.integral_coeff_2 = int(config.get("INTEGRAL_COEFF_2", 0.5) * 256)
|
||||
self.message_id = config.get("MESSAGE_ID", "00FF")
|
||||
|
||||
# Additional parameters
|
||||
self.gui_timeout_interval = config.get("GUI_TIMEOUT_INTERVAL", 5)
|
||||
self.save_points_number = config.get("SAVE_POINTS_NUMBER", 1000)
|
||||
|
||||
logger.info(f"Default parameters loaded from {config_path}")
|
||||
logger.info(f" Initial T1: {self.initial_temperature_1}°C, T2: {self.initial_temperature_2}°C")
|
||||
logger.info(f" Initial I1: {self.initial_current_1} mA, I2: {self.initial_current_2} mA")
|
||||
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Invalid JSON in config file: {e}")
|
||||
self._set_hardcoded_defaults()
|
||||
except Exception as e:
|
||||
logger.error(f"Error loading config file: {e}")
|
||||
self._set_hardcoded_defaults()
|
||||
|
||||
def _set_hardcoded_defaults(self) -> None:
|
||||
"""Set hardcoded default parameters as fallback."""
|
||||
self.initial_temperature_1 = 28
|
||||
self.initial_temperature_2 = 28.9
|
||||
self.initial_current_1 = 33
|
||||
self.initial_current_2 = 35
|
||||
self.proportional_coeff_1 = int(10 * 256)
|
||||
self.proportional_coeff_2 = int(10 * 256)
|
||||
self.integral_coeff_1 = int(0.5 * 256)
|
||||
self.integral_coeff_2 = int(0.5 * 256)
|
||||
self.message_id = "00FF"
|
||||
|
||||
logger.info("LaserController initialized")
|
||||
self.gui_timeout_interval = 5
|
||||
self.save_points_number = 1000
|
||||
logger.info("Using hardcoded default parameters")
|
||||
|
||||
def start_cycle(self, parameters: LaserParameters) -> Dict[str, Any]:
|
||||
"""
|
||||
|
||||
@ -348,10 +348,10 @@
|
||||
<div class="control-section" id="laserManualSection">
|
||||
<h4 class="control-section-title">Параметры ручного режима</h4>
|
||||
<div class="laser-params-table">
|
||||
<div class="laser-param-cell laser-param-header">Температура лазера 1 (°C)</div>
|
||||
<div class="laser-param-cell laser-param-header">Температура лазера 2 (°C)</div>
|
||||
<div class="laser-param-cell laser-param-header">Управляющий ток лазера 1 (15-60 мА)</div>
|
||||
<div class="laser-param-cell laser-param-header">Управляющий ток лазера 2 (15-60 мА)</div>
|
||||
<div class="laser-param-cell laser-param-header">T1 (°C)</div>
|
||||
<div class="laser-param-cell laser-param-header">T2 (°C)</div>
|
||||
<div class="laser-param-cell laser-param-header">Ток L1 (мА)</div>
|
||||
<div class="laser-param-cell laser-param-header">Ток L2 (мА)</div>
|
||||
|
||||
<div class="laser-param-cell laser-param-input">
|
||||
<input type="number" class="settings-input" id="laserTemp1"
|
||||
@ -374,63 +374,54 @@
|
||||
|
||||
<!-- Scan Mode Controls -->
|
||||
<div class="control-section" id="laserScanSection" style="display: none;">
|
||||
<h4 class="control-section-title">Режим сканирования тока лазера 1</h4>
|
||||
<h4 class="control-section-title">Параметры сканирования тока лазера 1</h4>
|
||||
<div class="laser-params-table">
|
||||
<!-- Row 1: Headers -->
|
||||
<div class="laser-param-cell laser-param-header">Мин ток L1 (мА)</div>
|
||||
<div class="laser-param-cell laser-param-header">Макс ток L1 (мА)</div>
|
||||
<div class="laser-param-cell laser-param-header">Шаг тока L1 (мА)</div>
|
||||
<div class="laser-param-cell laser-param-header">Δt (мкс)</div>
|
||||
|
||||
<div class="control-subsection">
|
||||
<h5 class="control-subsection-title">Параметры сканирования</h5>
|
||||
<div class="control-grid">
|
||||
<div class="control-group">
|
||||
<label class="control-label">Минимальный ток лазера 1 (мА):</label>
|
||||
<input type="number" class="settings-input" id="laserMinCurrent1"
|
||||
min="15" max="70" step="0.1" value="33" disabled>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Максимальный ток лазера 1 (мА):</label>
|
||||
<input type="number" class="settings-input" id="laserMaxCurrent1"
|
||||
min="15" max="70" step="0.1" value="70" disabled>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Шаг дискретизации тока лазера 1 (0.002-0.5 мА):</label>
|
||||
<input type="number" class="settings-input" id="laserDeltaCurrent1"
|
||||
min="0.002" max="0.5" step="0.001" value="0.05" disabled>
|
||||
</div>
|
||||
<!-- Row 2: Inputs -->
|
||||
<div class="laser-param-cell laser-param-input">
|
||||
<input type="number" class="settings-input" id="laserMinCurrent1"
|
||||
min="15" max="70" step="0.1" value="33" disabled>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-subsection">
|
||||
<h5 class="control-subsection-title">Фиксированные параметры</h5>
|
||||
<div class="control-grid">
|
||||
<div class="control-group">
|
||||
<label class="control-label">Температура лазера 1 (°C):</label>
|
||||
<input type="number" class="settings-input" id="laserScanTemp1"
|
||||
min="-1" max="45" step="0.1" value="28" disabled>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Температура лазера 2 (°C):</label>
|
||||
<input type="number" class="settings-input" id="laserScanTemp2"
|
||||
min="-1" max="45" step="0.1" value="28.9" disabled>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Управляющий ток лазера 2 (мА):</label>
|
||||
<input type="number" class="settings-input" id="laserScanCurrent2"
|
||||
min="15" max="60" step="0.1" value="35" disabled>
|
||||
</div>
|
||||
<div class="laser-param-cell laser-param-input">
|
||||
<input type="number" class="settings-input" id="laserMaxCurrent1"
|
||||
min="15" max="70" step="0.1" value="70" disabled>
|
||||
</div>
|
||||
<div class="laser-param-cell laser-param-input">
|
||||
<input type="number" class="settings-input" id="laserDeltaCurrent1"
|
||||
min="0.002" max="0.5" step="0.001" value="0.05" disabled>
|
||||
</div>
|
||||
<div class="laser-param-cell laser-param-input">
|
||||
<input type="number" class="settings-input" id="laserDeltaTime"
|
||||
min="20" max="100" step="10" value="50" disabled>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-subsection">
|
||||
<h5 class="control-subsection-title">Параметры времени</h5>
|
||||
<div class="control-grid">
|
||||
<div class="control-group">
|
||||
<label class="control-label">Шаг дискретизации времени (20-100 мкс, шаг 10):</label>
|
||||
<input type="number" class="settings-input" id="laserDeltaTime"
|
||||
min="20" max="100" step="10" value="50" disabled>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">Время задержки (3-10 мс):</label>
|
||||
<input type="number" class="settings-input" id="laserTau"
|
||||
min="3" max="10" step="1" value="10" disabled>
|
||||
</div>
|
||||
<!-- Row 3: Fixed params headers -->
|
||||
<div class="laser-param-cell laser-param-header">T1 (°C)</div>
|
||||
<div class="laser-param-cell laser-param-header">T2 (°C)</div>
|
||||
<div class="laser-param-cell laser-param-header">Ток L2 (мА)</div>
|
||||
<div class="laser-param-cell laser-param-header">Tau (мс)</div>
|
||||
|
||||
<!-- Row 4: Fixed params inputs -->
|
||||
<div class="laser-param-cell laser-param-input">
|
||||
<input type="number" class="settings-input" id="laserScanTemp1"
|
||||
min="-1" max="45" step="0.1" value="28" disabled>
|
||||
</div>
|
||||
<div class="laser-param-cell laser-param-input">
|
||||
<input type="number" class="settings-input" id="laserScanTemp2"
|
||||
min="-1" max="45" step="0.1" value="28.9" disabled>
|
||||
</div>
|
||||
<div class="laser-param-cell laser-param-input">
|
||||
<input type="number" class="settings-input" id="laserScanCurrent2"
|
||||
min="15" max="60" step="0.1" value="35" disabled>
|
||||
</div>
|
||||
<div class="laser-param-cell laser-param-input">
|
||||
<input type="number" class="settings-input" id="laserTau"
|
||||
min="3" max="10" step="1" value="10" disabled>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user