JHKKQueDuanJi.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491
  1. #include "global.h"
  2. #if JIN_HONG_MACHINE ==1
  3. void KK_QueDuan_AlarmProtect(void);
  4. void KK_QueDuan_ManualAction(void);
  5. void KK_QueDuan_AutoAction(void);
  6. void KK_QueDuan_StepCheckStart(void);
  7. void KK_QueDuan_XiaQue(void);
  8. void KK_QueDuan_Motor(void);
  9. void KK_QueDuan_YuanDianAction(void);
  10. void KK_QueDuan_TuiLianAction(void);
  11. void KK_QueDuan_ExtiActionX31(void);
  12. void KK_QueDuan_BingLian(void);
  13. void KKQD_TuiDaiAction(void);
  14. void KK_StopCode(void);
  15. void KK_Motor_SZ(unsigned char En);
  16. short *KK_length_buffer;
  17. void KK_QueDuan_ExtiActionX31(void)
  18. {
  19. KK_cCheckLianFlg = 1;
  20. }
  21. void KKQD_SetAlarmCode(unsigned alarm_code)
  22. {
  23. SetAlarmCode(KKQD_ALARM_ADDR,alarm_code);
  24. bAlarmStop = 1;
  25. }
  26. void KK_StopCode(void)
  27. {
  28. switch(BKQD_StopStep)
  29. {
  30. case 1:
  31. KKQD_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. KKQD_StopCodeDelay=dwTickCount+350;
  42. KKQD_StopStep = 3;
  43. AxisEgmStop(X_AXIS);
  44. }
  45. break;
  46. case 3:
  47. if(dwTickCount >= BKQD_StopCodeDelay)
  48. {
  49. // if(!cSTOPONE)
  50. {
  51. KKQD_StopStep=0;
  52. }
  53. // else
  54. // {
  55. // QD_SetAlarmCode(QD_PARAM_ANQUANMEN_ALARM);
  56. // BKQD_StopStep=0;
  57. // cSTOPONE=0;
  58. // }
  59. AxisEgmStop(X_AXIS);
  60. KK_Motor_SZ(KKQD_MOTOR_DIS); //电机松轴
  61. }
  62. break;
  63. }
  64. }
  65. //电机松轴
  66. void KK_Motor_SZ(unsigned char En)
  67. {
  68. if(En) //使能
  69. {
  70. if(KKQD_PARAM_MOTOR_SELECT)
  71. KKQD_SZ_OUT = 1; //伺服电机
  72. else
  73. KKQD_SZ_OUT = 0; //步进电机
  74. }
  75. else //松轴
  76. {
  77. if(KKQD_PARAM_MOTOR_SELECT)
  78. KKQD_SZ_OUT = 0; //伺服电机
  79. else
  80. KKQD_SZ_OUT = 1; //步进电机
  81. }
  82. }
  83. void KK_QueDuan_InitAction(void)
  84. {
  85. float length_buff,pulse_buff;
  86. length_buff = KKQD_PARAM_CYCLE_LENGTH;
  87. pulse_buff = KKQD_PARAM_CYCLE_PULSE;
  88. XGearRatio = pulse_buff/length_buff;
  89. KK_Motor_SZ(KKQD_MOTOR_DIS); //电机松轴
  90. SetDirReverse(X_AXIS, 0);
  91. axis_set_parameter(axis_x, AXIS_ACCDEC_MODE,0);
  92. }
  93. void KK_QueDuan_Action(void)
  94. {
  95. KK_QueDuan_AlarmProtect();
  96. KK_StopCode();
  97. KK_QueDuan_Motor();
  98. KK_QueDuan_XiaQue();
  99. KK_QueDuan_ManualAction();
  100. KK_QueDuan_TuiLianAction();
  101. KK_QueDuan_BingLian();
  102. KK_QueDuan_AutoAction();
  103. KK_QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
  104. }
  105. //手动动作
  106. void KK_QueDuan_ManualAction(void)
  107. {
  108. if(bRunning == 0)
  109. {
  110. KK_cGoLimitEn = 0;
  111. if(KKQD_bClearTotal) //切断计数清零
  112. {
  113. KKQD_bClearTotal = 0;
  114. ClrcToTal(KKQD_TOTAL_ADDR);
  115. }
  116. if(KKQD_bClearNowTotal)
  117. {
  118. KKQD_bClearNowTotal = 0;
  119. KKQD_PARAM_NOW_CNT = 0;
  120. }
  121. if(KKQD_bXiaQie)
  122. {
  123. KKQD_bXiaQie = 0;
  124. if((KKQD_XiaQieStep == 0) && !KKQD_TL_VAVLE)
  125. {
  126. KKQD_XiaQieStep = 1;
  127. }
  128. }
  129. if(KKQD_bQianDianDW)
  130. {
  131. KKQD_bQianDianDW = 0;
  132. if(KKQD_MotorStep == 0)
  133. {
  134. KKQD_MotorStep = 61;
  135. KK_cZipCnt = 0;
  136. KK_Motor_SZ(KKQD_MOTOR_EN); //电机锁轴
  137. KKQD_MotorDelay = dwTickCount + 150;
  138. }
  139. }
  140. if(KKQD_bTL)
  141. {
  142. KKQD_bTL = 0;
  143. if(KKQD_TL_VAVLE)
  144. {
  145. KKQD_TL_VAVLE = 0;
  146. }
  147. else if(!KKQD_GZ_VAVLE && !KKQD_SM_VAVLE)
  148. {
  149. KKQD_TL_VAVLE = ~KKQD_TL_VAVLE;
  150. }
  151. }
  152. if(KKQD_bYD)
  153. {
  154. KKQD_bYD = 0;
  155. KKQD_YD_VAVLE = ~KKQD_YD_VAVLE;
  156. }
  157. if(KKQD_bGZ)
  158. {
  159. KKQD_bGZ = 0;
  160. KKQD_GZ_VAVLE = ~KKQD_GZ_VAVLE;
  161. }
  162. if(KKQD_bJD)
  163. {
  164. KKQD_bJD = 0;
  165. KKQD_JD_VAVLE = ~KKQD_JD_VAVLE;
  166. }
  167. if(KKQD_bXM)
  168. {
  169. KKQD_bXM = 0;
  170. if(KKQD_XM_KAIKOU_VAVLE)
  171. {
  172. KKQD_XM_KAIKOU_VAVLE = 0;
  173. }
  174. else
  175. {
  176. KKQD_XM_KAIKOU_VAVLE = 1;
  177. }
  178. }
  179. if(KKQD_bSM)
  180. {
  181. KKQD_bSM = 0;
  182. if(KKQD_SM_VAVLE)
  183. KKQD_SM_VAVLE = 0;
  184. else if(!KKQD_TL_VAVLE)
  185. KKQD_SM_VAVLE = 1;
  186. }
  187. //推方块
  188. if(KKQD_bTFK)
  189. {
  190. KKQD_bTFK = 0;
  191. KKQD_TFK_VAVLE = ~KKQD_TFK_VAVLE;
  192. }
  193. //台面电机
  194. if(KKQD_bTB)
  195. {
  196. KKQD_bTB = 0;
  197. KKQD_TABLE_VAVLE = ~KKQD_TABLE_VAVLE;
  198. }
  199. // if(KKQD_bYBD)
  200. // / {
  201. // KKQD_bYBD = 0;
  202. // KKQD_YBD_VAVLE = ~KKQD_YBD_VAVLE;
  203. // }
  204. if(KKQD_bTestCS)
  205. {
  206. KKQD_bTestCS = 0;
  207. KKQD_CS_OUT = 1;
  208. KKQD_CSDelay = dwTickCount + KKQD_PARAM_CS_TIME;
  209. }
  210. if(KKQD_bBL)//合链
  211. {
  212. KKQD_bBL = 0;
  213. KKQD_BL_VAVLE = ~KKQD_BL_VAVLE;
  214. }
  215. if(KKQD_bHL) //护链,双开用
  216. {
  217. KKQD_bHL = 0;
  218. // KKQD_HL_VAVLE = ~KKQD_HL_VAVLE;
  219. }
  220. if(KKQD_bYX)
  221. {
  222. KKQD_bYX = 0;
  223. // KKQD_YX_VAVLE = ~KKQD_YX_VAVLE;
  224. }
  225. if(KKQD_XiaQieStep == 0)
  226. {
  227. if(dwTickCount >= KKQD_CSDelay) KKQD_CS_OUT = 0;
  228. }
  229. //电机控制
  230. if(KKQD_bGoMotor && !KKQD_QIAN_LIMIT_IN)
  231. {
  232. KK_Motor_SZ(KKQD_MOTOR_EN); //电机锁轴
  233. KKQD_STOPINDelay = dwTickCount;
  234. if(!X_DRV)
  235. {
  236. // X轴 运行速度 启动速度 加速度 减速度
  237. AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED,KKQD_PARAM_GO_LOW_SPEED,10,12);
  238. }
  239. }
  240. if(KKQD_bBackMotor) //后退限位已经取消
  241. {
  242. KK_Motor_SZ(KKQD_MOTOR_EN); //电机锁轴
  243. KKQD_STOPINDelay = dwTickCount;
  244. if(!X_DRV)
  245. // X轴 运行速度 启动速度 加速度 减速度
  246. AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_P,KKQD_PARAM_GO_LOW_SPEED,KKQD_PARAM_GO_LOW_SPEED,10,12);
  247. }
  248. if(!KKQD_bGoMotor && !KKQD_bBackMotor && (KKQD_MotorStep == 0) && (dwTickCount >= KKQD_STOPINDelay))
  249. {
  250. if(X_DRV) AxisEgmStop(X_AXIS);
  251. }
  252. if(KKQD_QIAN_LIMIT_IN && (KKQD_MotorStep == 0) && !KKQD_bBackMotor &&(KKQD_AutoStep == 0))
  253. {
  254. if(X_DRV)AxisEgmStop(X_AXIS);
  255. }
  256. }
  257. }
  258. void KK_QueDuan_AlarmProtect(void)
  259. {
  260. dwXRealPos = GetPos(X_AXIS);
  261. if(!bRunning)
  262. {
  263. ;
  264. }
  265. else
  266. {
  267. if(KKQD_PARAM_RUN_LENGTH < 5000)
  268. KKQD_PARAM_RUN_LENGTH= 5000;
  269. if((dwXRealPos > KKQD_PARAM_RUN_LENGTH) && (KK_cGoLimitEn != 0)) //第一条手动时不保护
  270. {
  271. //AxisEgmStop(X_AXIS);
  272. KK_cGoLimitEn = 0;
  273. bStop = 1;
  274. KKQD_StopStep = 1;
  275. KKQD_JD_VAVLE = 0;
  276. KKQD_SetAlarmCode(KKQD_BACK_ALARM);
  277. }
  278. }
  279. }
  280. void KK_QueDuan_AutoAction(void)
  281. {
  282. if(bRunning)
  283. {//台面电机定时关掉
  284. if(dwTickCount >= KKQD_TBDelay)
  285. KKQD_TABLE_VAVLE = 0;
  286. switch(KKQD_AutoStep)
  287. {
  288. case 1:
  289. if(dwTickCount >= KKQD_AutoDelay)
  290. {
  291. KKQD_AutoStep = 2;
  292. if(KKQD_MotorStep == 0)
  293. {
  294. KKQD_MotorStep = 61; //前点定位
  295. }
  296. KK_cGoLimitEn = 0;
  297. }
  298. break;
  299. case 2:
  300. if(KKQD_MotorStep == 0)
  301. {
  302. KKQD_MotorStep = 30;
  303. KKQD_AutoStep = 3;
  304. KK_cGoLimitEn = 1;
  305. }
  306. break;
  307. case 3: //后面两步为延时反转步
  308. if((KKQD_MotorStep == 0) || (KKQD_MotorStep == 390) || (KKQD_MotorStep == 391))
  309. {
  310. if(KKQD_SAFE_IN)
  311. {
  312. bStop = 1;
  313. }
  314. else
  315. {
  316. if(KKQD_XiaQieStep == 0)
  317. KKQD_XiaQieStep = 1;
  318. KKQD_AutoStep = 4;
  319. }
  320. }
  321. break;
  322. case 4:
  323. // if((KKQD_MACHINE_TYPE == KKQD_NO_GL_TUIFANGKUAI) || (KKQD_MACHINE_TYPE == KKQD_CS_TUIFANGKUAI))
  324. // {
  325. // 闭口
  326. if((KKQD_XiaQieStep == 0) || ((KKQD_XiaQieStep == 6) && (KKQD_PARAM_KAIBEE_SELECT == 1))|| ((KKQD_XiaQieStep == 13) && (KKQD_PARAM_KAIBEE_SELECT == 0)))// && !KKQD_SHANG_MU_LIMIT_IN)
  327. {
  328. if(KKQD_MotorStep == 0)
  329. {
  330. KKQD_MotorStep = 40; //切完后退
  331. }
  332. KKQD_AutoStep = 5;
  333. }
  334. /*
  335. // }
  336. // else
  337. // {
  338. if(((KKQD_XiaQieStep == 0) || (KKQD_XiaQieStep == 13)) && !KKQD_SHANG_MU_LIMIT_IN && !KKQD_XIA_MU_LIMIT_IN)
  339. {
  340. if(KKQD_MotorStep == 0)
  341. {
  342. KKQD_MotorStep = 40; //切完后退
  343. KKQD_AutoStep = 5;
  344. }
  345. }
  346. }
  347. */
  348. break;
  349. case 5:
  350. if(KKQD_MotorStep == 0)
  351. {
  352. KK_cZipCnt++;
  353. KKQD_PARAM_NOW_CNT++;
  354. KK_cTableCnt++;
  355. AddToTal(KKQD_TOTAL_ADDR);
  356. AddToTal(CT_WORKTOTAL_ADDR);
  357. CalProSP(KKQD_PROSPEED_ADDR);
  358. if(KK_cTableCnt >= KKQD_PARAM_TABLE_NUM)
  359. {
  360. KK_cTableCnt = 0;
  361. KKQD_TABLE_VAVLE = 1;
  362. KKQD_TBDelay = dwTickCount + KKQD_PARAM_TB_TIME;
  363. }
  364. if(/*(GetTotal(KKQD_TOTAL_ADDR) >= KKQD_PARAM_SET_TOTAL) ||*/KK_QDSingOneFlg)
  365. {
  366. bRunning = 0;
  367. KKQD_AutoStep = 0;
  368. KK_QDSingOneFlg = 0;
  369. KKQD_TABLE_VAVLE = 0;
  370. // if(GetTotal(KKQD_TOTAL_ADDR) >= KKQD_PARAM_SET_TOTAL) KKQD_SetAlarmCode(KKQD_TOTAL_ALARM);
  371. }
  372. else
  373. {
  374. KKQD_AutoStep = 1;
  375. if((KKQD_PARAM_NOW_CNT >= KKQD_PARAM_ZHA_SHU) && (KKQD_PARAM_ZHA_SHU > 0))
  376. {
  377. KKQD_AutoDelay = dwTickCount + KKQD_PARAM_ZS_STOP_TIME;
  378. KKQD_PARAM_NOW_CNT = 0;
  379. if(KKQD_PARAM_ZS_STOP_TIME == 0)
  380. {
  381. bRunning = 0;
  382. KKQD_AutoStep = 0;
  383. KK_QDSingOneFlg = 0;
  384. KKQD_SetAlarmCode(KKQD_TOTAL_ALARM);
  385. KKQD_TABLE_VAVLE = 0;
  386. }
  387. }
  388. else
  389. KKQD_AutoDelay = dwTickCount + KKQD_PARAM_CYCLE_DELAY;
  390. }
  391. }
  392. break;
  393. }
  394. }
  395. }
  396. void KK_QueDuan_StepCheckStart(void)
  397. {
  398. // 启动
  399. if((KKQD_START_IN_UP) || bStart || KKQD_bSingle)
  400. {
  401. bStart = 0;
  402. if(!bRunning && (KKQD_AutoStep == 0))
  403. {
  404. if((KKQD_XIA_MU_LIMIT_IN|| KKQD_KAIKUO_XIAMO_LIMIT_IN) && !KKQD_PARAM_XM_ENABLE)KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
  405. // else if(GetAlarmCode(KKQD_ALARM_ADDR) != 0);
  406. //else if(GetTotal(KKQD_TOTAL_ADDR) >= KKQD_PARAM_SET_TOTAL) KKQD_SetAlarmCode(KKQD_TOTAL_ALARM);
  407. // else if(KKQD_BL_VAVLE)KKQD_SetAlarmCode(KKQD_BL_ALARM);
  408. else if(KKQD_SM_VAVLE)KKQD_SetAlarmCode(KKQD_SM_ALARM);
  409. else
  410. {
  411. bRunning = 1;
  412. KKQD_AutoStep = 1;
  413. if(KKQD_bSingle)
  414. KK_QDSingOneFlg= 0;
  415. KK_cZipCnt = 0;
  416. KK_cTuiFangKuaiCnt = 0;
  417. KKQD_BL_VAVLE = 0; //并链关
  418. KKQD_DGLG_VAVLE = 0; //顶过链杆关
  419. SetAlarmCode(KKQD_ALARM_ADDR,0);
  420. KK_Motor_SZ(KKQD_MOTOR_EN); //电机锁轴
  421. KKQD_AutoDelay = dwTickCount + 150;
  422. }
  423. }
  424. KKQD_bSingle = 0;
  425. }
  426. //停止
  427. if((KKQD_STOP_IN_UP && (dwTickCount >= KKQD_STOPINDelay)) || bStop)
  428. {
  429. bStop = 0;
  430. KKQD_STOPINDelay = dwTickCount + 100;
  431. if(bRunning)
  432. {
  433. KKQD_AutoDelay = dwTickCount;
  434. KKQD_MotorDelay = dwTickCount;
  435. KKQD_XiaQieDelay = dwTickCount;
  436. KKQD_KaDaiDelay = dwTickCount;
  437. KKQD_CSDelay = dwTickCount;
  438. KKQD_TBDelay = dwTickCount;
  439. KKQD_TFKDelay = dwTickCount;
  440. KKQD_TLDelay = dwTickCount;
  441. KK_QDSingOneFlg = 0;
  442. KKQD_JD_VAVLE = 0;
  443. KKQD_SM_VAVLE = 0;
  444. KKQD_YD_VAVLE = 0;
  445. KKQD_TFK_VAVLE= 0;
  446. KKQD_TL_VAVLE = 0;
  447. // KKQD_HL_VAVLE = 0;
  448. KKQD_CS_OUT = 0;
  449. KKQD_XiaQieStep = 0;
  450. KKQD_MotorStep = 0;
  451. KKQD_TuiLianStep = 0;
  452. KKQD_GZ_VAVLE = 0;
  453. KKQD_TABLE_VAVLE = 0;
  454. KKQD_DGLG_VAVLE = 0; //顶过链杆关
  455. if((KKQD_StopStep == 0) && X_DRV)
  456. KKQD_StopStep = 1;
  457. // AxisDecStop(X_AXIS);
  458. KKQD_BinLianStep = 0;
  459. KKQD_BL_VAVLE = 0;
  460. user_datas[121] = 0;
  461. user_datas[122] = 0;
  462. SetAlarmCode(KKQD_ALARM_ADDR,0);
  463. }
  464. else
  465. {
  466. KKQD_AutoDelay = dwTickCount;
  467. KKQD_MotorDelay = dwTickCount;
  468. KKQD_XiaQieDelay = dwTickCount;
  469. KKQD_KaDaiDelay = dwTickCount;
  470. KKQD_CSDelay = dwTickCount;
  471. KKQD_TBDelay = dwTickCount;
  472. KKQD_TFKDelay = dwTickCount;
  473. KKQD_TLDelay = dwTickCount;
  474. dwTickCount = KKQD_TBDelay;
  475. KK_QDSingOneFlg = 0;
  476. KKQD_JD_VAVLE = 0;
  477. KKQD_SM_VAVLE = 0;
  478. KKQD_XM_KAIKOU_VAVLE = 0;
  479. KKQD_YD_VAVLE = 0;
  480. KKQD_TFK_VAVLE= 0;
  481. // KKQD_YX_VAVLE = 0;
  482. // KKQD_HL_VAVLE = 0;
  483. KKQD_TL_VAVLE = 0;
  484. KKQD_DGLG_VAVLE = 0; //顶过链杆关
  485. KKQD_GZ_VAVLE = 0;
  486. KKQD_CS_OUT = 0;
  487. KKQD_XiaQieStep = 0;
  488. KKQD_MotorStep = 0;
  489. KKQD_TuiLianStep = 0;
  490. KKQD_TABLE_VAVLE = 0;
  491. // KK_Motor_SZ(KKQD_MOTOR_DIS); //电机松轴
  492. if((KKQD_StopStep == 0))
  493. {
  494. AxisEgmStop(X_AXIS);
  495. KK_Motor_SZ(KKQD_MOTOR_DIS); //电机松轴
  496. }
  497. KKQD_BinLianStep = 0;
  498. KKQD_BL_VAVLE = 0;
  499. SetAlarmCode(KKQD_ALARM_ADDR,0);
  500. }
  501. bRunning = 0;
  502. KKQD_XiaQieStep = 0;
  503. KKQD_AutoStep = 0;
  504. KKQD_MotorStep = 0;
  505. KKQD_TuiLianStep = 0;
  506. }
  507. if(bAlarmStop)
  508. {
  509. bAlarmStop = 0;
  510. KKQD_XiaQieStep = 0;
  511. KKQD_AutoStep = 0;
  512. KKQD_MotorStep = 0;
  513. KKQD_TuiLianStep = 0;
  514. KKQD_XiaQieStep = 0;
  515. KKQD_MotorStep = 0;
  516. KKQD_TuiLianStep = 0;
  517. KKQD_AutoDelay = dwTickCount;
  518. KKQD_MotorDelay = dwTickCount;
  519. KKQD_XiaQieDelay = dwTickCount;
  520. KKQD_KaDaiDelay = dwTickCount;
  521. KKQD_CSDelay = dwTickCount;
  522. KKQD_TBDelay = dwTickCount;
  523. KKQD_TFKDelay = dwTickCount;
  524. KKQD_TLDelay = dwTickCount;
  525. KK_QDSingOneFlg = 0;
  526. bRunning = 0;
  527. if(X_DRV)
  528. KKQD_StopStep=1;
  529. // AxisEgmStop(X_AXIS);
  530. dwTickCount = KKQD_TBDelay;
  531. KKQD_TABLE_VAVLE = 0;
  532. KKQD_JD_VAVLE=0;
  533. KKQD_GZ_VAVLE=0;
  534. }
  535. }
  536. //记忆长度模式误差检测
  537. void KK_QueDuan_CheckLength(long zip_length)
  538. {
  539. static long start_dist;
  540. switch(KKQD_CheckLengthStep)
  541. {
  542. case 0:break;
  543. case 1:
  544. start_dist = dwXRealPos;
  545. KK_dwSaveLength = 0;
  546. KKQD_CheckLengthStep = 2;
  547. break;
  548. case 2:
  549. if(KKQD_GUO_LIAN_IN_DW){
  550. KK_dwSaveLength = dwXRealPos - start_dist;
  551. }
  552. break;
  553. }
  554. }
  555. #if 1//!KKQD_KB_MODE //开口
  556. //开口切专用
  557. //30步开始后拉开始,分解4种工作模式
  558. //40步开始用切断后拉动作
  559. //60步开始为前方向,开闭口一样
  560. void KK_QueDuan_Motor_KK(void)
  561. {
  562. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_length_buff,jz_buff;
  563. unsigned short ch;
  564. user_datas[121]= KKQD_MotorStep;
  565. user_datas[122]= length_buff;
  566. user_datas[123] = dwXRealPos;
  567. user_datas[124] = KK_QDSingOneFlg;
  568. user_datas[125] = KKQD_AutoStep;
  569. user_datas[126] = KKQD_XiaQieStep;
  570. // user_datas[127] = KKQD_XiaQieStep;
  571. KK_QueDuan_CheckLength(length_buff);
  572. switch(KKQD_MotorStep)
  573. {
  574. case 30:
  575. switch(KKQD_PARAM_BACK_MODE) //开口分四种模式
  576. {
  577. case 0: //单数控模式
  578. KKQD_MotorStep = 310; //每种模式留20步
  579. KKQD_DGLG_VAVLE = 1; //顶过链杆关
  580. break;
  581. case 1://单感应模式
  582. KKQD_MotorStep = 330; //每种模式留20步
  583. break;
  584. case 2: //先感应后数控模式+检测
  585. KKQD_MotorStep = 350; //每种模式留20步
  586. break;
  587. default: //数控模式+过链检测长度
  588. KKQD_MotorStep = 370; //每种模式留20步
  589. break;
  590. }
  591. KKQD_MotorDelay = dwTickCount + KKQD_PARAM_DELAY_BACK;
  592. SetPos(X_AXIS, 0);
  593. dwXRealPos = 0;
  594. back_buff = 0;
  595. gou_zhen_buff = 0;
  596. save_buff = 0;
  597. break;
  598. //310步到315步为数控模式
  599. case 310:
  600. KKQD_MotorStep = 311;
  601. // KKQD_JZ_DIR = KKQD_YDIR_P;
  602. if(KKQD_PARAM_BL_ENABLE)
  603. KKQD_BinLianStep = 1; //并链起动
  604. break;
  605. case 311:
  606. if(dwTickCount >= KKQD_MotorDelay)
  607. {
  608. KK_length_buffer = &KKQD_PARAM_OFFSET_LENGTH;
  609. //李永庆代码
  610. //两段速度移动距离 拉链长度+慢速长度停止
  611. // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
  612. KK_DCC_TIME_BL = KKQD_PARAM_DCC + KKQD_PARAM_BACK_SPEED/500;
  613. AxisMovePosAccDec(X_AXIS,KKQD_PARAM_BACK_SPEED,KKQD_PARAM_ZIPPER_LENGTH + (*KK_length_buffer), KKQD_PARAM_START_SPEED,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_ACC,KK_DCC_TIME_BL,KKQD_PARAM_BACK_LOW_SPEED_LENGTH);
  614. KKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  615. KKQD_MotorStep = 312;
  616. }
  617. break;
  618. case 312:
  619. if(dwXRealPos >= 10)
  620. KKQD_TL_VAVLE = 0;
  621. //勾针提前输出 ,争取时间推方块
  622. if (!KKQD_GZ_VAVLE && (dwXRealPos >= (KKQD_PARAM_ZIPPER_LENGTH- 230)))
  623. {
  624. KKQD_GZ_VAVLE = 1;
  625. KKQD_XM_KAIKOU_VAVLE=1;
  626. }
  627. //电机停止
  628. if(!X_DRV)
  629. {
  630. KKQD_MotorDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
  631. KKQD_MotorStep = 314;
  632. KKQD_BL_VAVLE = 0; //停止时并链一定要打开
  633. if((KKQD_PARAM_BACK_MODE == 2) && !KKQD_DGLG_VAVLE) //模式2,先检测长度后数控
  634. {//对比长度 ,发须要有过链信号,模式2,3. 模式0,1不用在这里对比长度
  635. if(KK_cZipCnt > 1) //长度检测
  636. {
  637. if(KKQD_PARAM_ERROR_LENGTH != 0) //长度误差值不能为0
  638. {
  639. if(((KK_dwSaveLength + KKQD_PARAM_MOTOR_DELAY_LENGTH) > (length_buff + KKQD_PARAM_ERROR_LENGTH)) || (KK_dwSaveLength == 0))
  640. {
  641. KKQD_SetAlarmCode(KKQD_LENGTH_LONG_ALARM);//拉链变长,对比警告
  642. }
  643. else if((KK_dwSaveLength + KKQD_PARAM_MOTOR_DELAY_LENGTH+ KKQD_PARAM_ERROR_LENGTH) < length_buff)
  644. {
  645. KKQD_SetAlarmCode(KKQD_LENGTH_SHORT_ALARM); ////拉链变短
  646. }
  647. KKQD_CheckLengthStep = 0;
  648. }
  649. }
  650. }
  651. }
  652. break;
  653. case 314:
  654. if(!X_DRV && (dwTickCount >= KKQD_MotorDelay)) //数控到停止
  655. {
  656. KKQD_MotorStep = 0;
  657. KKQD_TFK_VAVLE = 1; //推方块输出
  658. }
  659. break;
  660. //330步到349步单感应模式
  661. case 330:
  662. KKQD_MotorStep = 331;
  663. break;
  664. case 331:
  665. if(dwTickCount >= KKQD_MotorDelay)
  666. {
  667. KKQD_MotorStep = 332;
  668. if(KK_cZipCnt < 2)
  669. {
  670. if(KKQD_PARAM_BL_ENABLE)
  671. KKQD_BinLianStep = 10; //并链起动
  672. //第一条都是过链感应,后拉速度减半//原来KKQD_PARAM_CHECK_BACK_HSPEED/2
  673. // X轴 运行速度 启动速度 加速度 减速度
  674. AxisContinueMoveAcc(X_AXIS,8000,KKQD_DIR_P,KKQD_PARAM_START_SPEED,KKQD_PARAM_START_SPEED,8,13);
  675. // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
  676. // AxisMoveTwoPos(X_AXIS,KKQD_PARAM_BACK_SPEED,KKQD_PARAM_ZIPPER_LENGTH + (*KK_length_buffer)-KKQD_PARAM_BACK_LOW_SPEED_LENGTH,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED_LENGTH,KKQD_DIR_P);
  677. }
  678. else
  679. {
  680. KK_QD_DCC_TIME_BL = KKQD_PARAM_DCC+ KKQD_PARAM_CHECK_BACK_HSPEED/500;
  681. if(KKQD_PARAM_BL_ENABLE)
  682. KKQD_BinLianStep = 1; //并链起动
  683. //因为每条都是过链感应,所以直接运行检测模式后拉速度
  684. // X轴 运行速度 启动速度 停止速度 加速度 减速度
  685. //AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_CHECK_BACK_HSPEED,KKQD_DIR_P,KKQD_PARAM_START_SPEED,KKQD_PARAM_START_SPEED,KKQD_PARAM_ACC,KKQD_PARAM_DCC);
  686. AxisMovePosAccDecNotStop(X_AXIS,KKQD_PARAM_CHECK_BACK_HSPEED,KKQD_PARAM_ZIPPER_LENGTH , KKQD_PARAM_START_SPEED,KKQD_PARAM_START_SPEED*9/5,KKQD_PARAM_ACC,KK_QD_DCC_TIME_BL,KKQD_PARAM_BACK_LOW_SPEED_LENGTH + 500);
  687. }
  688. }
  689. break;
  690. case 332:
  691. if(dwXRealPos >= 10)
  692. KKQD_TL_VAVLE = 0;
  693. if(KK_cZipCnt > 1) //第二条开始数控降速
  694. {
  695. if(KKQD_GUO_LIAN_IN_DW) //重新到链上
  696. {
  697. AxisChangeSpeed(X_AXIS,KKQD_PARAM_BACK_LOW_SPEED);
  698. gou_zhen_buff = dwXRealPos;
  699. KKQD_MotorStep = 335; //到检测定位
  700. }
  701. //
  702. // if((dwXRealPos >= (KKQD_PARAM_BACK_LOW_SPEED_LENGTH + 60)) && KKQD_GUO_LIAN_IN)
  703. // {
  704. // }
  705. }
  706. else //第一条工作
  707. {
  708. if(KKQD_GUO_LIAN_IN_UP)
  709. {
  710. checkdelay_buff = dwXRealPos;
  711. AxisContinueMoveChangeSpeed(X_AXIS,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED/2,25,15);
  712. KKQD_MotorDelay = dwTickCount + 0;//KKQD_PARAM_DELAY_XM;
  713. KKQD_MotorStep = 333;
  714. }
  715. // else if((dwXRealPos >= KKQD_PARAM_RUN_LENGTH) && (KKQD_PARAM_RUN_LENGTH >= 5000)) //模组最长限制
  716. // {
  717. // KKQD_SetAlarmCode(KKQD_PARAM_RUN_LENGTH_ALARM); //超出轨道运行长度
  718. // }
  719. }
  720. break;
  721. case 333:
  722. if(dwTickCount >= KKQD_MotorDelay)
  723. {
  724. KKQD_MotorStep = 334;
  725. }
  726. break;
  727. case 334:
  728. if(KKQD_GUO_LIAN_IN_DW) //下降沿,定位长度
  729. {
  730. //滤波有待调试
  731. // if((((dwXRealPos - checkdelay_buff) >= KKQD_PARAM_DELAY_CHECK) && (KKQD_PARAM_LT_ENABLE)) || (((dwXRealPos - checkdelay_buff) >= KKQD_PARAM_NO_LT_DELAY_CHECK) && (KKQD_PARAM_LT_ENABLE == 0)))
  732. // {
  733. if(KKQD_GUO_LIAN_IN_DW)
  734. {
  735. gou_zhen_buff = dwXRealPos;
  736. KKQD_MotorStep = 335;
  737. }
  738. // }
  739. }
  740. break;
  741. case 335:
  742. if(KKQD_GUO_LIAN_IN_DW)
  743. {
  744. gou_zhen_buff = dwXRealPos;
  745. }
  746. //在空们都把延时清零
  747. if(KKQD_GUO_LIAN_IN)
  748. {
  749. gou_zhen_buff = dwXRealPos;
  750. }
  751. if(((dwXRealPos - gou_zhen_buff) >= KKQD_PARAM_MOTOR_DELAY_LENGTH/2) && !KKQD_GUO_LIAN_IN)
  752. {
  753. KKQD_GZ_VAVLE = 1;
  754. KKQD_XM_KAIKOU_VAVLE=1;
  755. }
  756. //定位停止
  757. if(((dwXRealPos - gou_zhen_buff) >= KKQD_PARAM_MOTOR_DELAY_LENGTH) && !KKQD_GUO_LIAN_IN)
  758. {
  759. AxisEgmStop(X_AXIS);
  760. KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  761. KKQD_MotorStep = 336;
  762. KKQD_GZ_VAVLE = 1;
  763. }
  764. break;
  765. case 336:
  766. if(!X_DRV)
  767. {
  768. KKQD_GZ_VAVLE = 1;
  769. KKQD_XM_KAIKOU_VAVLE=1;
  770. KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  771. //KKQD_XM_VAVLE = 1;
  772. KKQD_MotorStep = 337;
  773. }
  774. break;
  775. case 337:
  776. if(1)
  777. {
  778. KKQD_MotorStep = 338;
  779. KKQD_MotorDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
  780. }
  781. // else if(dwTickCount >= KKQD_MotorDelay) KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
  782. break;
  783. case 338:
  784. if((dwTickCount >= KKQD_MotorDelay))
  785. {
  786. KKQD_TFK_VAVLE = 1; //推方块输出
  787. KKQD_MotorStep = 339;
  788. KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  789. }
  790. break;
  791. case 339:
  792. if(KK_cZipCnt == 1)
  793. {
  794. length_buff = dwXRealPos - save_buff;
  795. SetData32bits(KKQD_PARAM_ZIPPER_LENGTH_ADDR,length_buff);
  796. }
  797. else if(KK_cZipCnt > 1) //长度检测
  798. {
  799. if(KKQD_PARAM_ERROR_LENGTH != 0) //长度误差值不能为0
  800. {
  801. if(dwXRealPos >= length_buff) //拉链变长,对比警告
  802. {
  803. if((dwXRealPos - save_buff) > (length_buff+KKQD_PARAM_ERROR_LENGTH))
  804. KKQD_SetAlarmCode(KKQD_LENGTH_LONG_ALARM);
  805. }
  806. else //拉链变短
  807. {
  808. if((dwXRealPos - save_buff + KKQD_PARAM_ERROR_LENGTH) < (length_buff))
  809. KKQD_SetAlarmCode(KKQD_LENGTH_SHORT_ALARM);
  810. }
  811. }
  812. }
  813. KKQD_MotorStep = 0;
  814. break;
  815. //350步到369步单感应模式
  816. case 350:
  817. back_buff = dwXRealPos;
  818. gou_zhen_buff = dwXRealPos;
  819. KKQD_MotorStep = 351;
  820. // KKQD_JZ_DIR = KKQD_YDIR_P;
  821. break;
  822. case 351:
  823. if(dwTickCount >= KKQD_MotorDelay)
  824. {
  825. KKQD_MotorStep = 352;
  826. //第一,二条都是过链感应,测量长度
  827. if(KK_cZipCnt < 2)
  828. {
  829. if(KKQD_PARAM_BL_ENABLE) //因为长度未知,只能通过过链退合链
  830. KKQD_BinLianStep = 10; //并链起动
  831. KKQD_DGLG_VAVLE = 0; //顶过链杆关
  832. // X轴 运行速度 启动速度 加速度 减速度
  833. AxisContinueMoveAcc(X_AXIS,9000,KKQD_DIR_P,KKQD_PARAM_START_SPEED,KKQD_PARAM_START_SPEED,8,12);
  834. }
  835. else
  836. {
  837. if(KKQD_PARAM_BL_ENABLE)
  838. KKQD_BinLianStep = 1; //并链起动
  839. KKQD_DGLG_VAVLE = 1; //顶过链杆关
  840. KKQD_CheckLengthStep = 1; //长度检测,第3条才有对比
  841. //走数控方式,因第二条中已经测量出来拉链长度,可以直接按长度数控方式走
  842. KKQD_MotorStep = 311;
  843. }
  844. }
  845. break;
  846. case 352:
  847. if(dwXRealPos >= 10)
  848. KKQD_TL_VAVLE = 0;
  849. //前两条都按最低速度工作
  850. if(KKQD_GUO_LIAN_IN_UP)
  851. {
  852. checkdelay_buff = dwXRealPos;
  853. AxisContinueMoveChangeSpeed(X_AXIS,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED/2,25,15);
  854. KKQD_MotorDelay = dwTickCount + 2;//因慢速,加8MS滤波
  855. KKQD_MotorStep = 353;
  856. }
  857. else if((dwXRealPos >= KKQD_PARAM_RUN_LENGTH) && (KKQD_PARAM_RUN_LENGTH >= 5000)) //模组最长限制
  858. {
  859. // KKQD_SetAlarmCode(KKQD_PARAM_RUN_LENGTH_ALARM); //超出轨道运行长度
  860. }
  861. break;
  862. case 353:
  863. if(dwTickCount >= KKQD_MotorDelay)
  864. {
  865. KKQD_MotorStep = 354;
  866. }
  867. break;
  868. case 354:
  869. if(KKQD_GUO_LIAN_IN_DW) //下降沿,定位长度
  870. {
  871. //滤波有待调试
  872. // if((((dwXRealPos - checkdelay_buff) >= KKQD_PARAM_DELAY_CHECK) && (KKQD_PARAM_LT_ENABLE)) || (((dwXRealPos - checkdelay_buff) >= KKQD_PARAM_NO_LT_DELAY_CHECK) && (KKQD_PARAM_LT_ENABLE == 0)))
  873. // {
  874. if(KKQD_GUO_LIAN_IN_DW)
  875. {
  876. gou_zhen_buff = dwXRealPos;
  877. KKQD_MotorStep = 355;
  878. }
  879. // }
  880. }
  881. break;
  882. case 355:
  883. if(KKQD_GUO_LIAN_IN_DW)
  884. {
  885. gou_zhen_buff = dwXRealPos;
  886. }
  887. //在空们都把延时清零
  888. if(KKQD_GUO_LIAN_IN)
  889. {
  890. gou_zhen_buff = dwXRealPos;
  891. }
  892. if(((dwXRealPos - gou_zhen_buff) >= KKQD_PARAM_MOTOR_DELAY_LENGTH/2) && !KKQD_GUO_LIAN_IN)
  893. {
  894. KKQD_GZ_VAVLE = 1;
  895. KKQD_XM_KAIKOU_VAVLE=1;
  896. }
  897. //定位停止
  898. if(((dwXRealPos - gou_zhen_buff) >= KKQD_PARAM_MOTOR_DELAY_LENGTH) && !KKQD_GUO_LIAN_IN)
  899. {
  900. AxisEgmStop(X_AXIS);
  901. KKQD_MotorStep = 356;
  902. }
  903. break;
  904. case 356:
  905. if(!X_DRV)
  906. {
  907. KKQD_GZ_VAVLE = 1;
  908. KKQD_XM_KAIKOU_VAVLE=1;
  909. KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  910. // KKQD_XM_VAVLE = 1;
  911. KKQD_MotorStep = 357;
  912. }
  913. break;
  914. case 357:
  915. if(1)
  916. {
  917. KKQD_MotorStep = 358;
  918. KKQD_MotorDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
  919. }
  920. break;
  921. case 358:
  922. if((dwTickCount >= KKQD_MotorDelay))
  923. {
  924. KKQD_TFK_VAVLE = 1; //推方块输出
  925. KKQD_MotorStep = 359;
  926. KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  927. }
  928. break;
  929. case 359:
  930. if(KK_cZipCnt == 1)
  931. {
  932. length_buff = dwXRealPos - save_buff;
  933. //测量出来长度
  934. SetData32bits(KKQD_PARAM_ZIPPER_LENGTH_ADDR,length_buff);
  935. }
  936. KKQD_MotorStep = 0;
  937. break;
  938. case 40:
  939. if(KKQD_PARAM_SJZ_LENGTH == 0)
  940. {
  941. KKQD_MotorDelay = dwTickCount + KKQD_PARAM_CUT_BACK_DELAY;
  942. KKQD_JD_VAVLE = 0;
  943. }
  944. else
  945. KKQD_MotorDelay = dwTickCount + 3;
  946. KKQD_MotorStep = 41;
  947. jz_buff = dwXRealPos;
  948. break;
  949. case 41:
  950. if((dwTickCount >= KKQD_MotorDelay))
  951. {
  952. //夹子已经张开
  953. AxisMovePosAccDec(X_AXIS,KKQD_PARAM_CUT_BACK_SPEED,(KKQD_PARAM_SJZ_LENGTH+KKQD_PARAM_BACK_LENGTH),1000,1000,10,10,0);
  954. KKQD_MotorStep = 42;
  955. }
  956. break;
  957. case 42:
  958. if( (dwXRealPos - jz_buff) >= KKQD_PARAM_SJZ_LENGTH)
  959. {
  960. KKQD_JD_VAVLE = 0;
  961. }
  962. if(!X_DRV)
  963. {
  964. KKQD_JD_VAVLE = 0;
  965. KKQD_MotorStep = 43;
  966. }
  967. break;
  968. case 43: // 切断完成后拉电机动作
  969. if(!X_DRV)
  970. {
  971. KKQD_MotorStep = 0;
  972. KKQD_MotorDelay = dwTickCount;
  973. }
  974. break;
  975. case 61: // 前点定位数控模式
  976. KKQD_BL_VAVLE = 0;//并链也要打开
  977. if(dwTickCount >= KKQD_MotorDelay)
  978. {
  979. // KKQD_JZ_DIR = KKQD_YDIR_N;
  980. if(!KKQD_TL_VAVLE && KK_cZipCnt && (KKQD_TuiLianStep == 0)) //没送链情况下主动送链
  981. {
  982. if(!KKQD_SHANG_MU_LIMIT_IN)
  983. {
  984. KKQD_TuiLianStep = 1;
  985. }
  986. }
  987. KKQD_MotorStep = 62;
  988. }
  989. break;
  990. case 62:
  991. if(dwTickCount >= KKQD_MotorDelay)
  992. {
  993. if(KKQD_QIAN_LIMIT_IN)
  994. {
  995. //前点亮的情况下先后退离开信号后再前进定位 ,10公分
  996. AxisMovePosAccDec(X_AXIS,3000,1000,2000,2000,10,10,30);
  997. KKQD_MotorDelay = dwTickCount + 300;
  998. }
  999. KKQD_MotorStep = 63;
  1000. KKQD_JD_VAVLE = 0;
  1001. }
  1002. break;
  1003. case 63:
  1004. if(!X_DRV && !KKQD_QIAN_LIMIT_IN && (dwTickCount >= KKQD_MotorDelay))// && !KKQD_SHANG_MU_LIMIT_IN)
  1005. {
  1006. KKQD_YD_VAVLE = 1;
  1007. if(KK_cZipCnt > 0)
  1008. {
  1009. if(dwXRealPos>(KKQD_PARAM_GO_LOW_SPEED_LENGTH))
  1010. {
  1011. KK_DCC_TIME_BL = KKQD_PARAM_DCC + KKQD_PARAM_GO_HIGH_SPEED/500;
  1012. AxisMovePosAccDecNotStop(X_AXIS,KKQD_PARAM_GO_HIGH_SPEED,-dwXRealPos,
  1013. KKQD_PARAM_START_SPEED,KKQD_PARAM_GO_LOW_SPEED,KKQD_PARAM_ACC,KK_DCC_TIME_BL,
  1014. KKQD_PARAM_GO_LOW_SPEED_LENGTH);
  1015. }
  1016. else
  1017. {
  1018. // X轴 运行速度 启动速度 加速度 减速度
  1019. AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED/3,KKQD_PARAM_GO_LOW_SPEED/3,15,15);
  1020. // MoveAction_Const_AccDec(X_AXIS, KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED_LENGTH,KKQD_PARAM_START_SPEED,KKQD_PARAM_ACC,KKQD_PARAM_DCC);
  1021. }
  1022. }
  1023. else
  1024. {
  1025. // X轴 运行速度 启动速度 加速度 减速度
  1026. AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED/3,KKQD_PARAM_GO_LOW_SPEED/3,15,15);
  1027. // MoveAction_Const_AccDec(X_AXIS, KKQD_DIR_N,KKQD_PARAM_FIRST_GO_HIGHSPEED,KKQD_PARAM_START_SPEED,KKQD_PARAM_ACC,KKQD_PARAM_DCC);//
  1028. }
  1029. KKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1030. KKQD_MotorStep =64;
  1031. }
  1032. break;
  1033. case 64:
  1034. if(KK_cZipCnt > 1)
  1035. {
  1036. if(KKQD_QIAN_LIMIT_IN) //前点限位
  1037. {
  1038. if(KKQD_PARAM_GO_DW_LENGTH)
  1039. {
  1040. SetPos(X_AXIS, KKQD_PARAM_GO_DW_LENGTH);
  1041. AxisMovePosAccDec(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,-KKQD_PARAM_GO_DW_LENGTH,1200,1000,5,5,00);
  1042. }
  1043. else
  1044. AxisEgmStop(X_AXIS);
  1045. KKQD_MotorStep = 66;
  1046. }
  1047. }
  1048. else
  1049. {
  1050. if(KKQD_QIAN_LIMIT_IN) //前点限位
  1051. {
  1052. if(KKQD_PARAM_GO_DW_LENGTH)
  1053. {
  1054. SetPos(X_AXIS, KKQD_PARAM_GO_DW_LENGTH);
  1055. AxisMovePosAccDec(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,-KKQD_PARAM_GO_DW_LENGTH,1200,1000,5,5,00);
  1056. }
  1057. else
  1058. AxisEgmStop(X_AXIS);
  1059. KKQD_MotorStep = 66;
  1060. }
  1061. }
  1062. break;
  1063. case 66:
  1064. if(!X_DRV || (dwXRealPos <= 0))
  1065. {
  1066. SetPos(X_AXIS, 0);
  1067. KKQD_MotorDelay = dwTickCount + 5;
  1068. KKQD_MotorStep = 67;
  1069. }
  1070. break;
  1071. case 67: //等推链完成后,
  1072. if((dwTickCount >= KKQD_MotorDelay) && (KKQD_TuiLianStep == 0) && ((KKQD_PARAM_TIAOSHI_MODE && KKQD_bTS) || (KKQD_PARAM_TIAOSHI_MODE == 0)) )
  1073. {
  1074. if(bRunning)
  1075. {
  1076. KKQD_JD_VAVLE = 1;
  1077. KKQD_MotorDelay = dwTickCount + KKQD_PARAM_DELAY_BACK * 3/5;
  1078. }
  1079. KKQD_MotorStep = 68;
  1080. }
  1081. break;
  1082. case 68:
  1083. if(dwTickCount >= KKQD_MotorDelay)
  1084. {
  1085. KKQD_YD_VAVLE = 0;
  1086. // KKQD_HL_VAVLE = 0;
  1087. // KKQD_YX_VAVLE = 0;
  1088. KKQD_MotorStep = 69;
  1089. KKQD_MotorDelay = dwTickCount + KKQD_PARAM_DELAY_BACK*2/5;
  1090. }
  1091. break;
  1092. case 69:
  1093. if(dwTickCount >= KKQD_MotorDelay)
  1094. {
  1095. KKQD_MotorStep = 0;
  1096. KKQD_MotorDelay = dwTickCount;
  1097. }
  1098. break;
  1099. }
  1100. }
  1101. #endif
  1102. void KK_QueDuan_BingLian(void)
  1103. {
  1104. static long bl_pos_buff,HL_delay;
  1105. switch(KKQD_BinLianStep)
  1106. {
  1107. case 0:break;
  1108. case 1:
  1109. bl_pos_buff = dwXRealPos;
  1110. KKQD_BinLianStep = 2;
  1111. break;
  1112. case 2:
  1113. if((dwXRealPos - bl_pos_buff) >= KKQD_PARAM_DELAY_HL_LENGTH)
  1114. {
  1115. KKQD_BL_VAVLE = 1;
  1116. KKQD_BinLianStep = 3;
  1117. }
  1118. break;
  1119. case 3://有过链检测
  1120. if(KKQD_GUO_LIAN_IN_DW || ((dwXRealPos - bl_pos_buff) >= (KKQD_PARAM_ZIPPER_LENGTH - KKQD_PARAM_HL_DELAY_BACK)))
  1121. {
  1122. KKQD_BL_VAVLE = 0;
  1123. KKQD_BinLianStep = 0;
  1124. }
  1125. break;
  1126. case 10:
  1127. bl_pos_buff = dwXRealPos;
  1128. KKQD_BinLianStep = 11;
  1129. break;
  1130. case 11:
  1131. if((dwXRealPos - bl_pos_buff) >= KKQD_PARAM_DELAY_HL_LENGTH)
  1132. {
  1133. KKQD_BL_VAVLE = 1;
  1134. KKQD_BinLianStep = 12;
  1135. }
  1136. break;
  1137. case 12://有过链检测
  1138. if(KKQD_GUO_LIAN_IN_DW)
  1139. {
  1140. KKQD_BL_VAVLE = 0;
  1141. KKQD_BinLianStep = 0;
  1142. }
  1143. break;
  1144. default:;
  1145. }
  1146. }
  1147. //电机动作
  1148. void KK_QueDuan_Motor(void)
  1149. {
  1150. KK_QueDuan_Motor_KK(); //
  1151. }
  1152. //超声方式下切,开口专用
  1153. void KK_QueDuan_XiaQue_KK(void)
  1154. {
  1155. switch(KKQD_XiaQieStep)
  1156. {
  1157. case 0:
  1158. break;
  1159. case 1:
  1160. if(bRunning)
  1161. {
  1162. KKQD_XiaQieStep = 6;
  1163. KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1164. }
  1165. else
  1166. KKQD_XiaQieStep = 2;
  1167. break;
  1168. case 2:
  1169. KKQD_XM_KAIKOU_VAVLE=1;
  1170. KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1171. KKQD_XiaQieStep = 3;
  1172. break;
  1173. case 3:
  1174. if(KKQD_KAIKUO_XIAMO_LIMIT_IN || KKQD_PARAM_XM_ENABLE)
  1175. {
  1176. KKQD_XiaQieDelay = dwTickCount + 0;//KKQD_PARAM_GZ_DELAY;
  1177. KKQD_XiaQieStep = 4;
  1178. }
  1179. else if(dwTickCount >= KKQD_XiaQieDelay)
  1180. {
  1181. KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
  1182. }
  1183. break;
  1184. case 4:
  1185. if(KKQD_GZ_VAVLE) //勾针已经有输出就不需要延时
  1186. {
  1187. KKQD_XiaQieDelay = dwTickCount + 0;
  1188. }
  1189. else
  1190. KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
  1191. KKQD_GZ_VAVLE = 1;
  1192. KK_cTuiFangKuaiCnt=0;
  1193. KKQD_XiaQieStep = 5;
  1194. break;
  1195. case 5:
  1196. if(dwTickCount >= KKQD_XiaQieDelay)
  1197. {
  1198. KKQD_TFK_VAVLE = 1;
  1199. KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1200. KKQD_XiaQieStep = 6;
  1201. }
  1202. break;
  1203. case 6:
  1204. if(1)
  1205. {
  1206. KKQD_XiaQieStep = 7;
  1207. KKQD_XiaQieDelay = dwTickCount + 1000;
  1208. }
  1209. else if(dwTickCount >= KKQD_XiaQieDelay)
  1210. {
  1211. KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
  1212. }
  1213. break;
  1214. case 7:
  1215. if(KKQD_GOUZHEN_IN)
  1216. {
  1217. KK_cTuiFangKuaiCnt = 0;
  1218. KKQD_YD_VAVLE = 1;
  1219. if(!bRunning)
  1220. KKQD_XiaQieDelay = dwTickCount + 200;
  1221. else
  1222. KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_CUT_DELAY;
  1223. if(!KKQD_QIAN_LIMIT_IN)
  1224. KKQD_XiaQieStep = 8;
  1225. else
  1226. KKQD_SetAlarmCode(KKQD_QIAN_LIMIT_ALARM);
  1227. }
  1228. else if((dwTickCount >= KKQD_XiaQieDelay))
  1229. {
  1230. if(KK_cTuiFangKuaiCnt < KKQD_PARAM_TFK_NUMBER)
  1231. {
  1232. KKQD_TFK_VAVLE = 0;
  1233. KK_cTuiFangKuaiCnt++;
  1234. KKQD_XiaQieDelay = dwTickCount + 500;
  1235. KKQD_XiaQieStep = 100;
  1236. }
  1237. else
  1238. KKQD_SetAlarmCode(KKQD_GZ_ALARM);
  1239. }
  1240. break;
  1241. case 100:
  1242. if((dwTickCount >= KKQD_XiaQieDelay))
  1243. {
  1244. KKQD_XiaQieStep = 5;
  1245. }
  1246. break;
  1247. case 8://上下模同时输出
  1248. if(dwTickCount >= KKQD_XiaQieDelay)
  1249. {
  1250. KKQD_SM_VAVLE = 1;
  1251. if(KKQD_PARAM_XM_ENABLE == 0) //配置下模动
  1252. KKQD_XM_KAIKOU_VAVLE = 1;
  1253. KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1254. KKQD_XiaQieStep = 9;
  1255. }
  1256. break;
  1257. case 9://上下模到位,调试模下的话,等按下一步按键 下模不动
  1258. if(KKQD_SHANG_MU_LIMIT_IN && (KKQD_KAIKUO_XIAMO_LIMIT_IN || KKQD_PARAM_XM_ENABLE) && ((KKQD_PARAM_TIAOSHI_MODE && KKQD_bTS) || (KKQD_PARAM_TIAOSHI_MODE == 0)) )
  1259. {
  1260. if(!KKQD_PARAM_CS_MODE) //无超声配置
  1261. {
  1262. KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_DELAYBACK_SM; //
  1263. KKQD_XiaQieStep = 12;
  1264. }
  1265. else
  1266. {
  1267. KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_DELAY_CS; //
  1268. KKQD_XiaQieStep = 10;
  1269. }
  1270. }
  1271. else if(dwTickCount >= KKQD_XiaQieDelay)
  1272. {
  1273. if(!KKQD_SHANG_MU_LIMIT_IN)KKQD_SetAlarmCode(KKQD_SM_DAOWEI);
  1274. else KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
  1275. }
  1276. break;
  1277. case 10:
  1278. if(dwTickCount >= KKQD_XiaQieDelay)
  1279. {
  1280. KKQD_CS_OUT = 1;
  1281. //
  1282. KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_CS_TIME; //
  1283. KKQD_XiaQieStep = 11;
  1284. }
  1285. break;
  1286. case 11:
  1287. if(dwTickCount >= KKQD_XiaQieDelay)
  1288. {
  1289. KKQD_CS_OUT = 0;
  1290. KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_CS_COLD_TIME; //
  1291. KKQD_XiaQieStep = 12;
  1292. }
  1293. break;
  1294. case 12:
  1295. if(dwTickCount >= KKQD_XiaQieDelay)
  1296. {
  1297. KKQD_SM_VAVLE = 0;
  1298. if(KKQD_PARAM_XM_ENABLE == 0) //配置下模动
  1299. KKQD_XM_KAIKOU_VAVLE=0;
  1300. KKQD_TFK_VAVLE = 0;
  1301. KKQD_GZ_VAVLE = 0;
  1302. KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1303. KKQD_XiaQieStep = 13;
  1304. }//
  1305. break;
  1306. case 13:
  1307. if(!KKQD_SHANG_MU_LIMIT_IN)
  1308. {
  1309. //启动推链(送链)
  1310. if((KKQD_TuiLianStep == 0) && !KKQD_TL_VAVLE)
  1311. KKQD_TuiLianStep = 1;
  1312. }
  1313. if(!KKQD_SHANG_MU_LIMIT_IN && (!KKQD_KAIKUO_XIAMO_LIMIT_IN || KKQD_PARAM_XM_ENABLE))
  1314. {
  1315. KKQD_XiaQieStep = 0;
  1316. }
  1317. else if(dwTickCount >= KKQD_XiaQieDelay)
  1318. {
  1319. KKQD_SetAlarmCode(KKQD_SM_YUANWEI);
  1320. }
  1321. break;
  1322. }
  1323. }
  1324. void KK_QueDuan_TuiLianAction(void)
  1325. {
  1326. if(KKQD_PARAM_XM_ENABLE == 0) //下模动不用推链动作
  1327. {
  1328. KKQD_TuiLianStep = 0;
  1329. }
  1330. else
  1331. {
  1332. switch(KKQD_TuiLianStep)
  1333. {
  1334. case 1:
  1335. KKQD_TuiLianStep = 2;
  1336. break;
  1337. case 2:
  1338. KKQD_TLDelay = dwTickCount + KKQD_PARAM_YD_DELAY;
  1339. KKQD_TuiLianStep = 3;
  1340. break;
  1341. case 3:
  1342. if(!KKQD_SM_VAVLE && !KKQD_SHANG_MU_LIMIT_IN)//dwTickCount >= KKQD_TLDelay)
  1343. {
  1344. KKQD_TL_VAVLE = 1;
  1345. if(!bRunning)KKQD_TFK_VAVLE = 0;
  1346. KKQD_TLDelay = dwTickCount + KKQD_PARAM_TL_DELAY;
  1347. KKQD_TuiLianStep = 4;
  1348. }
  1349. break;
  1350. case 4:
  1351. if(dwTickCount >= KKQD_TLDelay)
  1352. {
  1353. KKQD_TuiLianStep = 0;
  1354. }
  1355. break;
  1356. }
  1357. }
  1358. }
  1359. //切断动作
  1360. void KK_QueDuan_XiaQue(void)
  1361. {
  1362. KK_QueDuan_XiaQue_KK();
  1363. }
  1364. #endif