12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802 |
- #include "global.h"
- #if JU_XING_MACHINE ==1
- void KK_QueDuan_AlarmProtect(void);
- void KK_QueDuan_ManualAction(void);
- void KK_QueDuan_AutoAction(void);
- void KK_QueDuan_StepCheckStart(void);
- void KK_QueDuan_XiaQue(void);
- void KK_QueDuan_Motor(void);
- void KK_QueDuan_YuanDianAction(void);
- void KK_QueDuan_TuiLianAction(void);
- void KK_QueDuan_ExtiActionX31(void);
- void KK_QueDuan_BingLian(void);
- void KK_StopCode(void);
- void KKQD_TuiDaiAction(void);
- short *KK_length_buffer;
- void KKQD_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(KKQD_ALARM_ADDR,alarm_code);
- bAlarmStop = 1;
- }
- void KK_QueDuan_ExtiActionX31(void)
- {
- KK_cCheckLianFlg = 1;
- }
- void KK_StopCode(void)
- {
- switch(KKQD_StopStep)
- {
- case 1:
- KKQD_StopStep=2;
- if(X_DRV)
- {
- AxisChangeSpeedDirect(X_AXIS,GetCurSpeed(X_AXIS) * 2/3);
- AxisDecStop(X_AXIS);
- }
- break;
- case 2:
- if(!X_DRV || (KK_cRealPos < 10))
- {
- KKQD_StopCodeDelay=dwTickCount+350;
- KKQD_StopStep = 3;
- }
- break;
- case 3:
- if(dwTickCount >= KKQD_StopCodeDelay)
- {
- if(!cSTOPONE)
- {
- KKQD_StopStep=0;
-
- }
- else
- {
- KKQD_SetAlarmCode(KKQD_PARAM_ANQUANMEN_ALARM);
- KKQD_StopStep=0;
- cSTOPONE=0;
- }
- KKQD_SZ_OUT = 1; //电机松轴
- }
- break;
- }
- }
- void KK_QueDuan_InitAction(void)
- {
- float length_buff,pulse_buff;
-
- length_buff = KKQD_PARAM_CYCLE_LENGTH;
- pulse_buff = KKQD_PARAM_CYCLE_PULSE;
- XGearRatio = pulse_buff/length_buff;
- // KKQD_SZ_OUT = 1;
- KKQD_SetAlarmCode(0);
- SetDirReverse(X_AXIS, 1);
- }
- void KK_QueDuan_Action(void)
- {
-
- KK_QueDuan_AlarmProtect();
- KK_QueDuan_Motor();
- KK_QueDuan_XiaQue();
- KK_QueDuan_ManualAction();
- KK_QueDuan_TuiLianAction();
- KK_QueDuan_BingLian();
- KK_StopCode();
- KK_QueDuan_AutoAction();
- KK_QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
-
-
- }
- //手动动作
- void KK_QueDuan_ManualAction(void)
- {
- //条数或扎数达到后,台面电机转两秒之后再停机
- if(KK_cTABLETIME)
- {
- if(KK_cTABLETOTAL)
- {
- KK_cTABLETOTAL=0;
- KKQD_TABLE_VAVLE = 1;
- KKQD_TableDelay=dwTickCount + 2000;
-
- }
- if(dwTickCount >= KKQD_TableDelay)
- {
- KKQD_TABLE_VAVLE = 0;
- KK_cTABLETIME=0;
-
- }
- }
- if(bRunning == 0)
- {
-
-
-
- KK_cGoLimitEn = 0;
- if(KKQD_bClearTotal) //切断计数清零
- {
- KKQD_bClearTotal = 0;
- ClrcToTal(KKQD_TOTAL_ADDR);
- }
-
- if(KKQD_bClearNowTotal)
- {
- KKQD_bClearNowTotal = 0;
- KKQD_PARAM_NOW_CNT = 0;
- }
-
- if(KKQD_bXiaQie)
- {
- KKQD_bXiaQie = 0;
- if((KKQD_XiaQieStep == 0) && !KKQD_TL_VAVLE)
- {
- KKQD_XiaQieStep = 1;
- }
- }
-
- if(KKQD_bQianDianDW)
- {
- KKQD_bQianDianDW = 0;
- if(KKQD_MotorStep == 0)
- {
- KKQD_MotorStep = 61;
- cZipCnt = 0;
- }
- }
-
- if(KKQD_bTL)
- {
- KKQD_bTL = 0;
- if(KKQD_TL_VAVLE)
- {
- KKQD_TL_VAVLE = 0;
- }
- else if(!KKQD_GZ_VAVLE && !KKQD_SM_VAVLE)
- {
- KKQD_TL_VAVLE = ~KKQD_TL_VAVLE;
- }
- }
- if(KKQD_bECQ)
- {
- KKQD_bECQ=0;
- KK_cShuangDao=1;
- KK_cDiErLaChu=1;
- KK_cECQ_STOP=1;
- bRunning = 1;
- KKQD_AutoStep = 1;
-
- }
-
-
- // if(!Y_DRV)KKQD_bTL = 0;
-
- if(KKQD_bYD)
- {
- KKQD_bYD = 0;
- KKQD_YD_VAVLE = ~KKQD_YD_VAVLE;
- }
-
- if(KKQD_bGZ)
- {
- KKQD_bGZ = 0;
- KKQD_GZ_VAVLE = ~KKQD_GZ_VAVLE;
- }
-
- if(KKQD_bJD)
- {
- KKQD_bJD = 0;
- KKQD_JD_VAVLE = ~KKQD_JD_VAVLE;
- }
-
- if(KKQD_bXM)
- {
- KKQD_bXM = 0;
- KKQD_XM_VAVLE = ~KKQD_XM_VAVLE;
- if(!KKQD_XM_VAVLE)KKQD_GZ_VAVLE = 0;
- }
- if(KKQD_GOUZHEN_IN_UP)
- {
- KKQD_YD_VAVLE=1;
- }
-
- if(KKQD_bSM)
- {
- KKQD_bSM = 0;
- if(KKQD_SM_VAVLE)
- KKQD_SM_VAVLE = 0;
- else if(!KKQD_TL_VAVLE || !KKQD_PARAM_XM_ENABLE)
- KKQD_SM_VAVLE = 1;
- }
- //推方块
- if(KKQD_bTFK)
- {
- KKQD_bTFK = 0;
- KKQD_TFK_VAVLE = ~KKQD_TFK_VAVLE;
- }
- //台面电机
- if(KKQD_bTB)
- {
- KKQD_bTB = 0;
- KKQD_TABLE_VAVLE = ~KKQD_TABLE_VAVLE;
- }
-
- // if(KKQD_bYBD)
- // / {
- // KKQD_bYBD = 0;
- // KKQD_YBD_VAVLE = ~KKQD_YBD_VAVLE;
- // }
-
- if(KKQD_bTestCS)
- {
- KKQD_bTestCS = 0;
- KKQD_CS_OUT = 1;
- KKQD_CSDelay = dwTickCount + KKQD_PARAM_CS_TIME;
- }
-
- if(KKQD_bBL)//吹气
- {
- KKQD_bBL = 0;
- KKQD_CQ_VAVLE = ~KKQD_CQ_VAVLE;
- }
-
- if(KKQD_bHL) //护链,双开用
- {
- KKQD_bHL = 0;
- KKQD_HL_VAVLE = ~KKQD_HL_VAVLE;
- }
-
- if(KKQD_bYX)
- {
- KKQD_bYX = 0;
- KKQD_YX_VAVLE = ~KKQD_YX_VAVLE;
- }
- if(KKQD_XiaQieStep == 0)
- {
- if(dwTickCount >= KKQD_CSDelay)KKQD_CS_OUT = 0;
- }
- //电机控制
- if(KKQD_bGoMotor && !KKQD_QIAN_LIMIT_IN)
- {
- KKQD_SZ_OUT = 0;
- // KKQD_JZ_DIR = KKQD_YDIR_N;
- if(!X_DRV)
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED,KKQD_PARAM_GO_LOW_SPEED,10,12);
-
- }
-
- if(KKQD_bBackMotor) //后退限位已经取消
- {
- KKQD_SZ_OUT = 0;
- // KKQD_JZ_DIR = KKQD_YDIR_P;
- if(!X_DRV)
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_P,KKQD_PARAM_GO_LOW_SPEED,KKQD_PARAM_GO_LOW_SPEED,10,12);
- }
-
- if(!KKQD_bGoMotor && !KKQD_bBackMotor && (KKQD_MotorStep == 0))
- {
- if(X_DRV)AxisDecStop(X_AXIS);
- }
-
- if(KKQD_QIAN_LIMIT_IN && (KKQD_MotorStep == 0) && !KKQD_bBackMotor &&(KKQD_AutoStep == 0))
- {
- if(X_DRV)AxisEgmStop(X_AXIS);
- }
- }
- }
- void KK_QueDuan_AlarmProtect(void)
- {
- KK_cRealPos = GetPos(X_AXIS);
-
- if(!bRunning)
- {
- ;
-
- }
- else
- {
- if((KK_cRealPos > KKQD_PARAM_RUN_LENGTH) && (KKQD_PARAM_RUN_LENGTH > 3000)
- && (KK_cGoLimitEn != 0))
- {
- AxisEgmStop(X_AXIS);
- KKQD_JD_VAVLE = 0;
- KKQD_SetAlarmCode(KKQD_BACK_ALARM);
- }
- }
- }
- void KK_QueDuan_AutoAction(void)
- {
- //台面电机定时关掉
-
-
- if(KKQD_QIAN_STOP_Auto)
- {
-
- KK_cDLJ_ATUO=1;
- AxisEgmStop(X_AXIS);
-
-
-
- }
- if(KKQD_QIAN_START_Auto)
- {
- if(KK_cDLJ_ATUO)
- {
- KK_cDLJ_ATUO=0;
- KKQD_AutoDelay = dwTickCount + 1000;
- KKQD_MotorDelay = dwTickCount + 2000;
- if((KKQD_MotorStep==63 || KKQD_MotorStep==64 || KKQD_MotorStep==65) && !KKQD_QIAN_LIMIT_IN)
- AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED/3,KKQD_PARAM_GO_LOW_SPEED/3,15,15);
- else if((KK_cRealPos < KKQD_PARAM_ZIPPER_LENGTH) && (KKQD_MotorStep > 311))
- AxisMoveTwoPos(X_AXIS,1000,(KKQD_PARAM_ZIPPER_LENGTH - KK_cRealPos) + (*KK_length_buffer),
- KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED_LENGTH,KKQD_DIR_P,5000,3000,20,30);
-
- }
-
-
- }
- if(!KK_cDLJ_ATUO)
- {
- if(bRunning)
- {
- if(!KK_cTABLETIME)
- {
- if(dwTickCount >= KKQD_TBDelay)
- KKQD_TABLE_VAVLE = 0;
- }
- switch(KKQD_AutoStep)
- {
- case 1:
- if(dwTickCount >= KKQD_AutoDelay)
- {
- KKQD_AutoStep = 2;
- if(KKQD_MotorStep == 0)
- {
- KKQD_MotorStep = 61; //前点定位
- }
- KK_cGoLimitEn = 0;
- }
- break;
- case 2:
- if(KKQD_MotorStep == 0)
- {
- if(!KK_cShuangDao)
- KKQD_MotorStep = 30;
- else
- KKQD_MotorStep = 801;
- KKQD_AutoStep = 3;
- KK_cGoLimitEn = 1;
- }
- break;
- case 3:
- if(KKQD_MotorStep == 0)
- {
- if(KKQD_SAFE_IN)
- {
- bStop = 1;
- }
- else
- {
-
- if(!KK_cShuangDao)
- {
- if(KKQD_XiaQieStep == 0)
- KKQD_XiaQieStep = 1;
- }
- else
- {
- if(KKQD_XiaQieStep == 0)
- KKQD_XiaQieStep = 201;
- }
- KKQD_AutoStep = 4;
- }
- }
- break;
- case 4:
-
- // 闭口
- if((KKQD_XiaQieStep == 0) || ((KKQD_XiaQieStep == 6) && KKQD_KB_MODE)|| ((KKQD_XiaQieStep == 14) && (KKQD_KB_MODE == 0)))// && !KKQD_SHANG_MU_LIMIT_IN)
- {
- if(KKQD_MotorStep == 0)
- {
- KK_cGoLimitEn=0;
- KKQD_MotorStep = 40; //切完后退
-
- }
- KKQD_AutoStep = 5;
- }
-
- break;
- case 5:
-
- if(KKQD_MotorStep == 0)
- {
- if(!KK_cDiErLaChu)
- cZipCnt++;
- KKQD_PARAM_NOW_CNT++;
- cTableCnt++;
- AddToTal(KKQD_TOTAL_ADDR);
- AddToTal(CT_WORKTOTAL_ADDR);
- CalProSP(KKQD_PROSPEED_ADDR);
-
- if(cTableCnt >= KKQD_PARAM_TABLE_NUM)
- {
- cTableCnt = 0;
- KKQD_TABLE_VAVLE = 1;
- KKQD_TBDelay = dwTickCount + KKQD_PARAM_TB_TIME;
- }
-
- if( SingOneFlg || cZhouWanone)
- {
-
- {
- cZhouWanone=0;
- cStopMode=0;
- bRunning = 0;
- KKQD_AutoStep = 0;
- SingOneFlg = 0;
- KKQD_TABLE_VAVLE = 0;
-
- }
-
- // if(GetTotal(KKQD_TOTAL_ADDR) >= KKQD_PARAM_SET_TOTAL) KKQD_SetAlarmCode(KKQD_TOTAL_ALARM);
- }
- else
- {
- KKQD_AutoStep = 1;
-
- if((KKQD_PARAM_NOW_CNT >= KKQD_PARAM_ZHA_SHU) && (KKQD_PARAM_ZHA_SHU > 0))
- {
- KKQD_AutoDelay = dwTickCount + KKQD_PARAM_ZS_STOP_TIME;
- KKQD_PARAM_NOW_CNT = 0;
- KK_cTABLETIME = 1;
- KK_cTABLETOTAL= 1;
- if(KKQD_PARAM_ZS_STOP_TIME == 0)
- {
- bRunning = 0;
- KKQD_AutoStep = 0;
- SingOneFlg = 0;
- KK_cTABLETIME = 1;
- KK_cTABLETOTAL= 1;
- KKQD_SetAlarmCode(KKQD_TOTAL_ALARM);
- }
- }
- else
- KKQD_AutoDelay = dwTickCount + KKQD_PARAM_CYCLE_DELAY;
- }
- }
- break;
- }
- }
- }
- }
- void KK_QueDuan_StepCheckStart(void)
- {
- // 启动
- if((START_IN_UP) || bStart || KKQD_bSingle)
- {
- bStart = 0;
-
- if(!bRunning && (KKQD_AutoStep == 0))
- {
- if(KKQD_XIA_MU_LIMIT_IN && !KKQD_PARAM_XM_ENABLE)KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
- // else if(GetAlarmCode(KKQD_ALARM_ADDR) != 0);
- //else if(GetTotal(KKQD_TOTAL_ADDR) >= KKQD_PARAM_SET_TOTAL) KKQD_SetAlarmCode(KKQD_TOTAL_ALARM);
- // else if(KKQD_BL_VAVLE)KKQD_SetAlarmCode(KKQD_BL_ALARM);
- else if(KKQD_SM_VAVLE)KKQD_SetAlarmCode(KKQD_SM_ALARM);
- else
- {
- bRunning = 1;
- KKQD_AutoStep = 1;
- if(KKQD_PARAM_BL_ENABLE)
- KKQD_PARAM_BL_ENABLE=1 ; //并链起动
- if(KKQD_bSingle)
- {
- SingOneFlg= 1;
- KKQD_bSingle=0;
-
- }
- else
- {
- SingOneFlg=0;
- }
- cZipCnt = 0;
- KK_cTABLETIME = 0;
- KK_cTABLETOTAL= 0;
- cSTOPONE=0;
- cTuiFangKuaiCnt = 0;
- KKQD_BL_VAVLE = 0; //并链关
- KK_cDLJ_ATUO=0;
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- SetAlarmCode(KKQD_ALARM_ADDR,0);
- }
- }
- KKQD_bSingle = 0;
- }
- if(KKQD_STOP_ANNIU_IN_UP)
- {
- bRunning = 0;
- KKQD_XiaQieStep = 0;
- KKQD_AutoStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- KKQD_AutoDelay = dwTickCount;
- KKQD_MotorDelay = dwTickCount;
- KKQD_XiaQieDelay = dwTickCount;
- KKQD_KaDaiDelay = dwTickCount;
- KKQD_CSDelay = dwTickCount;
- KKQD_TBDelay = dwTickCount;
- KKQD_TFKDelay = dwTickCount;
- KKQD_TLDelay = dwTickCount;
- dwTickCount = KKQD_TBDelay;
- KKQD_CHUIQIStep=0;
- SingOneFlg = 0;
- KKQD_JD_VAVLE = 0;
- KKQD_SM_VAVLE = 0;
- KKQD_XM_VAVLE = 0;
- KKQD_YD_VAVLE = 0;
- KKQD_TFK_VAVLE= 0;
- KKQD_YX_VAVLE = 0;
- KKQD_HL_VAVLE = 0;
- KKQD_TL_VAVLE = 0;
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- KKQD_CS_OUT = 0;
- KKQD_XiaQieStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- KKQD_SZ_OUT = 1;
- KKQD_GZ_VAVLE = 0;
- KKQD_TABLE_VAVLE = 0;
- KKQD_StopStep=1;
- KK_cTABLETIME = 0;
- KK_cTABLETOTAL= 0;
- KKQD_BinLianStep = 0;
- KKQD_BL_VAVLE = 0;
- SetAlarmCode(KKQD_ALARM_ADDR,0);
-
- }
- if((KKQD_ANQUANMEN_LIMIT_IN_UP || KKQD_ANQUANMEN_LIMIT_IN) && bRunning)
- {
-
- KKQD_StopStep=1;
- cSTOPONE=1;
- }
- if(STOP_IN_UP)
- {
- if(bRunning)
- {
- KK_cShuangDao=0;
- KK_cDiErLaChu=0;
- KKQD_AutoDelay = dwTickCount;
- KKQD_MotorDelay = dwTickCount;
- KKQD_XiaQieDelay = dwTickCount;
- KKQD_KaDaiDelay = dwTickCount;
- KKQD_CSDelay = dwTickCount;
- KKQD_TBDelay = dwTickCount;
- KKQD_TFKDelay = dwTickCount;
- KKQD_TLDelay = dwTickCount;
- dwTickCount = KKQD_TBDelay;
- KKQD_CHUIQIStep=0;
- SingOneFlg = 0;
- KKQD_JD_VAVLE = 0;
- KKQD_SM_VAVLE = 0;
- KKQD_XM_VAVLE = 0;
- KKQD_YD_VAVLE = 0;
- KKQD_TFK_VAVLE= 0;
- KKQD_YX_VAVLE = 0;
- KKQD_HL_VAVLE = 0;
- cStopMode=0;
- cZhouWanone=0;
- KKQD_TL_VAVLE = 0;
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- KKQD_CS_OUT = 0;
- KKQD_XiaQieStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- // KKQD_SZ_OUT = 1;
- KKQD_GZ_VAVLE = 0;
- KKQD_TABLE_VAVLE = 0;
- if((KKQD_StopStep == 0) && X_DRV)
- KKQD_StopStep = 1;
- KK_cTABLETIME = 0;
- KK_cTABLETOTAL= 0;
- KKQD_BinLianStep = 0;
- KKQD_BL_VAVLE = 0;
- SetAlarmCode(KKQD_ALARM_ADDR,0);
- bRunning = 0;
- KKQD_XiaQieStep = 0;
- KKQD_AutoStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- }
- else
- {
- KK_cShuangDao=0;
- KK_cDiErLaChu=0;
- KKQD_AutoDelay = dwTickCount;
- KKQD_MotorDelay = dwTickCount;
- KKQD_XiaQieDelay = dwTickCount;
- KKQD_KaDaiDelay = dwTickCount;
- KKQD_CSDelay = dwTickCount;
- KKQD_TBDelay = dwTickCount;
- KKQD_TFKDelay = dwTickCount;
- KKQD_TLDelay = dwTickCount;
- dwTickCount = KKQD_TBDelay;
- KKQD_CHUIQIStep=0;
- SingOneFlg = 0;
- KKQD_JD_VAVLE = 0;
- KKQD_SM_VAVLE = 0;
- KKQD_XM_VAVLE = 0;
- KKQD_YD_VAVLE = 0;
- KKQD_TFK_VAVLE= 0;
- KKQD_YX_VAVLE = 0;
- KKQD_HL_VAVLE = 0;
- cStopMode=0;
- cZhouWanone=0;
- KKQD_TL_VAVLE = 0;
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- KKQD_CS_OUT = 0;
- KKQD_XiaQieStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- KKQD_SZ_OUT = 1;
- KKQD_GZ_VAVLE = 0;
- KKQD_TABLE_VAVLE = 0;
- if((KKQD_StopStep == 0))
- {
- KK_cSTOPONE = 0;
- AxisEgmStop(X_AXIS);
- KKQD_SZ_OUT = 1;
- }
- KK_cTABLETIME = 0;
- KK_cTABLETOTAL= 0;
- KKQD_BinLianStep = 0;
- KKQD_BL_VAVLE = 0;
- SetAlarmCode(KKQD_ALARM_ADDR,0);
- bRunning = 0;
- KKQD_XiaQieStep = 0;
- KKQD_AutoStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
-
- }
- }
- //停止
- if( bStop)
- {
- bStop = 0;
- if(cStopMode < 2)
- cStopMode++;
- if(cStopMode==1 && bRunning)
- cZhouWanone=1;
- if(bRunning && cStopMode==2)
- {
-
- KK_cShuangDao=0;
- KK_cDiErLaChu=0;
- KKQD_AutoDelay = dwTickCount;
- KKQD_MotorDelay = dwTickCount;
- KKQD_XiaQieDelay = dwTickCount;
- KKQD_KaDaiDelay = dwTickCount;
- KKQD_CSDelay = dwTickCount;
- KKQD_TBDelay = dwTickCount;
- KKQD_TFKDelay = dwTickCount;
- KKQD_TLDelay = dwTickCount;
- dwTickCount = KKQD_TBDelay;
- SingOneFlg = 0;
- bRunning = 0;
- KKQD_XiaQieStep = 0;
- KKQD_AutoStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- KKQD_JD_VAVLE = 0;
- KKQD_SM_VAVLE = 0;
- KKQD_XM_VAVLE = 0;
- KKQD_YD_VAVLE = 0;
- KKQD_TFK_VAVLE= 0;
- KKQD_TL_VAVLE = 0;
- KKQD_HL_VAVLE = 0;
- KKQD_CS_OUT = 0;
- KKQD_XiaQieStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- //KKQD_SZ_OUT = 1;
- KKQD_GZ_VAVLE = 0;
- KKQD_TABLE_VAVLE = 0;
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- if((KKQD_StopStep == 0) && X_DRV)
- KKQD_StopStep = 1;
- KKQD_BinLianStep = 0;
- KKQD_BL_VAVLE = 0;
- KK_cTABLETIME = 0;
- KK_cTABLETOTAL= 0;
- user_datas[121] = 0;
- user_datas[122] = 0;
-
- SetAlarmCode(KKQD_ALARM_ADDR,0);
- }
- else if(!bRunning)
- {
- KK_cShuangDao=0;
- KK_cDiErLaChu=0;
- KKQD_AutoDelay = dwTickCount;
- KKQD_MotorDelay = dwTickCount;
- KKQD_XiaQieDelay = dwTickCount;
- KKQD_KaDaiDelay = dwTickCount;
- KKQD_CSDelay = dwTickCount;
- KKQD_TBDelay = dwTickCount;
- KKQD_TFKDelay = dwTickCount;
- KKQD_TLDelay = dwTickCount;
- dwTickCount = KKQD_TBDelay;
- KKQD_CHUIQIStep=0;
- SingOneFlg = 0;
- KKQD_JD_VAVLE = 0;
- KKQD_SM_VAVLE = 0;
- KKQD_XM_VAVLE = 0;
- KKQD_YD_VAVLE = 0;
- KKQD_TFK_VAVLE= 0;
- KKQD_YX_VAVLE = 0;
- KKQD_HL_VAVLE = 0;
- cStopMode=0;
- cZhouWanone=0;
- KKQD_TL_VAVLE = 0;
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- KKQD_CS_OUT = 0;
- KKQD_XiaQieStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- KKQD_SZ_OUT = 1;
- KKQD_GZ_VAVLE = 0;
- KKQD_TABLE_VAVLE = 0;
- if((KKQD_StopStep == 0))
- {
- KK_cSTOPONE = 0;
- AxisEgmStop(X_AXIS);
- KKQD_SZ_OUT = 1;
- }
- KK_cTABLETIME = 0;
- KK_cTABLETOTAL= 0;
- KKQD_BinLianStep = 0;
- KKQD_BL_VAVLE = 0;
- SetAlarmCode(KKQD_ALARM_ADDR,0);
- bRunning = 0;
- KKQD_XiaQieStep = 0;
- KKQD_AutoStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- }
-
- }
-
- if(bAlarmStop)
- {
- bAlarmStop = 0;
- KKQD_XiaQieStep = 0;
- KKQD_AutoStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
-
- KKQD_XiaQieStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- KKQD_AutoDelay = dwTickCount;
- KKQD_MotorDelay = dwTickCount;
- KKQD_XiaQieDelay = dwTickCount;
- KKQD_KaDaiDelay = dwTickCount;
- KKQD_CSDelay = dwTickCount;
- KKQD_TBDelay = dwTickCount;
- KKQD_TFKDelay = dwTickCount;
- KKQD_TLDelay = dwTickCount;
- SingOneFlg = 0;
- bRunning = 0;
- // KKQD_StopStep=1;
- cStopMode=0;
- cZhouWanone=0;
- dwTickCount = KKQD_TBDelay;
- KKQD_TABLE_VAVLE = 0;
- KKQD_TFK_VAVLE =0;
- KKQD_JD_VAVLE=0;
- KKQD_GZ_VAVLE=0;
- }
-
- }
- //记忆长度模式误差检测
- void KK_QueDuan_CheckLength(long zip_length)
- {
- static long start_dist;
- switch(KKQD_CheckLengthStep)
- {
- case 0:break;
- case 1:
- start_dist = KK_cRealPos;
- dwSaveLength = 0;
- KKQD_CheckLengthStep = 2;
- break;
- case 2:
- if(KKQD_GUO_LIAN_IN_DW)
- {
- dwSaveLength = KK_cRealPos - start_dist;
- // user_datas[127] = KK_cRealPos;
-
- }
- break;
- }
- }
- void KK_QueDuan_Motor(void)
- {
- static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
- unsigned short ch;
- user_datas[121]= KKQD_MotorStep;
- user_datas[122]= length_buff;
- user_datas[123] = KK_cRealPos;
- user_datas[124] = dwSaveLength;//QD_BinLianStep;
- user_datas[125] = KKQD_CheckLengthStep;//QD_AutoStep;
-
- user_datas[126] = KKQD_XiaQieStep;
- // user_datas[127] = KKQD_XiaQieStep;
- KK_QueDuan_CheckLength(length_buff);
- if(!KK_cDLJ_ATUO)
- {
- switch(KKQD_MotorStep)
- {
- case 30:
- switch(KKQD_PARAM_BACK_MODE) //开口分四种模式
- {
- case 0: //单数控模式
- KKQD_MotorStep = 310; //每种模式留20步
-
- break;
- case 1://单感应模式
- KKQD_MotorStep = 330; //每种模式留20步
-
- break;
- case 2: //先感应后数控模式+检测
- KKQD_MotorStep = 350; //每种模式留20步
- break;
- default: //数控模式+过链检测长度
- KKQD_MotorStep = 370; //每种模式留20步
- break;
- }
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_DELAY_BACK;
- break;
- //310步到315步为数控模式
- case 310:
- SetDir(X_AXIS, KKQD_DIR_P);
- if(KKQD_PARAM_BL_ENABLE)
- KKQD_BinLianStep = 1; //并链起动
- KKQD_MotorStep = 311;
- break;
- case 311:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KK_length_buffer = &KKQD_PARAM_OFFSET_LENGTH;
- SetPos(X_AXIS, 0);
-
- //李永庆代码
-
- //两段速度移动距离 拉链长度+慢速长度停止
- // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
- KK_DCC_TIME_BL=KKQD_PARAM_BACK_SPEED/400;
- AxisMovePosAccDecNotStop(X_AXIS,KKQD_PARAM_BACK_SPEED,KKQD_PARAM_ZIPPER_LENGTH + (*KK_length_buffer), KKQD_PARAM_START_SPEED,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_ACC,KK_DCC_TIME_BL,KKQD_PARAM_BACK_LOW_SPEED_LENGTH);
- gou_zhen_buff = KK_cRealPos;
- save_buff = KK_cRealPos;
- KKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
- KKQD_MotorStep = 312;
- }
- break;
- case 312:
-
- //勾针提前输出 ,争取时间推方块
- if(KK_cRealPos>300)
- KKQD_DGLG_VAVLE = 1; //顶过链杆关
- if (!KKQD_GZ_VAVLE && (KK_cRealPos >= (KKQD_PARAM_ZIPPER_LENGTH- 230)))
- KKQD_GZ_VAVLE = 1;
-
- if((KK_cRealPos) > (KKQD_PARAM_ZIPPER_LENGTH + (*KK_length_buffer)-KKQD_PARAM_BACK_LOW_SPEED_LENGTH)) //- (*KK_length_buffer) - (KKQD_PARAM_BACK_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(KKQD_PARAM_BACK_SPEED,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_DCC)))))
- {
- KKQD_MotorStep = 313;
-
- }
- else if(KK_cRealPos >= (KKQD_PARAM_ZIPPER_LENGTH + (*KK_length_buffer) + KKQD_PARAM_ERROR_LENGTH))
- {
- KKQD_SetAlarmCode(KKQD_GZ_ALARM);
- }
-
- break;
- case 313:
-
- if (!KKQD_GZ_VAVLE && (KK_cRealPos >= (KKQD_PARAM_ZIPPER_LENGTH- 230)))
- KKQD_GZ_VAVLE = 1;
- if(!X_DRV || KK_cRealPos>=(KKQD_PARAM_ZIPPER_LENGTH + (*KK_length_buffer)))
- {
- AxisEgmStop(X_AXIS);
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
- KKQD_MotorStep = 314;
- KKQD_BL_VAVLE = 0; //停止时并链一定要打开
-
- if(KKQD_PARAM_BACK_MODE == 2) //模式2,先检测长度后数控
- {//对比长度 ,发须要有过链信号,模式2,3. 模式0,1不用在这里经
- if(cZipCnt > 1) //长度检测
- {
- if(KKQD_PARAM_ERROR_LENGTH != 0) //长度误差值不能为0
- {
- if(((dwSaveLength + KKQD_PARAM_MOTOR_DELAY_LENGTH) > (length_buff + KKQD_PARAM_ERROR_LENGTH)) || (dwSaveLength == 0))
- {
- KKQD_SetAlarmCode(KKQD_LENGTH_LONG_ALARM);//拉链变长,对比警告
- }
- else if((dwSaveLength + KKQD_PARAM_MOTOR_DELAY_LENGTH+ KKQD_PARAM_ERROR_LENGTH) < length_buff)
- {
- KKQD_SetAlarmCode(KKQD_LENGTH_SHORT_ALARM); ////拉链变短
- }
-
- KKQD_CheckLengthStep = 0;
- }
- }
- }
-
- }
- break;
- case 314:
- if(!X_DRV && (dwTickCount >= KKQD_MotorDelay)) //数控到停止
- {
- KKQD_MotorStep = 0;
- KKQD_TFK_VAVLE = 1; //推方块输出
- }
- break;
- //330步到349步单感应模式
- case 330:
-
- back_buff = KK_cRealPos;
- gou_zhen_buff = KK_cRealPos;
- SetDir(X_AXIS, KKQD_DIR_P);
- KKQD_MotorStep = 331;
- user_datas[127] = 0;
- break;
- case 331:
-
- if(dwTickCount >= KKQD_MotorDelay)
- {
-
- if(cZipCnt < 2)
- {
- if(KKQD_PARAM_BL_ENABLE)
- KKQD_BinLianStep = 10; //并链起动
- //第一条都是过链感应,后拉速度减半//原来KKQD_PARAM_CHECK_BACK_HSPEED/2
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,9000,KKQD_DIR_P,KKQD_PARAM_START_SPEED,2000,8,13);
-
- // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
- // AxisMoveTwoPos(X_AXIS,KKQD_PARAM_BACK_SPEED,KKQD_PARAM_ZIPPER_LENGTH + (*KK_length_buffer)-KKQD_PARAM_BACK_LOW_SPEED_LENGTH,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED_LENGTH,KKQD_DIR_P);
-
- }
- else
- {
- if(KKQD_PARAM_BL_ENABLE)
- KKQD_BinLianStep = 1; //并链起动
- //因为每条都是过链感应,所以直接运行检测模式后拉速度
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_CHECK_BACK_HSPEED,KKQD_DIR_P,KKQD_PARAM_START_SPEED,2000,KKQD_PARAM_ACC,KKQD_PARAM_DCC);
-
- }
- KKQD_MotorStep = 332;
- }
- break;
- case 332:
-
- if(KK_cRealPos>300)
- {
- if(cZipCnt > 1) //第二条开始数控降速
- {
- if((KK_cRealPos + KKQD_PARAM_BACK_LOW_SPEED_LENGTH + 600)>= length_buff)
- {
- AxisContinueMoveChangeSpeed(X_AXIS,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED/2,25,15);
-
- user_datas[127] = KK_cRealPos;
- KKQD_MotorStep = 334; //到检测定位
- }
- if(KKQD_GUO_LIAN_IN_DW) //重新到链上
- {
- AxisContinueMoveChangeSpeed(X_AXIS,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED/2,25,15);
-
- gou_zhen_buff = KK_cRealPos;
- KKQD_MotorStep = 335; //到检测定位
- }
- //
- // if((KK_cRealPos >= (KKQD_PARAM_BACK_LOW_SPEED_LENGTH + 60)) && KKQD_GUO_LIAN_IN)
- // {
-
- // }
- }
- else //第一条工作
- {
- if(KKQD_GUO_LIAN_IN_UP)
- {
- checkdelay_buff = KK_cRealPos;
- AxisContinueMoveChangeSpeed(X_AXIS,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED/2,25,15);
-
- KKQD_MotorDelay = dwTickCount + 0;//KKQD_PARAM_DELAY_XM;
- KKQD_MotorStep = 333;
- }
- else if((KK_cRealPos >= KKQD_PARAM_RUN_LENGTH) && (KKQD_PARAM_RUN_LENGTH >= 5000)) //模组最长限制
- {
- // KKQD_SetAlarmCode(KKQD_PARAM_RUN_LENGTH_ALARM); //超出轨道运行长度
- }
- }
- }
- break;
- case 333:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KKQD_MotorStep = 334;
- }
- break;
- case 334:
-
-
- if(KKQD_GUO_LIAN_IN_DW) //下降沿,定位长度
- {
- //滤波有待调试
- // if((((KK_cRealPos - checkdelay_buff) >= KKQD_PARAM_DELAY_CHECK) && (KKQD_PARAM_LT_ENABLE)) || (((KK_cRealPos - checkdelay_buff) >= KKQD_PARAM_NO_LT_DELAY_CHECK) && (KKQD_PARAM_LT_ENABLE == 0)))
- // {
- if(KKQD_GUO_LIAN_IN_DW)
- {
- gou_zhen_buff = KK_cRealPos;
- KKQD_MotorStep = 335;
- }
- // }
- }
- break;
- case 335:
-
- if(KKQD_GUO_LIAN_IN_DW)
- {
- gou_zhen_buff = KK_cRealPos;
-
- }
- //在空们都把延时清零
- if(KKQD_GUO_LIAN_IN)
- {
- gou_zhen_buff = KK_cRealPos;
- }
- //定位停止
- if(((KK_cRealPos - gou_zhen_buff) >= KKQD_PARAM_MOTOR_DELAY_LENGTH) && !KKQD_GUO_LIAN_IN)
- {
- AxisEgmStop(X_AXIS);
- KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- KKQD_MotorStep = 336;
- KKQD_GZ_VAVLE = 1;
- }
- break;
- case 336:
-
-
- if(!X_DRV)
- {
- KKQD_GZ_VAVLE = 1;
-
- KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- // KKQD_XM_VAVLE = 1;
- KKQD_MotorStep = 337;
- }
- break;
- case 337:
- if(1)
- {
-
- KKQD_MotorStep = 338;
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
- }
- // else if(dwTickCount >= KKQD_MotorDelay) KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
- break;
- case 338:
- if((dwTickCount >= KKQD_MotorDelay))
- {
- KKQD_TFK_VAVLE = 1; //推方块输出
- KKQD_MotorStep = 339;
- KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- }
- break;
- case 339:
- if(cZipCnt == 1)
- {
- length_buff = KK_cRealPos - save_buff;
- SetData32bits(KKQD_PARAM_ZIPPER_LENGTH_ADDR,length_buff);
- }
- else if(cZipCnt > 1) //长度检测
- {
- if(KKQD_PARAM_ERROR_LENGTH != 0) //长度误差值不能为0
- {
- if(KK_cRealPos >= length_buff) //拉链变长,对比警告
- {
- if((KK_cRealPos - save_buff) > (length_buff+KKQD_PARAM_ERROR_LENGTH))
- KKQD_SetAlarmCode(KKQD_LENGTH_LONG_ALARM);
- }
- else //拉链变短
- {
- if((KK_cRealPos - save_buff + KKQD_PARAM_ERROR_LENGTH) < (length_buff))
- KKQD_SetAlarmCode(KKQD_LENGTH_SHORT_ALARM);
- }
- }
- }
- KKQD_MotorStep = 0;
- break;
- //350步到369步单感应模式
- case 350:
- back_buff = KK_cRealPos;
- gou_zhen_buff = KK_cRealPos;
- SetDir(X_AXIS, KKQD_DIR_P);
-
- KKQD_MotorStep = 351;
-
-
-
- break;
- case 351:
- if(dwTickCount >= KKQD_MotorDelay)
- {
-
- //第一,二条都是过链感应,测量长度
- if(cZipCnt < 2)
- {
- if(KKQD_PARAM_BL_ENABLE) //因为长度未知,只能通过过链退合链
- KKQD_BinLianStep = 10; //并链起动
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,9000,KKQD_DIR_P,KKQD_PARAM_START_SPEED,2000,8,12);
- KKQD_MotorStep = 352;
- }
- else
- {
- if(KKQD_PARAM_BL_ENABLE)
- KKQD_BinLianStep = 1; //并链起动
- KKQD_DGLG_VAVLE = 1; //顶过链杆关
- KKQD_CheckLengthStep = 1; //长度检测,第3条才有对比
- //走数控方式,因第二条中已经测量出来拉链长度,可以直接按长度数控方式走
- KKQD_MotorStep = 311;
- }
-
-
- }
- break;
- case 352:
-
- if(KK_cRealPos>300)
- {
- //前两条都按最低速度工作
- if(KKQD_GUO_LIAN_IN_UP)
- {
- checkdelay_buff = KK_cRealPos;
- AxisContinueMoveChangeSpeed(X_AXIS,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED/2,25,15);
-
- KKQD_MotorDelay = dwTickCount + 2;//因慢速,加8MS滤波
- KKQD_MotorStep = 353;
- }
- else if((KK_cRealPos >= KKQD_PARAM_RUN_LENGTH) && (KKQD_PARAM_RUN_LENGTH >= 5000)) //模组最长限制
- {
- // KKQD_SetAlarmCode(KKQD_PARAM_RUN_LENGTH_ALARM); //超出轨道运行长度
- }
- }
-
- break;
- case 353:
-
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KKQD_MotorStep = 354;
- }
- break;
- case 354:
-
- if(KKQD_GUO_LIAN_IN_DW) //下降沿,定位长度
- {
-
- if(KKQD_GUO_LIAN_IN_DW)
- {
- gou_zhen_buff = KK_cRealPos;
- KKQD_MotorStep = 355;
- }
-
- }
- break;
- case 355:
-
- if(KKQD_GUO_LIAN_IN_DW)
- {
- gou_zhen_buff = KK_cRealPos;
-
- }
- //在空们都把延时清零
- if(KKQD_GUO_LIAN_IN)
- {
- gou_zhen_buff = KK_cRealPos;
- }
- //定位停止
- if(((KK_cRealPos - gou_zhen_buff) >= KKQD_PARAM_MOTOR_DELAY_LENGTH) && !KKQD_GUO_LIAN_IN)
- {
- AxisEgmStop(X_AXIS);
- KKQD_MotorStep = 356;
- KKQD_GZ_VAVLE = 1;
- }
- break;
- case 356:
-
- if(!X_DRV)
- {
- KKQD_GZ_VAVLE = 1;
-
- KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- // KKQD_XM_VAVLE = 1;
- KKQD_MotorStep = 357;
- }
- break;
- case 357:
- if(1)
- {
-
- KKQD_MotorStep = 358;
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
- }
- break;
- case 358:
- if((dwTickCount >= KKQD_MotorDelay))
- {
- KKQD_TFK_VAVLE = 1; //推方块输出
- KKQD_MotorStep = 359;
- KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- }
- break;
- case 359:
- if(cZipCnt == 1)
- {
- length_buff = KK_cRealPos - save_buff;
- //测量出来长度
- SetData32bits(KKQD_PARAM_ZIPPER_LENGTH_ADDR,length_buff);
- }
- KKQD_MotorStep = 0;
- break;
-
-
-
- case 40:
- //切完延时后拉带松夹子
- if(KKQD_PARAM_SJZ_LENGTH == 0 )
- {
- KKQD_JD_VAVLE = 0;
- SetDir(X_AXIS, KKQD_DIR_P);
- jz_buff = KK_cRealPos;
- AxisMovePosAccDec(X_AXIS,KKQD_PARAM_CUT_BACK_SPEED,KKQD_PARAM_BACK_LENGTH,1000,1000,100,50,0);
- // AxisMovePosAccDec(X_AXIS,KKQD_PARAM_CUT_BACK_SPEED,KKQD_PARAM_SJZ_LENGTH + KKQD_PARAM_BACK_LENGTH,2000,2000,25,25,40);
- KKQD_MotorStep = 44;
-
- }
- else
- {
- jz_buff = KK_cRealPos;
- SetDir(X_AXIS, KKQD_DIR_P);
- KKQD_MotorStep = 41;
- }
- break;
- case 41:
- AxisMovePosAccDec(X_AXIS,KKQD_PARAM_CUT_BACK_SPEED,(KKQD_PARAM_SJZ_LENGTH+KKQD_PARAM_BACK_LENGTH),1000,1000,100,50,0);
- KKQD_MotorStep = 42;
- break;
-
- case 42:
- if((KKQD_PARAM_SJZ_LENGTH <= (KK_cRealPos - jz_buff)))
- {
- KKQD_JD_VAVLE = 0;
- KKQD_GZ_VAVLE=0;
- KKQD_MotorStep = 44;
- }
- break;
- case 44: // 切断完成后拉电机动作
- if((KKQD_PARAM_SJZ_LENGTH+KKQD_PARAM_BACK_LENGTH) <= (KK_cRealPos - jz_buff) || !X_DRV)
- {
- AxisEgmStop(X_AXIS);
- KKQD_MotorStep = 0;
- KKQD_GZ_VAVLE=0;
- KKQD_MotorDelay = dwTickCount;
- }
- break;
- case 61: // 前点定位数控模式
- if(KKQD_SZ_OUT)
- {
- KKQD_SZ_OUT = 0;
- KKQD_MotorDelay = dwTickCount + 150;
- SetDir(X_AXIS, KKQD_DIR_N);
- SetPos(X_AXIS, 0);
- }
- else
- KKQD_MotorDelay = dwTickCount;
-
- KKQD_BL_VAVLE = 0;//并链也要打开
- // KKQD_JZ_DIR = KKQD_YDIR_N;
- if(KKQD_TuiLianStep==0)
- {
- if(!KKQD_TL_VAVLE && cZipCnt) //没送链情况下主动送链
- {
- if(!KKQD_SHANG_MU_LIMIT_IN && (KKQD_TuiLianStep == 0))
- {
- KKQD_TuiLianStep = 1;
- KKQD_MotorStep = 62;
- }
- }
- else
- KKQD_MotorStep = 62;
-
- }
- else
- KKQD_MotorStep = 62;
- break;
- case 62:
-
- if(dwTickCount >= KKQD_MotorDelay)
- {
- if(KKQD_QIAN_LIMIT_IN)
- {
- SetPos(X_AXIS, 0);//在前点,直接置零点
- // KKQD_JZ_DIR = KKQD_YDIR_P;
- //前点亮的情况下先退出
- AxisMovePos(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,1000);
- KKQD_MotorDelay = dwTickCount + 300;
- }
- KKQD_MotorStep = 63;
- KKQD_JD_VAVLE = 0;
- }
- break;
- case 63:
-
- if(!X_DRV && !KKQD_QIAN_LIMIT_IN && (dwTickCount >= KKQD_MotorDelay))// && !KKQD_SHANG_MU_LIMIT_IN)
- {
-
- // KKQD_JZ_DIR = KKQD_YDIR_N;
- SetDir(X_AXIS, KKQD_DIR_N);
- go_buff = KK_cRealPos;
- KKQD_YD_VAVLE = 1;
- KKQD_HL_VAVLE = 1;
- KKQD_YX_VAVLE = 1;
- //李永庆代码,当位置在慢速之外,走数控到慢速点
- if(cZipCnt > 0)
- {
-
- if(KK_cRealPos>(KKQD_PARAM_GO_LOW_SPEED_LENGTH))
- {
- KK_DCC_TIME_BL=KKQD_PARAM_GO_HIGH_SPEED/400;
- AxisMovePosAccDecNotStop(X_AXIS,KKQD_PARAM_GO_HIGH_SPEED,-KK_cRealPos,
- KKQD_PARAM_START_SPEED,KKQD_PARAM_GO_LOW_SPEED,KKQD_PARAM_ACC,KK_DCC_TIME_BL,
- KKQD_PARAM_GO_LOW_SPEED_LENGTH);
- }
- else
- {
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED/3,1000,15,15);
-
- }
-
- }
- else
- {
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED/3,1000,15,15);
- }
-
- KKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
- KKQD_MotorStep =64;
- }
-
- break;
- case 64:
-
- if(cZipCnt > 1)
- {
- //李永庆代码
- if(((KK_cRealPos) < (KKQD_PARAM_GO_LOW_SPEED_LENGTH+1200)))// || (KKQD_QIAN_DEC_IN))
- {
- user_datas[126]= GetCurSpeed(X_AXIS);
- // MoveChangSpeedDec(X_AXIS,KKQD_PARAM_GO_HIGH_SPEED*2/3,6,8);
- // AxisChangeSpeed(X_AXIS,40);
- KKQD_MotorStep =65;
- }
- if(KKQD_QIAN_LIMIT_IN) //前点限位
- {
-
- AxisEgmStop(X_AXIS);
- KKQD_MotorStep = 66;
- }
- }
- else
- {
- if(KKQD_QIAN_LIMIT_IN) //前点限位
- {
- AxisEgmStop(X_AXIS);
- KKQD_MotorStep = 66;
- }
- }
-
- break;
- case 65:
-
- if(KKQD_QIAN_LIMIT_IN)
- {
- KKQD_TFK_VAVLE = 0;
- AxisEgmStop(X_AXIS);
- KKQD_MotorStep = 66;
- }
- else if(dwTickCount >= KKQD_MotorDelay)
- KKQD_SetAlarmCode(KKQD_NO_ZIPPER_ALARM);
-
- break;
- case 66:
-
- if(!X_DRV)
- {
- KKQD_TFK_VAVLE=0;
- SetPos(X_AXIS, 0);
- KKQD_MotorDelay = dwTickCount;
- KKQD_MotorStep = 67;
- }
- break;
- case 67: //等推链完成后,
- if((dwTickCount >= KKQD_MotorDelay) && (KKQD_TuiLianStep == 0) && ((KKQD_PARAM_TIAOSHI_MODE && KKQD_bTS) || (KKQD_PARAM_TIAOSHI_MODE == 0)) )
- {
- if(bRunning)
- {
- KKQD_JD_VAVLE = 1;
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_DELAY_BACK;
- }
- KKQD_MotorStep = 68;
- }
- break;
- case 68:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KKQD_YD_VAVLE = 0;
- KKQD_HL_VAVLE = 0;
- KKQD_YX_VAVLE = 0;
-
- KKQD_TL_VAVLE = 0;
- KKQD_MotorStep = 0;
- KKQD_MotorDelay = dwTickCount;
- }
- break;
-
- }
- }
- }
- void KK_QueDuan_BingLian(void)
- {
- static long bl_pos_buff,HL_delay;
-
- switch(KKQD_BinLianStep)
- {
- case 1:
- bl_pos_buff = KK_cRealPos;
-
- KKQD_BinLianStep = 2;
- break;
- case 2:
- if((KK_cRealPos - bl_pos_buff) >= KKQD_PARAM_DELAY_HL_LENGTH)
- {
- KKQD_BL_VAVLE = 1;
- KKQD_BinLianStep = 3;
- }
- break;
- case 3://有过链检测
- if((KK_cRealPos - bl_pos_buff) >= (KKQD_PARAM_ZIPPER_LENGTH - KKQD_PARAM_HL_DELAY_BACK))
- {
- KKQD_BL_VAVLE = 0;
- KKQD_BinLianStep = 0;
- }
- if(KKQD_GUO_LIAN_IN_DW && KKQD_PARAM_BACK_MODE ==1) //|| (KKQD_PARAM_BACK_MODE==2 && cZipCnt < 2)))
- {
- KKQD_BL_VAVLE = 0;
- KKQD_BinLianStep = 0;
- }
- break;
- case 10:
- bl_pos_buff = KK_cRealPos;
- KKQD_BinLianStep = 11;
- break;
- case 11:
- if((KK_cRealPos - bl_pos_buff) >= KKQD_PARAM_DELAY_HL_LENGTH)
- {
- KKQD_BL_VAVLE = 1;
- KKQD_BinLianStep = 12;
- }
- break;
- case 12://有过链检测
- if(KKQD_GUO_LIAN_IN_DW)
- {
- KKQD_BL_VAVLE = 0;
- KKQD_BinLianStep = 0;
- }
- break;
- default:;
- }
-
- }
- //超声方式下切,开口专用
- void KK_QueDuan_XiaQue_KK(void)
- {
- switch(KKQD_XiaQieStep)
- {
- case 0:
- break;
- case 1:
-
- KKQD_XiaQieStep = 2;
- break;
- case 2:
- KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
- KKQD_XiaQieStep = 3;
- break;
- case 3:
- if(1)
- {
- KKQD_XiaQieDelay = dwTickCount + 0;//KKQD_PARAM_GZ_DELAY;
- KKQD_XiaQieStep = 4;
- }
- else if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
- }
- break;
- case 4:
- if(KKQD_GZ_VAVLE) //勾针已经有输出就不需要延时
- {
- KKQD_XiaQieDelay = dwTickCount + 0;
- }
- else
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
- KKQD_GZ_VAVLE = 1;
- cTuiFangKuaiCnt=0;
- KKQD_XiaQieStep = 5;
-
- break;
- case 5:
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_TFK_VAVLE = 1;
- KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
- KKQD_XiaQieStep = 6;
- }
- break;
- case 6:
- if(1)
- {
- KKQD_XiaQieStep = 7;
- KKQD_XiaQieDelay = dwTickCount + 1000;
- }
- else if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
- }
- break;
- case 7:
-
- if(KKQD_GOUZHEN_IN)
- {
-
- cTuiFangKuaiCnt = 0;
- KKQD_YD_VAVLE = 1;
- if(!bRunning)
- KKQD_XiaQieDelay = dwTickCount + 200;
- else
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_CUT_DELAY;
-
- if(!KKQD_QIAN_LIMIT_IN)
- KKQD_XiaQieStep = 8;
- else
- KKQD_SetAlarmCode(KKQD_QIAN_LIMIT_ALARM);
- }
- else if((dwTickCount >= KKQD_XiaQieDelay))
- {
- if(cTuiFangKuaiCnt < KKQD_PARAM_TFK_NUMBER)
- {
- KKQD_TFK_VAVLE = 0;
- cTuiFangKuaiCnt++;
- KKQD_XiaQieDelay = dwTickCount + 500;
- KKQD_XiaQieStep = 100;
- }
- else
-
- KKQD_SetAlarmCode(KKQD_GZ_ALARM);
- }
- break;
- case 100:
- if((dwTickCount >= KKQD_XiaQieDelay))
- {
- KKQD_XiaQieStep = 5;
- }
- break;
- case 8://上下模同时输出
- if(KKQD_GOUZHEN_IN)
- {
- if(KKQD_SHANG_MU_ORIGIN_IN)
- {
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_SM_VAVLE = 1;
- if(KKQD_PARAM_XM_ENABLE == 0) //配置下模动
- KKQD_XM_VAVLE = 1;
- KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
- KKQD_XiaQieStep = 9;
- }
- }
- else if(dwTickCount >= (KKQD_XiaQieDelay+3000))
- {
- KKQD_SetAlarmCode(KKQD_SM_YUANWEI);
- }
- }
- else
- {
- KKQD_SetAlarmCode(KKQD_GZ_ALARM);
- }
- break;
- case 9://上下模到位,调试模下的话,等按下一步按键 下模不动
- if(KKQD_SHANG_MU_LIMIT_IN && (KKQD_XIA_MU_LIMIT_IN || KKQD_PARAM_XM_ENABLE) && ((KKQD_PARAM_TIAOSHI_MODE && KKQD_bTS) || (KKQD_PARAM_TIAOSHI_MODE == 0)) )
- {
- if(!KKQD_PARAM_CS_MODE) //无超声配置
- {
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_DELAYBACK_SM; //
- KKQD_XiaQieStep = 12;
- }
- else
- {
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_DELAY_CS; //
- KKQD_XiaQieStep = 10;
- }
- }
- else if(dwTickCount >= KKQD_XiaQieDelay)
- {
- if(!KKQD_SHANG_MU_LIMIT_IN)KKQD_SetAlarmCode(KKQD_SM_DAOWEI);
- else KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
- }
- break;
- case 10:
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
-
- KKQD_CS_OUT = 1;
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_CS_TIME; //
- KKQD_XiaQieStep = 11;
- }
- break;
- case 11:
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_CS_OUT = 0;
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_CS_COLD_TIME; //
- KKQD_XiaQieStep = 12;
- }
- break;
- case 12:
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_SM_VAVLE = 0;
- if(KKQD_PARAM_XM_ENABLE == 0) //配置下模动
- KKQD_XM_VAVLE = 0;
-
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- KKQD_TFK_VAVLE = 0;
- // KKQD_GZ_VAVLE = 0
- KKQD_XiaQieStep = 13;
- }//
- break;
- case 13:
- KKQD_GZ_VAVLE = 0;
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_TTFK_TIME;
- KKQD_XiaQieStep = 14;
- break;
- case 14:
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
-
- KKQD_TFK_VAVLE = 1;
-
-
- }
- if(!KKQD_SHANG_MU_LIMIT_IN)
- {
- //启动推链(送链)
- if((KKQD_TuiLianStep == 0) && !KKQD_TL_VAVLE)
- KKQD_TuiLianStep = 1;
- }
- if(!KKQD_SHANG_MU_LIMIT_IN && (!KKQD_XIA_MU_LIMIT_IN || KKQD_PARAM_XM_ENABLE) && KKQD_TFK_VAVLE)
- {
- KKQD_XiaQieStep = 0;
- }
- else if(dwTickCount >= (KKQD_XiaQieDelay+3000))
- {
- KKQD_SetAlarmCode(KKQD_SM_YUANWEI);
- }
- break;
- }
- }
- void KK_QueDuan_TuiLianAction(void)
- {
- if(KKQD_PARAM_XM_ENABLE == 0)
- {
- KKQD_TuiLianStep = 0;
- }
- else
- {
- switch(KKQD_TuiLianStep)
- {
- case 1:
- KKQD_TuiLianStep = 2;
- break;
- case 2:
- KKQD_TLDelay = dwTickCount + KKQD_PARAM_YD_DELAY;
- KKQD_TuiLianStep = 3;
- break;
- case 3:
- if(!KKQD_SM_VAVLE && !KKQD_SHANG_MU_LIMIT_IN)//dwTickCount >= KKQD_TLDelay)
- {
- KKQD_TL_VAVLE = 1;
- // KKQD_TFK_VAVLE = 0;
- // if(!bRunning)KKQD_TFK_VAVLE = 1;
-
- KKQD_TLDelay = dwTickCount + KKQD_PARAM_TL_DELAY;
- KKQD_TuiLianStep = 4;
- }
- break;
- case 4:
- if(dwTickCount >= KKQD_TLDelay)
- {
- KKQD_TuiLianStep = 0;
-
- }
- break;
- case 10:
-
- KKQD_TuiLianStep = 11;
- break;
- case 11:
- if(!Y_DRV)
- {
- {
- KKQD_TuiLianStep = 0;
- }
- }
- break;
- }
- }
- }
- //切断动作
- void KK_QueDuan_XiaQue(void)
- {
-
- KK_QueDuan_XiaQue_KK();
-
- }
- #endif
|