From 946ad6bfc5ab81ec55e780a8f4d1a8b7d623915e Mon Sep 17 00:00:00 2001 From: lyq Date: Mon, 20 Apr 2026 09:43:05 +0800 Subject: [PATCH] =?UTF-8?q?[pl]=E9=81=BF=E5=85=8D=E5=BF=99=E7=AD=89?= =?UTF-8?q?=E5=BE=85=EF=BC=8C=E9=81=BF=E5=85=8D=E5=BF=99=E7=AD=89=E5=BE=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/autonomy/pl/src/pl.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/autonomy/pl/src/pl.cpp b/src/autonomy/pl/src/pl.cpp index c9cd453..5400b9c 100644 --- a/src/autonomy/pl/src/pl.cpp +++ b/src/autonomy/pl/src/pl.cpp @@ -206,9 +206,12 @@ void PL_ProcThread() int road_pos = 0; int des_pos = 3; int direction_pos = 20; + auto next_time = std::chrono::steady_clock::now(); while (1) { + next_time += std::chrono::milliseconds(50); + g_NavInfo.Latitude_degree = g_rtk.lat; g_NavInfo.Longitude_degree = g_rtk.lon; g_NavInfo.Yaw_rad = g_rtk.direction; @@ -274,6 +277,12 @@ void PL_ProcThread() } // printf("x_cm:%lf y_cm:%lf speed:%d\n", x, y, pl_speed); + + // 避免忙等待,增加延迟让 CPU 能够处理其他任务 + auto now = std::chrono::steady_clock::now(); + if (now > next_time) + next_time = now; + std::this_thread::sleep_until(next_time); } return;