From a43ff769d408c0716b512668737d0bf672cb7e29 Mon Sep 17 00:00:00 2001 From: spdis Date: Mon, 6 Jul 2026 17:25:24 +0800 Subject: [PATCH] =?UTF-8?q?speed20:=20=E5=B9=B3=E6=BB=91=E7=BA=BF=E6=80=A7?= =?UTF-8?q?=E8=BD=AC=E5=90=91=E6=B6=88=E9=99=A4=E6=AD=BB=E5=8C=BA=E6=96=AD?= =?UTF-8?q?=E5=B4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/camera.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index fa9f635..de9fd84 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -962,12 +962,15 @@ static void steering_update() } } - if (std::abs(deviation) < g_cfg.deadband) { - // 死区内 → 直行 + // 平滑线性转向: 偏差从死区边界开始缩放,消除死区断崖 + double effective = std::abs(deviation) - g_cfg.deadband; + if (effective <= 0) { servo.setDutyCycle(1500000); } else { - // 比例控制: 偏差 → 归一化 → × 增益 × 满偏占空比差 - double offset = deviation / (newWidth / 2.0) * g_cfg.steer_gain * 300000; + double half_w = newWidth / 2.0; + double norm = effective / (half_w - g_cfg.deadband); + double sign = (deviation > 0) ? 1.0 : -1.0; + double offset = norm * g_cfg.steer_gain * 300000.0 * sign; double duty_ns = std::clamp(1500000.0 + offset, 1200000.0, 1800000.0); servo.setDutyCycle((unsigned int)duty_ns); }