From 9fae087fed230a9737f7c8e8bb99a86ca3ad38b3 Mon Sep 17 00:00:00 2001 From: wangfq Date: Fri, 3 Jul 2026 09:13:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BB=E5=8A=A8=E4=B8=8A=E6=8A=A5?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=87=8F=20=E2=80=94=20=E8=A1=A5=E9=BD=90?= =?UTF-8?q?=E8=BD=A6=E9=97=B4=E8=B7=9D=E6=97=B6=E9=97=B4=20(gap=20time)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Loop154_Unit 新增 last_exit_tick 字段,记录上次离场时间戳 - 进场: misc_value = 车间距 (report_counter - last_exit_tick), 首车为0 - 离场 (flatness/cnt_release): 记录 last_exit_tick, misc_value = 通过时间 - 有限存在超时: 也记录 last_exit_tick, 确保下一辆车车间距正确 四通道独立计算, 单位 5ms tick --- .../utilities/at32f421_freertos_demo/inc/TaskLoop.h | 3 ++- .../utilities/at32f421_freertos_demo/src/TaskLoop.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h b/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h index 38f705d..f11facf 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h +++ b/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h @@ -181,7 +181,8 @@ typedef struct { /*--- 主动上报杂项计数 ---*/ uint32_t flow_count; // 车流量累计 uint32_t relay_count; // 继电器动作次数 - uint32_t passtime_start; // 进场/离开 时间戳(5ms tick) + uint32_t passtime_start; // 进场 时间戳(5ms tick) + uint32_t last_exit_tick; // 上次离场 时间戳(5ms tick), 用于车间距计算 uint32_t misc_value; // 当前要上报的杂项值 } Loop154_Unit; diff --git a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c index d1fb294..1d26040 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c @@ -313,6 +313,7 @@ void TMR15_GLOBAL_IRQHandler(void) unit->loop_stable = 0; unit->loop_ORG_CNT = 0; unit->loop_ORG_SUM = 0; + unit->last_exit_tick = g_loop_states.report_counter; #if USE_FLATNESS_EXIT unit->exit_state = 0; unit->max_slope = 0; @@ -518,11 +519,15 @@ void vd1_task_per_channel(Loop154_Unit *unit) unit->loop_freeze_cnt = 0; unit->loop_freeze_ref = 0; - /* 主动上报: 车流量+1, 继电器+1, 记录进场时间戳 */ + /* 主动上报: 车流量+1, 继电器+1, 车间距, 记录进场时间戳 */ unit->flow_count++; unit->relay_count++; + if (unit->last_exit_tick > 0) { + unit->misc_value = g_loop_states.report_counter - unit->last_exit_tick; + } else { + unit->misc_value = 0; // 首次检测, 车间距为0 + } unit->passtime_start = g_loop_states.report_counter; // 5ms tick - unit->misc_value = 0; // 车间距将在离开时计算 if (unit->hold_time > 0) { unit->loop_VD_HOLD = 1; } @@ -605,6 +610,7 @@ void vd1_task_per_channel(Loop154_Unit *unit) /* 主动上报: 计算通过时间 = 当前-进场时间戳 (5ms单位) */ unit->misc_value = g_loop_states.report_counter - unit->passtime_start; + unit->last_exit_tick = g_loop_states.report_counter; unit->relay_count++; // 离开时继电器翻转 } } else { @@ -636,6 +642,7 @@ void vd1_task_per_channel(Loop154_Unit *unit) /* 主动上报: 通过时间 + 继电器 */ unit->misc_value = g_loop_states.report_counter - unit->passtime_start; + unit->last_exit_tick = g_loop_states.report_counter; unit->relay_count++; } } else {