MainCode/adalm1000_logger.py aktualisiert
Test phase display issue: When continuous mode is disabled and the discharge voltage is already below cutoff, the phase still shows "Discharge" instead of switching to "Idle".
Graph update issue: The plot sometimes fails to update when starting a new test series.
(Deepseek)
This commit is contained in:
parent
1a6ebb2fab
commit
81ccc8ccd7
@ -424,6 +424,9 @@ class BatteryTester:
|
|||||||
self.coulomb_efficiency.set(0.0)
|
self.coulomb_efficiency.set(0.0)
|
||||||
self.cycle_count.set(0)
|
self.cycle_count.set(0)
|
||||||
|
|
||||||
|
# Ensure plot is properly reset for new test
|
||||||
|
self.reset_plot_data()
|
||||||
|
|
||||||
# Generate base filename without cycle number
|
# Generate base filename without cycle number
|
||||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
self.base_filename = os.path.join(self.log_dir, f"battery_test_{timestamp}")
|
self.base_filename = os.path.join(self.log_dir, f"battery_test_{timestamp}")
|
||||||
@ -496,6 +499,7 @@ class BatteryTester:
|
|||||||
self.request_stop = True
|
self.request_stop = True
|
||||||
self.test_running = False
|
self.test_running = False
|
||||||
self.measuring = False
|
self.measuring = False
|
||||||
|
self.test_phase.set("Idle") # Ensure phase is set to Idle
|
||||||
|
|
||||||
# Immediately set device to safe state
|
# Immediately set device to safe state
|
||||||
if hasattr(self, 'dev'):
|
if hasattr(self, 'dev'):
|
||||||
@ -512,20 +516,12 @@ class BatteryTester:
|
|||||||
self.phase_data.clear()
|
self.phase_data.clear()
|
||||||
|
|
||||||
# Reset test values
|
# Reset test values
|
||||||
self.test_phase.set("Idle")
|
|
||||||
self.capacity_ah.set(0.0)
|
self.capacity_ah.set(0.0)
|
||||||
self.charge_capacity.set(0.0)
|
self.charge_capacity.set(0.0)
|
||||||
self.coulomb_efficiency.set(0.0)
|
self.coulomb_efficiency.set(0.0)
|
||||||
|
|
||||||
# Reset plot if it exists
|
# Reset plot
|
||||||
if hasattr(self, 'line_voltage') and hasattr(self, 'line_current'):
|
self.reset_plot_data()
|
||||||
self.line_voltage.set_data([], [])
|
|
||||||
self.line_current.set_data([], [])
|
|
||||||
# Reset to reasonable default ranges
|
|
||||||
self.ax.set_xlim(0, 10) # Small range instead of 0-1
|
|
||||||
self.ax.set_ylim(0, 2) # Typical battery voltage range
|
|
||||||
self.ax2.set_ylim(-0.2, 0.2) # Typical current range
|
|
||||||
self.canvas.draw()
|
|
||||||
|
|
||||||
# Update UI
|
# Update UI
|
||||||
self.status_var.set("Test stopped - Ready for new test")
|
self.status_var.set("Test stopped - Ready for new test")
|
||||||
@ -667,6 +663,7 @@ class BatteryTester:
|
|||||||
|
|
||||||
if not self.continuous_var.get():
|
if not self.continuous_var.get():
|
||||||
self.test_running = False
|
self.test_running = False
|
||||||
|
self.test_phase.set("Idle") # Explicitly set to Idle when stopping
|
||||||
break # Exit the main test loop
|
break # Exit the main test loop
|
||||||
|
|
||||||
# 4. Rest period after discharge (only if not stopping)
|
# 4. Rest period after discharge (only if not stopping)
|
||||||
@ -776,6 +773,23 @@ class BatteryTester:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"GUI update error: {e}")
|
print(f"GUI update error: {e}")
|
||||||
|
|
||||||
|
def reset_plot_data(self):
|
||||||
|
"""Clear and reset plot data for a new test"""
|
||||||
|
self.line_voltage.set_data([], [])
|
||||||
|
self.line_current.set_data([], [])
|
||||||
|
# Reset to reasonable default ranges
|
||||||
|
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_xlim(0, 10) # Small initial time range
|
||||||
|
self.ax.set_ylim(min_voltage, max_voltage)
|
||||||
|
|
||||||
|
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.canvas.draw()
|
||||||
|
|
||||||
def write_cycle_summary(self):
|
def write_cycle_summary(self):
|
||||||
"""Write cycle summary to the current cycle's log file"""
|
"""Write cycle summary to the current cycle's log file"""
|
||||||
if not hasattr(self, 'current_cycle_file') or not self.current_cycle_file:
|
if not hasattr(self, 'current_cycle_file') or not self.current_cycle_file:
|
||||||
@ -800,24 +814,16 @@ class BatteryTester:
|
|||||||
|
|
||||||
def update_plot(self):
|
def update_plot(self):
|
||||||
"""Optimized plot update with change detection"""
|
"""Optimized plot update with change detection"""
|
||||||
if not self.time_data or len(self.time_data) < 5: # Wait for at least 5 samples
|
if not self.time_data:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Only update if there's significant new data
|
# Force update more frequently at start of test
|
||||||
if hasattr(self, '_last_plot_time') and (self.time_data[-1] - self._last_plot_time < 1.0):
|
if len(self.time_data) < 10 or (time.time() - getattr(self, '_last_plot_time', 0)) > 1.0:
|
||||||
return
|
|
||||||
|
|
||||||
self._last_plot_time = self.time_data[-1]
|
|
||||||
|
|
||||||
# Update plot data
|
|
||||||
self.line_voltage.set_data(self.time_data, self.voltage_data)
|
self.line_voltage.set_data(self.time_data, self.voltage_data)
|
||||||
self.line_current.set_data(self.time_data, self.current_data)
|
self.line_current.set_data(self.time_data, self.current_data)
|
||||||
|
|
||||||
# Auto-scale axes if needed
|
|
||||||
self.auto_scale_axes()
|
self.auto_scale_axes()
|
||||||
|
|
||||||
# Only redraw if needed
|
|
||||||
self.canvas.draw_idle()
|
self.canvas.draw_idle()
|
||||||
|
self._last_plot_time = time.time()
|
||||||
|
|
||||||
def auto_scale_axes(self):
|
def auto_scale_axes(self):
|
||||||
"""Auto-scale plot axes with appropriate padding"""
|
"""Auto-scale plot axes with appropriate padding"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user