[pl]避免忙等待,避免忙等待

This commit is contained in:
lyq 2026-04-20 09:43:05 +08:00
parent 3897be02b1
commit 946ad6bfc5

View File

@ -206,9 +206,12 @@ void PL_ProcThread()
int road_pos = 0; int road_pos = 0;
int des_pos = 3; int des_pos = 3;
int direction_pos = 20; int direction_pos = 20;
auto next_time = std::chrono::steady_clock::now();
while (1) while (1)
{ {
next_time += std::chrono::milliseconds(50);
g_NavInfo.Latitude_degree = g_rtk.lat; g_NavInfo.Latitude_degree = g_rtk.lat;
g_NavInfo.Longitude_degree = g_rtk.lon; g_NavInfo.Longitude_degree = g_rtk.lon;
g_NavInfo.Yaw_rad = g_rtk.direction; 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); // 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; return;