YXBKQueDuanJi.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. #include "global.h"
  2. #if FJ_YING_XING_MACHINE ==1
  3. void BK_QueDuan_AlarmProtect(void);
  4. void BK_QueDuan_ManualAction(void);
  5. void BK_QueDuan_AutoAction(void);
  6. void BK_QueDuan_StepCheckStart(void);
  7. void BK_QueDuan_XiaQue(void);
  8. void BK_QueDuan_Motor_NoGL(void);
  9. void BK_QueDuan_YuanDianAction(void);
  10. void BK_QueDuan_TuiLianAction(void);
  11. void BK_QueDuan_ExtiActionX31(void);
  12. void BK_QueDuan_BingLian(void);
  13. void BKQD_TuiDaiAction(void);
  14. short *length_buffer;
  15. void BK_QueDuan_ExtiActionX31(void)
  16. {
  17. cCheckLianFlg = 1;
  18. }
  19. void BKQD_SetAlarmCode(unsigned alarm_code)
  20. {
  21. SetAlarmCode(BKQD_ALARM_ADDR,alarm_code);
  22. bAlarmStop = 1;
  23. }
  24. void BK_QueDuan_InitAction(void)
  25. {
  26. float length_buff,pulse_buff;
  27. length_buff = BKQD_PARAM_CYCLE_LENGTH;
  28. pulse_buff = BKQD_PARAM_CYCLE_PULSE;
  29. XGearRatio = pulse_buff/length_buff;
  30. SetDirReverse(X_AXIS, 1);
  31. // BKQD_SZ_OUT = 1;
  32. }
  33. void BK_QueDuan_Action(void)
  34. {
  35. BK_QueDuan_AlarmProtect();
  36. BK_QueDuan_Motor_NoGL();
  37. BK_QueDuan_XiaQue();
  38. BK_QueDuan_ManualAction();
  39. BK_QueDuan_TuiLianAction();
  40. BK_QueDuan_BingLian();
  41. BK_QueDuan_AutoAction();
  42. BK_QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
  43. }
  44. //手动动作
  45. void BK_QueDuan_ManualAction(void)
  46. {
  47. //条数或扎数达到后,台面电机转两秒之后再停机
  48. if(cTABLETIME)
  49. {
  50. if(cTABLETOTAL)
  51. {
  52. cTABLETOTAL=0;
  53. BKQD_TABLE_VAVLE = 1;
  54. BKQD_TableDelay=dwTickCount + 2000;
  55. }
  56. if(dwTickCount >= BKQD_TableDelay)
  57. {
  58. BKQD_TABLE_VAVLE = 0;
  59. cTABLETIME=0;
  60. }
  61. }
  62. if(bRunning == 0)
  63. {
  64. cGoLimitEn = 0;
  65. if(BKQD_bClearTotal) //切断计数清零
  66. {
  67. BKQD_bClearTotal = 0;
  68. ClrcToTal(BKQD_TOTAL_ADDR);
  69. }
  70. if(BKQD_bClearNowTotal)
  71. {
  72. BKQD_bClearNowTotal = 0;
  73. BKQD_PARAM_NOW_CNT = 0;
  74. }
  75. if(BKQD_bXiaQie)
  76. {
  77. BKQD_bXiaQie = 0;
  78. if((BKQD_XiaQieStep == 0) && !BKQD_TL_VAVLE)
  79. {
  80. BKQD_XiaQieStep = 1;
  81. }
  82. }
  83. if(BKQD_bQianDianDW)
  84. {
  85. BKQD_bQianDianDW = 0;
  86. if(BKQD_MotorStep == 0)
  87. {
  88. BKQD_MotorStep = 61;
  89. cZipCnt = 0;
  90. }
  91. }
  92. if(BKQD_bTL)
  93. {
  94. BKQD_bTL = 0;
  95. if(BKQD_TL_VAVLE)
  96. {
  97. BKQD_TL_VAVLE = 0;
  98. }
  99. else if(!BKQD_GZ_VAVLE && !BKQD_SM_VAVLE)
  100. {
  101. BKQD_TL_VAVLE = ~BKQD_TL_VAVLE;
  102. }
  103. }
  104. // if(!Y_DRV)BKQD_bTL = 0;
  105. if(BKQD_bYD)
  106. {
  107. BKQD_bYD = 0;
  108. BKQD_YD_VAVLE = ~BKQD_YD_VAVLE;
  109. }
  110. if(BKQD_bGZ)
  111. {
  112. BKQD_bGZ = 0;
  113. BKQD_GZ_VAVLE = ~BKQD_GZ_VAVLE;
  114. }
  115. if(BKQD_bJD)
  116. {
  117. BKQD_bJD = 0;
  118. BKQD_JD_VAVLE = ~BKQD_JD_VAVLE;
  119. }
  120. if(BKQD_bXM)
  121. {
  122. BKQD_bXM = 0;
  123. BKQD_XM_VAVLE = ~BKQD_XM_VAVLE;
  124. if(!BKQD_XM_VAVLE)BKQD_GZ_VAVLE = 0;
  125. }
  126. if(BKQD_bSM)
  127. {
  128. BKQD_bSM = 0;
  129. if(BKQD_SM_VAVLE)
  130. BKQD_SM_VAVLE = 0;
  131. else if(!BKQD_TL_VAVLE)
  132. BKQD_SM_VAVLE = 1;
  133. }
  134. //推方块
  135. if(BKQD_bTFK)
  136. {
  137. BKQD_bTFK = 0;
  138. BKQD_TFK_VAVLE = ~BKQD_TFK_VAVLE;
  139. }
  140. //台面电机
  141. if(BKQD_bTB)
  142. {
  143. BKQD_bTB = 0;
  144. BKQD_TABLE_VAVLE = ~BKQD_TABLE_VAVLE;
  145. }
  146. if(BKQD_bTestCS)
  147. {
  148. BKQD_bTestCS = 0;
  149. BKQD_CS_OUT = 1;
  150. BKQD_CSDelay = dwTickCount + BKQD_PARAM_CS_TIME;
  151. }
  152. if(BKQD_bBL)//合链
  153. {
  154. BKQD_bBL = 0;
  155. BKQD_BL_VAVLE = ~BKQD_BL_VAVLE;
  156. }
  157. if(BKQD_bHL) //护链,双开用
  158. {
  159. BKQD_bHL = 0;
  160. BKQD_HL_VAVLE = ~BKQD_HL_VAVLE;
  161. }
  162. if(BKQD_bYX)
  163. {
  164. BKQD_bYX = 0;
  165. BKQD_YX_VAVLE = ~BKQD_YX_VAVLE;
  166. }
  167. if(BKQD_XiaQieStep == 0)
  168. {
  169. if(dwTickCount >= BKQD_CSDelay)BKQD_CS_OUT = 0;
  170. }
  171. //电机控制
  172. if(BKQD_bGoMotor && !BKQD_QIAN_LIMIT_IN)
  173. {
  174. BKQD_SZ_OUT = 0;
  175. // BKQD_JZ_DIR = BKQD_YDIR_N;
  176. if(!X_DRV)
  177. // X轴 运行速度 启动速度 加速度 减速度
  178. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED,BKQD_PARAM_GO_LOW_SPEED,10,12);
  179. }
  180. if(BKQD_bBackMotor) //后退限位已经取消
  181. {
  182. BKQD_SZ_OUT = 0;
  183. // BKQD_JZ_DIR = BKQD_YDIR_P;
  184. if(!X_DRV)
  185. // X轴 运行速度 启动速度 加速度 减速度
  186. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_P,BKQD_PARAM_GO_LOW_SPEED,BKQD_PARAM_GO_LOW_SPEED,10,12);
  187. }
  188. if(!BKQD_bGoMotor && !BKQD_bBackMotor && (BKQD_MotorStep == 0))
  189. {
  190. if(X_DRV)AxisDecStop(X_AXIS);
  191. }
  192. if(BKQD_QIAN_LIMIT_IN && (BKQD_MotorStep == 0) && !BKQD_bBackMotor &&(BKQD_AutoStep == 0))
  193. {
  194. if(X_DRV)AxisEgmStop(X_AXIS);
  195. }
  196. }
  197. }
  198. void BK_QueDuan_AlarmProtect(void)
  199. {
  200. BKQD_cRealPos = GetPos(X_AXIS);
  201. if(!bRunning)
  202. {
  203. ;
  204. }
  205. else
  206. {
  207. if((BKQD_cRealPos > BKQD_PARAM_RUN_LENGTH) && (BKQD_PARAM_RUN_LENGTH > 3000)
  208. && (cGoLimitEn != 0))
  209. {
  210. AxisEgmStop(X_AXIS);
  211. BKQD_JD_VAVLE = 0;
  212. BKQD_SetAlarmCode(BKQD_BACK_ALARM);
  213. }
  214. }
  215. }
  216. void BK_QueDuan_AutoAction(void)
  217. {
  218. //台面电机定时关掉
  219. if(BKQD_QIAN_STOP_Auto)
  220. {
  221. cDLJ_ATUO=1;
  222. AxisEgmStop(X_AXIS);
  223. }
  224. if(BKQD_QIAN_START_Auto)
  225. {
  226. if(cDLJ_ATUO)
  227. {
  228. cDLJ_ATUO=0;
  229. BKQD_AutoDelay = dwTickCount + 1000;
  230. BKQD_MotorDelay = dwTickCount + 2000;
  231. if((BKQD_MotorStep==63 || BKQD_MotorStep==64 || BKQD_MotorStep==65) && !BKQD_QIAN_LIMIT_IN)
  232. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED/3,BKQD_PARAM_GO_LOW_SPEED/3,15,15);
  233. else if((BKQD_cRealPos < BKQD_PARAM_ZIPPER_LENGTH) && (BKQD_MotorStep > 311))
  234. AxisMoveTwoPos(X_AXIS,1000,(BKQD_PARAM_ZIPPER_LENGTH - BKQD_cRealPos) + (*length_buffer),
  235. BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_BACK_LOW_SPEED_LENGTH,BKQD_DIR_P,5000,3000,20,30);
  236. }
  237. }
  238. if(!cDLJ_ATUO)
  239. {
  240. if(bRunning)
  241. {
  242. if(!cTABLETIME)
  243. {
  244. if(dwTickCount >= BKQD_TBDelay)
  245. BKQD_TABLE_VAVLE = 0;
  246. }
  247. switch(BKQD_AutoStep)
  248. {
  249. case 1:
  250. if(dwTickCount >= BKQD_AutoDelay)
  251. {
  252. BKQD_AutoStep = 2;
  253. if(BKQD_MotorStep == 0 && !X_DRV)
  254. {
  255. BKQD_MotorStep = 61; //前点定位
  256. }
  257. cGoLimitEn = 0;
  258. }
  259. break;
  260. case 2:
  261. if(BKQD_MotorStep == 0)
  262. {
  263. BKQD_MotorStep = 30;
  264. BKQD_AutoStep = 3;
  265. cGoLimitEn = 1;
  266. }
  267. break;
  268. case 3:
  269. if(BKQD_MotorStep == 0)
  270. {
  271. if(BKQD_SAFE_IN)
  272. {
  273. bStop = 1;
  274. }
  275. else
  276. {
  277. if(BKQD_XiaQieStep == 0)
  278. BKQD_XiaQieStep = 1;
  279. BKQD_AutoStep = 4;
  280. }
  281. }
  282. break;
  283. case 4:
  284. // 闭口
  285. if((BKQD_XiaQieStep == 0) || ((BKQD_XiaQieStep == 6) && BKQD_KB_MODE)|| ((BKQD_XiaQieStep == 13) && (BKQD_KB_MODE == 0)))// && !BKQD_SHANG_MU_LIMIT_IN)
  286. {
  287. if(BKQD_MotorStep == 0)
  288. {
  289. cGoLimitEn=0;
  290. BKQD_MotorStep = 40; //切完后退
  291. }
  292. BKQD_AutoStep = 5;
  293. }
  294. break;
  295. case 5:
  296. if(BKQD_MotorStep == 0)
  297. {
  298. cZipCnt++;
  299. BKQD_PARAM_NOW_CNT++;
  300. cTableCnt++;
  301. AddToTal(BKQD_TOTAL_ADDR);
  302. AddToTal(CT_WORKTOTAL_ADDR);
  303. CalProSP(BKQD_PROSPEED_ADDR);
  304. if(cTableCnt >= BKQD_PARAM_TABLE_NUM)
  305. {
  306. cTableCnt = 0;
  307. BKQD_TABLE_VAVLE = 1;
  308. BKQD_TBDelay = dwTickCount + BKQD_PARAM_TB_TIME;
  309. }
  310. if( SingOneFlg)
  311. {
  312. {
  313. bRunning = 0;
  314. BKQD_AutoStep = 0;
  315. SingOneFlg = 0;
  316. }
  317. }
  318. else
  319. {
  320. BKQD_AutoStep = 1;
  321. if((BKQD_PARAM_NOW_CNT >= BKQD_PARAM_ZHA_SHU) && (BKQD_PARAM_ZHA_SHU > 0))
  322. {
  323. BKQD_AutoDelay = dwTickCount + BKQD_PARAM_ZS_STOP_TIME;
  324. BKQD_PARAM_NOW_CNT = 0;
  325. cTABLETIME = 1;
  326. cTABLETOTAL= 1;
  327. if(BKQD_PARAM_ZS_STOP_TIME == 0)
  328. {
  329. bRunning = 0;
  330. BKQD_AutoStep = 0;
  331. SingOneFlg = 0;
  332. cTABLETIME = 1;
  333. cTABLETOTAL= 1;
  334. BKQD_SetAlarmCode(BKQD_TOTAL_ALARM);
  335. }
  336. }
  337. else
  338. BKQD_AutoDelay = dwTickCount + BKQD_PARAM_CYCLE_DELAY;
  339. }
  340. }
  341. break;
  342. }
  343. }
  344. }
  345. }
  346. void BK_QueDuan_StepCheckStart(void)
  347. {
  348. // 启动
  349. if((BKQD_START_IN_UP) || bStart || BKQD_bSingle)
  350. {
  351. bStart = 0;
  352. if(!bRunning && (BKQD_AutoStep == 0))
  353. {
  354. if(BKQD_XIA_MU_LIMIT_IN && !BKQD_PARAM_XM_ENABLE)BKQD_SetAlarmCode(BKQD_XM_DAOWEI);
  355. // else if(GetAlarmCode(BKQD_ALARM_ADDR) != 0);
  356. //else if(GetTotal(BKQD_TOTAL_ADDR) >= BKQD_PARAM_SET_TOTAL) BKQD_SetAlarmCode(BKQD_TOTAL_ALARM);
  357. // else if(BKQD_BL_VAVLE)BKQD_SetAlarmCode(BKQD_BL_ALARM);
  358. else if(BKQD_SM_VAVLE)BKQD_SetAlarmCode(BKQD_SM_ALARM);
  359. else
  360. {
  361. bRunning = 1;
  362. BKQD_AutoStep = 1;
  363. if(BKQD_PARAM_BL_ENABLE)
  364. BKQD_PARAM_BL_ENABLE=1 ; //并链起动
  365. if(BKQD_bSingle)
  366. SingOneFlg= 1;
  367. cZipCnt = 0;
  368. cTABLETIME = 0;
  369. cTABLETOTAL= 0;
  370. cTuiFangKuaiCnt = 0;
  371. BKQD_BL_VAVLE = 0; //并链关
  372. cDLJ_ATUO=0;
  373. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  374. SetAlarmCode(BKQD_ALARM_ADDR,0);
  375. }
  376. }
  377. BKQD_bSingle = 0;
  378. }
  379. //停止
  380. if(BKQD_STOP_IN_UP || bStop)
  381. {
  382. bStop = 0;
  383. if(bRunning)
  384. {
  385. BKQD_AutoDelay = dwTickCount;
  386. BKQD_MotorDelay = dwTickCount;
  387. BKQD_XiaQieDelay = dwTickCount;
  388. BKQD_KaDaiDelay = dwTickCount;
  389. BKQD_CSDelay = dwTickCount;
  390. BKQD_TBDelay = dwTickCount;
  391. BKQD_TFKDelay = dwTickCount;
  392. BKQD_TLDelay = dwTickCount;
  393. dwTickCount = BKQD_TBDelay;
  394. SingOneFlg = 0;
  395. BKQD_JD_VAVLE = 0;
  396. BKQD_SM_VAVLE = 0;
  397. BKQD_XM_VAVLE = 0;
  398. BKQD_YD_VAVLE = 0;
  399. BKQD_TFK_VAVLE= 0;
  400. BKQD_TL_VAVLE = 0;
  401. BKQD_HL_VAVLE = 0;
  402. BKQD_CS_OUT = 0;
  403. BKQD_XiaQieStep = 0;
  404. BKQD_MotorStep = 0;
  405. BKQD_TuiLianStep = 0;
  406. //BKQD_SZ_OUT = 1;
  407. BKQD_GZ_VAVLE = 0;
  408. BKQD_TABLE_VAVLE = 0;
  409. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  410. AxisDecStop(X_AXIS);
  411. BKQD_BinLianStep = 0;
  412. BKQD_BL_VAVLE = 0;
  413. cTABLETIME = 0;
  414. cTABLETOTAL= 0;
  415. user_datas[121] = 0;
  416. user_datas[122] = 0;
  417. SetAlarmCode(BKQD_ALARM_ADDR,0);
  418. }
  419. else
  420. {
  421. BKQD_AutoDelay = dwTickCount;
  422. BKQD_MotorDelay = dwTickCount;
  423. BKQD_XiaQieDelay = dwTickCount;
  424. BKQD_KaDaiDelay = dwTickCount;
  425. BKQD_CSDelay = dwTickCount;
  426. BKQD_TBDelay = dwTickCount;
  427. BKQD_TFKDelay = dwTickCount;
  428. BKQD_TLDelay = dwTickCount;
  429. dwTickCount = BKQD_TBDelay;
  430. SingOneFlg = 0;
  431. BKQD_JD_VAVLE = 0;
  432. BKQD_SM_VAVLE = 0;
  433. BKQD_XM_VAVLE = 0;
  434. BKQD_YD_VAVLE = 0;
  435. BKQD_TFK_VAVLE= 0;
  436. BKQD_YX_VAVLE = 0;
  437. BKQD_HL_VAVLE = 0;
  438. BKQD_TL_VAVLE = 0;
  439. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  440. BKQD_CS_OUT = 0;
  441. BKQD_XiaQieStep = 0;
  442. BKQD_MotorStep = 0;
  443. BKQD_TuiLianStep = 0;
  444. BKQD_SZ_OUT = 1;
  445. BKQD_GZ_VAVLE = 0;
  446. BKQD_TABLE_VAVLE = 0;
  447. AxisDecStop(X_AXIS);
  448. cTABLETIME = 0;
  449. cTABLETOTAL= 0;
  450. BKQD_BinLianStep = 0;
  451. BKQD_BL_VAVLE = 0;
  452. SetAlarmCode(BKQD_ALARM_ADDR,0);
  453. }
  454. bRunning = 0;
  455. BKQD_XiaQieStep = 0;
  456. BKQD_AutoStep = 0;
  457. BKQD_MotorStep = 0;
  458. BKQD_TuiLianStep = 0;
  459. }
  460. if(bAlarmStop)
  461. {
  462. bAlarmStop = 0;
  463. BKQD_XiaQieStep = 0;
  464. BKQD_AutoStep = 0;
  465. BKQD_MotorStep = 0;
  466. BKQD_TuiLianStep = 0;
  467. BKQD_XiaQieStep = 0;
  468. BKQD_MotorStep = 0;
  469. BKQD_TuiLianStep = 0;
  470. BKQD_AutoDelay = dwTickCount;
  471. BKQD_MotorDelay = dwTickCount;
  472. BKQD_XiaQieDelay = dwTickCount;
  473. BKQD_KaDaiDelay = dwTickCount;
  474. BKQD_CSDelay = dwTickCount;
  475. BKQD_TBDelay = dwTickCount;
  476. BKQD_TFKDelay = dwTickCount;
  477. BKQD_TLDelay = dwTickCount;
  478. SingOneFlg = 0;
  479. bRunning = 0;
  480. AxisDecStop(X_AXIS);
  481. dwTickCount = BKQD_TBDelay;
  482. BKQD_TABLE_VAVLE = 0;
  483. BKQD_TFK_VAVLE =0;
  484. BKQD_JD_VAVLE=0;
  485. BKQD_GZ_VAVLE=0;
  486. }
  487. }
  488. //记忆长度模式误差检测
  489. void BK_QueDuan_CheckLength(long zip_length)
  490. {
  491. static long start_dist;
  492. switch(BKQD_CheckLengthStep)
  493. {
  494. case 0:break;
  495. case 1:
  496. start_dist = BKQD_cRealPos;
  497. dwSaveLength = 0;
  498. BKQD_CheckLengthStep = 2;
  499. break;
  500. case 2:
  501. if(BKQD_GUO_LIAN_IN_DW){
  502. dwSaveLength = BKQD_cRealPos - start_dist;
  503. // user_datas[127] = BKQD_cRealPos;
  504. }
  505. break;
  506. }
  507. }
  508. void BK_QueDuan_BingLian(void)
  509. {
  510. static long bl_pos_buff,HL_delay;
  511. switch(BKQD_BinLianStep)
  512. {
  513. case 1:
  514. bl_pos_buff = BKQD_cRealPos;
  515. BKQD_BinLianStep = 2;
  516. break;
  517. case 2:
  518. if((BKQD_cRealPos - bl_pos_buff) >= BKQD_PARAM_DELAY_HL_LENGTH)
  519. {
  520. BKQD_BL_VAVLE = 1;
  521. BKQD_BinLianStep = 3;
  522. }
  523. break;
  524. case 3://有过链检测
  525. if((BKQD_cRealPos - bl_pos_buff) >= (BKQD_PARAM_ZIPPER_LENGTH - BKQD_PARAM_HL_DELAY_BACK))
  526. {
  527. BKQD_BL_VAVLE = 0;
  528. BKQD_BinLianStep = 0;
  529. }
  530. if(BKQD_GUO_LIAN_IN_DW && BKQD_PARAM_BACK_MODE ==1) //|| (BKQD_PARAM_BACK_MODE==2 && cZipCnt < 2)))
  531. {
  532. BKQD_BL_VAVLE = 0;
  533. BKQD_BinLianStep = 0;
  534. }
  535. break;
  536. case 10:
  537. bl_pos_buff = BKQD_cRealPos;
  538. BKQD_BinLianStep = 11;
  539. break;
  540. case 11:
  541. if((BKQD_cRealPos - bl_pos_buff) >= BKQD_PARAM_DELAY_HL_LENGTH)
  542. {
  543. BKQD_BL_VAVLE = 1;
  544. BKQD_BinLianStep = 12;
  545. }
  546. break;
  547. case 12://有过链检测
  548. if(BKQD_GUO_LIAN_IN_DW)
  549. {
  550. BKQD_BL_VAVLE = 0;
  551. BKQD_BinLianStep = 0;
  552. }
  553. break;
  554. default:;
  555. }
  556. }
  557. //不带过链感应长度输入电机长度 闭口有勾针到位
  558. void BK_QueDuan_Motor_NoGL(void)
  559. {
  560. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  561. long pulse_buff;
  562. unsigned short ch,kk;
  563. user_datas[121] = BKQD_MotorStep;
  564. user_datas[122] = BKQD_AutoStep;
  565. user_datas[124]= BKQD_cRealPos;
  566. user_datas[125]= bRunning;
  567. // user_datas[123] = length_buff - (*length_buffer);
  568. // user_datas[127] = BKQD_cRealPos;
  569. // user_datas[126] = go_buff - BKQD_cRealPos;
  570. if((BKQD_MotorStep >= 101) && (BKQD_MotorStep <= 103))
  571. {
  572. if(BKQD_QIAN_LIMIT_IN_DW)BKQD_HL_VAVLE = 0;
  573. }
  574. if(!cDLJ_ATUO)
  575. {
  576. switch(BKQD_MotorStep)
  577. {
  578. case 30:
  579. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_DELAY_BACK;
  580. SetPos(X_AXIS, 0);
  581. length_buffer = &BKQD_PARAM_OFFSET_LENGTH;
  582. if(BKQD_PARAM_BL_ENABLE) //
  583. BKQD_BinLianStep = 1;
  584. BKQD_MotorStep = 31;
  585. break;
  586. case 31:
  587. if(BKQD_cRealPos >= (BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_GOUZHEN_LENGTH ))
  588. BKQD_GZ_VAVLE = 1;
  589. if(dwTickCount >= BKQD_MotorDelay)
  590. {
  591. back_buff = BKQD_cRealPos;
  592. gou_zhen_buff = BKQD_cRealPos;
  593. save_buff = BKQD_cRealPos;
  594. length_buffer = &BKQD_PARAM_OFFSET_LENGTH;
  595. DCC_TIME_BL=BKQD_PARAM_GO_HIGH_SPEED/500;
  596. AxisMovePosAccDecNotStop(X_AXIS,BKQD_PARAM_BACK_SPEED,BKQD_PARAM_ZIPPER_LENGTH + (*length_buffer), BKQD_PARAM_START_SPEED,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_ACC,DCC_TIME_BL,BKQD_PARAM_BACK_LOW_SPEED_LENGTH);
  597. BKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  598. BKQD_MotorStep = 32;
  599. }
  600. break;
  601. case 32:
  602. //勾针提前输出
  603. if(BKQD_cRealPos >= (BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_GOUZHEN_LENGTH ))
  604. BKQD_GZ_VAVLE = 1;
  605. if((BKQD_cRealPos) > (BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_BACK_LOW_SPEED_LENGTH)) //- (*length_buffer) - (BKQD_PARAM_BACK_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(BKQD_PARAM_BACK_SPEED,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_DCC)))))
  606. {
  607. BKQD_MotorDelay = dwTickCount + 3000; //钩针未到位延时警告
  608. BKQD_MotorStep = 33;
  609. }
  610. else if(BKQD_cRealPos >= (BKQD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)))//BKQD_PARAM_ERROR_LENGTH))
  611. {
  612. BKQD_SetAlarmCode(BKQD_GZ_ALARM);
  613. }
  614. break;
  615. case 33:
  616. if(BKQD_cRealPos >= (BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_GOUZHEN_LENGTH ))
  617. {
  618. BKQD_GZ_VAVLE = 1;
  619. }
  620. if(BKQD_GOUZHEN_IN)
  621. {
  622. AxisEgmStop(X_AXIS);
  623. BKQD_MotorDelay = dwTickCount + 15;
  624. BKQD_YD_VAVLE = 1;
  625. BKQD_MotorStep = 34;
  626. BKQD_BL_VAVLE = 0; //停止时并链一定要打开
  627. }
  628. else if((BKQD_cRealPos >= BKQD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)))// && dwTickCount >= BKQD_MotorDelay)
  629. {
  630. AxisEgmStop(X_AXIS);
  631. if(dwTickCount >= BKQD_MotorDelay)
  632. BKQD_SetAlarmCode(BKQD_GZ_ALARM);
  633. }
  634. break;
  635. case 34:
  636. if(!X_DRV && (dwTickCount >= BKQD_MotorDelay))
  637. {
  638. BKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  639. BKQD_YD_VAVLE = 1;
  640. BKQD_MotorStep = 35;
  641. }
  642. break;
  643. case 35:
  644. if(cZipCnt == 0)
  645. {
  646. ch = BKQD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)-120;
  647. kk = BKQD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)+120;
  648. }
  649. else
  650. {
  651. ch = BKQD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)-100;
  652. kk = BKQD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)+100;
  653. }
  654. user_datas[128] = ch;
  655. user_datas[127] = kk;
  656. if(((BKQD_cRealPos) < (ch)))
  657. {
  658. SetAlarmCode(BKQD_ALARM_ADDR,BKQD_LENGTH_LONG_ALARM);
  659. if(dwTickCount >= BKQD_MotorDelay)
  660. bAlarmStop = 1;
  661. }
  662. else if((BKQD_cRealPos > kk))//(BKQD_PARAM_ERROR_LENGTH - 200 + (*length_buffer)+50)))
  663. {
  664. SetAlarmCode(BKQD_ALARM_ADDR,BKQD_LENGTH_LONG_ALARM);
  665. if(dwTickCount >= BKQD_MotorDelay)
  666. bAlarmStop = 1;
  667. }
  668. else
  669. {
  670. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,-BKQD_PARAM_FZ_LENGTH,3000,1000,BKQD_PARAM_ACC,BKQD_PARAM_DCC,00);
  671. BKQD_MotorStep = 0;
  672. }
  673. break;
  674. case 40:
  675. //切完延时后拉带松夹子
  676. if(BKQD_PARAM_SJZ_LENGTH == 0)
  677. {
  678. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_TDYS_DELAY;
  679. jz_buff = BKQD_cRealPos;
  680. BKQD_MotorStep = 43;
  681. BKQD_JD_VAVLE = 0;
  682. }
  683. else
  684. {
  685. jz_buff = BKQD_cRealPos;
  686. SetDir(X_AXIS, BKQD_DIR_P);
  687. BKQD_MotorStep = 41;
  688. }
  689. break;
  690. case 41:
  691. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_CUT_BACK_SPEED,BKQD_PARAM_SJZ_LENGTH+BKQD_PARAM_BACK_LENGTH,1000,1000,25,50,0);
  692. BKQD_MotorStep = 42;
  693. break;
  694. case 42:
  695. if(!X_DRV || (BKQD_PARAM_SJZ_LENGTH <= (BKQD_cRealPos - jz_buff)))
  696. {
  697. BKQD_JD_VAVLE = 0;
  698. BKQD_GZ_VAVLE=0;
  699. BKQD_MotorStep = 44;
  700. }
  701. break;
  702. case 43:
  703. if(dwTickCount >= BKQD_MotorDelay)
  704. {
  705. SetDir(X_AXIS, BKQD_DIR_P);
  706. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_CUT_BACK_SPEED,BKQD_PARAM_BACK_LENGTH,1000,1000,25,50,0);
  707. BKQD_MotorStep = 44;
  708. }
  709. break;
  710. case 44: // 切断完成后拉电机动作
  711. if(!X_DRV || (BKQD_cRealPos - jz_buff) >= (BKQD_PARAM_SJZ_LENGTH+BKQD_PARAM_BACK_LENGTH))
  712. {
  713. AxisEgmStop(X_AXIS);
  714. BKQD_MotorStep = 0;
  715. BKQD_GZ_VAVLE=0;
  716. BKQD_MotorDelay = dwTickCount;
  717. }
  718. break;
  719. case 61: // 前点定位数控模式
  720. if(BKQD_SZ_OUT)
  721. {
  722. BKQD_SZ_OUT = 0;
  723. BKQD_MotorDelay = dwTickCount + 150;
  724. SetPos(X_AXIS, 0);
  725. }
  726. else
  727. BKQD_MotorDelay = dwTickCount;
  728. BKQD_BL_VAVLE = 0;//并链也要打开
  729. if(!BKQD_TL_VAVLE && cZipCnt) //没送链情况下主动送链
  730. {
  731. if(!BKQD_SHANG_MU_LIMIT_IN && (BKQD_TuiLianStep == 0))
  732. {
  733. BKQD_TuiLianStep = 1;
  734. BKQD_MotorStep = 62;
  735. }
  736. }
  737. else
  738. BKQD_MotorStep = 62;
  739. break;
  740. case 62:
  741. if(dwTickCount >= BKQD_MotorDelay)
  742. {
  743. if(BKQD_QIAN_LIMIT_IN)
  744. {
  745. SetPos(X_AXIS, 0);//在前点,直接置零点
  746. //前点亮的情况下先退出
  747. AxisMovePos(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,1000);
  748. BKQD_MotorDelay = dwTickCount + 300;
  749. }
  750. BKQD_MotorStep = 63;
  751. BKQD_JD_VAVLE = 0;
  752. }
  753. break;
  754. case 63:
  755. if(!X_DRV && !BKQD_QIAN_LIMIT_IN && (dwTickCount >= BKQD_MotorDelay))// && !BKQD_SHANG_MU_LIMIT_IN)
  756. {
  757. go_buff = BKQD_cRealPos;
  758. BKQD_YD_VAVLE = 1;
  759. BKQD_HL_VAVLE = 1;
  760. BKQD_YX_VAVLE = 1;
  761. if(cZipCnt > 0)
  762. {
  763. if(BKQD_cRealPos>(BKQD_PARAM_GO_LOW_SPEED_LENGTH))
  764. {
  765. DCC_TIME_BL=BKQD_PARAM_GO_HIGH_SPEED/500;
  766. AxisMovePosAccDecNotStop(X_AXIS,BKQD_PARAM_GO_HIGH_SPEED,-BKQD_cRealPos,
  767. BKQD_PARAM_START_SPEED,BKQD_PARAM_GO_LOW_SPEED,BKQD_PARAM_ACC,DCC_TIME_BL,
  768. BKQD_PARAM_GO_LOW_SPEED_LENGTH); }
  769. else
  770. {
  771. // X轴 运行速度 启动速度 加速度 减速度
  772. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED/3,1000,15,15);
  773. }
  774. }
  775. else
  776. {
  777. // X轴 运行速度 启动速度 加速度 减速度
  778. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED/3,1000,15,15);
  779. }
  780. BKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  781. BKQD_MotorStep =64;
  782. }
  783. break;
  784. case 64:
  785. if(cZipCnt > 1)
  786. {
  787. //李永庆代码
  788. if(((BKQD_cRealPos) < (BKQD_PARAM_GO_LOW_SPEED_LENGTH+1200)))// || (BKQD_QIAN_DEC_IN))
  789. {
  790. user_datas[126]= GetCurSpeed(X_AXIS);
  791. BKQD_MotorStep =65;
  792. }
  793. if(BKQD_QIAN_LIMIT_IN) //前点限位
  794. {
  795. SetPos(X_AXIS, BKQD_PARAM_QDW_LENGTH);
  796. AxisMovePosAccDec(X_AXIS,1000,-BKQD_PARAM_QDW_LENGTH,1000,1000,5,5,00);
  797. BKQD_MotorStep = 66;
  798. }
  799. }
  800. else
  801. {
  802. if(BKQD_QIAN_LIMIT_IN) //前点限位
  803. {
  804. SetPos(X_AXIS, BKQD_PARAM_QDW_LENGTH);
  805. AxisMovePosAccDec(X_AXIS,1000,-BKQD_PARAM_QDW_LENGTH,1000,1000,5,5,00);
  806. BKQD_MotorStep = 66;
  807. }
  808. }
  809. break;
  810. case 65:
  811. if(BKQD_QIAN_LIMIT_IN)
  812. {
  813. SetPos(X_AXIS, BKQD_PARAM_QDW_LENGTH);
  814. AxisMovePosAccDec(X_AXIS,1000,-BKQD_PARAM_QDW_LENGTH,1000,1000,5,5,00);
  815. BKQD_MotorStep = 66;
  816. }
  817. else if(dwTickCount >= BKQD_MotorDelay)
  818. BKQD_SetAlarmCode(BKQD_NO_ZIPPER_ALARM);
  819. break;
  820. case 66:
  821. if(!X_DRV || BKQD_cRealPos<0)
  822. {
  823. SetPos(X_AXIS, 0);
  824. BKQD_MotorDelay = dwTickCount;
  825. BKQD_MotorStep = 67;
  826. }
  827. break;
  828. case 67: //等推链完成后,
  829. if((dwTickCount >= BKQD_MotorDelay) && (BKQD_TuiLianStep == 0) && ((BKQD_PARAM_TIAOSHI_MODE && BKQD_bTS) || (BKQD_PARAM_TIAOSHI_MODE == 0)) )
  830. {
  831. if(bRunning)
  832. {
  833. BKQD_JD_VAVLE = 1;
  834. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_DELAY_BACK;
  835. }
  836. BKQD_MotorStep = 68;
  837. }
  838. break;
  839. case 68:
  840. if(dwTickCount >= BKQD_MotorDelay)
  841. {
  842. BKQD_YD_VAVLE = 0;
  843. BKQD_HL_VAVLE = 0;
  844. BKQD_YX_VAVLE = 0;
  845. BKQD_TL_VAVLE = 0;
  846. BKQD_MotorStep = 0;
  847. BKQD_MotorDelay = dwTickCount;
  848. }
  849. break;
  850. }
  851. }
  852. }
  853. void BK_QueDuan_TuiLianAction(void)
  854. {
  855. if(BKQD_PARAM_XM_ENABLE == 0)
  856. {
  857. BKQD_TuiLianStep = 0;
  858. }
  859. else
  860. {
  861. switch(BKQD_TuiLianStep)
  862. {
  863. case 1:
  864. BKQD_TuiLianStep = 2;
  865. break;
  866. case 2:
  867. if(BKQD_PARAM_TL_DELAY)
  868. BKQD_TLDelay = dwTickCount + BKQD_PARAM_TL_DELAY;
  869. else
  870. BKQD_TLDelay = dwTickCount + 100;
  871. BKQD_TuiLianStep = 3;
  872. break;
  873. case 3:
  874. if(!BKQD_SM_VAVLE && !BKQD_SHANG_MU_LIMIT_IN && dwTickCount >= BKQD_TLDelay)
  875. {
  876. BKQD_TL_VAVLE = 1;
  877. BKQD_TFK_VAVLE = 0;
  878. if(!bRunning)BKQD_TFK_VAVLE = 0;
  879. BKQD_TLDelay = dwTickCount + BKQD_PARAM_TL_DELAY;
  880. BKQD_TuiLianStep = 4;
  881. }
  882. break;
  883. case 4:
  884. if(dwTickCount >= BKQD_TLDelay)
  885. {
  886. BKQD_TuiLianStep = 0;
  887. }
  888. break;
  889. case 10:
  890. BKQD_TuiLianStep = 11;
  891. break;
  892. case 11:
  893. if(!Y_DRV)
  894. {
  895. {
  896. BKQD_TuiLianStep = 0;
  897. }
  898. }
  899. break;
  900. }
  901. }
  902. }
  903. //闭口专用
  904. void BK_QueDuan_XiaQue_NO_GL(void)
  905. {
  906. switch(BKQD_XiaQieStep)
  907. {
  908. case 0:
  909. break;
  910. case 1:
  911. if(!bRunning)
  912. {
  913. BKQD_YD_VAVLE = 1;
  914. BKQD_XiaQieStep = 2;
  915. BKQD_XiaQieDelay = dwTickCount + 30;
  916. }
  917. else
  918. {
  919. BKQD_YD_VAVLE = 1;
  920. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CUT_DELAY;
  921. BKQD_XiaQieStep = 2;
  922. }
  923. break;
  924. case 2:
  925. if(dwTickCount >= BKQD_XiaQieDelay)
  926. {
  927. BKQD_XiaQieStep = 3;
  928. BKQD_XiaQieDelay = dwTickCount;
  929. }
  930. break;
  931. case 3:
  932. if(dwTickCount >= BKQD_XiaQieDelay)
  933. {
  934. if((BKQD_PARAM_TIAOSHI_MODE && BKQD_bTS) || (BKQD_PARAM_TIAOSHI_MODE == 0))
  935. {
  936. BKQD_SM_VAVLE = 1;
  937. BKQD_XM_VAVLE = 1;
  938. BKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  939. BKQD_XiaQieStep = 4;
  940. }
  941. }
  942. break;
  943. case 4://永兴为下模固定
  944. if(BKQD_SHANG_MU_LIMIT_IN && (BKQD_XIA_MU_LIMIT_IN || BKQD_PARAM_XM_ENABLE))
  945. {
  946. BKQD_GZ_VAVLE = 0;
  947. if(!BKQD_PARAM_CS_MODE) //气切
  948. {
  949. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_DELAYBACK_SM; //
  950. BKQD_XiaQieStep = 5;
  951. }
  952. else
  953. {
  954. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_DELAY_CS; //
  955. BKQD_XiaQieStep = 10;
  956. } //
  957. }
  958. else if(dwTickCount >= BKQD_XiaQieDelay)BKQD_SetAlarmCode(BKQD_SM_DAOWEI);
  959. break;
  960. case 5:
  961. if(dwTickCount >= BKQD_XiaQieDelay)
  962. {
  963. BKQD_SM_VAVLE = 0;
  964. BKQD_XM_VAVLE = 0;
  965. BKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  966. BKQD_XiaQieStep = 6;
  967. }
  968. break;
  969. case 6:
  970. if(!BKQD_SHANG_MU_LIMIT_IN && (!BKQD_XIA_MU_LIMIT_IN || BKQD_PARAM_XM_ENABLE)) //下模不动就不用判断
  971. {
  972. if(BKQD_TuiLianStep == 0)
  973. BKQD_TuiLianStep = 1;
  974. if(!bRunning)
  975. BKQD_JD_VAVLE = 0;
  976. BKQD_XiaQieStep = 0;
  977. }
  978. else if(dwTickCount >= BKQD_XiaQieDelay)
  979. {
  980. BKQD_SetAlarmCode(BKQD_SM_YUANWEI);
  981. }
  982. break;
  983. //10~11步为超声
  984. case 10:
  985. if(dwTickCount >= BKQD_XiaQieDelay)
  986. {
  987. if(BKQD_PARAM_CS_ENABLE)BKQD_CS_OUT = 1;
  988. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CS_TIME; //
  989. BKQD_XiaQieStep = 11;
  990. }
  991. break;
  992. case 11:
  993. if(dwTickCount >= BKQD_XiaQieDelay)
  994. {
  995. BKQD_CS_OUT = 0;
  996. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CS_COLD_TIME; //
  997. BKQD_XiaQieStep = 5;
  998. }
  999. break;
  1000. case 100:
  1001. if(dwTickCount >= BKQD_XiaQieDelay)
  1002. {
  1003. //这是双开程序,暂时不考虑
  1004. #if 1
  1005. if(BKQD_GOUZHEN_IN)
  1006. {
  1007. BKQD_YD_VAVLE = 1;
  1008. BKQD_XiaQieStep = 3;
  1009. }
  1010. #endif
  1011. }
  1012. break;
  1013. }
  1014. }
  1015. //切断动作
  1016. void BK_QueDuan_XiaQue(void)
  1017. {
  1018. BK_QueDuan_XiaQue_NO_GL();
  1019. }
  1020. #endif