#include "global.h" #if XI_DONG_MACHINE unsigned char FKCX_cGeiLiaoNum,FKCX_bStopOver,FKCX_bStopXiao,FKCX_bStopFang,FKCX_bStopXiaCong = 0,FKCX_bXiaCong; unsigned short cCountOutTime; /************************************** ** 函数名称:void ChaXiaoJi(void) ** 函数功能:方块插稍机动作函数 ** 输入输出说明: 输入: X0 插销启动 X1 停止开关 X2 方块启动 X3 手动钩针 X4 手动压带 X5 方块.插销选择 X6 手动给料 X7 手动夹料 X10 手动送料 X11 手动下冲 X12 过链接近开关 X13 下冲感应接近开关 X14 夹插销光电开关 X15 夹方块光电开关 X16 送插销到位磁感 X17 退送插销到位磁感 X20 送方块到位磁感 X21 退送方块到位磁感 X22 压带磁感 X23 给插销磁感 X24 给方块磁感 X25 冲针选择 X26 冲针保护 X27 打单边 输出: Y0 离合器 Y1 计数 Y2 插销运行指示 (触摸屏时为振动盘) Y3 方块运行指示 (触摸屏时为警告蜂鸣器) Y4 方块垫块电磁阀 Y5 压带电磁阀 Y6 下冲电磁阀 Y7 插销垫块电磁阀 Y10 给插销电磁阀 Y11 夹插销电磁阀 Y12 送插销电磁阀 Y13 送方块电磁阀 Y14 夹方块电磁阀 Y15 给方块电磁阀 Y16 勾针电磁阀 Y017 冲子选择电磁阀 D0 给插销(方块)到位后延时退回 D1 送插捎(方块)到位夹打开延时退回 D2 下冲输出时间 D3 给料次数 D4 给料故障后下一次给料时间 D5 给料到前点的最长时间 D6 延时停离合 D7 延时上勾针 D8 普通方块插销设置(2.55) 上下拉方块插销设置(0.55) D9 加速时间 D10 起动速度 D11 最高速度 D12 下冲感应方式(0 老方式 1 新常亮方式) ***************************************/ unsigned char FKCX_cReady,FKCX_cHalfRun,FKCX_cYaDai,FKCX_cSelectXiaChong,FKCX_YaDaiError,FKCX_cXiaChongStep = 0,FKCX_bRunning,FKCX_bStop; unsigned long FKCX_cErrorTime,FKCX_cErrorTime1,FKCX_cStartKeyDelay,FKCX_cTotal,FKCX_cTestNum,FKCX_cErrorTime2; unsigned long FKCX_JiaXiao(unsigned long En_Dis); unsigned long FKCX_SongXiao(unsigned long En_Dis); unsigned long FKCX_Motor(unsigned long En_Dis); unsigned long FKCX_JiaFang(unsigned long En_Dis); unsigned long FKCX_SongFang(unsigned long En_Dis); void FKCX_XiaChongStep(void); //故障报警 void FKCX_SetAlarmCode(unsigned alarm_code) { SetAlarmCode(FKCX_ALARM_ADDR,alarm_code); FKCX_bStop = 1; } void FKCX_InitAction(void) { XGearRatio = 1; YGearRatio = 1; } void FKCX_XiaChongStep(void) { static unsigned long dwXiaChongDelay; unsigned short ch,i; switch(FKCX_cXiaChongStep) { case 1: { if(FKCX_XC_ENABLE) { AxisMoveTwoPos(Y_AXIS,FKCX_XC_SPEED,2000,1,9999999,0); SETY006(); } else FKCX_cXiaChongStep = 0; } break; case 2: { if(X13_UP) { dwXiaChongDelay = dwTickCount + user_datas[17]*10; FKCX_cXiaChongStep = 3; } else if(dwTickCount >= dwXiaChongDelay) { FKCX_SetAlarmCode(16); } } break; case 3: { if(dwTickCount >= dwXiaChongDelay) { AxisEgmStop(Y_AXIS); CLRY006(); FKCX_cXiaChongStep = 4; } } break; case 4: { if(!Y_DRV) FKCX_cXiaChongStep = 0; } break; case 10: { AxisMoveTwoPos(Y_AXIS,FKCX_XC_SPEED,2000,1,0,0); SETY006(); dwXiaChongDelay = dwTickCount + 50; FKCX_cXiaChongStep = 11; } break; case 11: { if(dwTickCount >= dwXiaChongDelay) { AxisEgmStop(Y_AXIS); CLRY006(); FKCX_cXiaChongStep = 0; } } break; case 20: { AxisContinueMove(Y_AXIS,FKCX_XC_SPEED,FKCX_DIR_P); FKCX_cXiaChongStep = 21; SETY006(); } break; default:; } } void FKCX_Action(void) { unsigned long i,j; static unsigned long c10msDelay = 0; if(FKCX_bRunning) { if(FKCX_cHalfRun == 0) { M00 = 0; M01 = 0; M03 = 0; M04 = 0; M05 = 0; M06 = 0; M07 = 0; M08 = 0; M09 = 0; M10 = 0; M11 = 0; M12 = 0; M13 = 0; M14 = 0; } } else { if(M12 == 0)SETDR(); } if(dwTickCount >= c10msDelay) { c10msDelay = dwTickCount+10; if(cCountOutTime > 0) { cCountOutTime--; if(cCountOutTime == 0)CLRY001(); } } if(!FKCX_bRunning) { if(M25) { M25 = 0; //M25 if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep = 10; } if(M12) { if((cStepMByte2==0)&& !X_DRV) { MoveAction_Const_AccDec(X_AXIS, FKCX_DIR_P, user_datas[11],user_datas[10],user_datas[9],10); } } else { if((cStepMByte2==0) && X_DRV) { AxisEgmStop(X_AXIS); } } if(M27) { M27 = 0; //M27 if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep = 20; } } if(M15) //M15 故障确定 { M15 = 0; user_datas[100] = 0; cDelayTime7 = dwTickCount + 1010; CLRY003(); } if(M09) //清产量 { if(dwTickCount >= cDelayTime8) { M09 = 0; ClrcToTal(76); } } else { cDelayTime8 = dwTickCount + 200*10; } if(user_datas[71]) SETY02(); else CLRY02(); //手动模式 //手条件 if((!X01 || Y04 || Y07) && !FKCX_bRunning) { if(!M10) { //变为插稍方式 if(Y010) //插稍给料 { M19 = 1; } if(Y011) //插稍夹料 { M20 = 1; } if(Y012) //插稍夹料 { M21 = 1; } } else { //变为方块方式 if(Y015) //方块给料 { M19 = 1; } if(Y014) //方块夹料 { M20 = 1; } if(Y013) //方块夹料 { M21 = 1; } } //手动下冲 if(X11_UP || M08) { M08 = 0; if(dwTickCount >= cDelayTime7) { cDelayTime7 = dwTickCount + 10*10; // 送插销 送方块 退送插销到位 退送方块到位 if((Y012 == 0) && (Y013 == 0) && (X017 != 0) && (X021 != 0) //勾针电磁阀 压带磁感 手动下冲 上升延 &&(Y016 == 0) && (X022 != 0) && ((user_datas[12] == 0) || X013) ) { //方块\插销选择 if(X005 || (M10 == 0))//插销 { SETY007(); CLRY004(); } else //方块 { SETY004(); CLRY007(); } SETY006(); //下冲电磁阀 if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1; cDelayTime1 = dwTickCount + user_datas[2]*10; FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME; M14 = 1; //M14 } else //下冲条件不满足警告 { SETY003(); if(Y005 == 0)FKCX_SetAlarmCode(ERY05); else if(Y012 != 0)FKCX_SetAlarmCode(ERY12); else if(Y013 != 0)FKCX_SetAlarmCode(ERY13); else if(Y016 != 0)FKCX_SetAlarmCode(ERY16); else if(X017 == 0)FKCX_SetAlarmCode(ERX17); else if(X021 == 0)FKCX_SetAlarmCode(ERX21); else if(X013 == 0)FKCX_SetAlarmCode(ERX13); else FKCX_SetAlarmCode(ERX22); } } } if((Y006 != 0)) { if(X13_DW || ((user_datas[12] == 0) && (dwTickCount >= cDelayTime1))) { if(!FKCX_XC_ENABLE)CLRY006(); //下冲 cDelayTime1 = dwTickCount + 50; } } if((X013 != 0) && ((user_datas[12] == 0) || ((dwTickCount >= cDelayTime1) && !Y006))) { CLRY004(); //方块垫片 CLRY007(); //方块垫片 if(!FKCX_XC_ENABLE)CLRY006(); //下冲 M16 = 0; //M16 M14 = 0; } else if(M14 && (dwTickCount >= FKCX_cErrorTime) && (FKCX_XC_ENABLE==0)) //下冲故障警告 { M14 = 0; FKCX_SetAlarmCode(12); SETY003(); CLRY004(); //方块垫片 CLRY007(); //方块垫片 if(!FKCX_XC_ENABLE)CLRY006(); //下冲 } //手动勾针 if(X003 || (M3)) { M3 = 0; if(dwTickCount >= cDelayTime7) { cDelayTime7 = dwTickCount + 60; if(Y016)CLRY016(); // 方块垫片 插稍垫片 下冲 else if((Y004 == 0) && (Y007 == 0) && (Y006 == 0) && // 送插稍 送方块 送插稍到位 送方块到位 (Y012 == 0) && (Y013 == 0) && (X016 == 0) && (X020 == 0)) { SETY016(); } else //勾针条件不满足警告 { SETY003(); if(Y004 != 0)FKCX_SetAlarmCode(ERY04); else if(Y006 != 0)FKCX_SetAlarmCode(ERY06); else if(Y007 != 0)FKCX_SetAlarmCode(ERY07); else if(Y012 != 0)FKCX_SetAlarmCode(ERY12); else if(Y013 != 0)FKCX_SetAlarmCode(ERY13); else if(X016 != 0)FKCX_SetAlarmCode(ERX16); else FKCX_SetAlarmCode(ERX20); } } } //手动勾针完成 //手动压带 if(X004 || M4) { M4 = 0; if(dwTickCount >= cDelayTime7) { cDelayTime7 = dwTickCount + 8*10; if(Y005)CLRY005(); else { SETY005(); FKCX_cErrorTime1 = dwTickCount + FKCX_ERRORTIME; FKCX_YaDaiError = 1; } } if(Y005) //压带 FKCX_cYaDai = 1; else FKCX_cYaDai = 0; } if(X022) { FKCX_YaDaiError = 0; } if(FKCX_YaDaiError && Y005 && (!X022) && (dwTickCount >= FKCX_cErrorTime1)) { SETY003(); FKCX_SetAlarmCode(13); FKCX_YaDaiError = 0; } //手动压带完成 //手动送料 // 手动送料 if(FKCX_SongXiao(FKCX_TRUE) == FKCX_TRUE)cStepMByte5 = 0; if(FKCX_SongFang(FKCX_TRUE) == FKCX_TRUE)cStepMByte6 = 0; if(X010 || M7) { SETDR(); M7 = 0; if(dwTickCount >= cDelayTime7) { cDelayTime7 = dwTickCount + 10*10; if(X005 || (M10 == 0)) //手动送插销 { CLRY013(); if(Y012) { cStepMByte5 = 3; cDelayTime5 = dwTickCount + 5; } // 方块有料 勾针阀 插销垫片 方块垫片 下冲阀 给料电磁阀 给料前点 else if((X015 != 0) && (Y016 == 0) && (Y007 == 0) && (Y004 == 0) && (Y006 == 0) && (Y010 == 0) && (X023 == 0)) { SETY012(); } else //送料不满足条件 { SETY003(); if(Y004 != 0)FKCX_SetAlarmCode(ERY04); else if(Y006 != 0)FKCX_SetAlarmCode(ERY06); else if(Y007 != 0)FKCX_SetAlarmCode(ERY07); else if(Y010 != 0)FKCX_SetAlarmCode(ERY10); else if(Y016 != 0)FKCX_SetAlarmCode(ERY16); else if(X015 == 0)FKCX_SetAlarmCode(ERX15); else if(X023 != 0)FKCX_SetAlarmCode(ERX23); } } else //手动送方块 { CLRY012(); if(Y13) { cStepMByte6 = 3; cDelayTime6 = dwTickCount + 5; } // 勾针阀 插销垫片 方块垫片 下冲阀 给料电磁阀 给料前点 else if((Y016 == 0) && (Y007 == 0) && (Y004 == 0) && (Y006 == 0) && (Y015 == 0) && (X024 == 0)) { SETY013(); } else //送料不满足条件 { SETY003(); if(Y004 != 0)FKCX_SetAlarmCode(ERY04); else if(Y006 != 0)FKCX_SetAlarmCode(ERY06); else if(Y007 != 0)FKCX_SetAlarmCode(ERY07); else if(Y015 != 0)FKCX_SetAlarmCode(ERY15); else if(Y016 != 0)FKCX_SetAlarmCode(ERY16); else if(X024 != 0)FKCX_SetAlarmCode(ERX24); } } } } //手动送料完成 //手动给料 if(FKCX_JiaXiao(FKCX_TRUE) == FKCX_TRUE)cStepMByte3 = 0; if(FKCX_JiaFang(FKCX_TRUE) == FKCX_TRUE)cStepMByte4 = 0; if(X006 || M5) { M5 = 0; if(dwTickCount >= cDelayTime7) { cDelayTime7 = dwTickCount + 10*10; if(X005 || (M10 == 0)) //给插销 { CLRY014(); CLRY015(); if(Y010) { CLRY011(); //夹插稍 cStepMByte3 = 3; cDelayTime5 = dwTickCount + 50; } //送料在原点 在夹紧情况下无料 或夹张开 送料 else if((X017 != 0) && (((Y011 == 0) && (X014 != 0)) || Y011) && (Y012 == 0) && (Y015 == 0) && (X021 != 0)) { SETY010(); //给插稍 SETY011(); //夹插稍 } else //不满足给料 { CLRY010(); SETY003(); if(((Y011 == 0) && (X014 == 0))) FKCX_SetAlarmCode(ERX14); else if(Y012 != 0) FKCX_SetAlarmCode(ERY12); else if(X017 == 0) FKCX_SetAlarmCode(ERX17); else FKCX_SetAlarmCode(ERX21); } } else //给方块 { CLRY010(); CLRY011(); if((Y015)) { CLRY014(); //夹方块 cStepMByte4 = 3; cDelayTime6 = dwTickCount + 50; } //送料在原点 在夹紧情况下无料 或夹张开 送料 else if((X021 != 0) && (((Y014 == 0) && (X015 != 0)) || Y014) && (Y013 == 0) &&(X017 != 0)) { SETY015(); //给方块 SETY014(); //夹方块 } else //不满足给料 { CLRY015(); SETY003(); if(((Y014 == 0) && (X015 == 0)))FKCX_SetAlarmCode(ERX15); else if(Y013 != 0) FKCX_SetAlarmCode(ERY13); else if(X021 == 0) FKCX_SetAlarmCode(ERX21); else FKCX_SetAlarmCode(ERX17); } } } } //手动给料完成 //手动夹料 if(X007 || M6) { M6 = 0; if(dwTickCount >= cDelayTime7) { cDelayTime7 = dwTickCount + 10*10; if(X005 || (M10 == 0) ) //给插销 { CLRY014(); if(Y011) CLRY011(); else SETY011(); } else //给方块 { CLRY011(); if(Y014) CLRY014(); else SETY014(); } } } //手动夹料完成 } //互锁保护 if((Y004 != 0) || (Y007 != 0)) { CLRY012(); CLRY013(); } if((Y012 != 0) || (Y013 != 0)) { CLRY004(); CLRY007(); } //新功能选择(冲针选择) if(X25_UP && (X27 == 0)) { if(FKCX_cSelectXiaChong == 0) { FKCX_cSelectXiaChong = 1; if(Y007) //由垫片判断插稍还是方块 { SETY017(); //插稍 user_datas[88] = 1; } else { CLRY017(); user_datas[88] = 0; } } else FKCX_cSelectXiaChong = 0; } else if(X027) { CLRY017(); //插稍 } //手动下冲完成 //自动 // // 手动钩针 钩针输出 手动下冲 下冲输出 if((FKCX_bRunning == 0) && (X003 == 0) && (Y016 == 0) && (X011 == 0) && (Y006 == 0) && //手动给料 插稍给料 方块给料 手动夹料 (X006 == 0) && (Y010 == 0) && (Y015 == 0) && (X007 == 0) && //插稍夹料 方块夹料 手动送料 插稍送料 方块送料 (Y011 == 0) && (Y014 == 0) && (X010 == 0) && (Y012 == 0) && (Y013 == 0) && //方块选择 插稍送料原点 方块送料原点 (X017 != 0) && (X021 != 0)) { FKCX_cReady = 1; } else FKCX_cReady = 0; FKCX_XiaChongStep(); //停止 故障停机 按停止键 if((FKCX_bStop) || M2 || ((X01_UP) && (FKCX_cStartKeyDelay == 0))) { if(M2 || (X01_UP)) CLRY003(); FKCX_cStartKeyDelay = 8; FKCX_cHalfRun = 0; FKCX_bRunning = 0; AxisEgmStop(X_AXIS); if(FKCX_cXiaChongStep == 21) { AxisEgmStop(Y_AXIS); CLRY006(); FKCX_cXiaChongStep = 0; } SETDR(); //电机放松 M2 = 0; if(FKCX_bStopOver < 2) { FKCX_bStopOver++; } else FKCX_bStopOver = 0; FKCX_bStop = 0; //完全停止 if((X022 == 0) || (FKCX_bStopOver == 0) || (X04_DW)) { cStepMByte = 0; cStepMByte1 = 0; cStepMByte2 = 0; cStepMByte3 = 0; cStepMByte4 = 0; cStepMByte5 = 0; cStepMByte6 = 0; FKCX_bStopOver = 2; FKCX_bStopXiao = 0; FKCX_bStopFang = 0; FKCX_bStopXiaCong = 0; AxisEgmStop(X_AXIS); Y00 = 0; Y01 = 0; Y05 = 0; Y10 = 0; Y11 = 0; Y12 = 0; Y13 = 0; Y14 = 0; Y15 = 0; Y16 = 0; if((X004 != 0) || FKCX_cYaDai) { SETY005(); } else if(Y017) { if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1; SETY006(); //下冲电磁阀 cDelayTime1 = dwTickCount + user_datas[2]*10; FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME; } } else //故障停止 { cStepMByte = 0; cStepMByte1 = 0; cStepMByte2 = 0; cStepMByte3 = 0; cStepMByte4 = 0; cStepMByte5 = 0; cStepMByte6 = 0; FKCX_bStopOver = 2; FKCX_bStopXiao = 0; FKCX_bStopFang = 0; FKCX_bStopXiaCong = 0; AxisEgmStop(X_AXIS); Y00 = 0; Y01 = 0; Y05 = 0; Y10 = 0; Y11 = 0; Y12 = 0; Y13 = 0; Y14 = 0; Y15 = 0; Y16 = 0; SETY005(); } } //下冲时判断是否出错 // 压带磁感 //按插销起动 急停 方块工作指示 if((X00_UP || M0 || (M11 && (M10 == 0))) && (FKCX_cReady != 0) && (X001 == 0) && ((FKCX_bStopFang) == 0) && ((X015 != 0) || FKCX_bStopXiaCong) && (FKCX_bRunning == 0)) { SetAlarmCode(FKCX_ALARM_ADDR,0); if(M11)FKCX_cHalfRun = 1; M0 = 0; M11 = 0; FKCX_bStopXiao = 0; FKCX_bStopOver = 0; FKCX_bRunning = 1; cStepMByte2 = 0; cStepMByte3 = 0; FKCX_cGeiLiaoNum = 0; if(FKCX_bStopXiaCong != 0) { cStepMByte = 4; if(X015 != 0) cStepMByte4 = 1; //给方块开始 else cStepMByte4 = 10; if(user_datas[8] != 55) { if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1; SETY006(); //下冲 SETY007(); //垫片 cDelayTime1 = dwTickCount + user_datas[2]*10; FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME; M14 = 1; } FKCX_bStopXiao = 0; } else cStepMByte = 1; //从插销开始 } //按方块起动指示 if(((X02_UP) || M1 || (M11 && M10 && X022 && Y005)) && (FKCX_cReady != 0) && (X001 == 0) && (FKCX_bRunning == 0) && (FKCX_bStopXiao == 0) && ((FKCX_bStopFang) != 0)) { SetAlarmCode(FKCX_ALARM_ADDR,0); if(M11)FKCX_cHalfRun = 1; M1 = 0; M11 = 0; FKCX_bStopOver = 0; FKCX_bRunning = 1; cStepMByte3 = 0; cStepMByte2 = 0; FKCX_cGeiLiaoNum = 0; FKCX_bStopFang = 1; //之前已经送好料 直接下冲 if((FKCX_bStopXiaCong) != 0) { cStepMByte4 = 0; cStepMByte = 7; SETY006(); //下冲 if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1; SETY004(); //方块垫片 cDelayTime1 = dwTickCount + user_datas[2]*10; FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME; M14 = 1; } else { cStepMByte = 5; //从方块开始 if((X015 != 0)) cStepMByte4 = 1; else cStepMByte4 = 10; //已经有料 } } else { M1 = 0; if(M10)M11 = 0; } //从插销步开始工作 if((cStepMByte == 1)) { //电机开始 if((Y005) && (X022 != 0)) //先压带 { cStepMByte2 = 10; } else cStepMByte2 = 1; //给销开始 cStepMByte3 = 1; FKCX_cGeiLiaoNum = 0; //转下一步 cStepMByte = 2; FKCX_bStopXiaCong = 0; if(X014 == 0)cStepMByte3 = 10; } //等待给料,电机拖带 if((cStepMByte == 2)) { i = FKCX_Motor(FKCX_TRUE); FKCX_bStopXiao = 1; //没料 j = FKCX_JiaXiao(FKCX_TRUE); //拖带和给料已完成 if((i == FKCX_TRUE) && (j == FKCX_TRUE)) { cStepMByte = 3; cStepMByte5 = 1; //送梢启动 } } //送插销 if((cStepMByte == 3)) { if((user_datas[12] == 0) || X013) i = FKCX_SongXiao(FKCX_TRUE); //送料完毕(销) if(i == FKCX_TRUE) { cStepMByte = 4; if((FKCX_cHalfRun == 0) && (Y007 == 0)) //半 { if((X015 != 0) && (X027 == 0)) //打单边 cStepMByte4 = 1; else cStepMByte4 = 10; //已经有料 FKCX_cGeiLiaoNum = 0; } FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME; if(user_datas[8] != 55) { if(Y007) { if(dwTickCount >= cDelayTime1) { cStepMByte = 4; SETY006(); //下冲 if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1; cDelayTime1= dwTickCount + user_datas[2]*10; } } else { cStepMByte = 3; SETY007(); //垫片 cDelayTime1= dwTickCount + user_datas[13]*10; } M14 = 1; } } } //下冲动作 if((cStepMByte == 4)) { if(Y006 != 0) { if(X13_DW || ((user_datas[12] == 0) && (dwTickCount >= cDelayTime1))) { if(!FKCX_XC_ENABLE)CLRY006(); //下冲 if(X027 == 0) FKCX_bStopFang = 1; FKCX_bStopXiao = 0; FKCX_bStopXiaCong = 0; cDelayTime1 = dwTickCount + 40; } } //下冲感应开关 if((((X013 != 0)&&(FKCX_cXiaChongStep==0)) && ((user_datas[12] == 0) || ((dwTickCount >= cDelayTime1) && !Y006))) || (user_datas[8] == 55)) { M14 = 0; if(!FKCX_XC_ENABLE)CLRY006(); //下冲 CLRY007(); //插销垫片 cDelayTime1 = dwTickCount + 60; if(X027 == 0) { FKCX_bStopFang = 1; cStepMByte = 5; } else cStepMByte = 8; FKCX_bStopXiao = 0; FKCX_bStopXiaCong = 0; if(FKCX_cHalfRun) //半 { cStepMByte = 0; FKCX_bRunning = 0; FKCX_cHalfRun = 0; CLRY002(); } } if(dwTickCount >= FKCX_cErrorTime) { SETY003(); SetAlarmCode(FKCX_ALARM_ADDR,16); CLRY007(); //插销垫片 if(!FKCX_XC_ENABLE)CLRY006(); } //给方块开始 j = FKCX_JiaFang(FKCX_TRUE); } if((cStepMByte == 5)) { j = FKCX_JiaFang(FKCX_TRUE); if(j == FKCX_TRUE) //给方块已经完成 { cStepMByte = 6; cStepMByte6 = 1; //送方块开始 } } if((cStepMByte == 6)) { j = FKCX_SongFang(FKCX_TRUE); //送料完毕(销) if(j == FKCX_TRUE) { cStepMByte4 = 0; if(Y004) { if(dwTickCount >= cDelayTime1) { cStepMByte = 7; SETY006(); //下冲 if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1; cDelayTime1 = dwTickCount + user_datas[2]*10; FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME; } } else { SETY004(); //方块垫片 cDelayTime1 = dwTickCount + user_datas[13]*10; } M14 = 1; } else if((user_datas[12] == 1) && !X013) //证明没法卡住 { SETY003(); SetAlarmCode(FKCX_ALARM_ADDR,16); CLRY007(); //插销垫片 CLRY013(); } } //下冲动作 if((cStepMByte == 7)) { if(Y006 != 0) { if(X13_DW || ((user_datas[12] == 0) && (dwTickCount >= cDelayTime1))) { if(!FKCX_XC_ENABLE)CLRY006(); //下冲 cDelayTime1 = dwTickCount + 40; } } //下冲感应开关 if((X013 != 0) && ((user_datas[12] == 0) || ((dwTickCount >= cDelayTime1) && !Y006))) { CLRY004(); //方块垫片 cStepMByte = 8; FKCX_bStopFang = 0; FKCX_bStopXiaCong = 0; FKCX_bStopFang = 0; M14 = 0; } if(dwTickCount >= FKCX_cErrorTime) { SETY003(); CLRY004(); //方块垫片 SetAlarmCode(FKCX_ALARM_ADDR,16); if(!FKCX_XC_ENABLE)CLRY006(); } } //一个周期完成 方块没插在拉链上带出来 if(((cStepMByte == 8))) { cStepMByte3 = 0; cStepMByte4 = 0; cStepMByte5 = 0; cStepMByte6 = 0; //计数器 if(FKCX_cHalfRun == 0) //半循环不用计数 { cCountOutTime = 8; SETY001(); } //在先手动压带情况下 if(FKCX_cYaDai || FKCX_cHalfRun) { CLRY002(); FKCX_bRunning = 0; FKCX_cHalfRun = 0; cStepMByte = 0; } //在其它启动情况下,启动下一周期 else { SETY002(); CLRY005(); //松压带 cStepMByte = 9; } } if(((cStepMByte == 9))) { if(X022 == 0) { cStepMByte = 1; //开始 cStepMByte4 = 0; cStepMByte3 = 0; cStepMByte5 = 0; cStepMByte6 = 0; cStepMByte1 = 0; cStepMByte2 = 0; FKCX_cTotal++; SetData32bits(76,FKCX_cTotal); CalProSP(78); //计算生产速度 } } } //电机控制 unsigned long FKCX_Motor(unsigned long En_Dis) { if(En_Dis == 0) { CLRY000(); AxisEgmStop(X_AXIS); SETDR(); //电机放松 return FKCX_TRUE; } switch(cStepMByte2) { case 1: //离合器起动 cStepMByte2 = 2; SETY000(); //离合器输出 if(user_datas[90] == 55)cDelayTime3 = dwTickCount + 300; //步进启动 CLRDR(); MoveAction_Const_AccDec(X_AXIS, FKCX_DIR_P, user_datas[11],user_datas[10],user_datas[9],1); break; case 2: //过链接近下降沿 if((X12_DW) || ((user_datas[90] == 55) && (dwTickCount >= cDelayTime3))) { cStepMByte2 = 3; cDelayTime3 = dwTickCount + 7; cDelayTime4 = dwTickCount + user_datas[7]; // 延时上勾针 FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME; MoveChangSpeed(X_AXIS,user_datas[10]); } break; case 3: //要加延时上勾针 if(dwTickCount >= cDelayTime4)SETY016(); //上勾针 //过链接近上升沿 //拖带到 if(((X12_UP) || (user_datas[90] == 55)) && (dwTickCount >= cDelayTime3)) { SETY016(); //上勾针 cStepMByte2 = 4; cDelayTime3 = dwTickCount + 250; } if(dwTickCount >= FKCX_cErrorTime) //拖带警告 { SETY003(); FKCX_SetAlarmCode(1); } break; case 4: if(X026) { cStepMByte2 = 5; cDelayTime3 = dwTickCount + user_datas[6]*5; } else if(dwTickCount >= cDelayTime3) { FKCX_SetAlarmCode(9); SETY003(); } break; case 5: if(dwTickCount >= cDelayTime3) { cStepMByte2 = 6; CLRY000(); //离合停 SETY005(); FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME; AxisEgmStop(X_AXIS); //步进电机停 } break; case 6: //压带到 if(X022 != 0) { cStepMByte2 = 7; //拖带完成 cDelayTime3 = dwTickCount + 30; } else if(dwTickCount >= FKCX_cErrorTime) //压带警告 { SETY003(); FKCX_SetAlarmCode(2); } break; case 7: if(dwTickCount >= cDelayTime3) { CLRY016(); //下勾针 cStepMByte2 = 10; //拖带完成 } break; case 10: return FKCX_TRUE; } return FKCX_FALSE; } //夹销.给销动作 unsigned long FKCX_JiaXiao(unsigned long En_Dis) { // if(En_Dis == 0) return FKCX_TRUE; switch(cStepMByte3) //离合器起动 { case 0: break; case 1: if(X017 != 0) //退送插销到位磁感 { cStepMByte3 = 2; SETY010(); //给插销打开 SETY011(); //夹插销打开 FKCX_cErrorTime1 = dwTickCount + user_datas[5]*10; cDelayTime5 = dwTickCount + 1200; } else CLRY010(); CLRY012(); break; case 2: //给销到位 if(X023 != 0) //给销到位 { if(X23_UP) cDelayTime5 = dwTickCount + 25; if(dwTickCount >= cDelayTime5) { CLRY011(); //夹插销夹 cStepMByte3 = 6; cDelayTime5 = dwTickCount + 50; } } else if(dwTickCount >= FKCX_cErrorTime1) { CLRY011(); //夹方块夹 cStepMByte3 = 0; FKCX_cGeiLiaoNum++; if(FKCX_cGeiLiaoNum >= user_datas[3]) //给料次数到卡料警告 { FKCX_cGeiLiaoNum = 0; SETY003(); FKCX_SetAlarmCode(3); cStepMByte3 = 0; } else { cStepMByte3 = 4; CLRY010(); //给插稍退回 } } break; case 3: //给料到位成功 if(dwTickCount >= cDelayTime5) { cStepMByte3 = 0; //不用料自动运行 if((X014 != 0) && (user_datas[90] != 55) && (FKCX_bRunning != 0)) //没料 { FKCX_cGeiLiaoNum++; if(FKCX_cGeiLiaoNum >= user_datas[3]) //送三次没料 { FKCX_cGeiLiaoNum = 0; SETY003(); FKCX_SetAlarmCode(5); } else { cStepMByte3 = 4; } } else { cStepMByte3 = 10; FKCX_cGeiLiaoNum = 0; CLRY010(); //给插销退回 } } break; case 4: //给料不成功 if(X023 == 0) { cStepMByte3 = 5; cDelayTime5 = dwTickCount + user_datas[4]*10; } break; case 5: if((dwTickCount >= cDelayTime5)) { if(X014 != 0) { cStepMByte3 = 2; SETY010(); //给插销打开 SETY011(); //夹插销打开 FKCX_cErrorTime1 = dwTickCount + user_datas[5]*10; cDelayTime5 = dwTickCount + 1200; } else { FKCX_cGeiLiaoNum = 0; SETY003(); FKCX_SetAlarmCode(3); } } break; case 6: if(dwTickCount >= cDelayTime5) { CLRY010(); //给插销退回 CLRY011(); //夹插销夹 cStepMByte3 = 3; cDelayTime5 = dwTickCount + user_datas[0]*10 + 30; } break; case 10: return FKCX_TRUE; } return FKCX_FALSE; } //送销动作 unsigned long FKCX_SongXiao(unsigned long En_Dis) { // if(En_Dis == 0) return FKCX_TRUE; switch(cStepMByte5) { case 0: break; case 1: cStepMByte5 = 2; FKCX_cErrorTime1 = dwTickCount + 10*FKCX_ERRORTIME; if((X014 == 0) || (user_datas[90] == 55) || (FKCX_bRunning == 0)) //方块 SETY012(); //送销打开 else break; case 2: //送销到位 if((X016 != 0) && (X017 == 0)) { cStepMByte5 = 3; cDelayTime5 = dwTickCount + 20; } else if((dwTickCount >= FKCX_cErrorTime1) && (FKCX_cHalfRun == 0)) //送销不到位故障 { cStepMByte5 = 0; SETY003(); FKCX_SetAlarmCode(7); } break; case 3: if(dwTickCount >= cDelayTime5) { cStepMByte5 = 4; SETY011(); //夹插销打开 cDelayTime5 = dwTickCount + user_datas[1]*10; } break; case 4: if(dwTickCount >= cDelayTime5) { cStepMByte5 = 5; CLRY012(); //退送插销 if(FKCX_bRunning != 0)FKCX_bStopXiaCong = 1; FKCX_cErrorTime1 = dwTickCount + FKCX_ERRORTIME; } break; case 5: if((X017 != 0) && (X016 == 0)) { cStepMByte5 = 6; CLRY011(); //夹插销关 cDelayTime5 = dwTickCount + 500; } else if(dwTickCount >= FKCX_cErrorTime1) //退送出错警告 { SETY003(); FKCX_SetAlarmCode(7); } break; case 6: if(X014 != 0) { cStepMByte5 = 7; if(FKCX_bRunning != 0)FKCX_bStopXiaCong = 1; } else if(dwTickCount >= cDelayTime5) //带料出来警告 { cStepMByte5 = 0; FKCX_cTestNum = 35; FKCX_bStopXiaCong = 0; SETY003(); FKCX_SetAlarmCode(11); } break; case 7: return FKCX_TRUE; } return FKCX_FALSE; } //夹方块.给方块动作 unsigned long FKCX_JiaFang(unsigned long En_Dis) { // if(En_Dis == 0) return FKCX_TRUE; switch(cStepMByte4) { case 0: break; case 1: if(X021 != 0) { cStepMByte4 = 2; SETY015(); //给方块打开 SETY014(); //夹方块打开 FKCX_cErrorTime2 = dwTickCount + user_datas[5]*10; cDelayTime6 = dwTickCount + 1200; } else CLRY015(); CLRY013(); break; case 2: //给方块到位 if(X024 != 0) { if(X24_UP) { cDelayTime6 = dwTickCount + 20; } if(dwTickCount >= cDelayTime6) { CLRY014(); //夹方块夹 cStepMByte4 = 6; cDelayTime6 = dwTickCount + 50; } } else if(dwTickCount >= FKCX_cErrorTime2) { CLRY014(); //夹方块夹 cStepMByte4 = 0; FKCX_cGeiLiaoNum++; if(FKCX_cGeiLiaoNum >= user_datas[3]) //给料三次错误 { FKCX_cGeiLiaoNum = 0; SETY003(); FKCX_SetAlarmCode(4); } else { cStepMByte4 = 4; CLRY015(); //给方块退回 } } break; case 3: //已给料到前面 if(dwTickCount >= cDelayTime6) { //没带空打 if((X015 != 0) && (user_datas[90] != 55) && (FKCX_bRunning != 0)) //没料 { cStepMByte4 = 0; FKCX_cGeiLiaoNum++; if(FKCX_cGeiLiaoNum >= user_datas[3]) //没料三次警告 { FKCX_cGeiLiaoNum = 0; SETY003(); FKCX_SetAlarmCode(6); } else { cStepMByte4 = 4; } } else { cStepMByte4 = 10; //完成 FKCX_cGeiLiaoNum = 0; CLRY015(); //给方块退回 } } break; case 4://出错退回 if(X024 == 0) { cStepMByte4 = 5; cDelayTime6 = dwTickCount + user_datas[4]*10; } break; case 5: if((dwTickCount >= cDelayTime6)) { if(X015 != 0) { cStepMByte4 = 2; SETY014(); //给插销打开 SETY015(); //夹插销打开 FKCX_cErrorTime2 = dwTickCount + user_datas[5]*10; cDelayTime6 = dwTickCount + 1200; } else { FKCX_cGeiLiaoNum = 0; SETY003(); FKCX_SetAlarmCode(4); } } break; case 6: if(dwTickCount >= cDelayTime6) { CLRY015(); //给方块退回 cStepMByte4 = 3; cDelayTime6 = dwTickCount + user_datas[0]*10 + 30; } break; case 10: return FKCX_TRUE; } return FKCX_FALSE; } //送方块动作 unsigned long FKCX_SongFang(unsigned long En_Dis) { // if(En_Dis == 0)return FKCX_TRUE; switch(cStepMByte6) { case 0: break; case 1: if((X015 == 0) || (user_datas[90] == 55) || (FKCX_bRunning == 0)) { cStepMByte6 = 2; SETY013(); //送方块打开 FKCX_cErrorTime2 = dwTickCount + 10*FKCX_ERRORTIME; } break; case 2: //送销到位 if((X020 != 0) && (X021 == 0)) { cStepMByte6 = 3; cDelayTime6 = dwTickCount + 20; } else if((dwTickCount >= FKCX_cErrorTime2) && (FKCX_cHalfRun == 0)) //送销不到位故障 { cStepMByte6 = 0; FKCX_SetAlarmCode(6); SETY003(); } break; case 3: if(dwTickCount >= cDelayTime6) { cStepMByte6 = 4; SETY014(); //夹方块打开 cDelayTime6 = dwTickCount + user_datas[1]*10; } break; case 4: if(dwTickCount >= cDelayTime6) { cStepMByte6 = 5; CLRY013(); //退送方块 if(FKCX_bRunning != 0)FKCX_bStopXiaCong = 1; FKCX_cErrorTime2 = dwTickCount + FKCX_ERRORTIME; } break; case 5: if((X021 != 0) && (X020 == 0)) { cStepMByte6 = 6; CLRY014(); //夹方块关 cDelayTime6 = dwTickCount + 500; } else if(dwTickCount >= FKCX_cErrorTime2) //退送方块出错警告 { SETY003(); FKCX_SetAlarmCode(8); } break; case 6: if(X015 != 0) { cStepMByte6 = 7; if(FKCX_bRunning != 0) FKCX_bStopXiaCong = 1; } else if(dwTickCount >= cDelayTime6) //带料出来警告 { cStepMByte6 = 0; FKCX_bStopXiaCong = 0; SETY003(); FKCX_SetAlarmCode(11); } break; case 7: return FKCX_TRUE; } return FKCX_FALSE; } #endif