zhunk 10 hónapja
szülő
commit
b732a56d39

+ 5 - 2
Application_cbd_apm32f1/applications/control.c

@@ -955,6 +955,7 @@ static void Work_status_thread_entry(void *parameter)
 
 
          if(device_status.ds==0||device_status.temp_status==1){
          if(device_status.ds==0||device_status.temp_status==1){
              device_status.work_status = 0;
              device_status.work_status = 0;
+             rt_thread_delay(5000);
              continue;
              continue;
          }
          }
 
 
@@ -1083,7 +1084,9 @@ void slide_thread_entry(void *parameter)
                 rt_kprintf("The slide's y movement was done ok\n");
                 rt_kprintf("The slide's y movement was done ok\n");
                 rt_thread_delay(1000);
                 rt_thread_delay(1000);
                 if(1){
                 if(1){
-                    char *photo = makeJson_Warn("movy","done");
+                    char utos[5];
+                    rt_sprintf(utos,"%d",slide_para.ystep);
+                    char *photo = makeJson_Warn("movy",utos);
                     LOG_I("%s",photo);
                     LOG_I("%s",photo);
                     DTU_Write("%s",photo);
                     DTU_Write("%s",photo);
                     rt_free(photo);
                     rt_free(photo);
@@ -1122,7 +1125,7 @@ int Workstatus_check(void)
 {
 {
 
 
     /* 创建线程*/
     /* 创建线程*/
-    tid_wkstc = rt_thread_create("work_status_check_thread",
+    tid_wkstc = rt_thread_create("w_s_c_t",
                                 Work_status_thread_entry, RT_NULL,
                                 Work_status_thread_entry, RT_NULL,
                                 WORK_CHECK_THREAD_STACK_SIZE,       //1024
                                 WORK_CHECK_THREAD_STACK_SIZE,       //1024
                                 WORK_CHECK_THREAD_PRIORITY,         //23
                                 WORK_CHECK_THREAD_PRIORITY,         //23

+ 4 - 2
Application_cbd_apm32f1/applications/control.h

@@ -17,7 +17,7 @@
 #define SENSOR_EN        1              //温湿度:0关闭,1打开
 #define SENSOR_EN        1              //温湿度:0关闭,1打开
 ////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////
 
 
-#define VERSION_BZY         "2.6.12"                   //孢子仪
+#define VERSION_BZY         "2.6.13"                   //孢子仪
 
 
 
 
 /*********************************************************************/
 /*********************************************************************/
@@ -37,6 +37,7 @@ typedef struct  _packed
     uint8_t wind_sw;              //风机开关   0-关   1-开
     uint8_t wind_sw;              //风机开关   0-关   1-开
     uint8_t collect_fan_status;   //采集状态   0-关   1-开
     uint8_t collect_fan_status;   //采集状态   0-关   1-开
     uint8_t autotakepic;          //对焦拍照   0-关   1-开
     uint8_t autotakepic;          //对焦拍照   0-关   1-开
+    uint8_t calibrate_slide;            //校准开关   0-关   1 X 2 Y 3 Z
     uint8_t develop_flag;         //是否进入培养模式
     uint8_t develop_flag;         //是否进入培养模式
     uint8_t cool_fan_status;      //散热风机状态 0-停止 1-打开
     uint8_t cool_fan_status;      //散热风机状态 0-停止 1-打开
     uint8_t fsl_sw;               //凡士林开关:0-关,1-开
     uint8_t fsl_sw;               //凡士林开关:0-关,1-开
@@ -161,7 +162,8 @@ typedef struct
     uint32_t xdis;           //x轴坐标移动距离
     uint32_t xdis;           //x轴坐标移动距离
     uint32_t ydis;
     uint32_t ydis;
     uint32_t zdis;           //z轴坐标移动距离
     uint32_t zdis;           //z轴坐标移动距离
-    uint32_t pulse_period;    //滑台的运动速度  1为最高
+    uint32_t ystep;          //y步进距离
+    uint32_t pulse_period;   //滑台的运动速度  1为最高
     uint16_t dxdis;          //x轴坐标蛇形移动间距距离
     uint16_t dxdis;          //x轴坐标蛇形移动间距距离
     uint16_t dzdis;          //z轴坐标蛇形移动间距距离
     uint16_t dzdis;          //z轴坐标蛇形移动间距距离
     uint8_t xdir;            //x轴坐标移动方向
     uint8_t xdir;            //x轴坐标移动方向

+ 18 - 3
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -666,6 +666,7 @@ int parseDtu(char *json_string)
     cJSON* movx = NULL;
     cJSON* movx = NULL;
     cJSON* movy = NULL;
     cJSON* movy = NULL;
     cJSON* movz = NULL;
     cJSON* movz = NULL;
+    cJSON* calibrate = NULL;
     cJSON* speed = NULL;
     cJSON* speed = NULL;
     rt_kprintf("解析串口接受区数据:%s\n",json_string);
     rt_kprintf("解析串口接受区数据:%s\n",json_string);
     //LOG_I("解析串口接受区数据:%s",json_string);
     //LOG_I("解析串口接受区数据:%s",json_string);
@@ -683,7 +684,12 @@ int parseDtu(char *json_string)
           item_focus = cJSON_GetObjectItem(root,"focus");
           item_focus = cJSON_GetObjectItem(root,"focus");
           if(item_focus!=RT_NULL){
           if(item_focus!=RT_NULL){
               device_status.focus_value = item_focus->valuedouble;
               device_status.focus_value = item_focus->valuedouble;
-              send_signal();
+              if(device_status.calibrate_slide==0){
+                  send_signal(SIGUSR1);
+              }else{
+                  send_signal(SIGUSR2);
+              }
+
           }
           }
 
 
           if(item_cmd!=RT_NULL)
           if(item_cmd!=RT_NULL)
@@ -699,6 +705,7 @@ int parseDtu(char *json_string)
                   ctr_led(ON);
                   ctr_led(ON);
               }
               }
               if(strstr(item_cmd->valuestring,"ledoff")!=RT_NULL){
               if(strstr(item_cmd->valuestring,"ledoff")!=RT_NULL){
+                  device_status.calibrate_slide = 0;
                   ctr_Cold(OFF);
                   ctr_Cold(OFF);
                   ctr_led(OFF);
                   ctr_led(OFF);
                   slidelock();
                   slidelock();
@@ -721,8 +728,18 @@ int parseDtu(char *json_string)
                  movx = cJSON_GetObjectItem(item_ext,"movx");
                  movx = cJSON_GetObjectItem(item_ext,"movx");
                  movy = cJSON_GetObjectItem(item_ext,"movy");
                  movy = cJSON_GetObjectItem(item_ext,"movy");
                  movz = cJSON_GetObjectItem(item_ext,"movz");
                  movz = cJSON_GetObjectItem(item_ext,"movz");
+                 calibrate = cJSON_GetObjectItem(item_ext,"calibrate");
                  speed = cJSON_GetObjectItem(item_ext,"speed");
                  speed = cJSON_GetObjectItem(item_ext,"speed");
 
 
+                 if(calibrate!=RT_NULL){
+                     if(calibrate->type==cJSON_String)
+                     {
+                         LOG_D("校准:%s",calibrate->valuestring);
+                         if(strstr(calibrate->valuestring,"x")!=RT_NULL) device_status.calibrate_slide = 1;
+                         if(strstr(calibrate->valuestring,"y")!=RT_NULL) device_status.calibrate_slide = 2;
+                         if(strstr(calibrate->valuestring,"z")!=RT_NULL) device_status.calibrate_slide = 3;
+                     }
+                 }
                  if(speed!=RT_NULL){
                  if(speed!=RT_NULL){
                      if(speed->type==cJSON_String)
                      if(speed->type==cJSON_String)
                      {
                      {
@@ -953,8 +970,6 @@ int parseDtu(char *json_string)
                   mqttcfg2 = cJSON_GetObjectItem(item_ext,"mqttcfg2");
                   mqttcfg2 = cJSON_GetObjectItem(item_ext,"mqttcfg2");
                   link_sta = cJSON_GetObjectItem(item_ext,"link_sta");
                   link_sta = cJSON_GetObjectItem(item_ext,"link_sta");
                   photo_sta = cJSON_GetObjectItem(item_ext,"photo_sta");
                   photo_sta = cJSON_GetObjectItem(item_ext,"photo_sta");
-                  cJSON *gps_inuse = cJSON_GetObjectItem(item_ext,"gps_inuse");
-                  cJSON *gps_view = cJSON_GetObjectItem(item_ext,"gps_view");
                   //如果DTU的IMEI和FLash中的不一样,保存到FLASH
                   //如果DTU的IMEI和FLash中的不一样,保存到FLASH
                   value_commn = cJSON_GetObjectItem(item_ext,"photo_sta");
                   value_commn = cJSON_GetObjectItem(item_ext,"photo_sta");
                   if(photo_sta!=NULL){
                   if(photo_sta!=NULL){

+ 87 - 7
Application_cbd_apm32f1/applications/hmi.c

@@ -1204,15 +1204,15 @@ int findMaxIndex(double arr[], int size) {
 }
 }
 
 
 
 
-void send_signal(void)
+void send_signal(int sig)
 {
 {
-    rt_thread_kill(ctr_motor, SIGUSR1);
+    rt_thread_kill(ctr_motor, sig);
 }
 }
 
 
 // 全局状态变量(需在合适位置初始化)
 // 全局状态变量(需在合适位置初始化)
 static float g_best_sharpness = -FLT_MAX;    // 全局最佳清晰度
 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 = 0.0;    // 上一次移动后的清晰度
 static bool g_initial_move = true;           // 初始方向判断标志
 static bool g_initial_move = true;           // 初始方向判断标志
 static bool focus_done = false;
 static bool focus_done = false;
 int maxIterations = 100;
 int maxIterations = 100;
@@ -1316,6 +1316,7 @@ void thread1_signal_handler(int sig)
 
 
         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&&current_sharpness>g_best_sharpness*0.95){
         if(g_peak_counter>=3&&current_sharpness>g_best_sharpness*0.95){
             focus_done = true;
             focus_done = true;
         }else{
         }else{
@@ -1347,7 +1348,7 @@ void thread1_signal_handler(int sig)
                 return;
                 return;
             }
             }
         }
         }
-
+        slide_para.ystep = stepSize;
         slide_para.ydir = dir;
         slide_para.ydir = dir;
         slide_para.ydis = stepSize;
         slide_para.ydis = stepSize;
         slide_para.en_slide = 6;  // 触发移动
         slide_para.en_slide = 6;  // 触发移动
@@ -1357,15 +1358,77 @@ void thread1_signal_handler(int sig)
     }
     }
 }
 }
 
 
+void thread2_signal_handler(int sig)
+{
+    rt_timer_stop(timer_takephoto);
+    maxIterations--;
+    LOG_I("[Y] 清晰度值更新:%.2f", device_status.focus_value);
+    slide_para.pulse_period = mapSpeed(slide_para.pulse_period);  // 更新电机速度参数
+    if(device_status.calibrate_slide==20&& maxIterations >= 0){
+        float current_sharpness = device_status.focus_value;
+        /* 更新全局最佳状态 */
+        if (current_sharpness > g_best_sharpness) {
+            g_best_sharpness = current_sharpness;
+            LOG_I("[Y] 发现更佳位置(清晰度:%.2f)",g_best_sharpness);
+        }
+        /* 初始方向判断(首步移动后) */
+        if (g_initial_move) {
+            if (current_sharpness > g_last_sharpness) {
+                LOG_I("[对焦] 初始方向正确,保持方向:%d", dir);
+            }
+            g_initial_move = false;
+        }else{
+            double diff_sharpness =  fabs(current_sharpness-g_last_sharpness);
+            if(diff_sharpness<1.0)
+            {
+                counter_sharpness_diff++;
+            }
+
+            LOG_I("[Y] 清晰度变化累计%d次小于1.0",counter_sharpness_diff);
+            if(counter_sharpness_diff>1&&diff_sharpness>100.0){
+                //停止,保存当前位置
+                device_status.y_init_dis = slide_para.ystep;
+                LOG_I("设置Y轴初始位置:%d",slide_para.ystep);
+                ef_set_env_blob("y_init_dis", &device_status.y_init_dis, sizeof(device_status.y_init_dis));
+                return;
+            }
+            /* 记录本次清晰度值 */
+            g_last_sharpness = current_sharpness;
+        }
+
+        /* 终止条件检测 */
+        if (maxIterations <= 0) {
+            device_status.calibrate_slide = 0;
+            return;
+        }
+        slide_para.ydir = dir;
+        slide_para.ydis = 80;
+        slide_para.ystep += 80;
+        slide_para.en_slide = 6;  // 触发移动
+        while (slide_para.en_slide != 0) {
+            rt_thread_delay(500); // 等待移动完成
+        }
+    }
+
+}
+
 
 
 //入口函数-电机控制及
 //入口函数-电机控制及
 static void Ctr_Mortor_entry(void* parameter)
 static void Ctr_Mortor_entry(void* parameter)
 {
 {
    /*孢子仪2.0*/
    /*孢子仪2.0*/
-   rt_signal_install(SIGUSR1, thread1_signal_handler);
+   rt_signal_install(SIGUSR1, thread1_signal_handler);  //自动对焦信号
+   rt_signal_install(SIGUSR2, thread2_signal_handler);  //坐标校准信号
    rt_signal_unmask(SIGUSR1);
    rt_signal_unmask(SIGUSR1);
+   rt_signal_unmask(SIGUSR2);
     while(1)
     while(1)
     {
     {
+        if(device_status.calibrate_slide==2)
+        {
+            device_status.autotakepic=1;
+            device_status.calibrate_slide = 20;
+        }
+
         /*对焦拍照,滑台初始化*/
         /*对焦拍照,滑台初始化*/
         if(device_status.autotakepic==1)
         if(device_status.autotakepic==1)
         {
         {
@@ -1403,7 +1466,24 @@ static void Ctr_Mortor_entry(void* parameter)
                     rt_thread_delay(1000);
                     rt_thread_delay(1000);
                 }
                 }
             }
             }
-            device_status.autotakepic = 3;
+            if(device_status.calibrate_slide==0){
+                device_status.autotakepic = 3;
+            }else{
+                slide_para.en_slide = 7;    //Y轴复位
+                slide_para.pulse_period = mapSpeed(50);
+                while(slide_para.en_slide!=0){
+                    LOG_D("等待Y轴电机完成复位!");
+                    rt_thread_delay(1000);
+                }
+                rt_thread_delay(1000);
+
+                //生成JSON指令
+                char *photo = makeJson_Warn("mov_init_y","takephoto_done");
+                DTU_Write("%s",photo);
+                rt_free(photo);
+                device_status.autotakepic = 4;
+                rt_timer_start(timer_takephoto);
+            }
         }
         }
         if(device_status.autotakepic==3)
         if(device_status.autotakepic==3)
         {
         {
@@ -1442,7 +1522,7 @@ static void Ctr_Mortor_entry(void* parameter)
             dir = 1;
             dir = 1;
             stepSize = 20;     // 初始步长(单位:步进电机脉冲数)
             stepSize = 20;     // 初始步长(单位:步进电机脉冲数)
             current_pos = 0;  // 根据实际类型修改(int/float等)
             current_pos = 0;  // 根据实际类型修改(int/float等)
-
+            slide_para.ystep = 0;
             g_peak_counter = 0;
             g_peak_counter = 0;
             g_last_rising = false;
             g_last_rising = false;
             focus_done = false;
             focus_done = false;

+ 1 - 1
Application_cbd_apm32f1/applications/hmi.h

@@ -34,6 +34,6 @@ void Debug_log_ON(void);
 void bubblesort(int a[], int n);
 void bubblesort(int a[], int n);
 
 
 
 
-void send_signal(void);
+void send_signal(int sig);
 
 
 #endif /* APPLICATIONS_INC_HMI_H_ */
 #endif /* APPLICATIONS_INC_HMI_H_ */

+ 4 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,7 @@
+# 2025-12-26 更新说明
+	#define VERSION_BZY         "2.6.13"                   //孢子仪
+	增加坐标辅助校准功能
+
 # 2025-12-19 更新说明
 # 2025-12-19 更新说明
 	#define VERSION_BZY         "2.6.12"                   //孢子仪
 	#define VERSION_BZY         "2.6.12"                   //孢子仪
 	修复下发设置tph不解析问题
 	修复下发设置tph不解析问题