修改在无人计时期间状态跳转的问题
authorzwj <645281962@qq.com>
Mon, 10 Jul 2023 09:22:24 +0000 (17:22 +0800)
committerzwj <645281962@qq.com>
Mon, 10 Jul 2023 09:22:24 +0000 (17:22 +0800)
tof/src/tof.c

index d3a6857a3a0cb5a773c9cbf697a8fae9bf74c8cc..44139d1c9ec34d64dcad227bdf12c91e33e0dbb2 100644 (file)
@@ -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);