|
|
@@ -2042,6 +2042,110 @@ static void pin_guangshan_unbind(void)
|
|
|
rt_pin_detach_irq(GUANG_SHAN);
|
|
|
}
|
|
|
|
|
|
+#define PULES 1 //延时时间 ms 5.0测报灯电机归零延时使用
|
|
|
+
|
|
|
+void slidelock()
|
|
|
+{
|
|
|
+ ctr_Motor_Driver_Power(ON); //电机驱动供电
|
|
|
+ rt_thread_delay(300);
|
|
|
+ rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT); //使能电机驱动引脚 PB14
|
|
|
+ rt_pin_write(Motor_EN, ON); //引脚输出高使能有效
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void motor_zero()
|
|
|
+{
|
|
|
+ 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_thread_delay(300);
|
|
|
+
|
|
|
+ rt_thread_delay(300);
|
|
|
+
|
|
|
+ rt_pin_mode(Motor_Direction_Button, PIN_MODE_INPUT); //GET_PIN(B,8)
|
|
|
+ rt_pin_write(CTR_RO_LIMIT, OFF); //CCW back配置
|
|
|
+
|
|
|
+ uint32_t j;
|
|
|
+ for(j=0;j<3200;j++) //多配置1600个脉冲,保证肯定能归零;
|
|
|
+ {
|
|
|
+ rt_pin_write(CTR_RC_LIMIT, OFF);
|
|
|
+ rt_thread_delay(PULES);
|
|
|
+ rt_pin_write(CTR_RC_LIMIT, ON);
|
|
|
+ rt_thread_delay(PULES);
|
|
|
+ if( rt_pin_read(Motor_Direction_Button)==0)//判断得到限位信号
|
|
|
+ {
|
|
|
+ rt_thread_delay(5);
|
|
|
+ if( rt_pin_read(Motor_Direction_Button)==0)
|
|
|
+ {
|
|
|
+ slidelock();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rt_thread_delay(300);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+uint16_t ctr_xmove(uint32_t xdis,uint16_t pulse)
|
|
|
+{
|
|
|
+ //rt_kprintf("run here1");
|
|
|
+ uint32_t j;
|
|
|
+ uint32_t xtemp = 0;
|
|
|
+ xtemp = xdis; //两个脉冲移动0.72度,轴方向上移动2um
|
|
|
+
|
|
|
+ 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_kprintf("run here2");
|
|
|
+ rt_pin_write(CTR_RO_LIMIT, OFF); //CCW 置高
|
|
|
+ rt_thread_delay(300);
|
|
|
+
|
|
|
+ for(j=0;j<xtemp;j++)
|
|
|
+ {
|
|
|
+ //rt_kprintf("run here4");
|
|
|
+ if((j <= 0.1*xtemp))
|
|
|
+ {
|
|
|
+ //rt_kprintf("run here5");
|
|
|
+ //rt_kprintf("xtemp is %d",xtemp );
|
|
|
+ rt_pin_write(CTR_RC_LIMIT, OFF);
|
|
|
+ //rt_kprintf("run here10");
|
|
|
+ //rt_kprintf("pulse is %d",pulse);
|
|
|
+ //rt_thread_delay(1); //前10%以线性加速运动
|
|
|
+ rt_hw_us_delay(pulse*(0.1*xtemp - j + 20)/20); //前10%以线性加速运动
|
|
|
+ rt_pin_write(CTR_RC_LIMIT, ON);
|
|
|
+ //rt_kprintf("run here11");
|
|
|
+ //rt_thread_delay(1);
|
|
|
+ rt_hw_us_delay(pulse*(0.1*xtemp - j + 20)/20);
|
|
|
+ //rt_kprintf("run here9");
|
|
|
+ }
|
|
|
+ if((j >0.1*xtemp)&&(j <= 0.9*xtemp))
|
|
|
+ {
|
|
|
+ //rt_kprintf("run here6");
|
|
|
+ rt_pin_write(CTR_RC_LIMIT, OFF);
|
|
|
+ rt_hw_us_delay(pulse);
|
|
|
+ rt_pin_write(CTR_RC_LIMIT, ON);
|
|
|
+ rt_hw_us_delay(pulse);
|
|
|
+ }
|
|
|
+ if((j > 0.9*xtemp))
|
|
|
+ {
|
|
|
+ //rt_kprintf("run here7");
|
|
|
+ rt_pin_write(CTR_RC_LIMIT, OFF);
|
|
|
+ rt_hw_us_delay(pulse*(j-0.9*xtemp + 20)/20); //后10%以线性减速运动
|
|
|
+ rt_pin_write(CTR_RC_LIMIT, ON);
|
|
|
+ rt_hw_us_delay(pulse*(j-0.9*xtemp + 20)/20);
|
|
|
+ }
|
|
|
+ //rt_kprintf("run here8");
|
|
|
+ }
|
|
|
+ slidelock();
|
|
|
+ return xdis;
|
|
|
+ }
|
|
|
|
|
|
/*
|
|
|
* 灯管
|