FYChuantou_HeLian.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816
  1. #include "global.h"
  2. #if FIE_YUE_MACHINE == 1
  3. void CTHL_SetAlarmCode(unsigned short alarm_code,unsigned short cStopFlag);
  4. void CTHL_ManualAction(void);
  5. void CTHL_AutoStepAction(void);
  6. void CTHL_TableAction(void);
  7. void CTHL_TD_Motor(void);
  8. void CTHL_CL_Motor(void);
  9. void CTHL_CheckStart(void);
  10. void CTHL_TLiao_Step(void); //推料(推拉头)
  11. void CTHL_AlarmProtect(void);
  12. void CTHL_ZLT_Step(void);
  13. void CTHL_ZhenDongAction(void);
  14. void CTHL_bFKCXTDDWStep(void);
  15. void CTHL_bCXCRStep(void);
  16. void CTHL_bCLFirstStep(void);
  17. void ExtiAcitionX02(void)
  18. {
  19. if(bCheckEN_FLG)
  20. {
  21. bCheckEN_FLG = 0;
  22. CTHL_CheckInX02PosBuff = GetPos(X_AXIS);
  23. }
  24. }
  25. //故障报警
  26. void CTHL_SetAlarmCode(unsigned short alarm_code,unsigned short cStopFlag)
  27. {
  28. SetAlarmCode(CTHL_ALARM_ADDR,alarm_code);
  29. // bAlarmStop = 0;
  30. // if(cStopFlag)
  31. if(!cWULATOUCnt && !cXiaoChaCNT && !cCHULIANBAOJIN)
  32. {
  33. bAlarmStop = 1;
  34. }
  35. else
  36. {
  37. cWULATOUCnt=0;
  38. }
  39. }
  40. //初始化动作
  41. void CTHL_InitAction(void)
  42. {
  43. float buff_pulse,buff_dist;
  44. buff_pulse = CTHL_PARAM_CYCLE_PULSE;
  45. buff_dist = CTHL_PARAM_CYCLE_LENGTH;
  46. XGearRatio = buff_pulse/buff_dist;
  47. buff_pulse = 2000;//CTHL_PARAM_CYCLE_PULSE;
  48. buff_dist = 750;//CTHL_PARAM_CYCLE_LENGTH;
  49. YGearRatio = buff_pulse/buff_dist;
  50. bYFirstDingWeiFlg = 1;
  51. user_datas[121] = 0;
  52. user_datas[122] = 0;
  53. user_datas[123] = 0;
  54. if(!CTHL_PARAM_MATOR_MODE)
  55. SetEnReverse(X_AXIS, 1);
  56. else
  57. SetEnReverse(X_AXIS, 0);
  58. SetEnReverse(Y_AXIS, 1);
  59. SetEnReverse(Z_AXIS, 1);
  60. SetDirReverse(X_AXIS, 0);
  61. SetDirReverse(Y_AXIS, 0);
  62. SetDirReverse(Z_AXIS, 0);
  63. SetEn(X_AXIS, MOTOR_DISEN);
  64. SetEn(Y_AXIS, MOTOR_DISEN);
  65. SetEn(Z_AXIS, MOTOR_DISEN);
  66. SetAlarmCode(CTHL_ALARM_ADDR,0);
  67. // QDCT_SZ_OUT = QDCT_MOTOR_DISEN;
  68. }
  69. void CTHL_Action(void)
  70. {
  71. user_datas[121] = CTHL_LianLengSave;
  72. // user_datas[122] =axis_x->cur_speed;
  73. // user_datas[123] = CTHL_bCXCR_Step;
  74. dwXRealPos = GetPos(X_AXIS);
  75. dwYRealPos = GetPos(Y_AXIS);
  76. dwZRealPos = GetPos(Z_AXIS);
  77. user_datas[124] = dwXRealPos;
  78. user_datas[125] = dwYRealPos;
  79. user_datas[126] = GetAlarm(X_AXIS);
  80. user_datas[127] = GetAlarm(Y_AXIS);
  81. user_datas[128] = CTHL_AutoStep;
  82. CTHL_ZhenDongAction();
  83. CTHL_AlarmProtect();
  84. CTHL_CheckStart();
  85. CTHL_ZLT_Step();
  86. CTHL_TLiao_Step();
  87. CTHL_TD_Motor();
  88. CTHL_CL_Motor();
  89. CTHL_bFKCXTDDWStep();
  90. CTHL_bCXCRStep();
  91. CTHL_bCLFirstStep();
  92. CTHL_ManualAction();
  93. CTHL_AutoStepAction();
  94. }
  95. void CTHL_AlarmProtect(void)
  96. {
  97. }
  98. //自动动作
  99. void CTHL_AutoStepAction(void)
  100. {
  101. if(bRunning)
  102. {
  103. switch(CTHL_AutoStep)
  104. {
  105. case 1:
  106. if(CTHL_SF_Origin_IN)
  107. {
  108. /* CTHL_AutoStep = 10; //测试拖带定位
  109. CTHL_AutoDelay = dwTickCount + 1000;
  110. break; */
  111. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  112. {
  113. CTHL_FKJD_VAVLE = 1; //方块夹带气缸输出
  114. CTHL_XKTD_VAVLE = 1; //斜口推带气缸输出
  115. CTHL_FKGD_VAVLE = 0; //方块固定关
  116. // CTHL_XKDW_VAVLE = 1;
  117. CTHL_AutoStep = 2;
  118. CTHL_AutoDelay = dwTickCount + 50;
  119. if(CTHL_ZhuangLiaoStep == 0)
  120. {
  121. CTHL_ZhuangLiaoStep = 1;
  122. CTHL_TryCnt = 0;
  123. }
  124. }
  125. }
  126. break;
  127. case 2:
  128. if(!CTHL_XKTD_Origin_IN && (dwTickCount >= CTHL_AutoDelay)) //斜口推带原位离开
  129. {
  130. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  131. {
  132. CTHL_AutoStep = 3;
  133. CTHL_XKDW_VAVLE = 1;
  134. CTHL_AutoDelay = dwTickCount + 20;
  135. }
  136. }
  137. break;
  138. case 3://斜口定位
  139. if(dwTickCount >= CTHL_AutoDelay)
  140. {
  141. CTHL_AutoStep = 4;
  142. // CTHL_AutoDelay = dwTickCount + CTHL_PARAM_XKDW_TD_DELAY;
  143. }
  144. break;
  145. case 4:
  146. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  147. {
  148. AxisMovePosAccDecNotStop(X_AXIS,1600,150,600,1000,5,3,00);
  149. CTHL_AutoStep = 5;
  150. CTHL_XSavePosBuff = dwXRealPos;
  151. // SetPos(X_AXIS, 0); //启动位置设为0点
  152. if(cZipCnt < 1)
  153. CTHL_AutoDelay = dwTickCount +350;
  154. else
  155. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_FKJD_DELAY;
  156. }
  157. break;
  158. case 5:
  159. if(dwTickCount >= CTHL_AutoDelay)
  160. {
  161. CTHL_FKJD_VAVLE = 1; //方块夹带气缸输出
  162. }
  163. if(bCL_EN_FLG && (dwXRealPos >= 230) && CTHL_XKSC_Limit_IN)
  164. {
  165. CTHL_HLJJ_VAVLE = 1; //Y20 合链夹具电磁阀输出后,电机穿入
  166. }
  167. if(CTHL_XKSC_Limit_IN) //方块上止到位
  168. {
  169. AxisEgmStop(X_AXIS);
  170. // AxisMovePosAccDec(X_AXIS,1200,10,1200,1200,6,6,0);
  171. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  172. {
  173. CTHL_QDXK_VAVLE = 1;
  174. CTHL_FKJD_VAVLE=0;
  175. CTHL_AutoStep = 6;
  176. CTHL_bLTCHECK_Delay = dwTickCount + 20;
  177. //电机穿入可以启动
  178. bCL_OK_FLG = 1; //不用穿合链的话认为已经完成
  179. if(bCL_EN_FLG)
  180. {
  181. bCL_OK_FLG = 0;
  182. CTHL_HLJJ_VAVLE = 1; //Y20 合链夹具电磁阀输出后,电机穿入
  183. CTHL_CL_MotorStep = 1;
  184. CTHL_CL_MotorDelay = dwTickCount + CTHL_PARAM_HLJJ_CL_DELAY;
  185. CTHL_AutoDelay = dwTickCount + 50 + CTHL_PARAM_HLJJ_CL_DELAY;
  186. }
  187. else
  188. {
  189. CTHL_XKTD_VAVLE = 0; //斜口推带气缸关闭
  190. CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  191. }
  192. }
  193. }
  194. else if(dwXRealPos >= (CTHL_XSavePosBuff + 1500))
  195. {
  196. CTHL_SetAlarmCode(CTHL_FKCXDW_ALARM,bRunning); //方块插销定位异常警告
  197. }
  198. break;
  199. case 6:
  200. if(((dwYRealPos > 1000) || (!Y_DRV && dwYRealPos)) && CTHL_XKTD_VAVLE)
  201. {
  202. CTHL_XKTD_VAVLE = 0; //斜口推带气缸关闭
  203. CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  204. }
  205. if(CTHL_XKTD_Origin_IN) //斜口推带回到原位
  206. {
  207. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  208. {
  209. if(bZhuangLiaoOkFlg && (CTHL_ZhuangLiaoStep == 0))
  210. {
  211. if(dwTickCount >= CTHL_bLTCHECK_Delay)
  212. {
  213. if(!CTHL_LTou_Check)
  214. {
  215. if(CTHL_PARAM_TDFZ_LENTH && !X_DRV) //拖带电机反转
  216. {
  217. AxisMovePosAccDec(X_AXIS,8000,-CTHL_PARAM_DXKFZ_LENTH,800,600,6,6,0);
  218. if(!CTHL_PARAM_NLSL_MODE)
  219. CTHL_FKJD_VAVLE= 0; //方块夹带气缸关
  220. }
  221. if(CTHL_PARAM_CXMODE)
  222. CTHL_CXVAVLE = 1;
  223. CTHL_CTXM_VAVLE = 1; //穿头下模上升
  224. CTHL_AutoStep = 7;
  225. CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  226. }
  227. else
  228. {
  229. cWULATOUCnt=1;
  230. CTHL_SetAlarmCode(CTHL_ZLT_ALARM,bRunning); // 没有拉头
  231. }
  232. }
  233. }
  234. }
  235. }
  236. else if((dwTickCount >= CTHL_AutoDelay) && !CTHL_XKTD_VAVLE )
  237. {
  238. CTHL_SetAlarmCode(CTHL_XKTD_Origin_ALARM,bRunning); //斜口推带回到异常
  239. }
  240. break;
  241. case 7:
  242. if(!CTHL_CTM_Origin_IN)
  243. {
  244. CTHL_JLTou_VAVLE = 0; //接拉头
  245. }
  246. if(CTHL_CTM_Limit_IN)
  247. {
  248. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  249. {
  250. if(CTHL_PARAM_NLSL_MODE)
  251. {
  252. CTHL_XKTD_VAVLE=1;
  253. }
  254. CTHL_JLTou_VAVLE = 0;
  255. CTHL_AutoStep = 8;
  256. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_DXKYS_DELAY;
  257. }
  258. }
  259. else if(dwTickCount >= CTHL_AutoDelay)
  260. {
  261. CTHL_SetAlarmCode(CTHL_CTM_Limit_ALARM,bRunning); //穿头下模上升异常
  262. }
  263. break;
  264. case 8:
  265. if(!X_DRV) //延时顶斜口
  266. {
  267. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  268. {
  269. if((dwTickCount >= CTHL_AutoDelay) || (CTHL_PARAM_NLSL_MODE))
  270. {
  271. if(!CTHL_PARAM_NLSL_MODE)
  272. CTHL_DXK_VAVLE=1;
  273. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_DXK_XKDW_Off_DELAY;
  274. CTHL_AutoStep = 9;
  275. }
  276. }
  277. }
  278. break;
  279. case 9:
  280. if((dwTickCount >= CTHL_AutoDelay) && (bCL_OK_FLG)) //顶斜口延时退斜口上止定位
  281. {
  282. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  283. {
  284. // AxisMovePosAccDec(X_AXIS,2000,-150,1200,1200,3,6,0); //反转1.5CM
  285. CTHL_XKDW_VAVLE = 0; //斜口上止定位关
  286. CTHL_FKJD_VAVLE = 0; //方块夹带气缸关
  287. CTHL_AutoStep = 10;
  288. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_XK_CR_DELAY;
  289. }
  290. }
  291. break;
  292. case 10:
  293. if((dwTickCount >= CTHL_AutoDelay) && !X_DRV)
  294. {
  295. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  296. {
  297. CTHL_TD_MotorStep = 10; //启动拖带穿入
  298. CTHL_AutoStep = 11;
  299. }
  300. }
  301. break;
  302. case 11:
  303. if(CTHL_TD_MotorStep == 0) //穿入定位完成
  304. {
  305. /* //测试拖带定位
  306. CTHL_AutoStep = 1;
  307. CTHL_AutoDelay = dwTickCount + 1000;
  308. if(cZipCnt<3)
  309. cZipCnt++;
  310. break; */
  311. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  312. {
  313. CTHL_XKDW_VAVLE = 0; //斜口上止定位关
  314. CTHL_XKTD_VAVLE = 1; //斜口推带气缸输出
  315. CTHL_CXSCDW_VAVLE = 1; //Y21 插销上止定位电磁阀
  316. cXcxcrCnt = 0;
  317. if(CTHL_CL_MotorStep == 0)
  318. {
  319. CTHL_CXQJD_VAVLE = 1;
  320. }
  321. CTHL_AutoStep = 12;
  322. // CTHL_AutoDelay = dwTickCount + 50;
  323. }
  324. }
  325. break;
  326. case 12:
  327. if((CTHL_CL_MotorStep == 0)&& (CTHL_SF_Origin_IN)) //插销前夹带回到原位
  328. {
  329. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  330. {
  331. CTHL_AutoStep = 14;
  332. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_XCQJD_XCDW_DELAY;
  333. if(cXcxcrCnt != 1)
  334. {
  335. CTHL_CXQJD_VAVLE = 1;
  336. }
  337. }
  338. }
  339. break;
  340. case 14:
  341. if(dwTickCount >= CTHL_AutoDelay)
  342. {
  343. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  344. {
  345. CTHL_XKDW_VAVLE = 1; //斜口定位
  346. CTHL_AutoStep = 15;
  347. CTHL_FKGD_VAVLE = 1; //方块固定
  348. //Y轴启动插销
  349. if(cXcxcrCnt != 1)
  350. {
  351. CTHL_CL_MotorStep = 20; //插销定位
  352. }
  353. }
  354. }
  355. break;
  356. case 15:
  357. if(CTHL_CL_MotorStep == 0) //插销定位完成
  358. {
  359. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  360. {
  361. CTHL_AutoStep = 16;
  362. CTHL_CXDWZ_VAVLE = 1; //插销定位针(到位)电磁阀
  363. CTHL_CXHJD_VAVLE = 1; //Y14 插销后夹带输出
  364. CTHL_AutoDelay = dwTickCount + 10; //延时插销下移
  365. }
  366. }
  367. break;
  368. case 16:
  369. if(dwTickCount >= CTHL_AutoDelay)
  370. {
  371. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  372. {
  373. CTHL_AutoStep = 17;
  374. if(CTHL_PARAM_CXMODE)
  375. CTHL_CXVAVLE = 0;
  376. else
  377. CTHL_CXVAVLE = 1; //Y06 插销下移电磁阀
  378. CTHL_CXHJD_VAVLE = 1; //Y14 插销后夹带输出
  379. CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME; //插销下移异常时间
  380. }
  381. }
  382. break;
  383. case 17:
  384. if(CTHL_PARAM_CXMODE)
  385. {
  386. if(CTHL_CXLimit_IN)
  387. {
  388. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  389. {
  390. CTHL_AutoStep = 18;
  391. if( cXcxcrCnt==0 && !X_DRV) //拖带电机反转
  392. {
  393. AxisMovePosAccDec(X_AXIS,8000,-CTHL_PARAM_TDFZ_LENTH,800,600,6,6,0);
  394. }
  395. CTHL_CXQJD_VAVLE = 0; //插销前夹带电磁阀
  396. CTHL_CXSCDW_VAVLE = 0; //Y21 插销上止定位关
  397. CTHL_CXHJD_VAVLE = 1; //Y14 插销后夹带输出
  398. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_SCDWOff_CXDW_DELAY;
  399. }
  400. }
  401. else if(dwTickCount >= CTHL_AutoDelay)
  402. {
  403. CTHL_SetAlarmCode(CTHL_CXLimit_ALARM,bRunning); //插销下移异常
  404. }
  405. }
  406. else
  407. {
  408. CTHL_AutoStep = 18;
  409. if( cXcxcrCnt==0 && !X_DRV) //拖带电机反转
  410. {
  411. AxisMovePosAccDec(X_AXIS,8000,-CTHL_PARAM_TDFZ_LENTH,800,600,6,6,0);
  412. }
  413. CTHL_CXQJD_VAVLE = 0; //插销前夹带电磁阀
  414. CTHL_CXSCDW_VAVLE = 0; //Y21 插销上止定位关
  415. CTHL_CXHJD_VAVLE = 1; //Y14 插销后夹带输出
  416. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_SCDWOff_CXDW_DELAY;
  417. }
  418. break;
  419. case 18:
  420. // if(START_IN_UP)
  421. {
  422. if(dwTickCount >= CTHL_AutoDelay)
  423. {
  424. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  425. {
  426. CTHL_AutoStep = 19;
  427. cBAOHUCNT=0;
  428. CTHL_CXHDW_VAVLE = 1; //插销后定位(插销穿入)
  429. CTHL_AutoDelay = dwTickCount + 500; //插销穿入到位异常时间
  430. CTHL_CL_MotorStep = 50; //合链电机回原点
  431. }
  432. }
  433. }
  434. break;
  435. case 19:
  436. if(CTHL_CX_Limit_IN && (cXcxcrCnt<4))
  437. {
  438. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  439. {
  440. cXcxcrCnt=0;
  441. cXiaoChaCNT=0;
  442. user_datas[100]=0;
  443. bZhuangLiaoOkFlg = 0;
  444. CTHL_CXVAVLE=0;
  445. CTHL_AutoStep = 901;
  446. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_FKGD_DELAY; //退方块固定时间
  447. CTHL_CXDWZ_VAVLE = 0; //插销定位针(到位)电磁阀
  448. }
  449. }
  450. else if ((dwTickCount >= CTHL_AutoDelay) && (cXcxcrCnt<3) )
  451. {
  452. cXcxcrCnt++;
  453. CTHL_CXHJD_VAVLE=0;
  454. CTHL_CXHDW_VAVLE=0;
  455. if(!CTHL_PARAM_CXMODE)
  456. CTHL_CXVAVLE=0;
  457. else
  458. CTHL_CXVAVLE=1;
  459. if(cXcxcrCnt<3)
  460. {
  461. CTHL_CXSCDW_VAVLE=1;
  462. CTHL_AutoStep = 12;
  463. CTHL_AutoDelay = dwTickCount + 120;
  464. }
  465. }
  466. else if((dwTickCount >= (CTHL_AutoDelay +3000)) && !CTHL_CX_Limit_IN )
  467. {
  468. cXiaoChaCNT=1;
  469. if(!CTHL_PARAM_CXMODE)
  470. CTHL_CXVAVLE=0;
  471. else
  472. CTHL_CXVAVLE=1;
  473. CTHL_CXHJD_VAVLE =0;
  474. cBAOHUCNT=1;
  475. CTHL_SetAlarmCode(CTHL_CX_Limit_ALARM ,bRunning);//插销穿入到位异常
  476. }
  477. if( cXcxcrCnt > 2)
  478. {
  479. cXiaoChaCNT=1;
  480. CTHL_CXVAVLE=0;
  481. CTHL_CXHJD_VAVLE =0;
  482. cBAOHUCNT=1;
  483. CTHL_SetAlarmCode(CTHL_CX_Limit_ALARM ,bRunning);//插销穿入到位异常
  484. }
  485. break;
  486. case 901:
  487. if(dwTickCount >= CTHL_AutoDelay)
  488. {
  489. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  490. {
  491. CTHL_FKGD_VAVLE = 0; //方块固定退
  492. CTHL_AutoStep = 20;
  493. if(!cBAOHUCNT)
  494. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_First_CL_DELAY;//延时一次穿入
  495. else
  496. {
  497. CTHL_AutoDelay = dwTickCount + 1000;//手动插销保护时间
  498. cBAOHUCNT=0;
  499. }
  500. }
  501. }
  502. break;
  503. case 20:
  504. if(dwTickCount >= CTHL_AutoDelay)
  505. {
  506. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  507. {
  508. CTHL_AutoStep = 21;
  509. CTHL_First_CT_VAVLE = 1; //一次穿入电磁阀输出
  510. CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  511. }
  512. }
  513. break;
  514. case 21:
  515. if(!CTHL_First_CT_Origin_IN) //原点离开后才开始时间
  516. {
  517. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  518. {
  519. CTHL_AutoStep = 22;
  520. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_First_CL_Timer; //一次穿入时间
  521. }
  522. }
  523. else if(dwTickCount >= CTHL_AutoDelay)
  524. {
  525. CTHL_SetAlarmCode(CTHL_YCCRYWYC_ALARM,bRunning); //一次穿入原位异常
  526. }
  527. break;
  528. case 22:
  529. if(dwTickCount >= CTHL_AutoDelay)
  530. {
  531. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  532. {
  533. CTHL_AutoStep = 23;
  534. CTHL_MGuo_VAVLE = 0; //码勾退
  535. if(CTHL_PARAM_LTJJ_MODE)
  536. {
  537. CTHL_LTJJ_VAVLE=1;
  538. }
  539. CTHL_AutoDelay = dwTickCount + CTHL_PARAM_MGOff_XiaMo_DELAY;
  540. CTHL_FKGD_VAVLE = 0; //方块固定退
  541. CTHL_FKJD_VAVLE=0;
  542. // CTHL_CXHJD_VAVLE = 0; //Y14 插销后夹带打开
  543. CTHL_CXVAVLE = 0; //Y06 插销下移电磁阀关
  544. }
  545. }
  546. break;
  547. case 23:
  548. if(dwTickCount >= CTHL_AutoDelay)
  549. {
  550. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  551. {
  552. if(!CTHL_LTJJ_Origin_IN || !CTHL_PARAM_LTJJ_MODE)
  553. {
  554. CTHL_CTXM_VAVLE = 0; //穿头下模下降
  555. CTHL_AutoStep = 24;
  556. CTHL_AutoDelay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  557. }
  558. else if(dwTickCount >= CTHL_AutoDelay+3000)
  559. {
  560. CTHL_SetAlarmCode(CTHL_XMKH_Origin_ALARM,bRunning);
  561. }
  562. }
  563. }
  564. break;
  565. case 24:
  566. if(!CTHL_CTM_Limit_IN)
  567. {
  568. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  569. {
  570. CTHL_AutoStep = 25;
  571. CTHL_FKJD_VAVLE=0;
  572. CTHL_CXHJD_VAVLE = 0;
  573. CTHL_AutoDelay = dwTickCount + 30; //一次穿入延时返回
  574. }
  575. }
  576. else if(dwTickCount >= CTHL_AutoDelay)
  577. {
  578. CTHL_SetAlarmCode(CTHL_CTM_Origin_ALARM,bRunning);//穿头下模下降异常
  579. }
  580. break;
  581. case 25:
  582. if(dwTickCount >= CTHL_AutoDelay)
  583. {
  584. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  585. {
  586. CTHL_AutoStep = 26;
  587. CTHL_First_CT_VAVLE = 0; //一次穿入电磁阀关
  588. CTHL_AutoDelay = dwTickCount + 5;
  589. CTHL_CXHDW_VAVLE = 0; //插销后定位(插销穿入)关闭
  590. //退下出错警告
  591. CTHL_AutoDelay1 = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  592. CTHL_AutoStep1 = 1;
  593. }
  594. }
  595. break;
  596. case 26:
  597. if(dwTickCount >= CTHL_AutoDelay)
  598. {
  599. if(!CTHL_DANBU_MODE || CTHL_START_IN_UP)
  600. {
  601. CTHL_FKJD_VAVLE = 1; //方块夹带气缸输出
  602. CTHL_FKGD_VAVLE = 0; //方块固定关
  603. CTHL_AutoStep = 4;
  604. bCL_EN_FLG = 1;
  605. cXcxcrCnt=0;
  606. AddToTal(CTHL_TOTAL_ADDR);
  607. AddToTal(CTHL_TRUST_ALARM_ADDR);
  608. AddToTal(CTHL_TEST_ALARM_ADDR);
  609. CalProSP(CTHL_SPEED_ADDR);
  610. if(cZipCnt<3)
  611. cZipCnt++;
  612. }
  613. }
  614. break;
  615. }
  616. }
  617. //退下模后启动送拉头
  618. switch(CTHL_AutoStep1)
  619. {
  620. case 1:
  621. if(cStopMode==1 || bSingOneFlg )
  622. {
  623. bCL_EN_FLG=1;
  624. cStopMode=2;
  625. bSingOneFlg=0;
  626. bStop=1;
  627. }
  628. if(CTHL_CTM_Origin_IN && CTHL_First_CT_Origin_IN)
  629. {
  630. CTHL_ZhuangLiaoStep = 1;
  631. CTHL_TryCnt = 0;
  632. CTHL_AutoStep1 = 0;
  633. CTHL_MGuo_VAVLE = 0;
  634. CTHL_JLTou_VAVLE = 0;
  635. }
  636. else if(dwTickCount >= CTHL_AutoDelay1)
  637. {
  638. //穿头模和一次穿入回位异常
  639. if(!CTHL_CTM_Origin_IN)
  640. CTHL_SetAlarmCode(CTHL_CTM_Origin_ALARM,bRunning);
  641. else if(!CTHL_First_CT_Origin_IN)
  642. CTHL_SetAlarmCode(CTHL_First_CT_Origin_ALARM,bRunning);
  643. }
  644. break;
  645. }
  646. }
  647. void CTHL_CheckStart(void)
  648. {
  649. if(cXCXQXQD)
  650. {
  651. if(CTHL_START_IN_UP || bStart)
  652. {
  653. bStart=0;
  654. if(!bRunning)
  655. {
  656. if(CTHL_SafeDoor_IN )
  657. {
  658. bRunning=1;
  659. cXCXQXQD =0;
  660. CTHL_TD_MotorStep = 0;
  661. CTHL_AutoStep=11;
  662. }
  663. else
  664. {
  665. CTHL_SetAlarmCode(CTHL_SafeDoor_ALARM,0); // 安全门关上才能启动
  666. }
  667. }
  668. }
  669. }
  670. if(cWULATOUCnt) // 无拉头警告后按
  671. {
  672. if(CTHL_START_IN_UP || bStart)
  673. {
  674. bStart=0;
  675. if(!bRunning)
  676. {
  677. if(CTHL_SafeDoor_IN)
  678. {
  679. bRunning=1;
  680. CTHL_TryCnt=0;
  681. cWULATOUCnt=0;
  682. CTHL_ZhuangLiaoStep = 1;
  683. CTHL_AutoStep=6;
  684. bTuiLaTouOkFlg = 1;
  685. bZhuangLiaoOkFlg= 0;
  686. CTHL_MGuo_VAVLE = 1; //判断是否已经有料
  687. CTHL_LTJJ_VAVLE=0;
  688. CTHL_ZhuangLiaoDelay = dwTickCount + 150;
  689. }
  690. else
  691. {
  692. CTHL_SetAlarmCode(CTHL_SafeDoor_ALARM,0); // 安全门关上才能启动
  693. }
  694. }
  695. }
  696. }
  697. if(!CTHL_SafeDoor_IN && bRunning)
  698. {
  699. bStop=1;
  700. CTHL_SetAlarmCode(CTHL_SafeDoor_ALARM,0); // 安全门关上才能启动
  701. }
  702. //启动 自动启动 单一自动
  703. if((CTHL_START_IN_UP || bStart || CTHL_bSingleone) && !cWULATOUCnt && !cXCXQXQD)
  704. {
  705. if(cCHULIANBAOJIN) //无链停机启动
  706. {
  707. cCHULIANBAOJIN=0;
  708. SetEn(X_AXIS, MOTOR_EN);
  709. // dwXRealPos=0;
  710. CTHL_TD_MotorStep=10;
  711. cZipCnt=0;
  712. CTHL_TD_MotorDelay = dwTickCount + 500;
  713. CTHL_AutoDelay = dwTickCount + 150;
  714. if(GetAlarmCode(CTHL_ALARM_ADDR) != 0)
  715. SetAlarmCode(CTHL_ALARM_ADDR,0);
  716. }
  717. if(!bRunning)
  718. {
  719. if(CTHL_SafeDoor_IN)
  720. {
  721. cStopMode=0;
  722. if(CTHL_bSingleone)
  723. {
  724. bSingOneFlg=1;
  725. }
  726. bRunning = 1;
  727. cWULATOUCnt=0;
  728. cHeLian=0;
  729. if(GetEn(X_AXIS)==MOTOR_DISEN)
  730. {
  731. SetEn(X_AXIS, MOTOR_EN);
  732. CTHL_AutoDelay = dwTickCount + 150;
  733. }
  734. SetEn(Y_AXIS, MOTOR_EN);
  735. CTHL_CL_MotorStep = 40;
  736. CTHL_AutoStep = 1;
  737. bTuiLaTouOkFlg = 1;
  738. CTHL_PARAM_ZDP_AUTO= 0;
  739. bZhuangLiaoOkFlg= 0;
  740. if(!CTHL_PARAM_LTJJ_MODE)
  741. {
  742. CTHL_LTJJ_VAVLE=0;
  743. }
  744. CTHL_MGuo_VAVLE = 1; //判断是否已经有料
  745. CTHL_LTJJ_VAVLE=0;
  746. CTHL_ZhuangLiaoDelay = dwTickCount + 150;
  747. // bCL_EN_FLG = 0;
  748. cZipCnt = 0;
  749. cQDXK_DXK=0;
  750. CTHL_LianLengthCheck = 0;
  751. cStopInCnt = 0;
  752. }
  753. else
  754. {
  755. CTHL_SetAlarmCode(CTHL_SafeDoor_ALARM,0); // 安全门关上才能启动
  756. }
  757. }
  758. CTHL_bSingleone=0;
  759. bStart = 0;
  760. }
  761. if(CTHL_STOP_INJT_UP)
  762. {
  763. bRunning=0;
  764. cXcxcrCnt=0;
  765. cStopMode=0;
  766. cCHULIANBAOJIN=0;
  767. cXCXQXQD=0;
  768. cWULATOUCnt=0;
  769. bCL_EN_FLG=0;
  770. AxisEgmStop(X_AXIS);
  771. AxisEgmStop(Y_AXIS);
  772. SetEn(X_AXIS, MOTOR_DISEN);
  773. SetEn(Y_AXIS, MOTOR_DISEN);
  774. cStopMode=0;
  775. cQDXK_DXK=0;
  776. if(GetAlarm(Y_AXIS)==1 || GetAlarm(X_AXIS)==0)
  777. {
  778. SetClr(Y_AXIS, MOTOR_NOALARM);
  779. SetClr(X_AXIS, MOTOR_NOALARM);
  780. CTHL_bSFBBAOJIN_Delay= dwTickCount + 2000;
  781. }
  782. CTHL_TLiao_VAVLE=0;
  783. CTHL_HSLiao_VAVLE =0;
  784. CTHL_JLTou_VAVLE =0;
  785. CTHL_XKTD_VAVLE =0;
  786. CTHL_XKDW_VAVLE =0;
  787. CTHL_DXK_VAVLE =0;
  788. CTHL_CXVAVLE =0;
  789. CTHL_CTXM_VAVLE =0;
  790. CTHL_First_CT_VAVLE =0;
  791. CTHL_FKGD_VAVLE =0;
  792. CTHL_CXQJD_VAVLE =0;
  793. CTHL_CXDWZ_VAVLE =0;
  794. CTHL_CXHJD_VAVLE =0;
  795. CTHL_CXHDW_VAVLE =0;
  796. CTHL_FKJD_VAVLE =0;
  797. CTHL_HLJJ_VAVLE =0;
  798. CTHL_CXSCDW_VAVLE =0;
  799. CTHL_MGuo_VAVLE =0;
  800. CTHL_QDXK_VAVLE=0;
  801. CTHL_LTJJ_VAVLE =0;
  802. CTHL_AutoStep = 0;
  803. CTHL_ZhuangLiaoStep=0;
  804. CTHL_TLiaoStep=0;
  805. CTHL_TD_MotorStep=0;
  806. CTHL_JiaLianStep =0;
  807. CTHL_SongLiaoStep =0;
  808. CTHL_CL_MotorStep =0;
  809. CTHL_AutoStep1 =0;
  810. CTHL_bFKCXTDDW_Step=0;
  811. CTHL_bCXCR_Step=0;
  812. CTHL_bCLFirst_Step=0;
  813. if(GetAlarmCode(CTHL_ALARM_ADDR) != 0)
  814. SetAlarmCode(CTHL_ALARM_ADDR,0);
  815. SetPos(X_AXIS, 0);
  816. CTHL_TLiaoStep = 0;
  817. CTHL_AutoStep = 0;
  818. //穿合链电机是往零点方向时可以停止
  819. if(GetDir(Y_AXIS) == DIR_N)
  820. AxisEgmStop(Y_AXIS);
  821. }
  822. //停止
  823. if(CTHL_STOP_IN_UP || bStop)
  824. {
  825. if(cStopMode < 2)
  826. cStopMode++;
  827. if(bRunning && cStopMode==2)
  828. {
  829. bRunning=0;
  830. cStopMode=0;
  831. cXcxcrCnt=0;
  832. bSingOneFlg=0;
  833. cXCXQXQD=0;
  834. cCHULIANBAOJIN=0;
  835. cWULATOUCnt=0;
  836. AxisEgmStop(X_AXIS);
  837. AxisEgmStop(Y_AXIS);
  838. CTHL_AutoStep = 0;
  839. CTHL_CL_MotorStep =0;
  840. CTHL_bCLFirst_Step=0;
  841. CTHL_ZhuangLiaoStep=0;
  842. // CTHL_XKTD_VAVLE = 0;
  843. cQDXK_DXK=0;
  844. // CTHL_XKDW_VAVLE =0;
  845. if(GetAlarm(Y_AXIS)==1 || GetAlarm(X_AXIS)==0)
  846. {
  847. SetClr(Y_AXIS, MOTOR_NOALARM);
  848. SetClr(X_AXIS, MOTOR_NOALARM);
  849. CTHL_bSFBBAOJIN_Delay= dwTickCount + 2000;
  850. }
  851. if(GetAlarmCode(CTHL_ALARM_ADDR) != 0)
  852. SetAlarmCode(CTHL_ALARM_ADDR,0);
  853. }
  854. else if(!bRunning)
  855. {
  856. bRunning=0;
  857. cXcxcrCnt=0;
  858. cStopMode=0;
  859. cCHULIANBAOJIN=0;
  860. cXCXQXQD=0;
  861. cWULATOUCnt=0;
  862. bCL_EN_FLG=0;
  863. bSingOneFlg=0;
  864. AxisEgmStop(X_AXIS);
  865. AxisEgmStop(Y_AXIS);
  866. SetEn(X_AXIS, MOTOR_DISEN);
  867. SetEn(Y_AXIS, MOTOR_DISEN);
  868. cStopMode=0;
  869. cQDXK_DXK=0;
  870. if(GetAlarm(Y_AXIS)==1 || GetAlarm(X_AXIS)==0)
  871. {
  872. SetClr(Y_AXIS, MOTOR_NOALARM);
  873. SetClr(X_AXIS, MOTOR_NOALARM);
  874. CTHL_bSFBBAOJIN_Delay= dwTickCount + 2000;
  875. }
  876. CTHL_TLiao_VAVLE=0;
  877. CTHL_HSLiao_VAVLE =0;
  878. CTHL_JLTou_VAVLE =0;
  879. CTHL_XKTD_VAVLE =0;
  880. CTHL_XKDW_VAVLE =0;
  881. CTHL_DXK_VAVLE =0;
  882. CTHL_CXVAVLE =0;
  883. CTHL_CTXM_VAVLE =0;
  884. CTHL_First_CT_VAVLE =0;
  885. CTHL_FKGD_VAVLE =0;
  886. CTHL_CXQJD_VAVLE =0;
  887. CTHL_CXDWZ_VAVLE =0;
  888. CTHL_CXHJD_VAVLE =0;
  889. CTHL_CXHDW_VAVLE =0;
  890. CTHL_FKJD_VAVLE =0;
  891. CTHL_HLJJ_VAVLE =0;
  892. CTHL_CXSCDW_VAVLE =0;
  893. CTHL_MGuo_VAVLE =0;
  894. CTHL_QDXK_VAVLE=0;
  895. CTHL_LTJJ_VAVLE =0;
  896. CTHL_AutoStep = 0;
  897. CTHL_ZhuangLiaoStep=0;
  898. CTHL_TLiaoStep=0;
  899. CTHL_TD_MotorStep=0;
  900. CTHL_JiaLianStep =0;
  901. CTHL_SongLiaoStep =0;
  902. CTHL_CL_MotorStep =0;
  903. CTHL_AutoStep1 =0;
  904. CTHL_bFKCXTDDW_Step=0;
  905. CTHL_bCXCR_Step=0;
  906. CTHL_bCLFirst_Step=0;
  907. if(GetAlarmCode(CTHL_ALARM_ADDR) != 0)
  908. SetAlarmCode(CTHL_ALARM_ADDR,0);
  909. SetPos(X_AXIS, 0);
  910. CTHL_TLiaoStep = 0;
  911. CTHL_AutoStep = 0;
  912. //穿合链电机是往零点方向时可以停止
  913. if(GetDir(Y_AXIS) == DIR_N)
  914. AxisEgmStop(Y_AXIS);
  915. }
  916. bStop=0;
  917. }
  918. if(bAlarmStop)
  919. {
  920. bRunning = 0;
  921. bAlarmStop=0;
  922. cStopMode=0;
  923. cXcxcrCnt=0;
  924. AxisEgmStop(X_AXIS);
  925. AxisEgmStop(Y_AXIS);
  926. CTHL_AutoStep = 0;
  927. cQDXK_DXK=0;
  928. CTHL_CL_MotorStep =0;
  929. CTHL_bCLFirst_Step=0;
  930. CTHL_SongLiaoStep =0;
  931. CTHL_ZhuangLiaoStep=0;
  932. // CTHL_XKTD_VAVLE = 0;
  933. // CTHL_XKDW_VAVLE =0;
  934. }
  935. }
  936. //拖带电机控制动作 X轴
  937. void CTHL_TD_Motor(void) //
  938. {
  939. #if 1
  940. switch(CTHL_TD_MotorStep)
  941. {
  942. //1步开始,纯定位, 没有穿入
  943. case 1:
  944. if(dwTickCount >= CTHL_TD_MotorDelay) //给锁轴时间
  945. {
  946. bCheckEN_FLG = 1;
  947. CTHL_CheckInX02PosBuff= 0;
  948. CTHL_TD_MotorStep = 2;
  949. SetPos(X_AXIS, 0); //启动位置设为0点
  950. AxisContinueMoveAcc(X_AXIS,CTHL_PARAM_TD_RunSpeed*2/3,DIR_P,800,600,15,15);
  951. CTHL_X_CXPosBuff=0;
  952. }
  953. break;
  954. case 2://检测到过链
  955. if(dwXRealPos > 400) //穿入2CM后退
  956. {
  957. if(CTHL_PARAM_NLSL_MODE)
  958. {
  959. CTHL_XKTD_VAVLE=0;
  960. }
  961. CTHL_DXK_VAVLE = 0; //顶斜口气缸关
  962. CTHL_QDXK_VAVLE = 0;
  963. }
  964. if(dwXRealPos >= CTHL_PARAM_WLCDSHEZHI_LENTH)
  965. {
  966. CTHL_SetAlarmCode(CTHL_WLZDTJ_ALARM,bRunning); //无拉链自动停机
  967. }
  968. if(CTHL_FK_Check)
  969. {
  970. CTHL_DXK_VAVLE = 0; //顶斜口气缸关
  971. CTHL_QDXK_VAVLE = 0;
  972. CTHL_XSavePosBuff = dwXRealPos;
  973. CTHL_TD_MotorStep = 3;
  974. user_datas[123] = dwXRealPos - CTHL_CheckInX02PosBuff;
  975. if((dwXRealPos >= CTHL_CheckInX02PosBuff) && CTHL_CheckInX02PosBuff)
  976. AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed*2/3,CTHL_PARAM_FKDW_Length - (dwXRealPos- CTHL_CheckInX02PosBuff)-160,
  977. CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,30,40);
  978. else
  979. AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed*2/3,CTHL_PARAM_FKDW_Length-120,
  980. CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,30,40);
  981. }
  982. break;
  983. case 3:
  984. if(CTHL_CXSC_Limit_IN_UP)
  985. {
  986. CTHL_X_CXPosBuff = dwXRealPos;
  987. }
  988. if(!X_DRV || (dwXRealPos >= (CTHL_XSavePosBuff + CTHL_PARAM_FKDW_Length)))
  989. {
  990. AxisEgmStop(X_AXIS);
  991. CTHL_TD_MotorStep =4 ;
  992. CTHL_LianLengthAutoCheck = dwXRealPos;
  993. }
  994. break;
  995. case 4:
  996. if(CTHL_PARAM_XCX_LENTH) //0的话不判断位置
  997. {
  998. if ((dwXRealPos - CTHL_X_CXPosBuff) > (CTHL_PARAM_XCX_LENTH + CTHL_PARAM_XCXWC_LENTH))
  999. {
  1000. // user_datas[121] = 1;
  1001. CTHL_TD_MotorStep = 0;
  1002. CTHL_SetAlarmCode(CTHL_XCXXCYC_ALARM,bRunning); // 小插销行程异常
  1003. }
  1004. else if(CTHL_X_CXPosBuff == 0)
  1005. {
  1006. // user_datas[121] = 3;
  1007. CTHL_TD_MotorStep = 0;
  1008. CTHL_SetAlarmCode(CTHL_XCXXCYC_ALARM,bRunning); // 小插销行程异常
  1009. }
  1010. else
  1011. {
  1012. CTHL_TD_MotorStep = 0;
  1013. CTHL_X_CXPosBuff=dwXRealPos;
  1014. }
  1015. }
  1016. else
  1017. {
  1018. CTHL_TD_MotorStep = 0;
  1019. // CTHL_X_CXPosBuff=dwXRealPos;
  1020. }
  1021. break;
  1022. //穿拉头定位
  1023. case 10:
  1024. if(dwTickCount >= CTHL_TD_MotorDelay)
  1025. {
  1026. CTHL_TD_MotorStep = 11;
  1027. SetPos(X_AXIS, 0); //启动位置设为0点
  1028. dwXRealPos = 0;
  1029. AxisContinueMoveAcc(X_AXIS,CTHL_PARAM_TDCR_LowSpeed,DIR_P,200,200,5,5);
  1030. CTHL_CheckInX02PosBuff= 0;
  1031. CTHL_X_CXPosBuff=0;
  1032. bCheckEN_FLG = 1;
  1033. }
  1034. break;
  1035. case 11:
  1036. if(CTHL_PARAM_NLSL_MODE)
  1037. CTHL_Data_Buff = 600;
  1038. else
  1039. CTHL_Data_Buff = 400;
  1040. if(dwXRealPos > CTHL_Data_Buff) //穿入2CM后退
  1041. {
  1042. CTHL_CheckInX02PosBuff= 0;
  1043. CTHL_DXK_VAVLE = 0; //顶斜口气缸关
  1044. CTHL_QDXK_VAVLE = 0;
  1045. if(CTHL_PARAM_NLSL_MODE)
  1046. {
  1047. CTHL_XKTD_VAVLE=0;
  1048. }
  1049. CTHL_TD_MotorStep = 12;
  1050. if((cZipCnt < 2) || ((CTHL_LianLengthCheck < CTHL_PARAM_TDCR_LowSpeedLength+300) && (CTHL_PARAM_NLSL_MODE == 0)) ||
  1051. ((CTHL_LianLengthCheck < CTHL_PARAM_TDCR_LowSpeedLength+600) && (CTHL_PARAM_NLSL_MODE == 1)))
  1052. AxisContinueMoveAcc(X_AXIS,CTHL_PARAM_TD_RunSpeed*2/3,DIR_P,3000,600,10,10);
  1053. else ////两段速度移动距离
  1054. {
  1055. if(CTHL_PARAM_NLSL_MODE == 0)
  1056. 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);
  1057. else //尼龙
  1058. {
  1059. 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);
  1060. }
  1061. }
  1062. }
  1063. if(CTHL_FK_Check) //在这里检测到说明速度还没有起来
  1064. {
  1065. CTHL_DXK_VAVLE = 0; //顶斜口气缸关
  1066. CTHL_QDXK_VAVLE = 0;
  1067. if(CTHL_PARAM_NLSL_MODE)
  1068. {
  1069. CTHL_XKTD_VAVLE=0;
  1070. }
  1071. CTHL_TD_MotorDelay= dwTickCount + CTHL_PARAM_FKJDSECONG_DEALY;
  1072. CTHL_LianLengthReal = dwXRealPos;
  1073. CTHL_XSavePosBuff = dwXRealPos;
  1074. CTHL_TD_MotorStep = 13;
  1075. // user_datas[122] = CTHL_PARAM_FKDW_Length - (dwXRealPos- CTHL_CheckInX02PosBuff);
  1076. if((dwXRealPos >= CTHL_CheckInX02PosBuff) && CTHL_CheckInX02PosBuff)
  1077. AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed,CTHL_PARAM_FKDW_Length - (dwXRealPos- CTHL_CheckInX02PosBuff),
  1078. CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,10);
  1079. else
  1080. AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed,CTHL_PARAM_FKDW_Length,
  1081. CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,10);
  1082. //CTHL_TD_MotorStep = 0;
  1083. }
  1084. else if(CTHL_CXSC_Limit_IN_DW)
  1085. {
  1086. CTHL_SetAlarmCode(CTHL_DK_ERROR_ALARM,bRunning);
  1087. }
  1088. else if(CTHL_CXSC_Limit_IN_UP)
  1089. {
  1090. AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed * 2/3,CTHL_PARAM_FKDW_Length,
  1091. CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,10);
  1092. }
  1093. break;
  1094. case 12://检测到过链
  1095. if(cZipCnt<2)
  1096. {
  1097. if(dwXRealPos >= CTHL_PARAM_WLCDSHEZHI_LENTH)
  1098. {
  1099. if(bRunning)
  1100. {
  1101. cCHULIANBAOJIN=1;
  1102. SetEn(X_AXIS, MOTOR_DISEN);
  1103. AxisEgmStop(X_AXIS);
  1104. SetPos(X_AXIS, 0); //启动位置设为0点
  1105. // dwXRealPos=0;
  1106. }
  1107. CTHL_SetAlarmCode(CTHL_WLZDTJ_ALARM,bRunning); //无拉链自动停机
  1108. }
  1109. }
  1110. else
  1111. {
  1112. if(dwXRealPos >= CTHL_LianLengthAutoCheckERROR + CTHL_PARAM_WUCD_LENTH)
  1113. {
  1114. if(bRunning)
  1115. {
  1116. cCHULIANBAOJIN=1;
  1117. SetEn(X_AXIS, MOTOR_DISEN);
  1118. AxisEgmStop(X_AXIS);
  1119. SetPos(X_AXIS, 0); //启动位置设为0点
  1120. // dwXRealPos=0;
  1121. }
  1122. CTHL_SetAlarmCode(CTHL_WLZDTJ_ALARM,bRunning); //无拉链自动停机
  1123. }
  1124. }
  1125. if(CTHL_FK_Check)
  1126. {
  1127. CTHL_TD_MotorDelay= dwTickCount + CTHL_PARAM_FKJDSECONG_DEALY;
  1128. CTHL_LianLengthReal = dwXRealPos;
  1129. //if(cZipCnt == 1)
  1130. // user_datas[122] = dwXRealPos;
  1131. // user_datas[121] = dwXRealPos;
  1132. if((cZipCnt == 1) || dwXRealPos < (CTHL_LianLengthCheck*0.85) || dwXRealPos>(CTHL_LianLengthCheck*1.3))
  1133. CTHL_LianLengthCheck = dwXRealPos;
  1134. CTHL_LianLengthCheckOLD=CTHL_LianLengthNEWCheck;
  1135. CTHL_LianLengthNEWCheck = dwXRealPos;
  1136. //break;
  1137. CTHL_XSavePosBuff = dwXRealPos;
  1138. CTHL_TD_MotorStep = 13;
  1139. // user_datas[122] = CTHL_PARAM_FKDW_Length - (dwXRealPos- CTHL_CheckInX02PosBuff);
  1140. if((dwXRealPos >= CTHL_CheckInX02PosBuff) && CTHL_CheckInX02PosBuff)
  1141. AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed,CTHL_PARAM_FKDW_Length - (dwXRealPos- CTHL_CheckInX02PosBuff)-50,
  1142. CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,40);
  1143. else
  1144. AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed,CTHL_PARAM_FKDW_Length-50,
  1145. CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,40);
  1146. //CTHL_TD_MotorStep = 0;
  1147. }
  1148. else if(CTHL_CXSC_Limit_IN_DW)
  1149. {
  1150. CTHL_SetAlarmCode(CTHL_DK_ERROR_ALARM,bRunning);
  1151. }
  1152. else if(CTHL_CXSC_Limit_IN_UP)
  1153. {
  1154. AxisMovePosAccDec(X_AXIS,CTHL_PARAM_TD_RunSpeed * 2/3,CTHL_PARAM_FKDW_Length,
  1155. CTHL_PARAM_FKDW_Speed,CTHL_PARAM_FKDW_Speed,10,150,40);
  1156. }
  1157. break;
  1158. case 13:
  1159. if(dwTickCount >= CTHL_TD_MotorDelay)
  1160. {
  1161. CTHL_FKJD_VAVLE = 1; //方块夹带气缸输出
  1162. }
  1163. if(CTHL_CXSC_Limit_IN_UP)
  1164. {
  1165. CTHL_X_CXPosBuff = dwXRealPos;
  1166. }
  1167. if((!X_DRV ))// || (dwXRealPos >= (CTHL_XSavePosBuff + CTHL_PARAM_FKDW_Length)))
  1168. {
  1169. // user_datas[123] = dwXRealPos-CTHL_CheckInX02PosBuff;
  1170. AxisEgmStop(X_AXIS);
  1171. CTHL_TD_MotorStep = 14;
  1172. /* if(cZipCnt>2)
  1173. {
  1174. if(((CTHL_LianLengthNEWCheck+CTHL_LianLengthCheckOLD)*0.5) < (CTHL_LianLengthCheck*0.95))
  1175. {
  1176. cZipCnt=0;
  1177. cHeLian=1;
  1178. }
  1179. }*/
  1180. if(cZipCnt==1)
  1181. CTHL_LianLengthAutoCheckERROR = dwXRealPos;
  1182. if(cZipCnt==1)
  1183. CTHL_LianLengSave=dwXRealPos;
  1184. CTHL_LianLengthAutoCheck = dwXRealPos;
  1185. user_datas[122] = dwXRealPos-CTHL_X_CXPosBuff;
  1186. }
  1187. break;
  1188. case 14:
  1189. if(CTHL_PARAM_XCX_LENTH) //0的话不判断位置
  1190. {
  1191. if ((dwXRealPos - CTHL_X_CXPosBuff) > (CTHL_PARAM_XCX_LENTH + CTHL_PARAM_XCXWC_LENTH))
  1192. {
  1193. // user_datas[121] = 1;
  1194. CTHL_TD_MotorStep = 0;
  1195. cXCXQXQD=1;
  1196. CTHL_SetAlarmCode(CTHL_XCXXCYC_ALARM,bRunning); // 小插销行程异常
  1197. }
  1198. else if((dwXRealPos - CTHL_X_CXPosBuff) < (CTHL_PARAM_XCX_LENTH - CTHL_PARAM_XCXWC_LENTH))
  1199. {
  1200. // user_datas[121] = 2;
  1201. CTHL_TD_MotorStep = 0;
  1202. cXCXQXQD=1;
  1203. CTHL_SetAlarmCode(CTHL_XCXXCYC_ALARM,bRunning); // 小插销行程异常
  1204. }
  1205. else if(CTHL_X_CXPosBuff == 0)
  1206. {
  1207. // user_datas[121] = 3;
  1208. CTHL_TD_MotorStep = 0;
  1209. cXCXQXQD=1;
  1210. CTHL_SetAlarmCode(CTHL_XCXXCYC_ALARM,bRunning); // 小插销行程异常
  1211. }
  1212. else
  1213. {
  1214. CTHL_TD_MotorStep = 15;
  1215. }
  1216. }
  1217. else
  1218. {
  1219. CTHL_TD_MotorStep = 15;
  1220. }
  1221. break;
  1222. case 15:
  1223. // if(CTHL_START_IN_UP)
  1224. CTHL_TD_MotorStep = 0;
  1225. }
  1226. #endif
  1227. }
  1228. //穿入电机动作,Y轴
  1229. void CTHL_CL_Motor(void) //
  1230. {
  1231. #if 0
  1232. //1步开始, 穿链长度开始
  1233. //20步开始 插销定位开始
  1234. //40步,回原点为
  1235. switch(CTHL_CL_MotorStep)
  1236. {
  1237. //穿入长度位置
  1238. case 1:
  1239. if(dwTickCount >= CTHL_CL_MotorDelay)
  1240. {
  1241. // SetDir(Y_AXIS, DIR_P);
  1242. if(CTHL_PARAM_CL_Length >= CTHL_PARAM_CL_MAX_Length)
  1243. CTHL_PARAM_CL_Length = CTHL_PARAM_CL_MAX_Length;
  1244. //穿入长度要根据检测长度减动一次穿入的1CM,反转的2CM
  1245. if((CTHL_LianLengthAutoCheck < (CTHL_PARAM_CL_Length + 500 )) && bRunning)
  1246. AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,(CTHL_LianLengthAutoCheck-500),800,600,6,6,50);
  1247. else
  1248. AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,(CTHL_PARAM_CL_Length-100),800,600,6,6,50);
  1249. CTHL_CL_MotorStep = 2;
  1250. }
  1251. break;
  1252. case 2:
  1253. if((dwYRealPos + 120) > CTHL_PARAM_CL_Length)
  1254. CTHL_HLJJ_VAVLE = 0;
  1255. if(!Y_DRV || dwYRealPos >= CTHL_PARAM_CL_Length)
  1256. {
  1257. CTHL_HLJJ_VAVLE = 0;
  1258. CTHL_CL_MotorStep = 3;
  1259. bCL_OK_FLG = 1;
  1260. CTHL_CL_MotorDelay = dwTickCount + 40; //延时数控回零点
  1261. }
  1262. break;
  1263. case 3:
  1264. if(dwTickCount >= CTHL_CL_MotorDelay)
  1265. {
  1266. CTHL_CL_MotorStep = 50;
  1267. }
  1268. break;
  1269. //夹带插销到穿入位置
  1270. case 20: //此处最好算好定位长度相减
  1271. if(cXcxcrCnt > 0)
  1272. {
  1273. CTHL_LENTH = CTHL_PARAM_CXDW_Length + 30;
  1274. CTHL_CL_MotorStep = 21;
  1275. }
  1276. else
  1277. {
  1278. CTHL_LENTH = CTHL_PARAM_CXDW_Length ;
  1279. CTHL_CL_MotorStep = 21;
  1280. }
  1281. break;
  1282. case 21:
  1283. SetDir(Y_AXIS, DIR_P);
  1284. AxisMovePosAccDec(Y_AXIS,8000,CTHL_LENTH,800,500,6,6,50);
  1285. CTHL_CL_MotorStep = 22;
  1286. break;
  1287. case 22:
  1288. if(!Y_DRV || (dwYRealPos >= CTHL_LENTH)) //插销定位已经结束
  1289. {
  1290. AxisEgmStop(Y_AXIS);
  1291. CTHL_YsaveCXDWPosBuff = 0;
  1292. CTHL_CL_MotorStep = 0;
  1293. }
  1294. break;
  1295. //回原点开始
  1296. case 40:
  1297. //要先离开
  1298. if(CTHL_SF_Origin_IN && (GetEn(Y_AXIS) == MOTOR_DISEN))
  1299. {
  1300. CTHL_CL_MotorStep = 41;
  1301. SetDir(Y_AXIS, DIR_P);
  1302. }
  1303. else
  1304. {
  1305. SetDir(Y_AXIS, DIR_N);
  1306. CTHL_CL_MotorStep = 46;
  1307. }
  1308. if(GetEn(Y_AXIS) == MOTOR_DISEN)
  1309. {
  1310. SetEn(Y_AXIS, MOTOR_EN);
  1311. CTHL_CL_MotorDelay = dwTickCount + 260; //锁轴时间
  1312. }
  1313. else //已经锁轴
  1314. CTHL_CL_MotorDelay = dwTickCount + 5;
  1315. break;
  1316. case 41:
  1317. if(dwTickCount >= CTHL_CL_MotorDelay)
  1318. {
  1319. CTHL_CL_MotorStep = 42;
  1320. AxisContinueMoveAcc(Y_AXIS,5000,DIR_P,1000,800,15,15);
  1321. }
  1322. break;
  1323. case 42:
  1324. if(!CTHL_SF_Origin_IN)
  1325. {
  1326. CTHL_CL_MotorStep = 43;
  1327. CTHL_YSavePosBuff = dwYRealPos;
  1328. }
  1329. break;
  1330. case 43:
  1331. //离开原点5CM停止
  1332. if((dwYRealPos - CTHL_YSavePosBuff) >= 800)
  1333. {
  1334. AxisEgmStop(Y_AXIS);
  1335. CTHL_CL_MotorStep = 46; //留空几步备用
  1336. CTHL_CL_MotorDelay = dwTickCount + 50;
  1337. }
  1338. break;
  1339. case 46:
  1340. if(dwTickCount >= CTHL_CL_MotorDelay)
  1341. {
  1342. CTHL_CL_MotorStep = 47; //检测回到原位
  1343. if(!CTHL_SF_Origin_IN)
  1344. AxisContinueMoveAcc(Y_AXIS,1500,DIR_N,1000,800,15,10);
  1345. }
  1346. break;
  1347. case 47:
  1348. if(CTHL_SF_Origin_IN)
  1349. {
  1350. CTHL_CL_MotorStep = 0;
  1351. AxisEgmStop(Y_AXIS);
  1352. SetPos(Y_AXIS, 0);
  1353. }
  1354. break;
  1355. //数控回原位 (条件为自动工作,SON一直没有松开)
  1356. case 50:
  1357. if(dwYRealPos > 150)
  1358. { //回零速度
  1359. SetDir(Y_AXIS, DIR_N);
  1360. AxisMovePosAccDecNotStop(Y_AXIS,CTHL_PARAM_CL_Back_O_Speed,-dwYRealPos + 150,5000,2000,10,50,50);
  1361. }
  1362. else
  1363. AxisContinueMoveAcc(Y_AXIS,1000,DIR_N,1000,1000,15,15);
  1364. CTHL_CL_MotorStep = 51;
  1365. break;
  1366. case 51:
  1367. if(CTHL_SF_Origin_IN)
  1368. {
  1369. CTHL_CL_MotorStep = 0;
  1370. AxisEgmStop(Y_AXIS);
  1371. SetPos(Y_AXIS, 0);
  1372. }
  1373. break;
  1374. }
  1375. #endif
  1376. #if 1
  1377. //1步开始, 穿链长度开始
  1378. //20步开始 插销定位开始
  1379. //40步,回原点为
  1380. switch(CTHL_CL_MotorStep)
  1381. {
  1382. //穿入长度位置
  1383. case 1:
  1384. if(dwTickCount >= CTHL_CL_MotorDelay)
  1385. {
  1386. if(!CTHL_PARAM_AUTO_MODE)
  1387. {
  1388. //穿入长度要根据检测长度减动一次穿入的1CM,反转的2CM
  1389. if(CTHL_LianLengthAutoCheck <= 700)
  1390. {
  1391. CTHL_Y_CL_Length=CTHL_LianLengthAutoCheck-200;
  1392. if(CTHL_Y_CL_Length<10)
  1393. CTHL_Y_CL_Length=200;
  1394. if(CTHL_Y_CL_Length >= CTHL_PARAM_CL_MAX_Length)
  1395. CTHL_Y_CL_Length = CTHL_PARAM_CL_MAX_Length-40;
  1396. AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,CTHL_Y_CL_Length,800,600,6,6,50);
  1397. }
  1398. else if(CTHL_LianLengthAutoCheck>700)
  1399. {
  1400. user_datas[123] =CTHL_LianLengthAutoCheck;
  1401. if(cZipCnt>1)
  1402. CTHL_Y_CL_Length=CTHL_LianLengSave-CTHL_PARAM_HLTSY_LENTH-300;
  1403. else
  1404. {
  1405. if(cZipCnt<1)
  1406. CTHL_Y_CL_Length=CTHL_LianLengthAutoCheck-CTHL_PARAM_HLTSY_LENTH-100;
  1407. else
  1408. CTHL_Y_CL_Length=CTHL_LianLengthAutoCheck-CTHL_PARAM_HLTSY_LENTH-300;
  1409. }
  1410. if(cZipCnt>1)
  1411. {
  1412. if(CTHL_LianLengthAutoCheck<(CTHL_LianLengSave*0.7))
  1413. {
  1414. CTHL_Y_CL_Length=CTHL_LianLengthAutoCheck-CTHL_PARAM_HLTSY_LENTH-300;
  1415. cZipCnt=0;
  1416. }
  1417. }
  1418. if(CTHL_Y_CL_Length<200)
  1419. CTHL_Y_CL_Length=200;
  1420. if(CTHL_Y_CL_Length >= CTHL_PARAM_CL_MAX_Length)
  1421. CTHL_Y_CL_Length = CTHL_PARAM_CL_MAX_Length-40;
  1422. AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,CTHL_Y_CL_Length,800,600,6,6,50);
  1423. }
  1424. }
  1425. else
  1426. {
  1427. if(CTHL_PARAM_CL_Length >= CTHL_PARAM_CL_MAX_Length)
  1428. CTHL_PARAM_CL_Length = CTHL_PARAM_CL_MAX_Length;
  1429. //穿入长度要根据检测长度减动一次穿入的1CM,反转的2CM
  1430. if((CTHL_LianLengthAutoCheck < (CTHL_PARAM_CL_Length + 500 )) && bRunning)
  1431. AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,(CTHL_LianLengthAutoCheck-500),800,600,6,6,50);
  1432. else
  1433. AxisMovePosAccDec(Y_AXIS,CTHL_PARAM_CL_Speed,(CTHL_PARAM_CL_Length-100),800,600,6,6,50);
  1434. }
  1435. CTHL_CL_MotorStep = 2;
  1436. }
  1437. break;
  1438. case 2:
  1439. if(CTHL_PARAM_AUTO_MODE)
  1440. {
  1441. if((dwYRealPos + 120) > CTHL_PARAM_CL_Length)
  1442. CTHL_HLJJ_VAVLE = 0;
  1443. if(!Y_DRV || dwYRealPos >= CTHL_PARAM_CL_Length)
  1444. {
  1445. CTHL_HLJJ_VAVLE = 0;
  1446. CTHL_CL_MotorStep = 3;
  1447. bCL_OK_FLG = 1;
  1448. CTHL_CL_MotorDelay = dwTickCount + 30; //延时数控回零点
  1449. }
  1450. }
  1451. else
  1452. {
  1453. if((dwYRealPos + 120) > CTHL_Y_CL_Length)
  1454. CTHL_HLJJ_VAVLE = 0;
  1455. if(!Y_DRV || dwYRealPos >= CTHL_Y_CL_Length)
  1456. {
  1457. CTHL_HLJJ_VAVLE = 0;
  1458. CTHL_CL_MotorStep = 3;
  1459. bCL_OK_FLG = 1;
  1460. CTHL_CL_MotorDelay = dwTickCount + 30; //延时数控回零点
  1461. }
  1462. }
  1463. break;
  1464. case 3:
  1465. if(dwTickCount >= CTHL_CL_MotorDelay)
  1466. {
  1467. CTHL_CL_MotorStep = 50;
  1468. }
  1469. break;
  1470. //夹带插销到穿入位置
  1471. case 20: //此处最好算好定位长度相减
  1472. if(cXcxcrCnt > 0)
  1473. {
  1474. if(cXcxcrCnt==1)
  1475. CTHL_LENTH = CTHL_PARAM_CXDW_Length+CTHL_PARAM_TDFZ_LENTH + 50;
  1476. if(cXcxcrCnt>1)
  1477. CTHL_LENTH = CTHL_PARAM_CXDW_Length +CTHL_PARAM_TDFZ_LENTH + 120;
  1478. CTHL_CL_MotorStep = 21;
  1479. }
  1480. else
  1481. {
  1482. CTHL_LENTH = CTHL_PARAM_CXDW_Length ;
  1483. CTHL_CL_MotorStep = 21;
  1484. }
  1485. break;
  1486. case 21:
  1487. SetDir(Y_AXIS, DIR_P);
  1488. CTHL_Y_CL_PosBuff = dwYRealPos;
  1489. AxisMovePosAccDec(Y_AXIS,20000,CTHL_LENTH,800,500,6,6,50);
  1490. CTHL_CL_MotorStep = 22;
  1491. break;
  1492. case 22:
  1493. if(dwYRealPos >= CTHL_Y_CL_PosBuff+CTHL_LENTH-CTHL_PARAM_CXDW_Length) //插销定位已经结束
  1494. {
  1495. CTHL_CXSCDW_VAVLE = 1;
  1496. }
  1497. if(!Y_DRV || (dwYRealPos >= CTHL_Y_CL_PosBuff+CTHL_LENTH)) //插销定位已经结束
  1498. {
  1499. AxisEgmStop(Y_AXIS);
  1500. CTHL_YsaveCXDWPosBuff = 0;
  1501. CTHL_CL_MotorStep = 0;
  1502. }
  1503. break;
  1504. case 30:
  1505. CTHL_YsaveCXDWPosBuff = 0;
  1506. CTHL_CL_MotorStep = 0;
  1507. break;
  1508. //回原点开始
  1509. case 40:
  1510. //要先离开
  1511. if(CTHL_SF_Origin_IN && (GetEn(Y_AXIS) == MOTOR_DISEN))
  1512. {
  1513. CTHL_CL_MotorStep = 41;
  1514. SetDir(Y_AXIS, DIR_P);
  1515. }
  1516. else
  1517. {
  1518. SetDir(Y_AXIS, DIR_N);
  1519. CTHL_CL_MotorStep = 46;
  1520. }
  1521. if(GetEn(Y_AXIS) == MOTOR_DISEN)
  1522. {
  1523. SetEn(Y_AXIS, MOTOR_EN);
  1524. CTHL_CL_MotorDelay = dwTickCount + 260; //锁轴时间
  1525. }
  1526. else //已经锁轴
  1527. CTHL_CL_MotorDelay = dwTickCount + 5;
  1528. break;
  1529. case 41:
  1530. if(dwTickCount >= CTHL_CL_MotorDelay)
  1531. {
  1532. CTHL_CL_MotorStep = 42;
  1533. AxisContinueMoveAcc(Y_AXIS,5000,DIR_P,1000,800,15,15);
  1534. }
  1535. break;
  1536. case 42:
  1537. if(!CTHL_SF_Origin_IN)
  1538. {
  1539. CTHL_CL_MotorStep = 43;
  1540. CTHL_YSavePosBuff = dwYRealPos;
  1541. }
  1542. break;
  1543. case 43:
  1544. //离开原点5CM停止
  1545. if((dwYRealPos - CTHL_YSavePosBuff) >= 800)
  1546. {
  1547. AxisEgmStop(Y_AXIS);
  1548. CTHL_CL_MotorStep = 46; //留空几步备用
  1549. CTHL_CL_MotorDelay = dwTickCount + 50;
  1550. }
  1551. break;
  1552. case 46:
  1553. if(dwTickCount >= CTHL_CL_MotorDelay)
  1554. {
  1555. CTHL_CL_MotorStep = 47; //检测回到原位
  1556. if(!CTHL_SF_Origin_IN)
  1557. AxisContinueMoveAcc(Y_AXIS,1500,DIR_N,1000,800,15,10);
  1558. }
  1559. break;
  1560. case 47:
  1561. if(CTHL_SF_Origin_IN)
  1562. {
  1563. CTHL_CL_MotorStep = 0;
  1564. AxisEgmStop(Y_AXIS);
  1565. SetPos(Y_AXIS, 0);
  1566. }
  1567. break;
  1568. //数控回原位 (条件为自动工作,SON一直没有松开)
  1569. case 50:
  1570. if(dwYRealPos > 151)
  1571. { //回零速度
  1572. SetDir(Y_AXIS, DIR_N);
  1573. AxisMovePosAccDecNotStop(Y_AXIS,CTHL_PARAM_CL_Back_O_Speed,-dwYRealPos + 150,5000,2000,10,50,100);
  1574. }
  1575. else
  1576. AxisContinueMoveAcc(Y_AXIS,1000,DIR_N,1000,1000,15,15);
  1577. CTHL_CL_MotorStep = 51;
  1578. break;
  1579. case 51:
  1580. if(CTHL_SF_Origin_IN)
  1581. {
  1582. CTHL_CL_MotorStep = 0;
  1583. AxisEgmStop(Y_AXIS);
  1584. SetPos(Y_AXIS, 0);
  1585. }
  1586. break;
  1587. }
  1588. #endif
  1589. }
  1590. //装拉头动作
  1591. void CTHL_ZLT_Step(void)
  1592. {
  1593. switch(CTHL_ZhuangLiaoStep)
  1594. {
  1595. case 1://检测是否有拉头?
  1596. if(bZhuangLiaoOkFlg)
  1597. {
  1598. CTHL_ZhuangLiaoStep = 0;
  1599. }
  1600. else if(dwTickCount >= CTHL_ZhuangLiaoDelay)
  1601. {
  1602. if(((CTHL_MGuo_VAVLE && CTHL_LTou_Check) || (!CTHL_MGuo_VAVLE)) && !CTHL_JLiao_Limit_IN )//说明没有拉头
  1603. {
  1604. //穿头模和一次穿入必须在原位,接料不能有输出
  1605. if(CTHL_CTM_Origin_IN && !CTHL_CTXM_VAVLE)//下模没有输出、下模在原位。
  1606. {
  1607. CTHL_First_CT_VAVLE = 0;//?
  1608. CTHL_JLTou_VAVLE = 0;//夹拉头松开
  1609. CTHL_MGuo_VAVLE = 0; //码钩松开
  1610. if(CTHL_TLiaoStep == 0)//执行推料步骤动作
  1611. {
  1612. CTHL_TLiaoStep = 1;
  1613. CTHL_ZhuangLiaoStep = 2;
  1614. }
  1615. }
  1616. else if(dwTickCount >= CTHL_ZhuangLiaoDelay + 500) //下模原位异常
  1617. {
  1618. CTHL_SetAlarmCode(CTHL_CTM_Origin_ALARM,bRunning);
  1619. }
  1620. }
  1621. else //已经有拉头直接跳到结束
  1622. {
  1623. CTHL_ZhuangLiaoDelay = dwTickCount + 40;
  1624. CTHL_ZhuangLiaoStep = 9;
  1625. }
  1626. }
  1627. break;
  1628. case 2: //等待推料完成
  1629. if(CTHL_TLiaoStep == 0) //推料已经完成
  1630. {
  1631. CTHL_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1632. CTHL_JLTou_VAVLE = 0;//夹拉头送开
  1633. CTHL_MGuo_VAVLE = 0; //码钩松开
  1634. if(!CTHL_JLiao_Limit_IN && CTHL_First_CT_Origin_IN)
  1635. {
  1636. CTHL_ZhuangLiaoStep = 3;
  1637. CTHL_HSLiao_VAVLE = 1;
  1638. if(CTHL_PARAM_LTJJ_MODE)
  1639. {
  1640. CTHL_LTJJ_VAVLE=1;
  1641. }
  1642. else
  1643. CTHL_LTJJ_VAVLE=0;
  1644. }
  1645. }
  1646. break;
  1647. case 3:
  1648. //横送到位
  1649. if(CTHL_HSLiao_Limit_IN && !CTHL_HSLiao_Origin_IN)
  1650. {
  1651. CTHL_ZhuangLiaoStep = 4;
  1652. // CTHL_JLTou_VAVLE = 1; //接拉头输出,不需要时间
  1653. CTHL_ZhuangLiaoDelay = dwTickCount + 5;
  1654. }
  1655. else if(dwTickCount >= CTHL_ZhuangLiaoDelay)
  1656. {
  1657. CTHL_SetAlarmCode(CTHL_HSLiao_Limit_ALARM,bRunning);
  1658. }
  1659. break;
  1660. case 4:
  1661. if(dwTickCount >= CTHL_ZhuangLiaoDelay)
  1662. {
  1663. CTHL_ZhuangLiaoStep = 5;
  1664. CTHL_JLTou_VAVLE = 1; //接拉头输出,不需要时间
  1665. CTHL_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1666. }
  1667. break;
  1668. case 5:
  1669. if(CTHL_JLiao_Limit_IN)
  1670. {
  1671. CTHL_LTJJ_VAVLE=0;
  1672. CTHL_ZhuangLiaoStep = 6;
  1673. if(CTHL_PARAM_LTJJ_MODE)
  1674. {
  1675. CTHL_ZhuangLiaoDelay = dwTickCount + CTHL_PARAM_MaGou_DELAY+30;
  1676. }
  1677. else
  1678. {
  1679. CTHL_ZhuangLiaoDelay = dwTickCount + CTHL_PARAM_MaGou_DELAY;
  1680. }
  1681. }
  1682. else if(dwTickCount >= CTHL_ZhuangLiaoDelay) //接拉头(接料)到们信号异常
  1683. {
  1684. CTHL_SetAlarmCode(CTHL_JLiao_Limit_ALARM,bRunning);
  1685. }
  1686. break;
  1687. case 6:
  1688. if(dwTickCount >= CTHL_ZhuangLiaoDelay) //延时码勾
  1689. {
  1690. if(!CTHL_PARAM_LTJJ_MODE || CTHL_LTJJ_Origin_IN)
  1691. {
  1692. CTHL_MGuo_VAVLE = 1; //码勾输出
  1693. CTHL_ZhuangLiaoStep = 7;
  1694. CTHL_ZhuangLiaoDelay = dwTickCount + CTHL_PARAM_HSLiaoOff_DELAY;
  1695. bTuiLaTouOkFlg = 0; //认为拉头没法带出
  1696. }
  1697. else if(dwTickCount >= CTHL_ZhuangLiaoDelay+3000)
  1698. {
  1699. CTHL_SetAlarmCode(CTHL_XMKH_Origin_ALARM,bRunning);
  1700. }
  1701. }
  1702. break;
  1703. case 7:
  1704. if(dwTickCount >= CTHL_ZhuangLiaoDelay)
  1705. {
  1706. CTHL_HSLiao_VAVLE = 0;
  1707. CTHL_ZhuangLiaoStep = 8;
  1708. CTHL_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1709. }
  1710. break;
  1711. case 8:
  1712. if(!CTHL_HSLiao_Limit_IN) //
  1713. {
  1714. CTHL_ZhuangLiaoStep = 9;
  1715. CTHL_TLiaoStep = 1; //推拉头
  1716. CTHL_ZhuangLiaoDelay = dwTickCount + CTHL_PARAM_CheckLT_DELAY; //也是给下模能上升的时间
  1717. }
  1718. else if (CTHL_LTou_Check) //时间内信号这说明没有拉头
  1719. {
  1720. //重送3次
  1721. CTHL_TryCnt++;
  1722. CTHL_JLTou_VAVLE = 0; //接拉头关
  1723. CTHL_MGuo_VAVLE = 0; //码勾打开
  1724. if(CTHL_TryCnt >= CTHL_PARAM_SLT_NUMBER)
  1725. {
  1726. CTHL_TryCnt = 0;
  1727. bZhuangLiaoOkFlg = 0;
  1728. CTHL_ZhuangLiaoStep = 0;
  1729. CTHL_SetAlarmCode(CTHL_ZLT_ALARM,bRunning);
  1730. cWULATOUCnt=1;
  1731. }
  1732. else
  1733. {
  1734. CTHL_ZhuangLiaoStep = 20; //重新送3次
  1735. CTHL_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1736. }
  1737. }
  1738. else if(dwTickCount >= CTHL_ZhuangLiaoDelay)
  1739. {
  1740. CTHL_SetAlarmCode(CTHL_HSLiao_Limit_ALARM,bRunning);
  1741. if(bRunning)
  1742. {
  1743. CTHL_ZhuangLiaoStep = 0 ;
  1744. }
  1745. }
  1746. break;
  1747. case 9:
  1748. if(CTHL_LTou_Check) //时间内信号这说明没有拉头
  1749. {
  1750. CTHL_TryCnt++;
  1751. CTHL_JLTou_VAVLE = 0; //接拉头关
  1752. CTHL_MGuo_VAVLE = 0; //码勾打开
  1753. if(CTHL_TryCnt >= 3)
  1754. {
  1755. CTHL_TryCnt=0;
  1756. bZhuangLiaoOkFlg = 0;
  1757. CTHL_ZhuangLiaoStep = 0;
  1758. CTHL_SetAlarmCode(CTHL_ZLT_ALARM,bRunning);
  1759. cWULATOUCnt=1;
  1760. }
  1761. else
  1762. {
  1763. CTHL_ZhuangLiaoStep = 20; //重新送3次
  1764. CTHL_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  1765. }
  1766. }
  1767. else if(dwTickCount >= CTHL_ZhuangLiaoDelay)
  1768. {
  1769. bZhuangLiaoOkFlg = 1;
  1770. CTHL_ZhuangLiaoStep = 0;
  1771. }
  1772. break;
  1773. //装拉头不成攻重新送拉头
  1774. case 20:
  1775. if(CTHL_HSLiao_Origin_IN)
  1776. {
  1777. CTHL_JLTou_VAVLE = 0; //接拉头关
  1778. CTHL_MGuo_VAVLE = 0; //码勾打开
  1779. CTHL_ZhuangLiaoStep = 1;
  1780. CTHL_ZhuangLiaoDelay = dwTickCount + 10;
  1781. }
  1782. else if(dwTickCount >= CTHL_ZhuangLiaoDelay)
  1783. {
  1784. CTHL_SetAlarmCode(CTHL_HSLiao_Origin_ALARM,bRunning);
  1785. }
  1786. break;
  1787. }
  1788. }
  1789. void CTHL_TLiao_Step(void)
  1790. {
  1791. switch(CTHL_TLiaoStep)
  1792. {
  1793. case 1:
  1794. if(bTuiLaTouOkFlg)
  1795. {
  1796. CTHL_TLiaoStep = 0;
  1797. }
  1798. else
  1799. {
  1800. CTHL_TLiao_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  1801. CTHL_TLiaoStep = 2;
  1802. }
  1803. break;
  1804. case 2: //横送料在原位
  1805. if(CTHL_HSLiao_Origin_IN && !CTHL_HSLiao_Limit_IN && !CTHL_HSLiao_VAVLE)
  1806. {
  1807. CTHL_TLiao_VAVLE = 1; //推料(推拉头)输出
  1808. CTHL_TLiao_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  1809. CTHL_TLiaoStep = 3;
  1810. }
  1811. else if(dwTickCount >= CTHL_TLiao_Delay)
  1812. CTHL_SetAlarmCode(CTHL_HSLiao_Origin_ALARM,1);
  1813. break;
  1814. case 3: //推拉头到位
  1815. if(CTHL_TLiao_Limit_IN)
  1816. {
  1817. CTHL_TLiao_Delay = dwTickCount + CTHL_PARAM_TLiao_BACKDELAY;
  1818. CTHL_TLiaoStep = 4;
  1819. }
  1820. else if(dwTickCount >= CTHL_TLiao_Delay)
  1821. CTHL_SetAlarmCode(CTHL_TLiao_Limit_ALARM,1);
  1822. break;
  1823. case 4:
  1824. if(dwTickCount >= CTHL_TLiao_Delay)
  1825. {
  1826. CTHL_TLiao_VAVLE = 0;
  1827. CTHL_TLiao_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  1828. CTHL_TLiaoStep = 5;
  1829. }
  1830. break;
  1831. case 5:
  1832. if(!CTHL_TLiao_Limit_IN)
  1833. {
  1834. CTHL_TLiaoStep = 0;
  1835. CTHL_TLiao_Delay = dwTickCount;
  1836. bTuiLaTouOkFlg = 1;
  1837. }
  1838. else if(dwTickCount >= CTHL_TLiao_Delay)
  1839. CTHL_SetAlarmCode(CTHL_TLiao_Limit_ALARM,0);
  1840. break;
  1841. }
  1842. }
  1843. //振动盘控制
  1844. void CTHL_ZhenDongAction(void)
  1845. {
  1846. #if 0
  1847. if((CTHL_bDLP || bRunning) && CTHL_ZhenDongPian_OUT && CTHL_PARAM_DALIAOPIAN)
  1848. {
  1849. if(CT_DLP_Time >= dwTickCount)
  1850. {
  1851. CT_ZDP_Delay = dwTickCount + CT_PARAM_DLP_TIME + 40;
  1852. CT_DaLaPian_VAVLE = ~CT_DaLaPian_VAVLE;
  1853. }
  1854. }
  1855. else
  1856. CT_DaLaPian_VAVLE = 0;
  1857. #endif
  1858. #if 1
  1859. // if(bRunning)
  1860. // {
  1861. /*
  1862. switch(CTHL_PARAM_ZDP_AUTO)
  1863. {
  1864. case 0:
  1865. if(CTHL_ZhenDongPian_OUT == 0)
  1866. {
  1867. if(!CTHL_ZDP_IN)
  1868. {
  1869. if(dwTickCount >= CTHL_ZDP_Delay)
  1870. {
  1871. CTHL_ZhenDongPian_OUT = 1;
  1872. CTHL_ZDP_Delay = dwTickCount + CTHL_PARAM_ZDP_Stop_TIME;//CTHL_PARAM_ZDP_Stop_TIME + 50;
  1873. }
  1874. }
  1875. else
  1876. {
  1877. CTHL_ZDP_Delay = dwTickCount + CTHL_PARAM_ZDP_Start_TIME;//CTHL_PARAM_ZDP_Start_TIME;
  1878. }
  1879. }
  1880. else
  1881. {
  1882. if(CTHL_ZDP_IN)
  1883. {
  1884. if(dwTickCount >= CTHL_ZDP_Delay)
  1885. {
  1886. CTHL_ZhenDongPian_OUT = 0;
  1887. CTHL_ZDP_Delay = dwTickCount + CTHL_PARAM_ZDP_Start_TIME;//CTHL_PARAM_ZDP_Start_TIME
  1888. }
  1889. }
  1890. else
  1891. CTHL_ZDP_Delay = dwTickCount + CTHL_PARAM_ZDP_Stop_TIME;//CTHL_PARAM_ZDP_Stop_TIME+ 50;
  1892. }
  1893. break;
  1894. case 1:
  1895. CTHL_ZhenDongPian_OUT=0;
  1896. CTHL_ZDP_Delay = dwTickCount;
  1897. break;
  1898. case 2:
  1899. CTHL_ZhenDongPian_OUT=1;
  1900. CTHL_ZDP_Delay = dwTickCount;
  1901. break;
  1902. }
  1903. }
  1904. else
  1905. CTHL_DaLaPian_OUT = 0; */
  1906. if(CTHL_ZDP_IN)
  1907. {
  1908. if(CTHL_PARAM_LaPian_EN)
  1909. {
  1910. if(dwTickCount >= CTHL_DLP_Delay)
  1911. {
  1912. CTHL_DaLaPian_OUT = !CTHL_DaLaPian_OUT;
  1913. if(CTHL_DaLaPian_OUT)
  1914. CTHL_DLP_Delay = dwTickCount + CTHL_PARAM_DaLaPian;
  1915. else
  1916. CTHL_DLP_Delay = dwTickCount + CTHL_PARAM_DaLaPian+50;
  1917. }
  1918. }
  1919. }
  1920. else
  1921. CTHL_DaLaPian_OUT = 0;
  1922. #endif
  1923. }
  1924. void CTHL_bFKCXTDDWStep(void)
  1925. {
  1926. switch(CTHL_bFKCXTDDW_Step)
  1927. {
  1928. case 1:
  1929. CTHL_FKJD_VAVLE = 1; //方块夹带气缸输出
  1930. CTHL_XKTD_VAVLE = 1; //斜口推带气缸输出
  1931. CTHL_FKGD_VAVLE = 0; //方块固定关
  1932. CTHL_bFKCXTDDW_Step = 2;
  1933. break;
  1934. case 2:
  1935. if(!CTHL_XKTD_Origin_IN) //斜口推带原位离开
  1936. {
  1937. CTHL_bFKCXTDDW_Step = 3;
  1938. CTHL_bFKCXTDDW_Delay = dwTickCount + 20;
  1939. }
  1940. break;
  1941. case 3://斜口定位
  1942. if(dwTickCount >= CTHL_bFKCXTDDW_Delay)
  1943. {
  1944. CTHL_XKDW_VAVLE = 1;
  1945. CTHL_bFKCXTDDW_Step = 4;
  1946. // CTHL_bFKCXTDDW_Delay = dwTickCount + CTHL_PARAM_XKDW_TD_DELAY;
  1947. }
  1948. break;
  1949. case 4:
  1950. if(dwTickCount >= CTHL_bFKCXTDDW_Delay)
  1951. {
  1952. AxisContinueMoveAcc(X_AXIS,1200,DIR_P,800,600,10,10);//拖带电机
  1953. CTHL_bFKCXTDDW_Step = 5;
  1954. CTHL_XSavePosBuff = dwXRealPos;
  1955. SetPos(X_AXIS, 0); //启动位置设为0点
  1956. dwXRealPos = 0;
  1957. }
  1958. break;
  1959. case 5:
  1960. if(CTHL_XKSC_Limit_IN) //方块到位
  1961. {
  1962. AxisEgmStop(X_AXIS);
  1963. CTHL_QDXK_VAVLE=1;
  1964. CTHL_bFKCXTDDW_Step = 6;
  1965. CTHL_XKTD_VAVLE = 0; //斜口推带气缸关闭
  1966. CTHL_bFKCXTDDW_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  1967. }
  1968. else if(dwXRealPos >= (CTHL_XSavePosBuff + 800))
  1969. {
  1970. CTHL_SetAlarmCode(CTHL_FKCXDW_ALARM,bRunning);//方块插销定位异常警告
  1971. }
  1972. break;
  1973. case 6:
  1974. if(CTHL_PARAM_TDFZ_LENTH && !X_DRV) //拖带电机反转
  1975. AxisMovePosAccDec(X_AXIS,8000,-CTHL_PARAM_DXKFZ_LENTH,800,600,6,6,0);
  1976. if(CTHL_PARAM_CXMODE)
  1977. CTHL_CXVAVLE = 1;
  1978. CTHL_bFKCXTDDW_Step = 0;
  1979. break;
  1980. }
  1981. }
  1982. //插销穿入动作
  1983. void CTHL_bCXCRStep(void)
  1984. {
  1985. switch(CTHL_bCXCR_Step)
  1986. {
  1987. case 11:
  1988. CTHL_XKTD_VAVLE = 1; //斜口推带气缸输出
  1989. CTHL_FKGD_VAVLE = 0; //方块固定关
  1990. CTHL_CXSCDW_VAVLE=1;
  1991. CTHL_bCXCR_Step = 12;
  1992. break;
  1993. case 12:
  1994. if(!CTHL_XKTD_Origin_IN) //斜口推带原位离开
  1995. {
  1996. CTHL_bCXCR_Step = 13;
  1997. // CTHL_CXQJD_VAVLE = 1; //插销前夹带
  1998. CTHL_bCXCR_Delay = dwTickCount + 20;
  1999. }
  2000. break;
  2001. case 13:
  2002. if((CTHL_CL_MotorStep == 0) && (CTHL_SF_Origin_IN) && (dwTickCount >= CTHL_bCXCR_Delay)) //插销前夹带回到原位
  2003. {
  2004. CTHL_bCXCR_Step = 14;
  2005. // CTHL_FKGD_VAVLE = 1; //方块固定开
  2006. CTHL_CXQJD_VAVLE = 1; //插销前夹带
  2007. CTHL_bCXCR_Delay = dwTickCount + CTHL_PARAM_XCQJD_XCDW_DELAY;
  2008. }
  2009. break;
  2010. case 14:
  2011. if(dwTickCount >= CTHL_bCXCR_Delay)
  2012. {
  2013. CTHL_bCXCR_Step = 15;
  2014. CTHL_FKGD_VAVLE = 1; //方块固定
  2015. //Y轴启动插销
  2016. CTHL_CL_MotorStep = 20; //插销定位
  2017. }
  2018. break;
  2019. case 15:
  2020. if(CTHL_CL_MotorStep == 0) //插销定位完成
  2021. {
  2022. CTHL_bCXCR_Step = 16;
  2023. CTHL_CXDWZ_VAVLE = 1; //插销定位针(到位)电磁阀
  2024. CTHL_bCXCR_Delay = dwTickCount + 10; //延时插销下移
  2025. }
  2026. break;
  2027. case 16:
  2028. if(dwTickCount >= CTHL_bCXCR_Delay)
  2029. {
  2030. CTHL_bCXCR_Step = 17;
  2031. if(CTHL_PARAM_CXMODE)
  2032. CTHL_CXVAVLE = 0;
  2033. else
  2034. CTHL_CXVAVLE = 1; //Y06 插销下移电磁阀
  2035. if(CTHL_PARAM_NLSL_MODE == 0)
  2036. CTHL_bCXCR_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME; //插销下移异常时间
  2037. else
  2038. CTHL_bCXCR_Delay = dwTickCount + 80; //插销下移异常时间
  2039. }
  2040. break;
  2041. case 17:
  2042. if((CTHL_CXLimit_IN) || CTHL_PARAM_NLSL_MODE)
  2043. {
  2044. if(CTHL_CXLimit_IN || (dwTickCount >= CTHL_bCXCR_Delay))
  2045. {
  2046. CTHL_bCXCR_Step = 18;
  2047. if( cXcxcrCnt==0 && !X_DRV) //拖带电机反转
  2048. {
  2049. AxisMovePosAccDec(X_AXIS,10000,-CTHL_PARAM_TDFZ_LENTH,800,600,6,6,0);
  2050. }
  2051. CTHL_CXQJD_VAVLE = 0; //插销前夹带电磁阀
  2052. CTHL_CXSCDW_VAVLE = 0; //Y21 插销上止定位关
  2053. CTHL_CXHJD_VAVLE = 1; //Y14 插销后夹带输出
  2054. CTHL_bCXCR_Delay = dwTickCount + CTHL_PARAM_SCDWOff_CXDW_DELAY;
  2055. }
  2056. }
  2057. else if(dwTickCount >= CTHL_bCXCR_Delay)
  2058. {
  2059. CTHL_SetAlarmCode(CTHL_CXLimit_ALARM,bRunning);//插销下移异常
  2060. }
  2061. break;
  2062. case 18:
  2063. // if(START_IN_UP)
  2064. {
  2065. if(dwTickCount >= CTHL_bCXCR_Delay)
  2066. {
  2067. CTHL_bCXCR_Step = 19;
  2068. CTHL_CXHDW_VAVLE = 1; //插销后定位(插销穿入)
  2069. CTHL_bCXCR_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME +1000; //插销穿入到位异常时间
  2070. CTHL_CL_MotorStep = 50; //合链电机回原点
  2071. }
  2072. }
  2073. break;
  2074. case 19:
  2075. if( cXcxcrCnt > 1)
  2076. {
  2077. CTHL_SetAlarmCode(CTHL_CX_Limit_ALARM,bRunning); //插销穿入到位异常
  2078. }
  2079. if( CTHL_CX_Limit_IN && cXcxcrCnt<2 )
  2080. {
  2081. cXcxcrCnt=0;
  2082. bZhuangLiaoOkFlg = 0;
  2083. CTHL_bCXCR_Step = 0;
  2084. CTHL_CXDWZ_VAVLE = 0; //插销定位针(到位)电磁阀
  2085. }
  2086. else if (dwTickCount >= CTHL_bCXCR_Delay)
  2087. {
  2088. cXcxcrCnt++;
  2089. CTHL_CXHJD_VAVLE=0;
  2090. CTHL_CXHDW_VAVLE=0;
  2091. CTHL_CXDWZ_VAVLE = 0;
  2092. if(CTHL_PARAM_CXMODE)
  2093. CTHL_CXVAVLE = 0;
  2094. else
  2095. CTHL_CXVAVLE = 1; //Y06 插销下移电磁阀
  2096. CTHL_bCXCR_Step = 11;
  2097. }
  2098. break;
  2099. }
  2100. }
  2101. void CTHL_bCLFirstStep(void)
  2102. {
  2103. switch(CTHL_bCLFirst_Step)
  2104. {
  2105. case 19:
  2106. CTHL_JLTou_VAVLE = 0; //接拉头
  2107. bZhuangLiaoOkFlg = 0;
  2108. CTHL_bCLFirst_Step = 20;
  2109. CTHL_CXDWZ_VAVLE = 0; //插销定位针(到位)电磁阀
  2110. CTHL_CXVAVLE = 0; //Y06 插销下移电磁阀关
  2111. CTHL_bCLFirst_Delay = dwTickCount + CTHL_PARAM_First_CL_DELAY;//延时一次穿入
  2112. break;
  2113. case 20:
  2114. if(dwTickCount >= CTHL_bCLFirst_Delay)
  2115. {
  2116. CTHL_bCLFirst_Step = 21;
  2117. CTHL_First_CT_VAVLE = 1; //一次穿入电磁阀输出
  2118. CTHL_bCLFirst_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  2119. }
  2120. break;
  2121. case 21:
  2122. if(!CTHL_First_CT_Origin_IN) //原点离开后才开始时间
  2123. {
  2124. CTHL_bCLFirst_Step = 22;
  2125. CTHL_bCLFirst_Delay = dwTickCount + CTHL_PARAM_First_CL_Timer; //一次穿入时间
  2126. }
  2127. else if(dwTickCount >= CTHL_bCLFirst_Delay)
  2128. {
  2129. CTHL_SetAlarmCode(CTHL_YCCRYWYC_ALARM,bRunning); //一次穿入原位异常
  2130. }
  2131. break;
  2132. case 22:
  2133. if(dwTickCount >= CTHL_bCLFirst_Delay)
  2134. {
  2135. CTHL_bCLFirst_Step = 23;
  2136. CTHL_MGuo_VAVLE = 0; //码勾退
  2137. CTHL_bCLFirst_Delay = dwTickCount + CTHL_PARAM_MGOff_XiaMo_DELAY;
  2138. CTHL_FKGD_VAVLE = 0; //方块固定退
  2139. CTHL_CXHJD_VAVLE = 0; //Y14 插销后夹带打开
  2140. CTHL_CXVAVLE = 0; //Y06 插销下移电磁阀关
  2141. }
  2142. break;
  2143. case 23:
  2144. if(dwTickCount >= CTHL_bCLFirst_Delay)
  2145. {
  2146. CTHL_bCLFirst_Step = 24;
  2147. CTHL_CTXM_VAVLE = 0; //穿头下模下降
  2148. CTHL_CXHDW_VAVLE = 0; //插销后定位(插销穿入)关闭
  2149. CTHL_bCLFirst_Delay = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  2150. }
  2151. break;
  2152. case 24:
  2153. if(!CTHL_CTM_Limit_IN)
  2154. {
  2155. CTHL_bCLFirst_Step= 25;
  2156. CTHL_bCLFirst_Delay = dwTickCount + 25; //一次穿入延时返回
  2157. }
  2158. else if(dwTickCount >= CTHL_bCLFirst_Delay)
  2159. {
  2160. CTHL_SetAlarmCode(CTHL_CTM_Origin_ALARM,bRunning); //穿头下模下降异常
  2161. }
  2162. break;
  2163. case 25:
  2164. if(dwTickCount >= CTHL_bCLFirst_Delay)
  2165. {
  2166. CTHL_bCLFirst_Step= 0;
  2167. CTHL_First_CT_VAVLE = 0; //一次穿入电磁阀关
  2168. CTHL_CXHDW_VAVLE = 0; //插销后定位(插销穿入)关闭
  2169. //退下出错警告
  2170. CTHL_AutoDelay1 = dwTickCount + CTHL_VAVLE_ERROR_TIME;
  2171. CTHL_AutoStep1 = 1;
  2172. bTuiLaTouOkFlg = 1;
  2173. }
  2174. break;
  2175. }
  2176. }
  2177. //手动动作
  2178. void CTHL_ManualAction(void)
  2179. {
  2180. if(bRunning && user_datas[100]==0) // 运行灯输出
  2181. {
  2182. CTHL_Run_State=1;
  2183. CTHL_Stop_State=0;
  2184. }
  2185. else if(!bRunning && user_datas[100]==0)
  2186. {
  2187. CTHL_Run_State=0;
  2188. CTHL_Stop_State=0;
  2189. }
  2190. if(user_datas[100] != 0)
  2191. {
  2192. CTHL_Run_State=0;
  2193. CTHL_Stop_State=1;
  2194. }
  2195. if( (GetAlarm(Y_AXIS)==1) ) // 伺服报警
  2196. {
  2197. // cCHULIANBAOJIN=1;
  2198. // CTHL_SetAlarmCode(CTHL_SF_ALR_ALARM,0);
  2199. }
  2200. if(dwTickCount >= CTHL_bSFBBAOJIN_Delay)
  2201. {
  2202. SetClr(Y_AXIS,MOTOR_ALARM);
  2203. SetClr(X_AXIS,MOTOR_ALARM);
  2204. }
  2205. if(bRunning == 0)
  2206. {
  2207. if(bClearTotal) //切断计数清零
  2208. {
  2209. bClearTotal = 0;
  2210. ClrcToTal(QDCT_TOTAL_ADDR);
  2211. }
  2212. if(CTHL_bTLiao ) //手动推料(推拉头)
  2213. {
  2214. CTHL_bTLiao = 0;
  2215. if(CTHL_TLiao_VAVLE)
  2216. CTHL_TLiao_VAVLE = 0;//CTHL_TLiao_VAVLE;
  2217. else if(!CTHL_HSLiao_VAVLE && CTHL_HSLiao_Origin_IN)
  2218. {
  2219. CTHL_TLiao_VAVLE = 1;
  2220. }
  2221. else//条件警告
  2222. {
  2223. CTHL_SetAlarmCode(CTHL_HENSONGLIAO_ALARM,0); // 横送料不能输出
  2224. }
  2225. }
  2226. if(CTHL_bHSL) //手动横送料
  2227. {
  2228. CTHL_bHSL= 0;
  2229. if(!CTHL_First_CT_VAVLE)
  2230. {
  2231. if(CTHL_HSLiao_VAVLE)
  2232. {
  2233. CTHL_HSLiao_VAVLE = 0;//~CTHL_HSLiao_VAVLE;
  2234. }
  2235. else if(!CTHL_TLiao_VAVLE && !CTHL_TLiao_Limit_IN && CTHL_CTM_Origin_IN && !CTHL_JLiao_Limit_IN &&
  2236. !CTHL_JLTou_VAVLE && !CTHL_CTXM_VAVLE && !CTHL_CXDWZ_VAVLE && (!CTHL_bMG || (CTHL_bMG && CTHL_LTou_Check)))
  2237. {
  2238. if(CTHL_PARAM_LTJJ_MODE)
  2239. {
  2240. CTHL_LTJJ_VAVLE=1;
  2241. }
  2242. else
  2243. {
  2244. CTHL_LTJJ_VAVLE=0;
  2245. }
  2246. CTHL_HSLiao_VAVLE = 1;
  2247. }
  2248. else //条件警告 最后一个括号条件为已经有拉头
  2249. {
  2250. CTHL_SetAlarmCode(CTHL_YCCT_ALARM,0);
  2251. }
  2252. }
  2253. }
  2254. if(CTHL_bJLT) //接拉头
  2255. {
  2256. CTHL_bJLT = 0;
  2257. if(CTHL_JLTou_VAVLE)
  2258. CTHL_JLTou_VAVLE = 0;
  2259. else if(!CTHL_First_CT_VAVLE && !CTHL_CTXM_VAVLE && CTHL_CTM_Origin_IN && CTHL_First_CT_Origin_IN)
  2260. {
  2261. CTHL_MGuo_VAVLE = 0;
  2262. CTHL_JLTou_VAVLE = 1;
  2263. }
  2264. else//条件警告
  2265. {
  2266. CTHL_SetAlarmCode(CTHL_YCXM_Origin_ALARM,0);
  2267. }
  2268. }
  2269. if(CTHL_bMG) //码勾
  2270. {
  2271. CTHL_bMG = 0;
  2272. CTHL_MGuo_VAVLE = !CTHL_MGuo_VAVLE;
  2273. }
  2274. if(CTHL_bLTJJ) //码勾
  2275. {
  2276. CTHL_bLTJJ = 0;
  2277. CTHL_LTJJ_VAVLE = !CTHL_LTJJ_VAVLE;
  2278. }
  2279. if(CTHL_bFKJD) //方块夹带
  2280. {
  2281. CTHL_bFKJD = 0;
  2282. CTHL_FKJD_VAVLE = !CTHL_FKJD_VAVLE;
  2283. }
  2284. if(CTHL_bXKTD) //斜口推带
  2285. {
  2286. CTHL_bXKTD = 0;
  2287. if(CTHL_XKTD_VAVLE)
  2288. CTHL_XKTD_VAVLE = 0;
  2289. else if(!CTHL_DXK_VAVLE && (!CTHL_XKSC_Limit_IN || !CTHL_CTXM_VAVLE|| CTHL_PARAM_NLSL_MODE))
  2290. CTHL_XKTD_VAVLE = 1;
  2291. else//条件警告
  2292. {
  2293. CTHL_SetAlarmCode(CTHL_DXKCTXM_Origin_ALARM,0);
  2294. }
  2295. }
  2296. if(CTHL_bXKDW) //斜口定位
  2297. {
  2298. CTHL_bXKDW = 0;
  2299. CTHL_XKDW_VAVLE = ~CTHL_XKDW_VAVLE;
  2300. }
  2301. if(CTHL_bCTXM) //穿头下模
  2302. {
  2303. CTHL_bCTXM = 0;
  2304. if(CTHL_CTXM_VAVLE)
  2305. {
  2306. if(CTHL_PARAM_LTJJ_MODE)
  2307. {
  2308. CTHL_LTJJ_VAVLE=1;
  2309. }
  2310. else
  2311. {
  2312. CTHL_LTJJ_VAVLE=0;
  2313. }
  2314. CTHL_CTXM_VAVLE = 0;
  2315. CTHL_MGuo_VAVLE = 0;
  2316. CTHL_JLTou_VAVLE = 0;
  2317. CTHL_CXVAVLE=0;
  2318. }
  2319. else if(!CTHL_HSLiao_VAVLE && CTHL_HSLiao_Origin_IN && (!CTHL_XKSC_Limit_IN || !CTHL_XKTD_VAVLE))
  2320. {
  2321. if(CTHL_PARAM_CXMODE)
  2322. CTHL_CXVAVLE = 1;
  2323. CTHL_MGuo_VAVLE = 1;
  2324. CTHL_CTXM_VAVLE = 1;
  2325. CTHL_LTJJ_VAVLE=0;
  2326. }
  2327. }
  2328. if(CTHL_bQianDXK) //前顶斜口
  2329. {
  2330. CTHL_bQianDXK = 0;
  2331. if(CTHL_QDXK_VAVLE)
  2332. CTHL_QDXK_VAVLE = 0;
  2333. else if(!CTHL_XKTD_VAVLE)
  2334. CTHL_QDXK_VAVLE = 1;
  2335. else //条件警告
  2336. {
  2337. CTHL_SetAlarmCode(CTHL_XKTD_ALARM,0);
  2338. }
  2339. }
  2340. if(CTHL_bDXK) //顶斜口
  2341. {
  2342. CTHL_bDXK = 0;
  2343. if(!CTHL_PARAM_NLSL_MODE)
  2344. {
  2345. if(CTHL_DXK_VAVLE)
  2346. CTHL_DXK_VAVLE = 0;
  2347. else if(!CTHL_XKTD_VAVLE)
  2348. {
  2349. if(!CTHL_PARAM_NLSL_MODE)
  2350. CTHL_DXK_VAVLE = 1;
  2351. }
  2352. else //条件警告
  2353. {
  2354. CTHL_SetAlarmCode(CTHL_XKTD_ALARM,0);
  2355. }
  2356. }
  2357. else
  2358. {
  2359. if(CTHL_XKTD_VAVLE)
  2360. CTHL_XKTD_VAVLE = 0;
  2361. else if(!CTHL_DXK_VAVLE )
  2362. {
  2363. if(!CTHL_XKSC_Limit_IN || !CTHL_CTXM_VAVLE || CTHL_PARAM_NLSL_MODE)
  2364. CTHL_XKTD_VAVLE = 1;
  2365. else
  2366. {
  2367. CTHL_SetAlarmCode(CTHL_YCXM_Origin_ALARM,0);
  2368. }
  2369. }
  2370. else//条件警告
  2371. {
  2372. CTHL_SetAlarmCode(CTHL_DXKCTXM_Origin_ALARM,0);
  2373. }
  2374. }
  2375. }
  2376. if(CTHL_bFKGD) //方块固定
  2377. {
  2378. CTHL_bFKGD = 0;
  2379. CTHL_FKGD_VAVLE = ~CTHL_FKGD_VAVLE;
  2380. }
  2381. if(CTHL_bCXQJD) //插销前夹带
  2382. {
  2383. CTHL_bCXQJD = 0;
  2384. CTHL_CXQJD_VAVLE = ~CTHL_CXQJD_VAVLE;
  2385. }
  2386. if(CTHL_bCXSY) //插销下移电磁阀
  2387. {
  2388. CTHL_bCXSY = 0;
  2389. CTHL_CXVAVLE = !CTHL_CXVAVLE;
  2390. }
  2391. if(CTHL_bCXDWZ) //Y14 插销定位针电磁阀
  2392. {
  2393. CTHL_bCXDWZ = 0;
  2394. if(CTHL_CXDWZ_VAVLE)
  2395. CTHL_CXDWZ_VAVLE = 0;
  2396. else if(CTHL_HSLiao_Origin_IN)
  2397. {
  2398. CTHL_CXDWZ_VAVLE = 1;
  2399. }
  2400. else //条件警告
  2401. {
  2402. CTHL_SetAlarmCode(CTHL_HENSONGLIAO_ALARM,0);
  2403. }
  2404. }
  2405. if(CTHL_bCXHJD) //Y15 插销后夹带电磁阀
  2406. {
  2407. CTHL_bCXHJD = 0;
  2408. CTHL_CXHJD_VAVLE =~CTHL_CXHJD_VAVLE;
  2409. }
  2410. if(CTHL_bCXHDW) //Y16 插销后定位电磁阀
  2411. {
  2412. CTHL_bCXHDW = 0;
  2413. if(CTHL_CXHDW_VAVLE)
  2414. CTHL_CXHDW_VAVLE = 0;
  2415. else if(!CTHL_CXQJD_VAVLE)
  2416. CTHL_CXHDW_VAVLE = 1;
  2417. else//条件警告
  2418. {
  2419. CTHL_SetAlarmCode(CTHL_CXQJD_ALARM,0);
  2420. }
  2421. }
  2422. if(CTHL_bFirst_CT) //Y20 一次穿头电磁阀
  2423. {
  2424. CTHL_bFirst_CT = 0;
  2425. CTHL_First_CT_VAVLE = ~CTHL_First_CT_VAVLE;
  2426. }
  2427. if(CTHL_bHLJJ) //Y21 合链夹具电磁阀
  2428. {
  2429. CTHL_bHLJJ = 0;
  2430. CTHL_HLJJ_VAVLE = ~CTHL_HLJJ_VAVLE;
  2431. }
  2432. if(CTHL_bCXSCDW) //Y23 插销上止定位电磁阀
  2433. {
  2434. CTHL_bCXSCDW = 0;
  2435. CTHL_CXSCDW_VAVLE = ~CTHL_CXSCDW_VAVLE;
  2436. }
  2437. //自动装料
  2438. if(CTHL_bAutoZhuangLiao)
  2439. {
  2440. CTHL_bAutoZhuangLiao = 0;
  2441. if(CTHL_ZhuangLiaoStep == 0)
  2442. {
  2443. bTuiLaTouOkFlg = 1;
  2444. bZhuangLiaoOkFlg = 0;
  2445. CTHL_ZhuangLiaoStep = 1;
  2446. CTHL_MGuo_VAVLE = 1; //判断是否已经有料
  2447. CTHL_LTJJ_VAVLE=0;
  2448. CTHL_ZhuangLiaoDelay = dwTickCount + 150;
  2449. }
  2450. }
  2451. //测试电机
  2452. if(CTHL_bCLMotor_N)
  2453. {
  2454. SetEn(Y_AXIS, MOTOR_EN);
  2455. if(!CTHL_SF_Origin_IN)
  2456. {
  2457. if(!Y_DRV)
  2458. // Y轴 运行速度 启动速度 加速度 减速度
  2459. AxisContinueMoveAcc(Y_AXIS,2000,DIR_N,1000,1000,15,15);
  2460. }
  2461. else
  2462. {
  2463. CTHL_bCLMotor_N = 0;
  2464. }
  2465. }
  2466. if(CTHL_bCLMotor_P) //后退限位已经取消
  2467. {
  2468. SetEn(Y_AXIS, MOTOR_EN);
  2469. if(!Y_DRV)
  2470. // Y轴 运行速度 启动速度 加速度 减速度
  2471. AxisContinueMoveAcc(Y_AXIS,2000,DIR_P,1000,1000,15,15);
  2472. }
  2473. if(!CTHL_bCLMotor_P && !CTHL_bCLMotor_N && (CTHL_CL_MotorStep == 0))
  2474. {
  2475. AxisEgmStop(Y_AXIS);//AxisDecStop(Y_AXIS);
  2476. }
  2477. if(CTHL_bTDMotor_P) //后退限位已经取消
  2478. {
  2479. SetEn(X_AXIS, MOTOR_EN);
  2480. if(!X_DRV)
  2481. // Y轴 运行速度 启动速度 加速度 减速度
  2482. AxisContinueMoveAcc(X_AXIS,2000,DIR_P,1000,1000,15,15);
  2483. }
  2484. if(CTHL_bTDMotor_N) //后退限位已经取消
  2485. {
  2486. SetEn(X_AXIS, MOTOR_EN);
  2487. if(!X_DRV)
  2488. // Y轴 运行速度 启动速度 加速度 减速度
  2489. AxisContinueMoveAcc(X_AXIS,2000,DIR_N,1000,1000,15,15);
  2490. }
  2491. if(!CTHL_bTDMotor_P && !CTHL_bTDMotor_N && (CTHL_TD_MotorStep == 0))
  2492. {
  2493. AxisEgmStop(X_AXIS);//AxisDecStop(Y_AXIS);
  2494. }
  2495. //合链电机返回原点
  2496. if(CTHL_bCLMotor_O)
  2497. {
  2498. CTHL_bCLMotor_O = 0;
  2499. if(CTHL_CL_MotorStep == 0)
  2500. CTHL_CL_MotorStep = 40;
  2501. }
  2502. //拖带方块定位 ,因这步为前拖带定位, 很多电磁阀要关掉
  2503. if(CTHL_bFKTDDW)
  2504. {
  2505. CTHL_bFKTDDW = 0;
  2506. if(CTHL_TD_MotorStep == 0)
  2507. {
  2508. CTHL_XKDW_VAVLE = 0; //斜口定位
  2509. CTHL_CXQJD_VAVLE = 0; //插销前夹带
  2510. if(!CTHL_PARAM_CXMODE)
  2511. CTHL_CXVAVLE = 0; //插销下移
  2512. CTHL_CXHJD_VAVLE = 0; //插销后夹带
  2513. CTHL_CXHDW_VAVLE = 0; //插销后定位
  2514. CTHL_CXDWZ_VAVLE = 0; //插销定位针
  2515. CTHL_bHLJJ = 0; //合链夹具
  2516. CTHL_FKJD_VAVLE = 0; //方块夹带
  2517. if((GetEn(X_AXIS) == MOTOR_DISEN))
  2518. {
  2519. SetEn(X_AXIS, MOTOR_EN);
  2520. CTHL_TD_MotorDelay = dwTickCount + 200;
  2521. }
  2522. else
  2523. CTHL_TD_MotorDelay = dwTickCount + 50;
  2524. CTHL_TD_MotorStep = 1;
  2525. }
  2526. }
  2527. //拖带方块插销定位(斜口推带,斜口定位,顶斜口)
  2528. if(CTHL_bFKCXTDDW)
  2529. {
  2530. CTHL_bFKCXTDDW = 0;
  2531. if((CTHL_bFKCXTDDW_Step == 0) && (CTHL_CL_MotorStep == 0) &&
  2532. !CTHL_CTXM_VAVLE)
  2533. {
  2534. CTHL_bFKCXTDDW_Step = 1;
  2535. if(GetEn(X_AXIS)==MOTOR_DISEN)
  2536. {
  2537. SetEn(X_AXIS, MOTOR_EN);
  2538. CTHL_bFKCXTDDW_Delay = dwTickCount + 300;
  2539. }
  2540. CTHL_CXQJD_VAVLE = 0; //插销前夹带
  2541. CTHL_CXVAVLE = 0; //插销下移
  2542. CTHL_CXHJD_VAVLE = 0; //插销后夹带
  2543. CTHL_CXHDW_VAVLE = 0; //插销后定位
  2544. CTHL_CXDWZ_VAVLE = 0; //插销定位针
  2545. CTHL_HLJJ_VAVLE = 0; //合链夹具
  2546. }
  2547. }
  2548. //插销穿入(包含电机前定位,插销下移,后夹,后定位)
  2549. if(CTHL_bCXCR)
  2550. {
  2551. CTHL_bCXCR = 0;
  2552. //拉头模在上面到们并且码勾输出,判断有拉头
  2553. if(CTHL_CTXM_VAVLE && CTHL_MGuo_VAVLE && !CTHL_CXQJD_VAVLE &&
  2554. CTHL_CTM_Limit_IN && !CTHL_LTou_Check)
  2555. {
  2556. if(CTHL_CL_MotorStep == 0)
  2557. {
  2558. CTHL_bCXCR_Step = 11;
  2559. SetEn(Y_AXIS, MOTOR_EN);
  2560. if(!CTHL_SF_Origin_IN)
  2561. CTHL_CL_MotorStep = 40;
  2562. }
  2563. }
  2564. else //警告不能自动穿插销
  2565. {
  2566. CTHL_SetAlarmCode(CTHL_WFZIDONGCX_ALARM,0);
  2567. }
  2568. }
  2569. //电机合链动作
  2570. if(CTHL_bMotorHL)
  2571. {
  2572. CTHL_bMotorHL = 0;
  2573. if(CTHL_SF_Origin_IN)
  2574. {
  2575. if((CTHL_CL_MotorStep == 0) && !CTHL_CTXM_VAVLE && (!CTHL_CTM_Limit_IN))
  2576. {
  2577. bCL_OK_FLG = 0;
  2578. CTHL_HLJJ_VAVLE = 1; //Y20 合链夹具电磁阀输出后,电机穿入
  2579. CTHL_CL_MotorStep = 1;
  2580. CTHL_CL_MotorDelay = dwTickCount + CTHL_PARAM_HLJJ_CL_DELAY + 130;
  2581. if((GetEn(Y_AXIS) == MOTOR_DISEN))
  2582. {
  2583. SetEn(Y_AXIS, MOTOR_EN);
  2584. CTHL_CL_MotorDelay = dwTickCount + 250;
  2585. }
  2586. }
  2587. }
  2588. else
  2589. {
  2590. CTHL_bCLMotor_O =1;
  2591. }
  2592. }
  2593. //一次穿链动作
  2594. if(CTHL_bCL_First)
  2595. {
  2596. CTHL_bCL_First = 0;
  2597. //拉头模在上面到们并且码勾输出,判断有拉头
  2598. if(CTHL_CTXM_VAVLE && CTHL_MGuo_VAVLE && !CTHL_CXQJD_VAVLE &&
  2599. CTHL_CTM_Limit_IN && !CTHL_LTou_Check && (CTHL_CL_MotorStep == 0))
  2600. {
  2601. CTHL_bCLFirst_Step = 19;
  2602. CTHL_CXHJD_VAVLE = 1; //插销后夹带
  2603. CTHL_CXDWZ_VAVLE = 0; //插销定位针(到位)电磁阀
  2604. CTHL_CXQJD_VAVLE = 0; //插销前夹带
  2605. }
  2606. }
  2607. }
  2608. }
  2609. #endif