From 6db656c71b4763fea9c5fe6a44f372c770dd2726 Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 24 May 2025 01:33:36 +0200 Subject: [PATCH] MainCode/adalm1000_logger.py aktualisiert change cyclecount to beginning This will ensure your plot: Starts with a reasonable view of your expected voltage range Maintains good visibility of the key areas (charge/discharge cutoffs) Doesn't zoom out too far when there are measurement spikes Has better overall framing of the data --- MainCode/adalm1000_logger.py | 50 ++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/MainCode/adalm1000_logger.py b/MainCode/adalm1000_logger.py index ffc2153..28ae7b5 100644 --- a/MainCode/adalm1000_logger.py +++ b/MainCode/adalm1000_logger.py @@ -209,17 +209,29 @@ class BatteryTester: def setup_plot(self): """Configure the matplotlib plot""" self.fig = Figure(figsize=(8, 5), dpi=100, facecolor='#2E3440') - self.fig.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.15) + # Adjust margins to give more space on right side + self.fig.subplots_adjust(left=0.1, right=0.88, top=0.9, bottom=0.15) self.ax = self.fig.add_subplot(111) self.ax.set_facecolor('#3B4252') + # Set initial voltage range based on charge/discharge cutoffs ±0.2V + voltage_padding = 0.2 + min_voltage = max(0, self.discharge_cutoff.get() - voltage_padding) + max_voltage = self.charge_cutoff.get() + voltage_padding + self.ax.set_ylim(min_voltage, max_voltage) + # Voltage plot self.line_voltage, = self.ax.plot([], [], color='#00BFFF', label='Voltage (V)', linewidth=2) self.ax.set_ylabel("Voltage (V)", color='#00BFFF') self.ax.tick_params(axis='y', labelcolor='#00BFFF') - # Current plot (right axis) + # Current plot (right axis) - set initial range based on test current self.ax2 = self.ax.twinx() + current_padding = 0.05 + test_current = self.c_rate.get() * self.capacity.get() + max_current = test_current * 1.5 # Add 50% padding + self.ax2.set_ylim(-max_current - current_padding, max_current + current_padding) + self.line_current, = self.ax2.plot([], [], 'r-', label='Current (A)', linewidth=2) self.ax2.set_ylabel("Current (A)", color='r') self.ax2.tick_params(axis='y', labelcolor='r') @@ -229,8 +241,9 @@ class BatteryTester: self.ax.tick_params(axis='x', colors=self.fg_color) self.ax.grid(True, color='#4C566A') - self.ax.legend(loc='upper left') - self.ax2.legend(loc='upper right') + # Position legends to avoid overlap + self.ax.legend(loc='upper left', bbox_to_anchor=(0.01, 0.99)) + self.ax2.legend(loc='upper right', bbox_to_anchor=(0.99, 0.99)) # Embed plot self.canvas = FigureCanvasTkAgg(self.fig, master=self.plot_frame) @@ -469,7 +482,8 @@ class BatteryTester: while self.test_running and (self.continuous_mode or self.cycle_count.get() == 0): # Reset stop request at start of each cycle self.request_stop = False - + self.cycle_count.set(self.cycle_count.get() + 1) + # 1. Charge phase (constant current) self.test_phase.set("Charge") self.status_var.set(f"Charging to {self.charge_cutoff.get()}V @ {test_current:.3f}A") @@ -589,7 +603,6 @@ class BatteryTester: if not self.request_stop and self.charge_capacity.get() > 0: efficiency = (self.capacity_ah.get() / self.charge_capacity.get()) * 100 self.coulomb_efficiency.set(efficiency) - self.cycle_count.set(self.cycle_count.get() + 1) # Update cycle info self.status_var.set( @@ -753,19 +766,30 @@ class BatteryTester: self.ax.set_xlim(min_time, max_time) self.ax2.set_xlim(min_time, max_time) - # Auto-scale y-axes with some margin (only if significant change) + # Auto-scale y-axes but respect initial boundaries + voltage_padding = 0.2 if self.voltage_data: - voltage_margin = 0.2 - min_voltage = max(0, min(self.voltage_data) - voltage_margin) - max_voltage = max(self.voltage_data) + voltage_margin + min_voltage = max(0, min(self.voltage_data) - voltage_padding) + max_voltage = max(self.voltage_data) + voltage_padding + + # Ensure we don't go below discharge cutoff - padding or above charge cutoff + padding + min_voltage = max(min_voltage, max(0, self.discharge_cutoff.get() - voltage_padding*2)) + max_voltage = min(max_voltage, self.charge_cutoff.get() + voltage_padding*2) + current_ylim = self.ax.get_ylim() if abs(current_ylim[0] - min_voltage) > 0.1 or abs(current_ylim[1] - max_voltage) > 0.1: self.ax.set_ylim(min_voltage, max_voltage) + current_padding = 0.05 if self.current_data: - current_margin = 0.05 - min_current = min(self.current_data) - current_margin - max_current = max(self.current_data) + current_margin + test_current = self.c_rate.get() * self.capacity.get() + min_current = min(self.current_data) - current_padding + max_current = max(self.current_data) + current_padding + + # Ensure we don't go too far beyond test current + min_current = max(min_current, -test_current*1.5) + max_current = min(max_current, test_current*1.5) + current_ylim2 = self.ax2.get_ylim() if abs(current_ylim2[0] - min_current) > 0.02 or abs(current_ylim2[1] - max_current) > 0.02: self.ax2.set_ylim(min_current, max_current)