1. 电机描述
在X轴上有多段直线电机,如下图有9个,从X1到X9.
2.codesys程序结构
程序名称:Pou_two_motors
动作名称:ACT_move
把这个程序搞到任务配置里面
通过ethercat总线命名一下这些电机,方便调用。
3.程序内容
PROGRAM POU_two_motors
VAR
MC_Power0,MC_Power1: MC_Power;
MC_MoveAbsolute0,MC_MoveAbsolute1: MC_Moveabsolute;
AcPos,TarPos,Acc,Dcc,Jerk,speed: LREAL;
Direction: SM3_Basic.MC_Direction;
MotorNum,step: INT;
END_VAR
speed:=100;Acc:=speed*10;Dcc:=speed*10;Jerk:=speed*100;
IF (140*4<Axis_X4.fActPosition AND_THEN Axis_X4.fActPosition<140*5) THEN
AcPos:=Axis_X4.fActPosition;
MotorNum:=4;
END_IF
IF (140*5<Axis_X5.fActPosition AND_THEN Axis_X5.fActPosition<140*6) THEN
AcPos:=Axis_X5.fActPosition;
MotorNum:=5;
END_IF
IF TarPos>AcPos THEN
Direction:=MC_Direction.positive;
ELSE
Direction:=MC_Direction.negative;
END_IF
ACT_move();
CASE step OF
1:
TarPos:=140*5;
MC_Power0.bRegulatorOn:=TRUE;
IF MC_Power0.status THEN
MC_MoveAbsolute0.Execute:=TRUE;
END_IF
//IF MC_MoveAbsolute0.Done=1 AND_THEN Acpos>TarPos-1 THEN
IF MC_MoveAbsolute0.Done=1 THEN
MC_MoveAbsolute0.Execute:=FALSE;
MC_Power0.bRegulatorOn:=FALSE;
step:=2;
END_IF
2:
TarPos:=140*6-20;
MC_Power1.bRegulatorOn:=TRUE;
IF MC_Power1.status THEN
MC_MoveAbsolute1.Execute:=TRUE;
END_IF
IF MC_MoveAbsolute1.Done=1 THEN
MC_MoveAbsolute1.Execute:=FALSE;
step:=3;
END_IF
3:
TarPos:=140*5;
MC_Power1.bRegulatorOn:=TRUE;
IF MC_Power1.status THEN
MC_MoveAbsolute1.Execute:=TRUE;
END_IF
//IF MC_MoveAbsolute1.Done=1 AND_THEN Acpos<TarPos+1 THEN
IF MC_MoveAbsolute1.Done=1 THEN
MC_Power1.bRegulatorOn:=FALSE;
MC_MoveAbsolute1.Execute:=FALSE;
step:=4;
END_IF
4:
TarPos:=140*4+20;
MC_Power0.bRegulatorOn:=TRUE;
IF MC_Power0.status THEN
MC_MoveAbsolute0.Execute:=TRUE;
END_IF
IF MC_MoveAbsolute0.Done=1 THEN
MC_MoveAbsolute0.Execute:=FALSE;
step:=1;
END_IF
END_CASE
程序功能块是这么调用的
4.注意事项
1.该程序可以完成从X4到X5电机往返来回切换;
2.同一电机切换的时候不能下使能,切换电机上一个电机要下使能
MC_Power0.bRegulatorOn:=FALSE;
3.这个在切换电机的时候,会停止后再运行,速度越快越明显。