TYQueDuanJi.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  1. #include "global.h"
  2. #if TONG_YONG_MACHINE
  3. void QueDuan_AlarmProtect(void);
  4. void QueDuan_ManualAction(void);
  5. void QueDuan_AutoAction(void);
  6. void QueDuan_StepCheckStart(void);
  7. void QueDuan_XiaQue(void);
  8. void QueDuan_Motor(void);
  9. void QueDuan_YuanDianAction(void);
  10. void QueDuan_TuiLianAction(void);
  11. void QueDuan_ExtiActionX31(void);
  12. void QueDuan_BingLian(void);
  13. static unsigned long cZipCnt = 0,cTableCnt = 0,cTuiFangKuaiCnt = 0;
  14. static long save_limit_pos,cRealPos;
  15. static long dwSaveLength;
  16. unsigned char cCheckLianFlg = 0;
  17. unsigned char cCheckLianFlgEN = 0;
  18. unsigned char cGoLimitEn = 0;
  19. short *length_buffer;
  20. void QueDuan_ExtiActionX31(void)
  21. {
  22. cCheckLianFlg = 1;
  23. }
  24. void QD_SetAlarmCode(unsigned alarm_code)
  25. {
  26. SetAlarmCode(QD_ALARM_ADDR,alarm_code);
  27. bAlarmStop = 1;
  28. }
  29. void QueDuan_InitAction(void)
  30. {
  31. float length_buff,pulse_buff;
  32. length_buff = QD_PARAM_CYCLE_LENGTH;
  33. pulse_buff = QD_PARAM_CYCLE_PULSE;
  34. XGearRatio = pulse_buff/length_buff;
  35. QD_SZ_OUT = 1;
  36. }
  37. void QueDuan_Action(void)
  38. {
  39. QueDuan_AlarmProtect();
  40. QueDuan_Motor();
  41. QueDuan_XiaQue();
  42. QueDuan_ManualAction();
  43. QueDuan_YuanDianAction();
  44. QueDuan_TuiLianAction();
  45. QueDuan_BingLian();
  46. QueDuan_AutoAction();
  47. QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
  48. }
  49. //手动动作
  50. void QueDuan_ManualAction(void)
  51. {
  52. if(bRunning == 0)
  53. {
  54. if(QD_bClearTotal) //切断计数清零
  55. {
  56. QD_bClearTotal = 0;
  57. ClrcToTal(QD_TOTAL_ADDR);
  58. }
  59. if(QD_bClearNowTotal)
  60. {
  61. QD_bClearNowTotal = 0;
  62. QD_PARAM_NOW_CNT = 0;
  63. }
  64. if(QD_bXiaQie)
  65. {
  66. QD_bXiaQie = 0;
  67. if(QD_XiaQieStep == 0)QD_XiaQieStep = 1;
  68. }
  69. if(QD_bQianDianDW)
  70. {
  71. QD_bQianDianDW = 0;
  72. if(QD_MotorStep == 0)
  73. {
  74. QD_MotorStep = 61;
  75. cZipCnt = 0;
  76. }
  77. }
  78. if(QD_bTL)
  79. {
  80. QD_TL_VAVLE = ~QD_TL_VAVLE;
  81. }
  82. if(!Y_DRV)QD_bTL = 0;
  83. if(QD_bYD)
  84. {
  85. QD_bYD = 0;
  86. QD_YD_VAVLE = ~QD_YD_VAVLE;
  87. }
  88. if(QD_bGZ)
  89. {
  90. QD_bGZ = 0;
  91. QD_GZ_VAVLE = ~QD_GZ_VAVLE;
  92. }
  93. if(QD_bJD)
  94. {
  95. QD_bJD = 0;
  96. QD_JD_VAVEL = ~QD_JD_VAVEL;
  97. }
  98. if(QD_bXM)
  99. {
  100. QD_bXM = 0;
  101. QD_XM_VAVLE = ~QD_XM_VAVLE;
  102. if(!QD_XM_VAVLE)QD_GZ_VAVLE = 0;
  103. }
  104. if(QD_bSM)
  105. {
  106. QD_bSM = 0;
  107. QD_SM_VAVLE = ~QD_SM_VAVLE;
  108. }
  109. if(QD_bTFK)
  110. {
  111. QD_bTFK = 0;
  112. QD_TFK_VAVEL = ~QD_TFK_VAVEL;
  113. }
  114. if(QD_bTB)
  115. {
  116. QD_bTB = 0;
  117. QD_TABLE_VAVLE = ~QD_TABLE_VAVLE;
  118. }
  119. if(QD_bYBD)
  120. {
  121. QD_bYBD = 0;
  122. QD_YBD_VAVLE = ~QD_YBD_VAVLE;
  123. }
  124. if(QD_bTestCS)
  125. {
  126. QD_bTestCS = 0;
  127. QD_CS_OUT = 1;
  128. QD_CSDelay = dwTickCount + QD_PARAM_CS_TIME;
  129. }
  130. if(QD_bBL)
  131. {
  132. QD_bBL = 0;
  133. QD_BL_VAVLE = ~QD_BL_VAVLE;
  134. }
  135. if(QD_XiaQieStep == 0)
  136. {
  137. if(dwTickCount >= QD_CSDelay)QD_CS_OUT = 0;
  138. }
  139. if(QD_bYuanDianDW)
  140. {
  141. QD_bYuanDianDW = 0;
  142. if(QD_YuanDianStep == 0)QD_YuanDianStep = 1;
  143. }
  144. //电机控制
  145. if(QD_bGoMotor && !QD_QIAN_LIMIT_IN)
  146. {
  147. QD_SZ_OUT = 0;
  148. QD_JZ_DIR = QD_YDIR_N;
  149. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,QD_DIR_N,10,1,5,5);
  150. }
  151. if(QD_bBackMotor && !QD_BACK_LIMIT_IN)
  152. {
  153. QD_SZ_OUT = 0;
  154. QD_JZ_DIR = QD_YDIR_P;
  155. if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,10,1,5,5);
  156. }
  157. if(!QD_bGoMotor && !QD_bBackMotor && (QD_MotorStep == 0))
  158. {
  159. if(X_DRV)AxisDecStop(X_AXIS);
  160. }
  161. if(QD_QIAN_LIMIT_IN && (QD_MotorStep == 0) && !QD_bBackMotor &&(QD_AutoStep == 0))
  162. {
  163. if(X_DRV)AxisEgmStop(X_AXIS);
  164. }
  165. }
  166. }
  167. void QueDuan_YuanDianAction(void)
  168. {
  169. switch(QD_YuanDianStep)
  170. {
  171. case 0:break;
  172. case 1:
  173. if(QD_MotorStep == 0)QD_MotorStep = 61;
  174. QD_YuanDianStep = 2;
  175. break;
  176. case 2:
  177. if(QD_MotorStep == 0)
  178. {
  179. QD_MotorStep = 30;
  180. QD_YuanDianStep = 3;
  181. QD_JD_VAVEL = 1;
  182. }
  183. break;
  184. case 3:
  185. if(QD_MotorStep == 0)
  186. {
  187. QD_MotorStep = 0;
  188. QD_YuanDianStep = 0;
  189. }
  190. break;
  191. }
  192. }
  193. void QueDuan_AlarmProtect(void)
  194. {
  195. cRealPos = GetPos(X_AXIS);
  196. if(!bRunning)
  197. {
  198. if(QD_BACK_LIMIT_IN_UP)
  199. {
  200. if((QD_MotorStep == 0) && X_DRV && QD_bBackMotor) //到后限不能再后退但可以点前进
  201. {
  202. QD_bBackMotor = 0;
  203. AxisDecStop(X_AXIS);
  204. QD_JD_VAVEL = 0;
  205. QD_SetAlarmCode(QD_BACK_ALARM);
  206. }
  207. }
  208. }
  209. else
  210. {
  211. if(QD_BACK_LIMIT_IN_UP)
  212. {
  213. AxisDecStop(X_AXIS);
  214. QD_JD_VAVEL = 0;
  215. QD_SetAlarmCode(QD_BACK_ALARM);
  216. }
  217. }
  218. // if(!QD_KADAI_IN)QD_KaDaiDelay = dwTickCount + 3000;
  219. /* if(bRunning)
  220. {
  221. if(dwTickCount >= QD_KaDaiDelay)QD_SetAlarmCode(QD_KA_DAI_ALARM);
  222. }*/
  223. }
  224. void QueDuan_AutoAction(void)
  225. {
  226. if(bRunning)
  227. {
  228. if(dwTickCount >= QD_TBDelay)QD_TABLE_VAVLE = 0;
  229. switch(QD_AutoStep)
  230. {
  231. case 1:
  232. if(dwTickCount >= QD_AutoDelay)
  233. {
  234. QD_AutoStep = 2;
  235. if(QD_MotorStep == 0)
  236. {
  237. QD_MotorStep = 61; //前点定位
  238. }
  239. }
  240. break;
  241. case 2:
  242. if(QD_MotorStep == 0)
  243. {
  244. QD_MotorStep = 30;
  245. QD_AutoStep = 3;
  246. }
  247. break;
  248. case 3:
  249. if(QD_MotorStep == 0)
  250. {
  251. if(QD_XiaQieStep == 0)QD_XiaQieStep = 1;
  252. QD_AutoStep = 4;
  253. }
  254. break;
  255. case 4:
  256. if(QD_MACHINE_TYPE == QD_NO_GL_TUIFANGKUAI)
  257. {
  258. if(((QD_XiaQieStep == 0) || (QD_XiaQieStep == 6)) && !QD_SHANG_MU_LIMIT_IN)
  259. {
  260. if(QD_MotorStep == 0)
  261. {
  262. QD_MotorStep = 40; //切完后退
  263. QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  264. }
  265. QD_AutoStep = 5;
  266. }
  267. }
  268. else
  269. {
  270. if(((QD_XiaQieStep == 0) || (QD_XiaQieStep == 13)) && !QD_SHANG_MU_LIMIT_IN && !QD_XIA_MU_LIMIT_IN)
  271. {
  272. if(QD_MotorStep == 0)
  273. {
  274. QD_MotorStep = 40; //切完后退
  275. QD_AutoStep = 5;
  276. }
  277. }
  278. }
  279. break;
  280. case 5:
  281. if(QD_MotorStep == 0)
  282. {
  283. cZipCnt++;
  284. QD_PARAM_NOW_CNT++;
  285. cTableCnt++;
  286. AddToTal(QD_TOTAL_ADDR);
  287. CalProSP(QD_PROSPEED_ADDR);
  288. if(cTableCnt >= QD_PARAM_TABLE_NUM)
  289. {
  290. cTableCnt = 0;
  291. QD_TABLE_VAVLE = 1;
  292. QD_TBDelay = dwTickCount + QD_PARAM_TB_TIME;
  293. }
  294. if((GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) || SingOneFlg)
  295. {
  296. bRunning = 0;
  297. QD_AutoStep = 0;
  298. SingOneFlg = 0;
  299. if(GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) QD_SetAlarmCode(QD_TOTAL_ALARM);
  300. }
  301. else
  302. {
  303. QD_AutoStep = 1;
  304. if(QD_PARAM_NOW_CNT >= QD_PARAM_ZHA_SHU)
  305. {
  306. QD_AutoDelay = dwTickCount + QD_PARAM_ZS_STOP_TIME + 50;
  307. QD_PARAM_NOW_CNT = 0;
  308. }
  309. else
  310. QD_AutoDelay = dwTickCount + QD_PARAM_CYCLE_DELAY;
  311. }
  312. }
  313. break;
  314. }
  315. }
  316. }
  317. void QueDuan_StepCheckStart(void)
  318. {
  319. // 启动
  320. if((START_IN_UP) || bStart || QD_bSingle)
  321. {
  322. bStart = 0;
  323. if(!bRunning && (QD_AutoStep == 0))
  324. {
  325. if(!QD_SHANG_MU_ORIGIN_IN)QD_SetAlarmCode(QD_SM_YUANWEI);
  326. else if(QD_XIA_MU_LIMIT_IN)QD_SetAlarmCode(QD_XM_DAOWEI);
  327. else if(GetAlarmCode(QD_ALARM_ADDR) != 0);
  328. else if(GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) QD_SetAlarmCode(QD_TOTAL_ALARM);
  329. else if(QD_BL_VAVLE)QD_SetAlarmCode(QD_BL_ALARM);
  330. else if(QD_SM_VAVLE)QD_SetAlarmCode(QD_SM_ALARM);
  331. else
  332. {
  333. bRunning = 1;
  334. QD_AutoStep = 1;
  335. if(QD_bSingle) SingOneFlg= 1;
  336. cZipCnt = 0;
  337. cTuiFangKuaiCnt = 0;
  338. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  339. }
  340. }
  341. QD_bSingle = 0;
  342. }
  343. //停止
  344. if(STOP_IN_UP || bStop)
  345. {
  346. bStop = 0;
  347. if(bRunning)
  348. {
  349. bRunning = 0;
  350. QD_XiaQieStep = 0;
  351. QD_AutoStep = 0;
  352. QD_MotorStep = 0;
  353. QD_TuiLianStep = 0;
  354. QD_YuanDianStep = 0;
  355. QD_AutoDelay = dwTickCount;
  356. QD_MotorDelay = dwTickCount;
  357. QD_XiaQieDelay = dwTickCount;
  358. QD_KaDaiDelay = dwTickCount;
  359. QD_CSDelay = dwTickCount;
  360. QD_TBDelay = dwTickCount;
  361. QD_TFKDelay = dwTickCount;
  362. QD_TLDelay = dwTickCount;
  363. QD_CheckDelay = dwTickCount;
  364. dwTickCount = QD_TBDelay;
  365. SingOneFlg = 0;
  366. QD_JD_VAVEL = 0;
  367. QD_SM_VAVLE = 0;
  368. QD_XM_VAVLE = 0;
  369. QD_YD_VAVLE = 0;
  370. QD_TFK_VAVEL= 0;
  371. QD_TL_VAVLE = 0;
  372. QD_YBD_VAVLE = 0;
  373. QD_CS_OUT = 0;
  374. QD_XiaQieStep = 0;
  375. QD_MotorStep = 0;
  376. QD_TuiLianStep = 0;
  377. //QD_SZ_OUT = 1;
  378. QD_GZ_VAVLE = 0;
  379. QD_TABLE_VAVLE = 0;
  380. AxisDecStop(X_AXIS);
  381. QD_YuanDianStep = 0;
  382. QD_BinLianStep = 0;
  383. QD_BL_VAVLE = 0;
  384. user_datas[121] = 0;
  385. user_datas[122] = 0;
  386. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  387. }
  388. else
  389. {
  390. bRunning = 0;
  391. QD_XiaQieStep = 0;
  392. QD_AutoStep = 0;
  393. QD_MotorStep = 0;
  394. QD_TuiLianStep = 0;
  395. QD_YuanDianStep = 0;
  396. QD_AutoDelay = dwTickCount;
  397. QD_MotorDelay = dwTickCount;
  398. QD_XiaQieDelay = dwTickCount;
  399. QD_KaDaiDelay = dwTickCount;
  400. QD_CSDelay = dwTickCount;
  401. QD_TBDelay = dwTickCount;
  402. QD_TFKDelay = dwTickCount;
  403. QD_TLDelay = dwTickCount;
  404. QD_CheckDelay = dwTickCount;
  405. dwTickCount = QD_TBDelay;
  406. SingOneFlg = 0;
  407. QD_JD_VAVEL = 0;
  408. QD_SM_VAVLE = 0;
  409. QD_XM_VAVLE = 0;
  410. QD_YD_VAVLE = 0;
  411. QD_TFK_VAVEL= 0;
  412. QD_TL_VAVLE = 0;
  413. QD_YBD_VAVLE = 0;
  414. QD_CS_OUT = 0;
  415. QD_XiaQieStep = 0;
  416. QD_MotorStep = 0;
  417. QD_TuiLianStep = 0;
  418. QD_SZ_OUT = 1;
  419. QD_GZ_VAVLE = 0;
  420. QD_TABLE_VAVLE = 0;
  421. AxisDecStop(X_AXIS);
  422. QD_YuanDianStep = 0;
  423. QD_BinLianStep = 0;
  424. QD_BL_VAVLE = 0;
  425. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  426. }
  427. }
  428. if(bAlarmStop)
  429. {
  430. bAlarmStop = 0;
  431. QD_XiaQieStep = 0;
  432. QD_AutoStep = 0;
  433. QD_MotorStep = 0;
  434. QD_TuiLianStep = 0;
  435. QD_YuanDianStep = 0;
  436. QD_XiaQieStep = 0;
  437. QD_MotorStep = 0;
  438. QD_TuiLianStep = 0;
  439. QD_AutoDelay = dwTickCount;
  440. QD_MotorDelay = dwTickCount;
  441. QD_XiaQieDelay = dwTickCount;
  442. QD_KaDaiDelay = dwTickCount;
  443. QD_CSDelay = dwTickCount;
  444. QD_TBDelay = dwTickCount;
  445. QD_TFKDelay = dwTickCount;
  446. QD_TLDelay = dwTickCount;
  447. QD_CheckDelay = dwTickCount;
  448. SingOneFlg = 0;
  449. bRunning = 0;
  450. AxisDecStop(X_AXIS);
  451. dwTickCount = QD_TBDelay;
  452. QD_TABLE_VAVLE = 0;
  453. }
  454. }
  455. //记忆长度模式误差检测
  456. void QueDuan_CheckLength(long zip_length)
  457. {
  458. static long start_dist;
  459. switch(QD_CheckLengthStep)
  460. {
  461. case 0:break;
  462. case 1:
  463. start_dist = cRealPos;
  464. QD_CheckLengthStep = 2;
  465. break;
  466. case 2:
  467. if(QD_GUO_LIAN_IN_DW) dwSaveLength = cRealPos - start_dist;
  468. break;
  469. }
  470. }
  471. void QueDuan_Motor_CS(void)
  472. {
  473. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  474. user_datas[121]= QD_MotorStep;
  475. user_datas[122]= length_buff;
  476. user_datas[123] = cRealPos;
  477. user_datas[124] = dwSaveLength - (*length_buffer);
  478. user_datas[125] = QD_AutoStep;
  479. user_datas[126] = QD_XiaQieStep;
  480. user_datas[127] = QD_XiaQieStep;
  481. QueDuan_CheckLength(length_buff);
  482. switch(QD_MotorStep)
  483. {
  484. case 30:
  485. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  486. QD_MotorStep = 31;
  487. if(QD_PARAM_BL_ENABLE)QD_BinLianStep = 1;
  488. break;
  489. case 31:
  490. if(dwTickCount >= QD_MotorDelay)
  491. {
  492. save_buff = cRealPos;
  493. back_buff = cRealPos;
  494. QD_JZ_DIR = QD_YDIR_P;
  495. if(QD_PARAM_BACK_MODE == QD_BACK_INDUCTION_MODE) // 纯感应模式
  496. {
  497. if(QD_PARAM_DEC_MODE == QD_BACK_DIGITAL_MODE) // 数控降速
  498. {
  499. if(cZipCnt < 2)
  500. {
  501. MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,QD_PARAM_CHECK_BACK_HSPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  502. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  503. QD_MotorStep = 32;
  504. }
  505. else
  506. {
  507. MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,QD_PARAM_BACK_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  508. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  509. QD_MotorStep = 32;
  510. }
  511. }
  512. else
  513. {
  514. MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,QD_PARAM_BACK_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  515. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  516. QD_MotorStep = 32;
  517. }
  518. }
  519. else
  520. {
  521. if(QD_PARAM_BACK_MODE == QD_BACK_INPUT_LENGTH_MODE)
  522. {
  523. gouzhen_buff = cRealPos;
  524. length_buffer = &QD_PARAM_OFFSET_LENGTH;
  525. length_buff = QD_PARAM_ZIPPER_LENGTH + (*length_buffer);
  526. AxisMovePosAccDec(X_AXIS,QD_PARAM_BACK_SPEED,(-length_buff),QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  527. MoveChangSpeedPos(X_AXIS, QD_PARAM_BACK_LOW_SPEED,(PosToPulse(X_AXIS,QD_PARAM_BACK_LOW_SPEED_LENGTH) + MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_DCC)));
  528. QD_MotorDelay = dwTickCount;
  529. QD_MotorStep = 34;
  530. }
  531. else
  532. {
  533. if(cZipCnt < 2)
  534. {
  535. MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,QD_PARAM_CHECK_BACK_HSPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  536. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  537. QD_MotorStep = 32;
  538. }
  539. else
  540. {
  541. gouzhen_buff = cRealPos;
  542. AxisMovePosAccDec(X_AXIS,QD_PARAM_BACK_SPEED,(-length_buff),QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  543. MoveChangSpeedPos(X_AXIS, QD_PARAM_BACK_LOW_SPEED,(PosToPulse(X_AXIS,QD_PARAM_BACK_LOW_SPEED_LENGTH) + MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_DCC)));
  544. QD_MotorDelay = dwTickCount;
  545. QD_MotorStep = 34;
  546. QD_CheckLengthStep = 1;
  547. }
  548. }
  549. }
  550. }
  551. break;
  552. case 32:
  553. if(QD_PARAM_BACK_MODE == QD_BACK_INDUCTION_MODE) //感应方式
  554. {
  555. if(QD_PARAM_DEC_MODE == QD_BACK_DIGITAL_MODE) // 数控降速
  556. {
  557. if(cZipCnt < 2)
  558. {
  559. if(QD_GUO_LIAN_IN_UP)
  560. {
  561. checkdelay_buff = cRealPos;
  562. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_XM;
  563. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  564. QD_MotorStep = 33;
  565. }
  566. else if(dwTickCount >= QD_MotorDelay)
  567. {
  568. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  569. }
  570. }
  571. else
  572. {
  573. if((cRealPos - back_buff) > (length_buff - (QD_PARAM_BACK_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_DCC)))))
  574. {
  575. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  576. }
  577. if(QD_GUO_LIAN_IN_UP)
  578. {
  579. checkdelay_buff = cRealPos;
  580. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_XM;
  581. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  582. QD_MotorStep = 33;
  583. }
  584. else if(dwTickCount >= QD_MotorDelay)
  585. {
  586. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  587. }
  588. }
  589. }
  590. else
  591. {
  592. if(QD_GUO_LIAN_IN_UP)
  593. {
  594. checkdelay_buff = cRealPos;
  595. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  596. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_XM;
  597. QD_MotorStep = 33;
  598. }
  599. else if(dwTickCount >= QD_MotorDelay)
  600. {
  601. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  602. }
  603. }
  604. }
  605. else
  606. {
  607. if(cZipCnt < 2)
  608. {
  609. if(QD_GUO_LIAN_IN_UP)
  610. {
  611. checkdelay_buff = cRealPos;
  612. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_XM;
  613. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  614. QD_MotorStep = 33;
  615. }
  616. else if(dwTickCount >= QD_MotorDelay)
  617. {
  618. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  619. }
  620. }
  621. }
  622. break;
  623. case 33:
  624. if(dwTickCount >= QD_MotorDelay)
  625. {
  626. QD_XM_VAVLE = 1;
  627. QD_MotorStep = 34;
  628. }
  629. break;
  630. case 34:
  631. if(((cZipCnt < 2) || (QD_PARAM_BACK_MODE == QD_BACK_INDUCTION_MODE)) && (QD_PARAM_BACK_MODE != QD_BACK_INPUT_LENGTH_MODE))
  632. {
  633. if((((cRealPos - checkdelay_buff) >= QD_PARAM_DELAY_CHECK) && (QD_PARAM_LT_ENABLE)) || (((cRealPos - checkdelay_buff) >= QD_PARAM_NO_LT_DELAY_CHECK) && (QD_PARAM_LT_ENABLE == 0)))
  634. {
  635. if(QD_GUO_LIAN_IN_DW)
  636. {
  637. gou_zhen_buff = cRealPos;
  638. QD_MotorStep = 35;
  639. }
  640. }
  641. }
  642. else
  643. {
  644. if(QD_PARAM_LT_ENABLE == 0)
  645. {
  646. if((cRealPos - gouzhen_buff) >= (length_buff - (QD_PARAM_DELAY_XM_LENGTH)))QD_XM_VAVLE = 1;
  647. if((cRealPos - gouzhen_buff) >= (length_buff - QD_PARAM_GOUZHEN_LENGTH))
  648. {
  649. QD_XM_VAVLE = 1;
  650. QD_GZ_VAVLE = 1;
  651. QD_MotorStep = 36;
  652. }
  653. }
  654. else
  655. {
  656. if((cRealPos - gouzhen_buff) >= (length_buff - (QD_PARAM_DELAY_XM_LENGTH)))
  657. {
  658. QD_XM_VAVLE = 1;
  659. QD_MotorStep = 36;
  660. }
  661. }
  662. }
  663. break;
  664. case 35:
  665. if(QD_GUO_LIAN_IN_DW)
  666. {
  667. gou_zhen_buff = cRealPos;
  668. }
  669. if(QD_GUO_LIAN_IN_UP)
  670. {
  671. gou_zhen_buff = cRealPos;
  672. }
  673. if((cRealPos - gou_zhen_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  674. {
  675. AxisEgmStop(X_AXIS);
  676. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  677. QD_MotorStep = 36;
  678. }
  679. break;
  680. case 36:
  681. if(!X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  682. {
  683. if(QD_PARAM_BACK_MODE == QD_BACK_INDUCTION_MODE)
  684. {
  685. QD_GZ_VAVLE = 1;
  686. }
  687. else
  688. {
  689. if((cZipCnt < 2) || (QD_PARAM_BACK_MODE != QD_BACK_INPUT_LENGTH_MODE))
  690. {
  691. QD_GZ_VAVLE = 1;
  692. }
  693. else
  694. {
  695. if(QD_PARAM_LT_ENABLE == 1)QD_GZ_VAVLE = 1;
  696. }
  697. }
  698. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  699. QD_MotorStep = 37;
  700. }
  701. break;
  702. case 37:
  703. if(QD_XIA_MU_LIMIT_IN)
  704. {
  705. QD_MotorStep = 38;
  706. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  707. }
  708. else if(dwTickCount >= QD_MotorDelay) QD_SetAlarmCode(QD_XM_DAOWEI);
  709. break;
  710. case 38:
  711. if(dwTickCount >= QD_MotorDelay)
  712. {
  713. QD_TFK_VAVEL = 1;
  714. QD_MotorStep = 39;
  715. }
  716. break;
  717. case 39:
  718. if(!X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  719. {
  720. if(cZipCnt == 1)
  721. {
  722. length_buff = cRealPos - save_buff;
  723. }
  724. if(cZipCnt == 0)
  725. {
  726. go_length_buff = cRealPos - save_buff;
  727. }
  728. if((QD_PARAM_BACK_MODE != QD_BACK_INDUCTION_MODE)&&(QD_PARAM_BACK_MODE != QD_BACK_INPUT_LENGTH_MODE) && (cZipCnt >= 2))
  729. {
  730. length_buffer = &QD_PARAM_OFFSET_LENGTH;
  731. if((dwSaveLength - (*length_buffer)+ QD_PARAM_ERROR_LENGTH) < length_buff)
  732. {
  733. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  734. QD_CheckLengthStep = 0;
  735. }
  736. else if((dwSaveLength - (*length_buffer)-QD_PARAM_ERROR_LENGTH) > length_buff)
  737. {
  738. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  739. QD_CheckLengthStep = 0;
  740. }
  741. else
  742. QD_CheckLengthStep = 0;
  743. }
  744. if((QD_PARAM_BACK_MODE == QD_BACK_INDUCTION_MODE) && (cZipCnt >= 2))
  745. {
  746. if((cRealPos - save_buff) > (length_buff+QD_PARAM_ERROR_LENGTH))QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  747. else if((cRealPos - save_buff) < (length_buff-QD_PARAM_ERROR_LENGTH))QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  748. }
  749. QD_MotorStep = 0;
  750. QD_MotorDelay = dwTickCount;
  751. }
  752. break;
  753. case 40:
  754. dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  755. QD_JZ_DIR = QD_YDIR_P;
  756. QD_MotorStep = 41;
  757. break;
  758. case 41:
  759. if(dwTickCount >= QD_MotorDelay)
  760. {
  761. jz_buff = cRealPos;
  762. if(QD_PARAM_SJZ_LENGTH == 0)
  763. {
  764. QD_JD_VAVEL = 0;
  765. }
  766. QD_MotorDelay = dwTickCount + 35;
  767. QD_MotorStep = 42;
  768. }
  769. break;
  770. case 42:
  771. if((dwTickCount >= QD_MotorDelay) || (QD_JD_VAVEL == 1))
  772. {
  773. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH));
  774. QD_MotorStep = 43;
  775. }
  776. break;
  777. case 43:
  778. // 切断完成后拉电机动作
  779. if(dwTickCount >= QD_MotorDelay)
  780. {
  781. if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - jz_buff)))
  782. {
  783. QD_JD_VAVEL = 0;
  784. QD_MotorStep = 44;
  785. }
  786. else if(!X_DRV)
  787. {
  788. QD_JD_VAVEL = 0;
  789. QD_MotorStep = 44;
  790. }
  791. }
  792. break;
  793. case 44: // 切断完成后拉电机动作
  794. if(!X_DRV)
  795. {
  796. QD_MotorStep = 0;
  797. QD_MotorDelay = dwTickCount;
  798. }
  799. break;
  800. case 61: // 前点定位数控模式
  801. if(QD_SZ_OUT)
  802. {
  803. QD_SZ_OUT = 0;
  804. QD_MotorDelay = dwTickCount + 50;
  805. }
  806. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE)QD_TuiLianStep = 1;
  807. QD_MotorStep = 62;
  808. break;
  809. case 62:
  810. if(dwTickCount >= QD_MotorDelay)
  811. {
  812. if(QD_QIAN_LIMIT_IN || QD_QIAN_DEC_IN)
  813. {
  814. MV_Set_Acc_CPU(X_AXIS, 10);
  815. QD_JZ_DIR = QD_YDIR_P;
  816. AxisMovePos(X_AXIS,QD_PARAM_CHECK_BACK_HSPEED,-QD_PARAM_ON_BACK_LENGTH);
  817. QD_MotorDelay = dwTickCount + 1000;
  818. }
  819. QD_MotorStep = 63;
  820. QD_JD_VAVEL = 0;
  821. }
  822. break;
  823. case 63:
  824. if(!X_DRV && (dwTickCount >= QD_MotorDelay))
  825. {
  826. go_buff = cRealPos;
  827. QD_JZ_DIR = QD_YDIR_N;
  828. if(cZipCnt > 0)
  829. {
  830. MoveAction_Const_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);//
  831. }
  832. else
  833. {
  834. MoveAction_Const_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_FIRST_GO_HIGHSPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);//
  835. }
  836. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  837. QD_MotorStep = 64;
  838. }
  839. break;
  840. case 64:
  841. if(cZipCnt > 0)
  842. {
  843. if(((go_buff - cRealPos) > (go_length_buff - (QD_PARAM_GO_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,10))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) || (QD_QIAN_DEC_IN_UP))
  844. {
  845. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  846. QD_MotorStep =65;
  847. }
  848. }
  849. else
  850. {
  851. if(QD_QIAN_DEC_IN_UP)
  852. {
  853. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  854. QD_MotorStep =65;
  855. }
  856. }
  857. break;
  858. case 65:
  859. if(QD_QIAN_LIMIT_IN_UP)
  860. {
  861. AxisEgmStop(X_AXIS);
  862. QD_MotorStep = 66;
  863. }
  864. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  865. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  866. break;
  867. case 66:
  868. if(!X_DRV)
  869. {
  870. QD_MotorDelay = dwTickCount;
  871. QD_MotorStep = 67;
  872. }
  873. break;
  874. case 67:
  875. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  876. {
  877. if(bRunning)
  878. {
  879. QD_JD_VAVEL = 1;
  880. }
  881. QD_MotorStep = 68;
  882. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  883. }
  884. break;
  885. case 68:
  886. if(dwTickCount >= QD_MotorDelay)
  887. {
  888. QD_YD_VAVLE = 0;
  889. QD_YBD_VAVLE = 0;
  890. QD_TL_VAVLE = 0;
  891. QD_BL_VAVLE = 0;
  892. QD_MotorStep = 0;
  893. }
  894. break;
  895. }
  896. }
  897. void QueDuan_BingLian(void)
  898. {
  899. static long bl_pos_buff;
  900. switch(QD_BinLianStep)
  901. {
  902. case 0:break;
  903. case 1:
  904. bl_pos_buff = cRealPos;
  905. QD_BinLianStep = 2;
  906. break;
  907. case 2:
  908. if((cRealPos - bl_pos_buff) >= QD_PARAM_DELAY_HL_LENGTH)
  909. {
  910. QD_BL_VAVLE = 1;
  911. QD_BinLianStep = 3;
  912. }
  913. break;
  914. case 3:
  915. if(((cRealPos - bl_pos_buff+QD_PARAM_HL_BACK_LENGTH) >= QD_PARAM_ZIPPER_LENGTH) || QD_SM_VAVLE)
  916. {
  917. QD_BL_VAVLE = 0;
  918. QD_BinLianStep = 0;
  919. }
  920. break;
  921. default:;
  922. }
  923. }
  924. //不带过链感应长度输入电机长度
  925. void QueDuan_Motor_NoGL(void)
  926. {
  927. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  928. user_datas[124]= QD_MotorStep;
  929. // user_datas[125]= go_length_buff;
  930. // user_datas[123] = length_buff;
  931. user_datas[127] = cRealPos;
  932. // user_datas[126] = go_buff - cRealPos;
  933. // user_datas[121] = QD_PARAM_GOUZHEN_LENGTH;
  934. if(QD_GUO_LIAN_IN_DW)user_datas[122]++;
  935. switch(QD_MotorStep)
  936. {
  937. case 30:
  938. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  939. length_buffer = &QD_PARAM_OFFSET_LENGTH;
  940. if(QD_PARAM_BL_ENABLE)QD_BinLianStep = 1;
  941. if(QD_PARAM_LENGTH_MODE == 0)
  942. QD_MotorStep = 101;
  943. else
  944. QD_MotorStep = 31;
  945. break;
  946. case 31:
  947. if(dwTickCount >= QD_MotorDelay)
  948. {
  949. back_buff = cRealPos;
  950. gou_zhen_buff = cRealPos;
  951. save_buff = cRealPos;
  952. if(cZipCnt > 0)
  953. MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,QD_PARAM_BACK_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  954. else
  955. MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,QD_PARAM_CHECK_BACK_HSPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  956. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  957. QD_MotorStep = 33;
  958. }
  959. break;
  960. case 32:
  961. if(((cRealPos - gou_zhen_buff) > (QD_PARAM_ZIPPER_LENGTH - (*length_buffer) - QD_PARAM_GOUZHEN_LENGTH)) && !QD_GZ_VAVLE)QD_GZ_VAVLE = 1;
  962. if((cRealPos - back_buff) > (QD_PARAM_ZIPPER_LENGTH - (*length_buffer) - (QD_PARAM_BACK_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_DCC)))))
  963. {
  964. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  965. QD_MotorStep = 33;
  966. }
  967. else if(dwTickCount >= QD_MotorDelay)
  968. {
  969. QD_SetAlarmCode(QD_GZ_ALARM);
  970. }
  971. break;
  972. case 33:
  973. if(((cRealPos - gou_zhen_buff) > (QD_PARAM_ZIPPER_LENGTH - (*length_buffer) - QD_PARAM_GOUZHEN_LENGTH)) && !QD_GZ_VAVLE) QD_GZ_VAVLE = 1;
  974. if(QD_GOUZHEN_IN)
  975. {
  976. AxisEgmStop(X_AXIS);
  977. QD_YD_VAVLE = 1;
  978. QD_MotorStep = 34;
  979. }
  980. else if(((cRealPos - save_buff) >= (QD_PARAM_ERROR_LENGTH + QD_PARAM_ZIPPER_LENGTH - (*length_buffer))) && QD_GZ_VAVLE)
  981. {
  982. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  983. }
  984. else if(dwTickCount >= QD_MotorDelay)
  985. {
  986. QD_SetAlarmCode(QD_GZ_ALARM);
  987. }
  988. break;
  989. case 34:
  990. if(!X_DRV && (dwTickCount >= QD_MotorDelay))
  991. {
  992. AxisMovePos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_FZ_LENGTH);
  993. QD_MotorStep = 0;
  994. }
  995. break;
  996. case 101:
  997. if(dwTickCount >= QD_MotorDelay)
  998. {
  999. back_buff = cRealPos;
  1000. gou_zhen_buff = cRealPos;
  1001. save_buff = cRealPos;
  1002. if(cZipCnt < 2)
  1003. {
  1004. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1005. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P);
  1006. QD_MotorStep = 102;
  1007. }
  1008. else
  1009. {
  1010. MoveAction_Const_Back(X_AXIS,QD_DIR_P,QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,PosToPulse(X_AXIS,((length_buff - QD_PARAM_TC_LENGTH) - (QD_PARAM_BACK_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,30))))));
  1011. QD_MotorStep = 102;
  1012. }
  1013. }
  1014. break;
  1015. case 102:
  1016. if(cZipCnt < 2)
  1017. {
  1018. if(QD_GUO_LIAN_IN_UP)
  1019. {
  1020. QD_MotorDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1021. QD_MotorStep = 103;
  1022. }
  1023. }
  1024. else
  1025. {
  1026. if(((cRealPos - gou_zhen_buff) > ((length_buff - QD_PARAM_TC_LENGTH) - QD_PARAM_GOUZHEN_LENGTH)) && !QD_GZ_VAVLE)
  1027. {
  1028. save_buff = cRealPos;
  1029. QD_GZ_VAVLE = 1;
  1030. }
  1031. if((cRealPos - back_buff) > ((length_buff - QD_PARAM_TC_LENGTH) - (QD_PARAM_BACK_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,10)))))
  1032. {
  1033. if(X_DRV)
  1034. {
  1035. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1036. }
  1037. QD_MotorStep = 103;
  1038. }
  1039. }
  1040. break;
  1041. case 103:
  1042. if(cZipCnt < 2)
  1043. {
  1044. if(dwTickCount >= QD_MotorDelay)
  1045. {
  1046. QD_GZ_VAVLE = 1;
  1047. QD_MotorStep = 104;
  1048. }
  1049. }
  1050. else
  1051. {
  1052. if(((cRealPos - gou_zhen_buff) > ((length_buff - QD_PARAM_TC_LENGTH) - QD_PARAM_GOUZHEN_LENGTH)) && !QD_GZ_VAVLE)
  1053. {
  1054. QD_GZ_VAVLE = 1;
  1055. }
  1056. if(QD_GOUZHEN_IN)
  1057. {
  1058. QD_YD_VAVLE = 1;
  1059. QD_MotorDelay = dwTickCount + 5;
  1060. QD_MotorStep = 105;
  1061. }
  1062. else if(((cRealPos - save_buff) >= (QD_PARAM_ERROR_LENGTH + QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH)) && QD_GZ_VAVLE)
  1063. {
  1064. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1065. }
  1066. }
  1067. break;
  1068. case 104:
  1069. if(cZipCnt < 2)
  1070. {
  1071. if(QD_GOUZHEN_IN)
  1072. {
  1073. AxisEgmStop(X_AXIS);
  1074. QD_YD_VAVLE = 1;
  1075. QD_MotorStep = 105;
  1076. }
  1077. }
  1078. else
  1079. {
  1080. }
  1081. break;
  1082. case 105:
  1083. if(!X_DRV)
  1084. {
  1085. if(cZipCnt == 0)
  1086. {
  1087. go_length_buff = cRealPos - back_buff;
  1088. }
  1089. else if(cZipCnt == 1)
  1090. {
  1091. length_buff = cRealPos - back_buff;
  1092. SetData32bits(1,length_buff);
  1093. }
  1094. AxisMovePos(X_AXIS,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  1095. QD_MotorStep = 0;
  1096. }
  1097. break;
  1098. case 40:
  1099. if(dwTickCount >= QD_MotorDelay)
  1100. {
  1101. jz_buff = cRealPos;
  1102. if(QD_PARAM_SJZ_LENGTH == 0)
  1103. {
  1104. QD_JD_VAVEL = 0;
  1105. }
  1106. QD_MotorDelay = dwTickCount + 35;
  1107. QD_MotorStep = 41;
  1108. }
  1109. break;
  1110. case 41: if((dwTickCount >= QD_MotorDelay) || (QD_JD_VAVEL == 1))
  1111. {
  1112. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH));
  1113. QD_MotorStep = 42;
  1114. }
  1115. break;
  1116. case 42:
  1117. if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - jz_buff)))
  1118. {
  1119. QD_JD_VAVEL = 0;
  1120. QD_MotorStep = 43;
  1121. }
  1122. else if(!X_DRV)
  1123. {
  1124. QD_JD_VAVEL = 0;
  1125. QD_MotorStep = 43;
  1126. }
  1127. break;
  1128. case 43: // 切断完成后拉电机动作
  1129. if(!X_DRV)
  1130. {
  1131. QD_MotorStep = 0;
  1132. QD_MotorDelay = dwTickCount;
  1133. }
  1134. break;
  1135. case 61: // 前点定位数控模式
  1136. if(QD_SZ_OUT)
  1137. {
  1138. QD_SZ_OUT = 0;
  1139. QD_MotorDelay = dwTickCount + 50;
  1140. }
  1141. if(!QD_TL_VAVLE)
  1142. {
  1143. if(!QD_SHANG_MU_LIMIT_IN && (QD_TuiLianStep == 0))
  1144. {
  1145. QD_TuiLianStep = 1;
  1146. QD_MotorStep = 62;
  1147. }
  1148. }
  1149. else
  1150. QD_MotorStep = 62;
  1151. break;
  1152. case 62:
  1153. if(dwTickCount >= QD_MotorDelay)
  1154. {
  1155. if(QD_QIAN_LIMIT_IN || QD_QIAN_DEC_IN)
  1156. {
  1157. AxisMovePos(X_AXIS,QD_PARAM_CHECK_BACK_HSPEED,-QD_PARAM_ON_BACK_LENGTH);
  1158. QD_MotorDelay = dwTickCount + 1000;
  1159. }
  1160. QD_MotorStep = 63;
  1161. QD_JD_VAVEL = 0;
  1162. }
  1163. break;
  1164. case 63:
  1165. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay) && !QD_SHANG_MU_LIMIT_IN)
  1166. {
  1167. go_buff = cRealPos;
  1168. if(cZipCnt > 0)
  1169. {
  1170. MoveAction_Const_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);//
  1171. }
  1172. else
  1173. {
  1174. MoveAction_Const_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_FIRST_GO_HIGHSPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);//
  1175. }
  1176. length_buffer = &QD_PARAM_OFFSET_LENGTH;
  1177. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1178. QD_MotorStep =64;
  1179. }
  1180. break;
  1181. case 64:
  1182. if(QD_PARAM_LENGTH_MODE == 0)
  1183. {
  1184. if(((go_buff - cRealPos) > ((go_length_buff - (*length_buffer) - QD_PARAM_FZ_LENGTH) - (QD_PARAM_GO_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_GO_HIGH_SPEED,QD_PARAM_GO_LOW_SPEED,QD_PARAM_DCC))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) || QD_QIAN_DEC_IN_UP)
  1185. {
  1186. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1187. QD_MotorStep =65;
  1188. }
  1189. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1190. }
  1191. else
  1192. {
  1193. if(((go_buff - cRealPos) > ((QD_PARAM_ZIPPER_LENGTH - (*length_buffer) - QD_PARAM_FZ_LENGTH) - (QD_PARAM_GO_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_GO_HIGH_SPEED,QD_PARAM_GO_LOW_SPEED,QD_PARAM_DCC))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) || QD_QIAN_DEC_IN_UP)
  1194. {
  1195. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1196. QD_MotorStep =65;
  1197. }
  1198. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1199. }
  1200. break;
  1201. case 65:
  1202. if(QD_QIAN_LIMIT_IN_UP)
  1203. {
  1204. AxisEgmStop(X_AXIS);
  1205. QD_MotorStep = 66;
  1206. }
  1207. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1208. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1209. break;
  1210. case 66:
  1211. if(!X_DRV)
  1212. {
  1213. QD_MotorDelay = dwTickCount;
  1214. QD_MotorStep = 67;
  1215. }
  1216. break;
  1217. case 67:
  1218. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1219. {
  1220. if(bRunning)
  1221. {
  1222. QD_JD_VAVEL = 1;
  1223. }
  1224. QD_MotorStep = 68;
  1225. }
  1226. break;
  1227. case 68:
  1228. if(dwTickCount >= QD_MotorDelay)
  1229. {
  1230. QD_YD_VAVLE = 0;
  1231. QD_TL_VAVLE = 0;
  1232. if(QD_PARAM_BL_ENABLE)QD_BL_VAVLE = 0;
  1233. QD_MotorStep = 0;
  1234. QD_MotorDelay = dwTickCount;
  1235. }
  1236. break;
  1237. }
  1238. }
  1239. //电机动作
  1240. void QueDuan_Motor(void) //
  1241. {
  1242. switch(QD_MACHINE_TYPE)
  1243. {
  1244. case QD_NO_CS_TUIFANGKUAI: QueDuan_Motor_CS();break;
  1245. case QD_NO_GL_TUIFANGKUAI:QueDuan_Motor_NoGL();break;
  1246. default:;
  1247. }
  1248. }
  1249. //超声方式下切
  1250. void QueDuan_XiaQue_CS(void)
  1251. {
  1252. switch(QD_XiaQieStep)
  1253. {
  1254. case 0:
  1255. break;
  1256. case 1:
  1257. if(bRunning)
  1258. {
  1259. QD_XiaQieStep = 6;
  1260. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1261. }
  1262. else
  1263. QD_XiaQieStep = 2;
  1264. break;
  1265. case 2:
  1266. QD_XM_VAVLE = 1;
  1267. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1268. QD_XiaQieStep = 3;
  1269. break;
  1270. case 3:
  1271. if(QD_XIA_MU_LIMIT_IN)
  1272. {
  1273. QD_XiaQieDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1274. QD_XiaQieStep = 4;
  1275. }
  1276. else if(dwTickCount >= QD_XiaQieDelay)
  1277. {
  1278. QD_SetAlarmCode(QD_XM_DAOWEI);
  1279. }
  1280. break;
  1281. case 4:
  1282. QD_GZ_VAVLE = 1;
  1283. QD_XiaQieDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  1284. QD_XiaQieStep = 5;
  1285. break;
  1286. case 5:
  1287. QD_TFK_VAVEL = 1;
  1288. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1289. QD_XiaQieStep = 6;
  1290. break;
  1291. case 6:
  1292. if(QD_XIA_MU_LIMIT_IN)
  1293. {
  1294. QD_XiaQieStep = 7;
  1295. QD_XiaQieDelay = dwTickCount + 2000;
  1296. }
  1297. else if(dwTickCount >= QD_XiaQieDelay)
  1298. {
  1299. QD_SetAlarmCode(QD_XM_DAOWEI);
  1300. }
  1301. break;
  1302. case 7:
  1303. if(QD_GOUZHEN_IN)
  1304. {
  1305. cTuiFangKuaiCnt = 0;
  1306. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1307. QD_XiaQieStep = 8;
  1308. }
  1309. else if((dwTickCount >= QD_XiaQieDelay))
  1310. {
  1311. if(cTuiFangKuaiCnt == 0)
  1312. {
  1313. QD_TFK_VAVEL = 0;
  1314. cTuiFangKuaiCnt++;
  1315. QD_XiaQieDelay = dwTickCount + 1000;
  1316. QD_XiaQieStep = 100;
  1317. }
  1318. else
  1319. QD_SetAlarmCode(QD_GZ_ALARM);
  1320. }
  1321. break;
  1322. case 100:
  1323. if((dwTickCount >= QD_XiaQieDelay))
  1324. {
  1325. QD_XiaQieStep = 5;
  1326. }
  1327. break;
  1328. case 8:
  1329. if(dwTickCount >= QD_XiaQieDelay)
  1330. {
  1331. QD_SM_VAVLE = 1;
  1332. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1333. QD_XiaQieStep = 9;
  1334. }
  1335. break;
  1336. case 9:
  1337. if(QD_SHANG_MU_LIMIT_IN && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1338. {
  1339. if(!QD_PARAM_CS_MODE)
  1340. {
  1341. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_COLD_TIME; // QD_PARAM_DELAYBACK_SM; //
  1342. QD_XiaQieStep = 12;
  1343. }
  1344. else
  1345. {
  1346. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAY_CS; //
  1347. QD_XiaQieStep = 10;
  1348. }
  1349. }
  1350. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  1351. break;
  1352. case 10:
  1353. if(dwTickCount >= QD_XiaQieDelay)
  1354. {
  1355. if(QD_PARAM_CS_ENABLE)QD_CS_OUT = 1;
  1356. QD_YD_VAVLE = 1;
  1357. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_TIME; //
  1358. QD_XiaQieStep = 11;
  1359. }
  1360. break;
  1361. case 11:
  1362. if(dwTickCount >= QD_XiaQieDelay)
  1363. {
  1364. QD_CS_OUT = 0;
  1365. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_COLD_TIME; //
  1366. QD_XiaQieStep = 12;
  1367. }
  1368. break;
  1369. case 12:
  1370. if(dwTickCount >= QD_XiaQieDelay)
  1371. {
  1372. QD_SM_VAVLE = 0;
  1373. QD_XM_VAVLE = 0;
  1374. QD_TFK_VAVEL = 0;
  1375. QD_GZ_VAVLE = 0;
  1376. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1377. QD_XiaQieStep = 13;
  1378. }//
  1379. break;
  1380. case 13:
  1381. if(QD_SHANG_MU_ORIGIN_IN && !QD_XIA_MU_LIMIT_IN)
  1382. {
  1383. QD_XiaQieStep = 0;
  1384. QD_XiaQieDelay = dwTickCount;
  1385. }
  1386. else if(dwTickCount >= QD_XiaQieDelay)
  1387. {
  1388. QD_SetAlarmCode(QD_SM_YUANWEI);
  1389. }
  1390. break;
  1391. }
  1392. }
  1393. void QueDuan_TuiLianAction(void)
  1394. {
  1395. switch(QD_TuiLianStep)
  1396. {
  1397. case 1:
  1398. QD_TuiLianStep = 2;
  1399. break;
  1400. case 2:
  1401. QD_YBD_VAVLE = 1;
  1402. QD_TLDelay = dwTickCount + QD_PARAM_YD_DELAY;
  1403. QD_TuiLianStep = 3;
  1404. break;
  1405. case 3:
  1406. if(dwTickCount >= QD_TLDelay)
  1407. {
  1408. QD_TL_VAVLE = 1;
  1409. QD_BL_VAVLE = 1;
  1410. if(!bRunning)QD_TFK_VAVEL = 0;
  1411. QD_TLDelay = dwTickCount + QD_PARAM_TL_DELAY;
  1412. QD_TuiLianStep = 4;
  1413. }
  1414. break;
  1415. case 4:
  1416. if(dwTickCount >= QD_TLDelay)
  1417. {
  1418. QD_TuiLianStep = 0;
  1419. }
  1420. break;
  1421. case 10:
  1422. // if(bRunning)AxisMovePos(Y_AXIS,QD_PARAM_TL_SPEED,QD_PARAM_TL_LENGTH);
  1423. QD_TuiLianStep = 11;
  1424. break;
  1425. case 11:
  1426. if(!Y_DRV)
  1427. {
  1428. {
  1429. QD_TuiLianStep = 0;
  1430. }
  1431. }
  1432. break;
  1433. }
  1434. }
  1435. void QueDuan_XiaQue_NO_GL(void)
  1436. {
  1437. switch(QD_XiaQieStep)
  1438. {
  1439. case 0:
  1440. break;
  1441. case 1:
  1442. QD_YD_VAVLE = 1;
  1443. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1444. QD_XiaQieStep = 2;
  1445. break;
  1446. case 2:
  1447. if(dwTickCount >= QD_XiaQieDelay)
  1448. {
  1449. QD_XiaQieStep = 3;
  1450. }
  1451. break;
  1452. case 3:
  1453. if(dwTickCount >= QD_XiaQieDelay)
  1454. {
  1455. if((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0))
  1456. {
  1457. QD_SM_VAVLE = 1;
  1458. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1459. QD_XiaQieStep = 4;
  1460. }
  1461. }
  1462. break;
  1463. case 4:
  1464. if(QD_SHANG_MU_LIMIT_IN)
  1465. {
  1466. QD_XiaQieStep = 5;
  1467. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAYBACK_SM; //
  1468. }
  1469. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  1470. break;
  1471. case 5:
  1472. if(dwTickCount >= QD_XiaQieDelay)
  1473. {
  1474. QD_GZ_VAVLE = 0;
  1475. QD_SM_VAVLE = 0;
  1476. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1477. QD_XiaQieStep = 6;
  1478. }
  1479. break;
  1480. case 6:
  1481. if(QD_SHANG_MU_ORIGIN_IN && !QD_SHANG_MU_LIMIT_IN)
  1482. {
  1483. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  1484. if(!bRunning)QD_JD_VAVEL = 0;
  1485. QD_XiaQieStep = 0;
  1486. }
  1487. else if(dwTickCount >= QD_XiaQieDelay)
  1488. {
  1489. QD_SetAlarmCode(QD_SM_YUANWEI);
  1490. }
  1491. break;
  1492. }
  1493. }
  1494. //切断动作
  1495. void QueDuan_XiaQue(void)
  1496. {
  1497. switch(QD_MACHINE_TYPE)
  1498. {
  1499. case QD_NO_CS_TUIFANGKUAI:QueDuan_XiaQue_CS();break;
  1500. case QD_NO_GL_TUIFANGKUAI:QueDuan_XiaQue_NO_GL();break;
  1501. default:;
  1502. }
  1503. }
  1504. #endif