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
    双色即印即贴包装机 其他

    双色即印即贴包装机

    双色贴标与包装机即时贴标 RS232C 串口(限制功能) USB 2.0 Slave 傳輸接口 支援 10/100 Mbit/s TCP/IP 通訊協定的以太網絡 2 組 USB-Master 連結外...
    真空包装机 其他

    真空包装机

        外抽式筒膜真空包装机1~10kg 产品名称:真空包装机1~10kg 产品型号:JYzn-5050PZ 适用范围:包括SMT、电子元器件、食品、医药等行业。 技术参数 型号规格 JYzn-505...
    标准包装机为什么还需要定制化 其他

    标准包装机为什么还需要定制化

    包装机为什么还要定制化: 1.标准机型不能满足产品需求那就需要定制化。 2.包装机需要集成到到自已设备系统中,受空间的限制,安装方式的不同,需要定制化。 3.包装机袋子宽度及长度标准机不能满足,需要定...
    连卷袋包装机与筒膜包装机应用方向的区别 其他

    连卷袋包装机与筒膜包装机应用方向的区别

    连卷袋包装机: 1.使用的包装袋是预先做好点断线及开口。 2.预先开口适用在人工投料,不适合在连续作业,主要原因制袋稳定性控制难度高。 3.预先开好口,定位难度大,要求不太高的应用场合采用光纤定位,要...