修改判断逻辑
authorzwj <645281962@qq.com>
Thu, 1 Jun 2023 09:59:22 +0000 (17:59 +0800)
committerzwj <645281962@qq.com>
Thu, 1 Jun 2023 09:59:22 +0000 (17:59 +0800)
tof/src/tof.c

index 49a618b2848b9109fe4a93a8c5035ea19d646229..24d447d31a2717689c0ccadec7b9053f31c2cfcc 100644 (file)
@@ -2136,6 +2136,7 @@ int32_t Obtain_distance_parameters()
 
 
 int distanceThreshold = 0; // 距离阈值
+int is_fixe = 0; //区分检测有人的两种情况,有障碍物检测有人=1,无障碍物检测有人=0
 /*
 线程服务函数
 参数定义:
@@ -2156,12 +2157,28 @@ void* tof_task(void* data)
                }
                run_meas_loop(1);
                range = (int)dev_1xrange_data.RangeMilliMeter;
-               if(range >= my_tof->default_range) 
+               if(range >= my_tof->default_range)
                {
+                       is_fixe = 0;
                        distanceThreshold = my_tof->default_range;
                }
-
-               if(range < (distanceThreshold - 10)){
+               if(is_fixe){//在有障碍物的情况下,才会执行
+                       usleep(500000);
+                       run_meas_loop(1);
+                       range = (int)dev_1xrange_data.RangeMilliMeter;
+                       if(range >= my_tof->default_range){
+                               is_fixe = 0;
+                               continue;
+                       }
+                       else if((my_info->status != TOF_ANYBODY) && ((range < distanceThreshold-10) || (range > distanceThreshold+10))){
+                               my_info->distance = range;
+                               my_info->status = TOF_ANYBODY;
+                               if(tof_event != NULL){
+                                       tof_event(my_info);
+                               }
+                       }
+               }
+               else if(range < (distanceThreshold - 10)){//正常情况检测有人
                        if(my_info->status != TOF_ANYBODY){
                                my_info->distance = range;
                                my_info->status = TOF_ANYBODY;
@@ -2169,8 +2186,8 @@ void* tof_task(void* data)
                                        tof_event(my_info);
                                }
                        }
-
-               }else if(range > my_tof->default_range){
+               }
+               else if(range > my_tof->default_range){
                        if(my_info->status != TOF_NOBODY){
                                my_info->distance = range;
                                my_info->status = TOF_NOBODY;
@@ -2190,6 +2207,7 @@ void* tof_task(void* data)
                                        my_info->distance = range1;
                                        my_info->status = TOF_FIXED_BARRIER;
                                        distanceThreshold = range1;
+                                       is_fixe = 1;
                                        if(tof_event != NULL){
                                                tof_event(my_info);
                                        }
@@ -2326,4 +2344,4 @@ int32_t Distance_parameter_correction(mg_tof_t *tof_ctrl,uint32_t distance)
                return -1;
        }
        return 0;
-}
+}
\ No newline at end of file