|
|
@@ -1271,6 +1271,7 @@ void guanshan_on(void *args)
|
|
|
|
|
|
void pin_guangshan_bind(void)
|
|
|
{
|
|
|
+ LOG_W("pin_guangshan_bind");
|
|
|
/* PC14引脚为输入模式 */
|
|
|
rt_pin_mode(GUANG_SHAN, PIN_MODE_INPUT);
|
|
|
/* 绑定中断,下降沿模式,回调函数名为guanshan_on */
|
|
|
@@ -1279,8 +1280,33 @@ void pin_guangshan_bind(void)
|
|
|
rt_pin_irq_enable(GUANG_SHAN, PIN_IRQ_ENABLE);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+void motor_stop(void *args)
|
|
|
+{
|
|
|
+ LOG_W("motor_stop!");
|
|
|
+ stop_motor_86();
|
|
|
+}
|
|
|
+
|
|
|
+void pin_motor_bind(void)
|
|
|
+{
|
|
|
+ LOG_W("pin_motor_bind");
|
|
|
+ /* PC14引脚为输入模式 */
|
|
|
+ rt_pin_mode(MOTOR_86, PIN_MODE_INPUT);
|
|
|
+ /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
|
|
|
+ rt_pin_attach_irq(MOTOR_86, PIN_IRQ_MODE_RISING, motor_stop, RT_NULL);
|
|
|
+ /* 使能中断 */
|
|
|
+ rt_pin_irq_enable(MOTOR_86, PIN_IRQ_ENABLE);
|
|
|
+}
|
|
|
+
|
|
|
+void pin_motor_unbind(void)
|
|
|
+{
|
|
|
+ LOG_D("pin_motor_unbind");
|
|
|
+ rt_pin_detach_irq(MOTOR_86);
|
|
|
+}
|
|
|
+
|
|
|
void pin_guangshan_unbind(void)
|
|
|
{
|
|
|
+ LOG_D("pin_guangshan_unbind");
|
|
|
rt_pin_detach_irq(GUANG_SHAN);
|
|
|
}
|
|
|
|
|
|
@@ -1334,66 +1360,65 @@ uint16_t ctr_Motor86_move(uint32_t xdis,uint32_t pulse,uint8_t dir)
|
|
|
{
|
|
|
//rt_kprintf("run here1");
|
|
|
LOG_W("ctr_Motor86_move:%d-%d-%d",xdis,pulse,dir); //两个脉冲移动0.72度,轴方向上移动2um
|
|
|
- uint32_t limit_tm= 0;
|
|
|
+ //uint32_t limit_tm= 0;
|
|
|
rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT); //使能电机驱动引脚 PB14
|
|
|
rt_pin_write(Motor_EN, ON); //引脚输出高使能有效
|
|
|
|
|
|
rt_pin_mode(CTR_RO_LIMIT, PIN_MODE_OUTPUT); //CCW PB15 配置为输出模式
|
|
|
- //rt_pin_mode(CTR_RC_LIMIT, PIN_MODE_OUTPUT); //CW PC6 配置为输出模式
|
|
|
|
|
|
- rt_pin_mode(MOTOR_86, PIN_MODE_INPUT);
|
|
|
- //rt_kprintf("run here2");
|
|
|
+ // rt_pin_mode(MOTOR_86, PIN_MODE_INPUT);
|
|
|
+
|
|
|
rt_pin_write(CTR_RO_LIMIT, dir); //CCW 置高
|
|
|
rt_thread_delay(50);
|
|
|
pwm_motor86_enable(pulse);
|
|
|
- while(rt_pin_read(MOTOR_86)==0)
|
|
|
- {
|
|
|
- limit_tm++;
|
|
|
- rt_thread_delay(10);
|
|
|
- if(limit_tm>=1000) break;
|
|
|
- }
|
|
|
- pwm_motor86_enable(pulse*2);
|
|
|
- while(rt_pin_read(MOTOR_86)==1){
|
|
|
- limit_tm++;
|
|
|
- rt_thread_delay(10);
|
|
|
- if(limit_tm>=1000) break;
|
|
|
- }
|
|
|
- pwm_motor86_enable(pulse);
|
|
|
- while(rt_pin_read(MOTOR_86)==0)
|
|
|
- {
|
|
|
-
|
|
|
- pwm_motor86_enable(pulse);
|
|
|
- limit_tm++;
|
|
|
- rt_thread_delay(10);
|
|
|
- if(limit_tm>=1000) break;
|
|
|
- }
|
|
|
- stop_motor_86();
|
|
|
- if(dir==0)
|
|
|
- {
|
|
|
- pwm_motor86_enable(pulse*2);
|
|
|
- while(rt_pin_read(MOTOR_86)==1){
|
|
|
- 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){
|
|
|
- limit_tm++;
|
|
|
- rt_thread_delay(10);
|
|
|
- if(limit_tm>=1000) break;
|
|
|
- }
|
|
|
- while(rt_pin_read(MOTOR_86)==1){
|
|
|
- limit_tm++;
|
|
|
- rt_thread_delay(10);
|
|
|
- if(limit_tm>=1000) break;
|
|
|
- }
|
|
|
- }
|
|
|
- stop_motor_86();
|
|
|
- slidelock();
|
|
|
+// while(rt_pin_read(MOTOR_86)==0)
|
|
|
+// {
|
|
|
+// limit_tm++;
|
|
|
+// rt_thread_delay(10);
|
|
|
+// if(limit_tm>=1000) break;
|
|
|
+// }
|
|
|
+// pwm_motor86_enable(pulse*2);
|
|
|
+// while(rt_pin_read(MOTOR_86)==1){
|
|
|
+// limit_tm++;
|
|
|
+// rt_thread_delay(10);
|
|
|
+// if(limit_tm>=1000) break;
|
|
|
+// }
|
|
|
+// pwm_motor86_enable(pulse);
|
|
|
+// while(rt_pin_read(MOTOR_86)==0)
|
|
|
+// {
|
|
|
+//
|
|
|
+// pwm_motor86_enable(pulse);
|
|
|
+// limit_tm++;
|
|
|
+// rt_thread_delay(10);
|
|
|
+// if(limit_tm>=1000) break;
|
|
|
+// }
|
|
|
+// stop_motor_86();
|
|
|
+// if(dir==0)
|
|
|
+// {
|
|
|
+// pwm_motor86_enable(pulse*2);
|
|
|
+// while(rt_pin_read(MOTOR_86)==1){
|
|
|
+// 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){
|
|
|
+// limit_tm++;
|
|
|
+// rt_thread_delay(10);
|
|
|
+// if(limit_tm>=1000) break;
|
|
|
+// }
|
|
|
+// while(rt_pin_read(MOTOR_86)==1){
|
|
|
+// limit_tm++;
|
|
|
+// rt_thread_delay(10);
|
|
|
+// if(limit_tm>=1000) break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// stop_motor_86();
|
|
|
+// slidelock();
|
|
|
return xdis;
|
|
|
}
|
|
|
|
|
|
@@ -1446,6 +1471,8 @@ void WorkTask_CB5(void)
|
|
|
rt_thread_delay(1000);
|
|
|
//光栅检测启动
|
|
|
pin_guangshan_bind();
|
|
|
+ //电机限位检测启动
|
|
|
+ pin_motor_bind();
|
|
|
rt_thread_delay(1000);
|
|
|
while(rt_pin_read(GUANG_SHAN)==0)
|
|
|
{
|
|
|
@@ -1466,7 +1493,7 @@ void WorkTask_CB5(void)
|
|
|
if(device_status.work_done==0&&device_status.work_status==0)
|
|
|
{
|
|
|
pin_guangshan_unbind();
|
|
|
- //pin_motor_86_unbind();
|
|
|
+ pin_motor_unbind();
|
|
|
//打开推杆电机,益虫放生
|
|
|
DTU_Write("{\"cmd\":\"workdone\"}");
|
|
|
ResetInit();
|