• codesys CNC控制程序


    ——————————————————————————————————

    CNC G代码

    ——————————————————————————————————

    N000 F10 E30
    N001 G00 X250 Y120
    N010 G03 I-100 J0 T360
    N020 G00 X300 Y150
    N030 G01 X500 
    N040 G01 Y30
    N050 G01 X300
    N060 G01 Y150

    ——————————————————————————————————

    变量

    ——————————————————————————————————

    PROGRAM PLC_PRG
    VAR
        MC_PowerX:MC_Power;
        MC_PowerY:MC_Power;
        MC_PowerZ:MC_Power;
        SMC_Interpolator:SMC_Interpolator;
        SMC_TRAFO_Gantry3:SMC_TRAFO_Gantry3;
        SMC_ControlAxisByPosX:SMC_ControlAxisByPos;
        SMC_ControlAxisByPosY:SMC_ControlAxisByPos;
        SMC_ControlAxisByPosZ:SMC_ControlAxisByPos;
        
        x:INT;
        y:INT;
        z:INT;
        
        SMC_PathCopierFile:SMC_PathCopierFile;
        VisuStruct3DControl:VisuStruct3DControl;
        
        SMC_PositionTracker:SMC_PositionTracker;
        pointbuffer:ARRAY [0..100000] OF VisuStruct3DPathPoint;
    END_VAR

    ——————————————————————————————————

    程序

    ——————————————————————————————————

    //使能X
    MC_PowerX(
        Axis:=axisX , 
        Enable:=TRUE , 
        bRegulatorOn:=TRUE , 
        bDriveStart:=TRUE , 
        Status=> , 
        bRegulatorRealState=> , 
        bDriveStartRealState=> , 
        Busy=> , 
        Error=> , 
        ErrorID=> );

    //使能Y
    MC_PowerY(
        Axis:=axisY , 
        Enable:=TRUE , 
        bRegulatorOn:=TRUE , 
        bDriveStart:=TRUE , 
        Status=> , 
        bRegulatorRealState=> , 
        bDriveStartRealState=> , 
        Busy=> , 
        Error=> , 
        ErrorID=> );

    //使能Z
    MC_PowerZ(
        Axis:=axisZ , 
        Enable:=TRUE , 
        bRegulatorOn:=TRUE , 
        bDriveStart:=TRUE , 
        Status=> , 
        bRegulatorRealState=> , 
        bDriveStartRealState=> , 
        Busy=> , 
        Error=> , 
        ErrorID=> );

    //插补器
    SMC_Interpolator(
        bExecute:= , 
        poqDataIn:=ADR(CNC) , 
        bSlow_Stop:= , 
        bEmergency_Stop:= , 
        bWaitAtNextStop:= , 
        dOverride:= , 
        iVelMode:= , 
        dwIpoTime:=6000 , 
        dLastWayPos:= , 
        bAbort:= , 
        bSingleStep:= , 
        bAcknM:= , 
        bQuick_Stop:= , 
        dQuickDeceleration:= , 
        dJerkMax:= , 
        dQuickStopJerk:= , 
        bSuppressSystemMFunctions:= , 
        bDone=> , 
        bBusy=> , 
        bError=> , 
        wErrorID=> , 
        piSetPosition=> , 
        iStatus=> , 
        bWorking=> , 
        iActObjectSourceNo=> , 
        dActObjectLength=> , 
        dActObjectLengthRemaining=> , 
        dVel=> , 
        vecActTangent=> , 
        iLastSwitch=> , 
        dwSwitches=> , 
        dWayPos=> , 
        wM=> , 
        adToolLength=> , 
        Act_Object=> );

    //解析XYZ
    SMC_TRAFO_Gantry3(
        pi:=SMC_Interpolator.piSetPosition , 
        dOffsetX:= , 
        dOffsetY:= , 
        dOffsetZ:= , 
        dx=> , 
        dy=> , 
        dz=> );
        
    //位置控制轴x
    SMC_ControlAxisByPosX(
        Axis:=axisX , 
        iStatus:=SMC_Interpolator.iStatus , 
        bEnable:=SMC_Interpolator.bWorking , 
        bAvoidGaps:= , 
        fSetPosition:=SMC_TRAFO_Gantry3.dx , 
        fGapVelocity:=100 , 
        fGapAcceleration:=100 , 
        fGapDeceleration:=100 , 
        fGapJerk:=100 , 
        bBusy=> , 
        bCommandAborted=> , 
        bError=> , 
        iErrorID=> , 
        bStopIpo=> );

    //位置控制轴y
    SMC_ControlAxisByPosY(
        Axis:=axisY , 
        iStatus:=SMC_Interpolator.iStatus , 
        bEnable:=SMC_Interpolator.bWorking , 
        bAvoidGaps:= , 
        fSetPosition:=SMC_TRAFO_Gantry3.dy , 
        fGapVelocity:=100 , 
        fGapAcceleration:=100 , 
        fGapDeceleration:=100 , 
        fGapJerk:=100 , 
        bBusy=> , 
        bCommandAborted=> , 
        bError=> , 
        iErrorID=> , 
        bStopIpo=> );

    //位置控制轴Z
    SMC_ControlAxisByPosZ(
        Axis:=axisZ , 
        iStatus:=SMC_Interpolator.iStatus , 
        bEnable:=SMC_Interpolator.bWorking , 
        bAvoidGaps:= , 
        fSetPosition:=SMC_TRAFO_Gantry3.dz , 
        fGapVelocity:=100 , 
        fGapAcceleration:=100 , 
        fGapDeceleration:=100 , 
        fGapJerk:=100 , 
        bBusy=> , 
        bCommandAborted=> , 
        bError=> , 
        iErrorID=> , 
        bStopIpo=> );

    x:=TO_INT(axisX.fActPosition);
    y:=TO_INT(-axisY.fActPosition);
    z:=TO_INT(axisZ.fActPosition);

    //位置跟踪器
    SMC_PositionTracker(
        bEnable:=SMC_Interpolator.bBusy , 
        bClear:=SMC_Interpolator.bDone , 
        dX:=axisX.fActPosition , 
        dY:=axisY.fActPosition , 
        dZ:=axisZ.fActPosition , 
        udiNumberOfPointsInArray:=SIZEOF(pointbuffer)/SIZEOF(pointbuffer[0]) , 
        pBuffer:=ADR(pointbuffer) , 
        vs3dt=> );

    ——————————————————————————————————

    界面

    ——————————————————————————————————

  • 相关阅读:
    Spring Boot发送QQ邮件
    Redis 7.0 源码环境搭建与阅读技巧
    敏捷实践之Bug Bash
    Acwing 907. 区间覆盖
    Spring MVC里的DispatchServlet(结合Spring官网翻译)
    Istio微服务治理网格流量管理核心资源控制器详解
    Vue2项目练手——通用后台管理项目第二节
    【21天学习挑战赛—经典算法】LeetCode 922. 按奇偶排序数组 II
    记一次定时任务scheduler启动不了的日志
    嵌入式Linux驱动开发5---volatile变量
  • 原文地址:https://blog.csdn.net/weixin_58619062/article/details/133768610