12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816 |
- #include "global.h"
- #if FIE_YUE_MACHINE == 1
- void CTHL_SetAlarmCode(unsigned short alarm_code,unsigned short cStopFlag);
- void CTHL_ManualAction(void);
- void CTHL_AutoStepAction(void);
- void CTHL_TableAction(void);
- void CTHL_TD_Motor(void);
- void CTHL_CL_Motor(void);
- void CTHL_CheckStart(void);
- void CTHL_TLiao_Step(void); //推料(推拉头)
- void CTHL_AlarmProtect(void);
- void CTHL_ZLT_Step(void);
- void CTHL_ZhenDongAction(void);
- void CTHL_bFKCXTDDWStep(void);
- void CTHL_bCXCRStep(void);
- void CTHL_bCLFirstStep(void);
- void ExtiAcitionX02(void)
- {
- if(bCheckEN_FLG)
- {
- bCheckEN_FLG = 0;
- CTHL_CheckInX02PosBuff = GetPos(X_AXIS);
- }
- }
- //故障报警
- void CTHL_SetAlarmCode(unsigned short alarm_code,unsigned short cStopFlag)
- {
- SetAlarmCode(CTHL_ALARM_ADDR,alarm_code);
- // bAlarmStop = 0;
- // if(cStopFlag)
- if(!cWULATOUCnt && !cXiaoChaCNT && !cCHULIANBAOJIN)
- {
- bAlarmStop = 1;
- }
- else
- {
- cWULATOUCnt=0;
- }
-
-
-
- }
- //初始化动作
- void CTHL_InitAction(void)
- {
- float buff_pulse,buff_dist;
-
- buff_pulse = CTHL_PARAM_CYCLE_PULSE;
- buff_dist = CTHL_PARAM_CYCLE_LENGTH;
-
- XGearRatio = buff_pulse/buff_dist;
-
- buff_pulse = 2000;//CTHL_PARAM_CYCLE_PULSE;
- buff_dist = 750;//CTHL_PARAM_CYCLE_LENGTH;
- YGearRatio = buff_pulse/buff_dist;
-
-
-
- bYFirstDingWeiFlg = 1;
- user_datas[121] = 0;
- user_datas[122] = 0;
- user_datas[123] = 0;
- if(!CTHL_PARAM_MATOR_MODE)
- SetEnReverse(X_AXIS, 1);
- else
- SetEnReverse(X_AXIS, 0);
- SetEnReverse(Y_AXIS, 1);
- SetEnReverse(Z_AXIS, 1);
-
- SetDirReverse(X_AXIS, 0);
- SetDirReverse(Y_AXIS, 0);
- SetDirReverse(Z_AXIS, 0);
-
- SetEn(X_AXIS, MOTOR_DISEN);
- SetEn(Y_AXIS, MOTOR_DISEN);
- SetEn(Z_AXIS, MOTOR_DISEN);
-
- SetAlarmCode(CTHL_ALARM_ADDR,0);
- // QDCT_SZ_OUT = QDCT_MOTOR_DISEN;
- }
- void CTHL_Action(void)
- {
- user_datas[121] = CTHL_LianLengSave;
- // user_datas[122] =axis_x->cur_speed;
- // user_datas[123] = CTHL_bCXCR_Step;
- dwXRealPos = GetPos(X_AXIS);
- dwYRealPos = GetPos(Y_AXIS);
- dwZRealPos = GetPos(Z_AXIS);
- user_datas[124] = dwXRealPos;
- user_datas[125] = dwYRealPos;
-
- user_datas[126] = GetAlarm(X_AXIS);
- user_datas[127] = GetAlarm(Y_AXIS);
- user_datas[128] = CTHL_AutoStep;
-
- CTHL_ZhenDongAction();
- CTHL_AlarmProtect();
- CTHL_CheckStart();
- CTHL_ZLT_Step();
- CTHL_TLiao_Step();
-
- CTHL_TD_Motor();
- CTHL_CL_Motor();
- CTHL_bFKCXTDDWStep();
- CTHL_bCXCRStep();
- CTHL_bCLFirstStep();
- CTHL_ManualAction();
-
- CTHL_AutoStepAction();
- }
- void CTHL_AlarmProtect(void)
- {
-
-
-
- }
- //自动动作
- void CTHL_AutoStepAction(void)
- {
-
-
-
- if(bRunning)
- {
- switch(CTHL_AutoStep)
- {
- case 1:
- if(CTHL_SF_Origin_IN)
- {
- /* CTHL_AutoStep = 10; //测试拖带定位
- CTHL_AutoDelay = dwTickCount + 1000;
- break; */
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_FKJD_VAVLE = 1; //方块夹带气缸输出
- CTHL_XKTD_VAVLE = 1; //斜口推带气缸输出
- CTHL_FKGD_VAVLE = 0; //方块固定关
- // CTHL_XKDW_VAVLE = 1;
- CTHL_AutoStep = 2;
- CTHL_AutoDelay = dwTickCount + 50;
- if(CTHL_ZhuangLiaoStep == 0)
- {
- CTHL_ZhuangLiaoStep = 1;
- CTHL_TryCnt = 0;
- }
- }
- }
- break;
- case 2:
- if(!CTHL_XKTD_Origin_IN && (dwTickCount >= CTHL_AutoDelay)) //斜口推带原位离开
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 3;
- CTHL_XKDW_VAVLE = 1;
- CTHL_AutoDelay = dwTickCount + 20;
- }
- }
- break;
- case 3://斜口定位
- if(dwTickCount >= CTHL_AutoDelay)
- {
- CTHL_AutoStep = 4;
- // CTHL_AutoDelay = dwTickCount + CTHL_PARAM_XKDW_TD_DELAY;
- }
- break;
- case 4:
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- AxisMovePosAccDecNotStop(X_AXIS,1600,150,600,1000,5,3,00);
- CTHL_AutoStep = 5;
- CTHL_XSavePosBuff = dwXRealPos;
- // SetPos(X_AXIS, 0); //启动位置设为0点
- if(cZipCnt < 1)
- CTHL_AutoDelay = dwTickCount +350;
- else
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_FKJD_DELAY;
- }
- break;
- case 5:
- if(dwTickCount >= CTHL_AutoDelay)
- {
- CTHL_FKJD_VAVLE = 1; //方块夹带气缸输出
-
- }
- if(bCL_EN_FLG && (dwXRealPos >= 230) && CTHL_XKSC_Limit_IN)
- {
- CTHL_HLJJ_VAVLE = 1; //Y20 合链夹具电磁阀输出后,电机穿入
- }
-
- if(CTHL_XKSC_Limit_IN) //方块上止到位
- {
- AxisEgmStop(X_AXIS);
- // AxisMovePosAccDec(X_AXIS,1200,10,1200,1200,6,6,0);
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_QDXK_VAVLE = 1;
- CTHL_FKJD_VAVLE=0;
-
- CTHL_AutoStep = 6;
-
- CTHL_bLTCHECK_Delay = dwTickCount + 20;
- //电机穿入可以启动
- bCL_OK_FLG = 1; //不用穿合链的话认为已经完成
- if(bCL_EN_FLG)
- {
- bCL_OK_FLG = 0;
- CTHL_HLJJ_VAVLE = 1; //Y20 合链夹具电磁阀输出后,电机穿入
- CTHL_CL_MotorStep = 1;
- CTHL_CL_MotorDelay = dwTickCount + CTHL_PARAM_HLJJ_CL_DELAY;
-
- CTHL_AutoDelay = dwTickCount + 50 + CTHL_PARAM_HLJJ_CL_DELAY;
- }
- else
- {
- CTHL_XKTD_VAVLE = 0; //斜口推带气缸关闭
- CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- }
- }
- }
- else if(dwXRealPos >= (CTHL_XSavePosBuff + 1500))
- {
- CTHL_SetAlarmCode(CTHL_FKCXDW_ALARM,bRunning); //方块插销定位异常警告
-
- }
- break;
- case 6:
- if(((dwYRealPos > 1000) || (!Y_DRV && dwYRealPos)) && CTHL_XKTD_VAVLE)
- {
- CTHL_XKTD_VAVLE = 0; //斜口推带气缸关闭
- CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- }
-
- if(CTHL_XKTD_Origin_IN) //斜口推带回到原位
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- if(bZhuangLiaoOkFlg && (CTHL_ZhuangLiaoStep == 0))
- {
- if(dwTickCount >= CTHL_bLTCHECK_Delay)
- {
-
- if(!CTHL_LTou_Check)
- {
- if(CTHL_PARAM_TDFZ_LENTH && !X_DRV) //拖带电机反转
- {
- AxisMovePosAccDec(X_AXIS,8000,-CTHL_PARAM_DXKFZ_LENTH,800,600,6,6,0);
- if(!CTHL_PARAM_NLSL_MODE)
- CTHL_FKJD_VAVLE= 0; //方块夹带气缸关
-
- }
- if(CTHL_PARAM_CXMODE)
- CTHL_CXVAVLE = 1;
- CTHL_CTXM_VAVLE = 1; //穿头下模上升
- CTHL_AutoStep = 7;
- CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- }
- else
- {
- cWULATOUCnt=1;
- CTHL_SetAlarmCode(CTHL_ZLT_ALARM,bRunning); // 没有拉头
- }
- }
-
- }
- }
- }
- else if((dwTickCount >= CTHL_AutoDelay) && !CTHL_XKTD_VAVLE )
- {
- CTHL_SetAlarmCode(CTHL_XKTD_Origin_ALARM,bRunning); //斜口推带回到异常
- }
- break;
- case 7:
- if(!CTHL_CTM_Origin_IN)
- {
- CTHL_JLTou_VAVLE = 0; //接拉头
- }
- if(CTHL_CTM_Limit_IN)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- if(CTHL_PARAM_NLSL_MODE)
- {
-
- CTHL_XKTD_VAVLE=1;
- }
- CTHL_JLTou_VAVLE = 0;
- CTHL_AutoStep = 8;
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_DXKYS_DELAY;
- }
- }
- else if(dwTickCount >= CTHL_AutoDelay)
- {
- CTHL_SetAlarmCode(CTHL_CTM_Limit_ALARM,bRunning); //穿头下模上升异常
- }
- break;
-
- case 8:
- if(!X_DRV) //延时顶斜口
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- if((dwTickCount >= CTHL_AutoDelay) || (CTHL_PARAM_NLSL_MODE))
- {
- if(!CTHL_PARAM_NLSL_MODE)
- CTHL_DXK_VAVLE=1;
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_DXK_XKDW_Off_DELAY;
- CTHL_AutoStep = 9;
- }
- }
-
- }
- break;
- case 9:
- if((dwTickCount >= CTHL_AutoDelay) && (bCL_OK_FLG)) //顶斜口延时退斜口上止定位
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- // AxisMovePosAccDec(X_AXIS,2000,-150,1200,1200,3,6,0); //反转1.5CM
- CTHL_XKDW_VAVLE = 0; //斜口上止定位关
- CTHL_FKJD_VAVLE = 0; //方块夹带气缸关
- CTHL_AutoStep = 10;
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_XK_CR_DELAY;
- }
- }
- break;
- case 10:
- if((dwTickCount >= CTHL_AutoDelay) && !X_DRV)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_TD_MotorStep = 10; //启动拖带穿入
- CTHL_AutoStep = 11;
- }
-
- }
- break;
- case 11:
-
- if(CTHL_TD_MotorStep == 0) //穿入定位完成
- {
- /* //测试拖带定位
- CTHL_AutoStep = 1;
- CTHL_AutoDelay = dwTickCount + 1000;
- if(cZipCnt<3)
- cZipCnt++;
- break; */
-
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_XKDW_VAVLE = 0; //斜口上止定位关
- CTHL_XKTD_VAVLE = 1; //斜口推带气缸输出
- CTHL_CXSCDW_VAVLE = 1; //Y21 插销上止定位电磁阀
- cXcxcrCnt = 0;
- if(CTHL_CL_MotorStep == 0)
- {
- CTHL_CXQJD_VAVLE = 1;
- }
- CTHL_AutoStep = 12;
- // CTHL_AutoDelay = dwTickCount + 50;
- }
- }
- break;
- case 12:
- if((CTHL_CL_MotorStep == 0)&& (CTHL_SF_Origin_IN)) //插销前夹带回到原位
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 14;
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_XCQJD_XCDW_DELAY;
- if(cXcxcrCnt != 1)
- {
- CTHL_CXQJD_VAVLE = 1;
- }
- }
- }
- break;
- case 14:
- if(dwTickCount >= CTHL_AutoDelay)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_XKDW_VAVLE = 1; //斜口定位
- CTHL_AutoStep = 15;
- CTHL_FKGD_VAVLE = 1; //方块固定
- //Y轴启动插销
- if(cXcxcrCnt != 1)
- {
- CTHL_CL_MotorStep = 20; //插销定位
- }
- }
- }
- break;
- case 15:
- if(CTHL_CL_MotorStep == 0) //插销定位完成
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 16;
- CTHL_CXDWZ_VAVLE = 1; //插销定位针(到位)电磁阀
- CTHL_CXHJD_VAVLE = 1; //Y14 插销后夹带输出
- CTHL_AutoDelay = dwTickCount + 10; //延时插销下移
- }
- }
- break;
- case 16:
- if(dwTickCount >= CTHL_AutoDelay)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 17;
- if(CTHL_PARAM_CXMODE)
- CTHL_CXVAVLE = 0;
- else
- CTHL_CXVAVLE = 1; //Y06 插销下移电磁阀
- CTHL_CXHJD_VAVLE = 1; //Y14 插销后夹带输出
- CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME; //插销下移异常时间
- }
- }
- break;
- case 17:
- if(CTHL_PARAM_CXMODE)
- {
- if(CTHL_CXLimit_IN)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 18;
- if( cXcxcrCnt==0 && !X_DRV) //拖带电机反转
- {
- AxisMovePosAccDec(X_AXIS,8000,-CTHL_PARAM_TDFZ_LENTH,800,600,6,6,0);
- }
- CTHL_CXQJD_VAVLE = 0; //插销前夹带电磁阀
- CTHL_CXSCDW_VAVLE = 0; //Y21 插销上止定位关
- CTHL_CXHJD_VAVLE = 1; //Y14 插销后夹带输出
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_SCDWOff_CXDW_DELAY;
- }
- }
- else if(dwTickCount >= CTHL_AutoDelay)
- {
- CTHL_SetAlarmCode(CTHL_CXLimit_ALARM,bRunning); //插销下移异常
-
- }
- }
- else
- {
- CTHL_AutoStep = 18;
- if( cXcxcrCnt==0 && !X_DRV) //拖带电机反转
- {
- AxisMovePosAccDec(X_AXIS,8000,-CTHL_PARAM_TDFZ_LENTH,800,600,6,6,0);
- }
- CTHL_CXQJD_VAVLE = 0; //插销前夹带电磁阀
- CTHL_CXSCDW_VAVLE = 0; //Y21 插销上止定位关
-
- CTHL_CXHJD_VAVLE = 1; //Y14 插销后夹带输出
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_SCDWOff_CXDW_DELAY;
- }
- break;
- case 18:
- // if(START_IN_UP)
- {
- if(dwTickCount >= CTHL_AutoDelay)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 19;
- cBAOHUCNT=0;
- CTHL_CXHDW_VAVLE = 1; //插销后定位(插销穿入)
- CTHL_AutoDelay = dwTickCount + 500; //插销穿入到位异常时间
- CTHL_CL_MotorStep = 50; //合链电机回原点
- }
- }
- }
- break;
- case 19:
-
- if(CTHL_CX_Limit_IN && (cXcxcrCnt<4))
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- cXcxcrCnt=0;
- cXiaoChaCNT=0;
- user_datas[100]=0;
- bZhuangLiaoOkFlg = 0;
- CTHL_CXVAVLE=0;
- CTHL_AutoStep = 901;
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_FKGD_DELAY; //退方块固定时间
- CTHL_CXDWZ_VAVLE = 0; //插销定位针(到位)电磁阀
- }
-
- }
- else if ((dwTickCount >= CTHL_AutoDelay) && (cXcxcrCnt<3) )
- {
- cXcxcrCnt++;
- CTHL_CXHJD_VAVLE=0;
- CTHL_CXHDW_VAVLE=0;
- if(!CTHL_PARAM_CXMODE)
- CTHL_CXVAVLE=0;
- else
- CTHL_CXVAVLE=1;
- if(cXcxcrCnt<3)
- {
- CTHL_CXSCDW_VAVLE=1;
- CTHL_AutoStep = 12;
- CTHL_AutoDelay = dwTickCount + 120;
- }
- }
- else if((dwTickCount >= (CTHL_AutoDelay +3000)) && !CTHL_CX_Limit_IN )
- {
- cXiaoChaCNT=1;
- if(!CTHL_PARAM_CXMODE)
- CTHL_CXVAVLE=0;
- else
- CTHL_CXVAVLE=1;
- CTHL_CXHJD_VAVLE =0;
-
- cBAOHUCNT=1;
- CTHL_SetAlarmCode(CTHL_CX_Limit_ALARM ,bRunning);//插销穿入到位异常
- }
-
- if( cXcxcrCnt > 2)
- {
- cXiaoChaCNT=1;
-
- CTHL_CXVAVLE=0;
- CTHL_CXHJD_VAVLE =0;
- cBAOHUCNT=1;
- CTHL_SetAlarmCode(CTHL_CX_Limit_ALARM ,bRunning);//插销穿入到位异常
- }
-
- break;
-
- case 901:
- if(dwTickCount >= CTHL_AutoDelay)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_FKGD_VAVLE = 0; //方块固定退
- CTHL_AutoStep = 20;
- if(!cBAOHUCNT)
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_First_CL_DELAY;//延时一次穿入
- else
- {
- CTHL_AutoDelay = dwTickCount + 1000;//手动插销保护时间
- cBAOHUCNT=0;
- }
- }
-
- }
- break;
- case 20:
- if(dwTickCount >= CTHL_AutoDelay)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 21;
- CTHL_First_CT_VAVLE = 1; //一次穿入电磁阀输出
- CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- }
- }
- break;
- case 21:
- if(!CTHL_First_CT_Origin_IN) //原点离开后才开始时间
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 22;
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_First_CL_Timer; //一次穿入时间
- }
- }
- else if(dwTickCount >= CTHL_AutoDelay)
- {
- CTHL_SetAlarmCode(CTHL_YCCRYWYC_ALARM,bRunning); //一次穿入原位异常
- }
- break;
- case 22:
- if(dwTickCount >= CTHL_AutoDelay)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 23;
- CTHL_MGuo_VAVLE = 0; //码勾退
- if(CTHL_PARAM_LTJJ_MODE)
- {
- CTHL_LTJJ_VAVLE=1;
- }
- CTHL_AutoDelay = dwTickCount + CTHL_PARAM_MGOff_XiaMo_DELAY;
- CTHL_FKGD_VAVLE = 0; //方块固定退
- CTHL_FKJD_VAVLE=0;
- // CTHL_CXHJD_VAVLE = 0; //Y14 插销后夹带打开
- CTHL_CXVAVLE = 0; //Y06 插销下移电磁阀关
- }
- }
- break;
- case 23:
- if(dwTickCount >= CTHL_AutoDelay)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
-
- if(!CTHL_LTJJ_Origin_IN || !CTHL_PARAM_LTJJ_MODE)
- {
- CTHL_CTXM_VAVLE = 0; //穿头下模下降
- CTHL_AutoStep = 24;
- CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- }
- else if(dwTickCount >= CTHL_AutoDelay+3000)
- {
- CTHL_SetAlarmCode(CTHL_XMKH_Origin_ALARM,bRunning);
-
- }
- }
- }
- break;
- case 24:
- if(!CTHL_CTM_Limit_IN)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 25;
- CTHL_FKJD_VAVLE=0;
- CTHL_CXHJD_VAVLE = 0;
- CTHL_AutoDelay = dwTickCount + 30; //一次穿入延时返回
- }
- }
- else if(dwTickCount >= CTHL_AutoDelay)
- {
- CTHL_SetAlarmCode(CTHL_CTM_Origin_ALARM,bRunning);//穿头下模下降异常
- }
- break;
- case 25:
- if(dwTickCount >= CTHL_AutoDelay)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_AutoStep = 26;
- CTHL_First_CT_VAVLE = 0; //一次穿入电磁阀关
- CTHL_AutoDelay = dwTickCount + 5;
- CTHL_CXHDW_VAVLE = 0; //插销后定位(插销穿入)关闭
- //退下出错警告
- CTHL_AutoDelay1 = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- CTHL_AutoStep1 = 1;
- }
- }
- break;
-
-
- case 26:
- if(dwTickCount >= CTHL_AutoDelay)
- {
- if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
- {
- CTHL_FKJD_VAVLE = 1; //方块夹带气缸输出
- CTHL_FKGD_VAVLE = 0; //方块固定关
- CTHL_AutoStep = 4;
- bCL_EN_FLG = 1;
- cXcxcrCnt=0;
- AddToTal(CTHL_TOTAL_ADDR);
- AddToTal(CTHL_TRUST_ALARM_ADDR);
- AddToTal(CTHL_TEST_ALARM_ADDR);
- CalProSP(CTHL_SPEED_ADDR);
- if(cZipCnt<3)
- cZipCnt++;
- }
- }
- break;
-
- }
- }
- //退下模后启动送拉头
- switch(CTHL_AutoStep1)
- {
- case 1:
- if(cStopMode==1 || bSingOneFlg )
- {
- bCL_EN_FLG=1;
- cStopMode=2;
- bSingOneFlg=0;
- bStop=1;
- }
- if(CTHL_CTM_Origin_IN && CTHL_First_CT_Origin_IN)
- {
- CTHL_ZhuangLiaoStep = 1;
- CTHL_TryCnt = 0;
- CTHL_AutoStep1 = 0;
- CTHL_MGuo_VAVLE = 0;
- CTHL_JLTou_VAVLE = 0;
- }
- else if(dwTickCount >= CTHL_AutoDelay1)
- {
- //穿头模和一次穿入回位异常
- if(!CTHL_CTM_Origin_IN)
- CTHL_SetAlarmCode(CTHL_CTM_Origin_ALARM,bRunning);
- else if(!CTHL_First_CT_Origin_IN)
- CTHL_SetAlarmCode(CTHL_First_CT_Origin_ALARM,bRunning);
- }
- break;
-
- }
-
- }
- void CTHL_CheckStart(void)
- {
-
-
- if(cXCXQXQD)
- {
- if(CTHL_START_IN_UP || bStart)
- {
- bStart=0;
- if(!bRunning)
- {
- if(CTHL_SafeDoor_IN )
- {
- bRunning=1;
- cXCXQXQD =0;
- CTHL_TD_MotorStep = 0;
- CTHL_AutoStep=11;
- }
- else
- {
- CTHL_SetAlarmCode(CTHL_SafeDoor_ALARM,0); // 安全门关上才能启动
- }
- }
- }
-
-
- }
- if(cWULATOUCnt) // 无拉头警告后按
- {
- if(CTHL_START_IN_UP || bStart)
- {
- bStart=0;
- if(!bRunning)
- {
- if(CTHL_SafeDoor_IN)
- {
- bRunning=1;
- CTHL_TryCnt=0;
- cWULATOUCnt=0;
- CTHL_ZhuangLiaoStep = 1;
- CTHL_AutoStep=6;
- bTuiLaTouOkFlg = 1;
- bZhuangLiaoOkFlg= 0;
- CTHL_MGuo_VAVLE = 1; //判断是否已经有料
- CTHL_LTJJ_VAVLE=0;
- CTHL_ZhuangLiaoDelay = dwTickCount + 150;
- }
- else
- {
- CTHL_SetAlarmCode(CTHL_SafeDoor_ALARM,0); // 安全门关上才能启动
- }
- }
- }
- }
- if(!CTHL_SafeDoor_IN && bRunning)
- {
- bStop=1;
- CTHL_SetAlarmCode(CTHL_SafeDoor_ALARM,0); // 安全门关上才能启动
- }
-
- //启动 自动启动 单一自动
- if((CTHL_START_IN_UP || bStart || CTHL_bSingleone) && !cWULATOUCnt && !cXCXQXQD)
- {
- if(cCHULIANBAOJIN) //无链停机启动
- {
- cCHULIANBAOJIN=0;
- SetEn(X_AXIS, MOTOR_EN);
- // dwXRealPos=0;
- CTHL_TD_MotorStep=10;
-
- cZipCnt=0;
- CTHL_TD_MotorDelay = dwTickCount + 500;
- CTHL_AutoDelay = dwTickCount + 150;
- if(GetAlarmCode(CTHL_ALARM_ADDR) != 0)
- SetAlarmCode(CTHL_ALARM_ADDR,0);
-
- }
-
- if(!bRunning)
- {
- if(CTHL_SafeDoor_IN)
- {
- cStopMode=0;
- if(CTHL_bSingleone)
- {
- bSingOneFlg=1;
- }
- bRunning = 1;
- cWULATOUCnt=0;
- cHeLian=0;
- if(GetEn(X_AXIS)==MOTOR_DISEN)
- {
- SetEn(X_AXIS, MOTOR_EN);
- CTHL_AutoDelay = dwTickCount + 150;
- }
- SetEn(Y_AXIS, MOTOR_EN);
- CTHL_CL_MotorStep = 40;
- CTHL_AutoStep = 1;
- bTuiLaTouOkFlg = 1;
- CTHL_PARAM_ZDP_AUTO= 0;
- bZhuangLiaoOkFlg= 0;
- if(!CTHL_PARAM_LTJJ_MODE)
- {
- CTHL_LTJJ_VAVLE=0;
- }
-
- CTHL_MGuo_VAVLE = 1; //判断是否已经有料
- CTHL_LTJJ_VAVLE=0;
- CTHL_ZhuangLiaoDelay = dwTickCount + 150;
- // bCL_EN_FLG = 0;
- cZipCnt = 0;
- cQDXK_DXK=0;
- CTHL_LianLengthCheck = 0;
- cStopInCnt = 0;
- }
- else
- {
- CTHL_SetAlarmCode(CTHL_SafeDoor_ALARM,0); // 安全门关上才能启动
- }
- }
- CTHL_bSingleone=0;
- bStart = 0;
- }
- if(CTHL_STOP_INJT_UP)
- {
- bRunning=0;
- cXcxcrCnt=0;
- cStopMode=0;
- cCHULIANBAOJIN=0;
- cXCXQXQD=0;
- cWULATOUCnt=0;
- bCL_EN_FLG=0;
- AxisEgmStop(X_AXIS);
- AxisEgmStop(Y_AXIS);
- SetEn(X_AXIS, MOTOR_DISEN);
- SetEn(Y_AXIS, MOTOR_DISEN);
- cStopMode=0;
- cQDXK_DXK=0;
-
- if(GetAlarm(Y_AXIS)==1 || GetAlarm(X_AXIS)==0)
- {
- SetClr(Y_AXIS, MOTOR_NOALARM);
- SetClr(X_AXIS, MOTOR_NOALARM);
- CTHL_bSFBBAOJIN_Delay= dwTickCount + 2000;
- }
- CTHL_TLiao_VAVLE=0;
- CTHL_HSLiao_VAVLE =0;
- CTHL_JLTou_VAVLE =0;
- CTHL_XKTD_VAVLE =0;
- CTHL_XKDW_VAVLE =0;
- CTHL_DXK_VAVLE =0;
- CTHL_CXVAVLE =0;
- CTHL_CTXM_VAVLE =0;
- CTHL_First_CT_VAVLE =0;
- CTHL_FKGD_VAVLE =0;
- CTHL_CXQJD_VAVLE =0;
- CTHL_CXDWZ_VAVLE =0;
- CTHL_CXHJD_VAVLE =0;
- CTHL_CXHDW_VAVLE =0;
- CTHL_FKJD_VAVLE =0;
- CTHL_HLJJ_VAVLE =0;
- CTHL_CXSCDW_VAVLE =0;
- CTHL_MGuo_VAVLE =0;
- CTHL_QDXK_VAVLE=0;
- CTHL_LTJJ_VAVLE =0;
- CTHL_AutoStep = 0;
- CTHL_ZhuangLiaoStep=0;
- CTHL_TLiaoStep=0;
- CTHL_TD_MotorStep=0;
- CTHL_JiaLianStep =0;
- CTHL_SongLiaoStep =0;
- CTHL_CL_MotorStep =0;
- CTHL_AutoStep1 =0;
- CTHL_bFKCXTDDW_Step=0;
- CTHL_bCXCR_Step=0;
- CTHL_bCLFirst_Step=0;
- if(GetAlarmCode(CTHL_ALARM_ADDR) != 0)
- SetAlarmCode(CTHL_ALARM_ADDR,0);
- SetPos(X_AXIS, 0);
-
- CTHL_TLiaoStep = 0;
- CTHL_AutoStep = 0;
-
- //穿合链电机是往零点方向时可以停止
- if(GetDir(Y_AXIS) == DIR_N)
- AxisEgmStop(Y_AXIS);
- }
-
- //停止
- if(CTHL_STOP_IN_UP || bStop)
- {
-
- if(cStopMode < 2)
- cStopMode++;
- if(bRunning && cStopMode==2)
- {
- bRunning=0;
- cStopMode=0;
- cXcxcrCnt=0;
- bSingOneFlg=0;
- cXCXQXQD=0;
- cCHULIANBAOJIN=0;
- cWULATOUCnt=0;
- AxisEgmStop(X_AXIS);
- AxisEgmStop(Y_AXIS);
- CTHL_AutoStep = 0;
- CTHL_CL_MotorStep =0;
- CTHL_bCLFirst_Step=0;
- CTHL_ZhuangLiaoStep=0;
- // CTHL_XKTD_VAVLE = 0;
- cQDXK_DXK=0;
- // CTHL_XKDW_VAVLE =0;
-
- if(GetAlarm(Y_AXIS)==1 || GetAlarm(X_AXIS)==0)
- {
- SetClr(Y_AXIS, MOTOR_NOALARM);
- SetClr(X_AXIS, MOTOR_NOALARM);
- CTHL_bSFBBAOJIN_Delay= dwTickCount + 2000;
- }
- if(GetAlarmCode(CTHL_ALARM_ADDR) != 0)
- SetAlarmCode(CTHL_ALARM_ADDR,0);
-
- }
- else if(!bRunning)
- {
- bRunning=0;
- cXcxcrCnt=0;
- cStopMode=0;
- cCHULIANBAOJIN=0;
- cXCXQXQD=0;
- cWULATOUCnt=0;
- bCL_EN_FLG=0;
- bSingOneFlg=0;
- AxisEgmStop(X_AXIS);
- AxisEgmStop(Y_AXIS);
- SetEn(X_AXIS, MOTOR_DISEN);
- SetEn(Y_AXIS, MOTOR_DISEN);
- cStopMode=0;
- cQDXK_DXK=0;
-
- if(GetAlarm(Y_AXIS)==1 || GetAlarm(X_AXIS)==0)
- {
- SetClr(Y_AXIS, MOTOR_NOALARM);
- SetClr(X_AXIS, MOTOR_NOALARM);
- CTHL_bSFBBAOJIN_Delay= dwTickCount + 2000;
- }
- CTHL_TLiao_VAVLE=0;
- CTHL_HSLiao_VAVLE =0;
- CTHL_JLTou_VAVLE =0;
- CTHL_XKTD_VAVLE =0;
- CTHL_XKDW_VAVLE =0;
- CTHL_DXK_VAVLE =0;
- CTHL_CXVAVLE =0;
- CTHL_CTXM_VAVLE =0;
- CTHL_First_CT_VAVLE =0;
- CTHL_FKGD_VAVLE =0;
- CTHL_CXQJD_VAVLE =0;
- CTHL_CXDWZ_VAVLE =0;
- CTHL_CXHJD_VAVLE =0;
- CTHL_CXHDW_VAVLE =0;
- CTHL_FKJD_VAVLE =0;
- CTHL_HLJJ_VAVLE =0;
- CTHL_CXSCDW_VAVLE =0;
- CTHL_MGuo_VAVLE =0;
- CTHL_QDXK_VAVLE=0;
- CTHL_LTJJ_VAVLE =0;
- CTHL_AutoStep = 0;
- CTHL_ZhuangLiaoStep=0;
- CTHL_TLiaoStep=0;
- CTHL_TD_MotorStep=0;
- CTHL_JiaLianStep =0;
- CTHL_SongLiaoStep =0;
- CTHL_CL_MotorStep =0;
- CTHL_AutoStep1 =0;
- CTHL_bFKCXTDDW_Step=0;
- CTHL_bCXCR_Step=0;
- CTHL_bCLFirst_Step=0;
- if(GetAlarmCode(CTHL_ALARM_ADDR) != 0)
- SetAlarmCode(CTHL_ALARM_ADDR,0);
- SetPos(X_AXIS, 0);
-
- CTHL_TLiaoStep = 0;
- CTHL_AutoStep = 0;
-
- //穿合链电机是往零点方向时可以停止
- if(GetDir(Y_AXIS) == DIR_N)
- AxisEgmStop(Y_AXIS);
-
- }
- bStop=0;
- }
-
- if(bAlarmStop)
- {
- bRunning = 0;
- bAlarmStop=0;
- cStopMode=0;
- cXcxcrCnt=0;
- AxisEgmStop(X_AXIS);
- AxisEgmStop(Y_AXIS);
- CTHL_AutoStep = 0;
- cQDXK_DXK=0;
- CTHL_CL_MotorStep =0;
- CTHL_bCLFirst_Step=0;
- CTHL_SongLiaoStep =0;
- CTHL_ZhuangLiaoStep=0;
- // CTHL_XKTD_VAVLE = 0;
- // CTHL_XKDW_VAVLE =0;
-
- }
- }
- //拖带电机控制动作 X轴
- void CTHL_TD_Motor(void) //
- {
- #if 1
- switch(CTHL_TD_MotorStep)
- {
- //1步开始,纯定位, 没有穿入
- case 1:
- if(dwTickCount >= CTHL_TD_MotorDelay) //给锁轴时间
- {
- bCheckEN_FLG = 1;
- CTHL_CheckInX02PosBuff= 0;
- CTHL_TD_MotorStep = 2;
- SetPos(X_AXIS, 0); //启动位置设为0点
- AxisContinueMoveAcc(X_AXIS,CTHL_PARAM_TD_RunSpeed*2/3,DIR_P,800,600,15,15);
- CTHL_X_CXPosBuff=0;
- }
- break;
- case 2://检测到过链
- if(dwXRealPos > 400) //穿入2CM后退
- {
- if(CTHL_PARAM_NLSL_MODE)
- {
- CTHL_XKTD_VAVLE=0;
- }
- CTHL_DXK_VAVLE = 0; //顶斜口气缸关
- CTHL_QDXK_VAVLE = 0;
- }
- if(dwXRealPos >= CTHL_PARAM_WLCDSHEZHI_LENTH)
- {
- CTHL_SetAlarmCode(CTHL_WLZDTJ_ALARM,bRunning); //无拉链自动停机
- }
- if(CTHL_FK_Check)
- {
- CTHL_DXK_VAVLE = 0; //顶斜口气缸关
- CTHL_QDXK_VAVLE = 0;
- CTHL_XSavePosBuff = dwXRealPos;
- CTHL_TD_MotorStep = 3;
- user_datas[123] = dwXRealPos - CTHL_CheckInX02PosBuff;
- if((dwXRealPos >= CTHL_CheckInX02PosBuff) && CTHL_CheckInX02PosBuff)
- AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed*2/3,CTHL_PARAM_FKDW_Length - (dwXRealPos- CTHL_CheckInX02PosBuff)-160,
- CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,30,40);
- else
- AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed*2/3,CTHL_PARAM_FKDW_Length-120,
- CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,30,40);
- }
- break;
- case 3:
- if(CTHL_CXSC_Limit_IN_UP)
- {
- CTHL_X_CXPosBuff = dwXRealPos;
-
- }
-
- if(!X_DRV || (dwXRealPos >= (CTHL_XSavePosBuff + CTHL_PARAM_FKDW_Length)))
- {
- AxisEgmStop(X_AXIS);
- CTHL_TD_MotorStep =4 ;
- CTHL_LianLengthAutoCheck = dwXRealPos;
- }
- break;
- case 4:
- if(CTHL_PARAM_XCX_LENTH) //0的话不判断位置
- {
-
- if ((dwXRealPos - CTHL_X_CXPosBuff) > (CTHL_PARAM_XCX_LENTH + CTHL_PARAM_XCXWC_LENTH))
- {
- // user_datas[121] = 1;
- CTHL_TD_MotorStep = 0;
- CTHL_SetAlarmCode(CTHL_XCXXCYC_ALARM,bRunning); // 小插销行程异常
-
- }
-
- else if(CTHL_X_CXPosBuff == 0)
- {
- // user_datas[121] = 3;
- CTHL_TD_MotorStep = 0;
- CTHL_SetAlarmCode(CTHL_XCXXCYC_ALARM,bRunning); // 小插销行程异常
- }
- else
- {
- CTHL_TD_MotorStep = 0;
- CTHL_X_CXPosBuff=dwXRealPos;
-
- }
-
- }
- else
- {
- CTHL_TD_MotorStep = 0;
- // CTHL_X_CXPosBuff=dwXRealPos;
- }
- break;
-
- //穿拉头定位
- case 10:
- if(dwTickCount >= CTHL_TD_MotorDelay)
- {
- CTHL_TD_MotorStep = 11;
- SetPos(X_AXIS, 0); //启动位置设为0点
- dwXRealPos = 0;
- AxisContinueMoveAcc(X_AXIS,CTHL_PARAM_TDCR_LowSpeed,DIR_P,200,200,5,5);
- CTHL_CheckInX02PosBuff= 0;
- CTHL_X_CXPosBuff=0;
- bCheckEN_FLG = 1;
- }
- break;
- case 11:
- if(CTHL_PARAM_NLSL_MODE)
- CTHL_Data_Buff = 600;
- else
- CTHL_Data_Buff = 400;
- if(dwXRealPos > CTHL_Data_Buff) //穿入2CM后退
- {
- CTHL_CheckInX02PosBuff= 0;
- CTHL_DXK_VAVLE = 0; //顶斜口气缸关
- CTHL_QDXK_VAVLE = 0;
- if(CTHL_PARAM_NLSL_MODE)
- {
- CTHL_XKTD_VAVLE=0;
- }
- CTHL_TD_MotorStep = 12;
- if((cZipCnt < 2) || ((CTHL_LianLengthCheck < CTHL_PARAM_TDCR_LowSpeedLength+300) && (CTHL_PARAM_NLSL_MODE == 0)) ||
- ((CTHL_LianLengthCheck < CTHL_PARAM_TDCR_LowSpeedLength+600) && (CTHL_PARAM_NLSL_MODE == 1)))
- AxisContinueMoveAcc(X_AXIS,CTHL_PARAM_TD_RunSpeed*2/3,DIR_P,3000,600,10,10);
- else ////两段速度移动距离
- {
- if(CTHL_PARAM_NLSL_MODE == 0)
- AxisMovePosAccDecNotStop(X_AXIS,CTHL_PARAM_TD_RunSpeed * 1.5,CTHL_LianLengthCheck-(CTHL_PARAM_TDCR_LowSpeedLength),3000,CTHL_PARAM_TD_RunSpeed*2/3,15,70,600);
- else //尼龙
- {
- AxisMovePosAccDecNotStop(X_AXIS,CTHL_PARAM_TD_RunSpeed * 1.3,CTHL_LianLengthCheck-(CTHL_PARAM_TDCR_LowSpeedLength),3000,CTHL_PARAM_TD_RunSpeed*2/3,12,120,850);
- }
- }
- }
- if(CTHL_FK_Check) //在这里检测到说明速度还没有起来
- {
- CTHL_DXK_VAVLE = 0; //顶斜口气缸关
- CTHL_QDXK_VAVLE = 0;
- if(CTHL_PARAM_NLSL_MODE)
- {
- CTHL_XKTD_VAVLE=0;
- }
- CTHL_TD_MotorDelay= dwTickCount + CTHL_PARAM_FKJDSECONG_DEALY;
- CTHL_LianLengthReal = dwXRealPos;
-
- CTHL_XSavePosBuff = dwXRealPos;
- CTHL_TD_MotorStep = 13;
- // user_datas[122] = CTHL_PARAM_FKDW_Length - (dwXRealPos- CTHL_CheckInX02PosBuff);
-
- if((dwXRealPos >= CTHL_CheckInX02PosBuff) && CTHL_CheckInX02PosBuff)
- AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed,CTHL_PARAM_FKDW_Length - (dwXRealPos- CTHL_CheckInX02PosBuff),
- CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,10);
- else
- AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed,CTHL_PARAM_FKDW_Length,
- CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,10);
- //CTHL_TD_MotorStep = 0;
- }
- else if(CTHL_CXSC_Limit_IN_DW)
- {
- CTHL_SetAlarmCode(CTHL_DK_ERROR_ALARM,bRunning);
- }
- else if(CTHL_CXSC_Limit_IN_UP)
- {
- AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed * 2/3,CTHL_PARAM_FKDW_Length,
- CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,10);
- }
- break;
- case 12://检测到过链
- if(cZipCnt<2)
- {
- if(dwXRealPos >= CTHL_PARAM_WLCDSHEZHI_LENTH)
- {
- if(bRunning)
- {
- cCHULIANBAOJIN=1;
- SetEn(X_AXIS, MOTOR_DISEN);
- AxisEgmStop(X_AXIS);
- SetPos(X_AXIS, 0); //启动位置设为0点
- // dwXRealPos=0;
- }
- CTHL_SetAlarmCode(CTHL_WLZDTJ_ALARM,bRunning); //无拉链自动停机
- }
- }
- else
- {
- if(dwXRealPos >= CTHL_LianLengthAutoCheckERROR + CTHL_PARAM_WUCD_LENTH)
- {
- if(bRunning)
- {
- cCHULIANBAOJIN=1;
- SetEn(X_AXIS, MOTOR_DISEN);
- AxisEgmStop(X_AXIS);
- SetPos(X_AXIS, 0); //启动位置设为0点
- // dwXRealPos=0;
- }
- CTHL_SetAlarmCode(CTHL_WLZDTJ_ALARM,bRunning); //无拉链自动停机
- }
-
- }
- if(CTHL_FK_Check)
- {
- CTHL_TD_MotorDelay= dwTickCount + CTHL_PARAM_FKJDSECONG_DEALY;
- CTHL_LianLengthReal = dwXRealPos;
- //if(cZipCnt == 1)
- // user_datas[122] = dwXRealPos;
- // user_datas[121] = dwXRealPos;
- if((cZipCnt == 1) || dwXRealPos < (CTHL_LianLengthCheck*0.85) || dwXRealPos>(CTHL_LianLengthCheck*1.3))
- CTHL_LianLengthCheck = dwXRealPos;
-
- CTHL_LianLengthCheckOLD=CTHL_LianLengthNEWCheck;
- CTHL_LianLengthNEWCheck = dwXRealPos;
- //break;
- CTHL_XSavePosBuff = dwXRealPos;
- CTHL_TD_MotorStep = 13;
- // user_datas[122] = CTHL_PARAM_FKDW_Length - (dwXRealPos- CTHL_CheckInX02PosBuff);
-
- if((dwXRealPos >= CTHL_CheckInX02PosBuff) && CTHL_CheckInX02PosBuff)
- AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed,CTHL_PARAM_FKDW_Length - (dwXRealPos- CTHL_CheckInX02PosBuff)-50,
- CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,40);
- else
- AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed,CTHL_PARAM_FKDW_Length-50,
- CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,40);
- //CTHL_TD_MotorStep = 0;
- }
- else if(CTHL_CXSC_Limit_IN_DW)
- {
- CTHL_SetAlarmCode(CTHL_DK_ERROR_ALARM,bRunning);
- }
- else if(CTHL_CXSC_Limit_IN_UP)
- {
- AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed * 2/3,CTHL_PARAM_FKDW_Length,
- CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,40);
- }
- break;
- case 13:
- if(dwTickCount >= CTHL_TD_MotorDelay)
- {
- CTHL_FKJD_VAVLE = 1; //方块夹带气缸输出
-
- }
- if(CTHL_CXSC_Limit_IN_UP)
- {
- CTHL_X_CXPosBuff = dwXRealPos;
-
- }
- if((!X_DRV ))// || (dwXRealPos >= (CTHL_XSavePosBuff + CTHL_PARAM_FKDW_Length)))
- {
- // user_datas[123] = dwXRealPos-CTHL_CheckInX02PosBuff;
- AxisEgmStop(X_AXIS);
- CTHL_TD_MotorStep = 14;
- /* if(cZipCnt>2)
- {
- if(((CTHL_LianLengthNEWCheck+CTHL_LianLengthCheckOLD)*0.5) < (CTHL_LianLengthCheck*0.95))
- {
- cZipCnt=0;
- cHeLian=1;
- }
- }*/
- if(cZipCnt==1)
- CTHL_LianLengthAutoCheckERROR = dwXRealPos;
-
- if(cZipCnt==1)
- CTHL_LianLengSave=dwXRealPos;
-
- CTHL_LianLengthAutoCheck = dwXRealPos;
- user_datas[122] = dwXRealPos-CTHL_X_CXPosBuff;
- }
- break;
- case 14:
-
- if(CTHL_PARAM_XCX_LENTH) //0的话不判断位置
- {
-
- if ((dwXRealPos - CTHL_X_CXPosBuff) > (CTHL_PARAM_XCX_LENTH + CTHL_PARAM_XCXWC_LENTH))
- {
- // user_datas[121] = 1;
- CTHL_TD_MotorStep = 0;
- cXCXQXQD=1;
- CTHL_SetAlarmCode(CTHL_XCXXCYC_ALARM,bRunning); // 小插销行程异常
-
- }
- else if((dwXRealPos - CTHL_X_CXPosBuff) < (CTHL_PARAM_XCX_LENTH - CTHL_PARAM_XCXWC_LENTH))
- {
- // user_datas[121] = 2;
- CTHL_TD_MotorStep = 0;
- cXCXQXQD=1;
- CTHL_SetAlarmCode(CTHL_XCXXCYC_ALARM,bRunning); // 小插销行程异常
- }
- else if(CTHL_X_CXPosBuff == 0)
- {
- // user_datas[121] = 3;
- CTHL_TD_MotorStep = 0;
- cXCXQXQD=1;
- CTHL_SetAlarmCode(CTHL_XCXXCYC_ALARM,bRunning); // 小插销行程异常
- }
- else
- {
-
- CTHL_TD_MotorStep = 15;
- }
-
- }
- else
- {
-
- CTHL_TD_MotorStep = 15;
- }
- break;
- case 15:
- // if(CTHL_START_IN_UP)
- CTHL_TD_MotorStep = 0;
-
-
- }
- #endif
- }
- //穿入电机动作,Y轴
- void CTHL_CL_Motor(void) //
- {
- #if 0
- //1步开始, 穿链长度开始
- //20步开始 插销定位开始
- //40步,回原点为
- switch(CTHL_CL_MotorStep)
- {
- //穿入长度位置
- case 1:
-
- if(dwTickCount >= CTHL_CL_MotorDelay)
- {
- // SetDir(Y_AXIS, DIR_P);
- if(CTHL_PARAM_CL_Length >= CTHL_PARAM_CL_MAX_Length)
- CTHL_PARAM_CL_Length = CTHL_PARAM_CL_MAX_Length;
- //穿入长度要根据检测长度减动一次穿入的1CM,反转的2CM
- if((CTHL_LianLengthAutoCheck < (CTHL_PARAM_CL_Length + 500 )) && bRunning)
- AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,(CTHL_LianLengthAutoCheck-500),800,600,6,6,50);
- else
- AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,(CTHL_PARAM_CL_Length-100),800,600,6,6,50);
- CTHL_CL_MotorStep = 2;
- }
- break;
- case 2:
- if((dwYRealPos + 120) > CTHL_PARAM_CL_Length)
- CTHL_HLJJ_VAVLE = 0;
- if(!Y_DRV || dwYRealPos >= CTHL_PARAM_CL_Length)
- {
- CTHL_HLJJ_VAVLE = 0;
- CTHL_CL_MotorStep = 3;
- bCL_OK_FLG = 1;
- CTHL_CL_MotorDelay = dwTickCount + 40; //延时数控回零点
- }
- break;
- case 3:
- if(dwTickCount >= CTHL_CL_MotorDelay)
- {
- CTHL_CL_MotorStep = 50;
- }
- break;
- //夹带插销到穿入位置
- case 20: //此处最好算好定位长度相减
- if(cXcxcrCnt > 0)
- {
- CTHL_LENTH = CTHL_PARAM_CXDW_Length + 30;
- CTHL_CL_MotorStep = 21;
- }
- else
- {
- CTHL_LENTH = CTHL_PARAM_CXDW_Length ;
- CTHL_CL_MotorStep = 21;
- }
- break;
- case 21:
- SetDir(Y_AXIS, DIR_P);
- AxisMovePosAccDec(Y_AXIS,8000,CTHL_LENTH,800,500,6,6,50);
- CTHL_CL_MotorStep = 22;
- break;
- case 22:
- if(!Y_DRV || (dwYRealPos >= CTHL_LENTH)) //插销定位已经结束
- {
- AxisEgmStop(Y_AXIS);
- CTHL_YsaveCXDWPosBuff = 0;
- CTHL_CL_MotorStep = 0;
- }
- break;
- //回原点开始
- case 40:
- //要先离开
- if(CTHL_SF_Origin_IN && (GetEn(Y_AXIS) == MOTOR_DISEN))
- {
- CTHL_CL_MotorStep = 41;
- SetDir(Y_AXIS, DIR_P);
- }
- else
- {
- SetDir(Y_AXIS, DIR_N);
- CTHL_CL_MotorStep = 46;
-
- }
- if(GetEn(Y_AXIS) == MOTOR_DISEN)
- {
- SetEn(Y_AXIS, MOTOR_EN);
- CTHL_CL_MotorDelay = dwTickCount + 260; //锁轴时间
-
- }
- else //已经锁轴
- CTHL_CL_MotorDelay = dwTickCount + 5;
- break;
- case 41:
- if(dwTickCount >= CTHL_CL_MotorDelay)
- {
- CTHL_CL_MotorStep = 42;
- AxisContinueMoveAcc(Y_AXIS,5000,DIR_P,1000,800,15,15);
- }
- break;
- case 42:
- if(!CTHL_SF_Origin_IN)
- {
- CTHL_CL_MotorStep = 43;
- CTHL_YSavePosBuff = dwYRealPos;
- }
- break;
- case 43:
- //离开原点5CM停止
- if((dwYRealPos - CTHL_YSavePosBuff) >= 800)
- {
- AxisEgmStop(Y_AXIS);
- CTHL_CL_MotorStep = 46; //留空几步备用
- CTHL_CL_MotorDelay = dwTickCount + 50;
- }
- break;
- case 46:
- if(dwTickCount >= CTHL_CL_MotorDelay)
- {
- CTHL_CL_MotorStep = 47; //检测回到原位
- if(!CTHL_SF_Origin_IN)
- AxisContinueMoveAcc(Y_AXIS,1500,DIR_N,1000,800,15,10);
- }
- break;
- case 47:
- if(CTHL_SF_Origin_IN)
- {
- CTHL_CL_MotorStep = 0;
- AxisEgmStop(Y_AXIS);
- SetPos(Y_AXIS, 0);
- }
- break;
- //数控回原位 (条件为自动工作,SON一直没有松开)
- case 50:
- if(dwYRealPos > 150)
- { //回零速度
- SetDir(Y_AXIS, DIR_N);
- AxisMovePosAccDecNotStop(Y_AXIS,CTHL_PARAM_CL_Back_O_Speed,-dwYRealPos + 150,5000,2000,10,50,50);
-
-
- }
- else
- AxisContinueMoveAcc(Y_AXIS,1000,DIR_N,1000,1000,15,15);
- CTHL_CL_MotorStep = 51;
- break;
- case 51:
- if(CTHL_SF_Origin_IN)
- {
- CTHL_CL_MotorStep = 0;
- AxisEgmStop(Y_AXIS);
- SetPos(Y_AXIS, 0);
- }
- break;
-
- }
- #endif
-
- #if 1
- //1步开始, 穿链长度开始
- //20步开始 插销定位开始
- //40步,回原点为
- switch(CTHL_CL_MotorStep)
- {
- //穿入长度位置
- case 1:
- if(dwTickCount >= CTHL_CL_MotorDelay)
- {
- if(!CTHL_PARAM_AUTO_MODE)
- {
- //穿入长度要根据检测长度减动一次穿入的1CM,反转的2CM
- if(CTHL_LianLengthAutoCheck <= 700)
- {
- CTHL_Y_CL_Length=CTHL_LianLengthAutoCheck-200;
- if(CTHL_Y_CL_Length<10)
- CTHL_Y_CL_Length=200;
- if(CTHL_Y_CL_Length >= CTHL_PARAM_CL_MAX_Length)
- CTHL_Y_CL_Length = CTHL_PARAM_CL_MAX_Length-40;
- AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,CTHL_Y_CL_Length,800,600,6,6,50);
- }
- else if(CTHL_LianLengthAutoCheck>700)
- {
-
- user_datas[123] =CTHL_LianLengthAutoCheck;
- if(cZipCnt>1)
- CTHL_Y_CL_Length=CTHL_LianLengSave-CTHL_PARAM_HLTSY_LENTH-300;
- else
- {
- if(cZipCnt<1)
- CTHL_Y_CL_Length=CTHL_LianLengthAutoCheck-CTHL_PARAM_HLTSY_LENTH-100;
- else
- CTHL_Y_CL_Length=CTHL_LianLengthAutoCheck-CTHL_PARAM_HLTSY_LENTH-300;
- }
- if(cZipCnt>1)
- {
- if(CTHL_LianLengthAutoCheck<(CTHL_LianLengSave*0.7))
- {
- CTHL_Y_CL_Length=CTHL_LianLengthAutoCheck-CTHL_PARAM_HLTSY_LENTH-300;
- cZipCnt=0;
- }
- }
- if(CTHL_Y_CL_Length<200)
- CTHL_Y_CL_Length=200;
- if(CTHL_Y_CL_Length >= CTHL_PARAM_CL_MAX_Length)
- CTHL_Y_CL_Length = CTHL_PARAM_CL_MAX_Length-40;
- AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,CTHL_Y_CL_Length,800,600,6,6,50);
-
- }
-
- }
-
- else
- {
- if(CTHL_PARAM_CL_Length >= CTHL_PARAM_CL_MAX_Length)
- CTHL_PARAM_CL_Length = CTHL_PARAM_CL_MAX_Length;
- //穿入长度要根据检测长度减动一次穿入的1CM,反转的2CM
- if((CTHL_LianLengthAutoCheck < (CTHL_PARAM_CL_Length + 500 )) && bRunning)
- AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,(CTHL_LianLengthAutoCheck-500),800,600,6,6,50);
- else
- AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,(CTHL_PARAM_CL_Length-100),800,600,6,6,50);
-
- }
- CTHL_CL_MotorStep = 2;
- }
- break;
- case 2:
- if(CTHL_PARAM_AUTO_MODE)
- {
- if((dwYRealPos + 120) > CTHL_PARAM_CL_Length)
- CTHL_HLJJ_VAVLE = 0;
- if(!Y_DRV || dwYRealPos >= CTHL_PARAM_CL_Length)
- {
- CTHL_HLJJ_VAVLE = 0;
- CTHL_CL_MotorStep = 3;
- bCL_OK_FLG = 1;
- CTHL_CL_MotorDelay = dwTickCount + 30; //延时数控回零点
- }
- }
- else
- {
- if((dwYRealPos + 120) > CTHL_Y_CL_Length)
- CTHL_HLJJ_VAVLE = 0;
- if(!Y_DRV || dwYRealPos >= CTHL_Y_CL_Length)
- {
- CTHL_HLJJ_VAVLE = 0;
- CTHL_CL_MotorStep = 3;
- bCL_OK_FLG = 1;
- CTHL_CL_MotorDelay = dwTickCount + 30; //延时数控回零点
- }
-
- }
- break;
- case 3:
- if(dwTickCount >= CTHL_CL_MotorDelay)
- {
- CTHL_CL_MotorStep = 50;
- }
- break;
- //夹带插销到穿入位置
- case 20: //此处最好算好定位长度相减
- if(cXcxcrCnt > 0)
- {
- if(cXcxcrCnt==1)
- CTHL_LENTH = CTHL_PARAM_CXDW_Length+CTHL_PARAM_TDFZ_LENTH + 50;
- if(cXcxcrCnt>1)
- CTHL_LENTH = CTHL_PARAM_CXDW_Length +CTHL_PARAM_TDFZ_LENTH + 120;
- CTHL_CL_MotorStep = 21;
- }
- else
- {
- CTHL_LENTH = CTHL_PARAM_CXDW_Length ;
- CTHL_CL_MotorStep = 21;
- }
- break;
- case 21:
- SetDir(Y_AXIS, DIR_P);
- CTHL_Y_CL_PosBuff = dwYRealPos;
- AxisMovePosAccDec(Y_AXIS,20000,CTHL_LENTH,800,500,6,6,50);
- CTHL_CL_MotorStep = 22;
- break;
- case 22:
- if(dwYRealPos >= CTHL_Y_CL_PosBuff+CTHL_LENTH-CTHL_PARAM_CXDW_Length) //插销定位已经结束
- {
- CTHL_CXSCDW_VAVLE = 1;
- }
-
- if(!Y_DRV || (dwYRealPos >= CTHL_Y_CL_PosBuff+CTHL_LENTH)) //插销定位已经结束
- {
- AxisEgmStop(Y_AXIS);
- CTHL_YsaveCXDWPosBuff = 0;
- CTHL_CL_MotorStep = 0;
- }
-
- break;
- case 30:
- CTHL_YsaveCXDWPosBuff = 0;
- CTHL_CL_MotorStep = 0;
- break;
- //回原点开始
- case 40:
- //要先离开
- if(CTHL_SF_Origin_IN && (GetEn(Y_AXIS) == MOTOR_DISEN))
- {
- CTHL_CL_MotorStep = 41;
- SetDir(Y_AXIS, DIR_P);
- }
- else
- {
- SetDir(Y_AXIS, DIR_N);
- CTHL_CL_MotorStep = 46;
-
- }
- if(GetEn(Y_AXIS) == MOTOR_DISEN)
- {
- SetEn(Y_AXIS, MOTOR_EN);
- CTHL_CL_MotorDelay = dwTickCount + 260; //锁轴时间
-
- }
- else //已经锁轴
- CTHL_CL_MotorDelay = dwTickCount + 5;
- break;
- case 41:
- if(dwTickCount >= CTHL_CL_MotorDelay)
- {
- CTHL_CL_MotorStep = 42;
- AxisContinueMoveAcc(Y_AXIS,5000,DIR_P,1000,800,15,15);
- }
- break;
- case 42:
- if(!CTHL_SF_Origin_IN)
- {
- CTHL_CL_MotorStep = 43;
- CTHL_YSavePosBuff = dwYRealPos;
- }
- break;
- case 43:
- //离开原点5CM停止
- if((dwYRealPos - CTHL_YSavePosBuff) >= 800)
- {
- AxisEgmStop(Y_AXIS);
- CTHL_CL_MotorStep = 46; //留空几步备用
- CTHL_CL_MotorDelay = dwTickCount + 50;
- }
- break;
- case 46:
- if(dwTickCount >= CTHL_CL_MotorDelay)
- {
- CTHL_CL_MotorStep = 47; //检测回到原位
- if(!CTHL_SF_Origin_IN)
- AxisContinueMoveAcc(Y_AXIS,1500,DIR_N,1000,800,15,10);
- }
- break;
- case 47:
- if(CTHL_SF_Origin_IN)
- {
- CTHL_CL_MotorStep = 0;
- AxisEgmStop(Y_AXIS);
- SetPos(Y_AXIS, 0);
- }
- break;
- //数控回原位 (条件为自动工作,SON一直没有松开)
- case 50:
- if(dwYRealPos > 151)
- { //回零速度
-
- SetDir(Y_AXIS, DIR_N);
- AxisMovePosAccDecNotStop(Y_AXIS,CTHL_PARAM_CL_Back_O_Speed,-dwYRealPos + 150,5000,2000,10,50,100);
- }
- else
- AxisContinueMoveAcc(Y_AXIS,1000,DIR_N,1000,1000,15,15);
- CTHL_CL_MotorStep = 51;
- break;
- case 51:
- if(CTHL_SF_Origin_IN)
- {
- CTHL_CL_MotorStep = 0;
- AxisEgmStop(Y_AXIS);
- SetPos(Y_AXIS, 0);
- }
- break;
-
- }
- #endif
- }
- //装拉头动作
- void CTHL_ZLT_Step(void)
- {
-
- switch(CTHL_ZhuangLiaoStep)
- {
- case 1://检测是否有拉头?
-
- if(bZhuangLiaoOkFlg)
- {
- CTHL_ZhuangLiaoStep = 0;
- }
- else if(dwTickCount >= CTHL_ZhuangLiaoDelay)
- {
-
- if(((CTHL_MGuo_VAVLE && CTHL_LTou_Check) || (!CTHL_MGuo_VAVLE)) && !CTHL_JLiao_Limit_IN )//说明没有拉头
- {
- //穿头模和一次穿入必须在原位,接料不能有输出
- if(CTHL_CTM_Origin_IN && !CTHL_CTXM_VAVLE)//下模没有输出、下模在原位。
- {
- CTHL_First_CT_VAVLE = 0;//?
- CTHL_JLTou_VAVLE = 0;//夹拉头松开
- CTHL_MGuo_VAVLE = 0; //码钩松开
- if(CTHL_TLiaoStep == 0)//执行推料步骤动作
- {
- CTHL_TLiaoStep = 1;
- CTHL_ZhuangLiaoStep = 2;
- }
- }
- else if(dwTickCount >= CTHL_ZhuangLiaoDelay + 500) //下模原位异常
- {
- CTHL_SetAlarmCode(CTHL_CTM_Origin_ALARM,bRunning);
-
- }
- }
- else //已经有拉头直接跳到结束
- {
- CTHL_ZhuangLiaoDelay = dwTickCount + 40;
- CTHL_ZhuangLiaoStep = 9;
- }
- }
- break;
- case 2: //等待推料完成
- if(CTHL_TLiaoStep == 0) //推料已经完成
- {
- CTHL_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
- CTHL_JLTou_VAVLE = 0;//夹拉头送开
- CTHL_MGuo_VAVLE = 0; //码钩松开
- if(!CTHL_JLiao_Limit_IN && CTHL_First_CT_Origin_IN)
- {
- CTHL_ZhuangLiaoStep = 3;
- CTHL_HSLiao_VAVLE = 1;
- if(CTHL_PARAM_LTJJ_MODE)
- {
- CTHL_LTJJ_VAVLE=1;
- }
- else
- CTHL_LTJJ_VAVLE=0;
-
- }
- }
- break;
- case 3:
- //横送到位
- if(CTHL_HSLiao_Limit_IN && !CTHL_HSLiao_Origin_IN)
- {
- CTHL_ZhuangLiaoStep = 4;
- // CTHL_JLTou_VAVLE = 1; //接拉头输出,不需要时间
- CTHL_ZhuangLiaoDelay = dwTickCount + 5;
- }
- else if(dwTickCount >= CTHL_ZhuangLiaoDelay)
- {
- CTHL_SetAlarmCode(CTHL_HSLiao_Limit_ALARM,bRunning);
- }
- break;
- case 4:
- if(dwTickCount >= CTHL_ZhuangLiaoDelay)
- {
- CTHL_ZhuangLiaoStep = 5;
- CTHL_JLTou_VAVLE = 1; //接拉头输出,不需要时间
- CTHL_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
- }
- break;
- case 5:
- if(CTHL_JLiao_Limit_IN)
- {
- CTHL_LTJJ_VAVLE=0;
- CTHL_ZhuangLiaoStep = 6;
- if(CTHL_PARAM_LTJJ_MODE)
- {
- CTHL_ZhuangLiaoDelay = dwTickCount + CTHL_PARAM_MaGou_DELAY+30;
- }
- else
- {
- CTHL_ZhuangLiaoDelay = dwTickCount + CTHL_PARAM_MaGou_DELAY;
- }
- }
- else if(dwTickCount >= CTHL_ZhuangLiaoDelay) //接拉头(接料)到们信号异常
- {
- CTHL_SetAlarmCode(CTHL_JLiao_Limit_ALARM,bRunning);
- }
- break;
- case 6:
- if(dwTickCount >= CTHL_ZhuangLiaoDelay) //延时码勾
- {
- if(!CTHL_PARAM_LTJJ_MODE || CTHL_LTJJ_Origin_IN)
- {
- CTHL_MGuo_VAVLE = 1; //码勾输出
- CTHL_ZhuangLiaoStep = 7;
- CTHL_ZhuangLiaoDelay = dwTickCount + CTHL_PARAM_HSLiaoOff_DELAY;
- bTuiLaTouOkFlg = 0; //认为拉头没法带出
- }
- else if(dwTickCount >= CTHL_ZhuangLiaoDelay+3000)
- {
- CTHL_SetAlarmCode(CTHL_XMKH_Origin_ALARM,bRunning);
- }
- }
- break;
- case 7:
- if(dwTickCount >= CTHL_ZhuangLiaoDelay)
- {
- CTHL_HSLiao_VAVLE = 0;
- CTHL_ZhuangLiaoStep = 8;
- CTHL_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
- }
- break;
- case 8:
- if(!CTHL_HSLiao_Limit_IN) //
- {
- CTHL_ZhuangLiaoStep = 9;
- CTHL_TLiaoStep = 1; //推拉头
- CTHL_ZhuangLiaoDelay = dwTickCount + CTHL_PARAM_CheckLT_DELAY; //也是给下模能上升的时间
- }
- else if (CTHL_LTou_Check) //时间内信号这说明没有拉头
- {
- //重送3次
- CTHL_TryCnt++;
- CTHL_JLTou_VAVLE = 0; //接拉头关
- CTHL_MGuo_VAVLE = 0; //码勾打开
- if(CTHL_TryCnt >= CTHL_PARAM_SLT_NUMBER)
- {
- CTHL_TryCnt = 0;
- bZhuangLiaoOkFlg = 0;
- CTHL_ZhuangLiaoStep = 0;
- CTHL_SetAlarmCode(CTHL_ZLT_ALARM,bRunning);
- cWULATOUCnt=1;
- }
- else
- {
- CTHL_ZhuangLiaoStep = 20; //重新送3次
- CTHL_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
- }
- }
- else if(dwTickCount >= CTHL_ZhuangLiaoDelay)
- {
- CTHL_SetAlarmCode(CTHL_HSLiao_Limit_ALARM,bRunning);
- if(bRunning)
- {
- CTHL_ZhuangLiaoStep = 0 ;
- }
- }
- break;
- case 9:
- if(CTHL_LTou_Check) //时间内信号这说明没有拉头
- {
- CTHL_TryCnt++;
- CTHL_JLTou_VAVLE = 0; //接拉头关
- CTHL_MGuo_VAVLE = 0; //码勾打开
- if(CTHL_TryCnt >= 3)
- {
- CTHL_TryCnt=0;
- bZhuangLiaoOkFlg = 0;
- CTHL_ZhuangLiaoStep = 0;
- CTHL_SetAlarmCode(CTHL_ZLT_ALARM,bRunning);
- cWULATOUCnt=1;
- }
- else
- {
- CTHL_ZhuangLiaoStep = 20; //重新送3次
- CTHL_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
- }
- }
- else if(dwTickCount >= CTHL_ZhuangLiaoDelay)
- {
- bZhuangLiaoOkFlg = 1;
- CTHL_ZhuangLiaoStep = 0;
- }
- break;
- //装拉头不成攻重新送拉头
- case 20:
- if(CTHL_HSLiao_Origin_IN)
- {
- CTHL_JLTou_VAVLE = 0; //接拉头关
- CTHL_MGuo_VAVLE = 0; //码勾打开
- CTHL_ZhuangLiaoStep = 1;
- CTHL_ZhuangLiaoDelay = dwTickCount + 10;
- }
- else if(dwTickCount >= CTHL_ZhuangLiaoDelay)
- {
- CTHL_SetAlarmCode(CTHL_HSLiao_Origin_ALARM,bRunning);
- }
- break;
- }
- }
- void CTHL_TLiao_Step(void)
- {
- switch(CTHL_TLiaoStep)
- {
- case 1:
- if(bTuiLaTouOkFlg)
- {
- CTHL_TLiaoStep = 0;
- }
- else
- {
- CTHL_TLiao_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- CTHL_TLiaoStep = 2;
- }
- break;
- case 2: //横送料在原位
- if(CTHL_HSLiao_Origin_IN && !CTHL_HSLiao_Limit_IN && !CTHL_HSLiao_VAVLE)
- {
- CTHL_TLiao_VAVLE = 1; //推料(推拉头)输出
- CTHL_TLiao_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- CTHL_TLiaoStep = 3;
- }
- else if(dwTickCount >= CTHL_TLiao_Delay)
- CTHL_SetAlarmCode(CTHL_HSLiao_Origin_ALARM,1);
- break;
- case 3: //推拉头到位
- if(CTHL_TLiao_Limit_IN)
- {
- CTHL_TLiao_Delay = dwTickCount + CTHL_PARAM_TLiao_BACKDELAY;
- CTHL_TLiaoStep = 4;
- }
- else if(dwTickCount >= CTHL_TLiao_Delay)
- CTHL_SetAlarmCode(CTHL_TLiao_Limit_ALARM,1);
- break;
- case 4:
- if(dwTickCount >= CTHL_TLiao_Delay)
- {
- CTHL_TLiao_VAVLE = 0;
- CTHL_TLiao_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- CTHL_TLiaoStep = 5;
- }
- break;
- case 5:
- if(!CTHL_TLiao_Limit_IN)
- {
- CTHL_TLiaoStep = 0;
- CTHL_TLiao_Delay = dwTickCount;
- bTuiLaTouOkFlg = 1;
- }
- else if(dwTickCount >= CTHL_TLiao_Delay)
- CTHL_SetAlarmCode(CTHL_TLiao_Limit_ALARM,0);
- break;
- }
-
- }
- //振动盘控制
- void CTHL_ZhenDongAction(void)
- {
-
- #if 0
- if((CTHL_bDLP || bRunning) && CTHL_ZhenDongPian_OUT && CTHL_PARAM_DALIAOPIAN)
- {
- if(CT_DLP_Time >= dwTickCount)
- {
- CT_ZDP_Delay = dwTickCount + CT_PARAM_DLP_TIME + 40;
- CT_DaLaPian_VAVLE = ~CT_DaLaPian_VAVLE;
- }
- }
- else
- CT_DaLaPian_VAVLE = 0;
- #endif
-
- #if 1
-
- // if(bRunning)
- // {
- /*
- switch(CTHL_PARAM_ZDP_AUTO)
- {
- case 0:
- if(CTHL_ZhenDongPian_OUT == 0)
- {
- if(!CTHL_ZDP_IN)
- {
- if(dwTickCount >= CTHL_ZDP_Delay)
- {
- CTHL_ZhenDongPian_OUT = 1;
- CTHL_ZDP_Delay = dwTickCount + CTHL_PARAM_ZDP_Stop_TIME;//CTHL_PARAM_ZDP_Stop_TIME + 50;
- }
- }
- else
- {
- CTHL_ZDP_Delay = dwTickCount + CTHL_PARAM_ZDP_Start_TIME;//CTHL_PARAM_ZDP_Start_TIME;
- }
- }
- else
- {
- if(CTHL_ZDP_IN)
- {
- if(dwTickCount >= CTHL_ZDP_Delay)
- {
- CTHL_ZhenDongPian_OUT = 0;
- CTHL_ZDP_Delay = dwTickCount + CTHL_PARAM_ZDP_Start_TIME;//CTHL_PARAM_ZDP_Start_TIME
- }
- }
- else
- CTHL_ZDP_Delay = dwTickCount + CTHL_PARAM_ZDP_Stop_TIME;//CTHL_PARAM_ZDP_Stop_TIME+ 50;
- }
- break;
- case 1:
- CTHL_ZhenDongPian_OUT=0;
- CTHL_ZDP_Delay = dwTickCount;
- break;
- case 2:
- CTHL_ZhenDongPian_OUT=1;
- CTHL_ZDP_Delay = dwTickCount;
- break;
- }
-
-
- }
- else
- CTHL_DaLaPian_OUT = 0; */
-
- if(CTHL_ZDP_IN)
- {
- if(CTHL_PARAM_LaPian_EN)
- {
- if(dwTickCount >= CTHL_DLP_Delay)
- {
-
- CTHL_DaLaPian_OUT = !CTHL_DaLaPian_OUT;
-
- if(CTHL_DaLaPian_OUT)
- CTHL_DLP_Delay = dwTickCount + CTHL_PARAM_DaLaPian;
- else
- CTHL_DLP_Delay = dwTickCount + CTHL_PARAM_DaLaPian+50;
- }
- }
- }
- else
- CTHL_DaLaPian_OUT = 0;
- #endif
- }
- void CTHL_bFKCXTDDWStep(void)
- {
- switch(CTHL_bFKCXTDDW_Step)
- {
- case 1:
- CTHL_FKJD_VAVLE = 1; //方块夹带气缸输出
- CTHL_XKTD_VAVLE = 1; //斜口推带气缸输出
- CTHL_FKGD_VAVLE = 0; //方块固定关
- CTHL_bFKCXTDDW_Step = 2;
-
- break;
- case 2:
- if(!CTHL_XKTD_Origin_IN) //斜口推带原位离开
- {
- CTHL_bFKCXTDDW_Step = 3;
- CTHL_bFKCXTDDW_Delay = dwTickCount + 20;
- }
- break;
- case 3://斜口定位
- if(dwTickCount >= CTHL_bFKCXTDDW_Delay)
- {
- CTHL_XKDW_VAVLE = 1;
- CTHL_bFKCXTDDW_Step = 4;
- // CTHL_bFKCXTDDW_Delay = dwTickCount + CTHL_PARAM_XKDW_TD_DELAY;
- }
- break;
- case 4:
- if(dwTickCount >= CTHL_bFKCXTDDW_Delay)
- {
- AxisContinueMoveAcc(X_AXIS,1200,DIR_P,800,600,10,10);//拖带电机
- CTHL_bFKCXTDDW_Step = 5;
- CTHL_XSavePosBuff = dwXRealPos;
- SetPos(X_AXIS, 0); //启动位置设为0点
- dwXRealPos = 0;
- }
- break;
- case 5:
- if(CTHL_XKSC_Limit_IN) //方块到位
- {
- AxisEgmStop(X_AXIS);
- CTHL_QDXK_VAVLE=1;
- CTHL_bFKCXTDDW_Step = 6;
- CTHL_XKTD_VAVLE = 0; //斜口推带气缸关闭
- CTHL_bFKCXTDDW_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
-
- }
- else if(dwXRealPos >= (CTHL_XSavePosBuff + 800))
- {
- CTHL_SetAlarmCode(CTHL_FKCXDW_ALARM,bRunning);//方块插销定位异常警告
-
- }
- break;
- case 6:
- if(CTHL_PARAM_TDFZ_LENTH && !X_DRV) //拖带电机反转
- AxisMovePosAccDec(X_AXIS,8000,-CTHL_PARAM_DXKFZ_LENTH,800,600,6,6,0);
- if(CTHL_PARAM_CXMODE)
- CTHL_CXVAVLE = 1;
- CTHL_bFKCXTDDW_Step = 0;
- break;
-
- }
- }
- //插销穿入动作
- void CTHL_bCXCRStep(void)
- {
- switch(CTHL_bCXCR_Step)
- {
- case 11:
- CTHL_XKTD_VAVLE = 1; //斜口推带气缸输出
- CTHL_FKGD_VAVLE = 0; //方块固定关
- CTHL_CXSCDW_VAVLE=1;
- CTHL_bCXCR_Step = 12;
-
- break;
- case 12:
- if(!CTHL_XKTD_Origin_IN) //斜口推带原位离开
- {
- CTHL_bCXCR_Step = 13;
- // CTHL_CXQJD_VAVLE = 1; //插销前夹带
- CTHL_bCXCR_Delay = dwTickCount + 20;
- }
- break;
- case 13:
- if((CTHL_CL_MotorStep == 0) && (CTHL_SF_Origin_IN) && (dwTickCount >= CTHL_bCXCR_Delay)) //插销前夹带回到原位
- {
- CTHL_bCXCR_Step = 14;
- // CTHL_FKGD_VAVLE = 1; //方块固定开
- CTHL_CXQJD_VAVLE = 1; //插销前夹带
- CTHL_bCXCR_Delay = dwTickCount + CTHL_PARAM_XCQJD_XCDW_DELAY;
- }
- break;
- case 14:
- if(dwTickCount >= CTHL_bCXCR_Delay)
- {
- CTHL_bCXCR_Step = 15;
- CTHL_FKGD_VAVLE = 1; //方块固定
- //Y轴启动插销
- CTHL_CL_MotorStep = 20; //插销定位
- }
- break;
- case 15:
- if(CTHL_CL_MotorStep == 0) //插销定位完成
- {
- CTHL_bCXCR_Step = 16;
- CTHL_CXDWZ_VAVLE = 1; //插销定位针(到位)电磁阀
- CTHL_bCXCR_Delay = dwTickCount + 10; //延时插销下移
- }
- break;
- case 16:
- if(dwTickCount >= CTHL_bCXCR_Delay)
- {
- CTHL_bCXCR_Step = 17;
- if(CTHL_PARAM_CXMODE)
- CTHL_CXVAVLE = 0;
- else
- CTHL_CXVAVLE = 1; //Y06 插销下移电磁阀
- if(CTHL_PARAM_NLSL_MODE == 0)
- CTHL_bCXCR_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME; //插销下移异常时间
- else
- CTHL_bCXCR_Delay = dwTickCount + 80; //插销下移异常时间
- }
- break;
- case 17:
- if((CTHL_CXLimit_IN) || CTHL_PARAM_NLSL_MODE)
- {
-
- if(CTHL_CXLimit_IN || (dwTickCount >= CTHL_bCXCR_Delay))
- {
- CTHL_bCXCR_Step = 18;
- if( cXcxcrCnt==0 && !X_DRV) //拖带电机反转
- {
- AxisMovePosAccDec(X_AXIS,10000,-CTHL_PARAM_TDFZ_LENTH,800,600,6,6,0);
- }
- CTHL_CXQJD_VAVLE = 0; //插销前夹带电磁阀
- CTHL_CXSCDW_VAVLE = 0; //Y21 插销上止定位关
- CTHL_CXHJD_VAVLE = 1; //Y14 插销后夹带输出
- CTHL_bCXCR_Delay = dwTickCount + CTHL_PARAM_SCDWOff_CXDW_DELAY;
-
- }
- }
- else if(dwTickCount >= CTHL_bCXCR_Delay)
- {
- CTHL_SetAlarmCode(CTHL_CXLimit_ALARM,bRunning);//插销下移异常
-
- }
- break;
- case 18:
- // if(START_IN_UP)
- {
- if(dwTickCount >= CTHL_bCXCR_Delay)
- {
- CTHL_bCXCR_Step = 19;
-
- CTHL_CXHDW_VAVLE = 1; //插销后定位(插销穿入)
- CTHL_bCXCR_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME +1000; //插销穿入到位异常时间
- CTHL_CL_MotorStep = 50; //合链电机回原点
- }
- }
- break;
- case 19:
- if( cXcxcrCnt > 1)
- {
- CTHL_SetAlarmCode(CTHL_CX_Limit_ALARM,bRunning); //插销穿入到位异常
- }
-
- if( CTHL_CX_Limit_IN && cXcxcrCnt<2 )
- {
- cXcxcrCnt=0;
- bZhuangLiaoOkFlg = 0;
- CTHL_bCXCR_Step = 0;
- CTHL_CXDWZ_VAVLE = 0; //插销定位针(到位)电磁阀
-
- }
- else if (dwTickCount >= CTHL_bCXCR_Delay)
- {
- cXcxcrCnt++;
-
- CTHL_CXHJD_VAVLE=0;
- CTHL_CXHDW_VAVLE=0;
- CTHL_CXDWZ_VAVLE = 0;
- if(CTHL_PARAM_CXMODE)
- CTHL_CXVAVLE = 0;
- else
- CTHL_CXVAVLE = 1; //Y06 插销下移电磁阀
- CTHL_bCXCR_Step = 11;
- }
-
- break;
- }
- }
- void CTHL_bCLFirstStep(void)
- {
- switch(CTHL_bCLFirst_Step)
- {
- case 19:
- CTHL_JLTou_VAVLE = 0; //接拉头
- bZhuangLiaoOkFlg = 0;
- CTHL_bCLFirst_Step = 20;
- CTHL_CXDWZ_VAVLE = 0; //插销定位针(到位)电磁阀
- CTHL_CXVAVLE = 0; //Y06 插销下移电磁阀关
- CTHL_bCLFirst_Delay = dwTickCount + CTHL_PARAM_First_CL_DELAY;//延时一次穿入
- break;
- case 20:
- if(dwTickCount >= CTHL_bCLFirst_Delay)
- {
- CTHL_bCLFirst_Step = 21;
- CTHL_First_CT_VAVLE = 1; //一次穿入电磁阀输出
- CTHL_bCLFirst_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- }
- break;
- case 21:
- if(!CTHL_First_CT_Origin_IN) //原点离开后才开始时间
- {
- CTHL_bCLFirst_Step = 22;
- CTHL_bCLFirst_Delay = dwTickCount + CTHL_PARAM_First_CL_Timer; //一次穿入时间
- }
- else if(dwTickCount >= CTHL_bCLFirst_Delay)
- {
- CTHL_SetAlarmCode(CTHL_YCCRYWYC_ALARM,bRunning); //一次穿入原位异常
- }
- break;
- case 22:
- if(dwTickCount >= CTHL_bCLFirst_Delay)
- {
- CTHL_bCLFirst_Step = 23;
- CTHL_MGuo_VAVLE = 0; //码勾退
- CTHL_bCLFirst_Delay = dwTickCount + CTHL_PARAM_MGOff_XiaMo_DELAY;
- CTHL_FKGD_VAVLE = 0; //方块固定退
- CTHL_CXHJD_VAVLE = 0; //Y14 插销后夹带打开
- CTHL_CXVAVLE = 0; //Y06 插销下移电磁阀关
- }
- break;
- case 23:
- if(dwTickCount >= CTHL_bCLFirst_Delay)
- {
- CTHL_bCLFirst_Step = 24;
- CTHL_CTXM_VAVLE = 0; //穿头下模下降
- CTHL_CXHDW_VAVLE = 0; //插销后定位(插销穿入)关闭
- CTHL_bCLFirst_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- }
- break;
- case 24:
- if(!CTHL_CTM_Limit_IN)
- {
- CTHL_bCLFirst_Step= 25;
- CTHL_bCLFirst_Delay = dwTickCount + 25; //一次穿入延时返回
- }
- else if(dwTickCount >= CTHL_bCLFirst_Delay)
- {
- CTHL_SetAlarmCode(CTHL_CTM_Origin_ALARM,bRunning); //穿头下模下降异常
- }
- break;
- case 25:
- if(dwTickCount >= CTHL_bCLFirst_Delay)
- {
-
- CTHL_bCLFirst_Step= 0;
- CTHL_First_CT_VAVLE = 0; //一次穿入电磁阀关
- CTHL_CXHDW_VAVLE = 0; //插销后定位(插销穿入)关闭
-
-
- //退下出错警告
- CTHL_AutoDelay1 = dwTickCount + CTHL_VAVLE_ERROR_TIME;
- CTHL_AutoStep1 = 1;
- bTuiLaTouOkFlg = 1;
- }
- break;
- }
- }
- //手动动作
- void CTHL_ManualAction(void)
- {
- if(bRunning && user_datas[100]==0) // 运行灯输出
- {
- CTHL_Run_State=1;
- CTHL_Stop_State=0;
- }
- else if(!bRunning && user_datas[100]==0)
- {
- CTHL_Run_State=0;
- CTHL_Stop_State=0;
- }
- if(user_datas[100] != 0)
- {
- CTHL_Run_State=0;
- CTHL_Stop_State=1;
- }
-
- if( (GetAlarm(Y_AXIS)==1) ) // 伺服报警
- {
- // cCHULIANBAOJIN=1;
- // CTHL_SetAlarmCode(CTHL_SF_ALR_ALARM,0);
- }
-
- if(dwTickCount >= CTHL_bSFBBAOJIN_Delay)
- {
-
- SetClr(Y_AXIS,MOTOR_ALARM);
- SetClr(X_AXIS,MOTOR_ALARM);
- }
-
- if(bRunning == 0)
- {
- if(bClearTotal) //切断计数清零
- {
- bClearTotal = 0;
- ClrcToTal(QDCT_TOTAL_ADDR);
- }
- if(CTHL_bTLiao ) //手动推料(推拉头)
- {
- CTHL_bTLiao = 0;
- if(CTHL_TLiao_VAVLE)
- CTHL_TLiao_VAVLE = 0;//CTHL_TLiao_VAVLE;
- else if(!CTHL_HSLiao_VAVLE && CTHL_HSLiao_Origin_IN)
- {
- CTHL_TLiao_VAVLE = 1;
- }
- else//条件警告
- {
- CTHL_SetAlarmCode(CTHL_HENSONGLIAO_ALARM,0); // 横送料不能输出
- }
-
- }
-
- if(CTHL_bHSL) //手动横送料
- {
- CTHL_bHSL= 0;
- if(!CTHL_First_CT_VAVLE)
- {
- if(CTHL_HSLiao_VAVLE)
- {
- CTHL_HSLiao_VAVLE = 0;//~CTHL_HSLiao_VAVLE;
- }
- else if(!CTHL_TLiao_VAVLE && !CTHL_TLiao_Limit_IN && CTHL_CTM_Origin_IN && !CTHL_JLiao_Limit_IN &&
- !CTHL_JLTou_VAVLE && !CTHL_CTXM_VAVLE && !CTHL_CXDWZ_VAVLE && (!CTHL_bMG || (CTHL_bMG && CTHL_LTou_Check)))
- {
- if(CTHL_PARAM_LTJJ_MODE)
- {
- CTHL_LTJJ_VAVLE=1;
- }
- else
- {
- CTHL_LTJJ_VAVLE=0;
- }
-
- CTHL_HSLiao_VAVLE = 1;
- }
- else //条件警告 最后一个括号条件为已经有拉头
- {
- CTHL_SetAlarmCode(CTHL_YCCT_ALARM,0);
- }
- }
- }
- if(CTHL_bJLT) //接拉头
- {
- CTHL_bJLT = 0;
- if(CTHL_JLTou_VAVLE)
- CTHL_JLTou_VAVLE = 0;
- else if(!CTHL_First_CT_VAVLE && !CTHL_CTXM_VAVLE && CTHL_CTM_Origin_IN && CTHL_First_CT_Origin_IN)
- {
- CTHL_MGuo_VAVLE = 0;
- CTHL_JLTou_VAVLE = 1;
- }
- else//条件警告
- {
- CTHL_SetAlarmCode(CTHL_YCXM_Origin_ALARM,0);
- }
- }
- if(CTHL_bMG) //码勾
- {
- CTHL_bMG = 0;
- CTHL_MGuo_VAVLE = !CTHL_MGuo_VAVLE;
- }
- if(CTHL_bLTJJ) //码勾
- {
- CTHL_bLTJJ = 0;
- CTHL_LTJJ_VAVLE = !CTHL_LTJJ_VAVLE;
- }
- if(CTHL_bFKJD) //方块夹带
- {
- CTHL_bFKJD = 0;
- CTHL_FKJD_VAVLE = !CTHL_FKJD_VAVLE;
- }
- if(CTHL_bXKTD) //斜口推带
- {
- CTHL_bXKTD = 0;
- if(CTHL_XKTD_VAVLE)
- CTHL_XKTD_VAVLE = 0;
- else if(!CTHL_DXK_VAVLE && (!CTHL_XKSC_Limit_IN || !CTHL_CTXM_VAVLE|| CTHL_PARAM_NLSL_MODE))
- CTHL_XKTD_VAVLE = 1;
- else//条件警告
- {
- CTHL_SetAlarmCode(CTHL_DXKCTXM_Origin_ALARM,0);
- }
- }
- if(CTHL_bXKDW) //斜口定位
- {
- CTHL_bXKDW = 0;
- CTHL_XKDW_VAVLE = ~CTHL_XKDW_VAVLE;
- }
- if(CTHL_bCTXM) //穿头下模
- {
- CTHL_bCTXM = 0;
- if(CTHL_CTXM_VAVLE)
- {
- if(CTHL_PARAM_LTJJ_MODE)
- {
- CTHL_LTJJ_VAVLE=1;
- }
- else
- {
- CTHL_LTJJ_VAVLE=0;
- }
- CTHL_CTXM_VAVLE = 0;
- CTHL_MGuo_VAVLE = 0;
- CTHL_JLTou_VAVLE = 0;
- CTHL_CXVAVLE=0;
- }
- else if(!CTHL_HSLiao_VAVLE && CTHL_HSLiao_Origin_IN && (!CTHL_XKSC_Limit_IN || !CTHL_XKTD_VAVLE))
- {
- if(CTHL_PARAM_CXMODE)
- CTHL_CXVAVLE = 1;
-
-
- CTHL_MGuo_VAVLE = 1;
- CTHL_CTXM_VAVLE = 1;
- CTHL_LTJJ_VAVLE=0;
-
-
-
-
- }
- }
- if(CTHL_bQianDXK) //前顶斜口
- {
- CTHL_bQianDXK = 0;
- if(CTHL_QDXK_VAVLE)
- CTHL_QDXK_VAVLE = 0;
- else if(!CTHL_XKTD_VAVLE)
- CTHL_QDXK_VAVLE = 1;
- else //条件警告
- {
- CTHL_SetAlarmCode(CTHL_XKTD_ALARM,0);
- }
- }
-
- if(CTHL_bDXK) //顶斜口
- {
- CTHL_bDXK = 0;
- if(!CTHL_PARAM_NLSL_MODE)
- {
- if(CTHL_DXK_VAVLE)
- CTHL_DXK_VAVLE = 0;
- else if(!CTHL_XKTD_VAVLE)
- {
- if(!CTHL_PARAM_NLSL_MODE)
- CTHL_DXK_VAVLE = 1;
- }
- else //条件警告
- {
- CTHL_SetAlarmCode(CTHL_XKTD_ALARM,0);
- }
- }
- else
- {
- if(CTHL_XKTD_VAVLE)
- CTHL_XKTD_VAVLE = 0;
- else if(!CTHL_DXK_VAVLE )
- {
- if(!CTHL_XKSC_Limit_IN || !CTHL_CTXM_VAVLE || CTHL_PARAM_NLSL_MODE)
- CTHL_XKTD_VAVLE = 1;
- else
- {
- CTHL_SetAlarmCode(CTHL_YCXM_Origin_ALARM,0);
- }
- }
- else//条件警告
- {
- CTHL_SetAlarmCode(CTHL_DXKCTXM_Origin_ALARM,0);
- }
-
- }
- }
-
-
- if(CTHL_bFKGD) //方块固定
- {
- CTHL_bFKGD = 0;
- CTHL_FKGD_VAVLE = ~CTHL_FKGD_VAVLE;
- }
- if(CTHL_bCXQJD) //插销前夹带
- {
- CTHL_bCXQJD = 0;
- CTHL_CXQJD_VAVLE = ~CTHL_CXQJD_VAVLE;
- }
- if(CTHL_bCXSY) //插销下移电磁阀
- {
- CTHL_bCXSY = 0;
- CTHL_CXVAVLE = !CTHL_CXVAVLE;
- }
- if(CTHL_bCXDWZ) //Y14 插销定位针电磁阀
- {
- CTHL_bCXDWZ = 0;
- if(CTHL_CXDWZ_VAVLE)
- CTHL_CXDWZ_VAVLE = 0;
- else if(CTHL_HSLiao_Origin_IN)
- {
- CTHL_CXDWZ_VAVLE = 1;
- }
- else //条件警告
- {
- CTHL_SetAlarmCode(CTHL_HENSONGLIAO_ALARM,0);
- }
-
- }
- if(CTHL_bCXHJD) //Y15 插销后夹带电磁阀
- {
- CTHL_bCXHJD = 0;
- CTHL_CXHJD_VAVLE =~CTHL_CXHJD_VAVLE;
- }
- if(CTHL_bCXHDW) //Y16 插销后定位电磁阀
- {
- CTHL_bCXHDW = 0;
- if(CTHL_CXHDW_VAVLE)
- CTHL_CXHDW_VAVLE = 0;
- else if(!CTHL_CXQJD_VAVLE)
- CTHL_CXHDW_VAVLE = 1;
- else//条件警告
- {
- CTHL_SetAlarmCode(CTHL_CXQJD_ALARM,0);
- }
- }
- if(CTHL_bFirst_CT) //Y20 一次穿头电磁阀
- {
- CTHL_bFirst_CT = 0;
- CTHL_First_CT_VAVLE = ~CTHL_First_CT_VAVLE;
-
- }
- if(CTHL_bHLJJ) //Y21 合链夹具电磁阀
- {
- CTHL_bHLJJ = 0;
- CTHL_HLJJ_VAVLE = ~CTHL_HLJJ_VAVLE;
- }
- if(CTHL_bCXSCDW) //Y23 插销上止定位电磁阀
- {
- CTHL_bCXSCDW = 0;
- CTHL_CXSCDW_VAVLE = ~CTHL_CXSCDW_VAVLE;
- }
- //自动装料
- if(CTHL_bAutoZhuangLiao)
- {
- CTHL_bAutoZhuangLiao = 0;
- if(CTHL_ZhuangLiaoStep == 0)
- {
-
-
- bTuiLaTouOkFlg = 1;
- bZhuangLiaoOkFlg = 0;
- CTHL_ZhuangLiaoStep = 1;
- CTHL_MGuo_VAVLE = 1; //判断是否已经有料
- CTHL_LTJJ_VAVLE=0;
- CTHL_ZhuangLiaoDelay = dwTickCount + 150;
-
-
- }
- }
- //测试电机
- if(CTHL_bCLMotor_N)
- {
- SetEn(Y_AXIS, MOTOR_EN);
- if(!CTHL_SF_Origin_IN)
- {
- if(!Y_DRV)
- // Y轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(Y_AXIS,2000,DIR_N,1000,1000,15,15);
- }
- else
- {
- CTHL_bCLMotor_N = 0;
- }
-
- }
-
- if(CTHL_bCLMotor_P) //后退限位已经取消
- {
- SetEn(Y_AXIS, MOTOR_EN);
- if(!Y_DRV)
- // Y轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(Y_AXIS,2000,DIR_P,1000,1000,15,15);
- }
-
- if(!CTHL_bCLMotor_P && !CTHL_bCLMotor_N && (CTHL_CL_MotorStep == 0))
- {
- AxisEgmStop(Y_AXIS);//AxisDecStop(Y_AXIS);
- }
-
- if(CTHL_bTDMotor_P) //后退限位已经取消
- {
- SetEn(X_AXIS, MOTOR_EN);
- if(!X_DRV)
- // Y轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,2000,DIR_P,1000,1000,15,15);
- }
- if(CTHL_bTDMotor_N) //后退限位已经取消
- {
- SetEn(X_AXIS, MOTOR_EN);
- if(!X_DRV)
- // Y轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,2000,DIR_N,1000,1000,15,15);
- }
-
-
- if(!CTHL_bTDMotor_P && !CTHL_bTDMotor_N && (CTHL_TD_MotorStep == 0))
- {
- AxisEgmStop(X_AXIS);//AxisDecStop(Y_AXIS);
- }
-
- //合链电机返回原点
- if(CTHL_bCLMotor_O)
- {
- CTHL_bCLMotor_O = 0;
- if(CTHL_CL_MotorStep == 0)
- CTHL_CL_MotorStep = 40;
- }
- //拖带方块定位 ,因这步为前拖带定位, 很多电磁阀要关掉
- if(CTHL_bFKTDDW)
- {
- CTHL_bFKTDDW = 0;
- if(CTHL_TD_MotorStep == 0)
- {
- CTHL_XKDW_VAVLE = 0; //斜口定位
- CTHL_CXQJD_VAVLE = 0; //插销前夹带
- if(!CTHL_PARAM_CXMODE)
- CTHL_CXVAVLE = 0; //插销下移
-
- CTHL_CXHJD_VAVLE = 0; //插销后夹带
- CTHL_CXHDW_VAVLE = 0; //插销后定位
- CTHL_CXDWZ_VAVLE = 0; //插销定位针
- CTHL_bHLJJ = 0; //合链夹具
- CTHL_FKJD_VAVLE = 0; //方块夹带
- if((GetEn(X_AXIS) == MOTOR_DISEN))
- {
- SetEn(X_AXIS, MOTOR_EN);
- CTHL_TD_MotorDelay = dwTickCount + 200;
- }
- else
- CTHL_TD_MotorDelay = dwTickCount + 50;
- CTHL_TD_MotorStep = 1;
- }
- }
- //拖带方块插销定位(斜口推带,斜口定位,顶斜口)
- if(CTHL_bFKCXTDDW)
- {
- CTHL_bFKCXTDDW = 0;
- if((CTHL_bFKCXTDDW_Step == 0) && (CTHL_CL_MotorStep == 0) &&
- !CTHL_CTXM_VAVLE)
- {
- CTHL_bFKCXTDDW_Step = 1;
- if(GetEn(X_AXIS)==MOTOR_DISEN)
- {
- SetEn(X_AXIS, MOTOR_EN);
- CTHL_bFKCXTDDW_Delay = dwTickCount + 300;
- }
-
- CTHL_CXQJD_VAVLE = 0; //插销前夹带
- CTHL_CXVAVLE = 0; //插销下移
- CTHL_CXHJD_VAVLE = 0; //插销后夹带
- CTHL_CXHDW_VAVLE = 0; //插销后定位
- CTHL_CXDWZ_VAVLE = 0; //插销定位针
- CTHL_HLJJ_VAVLE = 0; //合链夹具
- }
- }
- //插销穿入(包含电机前定位,插销下移,后夹,后定位)
- if(CTHL_bCXCR)
- {
- CTHL_bCXCR = 0;
- //拉头模在上面到们并且码勾输出,判断有拉头
- if(CTHL_CTXM_VAVLE && CTHL_MGuo_VAVLE && !CTHL_CXQJD_VAVLE &&
- CTHL_CTM_Limit_IN && !CTHL_LTou_Check)
- {
- if(CTHL_CL_MotorStep == 0)
- {
- CTHL_bCXCR_Step = 11;
- SetEn(Y_AXIS, MOTOR_EN);
- if(!CTHL_SF_Origin_IN)
- CTHL_CL_MotorStep = 40;
- }
- }
- else //警告不能自动穿插销
- {
- CTHL_SetAlarmCode(CTHL_WFZIDONGCX_ALARM,0);
- }
- }
- //电机合链动作
- if(CTHL_bMotorHL)
- {
- CTHL_bMotorHL = 0;
- if(CTHL_SF_Origin_IN)
- {
- if((CTHL_CL_MotorStep == 0) && !CTHL_CTXM_VAVLE && (!CTHL_CTM_Limit_IN))
- {
- bCL_OK_FLG = 0;
- CTHL_HLJJ_VAVLE = 1; //Y20 合链夹具电磁阀输出后,电机穿入
- CTHL_CL_MotorStep = 1;
- CTHL_CL_MotorDelay = dwTickCount + CTHL_PARAM_HLJJ_CL_DELAY + 130;
- if((GetEn(Y_AXIS) == MOTOR_DISEN))
- {
- SetEn(Y_AXIS, MOTOR_EN);
- CTHL_CL_MotorDelay = dwTickCount + 250;
- }
- }
- }
- else
- {
- CTHL_bCLMotor_O =1;
-
- }
- }
- //一次穿链动作
- if(CTHL_bCL_First)
- {
- CTHL_bCL_First = 0;
- //拉头模在上面到们并且码勾输出,判断有拉头
- if(CTHL_CTXM_VAVLE && CTHL_MGuo_VAVLE && !CTHL_CXQJD_VAVLE &&
- CTHL_CTM_Limit_IN && !CTHL_LTou_Check && (CTHL_CL_MotorStep == 0))
- {
- CTHL_bCLFirst_Step = 19;
- CTHL_CXHJD_VAVLE = 1; //插销后夹带
- CTHL_CXDWZ_VAVLE = 0; //插销定位针(到位)电磁阀
- CTHL_CXQJD_VAVLE = 0; //插销前夹带
- }
- }
- }
- }
- #endif
|