MainCode/adalm1000_logger.py aktualisiert

Change _execute_phase() to accept charge_cutoff, discharge_cutoff

Use the passed-in values instead of nonexistent self.parent.charge_cutoff

Update function calls accordingly

start_time synchronization
(C und D)
This commit is contained in:
Jan 2025-06-30 02:37:08 +02:00
parent e9799c17de
commit ba583337bb

View File

@ -35,13 +35,8 @@ class MeasurementThread(QThread):
error_signal = pyqtSignal(str)
status_signal = pyqtSignal(str)
def __init__(self, device: object, interval: float = 0.1):
"""Initialize measurement thread.
Args:
device: ADALM1000 device object
interval: Measurement interval in seconds
"""
def __init__(self, device: object, interval: float = 0.1, start_time: float = None):
"""Initialize measurement thread."""
super().__init__()
self.device = device
self.interval = max(0.05, interval) # Minimum interval
@ -156,7 +151,7 @@ class TestSequenceThread(QThread):
cycle = self.parent.cycle_count
# Charge phase
self._execute_phase("charge", test_current, charge_cutoff)
self._execute_phase("charge", test_current, charge_cutoff, discharge_cutoff, charge_cutoff)
if not self._running:
break
@ -166,7 +161,7 @@ class TestSequenceThread(QThread):
break
# Discharge phase
self._execute_phase("discharge", test_current, discharge_cutoff)
self._execute_phase("discharge", test_current, discharge_cutoff, discharge_cutoff, charge_cutoff)
if not self.parent.continuous_mode:
break
@ -185,7 +180,7 @@ class TestSequenceThread(QThread):
finally:
self._running = False
def _execute_phase(self, phase: str, current: float, target_voltage: float):
def _execute_phase(self, phase: str, current: float, target_voltage: float, discharge_cutoff: float, charge_cutoff: float):
"""Execute charge/discharge phase.
Args:
@ -231,12 +226,10 @@ class TestSequenceThread(QThread):
# Update capacity
if phase == "charge":
self.parent.charge_capacity += abs(self.parent.current_data[-1]) * delta_t / 3600
progress = (current_voltage - self.parent.discharge_cutoff) / \
(target_voltage - self.parent.discharge_cutoff)
progress = (current_voltage - discharge_cutoff) / (target_voltage - discharge_cutoff)
else:
self.parent.capacity_ah += abs(self.parent.current_data[-1]) * delta_t / 3600
progress = (self.parent.charge_cutoff - current_voltage) / \
(self.parent.charge_cutoff - target_voltage)
progress = (charge_cutoff - current_voltage) / (charge_cutoff - target_voltage)
progress = max(0.0, min(1.0, progress))
self.progress_updated.emit(progress, f"{phase.capitalize()}ing")
@ -693,6 +686,12 @@ class BatteryTester(QMainWindow):
"""Start the measurement thread."""
if self.measurement_thread is not None:
self.measurement_thread.stop()
self.measurement_thread.wait(500)
self.measurement_thread = MeasurementThread(
device=self.dev,
interval=self.interval,
start_time=self.start_time
self.measurement_thread = MeasurementThread(self.dev, self.interval)
self.measurement_thread.update_signal.connect(self.update_measurements)
@ -999,7 +998,7 @@ class BatteryTester(QMainWindow):
voltage_padding = 0.2
min_voltage = max(0, float(self.discharge_cutoff_input.text()) - voltage_padding)
max_voltage = float(self.charge_cutoff_input.text()) + voltage_padding
self.ax.set_ylim(min_voltage, max_volume)
self.ax.set_ylim(min_voltage, max_voltage)
self.canvas.draw()