JXBKQueDuanJi.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  1. #include "global.h"
  2. #if JU_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(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 BK_StopCode(void);
  14. void BKQD_TuiDaiAction(void);
  15. short *BK_length_buffer;
  16. void BKQD_SetAlarmCode(unsigned alarm_code)
  17. {
  18. SetAlarmCode(BKQD_ALARM_ADDR,alarm_code);
  19. bAlarmStop = 1;
  20. }
  21. void BK_QueDuan_ExtiActionX31(void)
  22. {
  23. KK_cCheckLianFlg = 1;
  24. }
  25. void BK_StopCode(void)
  26. {
  27. switch(BKQD_StopStep)
  28. {
  29. case 1:
  30. BKQD_StopStep=2;
  31. if(X_DRV)
  32. {
  33. AxisChangeSpeedDirect(X_AXIS,GetCurSpeed(X_AXIS) * 2/3);
  34. AxisDecStop(X_AXIS);
  35. }
  36. break;
  37. case 2:
  38. if(!X_DRV || (KK_cRealPos < 10))
  39. {
  40. BKQD_StopCodeDelay=dwTickCount+350;
  41. BKQD_StopStep = 3;
  42. }
  43. break;
  44. case 3:
  45. if(dwTickCount >= BKQD_StopCodeDelay)
  46. {
  47. if(!cSTOPONE)
  48. {
  49. BKQD_StopStep=0;
  50. }
  51. else
  52. {
  53. BKQD_SetAlarmCode(BKQD_PARAM_ANQUANMEN_ALARM);
  54. BKQD_StopStep=0;
  55. cSTOPONE=0;
  56. }
  57. BKQD_SZ_OUT = 1; //电机松轴
  58. }
  59. break;
  60. }
  61. }
  62. void BK_QueDuan_InitAction(void)
  63. {
  64. float length_buff,pulse_buff;
  65. length_buff = BKQD_PARAM_CYCLE_LENGTH;
  66. pulse_buff = BKQD_PARAM_CYCLE_PULSE;
  67. XGearRatio = pulse_buff/length_buff;
  68. // BKQD_SZ_OUT = 1;
  69. BKQD_SetAlarmCode(0);
  70. SetDirReverse(X_AXIS, 1);
  71. }
  72. void BK_QueDuan_Action(void)
  73. {
  74. BK_QueDuan_AlarmProtect();
  75. BK_QueDuan_Motor();
  76. BK_QueDuan_XiaQue();
  77. BK_QueDuan_ManualAction();
  78. BK_QueDuan_TuiLianAction();
  79. BK_QueDuan_BingLian();
  80. BK_StopCode();
  81. BK_QueDuan_AutoAction();
  82. BK_QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
  83. }
  84. //手动动作
  85. void BK_QueDuan_ManualAction(void)
  86. {
  87. //条数或扎数达到后,台面电机转两秒之后再停机
  88. if(KK_cTABLETIME)
  89. {
  90. if(KK_cTABLETOTAL)
  91. {
  92. KK_cTABLETOTAL=0;
  93. BKQD_TABLE_VAVLE = 1;
  94. BKQD_TableDelay=dwTickCount + 2000;
  95. }
  96. if(dwTickCount >= BKQD_TableDelay)
  97. {
  98. BKQD_TABLE_VAVLE = 0;
  99. KK_cTABLETIME=0;
  100. }
  101. }
  102. if(bRunning == 0)
  103. {
  104. KK_cGoLimitEn = 0;
  105. if(BKQD_bClearTotal) //切断计数清零
  106. {
  107. BKQD_bClearTotal = 0;
  108. ClrcToTal(BKQD_TOTAL_ADDR);
  109. }
  110. if(BKQD_bClearNowTotal)
  111. {
  112. BKQD_bClearNowTotal = 0;
  113. BKQD_PARAM_NOW_CNT = 0;
  114. }
  115. if(BKQD_bXiaQie)
  116. {
  117. BKQD_bXiaQie = 0;
  118. if((BKQD_XiaQieStep == 0) && !BKQD_TL_VAVLE)
  119. {
  120. BKQD_XiaQieStep = 1;
  121. }
  122. }
  123. if(BKQD_bQianDianDW)
  124. {
  125. BKQD_bQianDianDW = 0;
  126. if(BKQD_MotorStep == 0)
  127. {
  128. BKQD_MotorStep = 61;
  129. cZipCnt = 0;
  130. }
  131. }
  132. if(BKQD_bTL)
  133. {
  134. BKQD_bTL = 0;
  135. if(BKQD_TL_VAVLE)
  136. {
  137. BKQD_TL_VAVLE = 0;
  138. }
  139. else if(!BKQD_GZ_VAVLE && !BKQD_SM_VAVLE)
  140. {
  141. BKQD_TL_VAVLE = ~BKQD_TL_VAVLE;
  142. }
  143. }
  144. if(BKQD_bECQ)
  145. {
  146. BKQD_bECQ=0;
  147. KK_cShuangDao=1;
  148. KK_cDiErLaChu=1;
  149. KK_cECQ_STOP=1;
  150. bRunning = 1;
  151. BKQD_AutoStep = 1;
  152. }
  153. // if(!Y_DRV)BKQD_bTL = 0;
  154. if(BKQD_bYD)
  155. {
  156. BKQD_bYD = 0;
  157. BKQD_YD_VAVLE = ~BKQD_YD_VAVLE;
  158. }
  159. if(BKQD_bGZ)
  160. {
  161. BKQD_bGZ = 0;
  162. BKQD_GZ_VAVLE = ~BKQD_GZ_VAVLE;
  163. }
  164. if(BKQD_bJD)
  165. {
  166. BKQD_bJD = 0;
  167. BKQD_JD_VAVLE = ~BKQD_JD_VAVLE;
  168. }
  169. if(BKQD_bXM)
  170. {
  171. BKQD_bXM = 0;
  172. BKQD_XM_VAVLE = ~BKQD_XM_VAVLE;
  173. if(!BKQD_XM_VAVLE)BKQD_GZ_VAVLE = 0;
  174. }
  175. if(BKQD_GOUZHEN_IN_UP)
  176. {
  177. BKQD_YD_VAVLE=1;
  178. }
  179. if(BKQD_bSM)
  180. {
  181. BKQD_bSM = 0;
  182. if(BKQD_SM_VAVLE)
  183. BKQD_SM_VAVLE = 0;
  184. else if(!BKQD_TL_VAVLE || !BKQD_PARAM_XM_ENABLE)
  185. BKQD_SM_VAVLE = 1;
  186. }
  187. //推方块
  188. if(BKQD_bTFK)
  189. {
  190. BKQD_bTFK = 0;
  191. BKQD_TFK_VAVLE = ~BKQD_TFK_VAVLE;
  192. }
  193. //台面电机
  194. if(BKQD_bTB)
  195. {
  196. BKQD_bTB = 0;
  197. BKQD_TABLE_VAVLE = ~BKQD_TABLE_VAVLE;
  198. }
  199. // if(BKQD_bYBD)
  200. // / {
  201. // BKQD_bYBD = 0;
  202. // BKQD_YBD_VAVLE = ~BKQD_YBD_VAVLE;
  203. // }
  204. if(BKQD_bTestCS)
  205. {
  206. BKQD_bTestCS = 0;
  207. BKQD_CS_OUT = 1;
  208. BKQD_CSDelay = dwTickCount + BKQD_PARAM_CS_TIME;
  209. }
  210. if(BKQD_bBL)//吹气
  211. {
  212. BKQD_bBL = 0;
  213. BKQD_CQ_VAVLE = ~BKQD_CQ_VAVLE;
  214. }
  215. if(BKQD_bHL) //护链,双开用
  216. {
  217. BKQD_bHL = 0;
  218. BKQD_HL_VAVLE = ~BKQD_HL_VAVLE;
  219. }
  220. if(BKQD_bYX)
  221. {
  222. BKQD_bYX = 0;
  223. BKQD_YX_VAVLE = ~BKQD_YX_VAVLE;
  224. }
  225. if(BKQD_XiaQieStep == 0)
  226. {
  227. if(dwTickCount >= BKQD_CSDelay)BKQD_CS_OUT = 0;
  228. }
  229. //电机控制
  230. if(BKQD_bGoMotor && !BKQD_QIAN_LIMIT_IN)
  231. {
  232. BKQD_SZ_OUT = 0;
  233. // BKQD_JZ_DIR = BKQD_YDIR_N;
  234. if(!X_DRV)
  235. // X轴 运行速度 启动速度 加速度 减速度
  236. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED,BKQD_PARAM_GO_LOW_SPEED,10,12);
  237. }
  238. if(BKQD_bBackMotor) //后退限位已经取消
  239. {
  240. BKQD_SZ_OUT = 0;
  241. // BKQD_JZ_DIR = BKQD_YDIR_P;
  242. if(!X_DRV)
  243. // X轴 运行速度 启动速度 加速度 减速度
  244. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_P,BKQD_PARAM_GO_LOW_SPEED,BKQD_PARAM_GO_LOW_SPEED,10,12);
  245. }
  246. if(!BKQD_bGoMotor && !BKQD_bBackMotor && (BKQD_MotorStep == 0))
  247. {
  248. if(X_DRV)AxisDecStop(X_AXIS);
  249. }
  250. if(BKQD_QIAN_LIMIT_IN && (BKQD_MotorStep == 0) && !BKQD_bBackMotor &&(BKQD_AutoStep == 0))
  251. {
  252. if(X_DRV)AxisEgmStop(X_AXIS);
  253. }
  254. }
  255. }
  256. void BK_QueDuan_AlarmProtect(void)
  257. {
  258. KK_cRealPos = GetPos(X_AXIS);
  259. if(!bRunning)
  260. {
  261. ;
  262. //
  263. #if 0
  264. if(BKQD_BACK_LIMIT_IN_UP)
  265. {
  266. if((BKQD_MotorStep == 0) && X_DRV && BKQD_bBackMotor) //到后限不能再后退但可以点前进
  267. {
  268. BKQD_bBackMotor = 0;
  269. AxisDecStop(X_AXIS);
  270. BKQD_JD_VAVLE = 0;
  271. BKQD_SetAlarmCode(BKQD_BACK_ALARM);
  272. }
  273. }
  274. #endif
  275. }
  276. else
  277. {
  278. if((KK_cRealPos > BKQD_PARAM_RUN_LENGTH) && (BKQD_PARAM_RUN_LENGTH > 3000)
  279. && (KK_cGoLimitEn != 0))
  280. {
  281. AxisEgmStop(X_AXIS);
  282. BKQD_JD_VAVLE = 0;
  283. BKQD_SetAlarmCode(BKQD_BACK_ALARM);
  284. }
  285. }
  286. }
  287. void BK_QueDuan_AutoAction(void)
  288. {
  289. //台面电机定时关掉
  290. if(BKQD_QIAN_STOP_Auto)
  291. {
  292. KK_cDLJ_ATUO=1;
  293. AxisEgmStop(X_AXIS);
  294. }
  295. if(BKQD_QIAN_START_Auto)
  296. {
  297. if(KK_cDLJ_ATUO)
  298. {
  299. KK_cDLJ_ATUO=0;
  300. BKQD_AutoDelay = dwTickCount + 1000;
  301. BKQD_MotorDelay = dwTickCount + 2000;
  302. if((BKQD_MotorStep==63 || BKQD_MotorStep==64 || BKQD_MotorStep==65) && !BKQD_QIAN_LIMIT_IN)
  303. 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);
  304. else if((KK_cRealPos < BKQD_PARAM_ZIPPER_LENGTH) && (BKQD_MotorStep > 311))
  305. AxisMoveTwoPos(X_AXIS,1000,(BKQD_PARAM_ZIPPER_LENGTH - KK_cRealPos) + (*BK_length_buffer),
  306. BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_BACK_LOW_SPEED_LENGTH,BKQD_DIR_P,5000,3000,20,30);
  307. }
  308. }
  309. if(!KK_cDLJ_ATUO)
  310. {
  311. if(bRunning)
  312. {
  313. if(!KK_cTABLETIME)
  314. {
  315. if(dwTickCount >= BKQD_TBDelay)
  316. BKQD_TABLE_VAVLE = 0;
  317. }
  318. switch(BKQD_AutoStep)
  319. {
  320. case 1:
  321. if(dwTickCount >= BKQD_AutoDelay)
  322. {
  323. BKQD_AutoStep = 2;
  324. if(BKQD_MotorStep == 0)
  325. {
  326. BKQD_MotorStep = 61; //前点定位
  327. }
  328. KK_cGoLimitEn = 0;
  329. }
  330. break;
  331. case 2:
  332. if(BKQD_MotorStep == 0)
  333. {
  334. if(!KK_cShuangDao)
  335. BKQD_MotorStep = 30;
  336. else
  337. BKQD_MotorStep = 801;
  338. BKQD_AutoStep = 3;
  339. KK_cGoLimitEn = 1;
  340. }
  341. break;
  342. case 3:
  343. if(BKQD_MotorStep == 0)
  344. {
  345. if(BKQD_SAFE_IN)
  346. {
  347. bStop = 1;
  348. }
  349. else
  350. {
  351. if(!KK_cShuangDao)
  352. {
  353. if(BKQD_XiaQieStep == 0)
  354. BKQD_XiaQieStep = 1;
  355. }
  356. else
  357. {
  358. if(BKQD_XiaQieStep == 0)
  359. BKQD_XiaQieStep = 201;
  360. }
  361. BKQD_AutoStep = 4;
  362. }
  363. }
  364. break;
  365. case 4:
  366. // 闭口
  367. if((BKQD_XiaQieStep == 0) || ((BKQD_XiaQieStep == 6) && BKQD_KB_MODE)|| ((BKQD_XiaQieStep == 14) && (BKQD_KB_MODE == 0)))// && !BKQD_SHANG_MU_LIMIT_IN)
  368. {
  369. if(BKQD_MotorStep == 0)
  370. {
  371. KK_cGoLimitEn=0;
  372. BKQD_MotorStep = 40; //切完后退
  373. }
  374. BKQD_AutoStep = 5;
  375. }
  376. break;
  377. case 5:
  378. if(BKQD_MotorStep == 0)
  379. {
  380. if(!KK_cDiErLaChu)
  381. cZipCnt++;
  382. BKQD_PARAM_NOW_CNT++;
  383. cTableCnt++;
  384. AddToTal(BKQD_TOTAL_ADDR);
  385. AddToTal(CT_WORKTOTAL_ADDR);
  386. CalProSP(BKQD_PROSPEED_ADDR);
  387. if(cTableCnt >= BKQD_PARAM_TABLE_NUM)
  388. {
  389. cTableCnt = 0;
  390. BKQD_TABLE_VAVLE = 1;
  391. BKQD_TBDelay = dwTickCount + BKQD_PARAM_TB_TIME;
  392. }
  393. if( SingOneFlg || cZhouWanone)
  394. {
  395. {
  396. cZhouWanone=0;
  397. cStopMode=0;
  398. bRunning = 0;
  399. BKQD_AutoStep = 0;
  400. SingOneFlg = 0;
  401. BKQD_TABLE_VAVLE = 0;
  402. }
  403. // if(GetTotal(BKQD_TOTAL_ADDR) >= BKQD_PARAM_SET_TOTAL) BKQD_SetAlarmCode(BKQD_TOTAL_ALARM);
  404. }
  405. else
  406. {
  407. BKQD_AutoStep = 1;
  408. if((BKQD_PARAM_NOW_CNT >= BKQD_PARAM_ZHA_SHU) && (BKQD_PARAM_ZHA_SHU > 0))
  409. {
  410. BKQD_AutoDelay = dwTickCount + BKQD_PARAM_ZS_STOP_TIME;
  411. BKQD_PARAM_NOW_CNT = 0;
  412. KK_cTABLETIME = 1;
  413. KK_cTABLETOTAL= 1;
  414. if(BKQD_PARAM_ZS_STOP_TIME == 0)
  415. {
  416. bRunning = 0;
  417. BKQD_AutoStep = 0;
  418. SingOneFlg = 0;
  419. KK_cTABLETIME = 1;
  420. KK_cTABLETOTAL= 1;
  421. BKQD_SetAlarmCode(BKQD_TOTAL_ALARM);
  422. }
  423. }
  424. else
  425. BKQD_AutoDelay = dwTickCount + BKQD_PARAM_CYCLE_DELAY;
  426. }
  427. }
  428. break;
  429. }
  430. }
  431. }
  432. }
  433. void BK_QueDuan_StepCheckStart(void)
  434. {
  435. // 启动
  436. if((START_IN_UP) || bStart || BKQD_bSingle)
  437. {
  438. bStart = 0;
  439. if(!bRunning && (BKQD_AutoStep == 0))
  440. {
  441. if(BKQD_XIA_MU_LIMIT_IN && !BKQD_PARAM_XM_ENABLE)BKQD_SetAlarmCode(BKQD_XM_DAOWEI);
  442. // else if(GetAlarmCode(BKQD_ALARM_ADDR) != 0);
  443. //else if(GetTotal(BKQD_TOTAL_ADDR) >= BKQD_PARAM_SET_TOTAL) BKQD_SetAlarmCode(BKQD_TOTAL_ALARM);
  444. // else if(BKQD_BL_VAVLE)BKQD_SetAlarmCode(BKQD_BL_ALARM);
  445. else if(BKQD_SM_VAVLE)BKQD_SetAlarmCode(BKQD_SM_ALARM);
  446. else
  447. {
  448. bRunning = 1;
  449. BKQD_AutoStep = 1;
  450. if(BKQD_PARAM_BL_ENABLE)
  451. BKQD_PARAM_BL_ENABLE=1 ; //并链起动
  452. if(BKQD_bSingle)
  453. {
  454. SingOneFlg= 1;
  455. BKQD_bSingle=0;
  456. }
  457. else
  458. {
  459. SingOneFlg=0;
  460. }
  461. cZipCnt = 0;
  462. KK_cTABLETIME = 0;
  463. KK_cTABLETOTAL= 0;
  464. cSTOPONE=0;
  465. cTuiFangKuaiCnt = 0;
  466. BKQD_BL_VAVLE = 0; //并链关
  467. KK_cDLJ_ATUO=0;
  468. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  469. SetAlarmCode(BKQD_ALARM_ADDR,0);
  470. }
  471. }
  472. BKQD_bSingle = 0;
  473. }
  474. if(BKQD_STOP_ANNIU_IN_UP)
  475. {
  476. bRunning = 0;
  477. BKQD_XiaQieStep = 0;
  478. BKQD_AutoStep = 0;
  479. BKQD_MotorStep = 0;
  480. BKQD_TuiLianStep = 0;
  481. BKQD_AutoDelay = dwTickCount;
  482. BKQD_MotorDelay = dwTickCount;
  483. BKQD_XiaQieDelay = dwTickCount;
  484. BKQD_KaDaiDelay = dwTickCount;
  485. BKQD_CSDelay = dwTickCount;
  486. BKQD_TBDelay = dwTickCount;
  487. BKQD_TFKDelay = dwTickCount;
  488. BKQD_TLDelay = dwTickCount;
  489. dwTickCount = BKQD_TBDelay;
  490. BKQD_CHUIQIStep=0;
  491. SingOneFlg = 0;
  492. BKQD_JD_VAVLE = 0;
  493. BKQD_SM_VAVLE = 0;
  494. BKQD_XM_VAVLE = 0;
  495. BKQD_YD_VAVLE = 0;
  496. BKQD_TFK_VAVLE= 0;
  497. BKQD_YX_VAVLE = 0;
  498. BKQD_HL_VAVLE = 0;
  499. BKQD_TL_VAVLE = 0;
  500. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  501. BKQD_CS_OUT = 0;
  502. BKQD_XiaQieStep = 0;
  503. BKQD_MotorStep = 0;
  504. BKQD_TuiLianStep = 0;
  505. BKQD_SZ_OUT = 1;
  506. BKQD_GZ_VAVLE = 0;
  507. BKQD_TABLE_VAVLE = 0;
  508. BKQD_StopStep=1;
  509. KK_cTABLETIME = 0;
  510. KK_cTABLETOTAL= 0;
  511. BKQD_BinLianStep = 0;
  512. BKQD_BL_VAVLE = 0;
  513. SetAlarmCode(BKQD_ALARM_ADDR,0);
  514. }
  515. if((BKQD_ANQUANMEN_LIMIT_IN_UP || BKQD_ANQUANMEN_LIMIT_IN) && bRunning)
  516. {
  517. BKQD_StopStep=1;
  518. cSTOPONE=1;
  519. }
  520. if(STOP_IN_UP)
  521. {
  522. if(bRunning)
  523. {
  524. KK_cShuangDao=0;
  525. KK_cDiErLaChu=0;
  526. BKQD_AutoDelay = dwTickCount;
  527. BKQD_MotorDelay = dwTickCount;
  528. BKQD_XiaQieDelay = dwTickCount;
  529. BKQD_KaDaiDelay = dwTickCount;
  530. BKQD_CSDelay = dwTickCount;
  531. BKQD_TBDelay = dwTickCount;
  532. BKQD_TFKDelay = dwTickCount;
  533. BKQD_TLDelay = dwTickCount;
  534. dwTickCount = BKQD_TBDelay;
  535. BKQD_CHUIQIStep=0;
  536. SingOneFlg = 0;
  537. BKQD_JD_VAVLE = 0;
  538. BKQD_SM_VAVLE = 0;
  539. BKQD_XM_VAVLE = 0;
  540. BKQD_YD_VAVLE = 0;
  541. BKQD_TFK_VAVLE= 0;
  542. BKQD_YX_VAVLE = 0;
  543. BKQD_HL_VAVLE = 0;
  544. cStopMode=0;
  545. cZhouWanone=0;
  546. BKQD_TL_VAVLE = 0;
  547. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  548. BKQD_CS_OUT = 0;
  549. BKQD_XiaQieStep = 0;
  550. BKQD_MotorStep = 0;
  551. BKQD_TuiLianStep = 0;
  552. // BKQD_SZ_OUT = 1;
  553. BKQD_GZ_VAVLE = 0;
  554. BKQD_TABLE_VAVLE = 0;
  555. if((BKQD_StopStep == 0) && X_DRV)
  556. BKQD_StopStep = 1;
  557. KK_cTABLETIME = 0;
  558. KK_cTABLETOTAL= 0;
  559. BKQD_BinLianStep = 0;
  560. BKQD_BL_VAVLE = 0;
  561. SetAlarmCode(BKQD_ALARM_ADDR,0);
  562. bRunning = 0;
  563. BKQD_XiaQieStep = 0;
  564. BKQD_AutoStep = 0;
  565. BKQD_MotorStep = 0;
  566. BKQD_TuiLianStep = 0;
  567. }
  568. else
  569. {
  570. KK_cShuangDao=0;
  571. KK_cDiErLaChu=0;
  572. BKQD_AutoDelay = dwTickCount;
  573. BKQD_MotorDelay = dwTickCount;
  574. BKQD_XiaQieDelay = dwTickCount;
  575. BKQD_KaDaiDelay = dwTickCount;
  576. BKQD_CSDelay = dwTickCount;
  577. BKQD_TBDelay = dwTickCount;
  578. BKQD_TFKDelay = dwTickCount;
  579. BKQD_TLDelay = dwTickCount;
  580. dwTickCount = BKQD_TBDelay;
  581. BKQD_CHUIQIStep=0;
  582. SingOneFlg = 0;
  583. BKQD_JD_VAVLE = 0;
  584. BKQD_SM_VAVLE = 0;
  585. BKQD_XM_VAVLE = 0;
  586. BKQD_YD_VAVLE = 0;
  587. BKQD_TFK_VAVLE= 0;
  588. BKQD_YX_VAVLE = 0;
  589. BKQD_HL_VAVLE = 0;
  590. cStopMode=0;
  591. cZhouWanone=0;
  592. BKQD_TL_VAVLE = 0;
  593. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  594. BKQD_CS_OUT = 0;
  595. BKQD_XiaQieStep = 0;
  596. BKQD_MotorStep = 0;
  597. BKQD_TuiLianStep = 0;
  598. BKQD_SZ_OUT = 1;
  599. BKQD_GZ_VAVLE = 0;
  600. BKQD_TABLE_VAVLE = 0;
  601. if((BKQD_StopStep == 0))
  602. {
  603. KK_cSTOPONE = 0;
  604. AxisEgmStop(X_AXIS);
  605. BKQD_SZ_OUT = 1;
  606. }
  607. KK_cTABLETIME = 0;
  608. KK_cTABLETOTAL= 0;
  609. BKQD_BinLianStep = 0;
  610. BKQD_BL_VAVLE = 0;
  611. SetAlarmCode(BKQD_ALARM_ADDR,0);
  612. bRunning = 0;
  613. BKQD_XiaQieStep = 0;
  614. BKQD_AutoStep = 0;
  615. BKQD_MotorStep = 0;
  616. BKQD_TuiLianStep = 0;
  617. }
  618. }
  619. //停止
  620. if( bStop)
  621. {
  622. bStop = 0;
  623. if(cStopMode < 2)
  624. cStopMode++;
  625. if(cStopMode==1 && bRunning)
  626. cZhouWanone=1;
  627. if(bRunning && cStopMode==2)
  628. {
  629. KK_cShuangDao=0;
  630. KK_cDiErLaChu=0;
  631. BKQD_AutoDelay = dwTickCount;
  632. BKQD_MotorDelay = dwTickCount;
  633. BKQD_XiaQieDelay = dwTickCount;
  634. BKQD_KaDaiDelay = dwTickCount;
  635. BKQD_CSDelay = dwTickCount;
  636. BKQD_TBDelay = dwTickCount;
  637. BKQD_TFKDelay = dwTickCount;
  638. BKQD_TLDelay = dwTickCount;
  639. dwTickCount = BKQD_TBDelay;
  640. SingOneFlg = 0;
  641. bRunning = 0;
  642. BKQD_XiaQieStep = 0;
  643. BKQD_AutoStep = 0;
  644. BKQD_MotorStep = 0;
  645. BKQD_TuiLianStep = 0;
  646. BKQD_JD_VAVLE = 0;
  647. BKQD_SM_VAVLE = 0;
  648. BKQD_XM_VAVLE = 0;
  649. BKQD_YD_VAVLE = 0;
  650. BKQD_TFK_VAVLE= 0;
  651. BKQD_TL_VAVLE = 0;
  652. BKQD_HL_VAVLE = 0;
  653. BKQD_CS_OUT = 0;
  654. BKQD_XiaQieStep = 0;
  655. BKQD_MotorStep = 0;
  656. BKQD_TuiLianStep = 0;
  657. //BKQD_SZ_OUT = 1;
  658. BKQD_GZ_VAVLE = 0;
  659. BKQD_TABLE_VAVLE = 0;
  660. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  661. if((BKQD_StopStep == 0) && X_DRV)
  662. BKQD_StopStep = 1;
  663. BKQD_BinLianStep = 0;
  664. BKQD_BL_VAVLE = 0;
  665. KK_cTABLETIME = 0;
  666. KK_cTABLETOTAL= 0;
  667. user_datas[121] = 0;
  668. user_datas[122] = 0;
  669. SetAlarmCode(BKQD_ALARM_ADDR,0);
  670. }
  671. else if(!bRunning)
  672. {
  673. KK_cShuangDao=0;
  674. KK_cDiErLaChu=0;
  675. BKQD_AutoDelay = dwTickCount;
  676. BKQD_MotorDelay = dwTickCount;
  677. BKQD_XiaQieDelay = dwTickCount;
  678. BKQD_KaDaiDelay = dwTickCount;
  679. BKQD_CSDelay = dwTickCount;
  680. BKQD_TBDelay = dwTickCount;
  681. BKQD_TFKDelay = dwTickCount;
  682. BKQD_TLDelay = dwTickCount;
  683. dwTickCount = BKQD_TBDelay;
  684. BKQD_CHUIQIStep=0;
  685. SingOneFlg = 0;
  686. BKQD_JD_VAVLE = 0;
  687. BKQD_SM_VAVLE = 0;
  688. BKQD_XM_VAVLE = 0;
  689. BKQD_YD_VAVLE = 0;
  690. BKQD_TFK_VAVLE= 0;
  691. BKQD_YX_VAVLE = 0;
  692. BKQD_HL_VAVLE = 0;
  693. cStopMode=0;
  694. cZhouWanone=0;
  695. BKQD_TL_VAVLE = 0;
  696. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  697. BKQD_CS_OUT = 0;
  698. BKQD_XiaQieStep = 0;
  699. BKQD_MotorStep = 0;
  700. BKQD_TuiLianStep = 0;
  701. BKQD_SZ_OUT = 1;
  702. BKQD_GZ_VAVLE = 0;
  703. BKQD_TABLE_VAVLE = 0;
  704. if((BKQD_StopStep == 0))
  705. {
  706. KK_cSTOPONE = 0;
  707. AxisEgmStop(X_AXIS);
  708. BKQD_SZ_OUT = 1;
  709. }
  710. KK_cTABLETIME = 0;
  711. KK_cTABLETOTAL= 0;
  712. BKQD_BinLianStep = 0;
  713. BKQD_BL_VAVLE = 0;
  714. SetAlarmCode(BKQD_ALARM_ADDR,0);
  715. bRunning = 0;
  716. BKQD_XiaQieStep = 0;
  717. BKQD_AutoStep = 0;
  718. BKQD_MotorStep = 0;
  719. BKQD_TuiLianStep = 0;
  720. }
  721. }
  722. if(bAlarmStop)
  723. {
  724. bAlarmStop = 0;
  725. BKQD_XiaQieStep = 0;
  726. BKQD_AutoStep = 0;
  727. BKQD_MotorStep = 0;
  728. BKQD_TuiLianStep = 0;
  729. BKQD_XiaQieStep = 0;
  730. BKQD_MotorStep = 0;
  731. BKQD_TuiLianStep = 0;
  732. BKQD_AutoDelay = dwTickCount;
  733. BKQD_MotorDelay = dwTickCount;
  734. BKQD_XiaQieDelay = dwTickCount;
  735. BKQD_KaDaiDelay = dwTickCount;
  736. BKQD_CSDelay = dwTickCount;
  737. BKQD_TBDelay = dwTickCount;
  738. BKQD_TFKDelay = dwTickCount;
  739. BKQD_TLDelay = dwTickCount;
  740. SingOneFlg = 0;
  741. bRunning = 0;
  742. // BKQD_StopStep=1;
  743. cStopMode=0;
  744. cZhouWanone=0;
  745. dwTickCount = BKQD_TBDelay;
  746. BKQD_TABLE_VAVLE = 0;
  747. BKQD_TFK_VAVLE =0;
  748. BKQD_JD_VAVLE=0;
  749. BKQD_GZ_VAVLE=0;
  750. }
  751. }
  752. //记忆长度模式误差检测
  753. void BK_QueDuan_CheckLength(long zip_length)
  754. {
  755. static long start_dist;
  756. switch(BKQD_CheckLengthStep)
  757. {
  758. case 0:break;
  759. case 1:
  760. start_dist = KK_cRealPos;
  761. dwSaveLength = 0;
  762. BKQD_CheckLengthStep = 2;
  763. break;
  764. case 2:
  765. if(BKQD_GUO_LIAN_IN_DW)
  766. {
  767. dwSaveLength = KK_cRealPos - start_dist;
  768. // user_datas[127] = KK_cRealPos;
  769. }
  770. break;
  771. }
  772. }
  773. void BK_QueDuan_BingLian(void)
  774. {
  775. static long bl_pos_buff,HL_delay;
  776. switch(BKQD_BinLianStep)
  777. {
  778. case 1:
  779. bl_pos_buff = KK_cRealPos;
  780. BKQD_BinLianStep = 2;
  781. break;
  782. case 2:
  783. if((KK_cRealPos - bl_pos_buff) >= BKQD_PARAM_DELAY_HL_LENGTH)
  784. {
  785. BKQD_BL_VAVLE = 1;
  786. BKQD_BinLianStep = 3;
  787. }
  788. break;
  789. case 3://有过链检测
  790. if((KK_cRealPos - bl_pos_buff) >= (BKQD_PARAM_ZIPPER_LENGTH - BKQD_PARAM_HL_DELAY_BACK))
  791. {
  792. BKQD_BL_VAVLE = 0;
  793. BKQD_BinLianStep = 0;
  794. }
  795. if(BKQD_GUO_LIAN_IN_DW && BKQD_PARAM_BACK_MODE ==1) //|| (BKQD_PARAM_BACK_MODE==2 && cZipCnt < 2)))
  796. {
  797. BKQD_BL_VAVLE = 0;
  798. BKQD_BinLianStep = 0;
  799. }
  800. break;
  801. case 10:
  802. bl_pos_buff = KK_cRealPos;
  803. BKQD_BinLianStep = 11;
  804. break;
  805. case 11:
  806. if((KK_cRealPos - bl_pos_buff) >= BKQD_PARAM_DELAY_HL_LENGTH)
  807. {
  808. BKQD_BL_VAVLE = 1;
  809. BKQD_BinLianStep = 12;
  810. }
  811. break;
  812. case 12://有过链检测
  813. if(BKQD_GUO_LIAN_IN_DW)
  814. {
  815. BKQD_BL_VAVLE = 0;
  816. BKQD_BinLianStep = 0;
  817. }
  818. break;
  819. default:;
  820. }
  821. }
  822. //作闭口专用程序
  823. //不带过链感应长度输入电机长度 闭口有勾针到位
  824. void BK_QueDuan_Motor_NoGL(void)
  825. {
  826. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  827. long pulse_buff;
  828. unsigned short ch,kk;
  829. user_datas[121] = BKQD_MotorStep;
  830. user_datas[122] = BKQD_AutoStep;
  831. user_datas[123]= KK_cRealPos;
  832. user_datas[125]= bRunning;
  833. // user_datas[123] = length_buff - (*BK_length_buffer);
  834. // user_datas[127] = KK_cRealPos;
  835. // user_datas[126] = go_buff - KK_cRealPos;
  836. if((BKQD_MotorStep >= 101) && (BKQD_MotorStep <= 103))
  837. {
  838. if(BKQD_QIAN_LIMIT_IN_DW)BKQD_HL_VAVLE = 0;
  839. }
  840. if(!KK_cDLJ_ATUO)
  841. {
  842. switch(BKQD_MotorStep)
  843. {
  844. case 30:
  845. switch(BKQD_PARAM_BACK_MODE) //开口分四种模式
  846. {
  847. case 0: //单数控模式
  848. BKQD_MotorStep = 310; //每种模式留20步
  849. BKQD_DGLG_VAVLE = 1; //顶过链杆关
  850. break;
  851. case 1://单感应模式
  852. BKQD_MotorStep = 330; //每种模式留20步
  853. break;
  854. case 2: //先感应后数控模式+检测
  855. BKQD_MotorStep = 350; //每种模式留20步
  856. break;
  857. default: //数控模式+过链检测长度
  858. BKQD_MotorStep = 370; //每种模式留20步
  859. break;
  860. }
  861. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_DELAY_BACK;
  862. break;
  863. case 310:
  864. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_DELAY_BACK;
  865. SetDir(X_AXIS, BKQD_DIR_P);
  866. BKQD_JZ_DIR = BKQD_YDIR_P;
  867. SetPos(X_AXIS, 0);
  868. BK_length_buffer = &BKQD_PARAM_OFFSET_LENGTH;
  869. if(BKQD_PARAM_BL_ENABLE) //
  870. BKQD_BinLianStep = 1;
  871. BKQD_MotorStep = 311;
  872. break;
  873. case 311:
  874. if(KK_cRealPos >= (BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_GOUZHEN_LENGTH ))
  875. BKQD_GZ_VAVLE = 1;
  876. if(dwTickCount >= BKQD_MotorDelay)
  877. {
  878. back_buff = KK_cRealPos;
  879. gou_zhen_buff = KK_cRealPos;
  880. save_buff = KK_cRealPos;
  881. BK_length_buffer = &BKQD_PARAM_OFFSET_LENGTH;
  882. DCC_TIME_BL=BKQD_PARAM_GO_HIGH_SPEED/500;
  883. //李永庆代码
  884. //两段速度移动距离
  885. // 轴 第一段速度 第一段长度要减去送链长度 第二段速度 第二段长度 方向
  886. AxisMovePosAccDecNotStop(X_AXIS,BKQD_PARAM_BACK_SPEED,BKQD_PARAM_ZIPPER_LENGTH + (*BK_length_buffer), BKQD_PARAM_START_SPEED,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_ACC,DCC_TIME_BL,BKQD_PARAM_BACK_LOW_SPEED_LENGTH);
  887. BKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  888. BKQD_MotorStep = 312;
  889. }
  890. break;
  891. case 312:
  892. if(BKQD_PARAM_BL_ENABLE)
  893. {
  894. if(KK_cRealPos>BKQD_PARAM_DELAY_HL_LENGTH)
  895. {
  896. BKQD_YD_VAVLE=1;
  897. }
  898. if(KK_cRealPos>(BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_HL_DELAY_BACK-200))
  899. {
  900. BKQD_YD_VAVLE=0;
  901. }
  902. }
  903. //勾针提前输出
  904. if(KK_cRealPos >= (BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_GOUZHEN_LENGTH ))
  905. BKQD_GZ_VAVLE = 1;
  906. if((KK_cRealPos) > (BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_BACK_LOW_SPEED_LENGTH)) //- (*BK_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)))))
  907. {
  908. BKQD_MotorDelay = dwTickCount + 3000; //钩针未到位延时警告
  909. BKQD_MotorStep = 313;
  910. }
  911. else if(KK_cRealPos >= (BKQD_PARAM_ZIPPER_LENGTH + 200 + (*BK_length_buffer)))//BKQD_PARAM_ERROR_LENGTH))
  912. {
  913. BKQD_SetAlarmCode(BKQD_GZ_ALARM);
  914. }
  915. break;
  916. case 313:
  917. if(BKQD_PARAM_BL_ENABLE)
  918. {
  919. if(KK_cRealPos>BKQD_PARAM_DELAY_HL_LENGTH)
  920. {
  921. BKQD_YD_VAVLE=1;
  922. }
  923. if(KK_cRealPos>(BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_HL_DELAY_BACK-200))
  924. {
  925. BKQD_YD_VAVLE=0;
  926. }
  927. }
  928. if(KK_cRealPos >= (BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_GOUZHEN_LENGTH ))
  929. {
  930. BKQD_GZ_VAVLE = 1;
  931. // BKQD_MotorDelay = dwTickCount + 2000; //钩针未到位延时警告
  932. }
  933. if(BKQD_GOUZHEN_IN)
  934. {
  935. AxisEgmStop(X_AXIS);
  936. BKQD_MotorDelay = dwTickCount + 10;
  937. BKQD_YD_VAVLE = 1;
  938. BKQD_MotorStep = 314;
  939. BKQD_BL_VAVLE = 0; //停止时并链一定要打开
  940. }
  941. else if(KK_cRealPos >= (BKQD_PARAM_ZIPPER_LENGTH+100+(*BK_length_buffer)))
  942. {
  943. AxisEgmStop(X_AXIS);
  944. if(dwTickCount >= BKQD_MotorDelay)
  945. BKQD_SetAlarmCode(BKQD_GZ_ALARM);
  946. }
  947. break;
  948. case 314:
  949. if(BKQD_PARAM_BL_ENABLE)
  950. {
  951. if(KK_cRealPos>BKQD_PARAM_DELAY_HL_LENGTH)
  952. {
  953. BKQD_YD_VAVLE=1;
  954. }
  955. if(KK_cRealPos>(BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_HL_DELAY_BACK-200))
  956. {
  957. BKQD_YD_VAVLE=0;
  958. }
  959. }
  960. if(!X_DRV && (dwTickCount >= BKQD_MotorDelay))
  961. {
  962. BKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  963. BKQD_YD_VAVLE = 1;
  964. BKQD_MotorStep = 315;
  965. SetDir(X_AXIS, BKQD_DIR_N);
  966. BKQD_JZ_DIR = BKQD_YDIR_N;
  967. }
  968. break;
  969. case 315:
  970. if(cZipCnt == 0)
  971. {
  972. ch = BKQD_PARAM_ZIPPER_LENGTH + (*BK_length_buffer)-120;
  973. kk = BKQD_PARAM_ZIPPER_LENGTH + (*BK_length_buffer)+120;
  974. }
  975. else
  976. {
  977. ch = BKQD_PARAM_ZIPPER_LENGTH + (*BK_length_buffer)-100;
  978. kk = BKQD_PARAM_ZIPPER_LENGTH + (*BK_length_buffer)+100;
  979. }user_datas[128] = ch;
  980. user_datas[127] = kk;
  981. if(((KK_cRealPos) < (ch)))
  982. {
  983. SetAlarmCode(BKQD_ALARM_ADDR,BKQD_LENGTH_LONG_ALARM);
  984. if(dwTickCount >= BKQD_MotorDelay)
  985. bAlarmStop = 1;
  986. }
  987. else if((KK_cRealPos > kk))//(BKQD_PARAM_ERROR_LENGTH - 200 + (*BK_length_buffer)+50)))
  988. {
  989. SetAlarmCode(BKQD_ALARM_ADDR,BKQD_LENGTH_LONG_ALARM);
  990. if(dwTickCount >= BKQD_MotorDelay)
  991. bAlarmStop = 1;
  992. }
  993. else
  994. {
  995. BKQD_MotorStep =390;
  996. }
  997. break;
  998. case 330:
  999. back_buff = KK_cRealPos;
  1000. gou_zhen_buff = KK_cRealPos;
  1001. save_buff = KK_cRealPos;
  1002. BKQD_MotorStep = 331;
  1003. SetDir(X_AXIS, BKQD_DIR_P);
  1004. user_datas[127] = 0;
  1005. break;
  1006. case 331:
  1007. if(dwTickCount >= BKQD_MotorDelay)
  1008. {
  1009. BKQD_MotorStep = 332;
  1010. if(cZipCnt < 2)
  1011. {
  1012. if(BKQD_PARAM_BL_ENABLE)
  1013. BKQD_BinLianStep = 10; //并链起动
  1014. //第一条都是过链感应,后拉速度减半//原来BKQD_PARAM_CHECK_BACK_HSPEED/2
  1015. // X轴 运行速度 启动速度 加速度 减速度
  1016. AxisContinueMoveAcc(X_AXIS,9000,BKQD_DIR_P,BKQD_PARAM_START_SPEED,2000,8,13);
  1017. }
  1018. else
  1019. {
  1020. if(BKQD_PARAM_BL_ENABLE)
  1021. BKQD_BinLianStep = 1; //并链起动
  1022. //因为每条都是过链感应,所以直接运行检测模式后拉速度
  1023. // X轴 运行速度 启动速度 加速度 减速度
  1024. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_CHECK_BACK_HSPEED,BKQD_DIR_P,BKQD_PARAM_START_SPEED,2000,BKQD_PARAM_ACC,BKQD_PARAM_DCC);
  1025. }
  1026. }
  1027. break;
  1028. case 332:
  1029. if(cZipCnt > 1) //第三条开始数控降速
  1030. {
  1031. if((KK_cRealPos + BKQD_PARAM_BACK_LOW_SPEED_LENGTH + 300)>= length_buff)
  1032. {
  1033. AxisContinueMoveChangeSpeed(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_BACK_LOW_SPEED/2,25,15);
  1034. BKQD_MotorStep = 334; //到检测定位
  1035. }
  1036. if(BKQD_GUO_LIAN_IN_UP) //重新到链上
  1037. {
  1038. BKQD_GZ_VAVLE = 1;
  1039. AxisContinueMoveChangeSpeed(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_BACK_LOW_SPEED/2,25,15);
  1040. gou_zhen_buff = KK_cRealPos;
  1041. BKQD_MotorStep = 333; //到检测定位
  1042. BKQD_MotorDelay = dwTickCount + 3;//BKQD_PARAM_DELAY_XM;
  1043. }
  1044. if(!BKQD_GZ_VAVLE && (KK_cRealPos + BKQD_PARAM_GOUZHEN_LENGTH) > (BKQD_PARAM_ZIPPER_LENGTH ))
  1045. {
  1046. BKQD_GZ_VAVLE = 1;
  1047. }
  1048. }
  1049. else //第一条工作
  1050. {
  1051. if(BKQD_GUO_LIAN_IN_UP)
  1052. {
  1053. checkdelay_buff = KK_cRealPos;
  1054. AxisContinueMoveChangeSpeed(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_BACK_LOW_SPEED/2,25,15);
  1055. BKQD_MotorDelay = dwTickCount + 3;//BKQD_PARAM_DELAY_XM;
  1056. BKQD_MotorStep = 333;
  1057. }
  1058. }
  1059. break;
  1060. case 333: //此步为前两条运行
  1061. if(BKQD_GUO_LIAN_IN_DW)
  1062. {
  1063. gou_zhen_buff = KK_cRealPos;
  1064. }
  1065. if(dwTickCount >= BKQD_MotorDelay)
  1066. {
  1067. if(BKQD_GUO_LIAN_IN)
  1068. {
  1069. AxisContinueMoveChangeSpeed(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_BACK_LOW_SPEED/2,25,15);
  1070. back_buff = KK_cRealPos;
  1071. BKQD_MotorDelay = dwTickCount + 30;
  1072. BKQD_MotorStep = 335;
  1073. }
  1074. }
  1075. else
  1076. {
  1077. if(!BKQD_GUO_LIAN_IN)
  1078. {
  1079. BKQD_MotorStep = 332;
  1080. }
  1081. }
  1082. break;
  1083. case 334:
  1084. if(BKQD_GUO_LIAN_IN_DW) //下降沿,定位长度
  1085. {
  1086. gou_zhen_buff = KK_cRealPos;
  1087. BKQD_MotorStep = 335;
  1088. BKQD_MotorDelay = dwTickCount + 30;
  1089. BKQD_GZ_VAVLE = 1;
  1090. }
  1091. if(cZipCnt > 1) //第三条开始要长度误差
  1092. {
  1093. if(KK_cRealPos >= (length_buff + BKQD_PARAM_ERROR_LENGTH))
  1094. {
  1095. BKQD_SetAlarmCode(BKQD_LENGTH_LONG_ALARM);
  1096. user_datas[128] = 1;
  1097. }
  1098. }
  1099. break;
  1100. case 335:
  1101. if(BKQD_GUO_LIAN_IN_DW)
  1102. {
  1103. gou_zhen_buff = KK_cRealPos;
  1104. BKQD_GZ_VAVLE = 1;
  1105. }
  1106. //在空们都把延时清零
  1107. if(BKQD_GUO_LIAN_IN)
  1108. {
  1109. gou_zhen_buff = KK_cRealPos;
  1110. }
  1111. if(BKQD_GOUZHEN_IN)
  1112. {
  1113. AxisEgmStop(X_AXIS);
  1114. BKQD_MotorDelay = dwTickCount + 10;
  1115. BKQD_YD_VAVLE = 1;
  1116. BKQD_MotorStep = 336;
  1117. BKQD_BL_VAVLE = 0; //停止时并链一定要打开
  1118. }
  1119. else
  1120. {
  1121. if(cZipCnt > 1) //2 条后才有长度误差
  1122. {
  1123. if(KK_cRealPos >= (length_buff + 100))
  1124. {
  1125. AxisEgmStop(X_AXIS);
  1126. user_datas[128] = 2;
  1127. if(dwTickCount >= BKQD_MotorDelay)
  1128. BKQD_SetAlarmCode(BKQD_GZ_ALARM);
  1129. }
  1130. }
  1131. }
  1132. break;
  1133. case 336:
  1134. if(cZipCnt > 1) //长度检测
  1135. {
  1136. ch = BKQD_PARAM_ZIPPER_LENGTH;
  1137. user_datas[127] = ch;
  1138. if(((KK_cRealPos + BKQD_PARAM_ERROR_LENGTH) < (ch)) && BKQD_PARAM_ERROR_LENGTH)
  1139. {
  1140. BKQD_SetAlarmCode(BKQD_LENGTH_LONG_ALARM);
  1141. user_datas[128] = 3;
  1142. }
  1143. else if((KK_cRealPos > (ch + BKQD_PARAM_ERROR_LENGTH)) && BKQD_PARAM_ERROR_LENGTH)//(BKQD_PARAM_ERROR_LENGTH - 200 + (*BK_length_buffer)+50)))
  1144. {
  1145. user_datas[128] = 4;
  1146. BKQD_SetAlarmCode(BKQD_LENGTH_SHORT_ALARM);
  1147. }
  1148. else
  1149. {
  1150. BKQD_MotorStep = 337;
  1151. }
  1152. }
  1153. else
  1154. {
  1155. if(cZipCnt == 1)
  1156. {
  1157. length_buff = KK_cRealPos - save_buff;
  1158. SetData32bits(BKQD_PARAM_ZIPPER_LENGTH_ADDR,length_buff); //测量记录长度
  1159. }
  1160. BKQD_MotorStep = 337;
  1161. }
  1162. break;
  1163. case 337:
  1164. BKQD_MotorStep = 390;
  1165. // SetDir(X_AXIS, BKQD_DIR_N);
  1166. // if(dwTickCount >= BKQD_MotorDelay)
  1167. // {
  1168. // AxisMovePosAccDec(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,-BKQD_PARAM_FZ_LENGTH,3000,BKQD_PARAM_ACC,BKQD_PARAM_DCC);
  1169. // BKQD_MotorStep = 0;
  1170. // }
  1171. break;
  1172. //350步到369步单感应模式
  1173. case 350:
  1174. back_buff = KK_cRealPos;
  1175. gou_zhen_buff = KK_cRealPos;
  1176. save_buff = KK_cRealPos;
  1177. BKQD_MotorStep = 351;
  1178. break;
  1179. case 351:
  1180. if(dwTickCount >= BKQD_MotorDelay)
  1181. {
  1182. BKQD_MotorStep = 352;
  1183. //第一,二条都是过链感应,测量长度
  1184. if(cZipCnt < 2)
  1185. {
  1186. if(BKQD_PARAM_BL_ENABLE) //因为长度未知,只能通过过链退合链
  1187. BKQD_BinLianStep = 10; //并链起动
  1188. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  1189. // X轴 运行速度 启动速度 加速度 减速度
  1190. AxisContinueMoveAcc(X_AXIS,9000,BKQD_DIR_P,BKQD_PARAM_START_SPEED,2000,8,12);
  1191. }
  1192. else
  1193. {
  1194. if(BKQD_PARAM_BL_ENABLE)
  1195. BKQD_BinLianStep = 1; //并链起动
  1196. BKQD_DGLG_VAVLE = 1; //顶过链杆关
  1197. BKQD_CheckLengthStep = 1; //长度检测,第3条才有对比
  1198. //走数控方式,因第二条中已经测量出来拉链长度,可以直接按长度数控方式走
  1199. BKQD_MotorStep = 311;
  1200. }
  1201. }
  1202. break;
  1203. case 352:
  1204. //前两条都按最低速度工作
  1205. if(BKQD_GUO_LIAN_IN_UP)
  1206. {
  1207. checkdelay_buff = KK_cRealPos;
  1208. AxisContinueMoveChangeSpeed(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_BACK_LOW_SPEED/2,25,15);
  1209. BKQD_MotorDelay = dwTickCount + 3;//BKQD_PARAM_DELAY_XM;
  1210. BKQD_MotorStep = 353;
  1211. BKQD_GZ_VAVLE = 1;
  1212. }
  1213. break;
  1214. case 353:
  1215. if(BKQD_GUO_LIAN_IN_DW)
  1216. {
  1217. gou_zhen_buff = KK_cRealPos;
  1218. }
  1219. if(dwTickCount >= BKQD_MotorDelay)
  1220. {
  1221. if(BKQD_GUO_LIAN_IN)
  1222. {
  1223. AxisContinueMoveChangeSpeed(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_BACK_LOW_SPEED/2,25,15);
  1224. back_buff = KK_cRealPos;
  1225. BKQD_MotorDelay = dwTickCount + 30;
  1226. BKQD_MotorStep = 354;
  1227. }
  1228. }
  1229. else
  1230. {
  1231. if(!BKQD_GUO_LIAN_IN)
  1232. {
  1233. BKQD_MotorStep = 352;
  1234. }
  1235. }
  1236. break;
  1237. case 354:
  1238. if(BKQD_GUO_LIAN_IN_DW) //下降沿,定位长度
  1239. {
  1240. if(BKQD_GUO_LIAN_IN_DW)
  1241. {
  1242. gou_zhen_buff = KK_cRealPos;
  1243. BKQD_MotorStep = 355;
  1244. BKQD_GZ_VAVLE = 1;
  1245. }
  1246. }
  1247. if(BKQD_GOUZHEN_IN)
  1248. {
  1249. AxisEgmStop(X_AXIS);
  1250. BKQD_MotorDelay = dwTickCount + 10;
  1251. BKQD_YD_VAVLE = 1;
  1252. BKQD_MotorStep = 356;
  1253. BKQD_BL_VAVLE = 0; //停止时并链一定要打开
  1254. }
  1255. break;
  1256. case 355:
  1257. //在空们都把延时清零
  1258. if(BKQD_GOUZHEN_IN)
  1259. {
  1260. AxisEgmStop(X_AXIS);
  1261. BKQD_MotorDelay = dwTickCount + 10;
  1262. BKQD_YD_VAVLE = 1;
  1263. BKQD_MotorStep = 356;
  1264. BKQD_BL_VAVLE = 0; //停止时并链一定要打开
  1265. }
  1266. break;
  1267. case 356:
  1268. if(cZipCnt == 1)
  1269. {
  1270. length_buff = KK_cRealPos - save_buff;
  1271. SetData32bits(BKQD_PARAM_ZIPPER_LENGTH_ADDR,length_buff); //测量记录长度
  1272. }
  1273. BKQD_MotorStep = 357;
  1274. break;
  1275. case 357:
  1276. BKQD_MotorStep = 390; //延时反转步
  1277. break;
  1278. //此两步为到位后反转步
  1279. case 390:
  1280. SetDir(X_AXIS, BKQD_DIR_N);
  1281. BKQD_MotorDelay = dwTickCount + 30;
  1282. BKQD_MotorStep = 391;
  1283. break;
  1284. case 391:
  1285. if(dwTickCount >= BKQD_MotorDelay)
  1286. {
  1287. SetDir(X_AXIS, BKQD_DIR_N);
  1288. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,-BKQD_PARAM_FZ_LENGTH,3000,1000,BKQD_PARAM_ACC,BKQD_PARAM_DCC,0);
  1289. BKQD_MotorStep = 0;
  1290. }
  1291. break;
  1292. case 801:
  1293. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_DELAY_BACK;
  1294. SetDir(X_AXIS, BKQD_DIR_P);
  1295. BKQD_JZ_DIR = BKQD_YDIR_P;
  1296. SetPos(X_AXIS, 0);
  1297. BKQD_MotorStep = 802;
  1298. break;
  1299. case 802:
  1300. if(dwTickCount >= BKQD_MotorDelay)
  1301. {
  1302. BKQD_MotorStep = 803;
  1303. AxisMovePosAccDec(X_AXIS,3000,BKQD_PARAM_SHUANGDAO_LENGTH,1000,1000,25,50,0);
  1304. }
  1305. break;
  1306. case 803:
  1307. if(!X_DRV || KK_cRealPos>=BKQD_PARAM_SHUANGDAO_LENGTH)
  1308. {
  1309. BKQD_MotorStep = 0;
  1310. KK_cDiErLaChu=1;
  1311. }
  1312. case 40:
  1313. //切完延时后拉带松夹子
  1314. if(BKQD_PARAM_SJZ_LENGTH == 0 || KK_cShuangDao)
  1315. {
  1316. SetDir(X_AXIS, BKQD_DIR_P);
  1317. jz_buff = KK_cRealPos;
  1318. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_CUT_BACK_SPEED,BKQD_PARAM_BACK_LENGTH,1000,1000,25,50,0);
  1319. BKQD_MotorStep = 44;
  1320. BKQD_JD_VAVLE = 0;
  1321. }
  1322. else
  1323. {
  1324. jz_buff = KK_cRealPos;
  1325. SetDir(X_AXIS, BKQD_DIR_P);
  1326. BKQD_MotorStep = 41;
  1327. }
  1328. break;
  1329. case 41:
  1330. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_CUT_BACK_SPEED,BKQD_PARAM_SJZ_LENGTH+BKQD_PARAM_BACK_LENGTH,1000,1000,25,50,0);
  1331. BKQD_MotorStep = 42;
  1332. break;
  1333. case 42:
  1334. if((BKQD_PARAM_SJZ_LENGTH <= (KK_cRealPos - jz_buff)) )
  1335. {
  1336. BKQD_JD_VAVLE = 0;
  1337. BKQD_GZ_VAVLE=0;
  1338. BKQD_MotorStep = 44;
  1339. }
  1340. break;
  1341. case 44: // 切断完成后拉电机动作
  1342. if(((BKQD_PARAM_SJZ_LENGTH+BKQD_PARAM_BACK_LENGTH) <= (KK_cRealPos - jz_buff)) ||!X_DRV)
  1343. {
  1344. AxisEgmStop(X_AXIS);
  1345. if(!KK_cECQ_STOP)
  1346. BKQD_MotorStep = 0;
  1347. else
  1348. {
  1349. cStopMode=2;
  1350. bStop=1;
  1351. }
  1352. BKQD_GZ_VAVLE=0;
  1353. BKQD_MotorDelay = dwTickCount;
  1354. }
  1355. break;
  1356. case 61: // 前点定位数控模式
  1357. if(!KK_cDiErLaChu)
  1358. {
  1359. if(BKQD_SZ_OUT)
  1360. {
  1361. BKQD_SZ_OUT = 0;
  1362. BKQD_MotorDelay = dwTickCount + 150;
  1363. SetPos(X_AXIS, 0);
  1364. }
  1365. else
  1366. BKQD_MotorDelay = dwTickCount;
  1367. BKQD_BL_VAVLE = 0;//并链也要打开
  1368. SetDir(X_AXIS,BKQD_DIR_N);
  1369. BKQD_JZ_DIR = BKQD_YDIR_N;
  1370. if(!BKQD_TL_VAVLE && cZipCnt) //没送链情况下主动送链
  1371. {
  1372. if(!BKQD_SHANG_MU_LIMIT_IN && (BKQD_TuiLianStep == 0))
  1373. {
  1374. BKQD_TuiLianStep = 1;
  1375. BKQD_MotorStep = 62;
  1376. }
  1377. }
  1378. else
  1379. BKQD_MotorStep = 62;
  1380. }
  1381. else
  1382. {
  1383. if(BKQD_SHANG_MU_ORIGIN_IN)
  1384. {
  1385. KK_cDiErLaChu=0;
  1386. BKQD_MotorStep = 65;
  1387. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED/3,1000,15,15);
  1388. }
  1389. }
  1390. break;
  1391. case 62:
  1392. if(dwTickCount >= BKQD_MotorDelay)
  1393. {
  1394. if(BKQD_QIAN_LIMIT_IN)
  1395. {
  1396. SetPos(X_AXIS, 0);//在前点,直接置零点
  1397. SetDir(X_AXIS,BKQD_DIR_N);
  1398. BKQD_JZ_DIR = BKQD_YDIR_P;
  1399. //前点亮的情况下先退出
  1400. AxisMovePos(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,1000);
  1401. BKQD_MotorDelay = dwTickCount + 300;
  1402. }
  1403. BKQD_MotorStep = 63;
  1404. BKQD_JD_VAVLE = 0;
  1405. }
  1406. break;
  1407. case 63:
  1408. if(!X_DRV && !BKQD_QIAN_LIMIT_IN && (dwTickCount >= BKQD_MotorDelay))// && !BKQD_SHANG_MU_LIMIT_IN)
  1409. {
  1410. SetDir(X_AXIS, BKQD_DIR_N);
  1411. BKQD_JZ_DIR = BKQD_YDIR_N;
  1412. go_buff = KK_cRealPos;
  1413. BKQD_YD_VAVLE = 1;
  1414. BKQD_HL_VAVLE = 1;
  1415. BKQD_YX_VAVLE = 1;
  1416. //李永庆代码,当位置在慢速之外,走数控到慢速点
  1417. if(cZipCnt > 0)
  1418. {
  1419. if(KK_cRealPos>(BKQD_PARAM_GO_LOW_SPEED_LENGTH))
  1420. {
  1421. DCC_TIME_BL=BKQD_PARAM_GO_HIGH_SPEED/500;
  1422. AxisMovePosAccDecNotStop(X_AXIS,BKQD_PARAM_GO_HIGH_SPEED,-BK_cRealPos,
  1423. BKQD_PARAM_START_SPEED,BKQD_PARAM_GO_LOW_SPEED,BKQD_PARAM_ACC,DCC_TIME_BL,
  1424. BKQD_PARAM_GO_LOW_SPEED_LENGTH);
  1425. }
  1426. else
  1427. {
  1428. // X轴 运行速度 启动速度 加速度 减速度
  1429. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED/3,1000,15,15);
  1430. // MoveAction_Const_AccDec(X_AXIS, BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED_LENGTH,BKQD_PARAM_START_SPEED,BKQD_PARAM_ACC,BKQD_PARAM_DCC);
  1431. }
  1432. }
  1433. else
  1434. {
  1435. // X轴 运行速度 启动速度 加速度 减速度
  1436. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED/3,1000,15,15);
  1437. // MoveAction_Const_AccDec(X_AXIS, BKQD_DIR_N,BKQD_PARAM_FIRST_GO_HIGHSPEED,BKQD_PARAM_START_SPEED,BKQD_PARAM_ACC,BKQD_PARAM_DCC);//
  1438. }
  1439. BKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1440. BKQD_MotorStep =64;
  1441. }
  1442. break;
  1443. case 64:
  1444. if(cZipCnt > 1)
  1445. {
  1446. //李永庆代码
  1447. if(((KK_cRealPos) < (BKQD_PARAM_GO_LOW_SPEED_LENGTH+1200)))// || (BKQD_QIAN_DEC_IN))
  1448. {
  1449. user_datas[126]= GetCurSpeed(X_AXIS);
  1450. // MoveChangSpeedDec(X_AXIS,BKQD_PARAM_GO_HIGH_SPEED*2/3,6,8);
  1451. // AxisChangeSpeed(X_AXIS,40);
  1452. BKQD_MotorStep =65;
  1453. }
  1454. if(BKQD_QIAN_LIMIT_IN) //前点限位
  1455. {
  1456. BKQD_TFK_VAVLE=0;
  1457. AxisEgmStop(X_AXIS);
  1458. BKQD_MotorStep = 66;
  1459. }
  1460. }
  1461. else
  1462. {
  1463. if(BKQD_QIAN_LIMIT_IN) //前点限位
  1464. {
  1465. BKQD_TFK_VAVLE=0;
  1466. AxisEgmStop(X_AXIS);
  1467. BKQD_MotorStep = 66;
  1468. }
  1469. }
  1470. break;
  1471. case 65:
  1472. if(BKQD_QIAN_LIMIT_IN)
  1473. {
  1474. BKQD_TFK_VAVLE=0;
  1475. AxisEgmStop(X_AXIS);
  1476. BKQD_MotorStep = 66;
  1477. }
  1478. else if(dwTickCount >= BKQD_MotorDelay)
  1479. BKQD_SetAlarmCode(BKQD_NO_ZIPPER_ALARM);
  1480. break;
  1481. case 66:
  1482. if(!X_DRV)
  1483. {
  1484. BKQD_TFK_VAVLE=0;
  1485. SetPos(X_AXIS, 0);
  1486. BKQD_MotorDelay = dwTickCount;
  1487. BKQD_MotorStep = 67;
  1488. }
  1489. break;
  1490. case 67: //等推链完成后,
  1491. if((dwTickCount >= BKQD_MotorDelay) && (BKQD_TuiLianStep == 0) && ((BKQD_PARAM_TIAOSHI_MODE && BKQD_bTS) || (BKQD_PARAM_TIAOSHI_MODE == 0)) )
  1492. {
  1493. if(bRunning)
  1494. {
  1495. BKQD_JD_VAVLE = 1;
  1496. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_DELAY_BACK;
  1497. }
  1498. BKQD_MotorStep = 68;
  1499. }
  1500. break;
  1501. case 68:
  1502. if(dwTickCount >= BKQD_MotorDelay)
  1503. {
  1504. BKQD_YD_VAVLE = 0;
  1505. BKQD_HL_VAVLE = 0;
  1506. BKQD_YX_VAVLE = 0;
  1507. BKQD_CHUIQIStep=1;
  1508. BKQD_TL_VAVLE = 0;
  1509. BKQD_MotorStep = 0;
  1510. BKQD_MotorDelay = dwTickCount;
  1511. }
  1512. break;
  1513. }
  1514. }
  1515. }
  1516. //电机动作
  1517. void BK_QueDuan_Motor(void)
  1518. {
  1519. BK_QueDuan_Motor_NoGL();
  1520. }
  1521. void BK_QueDuan_TuiLianAction(void)
  1522. {
  1523. if(BKQD_PARAM_XM_ENABLE == 0)
  1524. {
  1525. BKQD_TuiLianStep = 0;
  1526. }
  1527. else
  1528. {
  1529. switch(BKQD_TuiLianStep)
  1530. {
  1531. case 1:
  1532. BKQD_TuiLianStep = 2;
  1533. break;
  1534. case 2:
  1535. BKQD_TLDelay = dwTickCount + BKQD_PARAM_YD_DELAY;
  1536. BKQD_TuiLianStep = 3;
  1537. break;
  1538. case 3:
  1539. if(!BKQD_SM_VAVLE && !BKQD_SHANG_MU_LIMIT_IN)//dwTickCount >= BKQD_TLDelay)
  1540. {
  1541. BKQD_TL_VAVLE = 1;
  1542. // BKQD_TFK_VAVLE = 0;
  1543. // if(!bRunning)BKQD_TFK_VAVLE = 1;
  1544. BKQD_TLDelay = dwTickCount + BKQD_PARAM_TL_DELAY;
  1545. BKQD_TuiLianStep = 4;
  1546. }
  1547. break;
  1548. case 4:
  1549. if(dwTickCount >= BKQD_TLDelay)
  1550. {
  1551. BKQD_TuiLianStep = 0;
  1552. }
  1553. break;
  1554. case 10:
  1555. BKQD_TuiLianStep = 11;
  1556. break;
  1557. case 11:
  1558. if(!Y_DRV)
  1559. {
  1560. {
  1561. BKQD_TuiLianStep = 0;
  1562. }
  1563. }
  1564. break;
  1565. }
  1566. }
  1567. }
  1568. //闭口专用
  1569. void BK_QueDuan_XiaQue_NO_GL(void)
  1570. {
  1571. switch(BKQD_XiaQieStep)
  1572. {
  1573. case 0:
  1574. break;
  1575. case 1:
  1576. if(!bRunning)
  1577. {
  1578. // BKQD_GZ_VAVLE = 1; //勾针
  1579. // BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CUT_DELAY;
  1580. // BKQD_XiaQieStep = 100;
  1581. BKQD_YD_VAVLE = 1;
  1582. BKQD_XiaQieStep = 2;
  1583. BKQD_XiaQieDelay = dwTickCount + 30;
  1584. }
  1585. else
  1586. {
  1587. BKQD_YD_VAVLE = 1;
  1588. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CUT_DELAY;
  1589. BKQD_XiaQieStep = 2;
  1590. }
  1591. break;
  1592. case 2:
  1593. if(dwTickCount >= BKQD_XiaQieDelay)
  1594. {
  1595. BKQD_XiaQieStep = 3;
  1596. BKQD_XiaQieDelay = dwTickCount;
  1597. }
  1598. break;
  1599. case 3:
  1600. if(dwTickCount >= BKQD_XiaQieDelay )
  1601. {
  1602. if(BKQD_SHANG_MU_ORIGIN_IN)
  1603. {
  1604. if((BKQD_PARAM_TIAOSHI_MODE && BKQD_bTS) || (BKQD_PARAM_TIAOSHI_MODE == 0))
  1605. {
  1606. BKQD_SM_VAVLE = 1;
  1607. if(!BKQD_PARAM_XM_ENABLE)
  1608. BKQD_XM_VAVLE = 1;
  1609. BKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1610. BKQD_XiaQieStep = 4;
  1611. }
  1612. }
  1613. else if(dwTickCount >= (BKQD_XiaQieDelay+3000))
  1614. {
  1615. BKQD_SetAlarmCode(BKQD_SM_YUANWEI);
  1616. }
  1617. }
  1618. break;
  1619. case 4://永兴为下模固定
  1620. if(BKQD_SHANG_MU_LIMIT_IN && (BKQD_XIA_MU_LIMIT_IN || BKQD_PARAM_XM_ENABLE))
  1621. {
  1622. BKQD_GZ_VAVLE = 0;
  1623. if(!BKQD_PARAM_CS_MODE) //气切
  1624. {
  1625. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_DELAYBACK_SM; //
  1626. BKQD_XiaQieStep = 5;
  1627. }
  1628. else
  1629. {
  1630. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_DELAY_CS; //
  1631. BKQD_XiaQieStep = 10;
  1632. } //
  1633. }
  1634. else if(dwTickCount >= BKQD_XiaQieDelay)
  1635. BKQD_SetAlarmCode(BKQD_SM_DAOWEI);
  1636. break;
  1637. case 5:
  1638. if(dwTickCount >= BKQD_XiaQieDelay)
  1639. {
  1640. BKQD_SM_VAVLE = 0;
  1641. BKQD_XM_VAVLE = 0;
  1642. BKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1643. BKQD_XiaQieStep = 6;
  1644. }
  1645. break;
  1646. case 6:
  1647. if(!BKQD_SHANG_MU_LIMIT_IN && (!BKQD_XIA_MU_LIMIT_IN || BKQD_PARAM_XM_ENABLE)) //下模不动就不用判断
  1648. {
  1649. if(BKQD_TuiLianStep == 0)
  1650. BKQD_TuiLianStep = 1;
  1651. if(!bRunning)
  1652. BKQD_JD_VAVLE = 0;
  1653. if(BKQD_PARAM_SHUANGDAO_MODE)
  1654. {
  1655. if(!BK_cShuangDao)
  1656. BK_cShuangDao=1;
  1657. else
  1658. BK_cShuangDao=0;
  1659. }
  1660. BKQD_XiaQieStep = 0;
  1661. }
  1662. else if(dwTickCount >= BKQD_XiaQieDelay)
  1663. {
  1664. BKQD_SetAlarmCode(BKQD_SM_YUANWEI);
  1665. }
  1666. break;
  1667. //10~11步为超声
  1668. case 10:
  1669. if(dwTickCount >= BKQD_XiaQieDelay)
  1670. {
  1671. if(BKQD_PARAM_CS_ENABLE)BKQD_CS_OUT = 1;
  1672. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CS_TIME; //
  1673. BKQD_XiaQieStep = 11;
  1674. }
  1675. break;
  1676. case 11:
  1677. if(dwTickCount >= BKQD_XiaQieDelay)
  1678. {
  1679. BKQD_CS_OUT = 0;
  1680. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CS_COLD_TIME; //
  1681. BKQD_XiaQieStep = 5;
  1682. }
  1683. break;
  1684. case 201:
  1685. BKQD_XiaQieStep = 3;
  1686. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CUT_DELAY;
  1687. break;
  1688. case 100:
  1689. if(dwTickCount >= BKQD_XiaQieDelay)
  1690. {
  1691. //这是双开程序,暂时不考虑
  1692. #if 1
  1693. if(BKQD_GOUZHEN_IN)
  1694. {
  1695. BKQD_YD_VAVLE = 1;
  1696. BKQD_XiaQieStep = 3;
  1697. }
  1698. #endif
  1699. }
  1700. break;
  1701. }
  1702. }
  1703. //切断动作
  1704. void BK_QueDuan_XiaQue(void)
  1705. {
  1706. BK_QueDuan_XiaQue_NO_GL();
  1707. }
  1708. #endif