CODESYS 枕式机应用

  • 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
AUTOBAG包装机与ERP实现数据对接 其他

AUTOBAG包装机与ERP实现数据对接

  自动包装机实现与ERP实现数据交互: 1.企业通过设备与ERP系统交互,实现车间生产计划和调度、生产任务查询、生产过程监控、智能数据采集、质量检测与控制、物料跟踪、原辅料消耗控制、车间考...
CODESYS飞剪包装机 其他

CODESYS飞剪包装机

CODESYS飞剪包装机高速7伺服包装机中的应用高响应、高解析、集伺服放大器和运动控制器于一体的网络型伺服在立式包装机中的成功应用,伺服内置的电子凸轮功能使得飞剪曲线的建立轻而易举,高速抓取,高速比较...
JY450筒膜包装机 其他

JY450筒膜包装机

CODESYS不定长飞剪包装机 定义语法 语法:%<存储器区前缀><大小前缀><数字>|.<数字> l  编程系统支持以下3种存储区前缀 (1)I:输入...
JY450筒膜包装机 其他

JY450筒膜包装机

产品对象为高速CCD视觉计数机。 2. 设备的基本原理为通过高速线阵相机获得的图像数据、高度优化的视觉算法、合理的机械结构和合理的控制逻辑达到获取预设数量的颗粒型物料。 3. 本项目的客户对象为由计数...