zhunk 3 months ago
parent
commit
7d07baee80

+ 1 - 1
Application_cbd_apm32f1/applications/control.h

@@ -17,7 +17,7 @@
 #define SENSOR_EN        0              //温湿度:0关闭,1打开
 #define PCB_V1           0             //1-旧PCB,0-新PCB(模块化)
 ////////////////////////////////////////////////////////////////
-#define VERSION_BZY         "3.11.5"                   //孢子仪
+#define VERSION_BZY         "3.11.6"                   //孢子仪
 
 
 /*********************************************************************/

+ 56 - 69
Application_cbd_apm32f1/applications/hmi.c

@@ -298,11 +298,11 @@ static void depth_of_field_fusion(void)
 
     LOG_I("[景深融合] 开始: 最佳位置=%d", best_pos);
 
-    /* ========== 第一阶段:往 dir=1 方向步进 10 次 ========== */
+    /* ========== 第一阶段:往 dir=1 方向步进 3 次 ========== */
     g_af.dir = 1;
-    for (i = 0; i < 10; i++) {
+    for (i = 0; i < 3; i++) {
         g_af.current_pos += step_size;
-        LOG_I("[景深融合] 正向步进[%d/10]: 位置=%d", i + 1, g_af.current_pos);
+        LOG_I("[景深融合] 正向步进[%d/3]: 位置=%d", i + 1, g_af.current_pos);
 
         slide_para.pulse_period = mapSpeed(1);
         slide_para.ystep = step_size;
@@ -333,51 +333,44 @@ static void depth_of_field_fusion(void)
 
     LOG_I("[景深融合] 正向步进完成: 位置=%d", g_af.current_pos);
 
-    /* ========== 第一阶段:回到最清晰位置 ========== */
-    if (g_af.current_pos > best_pos) {
-        g_af.dir = 0;  // 反向移动
-        int steps_back = (g_af.current_pos - best_pos) / step_size;
-        if ((g_af.current_pos - best_pos) % step_size != 0) {
-            steps_back++;  // 向上取整
-        }
-        for (i = 0; i < steps_back && g_af.current_pos > best_pos; i++) {
-            g_af.current_pos -= step_size;
-            LOG_I("[景深融合] 返回最佳位置[%d/%d]: 位置=%d", i + 1, steps_back, g_af.current_pos);
-
-            slide_para.pulse_period = mapSpeed(1);
-            slide_para.ystep = step_size;
-            slide_para.ydir = g_af.dir;
-            slide_para.ydis = step_size;
-            slide_para.en_slide = 6;
+    /* ========== 第一阶段:直接回到最清晰位置 ========== */
+    if (g_af.current_pos != best_pos) {
+        int move_dist = best_pos - g_af.current_pos;
+        LOG_I("[景深融合] 直接回到最佳位置: 移动距离=%d", move_dist);
 
-            /* 等待电机到位 */
-            while (slide_para.en_slide != 0) {
-                rt_thread_delay(100);
-            }
+        slide_para.pulse_period = mapSpeed(1);
+        slide_para.ystep = abs(move_dist);
+        slide_para.ydir = (move_dist > 0) ? 1 : 0;
+        slide_para.ydis = abs(move_dist);
+        slide_para.en_slide = 6;
 
-            /* 等待清晰度更新 */
+        /* 等待电机到位 */
+        while (slide_para.en_slide != 0) {
+            rt_thread_delay(100);
+        }
+
+        /* 等待清晰度更新 */
+        g_af.sharpness_updated = false;
+        rt_timer_start(timer_takephoto);
+        wait_count = 0;
+        while (!g_af.sharpness_updated && wait_count < 200) {
+            rt_thread_delay(50);
+            wait_count++;
+        }
+        if (g_af.sharpness_updated) {
+            LOG_I("[景深融合] 收到清晰度:%.2f", g_af.new_sharpness);
             g_af.sharpness_updated = false;
-            rt_timer_start(timer_takephoto);
-            wait_count = 0;
-            while (!g_af.sharpness_updated && wait_count < 200) {
-                rt_thread_delay(50);
-                wait_count++;
-            }
-            if (g_af.sharpness_updated) {
-                LOG_I("[景深融合] 收到清晰度:%.2f", g_af.new_sharpness);
-                g_af.sharpness_updated = false;
-            }
         }
+        g_af.current_pos = best_pos;
     }
 
-    g_af.current_pos = best_pos;
     LOG_I("[景深融合] 回到正向起点: 位置=%d", g_af.current_pos);
 
-    /* ========== 第二阶段:往 dir=0 方向步进 10 次 ========== */
+    /* ========== 第二阶段:往 dir=0 方向步进 3 次 ========== */
     g_af.dir = 0;
-    for (i = 0; i < 10; i++) {
+    for (i = 0; i < 3; i++) {
         g_af.current_pos -= step_size;
-        LOG_I("[景深融合] 反向步进[%d/10]: 位置=%d", i + 1, g_af.current_pos);
+        LOG_I("[景深融合] 反向步进[%d/3]: 位置=%d", i + 1, g_af.current_pos);
 
         slide_para.pulse_period = mapSpeed(1);
         slide_para.ystep = step_size;
@@ -408,41 +401,35 @@ static void depth_of_field_fusion(void)
 
     LOG_I("[景深融合] 反向步进完成: 位置=%d", g_af.current_pos);
 
-    /* ========== 第二阶段:回到最清晰位置 ========== */
-    if (g_af.current_pos < best_pos) {
-        g_af.dir = 1;  // 正向移动
-        int steps_forward = (best_pos - g_af.current_pos) / step_size;
-        if ((best_pos - g_af.current_pos) % step_size != 0) {
-            steps_forward++;  // 向上取整
-        }
-        for (i = 0; i < steps_forward && g_af.current_pos < best_pos; i++) {
-            g_af.current_pos += step_size;
-            LOG_I("[景深融合] 返回最佳位置[%d/%d]: 位置=%d", i + 1, steps_forward, g_af.current_pos);
-
-            slide_para.pulse_period = mapSpeed(1);
-            slide_para.ystep = step_size;
-            slide_para.ydir = g_af.dir;
-            slide_para.ydis = step_size;
-            slide_para.en_slide = 6;
+    /* ========== 第二阶段:直接回到最清晰位置 ========== */
+    if (g_af.current_pos != best_pos) {
+        int move_dist = best_pos - g_af.current_pos;
+        LOG_I("[景深融合] 直接回到最佳位置: 移动距离=%d", move_dist);
 
-            /* 等待电机到位 */
-            while (slide_para.en_slide != 0) {
-                rt_thread_delay(100);
-            }
+        slide_para.pulse_period = mapSpeed(1);
+        slide_para.ystep = abs(move_dist);
+        slide_para.ydir = (move_dist > 0) ? 1 : 0;
+        slide_para.ydis = abs(move_dist);
+        slide_para.en_slide = 6;
+
+        /* 等待电机到位 */
+        while (slide_para.en_slide != 0) {
+            rt_thread_delay(100);
+        }
 
-            /* 等待清晰度更新 */
+        /* 等待清晰度更新 */
+        g_af.sharpness_updated = false;
+        rt_timer_start(timer_takephoto);
+        wait_count = 0;
+        while (!g_af.sharpness_updated && wait_count < 200) {
+            rt_thread_delay(50);
+            wait_count++;
+        }
+        if (g_af.sharpness_updated) {
+            LOG_I("[景深融合] 收到清晰度:%.2f", g_af.new_sharpness);
             g_af.sharpness_updated = false;
-            rt_timer_start(timer_takephoto);
-            wait_count = 0;
-            while (!g_af.sharpness_updated && wait_count < 200) {
-                rt_thread_delay(50);
-                wait_count++;
-            }
-            if (g_af.sharpness_updated) {
-                LOG_I("[景深融合] 收到清晰度:%.2f", g_af.new_sharpness);
-                g_af.sharpness_updated = false;
-            }
         }
+        g_af.current_pos = best_pos;
     }
 
     g_af.current_pos = best_pos;