|
@@ -140,9 +140,36 @@ void turnlimit(void)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+uint32_t mapSpeed(int a1) {
|
|
|
|
|
+ const int a1Min = 0;
|
|
|
|
|
+ const int a1Max = 100;
|
|
|
|
|
+ const int a2Min = 50000; //20khz
|
|
|
|
|
+ const int a2Max = 200000; //5khz
|
|
|
|
|
+
|
|
|
|
|
+ // 确保 a1 在有效范围内
|
|
|
|
|
+ if (a1 < a1Min) {
|
|
|
|
|
+ a1 = a1Min;
|
|
|
|
|
+ } else if (a1 > a1Max) {
|
|
|
|
|
+ a1 = a1Max;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 执行线性映射
|
|
|
|
|
+ uint32_t a2 = a2Max - ((a2Max - a2Min) * a1) / (a1Max - a1Min);
|
|
|
|
|
+
|
|
|
|
|
+ return a2;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void stop_move(void)
|
|
|
|
|
+{
|
|
|
|
|
+ slide_para.stop_flag = 1;
|
|
|
|
|
+ slidelock();
|
|
|
|
|
+ rt_pin_mode(HK_IO, PIN_MODE_OUTPUT); //PB14 EN
|
|
|
|
|
+ pwm_stop();
|
|
|
|
|
+ rt_pin_write(HK_IO, ON);
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
//DIR_ 轴选择(0-X,1-Y,2-Z) dir 轴方向
|
|
//DIR_ 轴选择(0-X,1-Y,2-Z) dir 轴方向
|
|
|
-uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint8_t pulse)
|
|
|
|
|
|
|
+uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint32_t pulse)
|
|
|
{
|
|
{
|
|
|
uint32_t j;
|
|
uint32_t j;
|
|
|
slidelock();
|
|
slidelock();
|
|
@@ -156,9 +183,14 @@ uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint8_t pulse)
|
|
|
rt_pin_mode(CTR_RO_LIMIT, PIN_MODE_OUTPUT); //PB15 DIR
|
|
rt_pin_mode(CTR_RO_LIMIT, PIN_MODE_OUTPUT); //PB15 DIR
|
|
|
|
|
|
|
|
//rt_pin_mode(CTR_RC_LIMIT, PIN_MODE_OUTPUT); //PC6 PWM
|
|
//rt_pin_mode(CTR_RC_LIMIT, PIN_MODE_OUTPUT); //PC6 PWM
|
|
|
|
|
+// if(dis_ >=1000){
|
|
|
|
|
+// beep_set(500000, 250000); //PWM使能
|
|
|
|
|
+// }else{
|
|
|
|
|
+// beep_set(2000000, 1000000); //PWM使能
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
//驱动使能
|
|
//驱动使能
|
|
|
- rt_pin_write(HK_IO, ON);
|
|
|
|
|
|
|
+ //rt_pin_write(HK_IO, ON);
|
|
|
|
|
|
|
|
//方向选择
|
|
//方向选择
|
|
|
if(dir_ == 1){
|
|
if(dir_ == 1){
|
|
@@ -167,15 +199,10 @@ uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint8_t pulse)
|
|
|
rt_pin_write(CTR_RO_LIMIT, OFF);
|
|
rt_pin_write(CTR_RO_LIMIT, OFF);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(dis_ >=1000){
|
|
|
|
|
- beep_set(500000, 250000); //PWM使能
|
|
|
|
|
- }else{
|
|
|
|
|
- beep_set(2000000, 1000000); //PWM使能
|
|
|
|
|
- }
|
|
|
|
|
switch(DIR_){
|
|
switch(DIR_){
|
|
|
case X_:
|
|
case X_:
|
|
|
ctr_lamp(1, ON); //X轴电源开关:开
|
|
ctr_lamp(1, ON); //X轴电源开关:开
|
|
|
- rt_thread_delay(500);
|
|
|
|
|
|
|
+ rt_thread_delay(100);
|
|
|
//判断限位
|
|
//判断限位
|
|
|
if(dir_== 0 && rt_pin_read(Limit_Motor_X)==1){
|
|
if(dir_== 0 && rt_pin_read(Limit_Motor_X)==1){
|
|
|
for(int z =0;z < 3; z++){
|
|
for(int z =0;z < 3; z++){
|
|
@@ -184,10 +211,11 @@ uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint8_t pulse)
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ rt_pin_write(HK_IO, ON);
|
|
|
|
|
+ beep_set(pulse, pulse/2); //PWM使能
|
|
|
for(j=0;j<dis_;j++){
|
|
for(j=0;j<dis_;j++){
|
|
|
if(slide_para.stop_flag == 0){
|
|
if(slide_para.stop_flag == 0){
|
|
|
- rt_thread_delay(pulse); //10ms
|
|
|
|
|
|
|
+ rt_thread_delay(10); //10ms
|
|
|
if(dir_==0&&rt_pin_read(Limit_Motor_X)==1){
|
|
if(dir_==0&&rt_pin_read(Limit_Motor_X)==1){
|
|
|
rt_thread_delay(10); //10ms
|
|
rt_thread_delay(10); //10ms
|
|
|
if(rt_pin_read(Limit_Motor_X)==1){
|
|
if(rt_pin_read(Limit_Motor_X)==1){
|
|
@@ -207,7 +235,7 @@ uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint8_t pulse)
|
|
|
break;
|
|
break;
|
|
|
case Y_:
|
|
case Y_:
|
|
|
ctr_Collect_Fan(ON); //Y轴电源开关:开
|
|
ctr_Collect_Fan(ON); //Y轴电源开关:开
|
|
|
- rt_thread_delay(500);
|
|
|
|
|
|
|
+ rt_thread_delay(100);
|
|
|
//判断限位
|
|
//判断限位
|
|
|
if(dir_== 0 && rt_pin_read(Limit_Motor_Y)==1){
|
|
if(dir_== 0 && rt_pin_read(Limit_Motor_Y)==1){
|
|
|
for(int z =0;z < 3; z++){
|
|
for(int z =0;z < 3; z++){
|
|
@@ -216,10 +244,12 @@ uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint8_t pulse)
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
+ rt_pin_write(HK_IO, ON);
|
|
|
|
|
+ beep_set(pulse, pulse/2); //PWM使能
|
|
|
|
|
|
|
|
for(j=0;j<dis_;j++){
|
|
for(j=0;j<dis_;j++){
|
|
|
if(slide_para.stop_flag == 0){
|
|
if(slide_para.stop_flag == 0){
|
|
|
- rt_thread_delay(pulse);
|
|
|
|
|
|
|
+ rt_thread_delay(10);
|
|
|
if(dir_==0&&rt_pin_read(Limit_Motor_Y)==1){
|
|
if(dir_==0&&rt_pin_read(Limit_Motor_Y)==1){
|
|
|
rt_thread_delay(10);
|
|
rt_thread_delay(10);
|
|
|
if(rt_pin_read(Limit_Motor_Y)==1){
|
|
if(rt_pin_read(Limit_Motor_Y)==1){
|
|
@@ -237,7 +267,7 @@ uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint8_t pulse)
|
|
|
break;
|
|
break;
|
|
|
case Z_:
|
|
case Z_:
|
|
|
ctr_swz(ON); //Z轴电源开关:开
|
|
ctr_swz(ON); //Z轴电源开关:开
|
|
|
- rt_thread_delay(500); //
|
|
|
|
|
|
|
+ rt_thread_delay(100); //
|
|
|
//判断限位
|
|
//判断限位
|
|
|
if(dir_== 0 && rt_pin_read(Limit_Motor_Z)==1){
|
|
if(dir_== 0 && rt_pin_read(Limit_Motor_Z)==1){
|
|
|
for(int z =0;z < 3; z++){
|
|
for(int z =0;z < 3; z++){
|
|
@@ -246,10 +276,12 @@ uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint8_t pulse)
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ //驱动使能
|
|
|
|
|
+ rt_pin_write(HK_IO, ON);
|
|
|
|
|
+ beep_set(pulse, pulse/2); //PWM使能
|
|
|
for(j=0;j<dis_;j++){
|
|
for(j=0;j<dis_;j++){
|
|
|
if(slide_para.stop_flag == 0){
|
|
if(slide_para.stop_flag == 0){
|
|
|
- rt_thread_delay(pulse);
|
|
|
|
|
|
|
+ rt_thread_delay(10);
|
|
|
if(dir_==0&&rt_pin_read(Limit_Motor_Z)==1){
|
|
if(dir_==0&&rt_pin_read(Limit_Motor_Z)==1){
|
|
|
rt_thread_delay(10);
|
|
rt_thread_delay(10);
|
|
|
if(rt_pin_read(Limit_Motor_Z)==1){
|
|
if(rt_pin_read(Limit_Motor_Z)==1){
|
|
@@ -1117,7 +1149,7 @@ void slide_thread_entry(void *parameter)
|
|
|
slide_para.pulse_period = 1; //默认滑台的脉宽为1ms
|
|
slide_para.pulse_period = 1; //默认滑台的脉宽为1ms
|
|
|
while(1)
|
|
while(1)
|
|
|
{
|
|
{
|
|
|
- rt_thread_delay(100);
|
|
|
|
|
|
|
+ rt_thread_delay(10);
|
|
|
switch(slide_para.en_slide){
|
|
switch(slide_para.en_slide){
|
|
|
case 1:{
|
|
case 1:{
|
|
|
ctr_move(X_,slide_para.xdir,slide_para.xdis,slide_para.pulse_period);
|
|
ctr_move(X_,slide_para.xdir,slide_para.xdis,slide_para.pulse_period);
|