From 2aad8782a707e0665fd479ded00a3450aa8e993f Mon Sep 17 00:00:00 2001 From: wangfq Date: Mon, 29 Jun 2026 17:27:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BF=AB=E9=80=9F=20IIR=20=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=94=B9=E4=B8=BA=E9=99=90=E5=B9=85=E5=90=8E=E5=8E=9F?= =?UTF-8?q?=E5=A7=8B=E5=80=BC=20(=E5=90=8C=E6=AD=A5=20DLD154V4B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../at32f421_freertos_demo/src/TaskLoop.c | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c index a6c58b2..cbd9198 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c @@ -450,28 +450,32 @@ void vd1_task_per_channel(Loop154_Unit *unit) *================================================================*/ /* 1a. 慢速 IIR — 斜率限幅 */ - if (unit->loop_CAPVD == 0) { - unit->loop_CAPVD = unit->loop_Value; - unit->loop_CAPVD_fast = unit->loop_Value; - } else { - /* 斜率限幅: 物理车辆不可能让频率瞬间跳变 > MAX_SLOPE_RATE% */ - int32_t raw_delta = (int32_t)unit->loop_Value - (int32_t)unit->loop_CAPVD; - int32_t max_step = (int32_t)(unit->loop_CAPVD * MAX_SLOPE_RATE / 100); - if (max_step < 100) max_step = 100; - if (raw_delta > max_step) raw_delta = max_step; - if (raw_delta < -max_step) raw_delta = -max_step; - uint32_t clamped_value = (uint32_t)((int32_t)unit->loop_CAPVD + raw_delta); - unit->loop_CAPVD = get_flt_value(clamped_value, unit->loop_CAPVD); - } + { + uint32_t fast_input; // 快速 IIR 的输入:限幅后的原始值,不经慢速 IIR 滞后 - /* 1b. 快速 IIR — α=0.5: (old + new) / 2 */ - if (unit->loop_CAPVD_fast == 0) { - unit->loop_CAPVD_fast = unit->loop_CAPVD; // 首次直接锁定 - } else { - unit->loop_CAPVD_fast = (unit->loop_CAPVD_fast + unit->loop_CAPVD) / 2; - } + if (unit->loop_CAPVD == 0) { + unit->loop_CAPVD = unit->loop_Value; + fast_input = unit->loop_Value; + } else { + /* 斜率限幅: 物理车辆不可能让频率瞬间跳变 > MAX_SLOPE_RATE% */ + int32_t raw_delta = (int32_t)unit->loop_Value - (int32_t)unit->loop_CAPVD; + int32_t max_step = (int32_t)(unit->loop_CAPVD * MAX_SLOPE_RATE / 100); + if (max_step < 100) max_step = 100; + if (raw_delta > max_step) raw_delta = max_step; + if (raw_delta < -max_step) raw_delta = -max_step; + uint32_t clamped_value = (uint32_t)((int32_t)unit->loop_CAPVD + raw_delta); + unit->loop_CAPVD = get_flt_value(clamped_value, unit->loop_CAPVD); + fast_input = clamped_value; + } - /*--- 2. 稳定期:绕过 IIR 和斜率限幅,直接用 Value 快速收敛 (V2.2) ---*/ + /* 1b. 快速 IIR — α=0.5: (old + new) / 2 + * 输入直接用限幅后的原始值,不经过慢速 IIR,保持 τ≈28ms 的响应速度 */ + if (unit->loop_CAPVD_fast == 0) { + unit->loop_CAPVD_fast = fast_input; + } else { + unit->loop_CAPVD_fast = (unit->loop_CAPVD_fast + fast_input) / 2; + } + } if (!unit->loop_stable) { unit->loop_CAPVD = unit->loop_Value; unit->loop_CAPVD_fast = unit->loop_Value;