1. 电机描述
在X轴上有多段直线电机,如下图有9个,从X1到X9.
2.codesys程序结构
程序名称:Pou_two_motors
动作名称:ACT_move
把这个程序搞到任务配置里面
通过ethercat总线命名一下这些电机,方便调用。
3.程序内容
PROGRAM POU_two_motors
VARMC_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_IFIF TarPos>AcPos THENDirection:=MC_Direction.positive;ELSEDirection:=MC_Direction.negative;
END_IFACT_move();CASE step OF1:TarPos:=140*5; MC_Power0.bRegulatorOn:=TRUE;IF MC_Power0.status THENMC_MoveAbsolute0.Execute:=TRUE;END_IF//IF MC_MoveAbsolute0.Done=1 AND_THEN Acpos>TarPos-1 THENIF MC_MoveAbsolute0.Done=1 THENMC_MoveAbsolute0.Execute:=FALSE;MC_Power0.bRegulatorOn:=FALSE;step:=2;END_IF2:TarPos:=140*6-20;MC_Power1.bRegulatorOn:=TRUE;IF MC_Power1.status THENMC_MoveAbsolute1.Execute:=TRUE;END_IFIF MC_MoveAbsolute1.Done=1 THENMC_MoveAbsolute1.Execute:=FALSE;step:=3;END_IF3:TarPos:=140*5;MC_Power1.bRegulatorOn:=TRUE;IF MC_Power1.status THENMC_MoveAbsolute1.Execute:=TRUE;END_IF//IF MC_MoveAbsolute1.Done=1 AND_THEN Acpos<TarPos+1 THENIF MC_MoveAbsolute1.Done=1 THENMC_Power1.bRegulatorOn:=FALSE;MC_MoveAbsolute1.Execute:=FALSE;step:=4;END_IF4:TarPos:=140*4+20; MC_Power0.bRegulatorOn:=TRUE;IF MC_Power0.status THENMC_MoveAbsolute0.Execute:=TRUE;END_IFIF MC_MoveAbsolute0.Done=1 THENMC_MoveAbsolute0.Execute:=FALSE;step:=1;END_IF
END_CASE
程序功能块是这么调用的
4.注意事项
1.该程序可以完成从X4到X5电机往返来回切换;
2.同一电机切换的时候不能下使能,切换电机上一个电机要下使能
MC_Power0.bRegulatorOn:=FALSE;
3.这个在切换电机的时候,会停止后再运行,速度越快越明显。