From 0af4a7793d92a7094ad382b66d941550aa6644b3 Mon Sep 17 00:00:00 2001 From: zwj <645281962@qq.com> Date: Mon, 10 Jul 2023 17:22:24 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E5=9C=A8=E6=97=A0=E4=BA=BA?= =?utf8?q?=E8=AE=A1=E6=97=B6=E6=9C=9F=E9=97=B4=E7=8A=B6=E6=80=81=E8=B7=B3?= =?utf8?q?=E8=BD=AC=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- tof/src/tof.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/tof/src/tof.c b/tof/src/tof.c index d3a6857..44139d1 100644 --- a/tof/src/tof.c +++ b/tof/src/tof.c @@ -2146,7 +2146,7 @@ int32_t Obtain_distance_parameters() void nobody_timer_handler(int signum) { - if(tof_event != NULL){ + if(tof_event != NULL && my_info->status != TOF_NOBODY){ my_info->distance = range; my_info->status = TOF_NOBODY; printf("== 无 人 ==\n"); @@ -2168,14 +2168,14 @@ void fixed_timer_handler(int signum) run_meas_loop(3); usleep(180 * 1000); range2 = (int)dev_1xrange_data.RangeMilliMeter; - if((abs(range1 - range2) <= 3 || range2 - range1 == 0) && my_info->status != TOF_FIXED_BARRIER) + if(abs(range1 - range2) <= 3 || range2 - range1 == 0) { - my_info->distance = range2; - my_info->status = TOF_FIXED_BARRIER; - distanceThreshold = range2; is_fixe = 1; TIMER_NOBODY = 1; - if(tof_event != NULL){ + if(tof_event != NULL && my_info->status != TOF_FIXED_BARRIER){ + my_info->distance = range2; + my_info->status = TOF_FIXED_BARRIER; + distanceThreshold = range2; printf("== 障 碍 物 ==\n"); tof_event(my_info); } @@ -2236,7 +2236,8 @@ static void start_timer(int sele_timer) //无人判定定时器 it.it_interval.tv_sec = 0; it.it_interval.tv_nsec = 0; - it.it_value.tv_sec = nobody_timer_secs;//修改这个值来改变有人到无人的判断时间 + //it.it_value.tv_sec = nobody_timer_secs;//修改这个值来改变有人到无人的判断时间 + it.it_value.tv_sec = 5;//修改这个值来改变有人到无人的判断时间 it.it_value.tv_nsec = 0; timer_settime(nobody_timer, 0, &it, NULL); break; @@ -2278,28 +2279,28 @@ void* tof_task(void* data) is_fixe = 0; continue; } - else if((my_info->status != TOF_ANYBODY) && ((range < distanceThreshold-5) || (range > distanceThreshold+5))){ - my_info->distance = range; - my_info->status = TOF_ANYBODY; - timer_flag = 1; - if(tof_event != NULL){ + else if(range < distanceThreshold-5 || range > distanceThreshold+5){ + if(tof_event != NULL && my_info->status != TOF_ANYBODY){ + timer_flag = 1; + my_info->distance = range; + my_info->status = TOF_ANYBODY; printf("== 有 人 ==\n"); tof_event(my_info); } } } //正常情况检测有人 - if(range < (distanceThreshold - 10) && my_info->status != TOF_ANYBODY){ - my_info->distance = range; - my_info->status = TOF_ANYBODY; - timer_flag = 1; + if(range < (distanceThreshold - 10)){ TIMER_NOBODY = 1; - if(tof_event != NULL){ + if(tof_event != NULL && my_info->status != TOF_ANYBODY){ + timer_flag = 1; + my_info->distance = range; + my_info->status = TOF_ANYBODY; printf("== 有 人 ==\n"); tof_event(my_info); } } - if(my_info->status != TOF_NOBODY && range > my_tof->default_range){ + if(range > my_tof->default_range){ if(TIMER_NOBODY == 1){ TIMER_NOBODY = 0; start_timer(1); -- 2.34.1