Explorar o código

电机驱动优化

zhunk hai 1 ano
pai
achega
43f550445b

+ 5 - 2
Application_cbd_apm32f1/applications/beep.c

@@ -181,8 +181,11 @@ int hwtimer2_pwm3_output(rt_uint32_t time,rt_uint32_t freq,uint8_t EN,uint8_t DI
         rt_pwm_enable(pwm_device, BEEP_PWM_CH); //使能蜂鸣器对应的 PWM 通道
     return 0;
 }
-
-static void stop_motor_86(void)
+void pwm_motor86_enable(rt_uint32_t freq)
+{
+    beep_set(freq,freq/2);
+}
+void stop_motor_86(void)
 {
     LOG_W("stop_motor_86!");
     rt_pwm_disable(pwm_device, BEEP_PWM_CH);

+ 3 - 0
Application_cbd_apm32f1/applications/beep.h

@@ -30,6 +30,9 @@ void Motor_shake(uint8_t status_shake,uint16_t shake_sec);
 /***********************************************************/
 void pin_motor_86_bind(void);
 void pin_motor_86_unbind(void);
+void pwm_motor86_enable(rt_uint32_t freq);
+void stop_motor_86(void);
+
 int hwtimer2_pwm3_output(rt_uint32_t time,rt_uint32_t freq,uint8_t EN,uint8_t DIR);
 int PWM2_CH3_PB10_Fan_LCTD(uint8_t on_off);
 

+ 26 - 59
Application_cbd_apm32f1/applications/control.c

@@ -1983,12 +1983,10 @@ void motor_zero()
 }
 
 
-uint16_t ctr_Motor86_move(uint32_t xdis,uint16_t pulse,uint8_t dir)
+uint16_t ctr_Motor86_move(uint32_t xdis,uint32_t pulse,uint8_t dir)
 {
     //rt_kprintf("run here1");
-    uint32_t j;
-    uint32_t xtemp = 0;
-    xtemp = xdis;                                     //两个脉冲移动0.72度,轴方向上移动2um
+    LOG_W("ctr_Motor86_move:%d-%d-%d",xdis,pulse,dir);                                   //两个脉冲移动0.72度,轴方向上移动2um
     uint32_t limit_tm= 0;
     rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);             //使能电机驱动引脚   PB14
     rt_pin_write(Motor_EN, ON);                         //引脚输出高使能有效
@@ -2000,82 +1998,51 @@ uint16_t ctr_Motor86_move(uint32_t xdis,uint16_t pulse,uint8_t dir)
     //rt_kprintf("run here2");
     rt_pin_write(CTR_RO_LIMIT, dir);             //CCW  置高
     rt_thread_delay(50);
+    pwm_motor86_enable(pulse);
     while(rt_pin_read(MOTOR_86)==0)
     {
-        rt_pin_write(CTR_RC_LIMIT, OFF);
-        rt_hw_us_delay(pulse);  //后10%以线性减速运动
-        rt_pin_write(CTR_RC_LIMIT, ON);
-        rt_hw_us_delay(pulse);
+        limit_tm++;
+        rt_thread_delay(10);
+        if(limit_tm>=1000) break;
     }
+    pwm_motor86_enable(pulse*2);
     while(rt_pin_read(MOTOR_86)==1){
-        rt_pin_write(CTR_RC_LIMIT, OFF);
-        rt_hw_us_delay(pulse*5);  //后10%以线性减速运动
-        rt_pin_write(CTR_RC_LIMIT, ON);
-        rt_hw_us_delay(pulse*5);
+        limit_tm++;
+        rt_thread_delay(10);
+        if(limit_tm>=1000) break;
     }
+    pwm_motor86_enable(pulse);
     while(rt_pin_read(MOTOR_86)==0)
     {
-        rt_pin_write(CTR_RC_LIMIT, OFF);
-        rt_hw_us_delay(pulse);  //后10%以线性减速运动
-        rt_pin_write(CTR_RC_LIMIT, ON);
-        rt_hw_us_delay(pulse);
+        limit_tm++;
+        rt_thread_delay(10);
+        if(limit_tm>=1000) break;
     }
     if(dir==0)
     {
+        pwm_motor86_enable(pulse*2);
         while(rt_pin_read(MOTOR_86)==1){
-            rt_pin_write(CTR_RC_LIMIT, OFF);
-            rt_hw_us_delay(pulse*5);  //后10%以线性减速运动
-            rt_pin_write(CTR_RC_LIMIT, ON);
-            rt_hw_us_delay(pulse*5);
+            limit_tm++;
+            rt_thread_delay(10);
+            if(limit_tm>=1000) break;
         }
     }else {
         rt_thread_delay(500);
         rt_pin_write(CTR_RO_LIMIT, !dir);             //CCW  置高
         rt_thread_delay(100);
+        pwm_motor86_enable(pulse*3);
         while(rt_pin_read(MOTOR_86)==0){
-            rt_pin_write(CTR_RC_LIMIT, OFF);
-            rt_hw_us_delay(pulse*20);  //
-            rt_pin_write(CTR_RC_LIMIT, ON);
-            rt_hw_us_delay(pulse*20);
+            limit_tm++;
+            rt_thread_delay(10);
+            if(limit_tm>=1000) break;
         }
         while(rt_pin_read(MOTOR_86)==1){
-            rt_pin_write(CTR_RC_LIMIT, OFF);
-            rt_hw_us_delay(pulse*10);  //
-            rt_pin_write(CTR_RC_LIMIT, ON);
-            rt_hw_us_delay(pulse*10);
+            limit_tm++;
+            rt_thread_delay(10);
+            if(limit_tm>=1000) break;
         }
     }
-
-//    while(rt_pin_read(MOTOR_86)==0)
-//    {
-//        rt_pin_write(CTR_RC_LIMIT, OFF);
-//        rt_hw_us_delay(pulse);  //后10%以线性减速运动
-//        rt_pin_write(CTR_RC_LIMIT, ON);
-//        rt_hw_us_delay(pulse);
-//    }
-//    if(dir==1)
-//    {
-//        while(rt_pin_read(MOTOR_86)==1)
-//        {
-//            rt_pin_write(CTR_RC_LIMIT, OFF);
-//            rt_hw_us_delay(pulse*10);  //后10%以线性减速运动
-//            rt_pin_write(CTR_RC_LIMIT, ON);
-//            rt_hw_us_delay(pulse*10);
-//        }
-//    }
-//    for(j=0;j<xtemp;j++)
-//    {
-//         rt_pin_write(CTR_RC_LIMIT, OFF);
-//         rt_hw_us_delay(pulse);  //后10%以线性减速运动
-//         rt_pin_write(CTR_RC_LIMIT, ON);
-//         rt_hw_us_delay(pulse);
-//         if(rt_pin_read(MOTOR_86)==0)
-//         {
-//             limit_tm++;
-//         }
-//         if(limit_tm==10) break;
-//    }
-
+    stop_motor_86();
     slidelock();
     return xdis;
  }

+ 1 - 1
Application_cbd_apm32f1/applications/control.h

@@ -310,7 +310,7 @@ void HardWare_Check(uint8_t boot);              //自检
 void ResetInit(void);                           //上电复位
 void SunTest(void);                             //光控测试
 /*****************************************************/
-uint16_t ctr_Motor86_move(uint32_t xdis,uint16_t pulse,uint8_t dir);
+uint16_t ctr_Motor86_move(uint32_t xdis,uint32_t pulse,uint8_t dir);
 void pin_guangshan_bind();
 void pin_guangshan_unbind();
 /***********************孢子仪****************************/

+ 13 - 18
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -139,15 +139,7 @@ void DTU_Write(char *fmt, ...)
     if (str_length > 1024 - 1)
         str_length = 1024 - 1;
     rt_device_write(dtuserial, 0, dtu_str, str_length);
-    rt_thread_mdelay(100);
-//    if(strstr(dtu_str,"volume")!=RT_NULL)
-//    {
-//        rt_device_write(dtuserial,0,dtu_conf,4);
-//    }
-//    else if (strstr(dtu_str,"reset")!=RT_NULL) {
-//        const char dtu_conf[4] = {7,0x00,0x00,0x00};
-//        rt_device_write(dtuserial,0,dtu_conf,4);
-//    }
+    LOG_I("DTU_Write:[%dbyte]%s",str_length,dtu_str);
 }
 /* 接收数据回调函数 */
 static rt_err_t dtu_input(rt_device_t dev, rt_size_t size)
@@ -426,7 +418,6 @@ static void dtu_thread_entry_send(void *parameter)
             }
             else {
                 char *readinfo =  makeJson_ReadInfo();
-                rt_kprintf("upload data:%s\n",readinfo);
                 DTU_Write("%s",readinfo);
                 rt_free(readinfo);
                 rt_thread_delay(1000);
@@ -483,14 +474,22 @@ int dtu_data_play(void)
             DTU_THREAD_PRIORITY,
             DTU_THREAD_TIMESLICE);
     /* 如果获得线程控制块,启动这个线程 */
-    if(dtu_send_data!=RT_NULL)
-        rt_thread_startup(dtu_send_data);
-    /* 如果获得线程控制块,启动这个线程 */
     if (dtu_recv_data != RT_NULL)
         rt_thread_startup(dtu_recv_data);
     return RT_EOK;
 }
 
+void dtu_thread_entry_send_start(void)
+{
+    if(dtu_send_data!=RT_NULL)
+    {
+        rt_thread_startup(dtu_send_data);
+        LOG_I("DTU_Uart_thread_send Started!");
+    }else {
+        LOG_E("DTU_Uart_thread_send FAILED!");
+    }
+}
+
 
 void get_iso8601_utc_time(char *buffer, size_t buffer_size,uint8_t time_h) {
     time_t now_seconds;
@@ -2627,12 +2626,8 @@ int parseDtu(char *json_string)
 void UpLoad_Data(void)
 {
     char *updata = makeJson();
-    LOG_I("upload data:%d %s",rt_strlen(updata),updata);
-    rt_free(updata);
-    #if Color_EN ==0
     DTU_Write("%s",updata);
-    #endif
-    //list_mem();
+    rt_free(updata);
     //播放数据上传中语音
 }
 

+ 1 - 2
Application_cbd_apm32f1/applications/dtu_uart2.h

@@ -50,8 +50,7 @@ typedef struct {
 }WS_CBDV5;
 
 
-
-
+void dtu_thread_entry_send_start(void);
 //查询数据---{"cmd": "read"}
 //重启-------{"cmd": "reboot"}
 //升级-------{"cmd": "update"}

+ 8 - 34
Application_cbd_apm32f1/applications/hmi.c

@@ -1538,17 +1538,17 @@ static void Ctr_Mortor_entry(void* parameter)
 
         if (device_status.autotakepic==10) {
             //hwtimer2_pwm3_output(1,500000,1,0);
-            ctr_Motor86_move(13000,30,1);
+            ctr_Motor86_move(0,50000,1);
             device_status.autotakepic = 0;
         }
 
         else if (device_status.autotakepic==11) {
             //hwtimer2_pwm3_output(1,500000,1,1);
-            ctr_Motor86_move(13000,30,0);
+            ctr_Motor86_move(0,50000,0);
             device_status.autotakepic = 0;
         }
         else if (device_status.autotakepic==12) {
-            ctr_Motor86_move(50000, 100, 0);
+            ctr_Motor86_move(0, 300000, 0);
             device_status.autotakepic = 0;
         }
 
@@ -1868,7 +1868,7 @@ void Check_ParamConfig(void)
         mb_master_samlpe();
 #endif
         thread_485_play();
-#if ROBOT_EN == 0
+
         uint16_t connect_num=0;
         //等待联网,
         while(atoi(device_status.net)==1)
@@ -1884,19 +1884,7 @@ void Check_ParamConfig(void)
             connect_num++;
             LOG_I("联网中......%d",connect_num);
             //超时时间为3分钟
-            #if MATCH_DEVICE == 1
-            if(connect_num==30) //180
-            {
-                device_status.timeSwitch = 1;
-                LOG_W("Time not set:%04d-%02d-%02d %02d:%02d:%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
-                #if 0
-                set_date(2020, 1, 1);
-                set_time(0, 0, 0);
-                #endif
-                break;
-            }
-            #else
-            if(connect_num==30) //180
+            if(connect_num==120) //180
             {
                 device_status.timeSwitch = 0;
                 LOG_W("Time not set:%04d-%02d-%02d %02d:%02d:%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
@@ -1906,7 +1894,6 @@ void Check_ParamConfig(void)
                 #endif
                 break;
             }
-            #endif
         }
         connect_num = 0;
         while(atoi(device_status.net)==0)
@@ -1919,24 +1906,11 @@ void Check_ParamConfig(void)
             if(connect_num>5) break;
         }
         if(device_status.version_type==6) device_status.timeSwitch = 1;
-
         DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
         rt_thread_delay(1000);
-        if(device_status.dtype!=7&&device_status.version_type!=30)
-        {
-            Workstatus_check();
-        }
-
-        /********************/
-        //工作流程
-        if(device_status.version_type!=30)
-        {
-            Work_Loop_Task();
-        }
-        #if MATCH_DEVICE == 1
-        device_status.selfcheck_ws = 3;
-        #endif
-#endif
+        dtu_thread_entry_send_start();  //数据发送线程,“后续改为定时器”
+        Workstatus_check(); //工作时间检测
+        Work_Loop_Task();   //工作任务循环
     }
 }
 void ResetParamDefault(void)