将PLC内伺服驱动工艺模块封装到FB中,后续其他项目都可使用,减少伺服工艺框架设计时间,提高编程效率

1,创建伺服驱动需要使用的Struct(需要两组,一组输入,一组输出)

 

2,创建封装使用的FB块(FC也可) 

3,添加运动控制工艺指令

MC_Power(Enable := MotorIn.Enable,
         Axis := Axis,
         Status => MotorOut.Enabled
         );
MC_Halt(Execute := MotorIn.Halt,
        Axis :=  Axis,
        Deceleration :=MotorIn.Dec_Time,
        CurveType := K0
        );
MC_Jog(Enable :=  M8000,
       Axis := Axis,
       JogForward := MotorIn.JogForward,
       JogBackward := MotorIn.JogReversal,
       Velocity := MotorIn.JogVelocity,
       Acceleration := MotorIn.ACC_Time,
       Deceleration := MotorIn.Dec_Time,
       CurveType :=K0 
       );
MC_MoveAbsolute(Execute := MotorIn.ExecuteAbs,
                Axis := Axis,
                Position := MotorIn.AbsPosition,
                Velocity := MotorIn.AbsVelocity,
                Acceleration := MotorIn.ACC_Time,
                Deceleration := MotorIn.Dec_Time,
                CurveType := K0,
                Direction :=K0 );
MC_MoveRelative(Execute := MotorIn.ExecuteRel,
                Axis :=  Axis,
                Distance := MotorIn.Distance,
                Velocity := MotorIn.AbsVelocity,
                Acceleration := MotorIn.ACC_Time,
                Deceleration := MotorIn.Dec_Time,
                CurveType := K0);
MC_Stop(Execute :=  MotorIn.Stop,
        Axis := Axis,
        Deceleration :=  MotorIn.Dec_Time,
        CurveType :=K0 );
MC_Reset(Execute :=  MotorIn.Reset,
         Axis := Axis);
MC_ReadAxisError(Enable := M8000,
                 Axis := Axis,
                 ServoErrorID => MotorOut.ServoErrorID,
                 AxisErrorID =>  MotorOut.AxisErrorId,
                 Error =>  MotorOut.Error);
MC_ReadActualPosition(Enable := m8000,
                      Axis := Axis,
                      Position => MotorOut.ActPosition);
MC_ReadActualVelocity(Enable := M8000,
                      Axis := Axis,
                      Velocity =>MotorOut.ActVelocity);

可根据使用需要自行添加。。。。

4.调用功能块

Motors(Axis := X_S1,MotorIn := ::X_ServerIN,MotorOut =>::X_ServerOUT );

 添加相关参数即可!

功能块封装与使用就完成了,此PLC使用的是汇川521系列

Logo

欢迎加入 MCP 技术社区!与志同道合者携手前行,一同解锁 MCP 技术的无限可能!

更多推荐