优化tof传感器
authorzwj <645281962@qq.com>
Fri, 2 Jun 2023 05:45:09 +0000 (13:45 +0800)
committerzwj <645281962@qq.com>
Fri, 2 Jun 2023 05:45:09 +0000 (13:45 +0800)
tof/src/tof.c

index 24d447d31a2717689c0ccadec7b9053f31c2cfcc..b7a08ca350017ef84ec4610f391a9950132d4761 100644 (file)
@@ -2148,13 +2148,13 @@ void* tof_task(void* data)
 {
        int rc = 0;
        uint32_t prev_ts = -1;
-       int range = 0 , range1 = 0;
+       int range = 0 , range1 = 0 ,range2=0;
        while(stop){
-               usleep(10000);
                if(tof_status == 0){
                        usleep(100000);
                        continue;
                }
+               usleep(1000);
                run_meas_loop(1);
                range = (int)dev_1xrange_data.RangeMilliMeter;
                if(range >= my_tof->default_range)
@@ -2164,7 +2164,7 @@ void* tof_task(void* data)
                }
                if(is_fixe){//在有障碍物的情况下,才会执行
                        usleep(500000);
-                       run_meas_loop(1);
+                       run_meas_loop(2);
                        range = (int)dev_1xrange_data.RangeMilliMeter;
                        if(range >= my_tof->default_range){
                                is_fixe = 0;
@@ -2178,7 +2178,10 @@ void* tof_task(void* data)
                                }
                        }
                }
-               else if(range < (distanceThreshold - 10)){//正常情况检测有人
+               usleep(100000);
+               run_meas_loop(5);
+               range = (int)dev_1xrange_data.RangeMilliMeter;
+               if(range < (distanceThreshold - 10)){//正常情况检测有人
                        if(my_info->status != TOF_ANYBODY){
                                my_info->distance = range;
                                my_info->status = TOF_ANYBODY;
@@ -2198,18 +2201,28 @@ void* tof_task(void* data)
                }
                if(my_info-> status == TOF_ANYBODY )
                {
-                       sleep(2);
+                       usleep(500000);
                        run_meas_loop(1);
                        range1 = (int)dev_1xrange_data.RangeMilliMeter;
-                       if(abs(range1 - range) <= 3 || range - range1 == 0)
+                       if(range1 > my_tof->default_range)
+                       {
+                               continue;
+                       }
+                       else
                        {
-                               if(my_info->status != TOF_FIXED_BARRIER) {
-                                       my_info->distance = range1;
-                                       my_info->status = TOF_FIXED_BARRIER;
-                                       distanceThreshold = range1;
-                                       is_fixe = 1;
-                                       if(tof_event != NULL){
-                                               tof_event(my_info);
+                               sleep(1);
+                               run_meas_loop(1);
+                               range2 = (int)dev_1xrange_data.RangeMilliMeter;
+                               if(abs(range1 - range2) <= 3 || range2 - range1 == 0)
+                               {
+                                       if(my_info->status != TOF_FIXED_BARRIER) {
+                                               my_info->distance = range2;
+                                               my_info->status = TOF_FIXED_BARRIER;
+                                               distanceThreshold = range2;
+                                               is_fixe = 1;
+                                               if(tof_event != NULL){
+                                                       tof_event(my_info);
+                                               }
                                        }
                                }
                        }