YXChuanTouJi.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. #include "global.h"
  2. #if FJ_YING_XING_MACHINE == 1
  3. //盈兴穿头机
  4. void ChuanTou_AlarmProtect(void);
  5. void ChuanTou_ManualAction(void);
  6. void ChuanTou_AutoAction(void);
  7. void ChuanTou_StepCheckStart(void);
  8. void ChuanTou_Motor(void);
  9. void ChuanTou_SongLiaoAction(void);
  10. void ChuanTou_HengSongLiao_Action(void); //横送料
  11. void ChuanTou_ZhuangLiaoStep(void); //装料
  12. void ChuanTou_HeMo(void); //合模动作
  13. void ChuanTou_CLT_Step(void); //穿拉头动作
  14. void ChuanTou_ZhenDongAction(void);
  15. static unsigned char cSongLiaoOk = 0,cMotorDinWei_OK = 0;
  16. static unsigned char cZhuangLiaoOk = 0;
  17. static unsigned char cZLCnt = 0;
  18. unsigned long Zipper_Length = 0;
  19. void CT_SetAlarmCode(unsigned alarm_code)
  20. {
  21. SetAlarmCode(CT_ALARM_ADDR,alarm_code);
  22. bAlarmStop = 1;
  23. }
  24. void ChuanTou_InitAction(void)
  25. {
  26. float length_buff,pulse_buff;
  27. axis_x->speed_unit = 1; //速度频率倍率单位
  28. length_buff = CT_PARAM_CYCLE_LENGTH;
  29. pulse_buff = CT_PARAM_CYCLE_PULSE;
  30. XGearRatio = pulse_buff/length_buff;
  31. YGearRatio = 1;
  32. SetEn(X_AXIS,CT_MOTOR_DISEN);
  33. CT_ZhenDongPian_OUT = 1;
  34. }
  35. void ChuanTou_Action(void)
  36. {
  37. //数据监控
  38. dwRealPos = GetPos(X_AXIS);
  39. user_datas[121] = CT_MotorStep;
  40. user_datas[122] = CT_AutoStep;
  41. user_datas[123] = dwRealPos;
  42. user_datas[124] = CT_HeMoStep;
  43. // user_datas[125] = CT_SL_Step;
  44. //user_datas[126] = CT_HSL_Step;
  45. // user_datas[127] = dwZipCnt;
  46. user_datas[128] = CT_CLT_Step;
  47. ChuanTou_AlarmProtect();
  48. ChuanTou_StepCheckStart(); // 调用脚踏开关检测程序
  49. ChuanTou_Motor();
  50. ChuanTou_ManualAction();
  51. ChuanTou_AutoAction();
  52. ChuanTou_ZhenDongAction();
  53. ChuanTou_SongLiaoAction();
  54. ChuanTou_HengSongLiao_Action(); //横送料
  55. ChuanTou_ZhuangLiaoStep(); //装料
  56. ChuanTou_HeMo(); //合模动作
  57. ChuanTou_CLT_Step();
  58. }
  59. //手动动作
  60. void ChuanTou_ManualAction(void)
  61. { static unsigned long CheckTime;
  62. if(bRunning == 0)
  63. {
  64. if(bClearTotal) //切断计数清零
  65. {
  66. bClearTotal = 0;
  67. ClrcToTal(CT_TOTAL_ADDR);
  68. }
  69. //手动分带
  70. if(CT_bFD)
  71. {
  72. CT_bFD = 0;
  73. CT_FenDai_VAVLE = ~CT_FenDai_VAVLE;
  74. }
  75. //手动下模
  76. if(CT_bXM)
  77. {
  78. CT_bXM = 0;
  79. if(CT_XiaMo_VAVLE)
  80. CT_XiaMo_VAVLE = 0;
  81. else if(CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE)
  82. CT_XiaMo_VAVLE = 1;
  83. else //下模输出条件警告
  84. {
  85. SetAlarmCode(CT_ALARM_ADDR,CT_XiaMo_out_ALARM); //横送料在原点才能输出
  86. }
  87. }
  88. if(CT_DZ_IN)
  89. CT_GouZhen_VAVLE = 1;
  90. if(CT_GUO_LIAN_IN_UP)
  91. CT_GouZhen_VAVLE = 0;
  92. //手动送料
  93. if(CT_bSL)
  94. {
  95. CT_bSL = 0;
  96. CT_SongLiao_VAVLE = ~CT_SongLiao_VAVLE;
  97. }
  98. // 手动合链
  99. if(CT_bHL)
  100. {
  101. CT_bHL = 0;
  102. CT_HeLian_VAVLE = ~CT_HeLian_VAVLE;
  103. }
  104. // 手动横送料
  105. if(CT_bHSL)
  106. {
  107. CT_bHSL = 0;
  108. if(CT_HangSongLiao_VAVLE)
  109. {
  110. CT_HangSongLiao_VAVLE = 0;
  111. } //送料电磁阀 接料电磁阀 下模电磁阀 保证没拉头
  112. else if(!CT_SongLiao_VAVLE && !CT_JieLiao_VAVLE && !CT_XiaMo_VAVLE && (!CT_MaGou_VAVLE || (CT_MaGou_VAVLE && CT_MG_IN)))
  113. {
  114. CT_MaGou_VAVLE = 0;
  115. CT_HangSongLiao_VAVLE = 1;
  116. }
  117. else //警告代码
  118. {
  119. if(CT_SongLiao_VAVLE)
  120. SetAlarmCode(CT_ALARM_ADDR,CT_SongLiao_VAVLE_Not_ALARM); //送料不能有输出
  121. else if(CT_JieLiao_VAVLE)
  122. SetAlarmCode(CT_ALARM_ADDR,CT_JieLiao_VAVLE_Not_ALARM); //接料不能有输出
  123. else if(CT_XiaMo_VAVLE)//下模不能有输出
  124. SetAlarmCode(CT_ALARM_ADDR,CT_XiaMo_VAVLE_Not_ALARM);
  125. else //已经有拉头
  126. SetAlarmCode(CT_ALARM_ADDR,CT_LaTuo_Not_ALARM); //不能有拉头
  127. }
  128. }
  129. //手动接料
  130. if(CT_bJL)
  131. {
  132. CT_bJL = 0;
  133. if(CT_JieLiao_VAVLE)
  134. {
  135. //如果接料输出后,没马勾或横送料已回到原位才能退
  136. if((!CT_HangSongLiao_VAVLE && CT_HSL_ORIGIN_IN) || !CT_MaGou_VAVLE)
  137. CT_JieLiao_VAVLE = 0;
  138. else //退接料警告
  139. {
  140. SetAlarmCode(CT_ALARM_ADDR,CT_TuiJieLiao_ALARM); //码勾输出情况下横送料要退回原点
  141. }
  142. }
  143. else if(!CT_MaGou_VAVLE || (CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE))
  144. {
  145. CT_JieLiao_VAVLE = 1;
  146. }
  147. else //接料警告
  148. {
  149. SetAlarmCode(CT_ALARM_ADDR,CT_JieLiao_out_ALARM); //码勾没输出或横送料在原点才能输出
  150. }
  151. }
  152. if(CT_bGM) //手动勾码
  153. {
  154. CT_bGM = 0;
  155. CT_MaGou_VAVLE = ~CT_MaGou_VAVLE;
  156. }
  157. if(CT_bHC) //手动护齿
  158. {
  159. CT_bHC = 0;
  160. CT_HuChi_VAVLE = ~CT_HuChi_VAVLE;
  161. }
  162. //手动装料
  163. if(CT_bZL)
  164. {
  165. CT_bZL = 0;
  166. if(CT_ZL_Step == 0)
  167. {
  168. cSongLiaoOk = 1;
  169. cZhuangLiaoOk = 0;
  170. CT_ZL_Step = 1;
  171. }
  172. }
  173. //
  174. //手动定位
  175. if(CT_bMotorDW)
  176. {
  177. CT_bMotorDW = 0;
  178. if(CT_MotorStep == 0)
  179. {
  180. if(!CT_FenDai_VAVLE)
  181. {
  182. CT_HuChi_VAVLE = 0;
  183. CT_HeLian_VAVLE = 0;
  184. CT_MotorStep = 1;
  185. }
  186. else
  187. {
  188. if(CT_FenDai_VAVLE) SetAlarmCode(CT_ALARM_ADDR,CT_FenDai_out_ALARM); //分带输出不能拖带
  189. //护链输出不能拖带
  190. }
  191. }
  192. }
  193. //自动装料
  194. if(CT_bZL)
  195. {
  196. CT_bZL = 0;
  197. if(CT_ZL_Step == 0)
  198. CT_ZL_Step = 1;
  199. }
  200. //合模 (半自动)
  201. if(CT_bHM)
  202. {
  203. CT_bHM = 0;
  204. if(CT_XiaMo_VAVLE && CT_FenDai_VAVLE)
  205. {
  206. CT_XiaMo_VAVLE = 0;
  207. CT_FenDai_VAVLE = 0;
  208. CT_HeLian_VAVLE = 0;
  209. CT_HuChi_VAVLE = 0;
  210. CT_JieLiao_VAVLE = 0;
  211. CT_MaGou_VAVLE = 0;
  212. CT_HeMoStep = 0;
  213. }
  214. else if(CT_HeMoStep == 0)
  215. {
  216. if(CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE)
  217. {
  218. CT_HeMoStep = 1;
  219. CT_MaGou_VAVLE = 1;
  220. CT_HeMoDelay = dwTickCount +70; //给码勾检测是否有拉头
  221. }
  222. else //合模条件不满足
  223. {
  224. SetAlarmCode(CT_ALARM_ADDR,CT_XiaMo_out_ALARM); //横送料在原点才能输出
  225. }
  226. }
  227. if(!CT_GUO_LIAN_IN)
  228. SetAlarmCode(CT_ALARM_ADDR,CT_Guo_Lian_IN_ALARM); //拉链在空位上容易爆链
  229. }
  230. //
  231. if(CT_bMotorH)
  232. {
  233. if(!X_DRV)AxisContinueMove(X_AXIS,20,CT_DIR_N);
  234. }
  235. if((QD_MotorStep == 0) && !CT_bMotorH && (CT_AutoStep == 0))
  236. {
  237. if(X_DRV)AxisEgmStop(X_AXIS);
  238. }
  239. //振动盘
  240. if(CT_bZDP)
  241. {
  242. CT_bZDP = 0;
  243. CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_STOP_TIME;
  244. CT_ZhenDongPian_OUT = 1;
  245. }
  246. }
  247. }
  248. void ChuanTou_AlarmProtect(void)
  249. {
  250. }
  251. //振动盘控制
  252. void ChuanTou_ZhenDongAction(void)
  253. {
  254. if((CT_bDLP || bRunning) && CT_ZhenDongPian_OUT && CT_PARAM_DALIAOPIAN)
  255. {
  256. if(CT_DLP_Time >= dwTickCount)
  257. {
  258. CT_ZDP_Delay = dwTickCount + CT_PARAM_DLP_TIME + 40;
  259. CT_DaLaPian_VAVLE = ~CT_DaLaPian_VAVLE;
  260. }
  261. }
  262. else
  263. CT_DaLaPian_VAVLE = 0;
  264. #if 1
  265. // if(bRunning)
  266. // {
  267. // if(CT_PARAM_ZDP_MODE)
  268. // {
  269. if(CT_ZhenDongPian_OUT == 0)
  270. {
  271. if(!CT_ZDP_IN)
  272. {
  273. CT_ZhenDongPian_OUT = 1;
  274. CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_STOP_TIME+ 50;
  275. }
  276. else
  277. {
  278. CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_START_TIME;
  279. }
  280. }
  281. else
  282. {
  283. if(CT_ZDP_IN)
  284. {
  285. if((dwTickCount >= CT_ZDP_Delay))
  286. {
  287. CT_ZhenDongPian_OUT = 0;
  288. }
  289. }
  290. else
  291. CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_STOP_TIME+ 50;
  292. }
  293. // }
  294. // else
  295. // {
  296. // if(CT_ZDP_IN_DW)CT_ZenDongPian_OUT = 0;
  297. // if(CT_ZDP_IN_UP)CT_ZenDongPian_OUT = 1;
  298. // }
  299. // }
  300. #if 0
  301. else
  302. {
  303. if(!CT_ZDP_IN && (CT_ZhenDongPian_OUT == 0))
  304. {
  305. CT_ZhenDongPian_OUT = 1;
  306. CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_TIME + 20;
  307. }
  308. if((dwTickCount >= CT_ZDP_Delay) && CT_ZhenDongPian_OUT)
  309. {
  310. CT_ZhenDongPian_OUT = 0;
  311. }
  312. }
  313. #endif
  314. #endif
  315. }
  316. //送料
  317. void ChuanTou_SongLiaoAction(void)
  318. {
  319. #if 1
  320. switch(CT_SL_Step)
  321. {
  322. case 1:
  323. if(cSongLiaoOk)
  324. {
  325. CT_SL_Step = 0;
  326. }
  327. else
  328. {
  329. // if(CT_PARAM_SL_MODE == 0)//横送模式
  330. // {
  331. CT_SL_Step = 2;
  332. CT_SL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  333. // }
  334. // else //直送料
  335. // {
  336. // ;
  337. // }
  338. }
  339. break;
  340. case 2:
  341. {
  342. //横送料必须保持在原位
  343. if(CT_HSL_ORIGIN_IN && !CT_HSL_LIMIT_IN && !CT_HangSongLiao_VAVLE)
  344. {
  345. CT_SongLiao_VAVLE = 1;
  346. CT_SL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  347. CT_SL_Step = 3;
  348. }
  349. else if(dwTickCount >= CT_SL_Delay)
  350. {
  351. if(!CT_HSL_ORIGIN_IN)CT_SetAlarmCode(CT_HSL_ORIGIN_ALARM);
  352. else if(CT_HSL_LIMIT_IN)CT_SetAlarmCode(CT_HSL_LIMIT_ALARM);
  353. else if(!CT_HangSongLiao_VAVLE)CT_SetAlarmCode(CT_HangSongLiao_Out_ALARM);
  354. }
  355. }
  356. break;
  357. case 3:
  358. {//送料离开原位
  359. if(!CT_SL_ORIGIN_IN)
  360. {
  361. CT_SL_Step = 4;
  362. CT_SL_Delay = dwTickCount + CT_PARAM_SL_DELAY_BACK;
  363. }
  364. else if(dwTickCount >= CT_SL_Delay)
  365. {
  366. CT_SetAlarmCode(CT_SL_ORIGIN_ALARM);
  367. }
  368. }break;
  369. case 4:
  370. {//送料时间到延时返回
  371. if(dwTickCount >= CT_SL_Delay)
  372. {
  373. CT_SongLiao_VAVLE = 0;
  374. CT_SL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  375. CT_SL_Step = 5;
  376. }
  377. }break;
  378. case 5:
  379. {
  380. if(CT_SL_ORIGIN_IN)
  381. {
  382. cSongLiaoOk = 1;
  383. CT_SL_Step = 0;
  384. }
  385. else if(dwTickCount >= CT_SL_Delay)
  386. {
  387. CT_SetAlarmCode(CT_SL_ORIGIN_ALARM);
  388. }
  389. }
  390. break;
  391. }
  392. #endif
  393. }
  394. //横送料
  395. void ChuanTou_HengSongLiao_Action(void)
  396. {
  397. #if 1
  398. switch(CT_HSL_Step)
  399. {
  400. case 1:
  401. {//送料,下模,马勾在原位,电磁阀不能有输出
  402. if(CT_SL_ORIGIN_IN && CT_XM_ORIGIN_IN && !CT_JieLiao_VAVLE && !CT_XiaMo_VAVLE)
  403. {
  404. CT_HSL_Step = 2;
  405. CT_MaGou_VAVLE = 0; //马勾自动打开
  406. CT_JieLiao_VAVLE = 0; //接料也要关掉
  407. }
  408. else if(!bRunning)
  409. {
  410. CT_HSL_Step = 0;
  411. }
  412. }
  413. break;
  414. case 2:
  415. if(CT_SL_Step == 0)
  416. {
  417. CT_HangSongLiao_VAVLE = 1;
  418. CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  419. CT_HSL_Step = 3;
  420. }
  421. break;
  422. case 3:
  423. {
  424. if(CT_HSL_LIMIT_IN)
  425. {
  426. //横送到位延接料,等待拉片稳定
  427. CT_HSL_Delay = dwTickCount + CT_PARAM_JIELIAO_DELAY;
  428. CT_HSL_Step = 4;
  429. }
  430. else if(dwTickCount >= CT_HSL_Delay) //横送料到位异常
  431. {
  432. CT_SetAlarmCode(CT_HSL_LIMIT_ALARM);
  433. }
  434. }
  435. break;
  436. case 4:
  437. if(dwTickCount >= CT_HSL_Delay)
  438. {
  439. CT_HSL_Step = 5;
  440. CT_JieLiao_VAVLE = 1; //接料输出上升
  441. CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  442. }
  443. break;
  444. case 5:
  445. {
  446. if(!CT_XM_ORIGIN_IN)//下模离开后,延时输出马勾
  447. {
  448. cSongLiaoOk = 0;
  449. CT_HSL_Delay = dwTickCount + CT_PARAM_GJ_TIME; //延时码勾输出
  450. CT_HSL_Step = 6;
  451. }
  452. else if(dwTickCount >= CT_HSL_Delay) //下模没法离开,电磁阀没有输出
  453. {
  454. CT_HSL_Step = 0;
  455. CT_SetAlarmCode(CT_XM_ORIGIN_ALARM);
  456. }
  457. }
  458. break;
  459. case 6:
  460. if(dwTickCount >= CT_HSL_Delay)
  461. {
  462. CT_MaGou_VAVLE = 1;
  463. CT_HSL_Delay = dwTickCount + CT_PARAM_HSL_BACK_DELAY;
  464. CT_HSL_Step = 7;
  465. }
  466. break;
  467. case 7:
  468. if(dwTickCount >= CT_HSL_Delay) //码勾输出后横送料退
  469. {
  470. CT_HangSongLiao_VAVLE = 0;
  471. CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  472. CT_HSL_Step = 8;
  473. CT_SL_Step = 1;
  474. }
  475. break;
  476. case 8://横送料退回
  477. if(CT_HSL_ORIGIN_IN && !CT_HSL_LIMIT_IN)
  478. {
  479. CT_HSL_Step = 0;
  480. }
  481. else if(dwTickCount >= CT_HSL_Delay)
  482. {
  483. CT_SetAlarmCode(CT_HSL_ORIGIN_ALARM);
  484. }
  485. break;
  486. case 9:
  487. break;
  488. }
  489. #endif
  490. }
  491. //装料
  492. void ChuanTou_ZhuangLiaoStep(void)
  493. {
  494. #if 1
  495. switch(CT_ZL_Step)
  496. {
  497. case 1:
  498. {
  499. if(cZhuangLiaoOk || (CT_MaGou_VAVLE && !CT_MG_IN))
  500. {
  501. CT_ZL_Step = 0;
  502. cZhuangLiaoOk = 1;
  503. }
  504. else
  505. {
  506. CT_ZL_Delay = dwTickCount + VAVLE_ALARM_TIME;
  507. CT_ZL_Step = 2;
  508. cZLCnt = 0;
  509. CT_ZL_Delay = dwTickCount + 60;
  510. cSongLiaoOk = 1;
  511. CT_MaGou_VAVLE = 1;
  512. }
  513. }
  514. break;
  515. case 2:
  516. if((dwTickCount >= CT_ZL_Delay) || CT_MG_IN)
  517. {
  518. // if(CT_SL_Step == 0)
  519. // CT_SL_Step = 1;
  520. CT_ZL_Step = 3;
  521. if(CT_MaGou_VAVLE && !CT_MG_IN)
  522. {
  523. CT_ZL_Step = 0;
  524. cZhuangLiaoOk = 1;
  525. }
  526. }
  527. break;
  528. case 3:
  529. {
  530. if(CT_SL_Step == 0)
  531. {
  532. CT_ZL_Step = 4;
  533. CT_HSL_Step = 1;
  534. }
  535. }
  536. break;
  537. case 4:
  538. {
  539. if(CT_HSL_Step == 0)
  540. {
  541. CT_ZL_Step = 0;
  542. cZhuangLiaoOk = 1;
  543. if(CT_MG_IN && CT_MaGou_VAVLE)
  544. {
  545. cZhuangLiaoOk = 0;
  546. CT_MaGou_VAVLE = 0;
  547. CT_JieLiao_VAVLE = 0;
  548. CT_ZL_Delay = dwTickCount + 600;
  549. cZLCnt++;
  550. if(cZLCnt>= 3)
  551. {
  552. CT_ZL_Delay = dwTickCount + 0;
  553. CT_ZL_Step = 0;
  554. CT_SetAlarmCode(CT_ZhuangLiao_ALARM);
  555. }
  556. else
  557. CT_ZL_Step = 2;
  558. }
  559. }
  560. }
  561. break;
  562. default:break;
  563. }
  564. #endif
  565. }
  566. //合模动作
  567. void ChuanTou_HeMo(void)
  568. {
  569. switch(CT_HeMoStep)
  570. {
  571. case 1:
  572. if(CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE && !CT_HSL_LIMIT_IN && (dwTickCount >= CT_HeMoDelay))
  573. {
  574. CT_HeMoStep = 2;
  575. if(CT_MaGou_VAVLE)
  576. {
  577. if(CT_MG_IN)
  578. {
  579. cZhuangLiaoOk = 0;
  580. CT_MaGou_VAVLE = 0;
  581. }
  582. }
  583. else
  584. {
  585. CT_MaGou_VAVLE = 1;
  586. }
  587. CT_ZL_Step = 1;
  588. CT_HuChi_VAVLE = 1;
  589. if(!bRunning || (dwZipCnt <= 2))
  590. CT_HeMoDelay = dwTickCount +70; //给码勾检测是否有拉头
  591. else
  592. CT_HeMoDelay = dwTickCount +CT_PARAM_FD_DELAY; //延时分带
  593. if((CT_PARAM_HouMa_MODE != HouMa_MODE_YOUHOUMA)) //有后码时不能有输出
  594. {
  595. CT_HeLian_VAVLE = 1;
  596. if(bRunning)
  597. CT_HeMoDelay = dwTickCount; //
  598. }
  599. CT_ZL_Step = 1;
  600. }
  601. break;
  602. case 2:
  603. if(dwTickCount >= CT_HeMoDelay)
  604. {
  605. CT_HeMoStep = 3;
  606. CT_FenDai_VAVLE = 1; //
  607. CT_HeMoDelay = dwTickCount +VAVLE_ALARM_TIME; //延时分带
  608. if(CT_MG_IN)
  609. {
  610. cZhuangLiaoOk = 0;
  611. CT_MaGou_VAVLE = 0;
  612. if(CT_ZL_Step == 0)
  613. CT_ZL_Step = 1;
  614. }
  615. }
  616. break;
  617. case 3:
  618. if(CT_FD_IN)
  619. {
  620. //装已经完成或在手动情况下
  621. if(cZhuangLiaoOk && !CT_MG_IN)
  622. {
  623. if(CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE && !CT_HSL_LIMIT_IN)
  624. {
  625. CT_HeMoStep = 4;
  626. CT_XiaMo_VAVLE = 1;
  627. CT_HeMoDelay = dwTickCount + 50; //延时退接料
  628. }
  629. }
  630. else if(CT_MaGou_VAVLE && CT_MG_IN)
  631. {
  632. if(CT_ZL_Step == 0)
  633. {
  634. CT_MaGou_VAVLE = 0;
  635. CT_ZL_Step = 2;
  636. CT_ZL_Delay = dwTickCount + 0;
  637. }
  638. }
  639. }
  640. else if(dwTickCount >= CT_HeMoDelay)
  641. {
  642. if(bRunning)
  643. {
  644. CT_SetAlarmCode(CT_FD_IN_ALARM);
  645. CT_HeMoStep = 0;
  646. }
  647. }
  648. break;
  649. case 4:
  650. if(dwTickCount >= CT_HeMoDelay)
  651. CT_JieLiao_VAVLE = 0;
  652. //下模离开原点,拉头顶到顶针处,或手动
  653. if(!CT_XM_ORIGIN_IN && CT_DZ_IN)
  654. {
  655. CT_HeMoStep = 5;
  656. CT_JieLiao_VAVLE = 0;
  657. CT_GouZhen_VAVLE = 1;
  658. CT_HeMoDelay = dwTickCount + 20; //退勾针延时拖带
  659. }
  660. break;
  661. case 5:
  662. if(dwTickCount >= CT_HeMoDelay)
  663. {
  664. CT_HeMoStep = 0;
  665. }
  666. break;
  667. }
  668. }
  669. void ChuanTou_CLT_Step(void)
  670. {
  671. static long xm_buff;
  672. long ch;
  673. #if 1
  674. switch(CT_CLT_Step)
  675. {
  676. case 1:
  677. SetPos(X_AXIS, 0); //开始穿入位为零点
  678. dwRealPos = GetPos(X_AXIS);
  679. CT_CLT_Step = 2;
  680. break;
  681. case 2:
  682. //两段速度移动距离
  683. // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
  684. // AxisMoveTwoPos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,QD_PARAM_SJZ_LENGTH,5000,QD_PARAM_BACK_LENGTH,QD_DIR_P);
  685. AxisMovePosAccDec(X_AXIS,CT_PARAM_CR_SPEED,CT_PARAM_CR_LENGTH + 230 - CT_PARAM_STOP_LENGTH ,3000,8,12);
  686. // SetDir(X_AXIS, CT_DIR_P);
  687. CT_HuChi_VAVLE = 0;
  688. CT_CLT_Step = 3;
  689. xm_buff = 0;
  690. cMotorDinWei_OK = 0;
  691. break;
  692. case 3:
  693. //穿入过程,检测到空位
  694. if(CT_GUO_LIAN_IN_DW)
  695. {
  696. xm_buff = 0;
  697. CancelPmoveState(X_AXIS);
  698. AxisChangeSpeed(X_AXIS,CT_PARAM_LSPEED);
  699. }
  700. //在上升沿
  701. if(CT_GUO_LIAN_IN_UP)
  702. {
  703. xm_buff = dwRealPos;
  704. AxisEgmStop(X_AXIS);
  705. }
  706. //根据后码模式退合链
  707. if(CT_PARAM_HouMa_MODE == HouMa_MODE_DANKUAI)
  708. {
  709. if(dwRealPos >= CT_PARAM_TUIHELIAN_DELAY)
  710. CT_HeLian_VAVLE = 0;
  711. }
  712. //退分带动作//提前8MM退分带 或退长度到
  713. if(((dwRealPos + 80) >= CT_PARAM_CR_LENGTH) || (dwRealPos >= CT_PARAM_TUIFENGDAI_DELAY))
  714. CT_FenDai_VAVLE = 0;
  715. if((dwRealPos + 35) >= CT_PARAM_CR_LENGTH)
  716. {
  717. CT_MaGou_VAVLE = 0;
  718. }
  719. if((dwRealPos) >= CT_PARAM_CR_LENGTH)
  720. {
  721. AxisEgmStop(X_AXIS);
  722. }
  723. //穿入长度到
  724. if(!X_DRV)
  725. {//如果无后码单开模式长度过长时也强制打开 //双闭口要先慢速退
  726. if((CT_PARAM_HouMa_MODE == HouMa_MODE_DANKUAI) ||
  727. ((CT_PARAM_HouMa_MODE == HouMa_MODE_SHUANGBI) && (CT_PARAM_TUIHELIAN_DELAY == 0)))
  728. {
  729. CT_HeLian_VAVLE = 0; //合链关
  730. }
  731. CT_FenDai_VAVLE = 0; //分带关
  732. CT_XiaMo_VAVLE = 0; //下模关
  733. CT_MaGou_VAVLE = 0; //码勾关
  734. CT_CLT_Step = 4;
  735. }
  736. break;
  737. case 4:
  738. if(!CT_DZ_IN)
  739. {
  740. CT_CLT_Delay = dwTickCount + CT_PARAM_XM_BACK_DELAY_START;
  741. CT_CLT_Step = 5;
  742. }
  743. break;
  744. case 5:
  745. //下模退回
  746. if(((dwTickCount >= CT_CLT_Delay) || CT_XM_ORIGIN_IN) && !CT_FD_IN)
  747. {
  748. CT_ZL_Step = 2; //重装料
  749. cZLCnt = 0;
  750. CT_ZL_Delay = dwTickCount + 0;
  751. CT_MaGou_VAVLE = 0; //码勾输出检测拉头是否脱离模具
  752. if(xm_buff) //已经检测到拉链
  753. {
  754. CT_CLT_Step = 8;
  755. CT_MotorStep = 50; //只走定位长度步
  756. }
  757. else //没有检测到拉链
  758. {
  759. if((CT_PARAM_HouMa_MODE == HouMa_MODE_SHUANGBI) && CT_HeLian_VAVLE) //双闭口要先慢速退
  760. {
  761. xm_buff = dwRealPos;
  762. CT_CLT_Step = 6;
  763. ch = 1400;
  764. SetStartSpeed(X_AXIS,ch);
  765. if((Zipper_Length > (dwRealPos + 2000)) && (dwZipCnt > 2))
  766. {
  767. AxisContinueMove(X_AXIS,(CT_PARAM_HSPEED + CT_PARAM_HSPEED/3),CT_DIR_N); //主要生成高速表
  768. }
  769. else
  770. AxisContinueMove(X_AXIS,(CT_PARAM_HSPEED),CT_DIR_N);//主要生成高速表
  771. //低速走长度给合链退回争取时间,快转碰拉头,损坏拉链
  772. AxisChangeSpeed(X_AXIS,ch);
  773. //也进入过链检测状态
  774. CT_MotorStep = 3;
  775. CT_MotorDelay = dwTickCount + 0;
  776. }
  777. else
  778. {
  779. CT_CLT_Step = 8;
  780. CT_CLT_Delay = dwTickCount + 0;
  781. }
  782. }
  783. }
  784. break;
  785. case 6:
  786. ch = CT_PARAM_TUIHELIAN_DELAY;
  787. if(ch > 30) //最长限制1.5CM
  788. ch = 28;
  789. // if(dwRealPos >= (xm_buff + ch))
  790. {
  791. CT_HeLian_VAVLE = 0;
  792. CT_CLT_Delay = dwTickCount + 30; //延时时间再加速
  793. CT_CLT_Step = 7;
  794. }
  795. break;
  796. case 7:
  797. if(dwTickCount >= CT_CLT_Delay)
  798. {
  799. if(CT_MotorStep == 3) //如果电机还在检测拉链状态,就到变速程序
  800. CT_MotorStep = 40;
  801. CT_CLT_Step = 8;
  802. }
  803. break;
  804. case 8:
  805. CT_CLT_Step = 0;
  806. if((CT_MotorStep == 0) && (cMotorDinWei_OK == 0))
  807. CT_MotorStep = 1;
  808. break;
  809. }
  810. #endif
  811. }
  812. void ChuanTou_AutoAction(void)
  813. {
  814. if(bRunning)
  815. {
  816. #if 1
  817. switch(CT_AutoStep)
  818. {
  819. case 1:
  820. if(dwTickCount >= CT_AutoDelay)
  821. {
  822. CT_AutoStep = 2;
  823. if(CT_MotorStep == 0)
  824. {
  825. CT_MotorStep = 1;
  826. }
  827. }
  828. break;
  829. case 2:
  830. if(CT_MotorStep == 0) //电机定位完成
  831. {
  832. if(SingOneFlg) //当为单一自动时,装料
  833. {
  834. bRunning = 0;
  835. CT_AutoStep = 0;
  836. }
  837. else
  838. {
  839. if(dwZipCnt == 2)
  840. Zipper_Length = dwRealPos;
  841. CT_AutoStep = 3;
  842. CT_HeMoStep = 1;
  843. }
  844. }
  845. break;
  846. case 3:
  847. if((CT_MotorStep == 0) && (CT_HeMoStep == 0))
  848. {
  849. CT_CLT_Step = 1;
  850. CT_AutoStep = 4;
  851. }
  852. break;
  853. case 4:
  854. if(CT_CLT_Step >= 3)
  855. {
  856. AddToTal(CT_TOTAL_ADDR);
  857. AddToTal(CT_WORKTOTAL_ADDR);
  858. CalProSP(CT_PROSPEED_ADDR);
  859. CT_AutoStep = 5;
  860. }
  861. break;
  862. case 5:
  863. if(CT_CLT_Step == 0)
  864. {
  865. dwZipCnt++;
  866. dwZipCnt &= 7;
  867. CT_AutoStep = 1;
  868. CT_AutoDelay = dwTickCount + 0;
  869. }
  870. break;
  871. }
  872. #endif
  873. }
  874. }
  875. void ChuanTou_StepCheckStart(void)
  876. {
  877. // 启动
  878. if((CT_START_IN_UP) || bStart || CT_bSingle)
  879. {
  880. bStart = 0;
  881. #if 1
  882. if(!bRunning && (CT_AutoStep == 0))
  883. {
  884. if(!CT_HSL_ORIGIN_IN)CT_SetAlarmCode(CT_HSL_ORIGIN_ALARM);
  885. else if(CT_HSL_LIMIT_IN)CT_SetAlarmCode(CT_HSL_LIMIT_ALARM);
  886. else if(!CT_SL_ORIGIN_IN)CT_SetAlarmCode(CT_SL_ORIGIN_ALARM);
  887. {
  888. bRunning = 1;
  889. SetEn(X_AXIS,CT_MOTOR_EN);
  890. CT_AutoStep = 3;
  891. CT_HeMoStep = 1;
  892. // if(!cZhuangLiaoOk)
  893. // CT_ZL_Step = 1;
  894. SingOneFlg= 0;
  895. if(CT_bSingle) SingOneFlg= 1;
  896. dwZipCnt = 0;
  897. Zipper_Length = 0;
  898. CT_AutoDelay = dwTickCount + 30;
  899. CT_HeMoDelay = dwTickCount +70;
  900. CT_MaGou_VAVLE = 1;
  901. cZLCnt = 0;
  902. SetAlarmCode(CT_ALARM_ADDR,0);
  903. }
  904. }
  905. CT_bSingle = 0;
  906. #endif
  907. }
  908. #if 1
  909. //停止
  910. if(CT_STOP_IN_UP || bStop)
  911. {
  912. bStop = 0;
  913. if(bRunning)
  914. {
  915. bRunning = 0;
  916. CT_AutoStep = 0;
  917. CT_MotorStep = 0;
  918. CT_AutoDelay = dwTickCount;
  919. CT_MotorDelay = dwTickCount;
  920. AxisDecStop(X_AXIS);
  921. SingOneFlg = 0;
  922. }
  923. else
  924. {
  925. bRunning = 0;
  926. CT_AutoStep = 0;
  927. CT_MotorStep = 0;
  928. CT_HeMoStep = 0;
  929. CT_SL_Step = 0;
  930. CT_HSL_Step = 0;
  931. CT_ZL_Step = 0;
  932. CT_CLT_Step = 0;
  933. CT_ZD_Step = 0;
  934. CT_AutoDelay = dwTickCount;
  935. CT_MotorDelay = dwTickCount;
  936. CT_HeMoDelay = dwTickCount;
  937. CT_SL_Delay = dwTickCount;
  938. CT_HSL_Delay = dwTickCount;
  939. CT_ZL_Delay = dwTickCount;
  940. CT_XM_BACK_Delay = dwTickCount;
  941. CT_CLT_Delay = dwTickCount;
  942. CT_ZDP_Delay = dwTickCount;
  943. SingOneFlg = 0;
  944. AxisDecStop(X_AXIS);
  945. SetEn(X_AXIS,CT_MOTOR_DISEN);
  946. cSongLiaoOk = 0;
  947. cZhuangLiaoOk = 0;
  948. CT_XiaMo_VAVLE = 0; //下模
  949. CT_SongLiao_VAVLE = 0; //送料
  950. CT_GouZhen_VAVLE = 0; //勾针
  951. CT_DaLaPian_VAVLE = 0; //顶拉片(打拉片)
  952. CT_FenDai_VAVLE = 0; //分带
  953. CT_HeLian_VAVLE = 0; //合链(穿模后面)
  954. CT_ZhenDongPian_OUT = 0; //振动盘
  955. CT_HuChi_VAVLE = 0; //护齿
  956. CT_HangSongLiao_VAVLE = 0; //横送料
  957. if(!CT_MaGou_VAVLE || (CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE))
  958. CT_JieLiao_VAVLE = 0; //接料下模
  959. CT_MaGou_VAVLE = 0; //马勾
  960. SetAlarmCode(CT_ALARM_ADDR,0);
  961. }
  962. }
  963. #endif
  964. #if 1
  965. if(bAlarmStop)
  966. {
  967. bAlarmStop = 0;
  968. bRunning = 0;
  969. CT_AutoStep = 0;
  970. // CT_MotorStep = 0;
  971. CT_HeMoStep = 0;
  972. CT_ZL_Step = 0;
  973. CT_HSL_Step = 0;
  974. CT_AutoDelay = dwTickCount;
  975. CT_MotorDelay = dwTickCount;
  976. SingOneFlg = 0;
  977. AxisEgmStop(X_AXIS);
  978. }
  979. #endif
  980. }
  981. //电机动作
  982. //第1~10前拖带定位
  983. //
  984. void ChuanTou_Motor(void) //
  985. {
  986. static long back_buff,save_buff;
  987. unsigned short ch;
  988. switch(CT_MotorStep)
  989. {
  990. case 0:
  991. break;
  992. //拖带定位动作
  993. case 1:
  994. if(cMotorDinWei_OK && bRunning)
  995. {
  996. CT_MotorStep = 0;
  997. break;
  998. }
  999. else
  1000. {
  1001. cMotorDinWei_OK = 0;
  1002. if(!GetEn(X_AXIS))
  1003. {
  1004. SetEn(X_AXIS,CT_MOTOR_EN);
  1005. // CT_SZ_OUT = CT_MOTOR_Y_EN;
  1006. CT_MotorDelay = dwTickCount + 150;
  1007. }
  1008. else
  1009. CT_MotorDelay = dwTickCount + 0;
  1010. SetDir(X_AXIS, CT_DIR_N);
  1011. CT_GouZhen_VAVLE = 1;
  1012. CT_MotorStep = 2;
  1013. }
  1014. break;
  1015. case 2:
  1016. if(dwTickCount >= CT_MotorDelay)
  1017. {
  1018. save_buff = dwRealPos;
  1019. SetDir(X_AXIS, CT_DIR_P);
  1020. ch = CT_PARAM_HSPEED;
  1021. SetDir(X_AXIS, CT_DIR_N);
  1022. if((Zipper_Length > dwRealPos + 2000) && (dwZipCnt > 2))
  1023. {
  1024. ch += CT_PARAM_HSPEED/3;
  1025. CT_MotorStep = 4;
  1026. }
  1027. else
  1028. CT_MotorStep = 3;
  1029. if(!X_DRV)
  1030. AxisContinueMove(X_AXIS,ch,CT_DIR_N);
  1031. }
  1032. break;
  1033. case 3: //不用变速
  1034. if(!CT_GUO_LIAN_IN)
  1035. {
  1036. back_buff = dwRealPos;
  1037. user_datas[127] = dwRealPos;//ch;
  1038. AxisChangeSpeed(X_AXIS,CT_PARAM_LSPEED);
  1039. CT_MotorStep = 5;
  1040. CT_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1041. }
  1042. else if(((dwRealPos - save_buff) >= CT_PARAM_MAX_LENGTH) && bRunning && CT_PARAM_MAX_LENGTH) //拖带拉链最大长度
  1043. {
  1044. CT_SetAlarmCode(CT_ZIPPER_MAXLENGHT_ALARM); //拉链长度保护
  1045. CT_MotorStep = 0;
  1046. }
  1047. break;
  1048. case 4://到空位
  1049. if(((dwRealPos + 1700) >= Zipper_Length) && Zipper_Length && (dwZipCnt > 2) && (CT_CLT_Step== 0))
  1050. {
  1051. AxisChangeSpeed(X_AXIS,CT_PARAM_HSPEED);
  1052. }
  1053. if(!CT_GUO_LIAN_IN)
  1054. {
  1055. back_buff = dwRealPos;
  1056. user_datas[127] = dwRealPos;//ch;
  1057. AxisChangeSpeed(X_AXIS,CT_PARAM_LSPEED);
  1058. CT_MotorStep = 5;
  1059. CT_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1060. }
  1061. else if(((dwRealPos - save_buff) >= CT_PARAM_MAX_LENGTH) && bRunning && CT_PARAM_MAX_LENGTH) //拖带拉链最大长度
  1062. {
  1063. CT_SetAlarmCode(CT_ZIPPER_MAXLENGHT_ALARM); //拉链长度保护
  1064. CT_MotorStep = 0;
  1065. }
  1066. break;
  1067. case 5:
  1068. if(CT_GUO_LIAN_IN_UP)
  1069. {
  1070. back_buff = dwRealPos;
  1071. AxisChangeSpeed(X_AXIS,CT_PARAM_LSPEED/2);
  1072. CT_MotorStep = 6;
  1073. }
  1074. else if(dwTickCount >= CT_MotorDelay)//(dwRealPos - back_buff) >= 4500) //空位走25公分停止
  1075. {
  1076. CT_SetAlarmCode(CT_NO_ZIPPER_ALARM);
  1077. CT_MotorStep = 0;
  1078. }
  1079. break;
  1080. case 6:
  1081. //延迟上勾针
  1082. if((dwRealPos - back_buff) >= CT_PARAM_GZ_LENGTH)
  1083. {
  1084. CT_GouZhen_VAVLE = 0;
  1085. if((CT_PARAM_HouMa_MODE == HouMa_MODE_DANKUAI) ||
  1086. (CT_PARAM_HouMa_MODE == HouMa_MODE_SHUANGBI) )
  1087. {
  1088. CT_HeLian_VAVLE = 1; //合链关
  1089. }
  1090. }
  1091. //定位长度
  1092. if((dwRealPos - back_buff) >= CT_PARAM_STOP_LENGTH)
  1093. {
  1094. CT_GouZhen_VAVLE = 0;
  1095. AxisEgmStop(X_AXIS);
  1096. CT_MotorStep = 7;
  1097. if((CT_PARAM_HouMa_MODE == HouMa_MODE_DANKUAI) ||
  1098. (CT_PARAM_HouMa_MODE == HouMa_MODE_SHUANGBI) )
  1099. {
  1100. CT_HeLian_VAVLE = 1; //合链关
  1101. }
  1102. }
  1103. break;
  1104. case 7:
  1105. if(!X_DRV)
  1106. {
  1107. CT_MotorStep = 0;
  1108. cMotorDinWei_OK = 1;
  1109. }
  1110. break;
  1111. case 40:
  1112. save_buff = 0;
  1113. ch = CT_PARAM_HSPEED;
  1114. if((Zipper_Length > (dwRealPos + 1800)) && (dwZipCnt > 2))
  1115. {
  1116. ch += CT_PARAM_HSPEED/3;
  1117. CT_MotorStep = 4;
  1118. }
  1119. else
  1120. CT_MotorStep = 3;
  1121. user_datas[125] = ch;
  1122. user_datas[126] = Zipper_Length;
  1123. user_datas[128] = dwRealPos;
  1124. AxisChangeSpeed(X_AXIS,ch);
  1125. break;
  1126. case 50: //此步为穿链时已经检测到拉链上升沿
  1127. back_buff = dwRealPos;
  1128. SetStartSpeed(X_AXIS,CT_PARAM_LSPEED/2);
  1129. AxisContinueMove(X_AXIS,CT_PARAM_LSPEED/2,CT_DIR_N);
  1130. CT_MotorStep = 6;
  1131. break;
  1132. /*
  1133. //穿入动作
  1134. case 100: //穿入电机慢慢复位动作
  1135. CT_MotorStep = 101;
  1136. break;
  1137. case 101:
  1138. if(CT_CR_ORIGIN_IN)
  1139. {
  1140. AxisDecStop(Y_AXIS);
  1141. CT_MotorStep = 102;
  1142. }
  1143. else if(dwTickCount >= CT_MotorDelay)
  1144. CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
  1145. break;
  1146. case 102:
  1147. if(!Y_DRV)
  1148. {
  1149. CT_MotorStep = 0;
  1150. }
  1151. break;
  1152. */
  1153. }
  1154. }
  1155. #endif