From a26f6b8fe5e0af88b8c8ba733c8933c38bd5e3bf Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 29 Jul 2025 12:46:09 +0200 Subject: [PATCH] MainCode/adalm1000_logger.py aktualisiert Alles sollte klappen (D) --- MainCode/adalm1000_logger.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/MainCode/adalm1000_logger.py b/MainCode/adalm1000_logger.py index 8076a1e..f06611c 100644 --- a/MainCode/adalm1000_logger.py +++ b/MainCode/adalm1000_logger.py @@ -447,6 +447,15 @@ class BatteryTester(QMainWindow): self.phase_data = deque() self.downsample_factor = 1 # Initial kein Downsampling self.downsample_counter = 0 + + # Initialize all measurement variables + self.capacity_ah = 0.0 + self.energy = 0.0 + self.charge_capacity = 0.0 + self.coulomb_efficiency = 0.0 + self.cycle_count = 0 + self.start_time = time.time() + self.last_update_time = self.start_time # Initialize UI and device self.setup_ui() @@ -1076,20 +1085,15 @@ class BatteryTester(QMainWindow): def update_status(self): """Update status information periodically""" - now = time.time() - if not hasattr(self, '_last_log_time'): - self._last_log_time = now - - if self.test_running or (hasattr(self, 'record_button') and self.record_button.isChecked()): - # Update capacity calculations if in test mode + if self.test_running or hasattr(self, 'record_button') and self.record_button.isChecked(): if self.time_data: - current_time = time.time() - self.start_time - delta_t = current_time - self.last_update_time - self.last_update_time = current_time - - current_current = abs(self.current_data[-1]) - self.capacity_ah += current_current * delta_t / 3600 - self.capacity_label.setText(f"{self.capacity_ah:.4f}") + current_time = self.time_data[-1] # Verwenden Sie den gespeicherten relativen Zeitstempel + if len(self.time_data) > 1: + delta_t = self.time_data[-1] - self.time_data[-2] # Korrekte Zeitdifferenz + if delta_t > 0: # Nur positive Differenzen berücksichtigen + current_current = abs(self.current_data[-1]) + self.capacity_ah += current_current * delta_t / 3600 + self.capacity_label.setText(f"{self.capacity_ah:.4f}") # Logging (1x per second) if hasattr(self, 'log_writer') and hasattr(self, 'current_cycle_file') and self.current_cycle_file is not None: