zhunk 1 éve
szülő
commit
8c56facadf

+ 1 - 1
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -458,7 +458,7 @@ int dtu_data_play(void)
     rt_err_t rm_dtu_result;
     rt_err_t rm_dtu_result;
     DTU_uart2_init();
     DTU_uart2_init();
     //初始化消息队列
     //初始化消息队列
-    rm_dtu_result = rt_mq_init(&rx_mq_dtu, "dtu", &data_arry.msg_pool[0], 128 - sizeof(void*), sizeof(data_arry.msg_pool), RT_IPC_FLAG_FIFO);
+    rm_dtu_result = rt_mq_init(&rx_mq_dtu, "dtu", &data_arry.msg_pool[0], 512 - sizeof(void*), sizeof(data_arry.msg_pool), RT_IPC_FLAG_FIFO);
     if(rm_dtu_result==RT_EOK)
     if(rm_dtu_result==RT_EOK)
     {
     {
         rt_kprintf("消息队列创建成功!!");
         rt_kprintf("消息队列创建成功!!");

+ 25 - 11
Application_cbd_apm32f1/applications/hmi.c

@@ -1356,6 +1356,7 @@ static float g_best_sharpness = -FLT_MAX;    // 全局最佳清晰度
 static int g_best_pos = 0;                   // 全局最佳位置
 static int g_best_pos = 0;                   // 全局最佳位置
 static float g_last_sharpness = -FLT_MAX;    // 上一次移动后的清晰度
 static float g_last_sharpness = -FLT_MAX;    // 上一次移动后的清晰度
 static bool g_initial_move = true;           // 初始方向判断标志
 static bool g_initial_move = true;           // 初始方向判断标志
+static bool focus_done = false;
 int maxIterations = 100;
 int maxIterations = 100;
 uint8_t dir = 1;
 uint8_t dir = 1;
 uint8_t stepSize = 20;     // 初始步长(单位:步进电机脉冲数)
 uint8_t stepSize = 20;     // 初始步长(单位:步进电机脉冲数)
@@ -1454,36 +1455,45 @@ void thread1_signal_handler(int sig)
             counter_sharpness_diff = 0;
             counter_sharpness_diff = 0;
         }
         }
 
 
-        slide_para.ydir = dir;
-        slide_para.ydis = stepSize;
-        slide_para.en_slide = 6;  // 触发移动
-        while (slide_para.en_slide != 0) {
-            rt_thread_delay(500); // 等待移动完成
-        }
+        LOG_I("[对焦] 更佳位置:%d (清晰度:%.2f)", g_best_pos, g_best_sharpness);
 
 
+        if(g_peak_counter>=3&&current_sharpness>g_best_sharpness-3.0f){
+            focus_done = true;
+        }else{
+            focus_done = false;
+            g_best_sharpness -= 3.0f;   //降低阈值,防止找不到
+        }
 
 
         /* 终止条件检测 */
         /* 终止条件检测 */
-        if (counter_sharpness_diff>=100||maxIterations <= 0 || g_peak_counter >= 3) {
+        if (counter_sharpness_diff>=100||maxIterations <= 0 || focus_done==true) {
+            counter_sharpness_reduce = 0;
+            maxIterations = 100;
             LOG_I("[对焦] 完成搜索,最佳位置:%d (清晰度:%.2f)", g_best_pos, g_best_sharpness);
             LOG_I("[对焦] 完成搜索,最佳位置:%d (清晰度:%.2f)", g_best_pos, g_best_sharpness);
             if (g_peak_counter >= 3) {
             if (g_peak_counter >= 3) {
                 LOG_I("[对焦] 连续三次波动确认峰值");
                 LOG_I("[对焦] 连续三次波动确认峰值");
             }
             }
-
+            focus_done = false;
             LOG_I("[对焦] 已到达最佳对焦位置");
             LOG_I("[对焦] 已到达最佳对焦位置");
             if(maxIterations==0)
             if(maxIterations==0)
             {
             {
                 stepSize = 20;
                 stepSize = 20;
                 dir = !dir;
                 dir = !dir;
                 current_pos = 0;
                 current_pos = 0;
-                maxIterations = 100;
             }else{
             }else{
                 counter_sharpness_diff = 0;
                 counter_sharpness_diff = 0;
                 char *c0 = makeJson_Warn("auto_focus","auto_focus");
                 char *c0 = makeJson_Warn("auto_focus","auto_focus");
                 DTU_Write("%s",c0);
                 DTU_Write("%s",c0);
                 rt_free(c0);
                 rt_free(c0);
                 device_status.autotakepic = 0; // 退出自动对焦模式
                 device_status.autotakepic = 0; // 退出自动对焦模式
+                return;
             }
             }
-            counter_sharpness_reduce = 0;
+        }
+
+        slide_para.ydir = dir;
+        slide_para.ydis = stepSize;
+        slide_para.en_slide = 6;  // 触发移动
+        while (slide_para.en_slide != 0) {
+            rt_thread_delay(500); // 等待移动完成
         }
         }
     }
     }
 }
 }
@@ -1573,6 +1583,7 @@ static void Ctr_Mortor_entry(void* parameter)
 
 
             g_peak_counter = 0;
             g_peak_counter = 0;
             g_last_rising = false;
             g_last_rising = false;
+            focus_done = false;
             //启动超时检测定时器
             //启动超时检测定时器
         }
         }
         if(device_status.fsl_sw==1)
         if(device_status.fsl_sw==1)
@@ -1584,7 +1595,7 @@ static void Ctr_Mortor_entry(void* parameter)
         {
         {
             //开始采集风机持续5S
             //开始采集风机持续5S
             ctr_router(ON);
             ctr_router(ON);
-            rt_thread_delay(1000*120);
+            rt_thread_delay(1000*60);
             //关闭采集风机
             //关闭采集风机
             ctr_router(OFF);
             ctr_router(OFF);
             //胶带传送
             //胶带传送
@@ -1593,6 +1604,9 @@ static void Ctr_Mortor_entry(void* parameter)
             //拍一张照片上传到平台
             //拍一张照片上传到平台
             device_status.autotakepic=1;
             device_status.autotakepic=1;
             device_status.auto_test_sw=0;
             device_status.auto_test_sw=0;
+            char *take_start = makeJson_Warn("start", "autofocus");
+            DTU_Write(take_start);
+            rt_free(take_start);
         }
         }
         rt_thread_delay(10);
         rt_thread_delay(10);
     }
     }

+ 1 - 1
Application_cbd_apm32f1/applications/selfcheck.c

@@ -289,7 +289,7 @@ int selfcheck(uint8_t type)
 int rt_software_timer_init(void)
 int rt_software_timer_init(void)
 {
 {
     //启动拍照超时定时器
     //启动拍照超时定时器
-    timer_takephoto = rt_timer_create("t_takephoto",t_takephoto_callback,RT_NULL, 20000, RT_TIMER_FLAG_ONE_SHOT|RT_TIMER_FLAG_HARD_TIMER);
+    timer_takephoto = rt_timer_create("t_takephoto",t_takephoto_callback,RT_NULL, 60000, RT_TIMER_FLAG_ONE_SHOT|RT_TIMER_FLAG_HARD_TIMER);
     if(timer_takephoto==RT_NULL)
     if(timer_takephoto==RT_NULL)
     {
     {
         LOG_E("rt_timer_create t_takephoto failed!");
         LOG_E("rt_timer_create t_takephoto failed!");