CODESYS 枕式机应用

    //----色标中断信号响应处理:将传送带轴当前位置存放到位置缓存
    IF SensorTriger=1 THEN
    IF (BufDeep<0) THEN
    BufDeep:=0; //防止出错
    END_IF
    IF BufDeep>=2 THEN
    BufDeep:=2; //最多只支持2个缓存,多于2个,丢弃,防止出错
    END_IF

    CASE BufDeep OF //--缓存指针,最多记住3个标志
    0:
    TargetPointArry0:=Axis_CONVERY.fActPosition;
    1:
    TargetPointArry1:=Axis_CONVERY.fActPosition;
    2:
    TargetPointArry2:=Axis_CONVERY.fActPosition;
    END_CASE

    BufDeep:=BufDeep+1;
    SensorTriger:=0;

    END_IF

    //-----自由计时器刷新,可用于判断超时错误-------->>--
    IF PowerupTimerS < 32700 THEN
    PowerupTimerS:=PowerupTimerS+2; //EtherCAT Period is 2ms
    END_IF

    //----按系统运行状态0~5分别处理---------------->>
    IF Sysstatus<0 OR Sysstatus>5 THEN //万一状态指针错误,纠正为重新开始运行
    Sysstatus:=0;
    END_IF

    CASE Sysstatus OF
    // System status: 0=Selfchecking; 1=Error; 2=Stopped; 3=Man-Jogging; 4=SlaveAxis Origining;
    // 5=MasterAxis firstrun;
    0: //上电自诊断,伺服使能 Self checking
    IF NOT Inited THEN
    //-----使能两个伺服驱动器----->>------
    MC_Power2(Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE, Axis:=Axis_FlyCut,);
    MC_Power1(Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE, Axis:=Axis_CONVERY,);

    MC_Power3(Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE, Axis:=Axis_ZJ,);

    Inited:= MC_Power1.Status AND MC_Power2.Status AND MC_Power3.Status;

    //-----超时错误判断------>>-----
    IF (PowerupTimerS> 10000) AND (Ethercat.xConfigFinished = FALSE) THEN
    SysStatuMark:=1; //EtherCAT Network/Cable Error
    Sysstatus:=1; //Error State
    END_IF

    IF (PowerupTimerS> 12000) AND (Ethercat.xError = TRUE) THEN
    SysStatuMark:=2; //EtherCAT Network/Cable Error
    Sysstatus:=1; //Error State
    END_IF

    ELSE
    Sysstatus :=2; //If two servo can be ENABLED, Switch to statu 2;
    SysStatuMark:=0; //OK
    END_IF

    1: //停机告警状态 Stopped,Error Alarming

    AxisConvy_RUN:=0;

    IF Reset_key=TRUE THEN //----如果手动复位按钮,
    Sysstatus:=0; //--退回到起始状态
    PowerupTimerS:=0; //--重新计时
    SysStatuMark:=0; //--清除告警

    IF EtherCAT.xConfigFinished=FALSE THEN
    EtherCAT.xRestart :=Reset_key; //---如果EtherCAT网络有问题,重启网络
    END_IF

    Reset_key:=FALSE;
    END_IF

    IF Setup_key=TRUE AND SysStatuMark=0 THEN //----系统正常的情况下,如果手动调试按钮,转到调试状态
    Sysstatus:=3;

    END_IF
    //Setup_key:=TRUE;
    IF Setup_key=FALSE AND SysStatuMark=0 THEN //----系统正常的情况下,如果手动调试按钮,转到调试状态
    Sysstatus:=2;

    END_IF

    2: //正常停机 Stopped, Normal

    AxisConvy_RUN:=0;

    IF Axis_CONVERY.nAxisState=4 OR Axis_CONVERY.nAxisState=5 THEN
    AxisConvery_Stop:=1; //此处给出停机标志
    END_IF

    IF Axis_FlyCut.nAxisState=4 OR Axis_FlyCut.nAxisState=5 THEN
    AxisFlyCut_Stop:=1; //此处给出停机标志
    END_IF

    IF Setup_key= TRUE THEN
    Sysstatus:= 3; //goto JOG and Setting

    END_IF

    IF Run_key= TRUE THEN
    Sysstatus:= 4; //Proparing to run
    Run_key:=0;
    Run1Cmd:=1;
    END_IF

    3: // Manual Jogging and setting, Omitted because of no Set_Key here
    MC_Jog1( Axis:= Axis_Convery, JogForward:= JOG_AxisConvery_for, JogBackward:=JOG_AxisConvery_bak, Velocity:= 100,Acceleration:= 1000, Deceleration:= 1000, );

    MC_Jog2( Axis:= Axis_FlyCut, JogBackward:= JOG_AxisFlyCut_for,JogBackward:=JOG_AxisFlyCut_bak, Velocity:= 100,Acceleration:= 1000, Deceleration:= 1000, );

    IF FlyZero_key= TRUE THEN
    MC_SetPosition1(Axis:= Axis_FlyCut,Execute:=TRUE,Mode:=FALSE,);
    FlyZero_key:= FALSE;
    END_IF

    IF Setup_key= FALSE AND JOG_AxisConvery_for= FALSE AND JOG_AxisFlyCut_for=FALSE AND JOG_AxisConvery_bak= FALSE AND JOG_AxisFlyCut_bak=FALSE THEN
    Sysstatus:= 2;
    END_IF

    4: //SlaveAxis Adjusting, 若飞剪轴不在等待位置,先回到原点
    MC_MoveAbsolute2(Axis:= Axis_FlyCut ,Execute:=Run1Cmd ,Position:=0 ,Velocity:=360 ,Acceleration:=3600 ,Deceleration:=3600 , );
    Run1Cmd :=0;
    //MC_Home1(Axis:= Axis_FlyCut, Execute:= Run1Cmd, Position:= 0, );

    IF MC_MoveAbsolute2.done=TRUE THEN
    MC_MoveAbsolute2(Axis:= Axis_FlyCut ,Execute:=FALSE ,);
    CAM_TabEnable:=TRUE;//凸轮表使能
    Sysstatus:=5; //goto runing

    //初始化用于同步起始点的比较寄存器缓冲,这里设计了2级缓冲,Clear CMR buffer------>>--
    CMR0:=0;
    CMR1:=0;
    CMR_Pointer:=0;

    //让自由计时器从新计时,便于检查色标信号超时判断--------->>-----
    PowerupTimerS:=0;

    END_IF

    5: //MasterAxis firstRun
    //传送带开始以速度方式运动,运行速度Vspeed为按时间变化----------------->>--
    AxisConvy_RUN:=TRUE;

    CAM_InEnable:=TRUE;//凸轮同步使能,由CMR+Offset比对匹配时,触发同步

    END_CASE

    //---以下为所有状态都需要的处理---------------->>
    //-----前面作了MC的执行触发、使能标志的处理,下面统一放在这里------>>
    MC_CAMTableSelect1(
    Master:= Axis_CONVERY,
    Slave:= Axis_FlyCut,
    CamTable:= Cam1,
    Execute:= CAM_TabEnable,
    Periodic:= FALSE,
    MasterAbsolute:= FALSE,
    SlaveAbsolute:= 1,
    Done=> Tbldn,
    Busy=> ,
    Error=> ,
    ErrorID=> ,
    CamTableID=> Cam1_ID);

    //---比较目标缓冲区的长度,触发CAM同步的判断、CamIn的触发-----
    IF CAM_InEnable=TRUE THEN
    IF BufDeep >0 THEN
    tmp1:=Axis_CONVERY.fActPosition-(TargetPointArry0+SensorCut_Length);
    IF tmp1>-0.1 THEN
    CamIn_trig:=1;

    TargetPointArry0:=TargetPointArry1;
    TargetPointArry1:=TargetPointArry2;
    BufDeep:=BufDeep-1;
    END_IF
    //---防错处理:若传送带的当前位置比比较点的位置大,清掉无用的比较点----->>
    (* (tmp1>0.1) THEN
    TargetPointArry0:=TargetPointArry1;
    TargetPointArry1:=TargetPointArry2;
    IF BufDeep>0 THEN
    BufDeep:=BufDeep-1;
    END_IF

    END_IF *)

    END_IF
    END_IF

    pp:=Run_key;

    MC_CamIn1(
    Master:= Axis_CONVERY,
    Slave:= Axis_FlyCut,
    Execute:= CamIn_trig,
    MasterOffset:= 0,
    SlaveOffset:= 0,
    MasterScaling:= 1,
    SlaveScaling:= -1,
    StartMode:=0 ,
    CamTableID:= Cam1_ID,
    VelocityDiff:= 0,
    Acceleration:= 30,
    Deceleration:= 30, );

    CamIn_trig:=FALSE; //

    MC_CamOut1(
    Slave:= Axis_FlyCut,
    Execute:= Stop_key,
    Done=> ,
    Busy=> ,
    Error=> ,
    ErrorID=> );

    MC_MoveVelocity1(Axis:= Axis_CONVERY , Execute:=AxisConvy_RUN , Velocity:= Vspeed , Acceleration:= 60, Deceleration:=60 , );

    //如果2个轴都已停稳3=standstill,返回停机状态
    (*IF Sysstatus=5 AND Axis_CONVERY.nAxisState=3 AND Axis_FlyCut.nAxisState =3 THEN
    Sysstatus:=2;
    END_IF
    *)
    //只要有1个轴故障停机1=errorstop,就返回故障停机状态
    IF Axis_CONVERY.nAxisState=1 OR Axis_FlyCut.nAxisState =1 THEN
    AxisFlyCut_Stop:=1;
    AxisConvery_Stop:=1;
    Sysstatus:=1;
    END_IF

    IF Stop_key=1 THEN
    AxisFlyCut_Stop:=1;
    AxisConvery_Stop:=1;
    AxisConvy_RUN:=0;
    Stop_key:=0;
    END_IF

    //----测试位移----->>
    MC_MoveRelative1(
    Axis:= Axis_CONVERY,
    Execute:= test1,
    Distance:=120 ,
    Velocity:= Vspeed,
    Acceleration:=60 ,
    Deceleration:= 60,
    );

    //----测试位移------>>
    MC_MoveRelative2(
    Axis:= Axis_FlyCut,
    Execute:= test2,
    Distance:=360 ,
    Velocity:= Vspeed,
    Acceleration:=60 ,
    Deceleration:= 60,
    );

    MC_Stop1(Axis:= Axis_CONVERY,Execute:=AxisConvery_Stop,);
    MC_Stop2(Axis:= Axis_FlyCut,Execute:=AxisFlyCut_Stop,);
    AxisFlyCut_Stop:=0;
    AxisConvery_Stop:=0;

    MC_Reset1(Axis:= Axis_CONVERY, Execute:= r1, );
    MC_Reset2(Axis:= Axis_FlyCut, Execute:= r2, );
    MC_Reset3(Axis:= Axis_ZJ, Execute:= r3, );

    IF Sysstatus >0 AND ( 飞剪伺服.wstate <>8) THEN
    b:=b+1;
    SysStatuMark:=2; //第二个伺服网络断线
    END_IF

    IF Sysstatus >0 AND ( 追剪伺服.wstate <>8) THEN
    a:=a+1;
    SysStatuMark:=3; //第一个伺服网络断线
    END_IF

    //---下面的语句是为了让MC指令能得到下一次的上升沿------------>>---
    MC_MoveAbsolute2(Axis:= Axis_FlyCut ,Execute:=FALSE , );
    MC_MoveVelocity1(Axis:= Axis_CONVERY , Execute:=FALSE,);
    MC_SetPosition1(Axis:= Axis_FlyCut,Execute:=FALSE,Mode:=FALSE,);

    继续阅读
    • 我的微信
    • 这是我的微信扫一扫
    • weinxin
    • 我的微信公众号
    • 我的微信公众号扫一扫
    • weinxin
    MES视觉计数包装设备 其他

    MES视觉计数包装设备

    我们在工业生产过程中,经常会有用到计数的要求,尤其是小的产品,人工点数效率低下,而且很容易出错,工人在点数过程中容易产生视觉疲劳,多点或漏点的情况时常出现。普通的产品我们可以用称重的方式解决,但是称重...
    粉沫自动包装机 其他

    粉沫自动包装机

    粉末包装机采用螺旋下料及电子称重技术相结合,微机控制,具有自动定量、自动充填、自动修正误差、计数、清料等功能。适用于农药、兽药、添加剂、面粉、奶粉、洗衣粉、固体饮料、白糖、味精、复合调味品(如麻辣鲜)...
    在线包装机与mes系统对接 其他

    在线包装机与mes系统对接

    设备对接的概念 1.对接只是手段,获取数据并控制设备才是目的。 2.对接的定义:MES系统通过一定的方式,与设备进行通信。 3.需要靠两个系统做一定的开发。 设备对接-数据的流向 1.可能会有两个方向...
    O型密封圈包装设备 其他

    O型密封圈包装设备

    O型密封圈是指截面为"O"形的橡胶圈。是液压与气压传动系统中使用较为广泛的一种。主要用于机械部件在静态条件下防止液体和气体介质的泄露。在某些情况下,O型密封圈还能用做轴向往复运动和低速旋转运动的动态密...