修改问题.md,且新增data_logger.py画图模块

This commit is contained in:
2026-08-13 14:28:03 +08:00
parent 84b2bdb35d
commit 64be6d7c7a
11 changed files with 226 additions and 10 deletions
+21
View File
@@ -15,6 +15,7 @@ import time
import config
from controllers import IncrementalPID
from data_logger import FlowRunRecorder
from flow_control import FlowControlFault, FlowControlLoop
@@ -131,6 +132,7 @@ def run(target_flow_slm):
controller.set_target_flow(target_flow_slm)
connected = False
recorder = None
exit_code = 0
try:
logger.info(
@@ -161,6 +163,11 @@ def run(target_flow_slm):
)
controller.start(initial_opening=0.0)
recorder = FlowRunRecorder(
Path(__file__).resolve().parent / config.DATA_DIRECTORY,
plot_dpi=config.PLOT_DPI,
)
logger.info("逐周期数据将保存到 %s", recorder.csv_path)
logger.info("闭环控制已启动;按 Ctrl+C 停止")
next_deadline = time.perf_counter()
@@ -168,6 +175,7 @@ def run(target_flow_slm):
while True:
now = time.perf_counter()
result = controller.step(now=now)
recorder.record(result)
if now >= next_status_time or result.status != "OK":
logger.info(format_status(result))
@@ -200,6 +208,19 @@ def run(target_flow_slm):
except Exception:
exit_code = max(exit_code, 5)
logger.exception("断开 MT2-AM8 时发生异常")
if recorder is not None:
try:
image_path = recorder.finalize()
logger.info("控制数据已保存:%s", recorder.csv_path)
if image_path is not None:
logger.info("三联曲线图已保存:%s", image_path)
else:
logger.warning("本次运行没有采样点,因此未生成曲线图")
except Exception:
recorder.close()
exit_code = max(exit_code, 7)
logger.exception("保存控制数据曲线图失败;CSV 数据仍保留")
logger.info("程序结束,退出码=%d", exit_code)
return exit_code