JHBKQueDuanJi.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. #include "global.h"
  2. #if JIN_HONG_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 BKQD_TuiDaiAction(void);
  14. void BK_StopCode(void);
  15. void BK_Motor_SZ(unsigned char En);
  16. short *BK_length_buffer;
  17. void BK_QueDuan_ExtiActionX31(void)
  18. {
  19. BK_cCheckLianFlg = 1;
  20. }
  21. void BKQD_SetAlarmCode(unsigned alarm_code)
  22. {
  23. SetAlarmCode(BKQD_ALARM_ADDR,alarm_code);
  24. bAlarmStop = 1;
  25. }
  26. void BK_StopCode(void)
  27. {
  28. switch(BKQD_StopStep)
  29. {
  30. case 1:
  31. BKQD_StopStep=2;
  32. if(X_DRV)
  33. {
  34. AxisChangeSpeedDirect(X_AXIS,GetCurSpeed(X_AXIS) * 2/3);
  35. AxisDecStop(X_AXIS);
  36. }
  37. break;
  38. case 2:
  39. if(!X_DRV || (dwXRealPos < 10))
  40. {
  41. BKQD_StopCodeDelay=dwTickCount+350;
  42. BKQD_StopStep = 3;
  43. }
  44. break;
  45. case 3:
  46. if(dwTickCount >= BKQD_StopCodeDelay)
  47. {
  48. // if(!cSTOPONE)
  49. {
  50. BKQD_StopStep=0;
  51. }
  52. // else
  53. // {
  54. // QD_SetAlarmCode(QD_PARAM_ANQUANMEN_ALARM);
  55. // BKQD_StopStep=0;
  56. // cSTOPONE=0;
  57. // }
  58. BK_Motor_SZ(BKQD_MOTOR_DIS); //电机松轴
  59. }
  60. break;
  61. }
  62. }
  63. //电机松轴
  64. void BK_Motor_SZ(unsigned char En)
  65. {
  66. if(En) //使能
  67. {
  68. if(BKQD_PARAM_MOTOR_SELECT)
  69. BKQD_SZ_OUT = 1; //伺服电机
  70. else
  71. BKQD_SZ_OUT = 0; //步进电机
  72. }
  73. else //松轴
  74. {
  75. if(BKQD_PARAM_MOTOR_SELECT)
  76. BKQD_SZ_OUT = 0; //伺服电机
  77. else
  78. BKQD_SZ_OUT = 1; //步进电机
  79. }
  80. }
  81. void BK_QueDuan_InitAction(void)
  82. {
  83. float length_buff,pulse_buff;
  84. length_buff = BKQD_PARAM_CYCLE_LENGTH;
  85. pulse_buff = BKQD_PARAM_CYCLE_PULSE;
  86. XGearRatio = pulse_buff/length_buff;
  87. if(BKQD_PARAM_KAIBEE_SELECT > 1)
  88. BKQD_PARAM_KAIBEE_SELECT = 1;
  89. BK_Motor_SZ(BKQD_MOTOR_DIS); //电机松轴
  90. SetDirReverse(X_AXIS, 0);
  91. axis_set_parameter(axis_x, AXIS_ACCDEC_MODE,0);
  92. }
  93. void BK_QueDuan_Action(void)
  94. {
  95. BK_QueDuan_AlarmProtect();
  96. BK_StopCode();
  97. BK_QueDuan_Motor();
  98. BK_QueDuan_XiaQue();
  99. BK_QueDuan_ManualAction();
  100. BK_QueDuan_TuiLianAction();
  101. BK_QueDuan_BingLian();
  102. BK_QueDuan_AutoAction();
  103. BK_QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
  104. }
  105. //手动动作
  106. void BK_QueDuan_ManualAction(void)
  107. {
  108. if(bRunning == 0)
  109. {
  110. BK_cGoLimitEn = 0;
  111. if(BKQD_bClearTotal) //切断计数清零
  112. {
  113. BKQD_bClearTotal = 0;
  114. ClrcToTal(BKQD_TOTAL_ADDR);
  115. }
  116. if(BKQD_bClearNowTotal)
  117. {
  118. BKQD_bClearNowTotal = 0;
  119. BKQD_PARAM_NOW_CNT = 0;
  120. }
  121. if(BKQD_bXiaQie)
  122. {
  123. BKQD_bXiaQie = 0;
  124. if((BKQD_XiaQieStep == 0) && !BKQD_TL_VAVLE)
  125. {
  126. BKQD_XiaQieStep = 1;
  127. }
  128. }
  129. if(BKQD_bQianDianDW)
  130. {
  131. BKQD_bQianDianDW = 0;
  132. if(BKQD_MotorStep == 0)
  133. {
  134. BKQD_MotorStep = 61;
  135. BK_cZipCnt = 0;
  136. BK_Motor_SZ(BKQD_MOTOR_EN); //电机锁轴
  137. BKQD_MotorDelay = dwTickCount + 150;
  138. }
  139. }
  140. if(BKQD_bTL)
  141. {
  142. BKQD_bTL = 0;
  143. if(BKQD_TL_VAVLE)
  144. {
  145. BKQD_TL_VAVLE = 0;
  146. }
  147. else if(!BKQD_GZ_VAVLE && !BKQD_SM_VAVLE)
  148. {
  149. BKQD_TL_VAVLE = ~BKQD_TL_VAVLE;
  150. }
  151. }
  152. if(BKQD_bYD)
  153. {
  154. BKQD_bYD = 0;
  155. BKQD_YD_VAVLE = ~BKQD_YD_VAVLE;
  156. }
  157. if(BKQD_bGZ)
  158. {
  159. BKQD_bGZ = 0;
  160. BKQD_GZ_VAVLE = ~BKQD_GZ_VAVLE;
  161. }
  162. if(BKQD_bJD)
  163. {
  164. BKQD_bJD = 0;
  165. BKQD_JD_VAVLE = ~BKQD_JD_VAVLE;
  166. }
  167. if(BKQD_bXM)
  168. {
  169. BKQD_bXM = 0;
  170. if(BKQD_XM_VAVLE)
  171. {
  172. BKQD_XM_VAVLE = 0;
  173. }
  174. else
  175. {
  176. BKQD_XM_VAVLE = 1;
  177. }
  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)
  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_BL_VAVLE = ~BKQD_BL_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. BK_Motor_SZ(BKQD_MOTOR_EN); //电机锁轴
  233. BKQD_STOPINDelay = dwTickCount;
  234. if(!X_DRV)
  235. {
  236. // X轴 运行速度 启动速度 加速度 减速度
  237. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED,BKQD_PARAM_GO_LOW_SPEED,10,12);
  238. }
  239. }
  240. if(BKQD_bBackMotor) //后退限位已经取消
  241. {
  242. BK_Motor_SZ(BKQD_MOTOR_EN); //电机锁轴
  243. BKQD_STOPINDelay = dwTickCount;
  244. if(!X_DRV)
  245. // X轴 运行速度 启动速度 加速度 减速度
  246. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_P,BKQD_PARAM_GO_LOW_SPEED,BKQD_PARAM_GO_LOW_SPEED,10,12);
  247. }
  248. if(!BKQD_bGoMotor && !BKQD_bBackMotor && (BKQD_MotorStep == 0) && (dwTickCount >= BKQD_STOPINDelay))
  249. {
  250. if(X_DRV) AxisEgmStop(X_AXIS);
  251. }
  252. if(BKQD_QIAN_LIMIT_IN && (BKQD_MotorStep == 0) && !BKQD_bBackMotor &&(BKQD_AutoStep == 0))
  253. {
  254. if(X_DRV)AxisEgmStop(X_AXIS);
  255. }
  256. }
  257. }
  258. void BK_QueDuan_AlarmProtect(void)
  259. {
  260. dwXRealPos = GetPos(X_AXIS);
  261. if(!bRunning)
  262. {
  263. ;
  264. }
  265. else
  266. {
  267. if(BKQD_PARAM_RUN_LENGTH < 5000)
  268. BKQD_PARAM_RUN_LENGTH= 5000;
  269. if((dwXRealPos > BKQD_PARAM_RUN_LENGTH) && (BK_cGoLimitEn != 0)) //第一条手动时不保护
  270. {
  271. BKQD_StopStep = 1;
  272. BK_cGoLimitEn = 0;
  273. bStop = 1;
  274. // AxisEgmStop(X_AXIS);
  275. BKQD_JD_VAVLE = 0;
  276. BKQD_SetAlarmCode(BKQD_BACK_ALARM);
  277. }
  278. }
  279. }
  280. void BK_QueDuan_AutoAction(void)
  281. {
  282. if(bRunning)
  283. {//台面电机定时关掉
  284. if(dwTickCount >= BKQD_TBDelay)
  285. BKQD_TABLE_VAVLE = 0;
  286. switch(BKQD_AutoStep)
  287. {
  288. case 1:
  289. if(dwTickCount >= BKQD_AutoDelay)
  290. {
  291. BKQD_AutoStep = 2;
  292. if(BKQD_MotorStep == 0)
  293. {
  294. BKQD_MotorStep = 61; //前点定位
  295. }
  296. BK_cGoLimitEn = 0;
  297. }
  298. break;
  299. case 2:
  300. if(BKQD_MotorStep == 0)
  301. {
  302. BKQD_MotorStep = 30;
  303. BKQD_AutoStep = 3;
  304. BK_cGoLimitEn = 1;
  305. }
  306. break;
  307. case 3: //后面两步为延时反转步
  308. if((BKQD_MotorStep == 0))
  309. {
  310. if(BKQD_SAFE_IN)
  311. {
  312. bStop = 1;
  313. }
  314. else
  315. {
  316. BK_XiaQueOver = 0;
  317. if(BKQD_XiaQieStep == 0)
  318. BKQD_XiaQieStep = 1;
  319. BKQD_AutoStep = 4;
  320. }
  321. }
  322. break;
  323. case 4:
  324. // if((BKQD_MACHINE_TYPE == BKQD_NO_GL_TUIFANGKUAI) || (BKQD_MACHINE_TYPE == BKQD_CS_TUIFANGKUAI))
  325. // {
  326. //
  327. if((BKQD_XiaQieStep == 0) || (BK_XiaQueOver != 0))// && !BKQD_SHANG_MU_LIMIT_IN)
  328. {
  329. if(BKQD_MotorStep == 0)
  330. {
  331. BKQD_MotorStep = 40; //切完后退
  332. }
  333. BKQD_AutoStep = 5;
  334. }
  335. /*
  336. // }
  337. // else
  338. // {
  339. if(((BKQD_XiaQieStep == 0) || (BKQD_XiaQieStep == 13)) && !BKQD_SHANG_MU_LIMIT_IN && !BKQD_XIA_MU_LIMIT_IN)
  340. {
  341. if(BKQD_MotorStep == 0)
  342. {
  343. BKQD_MotorStep = 40; //切完后退
  344. BKQD_AutoStep = 5;
  345. }
  346. }
  347. }
  348. */
  349. break;
  350. case 5:
  351. if(BKQD_MotorStep == 0)
  352. {
  353. BK_XiaQueOver = 0;
  354. BK_cZipCnt++;
  355. BKQD_PARAM_NOW_CNT++;
  356. BK_cTableCnt++;
  357. AddToTal(BKQD_TOTAL_ADDR);
  358. AddToTal(CT_WORKTOTAL_ADDR);
  359. CalProSP(BKQD_PROSPEED_ADDR);
  360. if(BK_cTableCnt >= BKQD_PARAM_TABLE_NUM)
  361. {
  362. BK_cTableCnt = 0;
  363. BKQD_TABLE_VAVLE = 1;
  364. BKQD_TBDelay = dwTickCount + BKQD_PARAM_TB_TIME;
  365. }
  366. if(/*(GetTotal(BKQD_TOTAL_ADDR) >= BKQD_PARAM_SET_TOTAL) ||*/BK_QDSingOneFlg)
  367. {
  368. bRunning = 0;
  369. BKQD_AutoStep = 0;
  370. BK_QDSingOneFlg = 0;
  371. BKQD_TABLE_VAVLE = 0;
  372. // if(GetTotal(BKQD_TOTAL_ADDR) >= BKQD_PARAM_SET_TOTAL) BKQD_SetAlarmCode(BKQD_TOTAL_ALARM);
  373. }
  374. else
  375. {
  376. BKQD_AutoStep = 1;
  377. if((BKQD_PARAM_NOW_CNT >= BKQD_PARAM_ZHA_SHU) && (BKQD_PARAM_ZHA_SHU > 0))
  378. {
  379. BKQD_AutoDelay = dwTickCount + BKQD_PARAM_ZS_STOP_TIME;
  380. BKQD_PARAM_NOW_CNT = 0;
  381. if(BKQD_PARAM_ZS_STOP_TIME == 0)
  382. {
  383. bRunning = 0;
  384. BKQD_AutoStep = 0;
  385. BK_QDSingOneFlg = 0;
  386. BKQD_SetAlarmCode(BKQD_TOTAL_ALARM);
  387. BKQD_TABLE_VAVLE = 0;
  388. }
  389. }
  390. else
  391. BKQD_AutoDelay = dwTickCount + BKQD_PARAM_CYCLE_DELAY;
  392. }
  393. }
  394. break;
  395. }
  396. }
  397. }
  398. void BK_QueDuan_StepCheckStart(void)
  399. {
  400. // 启动
  401. if((BKQD_START_IN_UP) || bStart || BKQD_bSingle)
  402. {
  403. bStart = 0;
  404. if(!bRunning && (BKQD_AutoStep == 0))
  405. {
  406. if((BKQD_XIA_MU_LIMIT_IN|| BKQD_KAIKUO_XIAMO_LIMIT_IN) && !BKQD_PARAM_XM_ENABLE)BKQD_SetAlarmCode(BKQD_XM_DAOWEI);
  407. // else if(GetAlarmCode(BKQD_ALARM_ADDR) != 0);
  408. // else if(GetTotal(BKQD_TOTAL_ADDR) >= BKQD_PARAM_SET_TOTAL) BKQD_SetAlarmCode(BKQD_TOTAL_ALARM);
  409. // else if(BKQD_BL_VAVLE)BKQD_SetAlarmCode(BKQD_BL_ALARM);
  410. else if(BKQD_SM_VAVLE)BKQD_SetAlarmCode(BKQD_SM_ALARM);
  411. else
  412. {
  413. bRunning = 1;
  414. BKQD_AutoStep = 1;
  415. if(BKQD_bSingle)
  416. BK_QDSingOneFlg= 0;
  417. BK_cZipCnt = 0;
  418. BK_cTuiFangKuaiCnt = 0;
  419. BKQD_BL_VAVLE = 0; //并链关
  420. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  421. SetAlarmCode(BKQD_ALARM_ADDR,0);
  422. BK_Motor_SZ(BKQD_MOTOR_EN); //电机锁轴
  423. BKQD_AutoDelay = dwTickCount + 150;
  424. }
  425. }
  426. BKQD_bSingle = 0;
  427. }
  428. //停止
  429. if((BKQD_STOP_IN_UP && (dwTickCount >= BKQD_STOPINDelay)) || bStop)
  430. {
  431. bStop = 0;
  432. BKQD_STOPINDelay = dwTickCount + 100;
  433. if(bRunning)
  434. {
  435. BKQD_AutoDelay = dwTickCount;
  436. BKQD_MotorDelay = dwTickCount;
  437. BKQD_XiaQieDelay = dwTickCount;
  438. BKQD_KaDaiDelay = dwTickCount;
  439. BKQD_CSDelay = dwTickCount;
  440. BKQD_TBDelay = dwTickCount;
  441. BKQD_TFKDelay = dwTickCount;
  442. BKQD_TLDelay = dwTickCount;
  443. BK_QDSingOneFlg = 0;
  444. BKQD_JD_VAVLE = 0;
  445. BKQD_SM_VAVLE = 0;
  446. BKQD_XM_VAVLE = 0;
  447. BKQD_YD_VAVLE = 0;
  448. BKQD_TFK_VAVLE= 0;
  449. BKQD_TL_VAVLE = 0;
  450. // BKQD_HL_VAVLE = 0;
  451. BKQD_CS_OUT = 0;
  452. BKQD_XiaQieStep = 0;
  453. BKQD_MotorStep = 0;
  454. BKQD_TuiLianStep = 0;
  455. BKQD_GZ_VAVLE = 0;
  456. BKQD_TABLE_VAVLE = 0;
  457. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  458. if((BKQD_StopStep == 0) && X_DRV)
  459. BKQD_StopStep = 1;
  460. // AxisDecStop(X_AXIS);
  461. BKQD_BinLianStep = 0;
  462. BKQD_BL_VAVLE = 0;
  463. user_datas[121] = 0;
  464. user_datas[122] = 0;
  465. SetAlarmCode(BKQD_ALARM_ADDR,0);
  466. }
  467. else
  468. {
  469. BKQD_AutoDelay = dwTickCount;
  470. BKQD_MotorDelay = dwTickCount;
  471. BKQD_XiaQieDelay = dwTickCount;
  472. BKQD_KaDaiDelay = dwTickCount;
  473. BKQD_CSDelay = dwTickCount;
  474. BKQD_TBDelay = dwTickCount;
  475. BKQD_TFKDelay = dwTickCount;
  476. BKQD_TLDelay = dwTickCount;
  477. dwTickCount = BKQD_TBDelay;
  478. BK_QDSingOneFlg = 0;
  479. BKQD_JD_VAVLE = 0;
  480. BKQD_SM_VAVLE = 0;
  481. BKQD_XM_VAVLE = 0;
  482. BKQD_YD_VAVLE = 0;
  483. BKQD_TFK_VAVLE= 0;
  484. BKQD_TL_VAVLE = 0;
  485. BKQD_DGLG_VAVLE = 0; //顶过链杆关
  486. BKQD_GZ_VAVLE = 0;
  487. BKQD_CS_OUT = 0;
  488. BKQD_XiaQieStep = 0;
  489. BKQD_MotorStep = 0;
  490. BKQD_TuiLianStep = 0;
  491. BKQD_TABLE_VAVLE = 0;
  492. // BK_Motor_SZ(BKQD_MOTOR_DIS); //电机松轴
  493. if((BKQD_StopStep == 0))
  494. {
  495. AxisEgmStop(X_AXIS);
  496. BK_Motor_SZ(BKQD_MOTOR_DIS); //电机松轴
  497. }
  498. // AxisEgmStop(X_AXIS);
  499. BKQD_BinLianStep = 0;
  500. BKQD_BL_VAVLE = 0;
  501. SetAlarmCode(BKQD_ALARM_ADDR,0);
  502. }
  503. bRunning = 0;
  504. BKQD_XiaQieStep = 0;
  505. BKQD_AutoStep = 0;
  506. BKQD_MotorStep = 0;
  507. BKQD_TuiLianStep = 0;
  508. }
  509. if(bAlarmStop)
  510. {
  511. bAlarmStop = 0;
  512. BKQD_XiaQieStep = 0;
  513. BKQD_AutoStep = 0;
  514. BKQD_MotorStep = 0;
  515. BKQD_TuiLianStep = 0;
  516. BKQD_XiaQieStep = 0;
  517. BKQD_MotorStep = 0;
  518. BKQD_TuiLianStep = 0;
  519. BKQD_AutoDelay = dwTickCount;
  520. BKQD_MotorDelay = dwTickCount;
  521. BKQD_XiaQieDelay = dwTickCount;
  522. BKQD_KaDaiDelay = dwTickCount;
  523. BKQD_CSDelay = dwTickCount;
  524. BKQD_TBDelay = dwTickCount;
  525. BKQD_TFKDelay = dwTickCount;
  526. BKQD_TLDelay = dwTickCount;
  527. BK_QDSingOneFlg = 0;
  528. bRunning = 0;
  529. if(X_DRV)
  530. BKQD_StopStep=1;
  531. // AxisEgmStop(X_AXIS);
  532. dwTickCount = BKQD_TBDelay;
  533. BKQD_TABLE_VAVLE = 0;
  534. BKQD_JD_VAVLE=0;
  535. BKQD_GZ_VAVLE=0;
  536. }
  537. }
  538. //记忆长度模式误差检测
  539. void BK_QueDuan_CheckLength(long zip_length)
  540. {
  541. static long start_dist;
  542. switch(BKQD_CheckLengthStep)
  543. {
  544. case 0:break;
  545. case 1:
  546. start_dist = dwXRealPos;
  547. BK_dwSaveLength = 0;
  548. BKQD_CheckLengthStep = 2;
  549. break;
  550. case 2:
  551. if(BKQD_GUO_LIAN_IN_DW){
  552. BK_dwSaveLength = dwXRealPos - start_dist;
  553. }
  554. break;
  555. }
  556. }
  557. void BK_QueDuan_BingLian(void)
  558. {
  559. static long bl_pos_buff,HL_delay;
  560. switch(BKQD_BinLianStep)
  561. {
  562. case 0:break;
  563. case 1:
  564. bl_pos_buff = dwXRealPos;
  565. BKQD_BinLianStep = 2;
  566. break;
  567. case 2:
  568. if((dwXRealPos - bl_pos_buff) >= BKQD_PARAM_DELAY_HL_LENGTH)
  569. {
  570. BKQD_BL_VAVLE = 1;
  571. BKQD_BinLianStep = 3;
  572. }
  573. break;
  574. case 3://有过链检测
  575. if(BKQD_GUO_LIAN_IN_DW || ((dwXRealPos - bl_pos_buff) >= (BKQD_PARAM_ZIPPER_LENGTH - BKQD_PARAM_HL_DELAY_BACK)))
  576. {
  577. BKQD_BL_VAVLE = 0;
  578. BKQD_BinLianStep = 0;
  579. }
  580. break;
  581. case 10:
  582. bl_pos_buff = dwXRealPos;
  583. BKQD_BinLianStep = 11;
  584. break;
  585. case 11:
  586. if((dwXRealPos - bl_pos_buff) >= BKQD_PARAM_DELAY_HL_LENGTH)
  587. {
  588. BKQD_BL_VAVLE = 1;
  589. BKQD_BinLianStep = 12;
  590. }
  591. break;
  592. case 12://有过链检测
  593. if(BKQD_GUO_LIAN_IN_DW)
  594. {
  595. BKQD_BL_VAVLE = 0;
  596. BKQD_BinLianStep = 0;
  597. }
  598. break;
  599. default:;
  600. }
  601. }
  602. //电机运行步骤
  603. void BK_QueDuan_Motor_NoGL(void)
  604. {
  605. static long save_buff,length_buff,gou_zhen_buff,go_buff,checkdelay_buff,dandao_buff,gouzhen_buff,go_length_buff,jz_buff;
  606. long pulse_buff;
  607. unsigned short ch,kk;
  608. user_datas[121] = BKQD_MotorStep;
  609. user_datas[122] = BKQD_AutoStep;
  610. user_datas[123] = dwXRealPos;
  611. // user_datas[124] = dwXRealPos;
  612. switch(BKQD_MotorStep)
  613. {
  614. case 30:
  615. switch(BKQD_PARAM_BACK_MODE) //开口分四种模式
  616. {
  617. case 0: //单数控模式
  618. BKQD_MotorStep = 310; //每种模式留20步
  619. BKQD_DGLG_VAVLE = 1; //顶过链杆关
  620. break;
  621. case 1://单感应模式
  622. BKQD_MotorStep = 330; //每种模式留20步
  623. break;
  624. case 2: //先感应后数控模式+检测
  625. BKQD_MotorStep = 350; //每种模式留20步
  626. break;
  627. default: //数控模式+过链检测长度
  628. BKQD_MotorStep = 370; //每种模式留20步
  629. break;
  630. }
  631. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_DELAY_BACK;
  632. break;
  633. //310步到315步为数控模式
  634. case 310:
  635. BKQD_MotorStep = 311;
  636. // BKQD_JZ_DIR = BKQD_YDIR_P;
  637. if(BKQD_PARAM_BL_ENABLE)
  638. BKQD_BinLianStep = 1; //并链起动
  639. break;
  640. case 311:
  641. if(dwTickCount >= BKQD_MotorDelay)
  642. {
  643. BK_length_buffer = &BKQD_PARAM_OFFSET_LENGTH;
  644. // 轴 第一段速度 第一段长度要减去送链长度 第二段速度 第二段长度 方向
  645. BK_DCC_TIME_BL= BKQD_PARAM_DCC + BKQD_PARAM_GO_HIGH_SPEED/500;
  646. 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,BK_DCC_TIME_BL,BKQD_PARAM_BACK_LOW_SPEED_LENGTH);
  647. gou_zhen_buff = dwXRealPos;
  648. save_buff = dwXRealPos;
  649. BKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  650. BKQD_MotorStep = 312;
  651. }
  652. break;
  653. case 312:
  654. if(dwXRealPos >= 10)
  655. BKQD_TL_VAVLE = 0;
  656. //勾针提前输出
  657. if (!BKQD_GZ_VAVLE && ((dwXRealPos + BKQD_PARAM_GOUZHEN_LENGTH+BKQD_PARAM_TL_LENGTH) >= (BKQD_PARAM_ZIPPER_LENGTH )))
  658. {
  659. BKQD_GZ_VAVLE = 1;
  660. }
  661. if((dwXRealPos) >= (BKQD_PARAM_ZIPPER_LENGTH + (*BK_length_buffer) - 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)))))
  662. {
  663. BKQD_MotorDelay = dwTickCount + 2000; //钩针未到位延时警告
  664. BKQD_MotorStep = 313;
  665. }//下面条件为无效代码
  666. else if((dwXRealPos >= (BKQD_PARAM_ZIPPER_LENGTH-BKQD_PARAM_TL_LENGTH + (*BK_length_buffer) + BKQD_PARAM_ERROR_LENGTH)) && BKQD_PARAM_ERROR_LENGTH)
  667. {
  668. BKQD_SetAlarmCode(BKQD_GZ_ALARM);
  669. }
  670. break;
  671. case 313:
  672. if(!BKQD_GZ_VAVLE && (dwXRealPos + BKQD_PARAM_GOUZHEN_LENGTH + BKQD_PARAM_TL_LENGTH) > (BKQD_PARAM_ZIPPER_LENGTH ))
  673. {
  674. BKQD_GZ_VAVLE = 1;
  675. }
  676. if(BKQD_GOUZHEN_IN)
  677. {
  678. AxisEgmStop(X_AXIS);
  679. BKQD_MotorDelay = dwTickCount + 0;
  680. BKQD_YD_VAVLE = 1;
  681. BKQD_MotorStep = 314;
  682. BKQD_BL_VAVLE = 0; //停止时并链一定要打开
  683. }
  684. else if((dwXRealPos >= (BKQD_PARAM_ZIPPER_LENGTH - BKQD_PARAM_TL_LENGTH + (*BK_length_buffer) + BKQD_PARAM_ERROR_LENGTH)) && BKQD_PARAM_ERROR_LENGTH)
  685. {
  686. AxisEgmStop(X_AXIS);
  687. if(dwTickCount >= BKQD_MotorDelay)
  688. BKQD_SetAlarmCode(BKQD_GZ_ALARM);
  689. }
  690. break;
  691. case 314:
  692. if(!X_DRV && (dwTickCount >= BKQD_MotorDelay))
  693. {
  694. BKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  695. BKQD_YD_VAVLE = 1;//压带
  696. BKQD_MotorStep = 315;
  697. }
  698. break;
  699. case 315:
  700. if(!BKQD_PARAM_WC_LENGTH)
  701. {
  702. BKQD_PARAM_WC_LENGTH=100;
  703. }
  704. if(BK_cZipCnt == 0) //第一条把误差到正负9MM
  705. {
  706. ch = BKQD_PARAM_ZIPPER_LENGTH -BKQD_PARAM_TL_LENGTH + (*BK_length_buffer)-BKQD_PARAM_WC_LENGTH;
  707. kk = BKQD_PARAM_ZIPPER_LENGTH -BKQD_PARAM_TL_LENGTH + (*BK_length_buffer)+BKQD_PARAM_WC_LENGTH;
  708. }
  709. else
  710. {
  711. ch = BKQD_PARAM_ZIPPER_LENGTH -BKQD_PARAM_TL_LENGTH + (*BK_length_buffer)-BKQD_PARAM_WC_LENGTH;
  712. kk = BKQD_PARAM_ZIPPER_LENGTH -BKQD_PARAM_TL_LENGTH + (*BK_length_buffer)+BKQD_PARAM_WC_LENGTH;
  713. }
  714. if(((dwXRealPos) < (ch)))
  715. {
  716. SetAlarmCode(BKQD_ALARM_ADDR,BKQD_LENGTH_SHORT_ALARM);
  717. if(dwTickCount >= BKQD_MotorDelay)
  718. bAlarmStop = 1;
  719. }
  720. else if((dwXRealPos > kk))//(BKQD_PARAM_ERROR_LENGTH - 200 + (*BK_length_buffer)+50)))
  721. {
  722. SetAlarmCode(BKQD_ALARM_ADDR,BKQD_LENGTH_LONG_ALARM);
  723. if(dwTickCount >= BKQD_MotorDelay)
  724. bAlarmStop = 1;
  725. }
  726. else
  727. {
  728. BKQD_MotorStep = 0;//390; //延时反转步
  729. }
  730. break;
  731. //330步到349步单感应模式
  732. case 330:
  733. gou_zhen_buff = dwXRealPos;
  734. save_buff = dwXRealPos;
  735. BKQD_MotorStep = 331;
  736. SetDir(X_AXIS, BKQD_DIR_P);
  737. break;
  738. case 331:
  739. if(dwTickCount >= BKQD_MotorDelay)
  740. {
  741. BKQD_MotorStep = 332;
  742. if(BK_cZipCnt < 2)
  743. {
  744. if(BKQD_PARAM_BL_ENABLE)
  745. BKQD_BinLianStep = 10; //并链起动
  746. //第一条都是过链感应,后拉速度减半//原来BKQD_PARAM_CHECK_BACK_HSPEED/2
  747. // X轴 运行速度 启动速度 加速度 减速度
  748. AxisContinueMoveAcc(X_AXIS,3000,BKQD_DIR_P,BKQD_PARAM_START_SPEED/2,BKQD_PARAM_START_SPEED/2,8,13);
  749. }
  750. else
  751. {
  752. if(BKQD_PARAM_BL_ENABLE)
  753. BKQD_BinLianStep = 1; //并链起动
  754. //因为每条都是过链感应,所以直接运行检测模式后拉速度
  755. // X轴 运行速度 启动速度 加速度 减速度
  756. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_CHECK_BACK_HSPEED,BKQD_DIR_P,BKQD_PARAM_START_SPEED,BKQD_PARAM_START_SPEED,BKQD_PARAM_ACC,BKQD_PARAM_DCC);
  757. }
  758. }
  759. break;
  760. case 332:
  761. if(dwXRealPos >= 10)
  762. BKQD_TL_VAVLE = 0;
  763. if(dwXRealPos >250)
  764. {
  765. if(BKQD_GUO_LIAN_IN_UP)
  766. {
  767. checkdelay_buff = dwXRealPos;
  768. AxisContinueMoveChangeSpeed(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_BACK_LOW_SPEED/2,25,15);
  769. BKQD_MotorDelay = dwTickCount + 16;//BKQD_PARAM_DELAY_XM;
  770. BKQD_MotorStep = 333;
  771. }
  772. }
  773. break;
  774. case 333: //此步为前两条运行
  775. if(BKQD_GUO_LIAN_IN_DW)
  776. {
  777. gou_zhen_buff = dwXRealPos;
  778. BKQD_MotorStep = 335;
  779. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_GYMODE_DEALY;
  780. }
  781. break;
  782. case 334:
  783. if(BKQD_GUO_LIAN_IN_DW) //下降沿,定位长度
  784. {
  785. gou_zhen_buff = dwXRealPos;
  786. BKQD_MotorStep = 335;
  787. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_GYMODE_DEALY;
  788. }
  789. if(BK_cZipCnt > 1) //第三条开始要长度误差
  790. {
  791. if(dwXRealPos >= (length_buff + BKQD_PARAM_ERROR_LENGTH))
  792. {
  793. BKQD_SetAlarmCode(BKQD_LENGTH_LONG_ALARM);
  794. }
  795. }
  796. break;
  797. case 335:
  798. if(dwTickCount >= BKQD_MotorDelay)
  799. {
  800. BKQD_GZ_VAVLE = 1;
  801. }
  802. if(BKQD_GUO_LIAN_IN_DW)
  803. {
  804. gou_zhen_buff = dwXRealPos;
  805. }
  806. //在空们都把延时清零
  807. if(BKQD_GUO_LIAN_IN)
  808. {
  809. gou_zhen_buff = dwXRealPos;
  810. }
  811. if(BKQD_GOUZHEN_IN)
  812. {
  813. AxisEgmStop(X_AXIS);
  814. BKQD_MotorDelay = dwTickCount + 10;
  815. BKQD_YD_VAVLE = 1;
  816. BKQD_MotorStep = 336;
  817. BKQD_BL_VAVLE = 0; //停止时并链一定要打开
  818. }
  819. else
  820. {
  821. if(BK_cZipCnt > 1) //2 条后才有长度误差
  822. {
  823. if(dwXRealPos >= (length_buff + BKQD_PARAM_ERROR_LENGTH))
  824. {
  825. AxisEgmStop(X_AXIS);
  826. if(dwTickCount >= BKQD_MotorDelay)
  827. BKQD_SetAlarmCode(BKQD_GZ_ALARM);
  828. }
  829. }
  830. }
  831. break;
  832. case 336:
  833. if(BK_cZipCnt > 1) //长度检测
  834. {
  835. ch = BKQD_PARAM_ZIPPER_LENGTH;
  836. if(((dwXRealPos + BKQD_PARAM_ERROR_LENGTH) < (ch)) && BKQD_PARAM_ERROR_LENGTH)
  837. {
  838. SetAlarmCode(BKQD_ALARM_ADDR,BKQD_LENGTH_LONG_ALARM);
  839. if(dwTickCount >= BKQD_MotorDelay)
  840. bAlarmStop = 1;
  841. }
  842. else if((dwXRealPos > (ch + BKQD_PARAM_ERROR_LENGTH)) && BKQD_PARAM_ERROR_LENGTH)//(BKQD_PARAM_ERROR_LENGTH - 200 + (*BK_length_buffer)+50)))
  843. {
  844. SetAlarmCode(BKQD_ALARM_ADDR,BKQD_LENGTH_LONG_ALARM);
  845. if(dwTickCount >= BKQD_MotorDelay)
  846. bAlarmStop = 1;
  847. }
  848. else
  849. {
  850. BKQD_MotorStep = 337;
  851. }
  852. }
  853. else
  854. {
  855. if(BK_cZipCnt == 1)
  856. {
  857. length_buff = dwXRealPos - save_buff +BKQD_PARAM_TL_LENGTH;
  858. SetData32bits(BKQD_PARAM_ZIPPER_LENGTH_ADDR,length_buff); //测量记录长度
  859. }
  860. BKQD_MotorStep = 337;
  861. }
  862. break;
  863. case 337:
  864. BKQD_MotorStep = 0;//390;
  865. // SetDir(X_AXIS, BKQD_DIR_N);
  866. // if(dwTickCount >= BKQD_MotorDelay)
  867. // {
  868. // AxisMovePosAccDec(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,-BKQD_PARAM_FZ_LENGTH,3000,BKQD_PARAM_ACC,BKQD_PARAM_DCC);
  869. // BKQD_MotorStep = 0;
  870. // }
  871. break;
  872. //350步到369步单感应模式
  873. case 350:
  874. gou_zhen_buff = dwXRealPos;
  875. BKQD_MotorStep = 351;
  876. break;
  877. case 351:
  878. if(dwTickCount >= BKQD_MotorDelay)
  879. {
  880. if(BK_cZipCnt < 2)
  881. {
  882. BKQD_MotorStep = 352;
  883. if(BKQD_PARAM_BL_ENABLE)
  884. BKQD_BinLianStep = 10; //并链起动
  885. //第一条都是过链感应,后拉速度减半//原来BKQD_PARAM_CHECK_BACK_HSPEED/2
  886. // X轴 运行速度 启动速度 加速度 减速度
  887. AxisContinueMoveAcc(X_AXIS,3000,BKQD_DIR_P,BKQD_PARAM_START_SPEED/2,BKQD_PARAM_START_SPEED/2,8,13);
  888. }
  889. else
  890. {
  891. if(BKQD_PARAM_BL_ENABLE)
  892. BKQD_BinLianStep = 1; //并链起动
  893. BKQD_DGLG_VAVLE = 1; //顶过链杆关
  894. BKQD_CheckLengthStep = 1; //长度检测,第3条才有对比
  895. //走数控方式,因第二条中已经测量出来拉链长度,可以直接按长度数控方式走
  896. BKQD_MotorStep = 311;
  897. }
  898. }
  899. break;
  900. case 352:
  901. if(dwXRealPos >= 10)
  902. BKQD_TL_VAVLE = 0;
  903. if(BKQD_GUO_LIAN_IN_DW)
  904. {
  905. checkdelay_buff = dwXRealPos;
  906. AxisContinueMoveChangeSpeed(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,BKQD_PARAM_BACK_LOW_SPEED/2,25,15);
  907. // BKQD_MotorDelay = dwTickCount + 16;//BKQD_PARAM_DELAY_XM;
  908. gou_zhen_buff = dwXRealPos;
  909. BKQD_MotorStep = 355;
  910. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_GYMODE_DEALY;
  911. }
  912. break;
  913. case 355:
  914. if(dwTickCount >= BKQD_MotorDelay)
  915. {
  916. BKQD_GZ_VAVLE = 1;
  917. }
  918. if(BKQD_GUO_LIAN_IN_DW)
  919. {
  920. gou_zhen_buff = dwXRealPos;
  921. }
  922. //在空们都把延时清零
  923. if(BKQD_GUO_LIAN_IN)
  924. {
  925. gou_zhen_buff = dwXRealPos;
  926. }
  927. if(BKQD_GOUZHEN_IN)
  928. {
  929. AxisEgmStop(X_AXIS);
  930. BKQD_MotorDelay = dwTickCount + 10;
  931. BKQD_YD_VAVLE = 1;
  932. BKQD_MotorStep = 336;
  933. BKQD_BL_VAVLE = 0; //停止时并链一定要打开
  934. }
  935. break;
  936. case 356:
  937. if(BK_cZipCnt == 1)
  938. {
  939. length_buff = dwXRealPos + BKQD_PARAM_TL_LENGTH;
  940. SetData32bits(BKQD_PARAM_ZIPPER_LENGTH_ADDR,length_buff); //测量记录长度
  941. }
  942. BKQD_MotorStep = 337;
  943. break;
  944. case 357:
  945. BKQD_MotorStep = 0;//390;
  946. break;
  947. //此两步为到位后反转步
  948. case 390:
  949. BKQD_MotorDelay = dwTickCount + 30;
  950. BKQD_MotorStep = 391;
  951. break;
  952. case 391:
  953. if(dwTickCount >= BKQD_MotorDelay)
  954. {
  955. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_BACK_LOW_SPEED,-BKQD_PARAM_FZ_LENGTH,3000,3000,BKQD_PARAM_ACC,BKQD_PARAM_DCC,00);
  956. BKQD_MotorStep = 0;
  957. }
  958. break;
  959. case 40:
  960. //切完延时后拉带松夹子
  961. if(BKQD_PARAM_SJZ_LENGTH == 0)
  962. {
  963. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_CUT_BACK_DELAY;
  964. BKQD_MotorStep = 43;
  965. BKQD_JD_VAVLE = 0;
  966. }
  967. else
  968. {
  969. jz_buff = dwXRealPos;
  970. BKQD_MotorStep = 41;
  971. }
  972. break;
  973. case 41:
  974. BKQD_GZ_VAVLE=0;
  975. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_CUT_BACK_SPEED,BKQD_PARAM_SJZ_LENGTH + BKQD_PARAM_BACK_LENGTH,2500,2000,25,25,40);
  976. BKQD_MotorStep = 42;
  977. break;
  978. case 42:
  979. if(BKQD_PARAM_SJZ_LENGTH <= (dwXRealPos - jz_buff))
  980. BKQD_JD_VAVLE = 0;
  981. if(!X_DRV)
  982. {
  983. BKQD_MotorStep = 0;
  984. }
  985. break;
  986. case 43:
  987. if(dwTickCount >= BKQD_MotorDelay)
  988. {
  989. BKQD_GZ_VAVLE=0; //延时退勾针有助于切断带丝情况
  990. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_CUT_BACK_SPEED,BKQD_PARAM_BACK_LENGTH,2500,2000,15,15,30);
  991. BKQD_MotorStep = 44;
  992. }
  993. break;
  994. case 44: // 切断完成后拉电机动作
  995. if(!X_DRV)
  996. {
  997. BKQD_MotorStep = 0;
  998. BKQD_MotorDelay = dwTickCount;
  999. }
  1000. break;
  1001. case 61: // 前点定位数控模式
  1002. BKQD_BL_VAVLE = 0;//并链也要打开
  1003. if(dwTickCount >= BKQD_MotorDelay)
  1004. {
  1005. // BKQD_JZ_DIR = BKQD_YDIR_N;
  1006. if(!BKQD_TL_VAVLE && BK_cZipCnt && (BKQD_TuiLianStep == 0)) //没送链情况下主动送链
  1007. {
  1008. if(!BKQD_SHANG_MU_LIMIT_IN)
  1009. {
  1010. BKQD_TuiLianStep = 1;
  1011. BKQD_MotorStep = 62;
  1012. }
  1013. }
  1014. else
  1015. BKQD_MotorStep = 62;
  1016. }
  1017. break;
  1018. case 62:
  1019. if(dwTickCount >= BKQD_MotorDelay)
  1020. {
  1021. if(BKQD_QIAN_LIMIT_IN)
  1022. {
  1023. //前点亮的情况下先后退离开信号后再前进定位 ,10公分
  1024. AxisMovePosAccDec(X_AXIS,3000,1000,2000,2000,10,10,30);
  1025. BKQD_MotorDelay = dwTickCount + 300;
  1026. }
  1027. BKQD_MotorStep = 63;
  1028. BKQD_JD_VAVLE = 0;
  1029. }
  1030. break;
  1031. case 63:
  1032. if(!X_DRV && !BKQD_QIAN_LIMIT_IN && (dwTickCount >= BKQD_MotorDelay))// && !BKQD_SHANG_MU_LIMIT_IN)
  1033. {
  1034. BKQD_YD_VAVLE = 1;
  1035. // BKQD_HL_VAVLE = 1;
  1036. // BKQD_YX_VAVLE = 1;
  1037. //李永庆代码,当位置在慢速之外,走数控到慢速点
  1038. if(BK_cZipCnt > 0)
  1039. {
  1040. if(dwXRealPos>(BKQD_PARAM_GO_LOW_SPEED_LENGTH))
  1041. {
  1042. BK_DCC_TIME_BL= BKQD_PARAM_DCC + BKQD_PARAM_GO_HIGH_SPEED/500;
  1043. AxisMovePosAccDecNotStop(X_AXIS,BKQD_PARAM_GO_HIGH_SPEED,-dwXRealPos,
  1044. BKQD_PARAM_START_SPEED,BKQD_PARAM_GO_LOW_SPEED,BKQD_PARAM_ACC,BK_DCC_TIME_BL,
  1045. BKQD_PARAM_GO_LOW_SPEED_LENGTH + BKQD_PARAM_GO_DW_LENGTH);
  1046. }
  1047. else
  1048. {
  1049. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED/3,BKQD_PARAM_GO_LOW_SPEED,15,15);
  1050. }
  1051. }
  1052. else
  1053. {
  1054. AxisContinueMoveAcc(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,BKQD_DIR_N,BKQD_PARAM_GO_LOW_SPEED/3,BKQD_PARAM_GO_LOW_SPEED,15,15);
  1055. }
  1056. BKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1057. BKQD_MotorStep =64;
  1058. }
  1059. break;
  1060. case 64:
  1061. if(BK_cZipCnt > 1)
  1062. {
  1063. if(BKQD_QIAN_LIMIT_IN) //前点限位
  1064. {
  1065. if(BKQD_PARAM_GO_DW_LENGTH)
  1066. {
  1067. SetPos(X_AXIS, BKQD_PARAM_GO_DW_LENGTH);
  1068. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,-BKQD_PARAM_GO_DW_LENGTH,1200,1000,5,5,00);
  1069. }
  1070. else
  1071. AxisEgmStop(X_AXIS);
  1072. BKQD_MotorStep = 66;
  1073. }
  1074. }
  1075. else
  1076. {
  1077. if(BKQD_QIAN_LIMIT_IN) //前点限位
  1078. {
  1079. if(BKQD_PARAM_GO_DW_LENGTH)
  1080. {
  1081. SetPos(X_AXIS, BKQD_PARAM_GO_DW_LENGTH);
  1082. AxisMovePosAccDec(X_AXIS,BKQD_PARAM_GO_LOW_SPEED,-BKQD_PARAM_GO_DW_LENGTH,1200,1000,5,5,00);
  1083. }
  1084. else
  1085. AxisEgmStop(X_AXIS);
  1086. BKQD_MotorStep = 66;
  1087. }
  1088. }
  1089. break;
  1090. case 66:
  1091. if(!X_DRV || (dwXRealPos <= 0))
  1092. {
  1093. SetPos(X_AXIS, 0);
  1094. BKQD_MotorDelay = dwTickCount + 5;
  1095. BKQD_MotorStep = 67;
  1096. }
  1097. break;
  1098. case 67: //等推链完成后,
  1099. if((dwTickCount >= BKQD_MotorDelay) && (BKQD_TuiLianStep == 0) && ((BKQD_PARAM_TIAOSHI_MODE && BKQD_bTS) || (BKQD_PARAM_TIAOSHI_MODE == 0)) )
  1100. {
  1101. if(bRunning)
  1102. {
  1103. BKQD_JD_VAVLE = 1;
  1104. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_DELAY_BACK*3/5;
  1105. }
  1106. BKQD_MotorStep = 68;
  1107. }
  1108. break;
  1109. case 68:
  1110. if(dwTickCount >= BKQD_MotorDelay)
  1111. {
  1112. BKQD_YD_VAVLE = 0;
  1113. BKQD_MotorStep = 69;
  1114. BKQD_MotorDelay = dwTickCount + BKQD_PARAM_DELAY_BACK*2/5;
  1115. }
  1116. break;
  1117. case 69:
  1118. if(dwTickCount >= BKQD_MotorDelay)
  1119. {
  1120. BKQD_MotorStep = 0;
  1121. BKQD_MotorDelay = dwTickCount;
  1122. }
  1123. break;
  1124. }
  1125. }
  1126. //电机动作
  1127. void BK_QueDuan_Motor(void)
  1128. {
  1129. BK_QueDuan_Motor_NoGL();
  1130. }
  1131. void BK_QueDuan_TuiLianAction(void)
  1132. {
  1133. if(BKQD_PARAM_XM_ENABLE == 0)
  1134. {
  1135. BKQD_TuiLianStep = 0;
  1136. }
  1137. else
  1138. {
  1139. switch(BKQD_TuiLianStep)
  1140. {
  1141. case 1:
  1142. BKQD_TuiLianStep = 2;
  1143. break;
  1144. case 2:
  1145. BKQD_TLDelay = dwTickCount + BKQD_PARAM_YD_DELAY;
  1146. BKQD_TuiLianStep = 3;
  1147. break;
  1148. case 3:
  1149. if(!BKQD_SM_VAVLE && !BKQD_SHANG_MU_LIMIT_IN)//dwTickCount >= BKQD_TLDelay)
  1150. {
  1151. BKQD_TL_VAVLE = 1;
  1152. if(!bRunning)BKQD_TFK_VAVLE = 0;
  1153. BKQD_TLDelay = dwTickCount + BKQD_PARAM_TL_DELAY;
  1154. BKQD_TuiLianStep = 4;
  1155. }
  1156. break;
  1157. case 4:
  1158. if(dwTickCount >= BKQD_TLDelay)
  1159. {
  1160. BKQD_TuiLianStep = 0;
  1161. }
  1162. break;
  1163. case 10:
  1164. BKQD_TuiLianStep = 11;
  1165. break;
  1166. case 11:
  1167. if(!Y_DRV)
  1168. {
  1169. {
  1170. BKQD_TuiLianStep = 0;
  1171. }
  1172. }
  1173. break;
  1174. }
  1175. }
  1176. }
  1177. //闭口专用
  1178. void BK_QueDuan_XiaQue_NO_GL(void)
  1179. {
  1180. switch(BKQD_XiaQieStep)
  1181. {
  1182. case 0:
  1183. break;
  1184. case 1:
  1185. if(!bRunning)
  1186. {
  1187. BKQD_YD_VAVLE = 1;
  1188. BKQD_XiaQieStep = 2;
  1189. BKQD_XiaQieDelay = dwTickCount + 30;
  1190. }
  1191. else
  1192. {
  1193. BKQD_YD_VAVLE = 1;
  1194. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CUT_DELAY;
  1195. BKQD_XiaQieStep = 2;
  1196. }
  1197. break;
  1198. case 2:
  1199. if(dwTickCount >= BKQD_XiaQieDelay)
  1200. {
  1201. BKQD_XiaQieStep = 3;
  1202. BKQD_XiaQieDelay = dwTickCount;
  1203. if(bRunning)
  1204. BKQD_MotorStep = 390; //延时反转步
  1205. }
  1206. break;
  1207. case 3:
  1208. if(dwTickCount >= BKQD_XiaQieDelay)
  1209. {
  1210. if((BKQD_PARAM_TIAOSHI_MODE && BKQD_bTS) || (BKQD_PARAM_TIAOSHI_MODE == 0))
  1211. {
  1212. BKQD_SM_VAVLE = 1;
  1213. BKQD_XM_VAVLE = 1;
  1214. BKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1215. BKQD_XiaQieStep = 4;
  1216. BKQD_CheckTime = dwTickCount;
  1217. }
  1218. }
  1219. break;
  1220. case 4:
  1221. if(BKQD_SHANG_MU_ORIGIN_DW)
  1222. user_datas[124] = dwTickCount - BKQD_CheckTime;
  1223. if(BKQD_SHANG_MU_LIMIT_IN_UP)
  1224. user_datas[125] = dwTickCount - BKQD_CheckTime;
  1225. if(BKQD_SHANG_MU_LIMIT_IN && (BKQD_XIA_MU_LIMIT_IN || BKQD_PARAM_XM_ENABLE))
  1226. {
  1227. BKQD_GZ_VAVLE = 0;
  1228. if(!BKQD_PARAM_CS_MODE) //气切
  1229. {
  1230. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_DELAYBACK_SM; //
  1231. BKQD_XiaQieStep = 5;
  1232. }
  1233. else
  1234. {
  1235. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_DELAY_CS *3/5; //
  1236. BKQD_XiaQieStep = 10;
  1237. } //
  1238. }
  1239. else if(dwTickCount >= BKQD_XiaQieDelay)
  1240. {
  1241. if(!BKQD_SHANG_MU_LIMIT_IN)
  1242. BKQD_SetAlarmCode(BKQD_SM_DAOWEI);
  1243. else
  1244. BKQD_SetAlarmCode(BKQD_XM_DAOWEI);
  1245. }
  1246. break;
  1247. case 5:
  1248. if(dwTickCount >= BKQD_XiaQieDelay)
  1249. {
  1250. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_DELAY_CS *2/5;
  1251. BKQD_XiaQieStep = 6;
  1252. BK_XiaQueOver = 1;
  1253. }
  1254. break;
  1255. case 6:
  1256. if(dwTickCount >= BKQD_XiaQieDelay)
  1257. {
  1258. BK_XiaQueOver = 1;
  1259. BKQD_SM_VAVLE = 0;
  1260. BKQD_XM_VAVLE = 0;
  1261. BKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1262. BKQD_XiaQieStep = 7;
  1263. }
  1264. break;
  1265. case 7:
  1266. if(!BKQD_SHANG_MU_LIMIT_IN && (!BKQD_XIA_MU_LIMIT_IN || BKQD_PARAM_XM_ENABLE)) //下模不动就不用判断
  1267. {
  1268. if(BKQD_TuiLianStep == 0)
  1269. BKQD_TuiLianStep = 1;
  1270. if(!bRunning)
  1271. BKQD_JD_VAVLE = 0;
  1272. BKQD_XiaQieStep = 0;
  1273. }
  1274. else if(dwTickCount >= BKQD_XiaQieDelay)
  1275. {
  1276. BKQD_SetAlarmCode(BKQD_SM_YUANWEI);
  1277. }
  1278. break;
  1279. //10~11步为超声
  1280. case 10:
  1281. if(dwTickCount >= BKQD_XiaQieDelay)
  1282. {
  1283. if(BKQD_PARAM_CS_ENABLE)BKQD_CS_OUT = 1;
  1284. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CS_TIME; //
  1285. BKQD_XiaQieStep = 11;
  1286. }
  1287. break;
  1288. case 11:
  1289. if(dwTickCount >= BKQD_XiaQieDelay)
  1290. {
  1291. BKQD_CS_OUT = 0;
  1292. BKQD_XiaQieDelay = dwTickCount + BKQD_PARAM_CS_COLD_TIME; //
  1293. BKQD_XiaQieStep = 5;
  1294. }
  1295. break;
  1296. case 100:
  1297. if(dwTickCount >= BKQD_XiaQieDelay)
  1298. {
  1299. //这是双开程序,暂时不考虑
  1300. #if 1
  1301. if(BKQD_GOUZHEN_IN)
  1302. {
  1303. BKQD_YD_VAVLE = 1;
  1304. BKQD_XiaQieStep = 3;
  1305. }
  1306. #endif
  1307. }
  1308. break;
  1309. }
  1310. }
  1311. //切断动作
  1312. void BK_QueDuan_XiaQue(void)
  1313. {
  1314. BK_QueDuan_XiaQue_NO_GL();
  1315. }
  1316. #endif