YXQueDuanJi.c 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211
  1. #include "global.h"
  2. #if FJ_YING_XING_MACHINE ==1
  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. void QD_TuiDaiAction(void);
  14. static unsigned long cZipCnt = 0,cTableCnt = 0,cTuiFangKuaiCnt = 0;
  15. static long save_limit_pos,cRealPos;
  16. static long dwSaveLength;
  17. unsigned char cCheckLianFlg = 0;
  18. unsigned char cCheckLianFlgEN = 0;
  19. unsigned char cGoLimitEn = 0;
  20. short *length_buffer;
  21. void QueDuan_ExtiActionX31(void)
  22. {
  23. cCheckLianFlg = 1;
  24. }
  25. void QD_SetAlarmCode(unsigned alarm_code)
  26. {
  27. SetAlarmCode(QD_ALARM_ADDR,alarm_code);
  28. bAlarmStop = 1;
  29. }
  30. void QueDuan_InitAction(void)
  31. {
  32. float length_buff,pulse_buff;
  33. length_buff = QD_PARAM_CYCLE_LENGTH;
  34. pulse_buff = QD_PARAM_CYCLE_PULSE;
  35. XGearRatio = pulse_buff/length_buff;
  36. QD_SZ_OUT = 1;
  37. }
  38. void QueDuan_Action(void)
  39. {
  40. InputPinConfig();
  41. QueDuan_AlarmProtect();
  42. QueDuan_Motor();
  43. QueDuan_XiaQue();
  44. QueDuan_ManualAction();
  45. QueDuan_TuiLianAction();
  46. QueDuan_BingLian();
  47. QueDuan_AutoAction();
  48. QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
  49. OutputPinConfig();
  50. }
  51. //手动动作
  52. void QueDuan_ManualAction(void)
  53. {
  54. if(bRunning == 0)
  55. {
  56. cGoLimitEn = 0;
  57. if(QD_bClearTotal) //切断计数清零
  58. {
  59. QD_bClearTotal = 0;
  60. ClrcToTal(QD_TOTAL_ADDR);
  61. }
  62. if(QD_bClearNowTotal)
  63. {
  64. QD_bClearNowTotal = 0;
  65. QD_PARAM_NOW_CNT = 0;
  66. }
  67. if(QD_bXiaQie)
  68. {
  69. QD_bXiaQie = 0;
  70. if((QD_XiaQieStep == 0) && !QD_TL_VAVLE)
  71. {
  72. QD_XiaQieStep = 1;
  73. }
  74. }
  75. if(QD_bQianDianDW)
  76. {
  77. QD_bQianDianDW = 0;
  78. if(QD_MotorStep == 0)
  79. {
  80. QD_MotorStep = 61;
  81. cZipCnt = 0;
  82. }
  83. }
  84. if(QD_bTL)
  85. {
  86. QD_bTL = 0;
  87. if(QD_TL_VAVLE)
  88. {
  89. QD_TL_VAVLE = 0;
  90. }
  91. else if(!QD_GZ_VAVLE && !QD_SM_VAVLE)
  92. {
  93. QD_TL_VAVLE = ~QD_TL_VAVLE;
  94. }
  95. }
  96. // if(!Y_DRV)QD_bTL = 0;
  97. if(QD_bYD)
  98. {
  99. QD_bYD = 0;
  100. QD_YD_VAVLE = ~QD_YD_VAVLE;
  101. }
  102. if(QD_bGZ)
  103. {
  104. QD_bGZ = 0;
  105. QD_GZ_VAVLE = ~QD_GZ_VAVLE;
  106. }
  107. if(QD_bJD)
  108. {
  109. QD_bJD = 0;
  110. QD_JD_VAVLE = ~QD_JD_VAVLE;
  111. }
  112. if(QD_bXM)
  113. {
  114. QD_bXM = 0;
  115. QD_XM_VAVLE = ~QD_XM_VAVLE;
  116. if(!QD_XM_VAVLE)QD_GZ_VAVLE = 0;
  117. }
  118. if(QD_bSM)
  119. {
  120. QD_bSM = 0;
  121. if(QD_SM_VAVLE)
  122. QD_SM_VAVLE = 0;
  123. else if(!QD_TL_VAVLE)
  124. QD_SM_VAVLE = 1;
  125. }
  126. //推方块
  127. if(QD_bTFK)
  128. {
  129. QD_bTFK = 0;
  130. QD_TFK_VAVLE = ~QD_TFK_VAVLE;
  131. }
  132. //台面电机
  133. if(QD_bTB)
  134. {
  135. QD_bTB = 0;
  136. QD_TABLE_VAVLE = ~QD_TABLE_VAVLE;
  137. }
  138. // if(QD_bYBD)
  139. // / {
  140. // QD_bYBD = 0;
  141. // QD_YBD_VAVLE = ~QD_YBD_VAVLE;
  142. // }
  143. if(QD_bTestCS)
  144. {
  145. QD_bTestCS = 0;
  146. QD_CS_OUT = 1;
  147. QD_CSDelay = dwTickCount + QD_PARAM_CS_TIME;
  148. }
  149. if(QD_bBL)//合链
  150. {
  151. QD_bBL = 0;
  152. QD_BL_VAVLE = ~QD_BL_VAVLE;
  153. }
  154. if(QD_bHL) //护链,双开用
  155. {
  156. QD_bHL = 0;
  157. QD_HL_VAVLE = ~QD_HL_VAVLE;
  158. }
  159. if(QD_bYX)
  160. {
  161. QD_bYX = 0;
  162. QD_YX_VAVLE = ~QD_YX_VAVLE;
  163. }
  164. if(QD_XiaQieStep == 0)
  165. {
  166. if(dwTickCount >= QD_CSDelay)QD_CS_OUT = 0;
  167. }
  168. //电机控制
  169. if(QD_bGoMotor && !QD_QIAN_LIMIT_IN)
  170. {
  171. QD_SZ_OUT = 0;
  172. // QD_JZ_DIR = QD_YDIR_N;
  173. if(!X_DRV)
  174. // X轴 运行速度 启动速度 加速度 减速度
  175. AxisContinueMoveAcc(X_AXIS,QD_PARAM_GO_LOW_SPEED/3,QD_DIR_N,QD_PARAM_GO_LOW_SPEED/3,15,15);
  176. }
  177. if(QD_bBackMotor) //后退限位已经取消
  178. {
  179. QD_SZ_OUT = 0;
  180. // QD_JZ_DIR = QD_YDIR_P;
  181. if(!X_DRV)
  182. // X轴 运行速度 启动速度 加速度 减速度
  183. AxisContinueMoveAcc(X_AXIS,QD_PARAM_GO_LOW_SPEED/3,QD_DIR_P,QD_PARAM_GO_LOW_SPEED/3,15,15);
  184. }
  185. if(!QD_bGoMotor && !QD_bBackMotor && (QD_MotorStep == 0))
  186. {
  187. if(X_DRV)AxisDecStop(X_AXIS);
  188. }
  189. if(QD_QIAN_LIMIT_IN && (QD_MotorStep == 0) && !QD_bBackMotor &&(QD_AutoStep == 0))
  190. {
  191. if(X_DRV)AxisEgmStop(X_AXIS);
  192. }
  193. }
  194. }
  195. void QueDuan_AlarmProtect(void)
  196. {
  197. cRealPos = GetPos(X_AXIS);
  198. if(!bRunning)
  199. {
  200. ;
  201. //
  202. #if 0
  203. if(QD_BACK_LIMIT_IN_UP)
  204. {
  205. if((QD_MotorStep == 0) && X_DRV && QD_bBackMotor) //到后限不能再后退但可以点前进
  206. {
  207. QD_bBackMotor = 0;
  208. AxisDecStop(X_AXIS);
  209. QD_JD_VAVLE = 0;
  210. QD_SetAlarmCode(QD_BACK_ALARM);
  211. }
  212. }
  213. #endif
  214. }
  215. else
  216. {
  217. if((cRealPos > QD_PARAM_RUN_LENGTH) && (QD_PARAM_RUN_LENGTH > 3000)
  218. && (cGoLimitEn != 0))
  219. {
  220. AxisEgmStop(X_AXIS);
  221. QD_JD_VAVLE = 0;
  222. QD_SetAlarmCode(QD_BACK_ALARM);
  223. }
  224. }
  225. }
  226. void QueDuan_AutoAction(void)
  227. {
  228. //台面电机定时关掉
  229. if(bRunning)
  230. {
  231. if(dwTickCount >= QD_TBDelay)
  232. QD_TABLE_VAVLE = 0;
  233. switch(QD_AutoStep)
  234. {
  235. case 1:
  236. if(dwTickCount >= QD_AutoDelay)
  237. {
  238. QD_AutoStep = 2;
  239. if(QD_MotorStep == 0)
  240. {
  241. QD_MotorStep = 61; //前点定位
  242. }
  243. cGoLimitEn = 0;
  244. }
  245. break;
  246. case 2:
  247. if(QD_MotorStep == 0)
  248. {
  249. QD_MotorStep = 30;
  250. QD_AutoStep = 3;
  251. cGoLimitEn = 1;
  252. }
  253. break;
  254. case 3:
  255. if(QD_MotorStep == 0)
  256. {
  257. if(QD_SAFE_IN)
  258. {
  259. bStop = 1;
  260. }
  261. else
  262. {
  263. if(QD_XiaQieStep == 0)
  264. QD_XiaQieStep = 1;
  265. QD_AutoStep = 4;
  266. }
  267. }
  268. break;
  269. case 4:
  270. // 闭口
  271. if((QD_XiaQieStep == 0) || ((QD_XiaQieStep == 6) && QD_KB_MODE)|| ((QD_XiaQieStep == 13) && (QD_KB_MODE == 0)))// && !QD_SHANG_MU_LIMIT_IN)
  272. {
  273. if(QD_MotorStep == 0)
  274. {
  275. cGoLimitEn=0;
  276. QD_MotorStep = 40; //切完后退
  277. }
  278. QD_AutoStep = 5;
  279. }
  280. break;
  281. case 5:
  282. if(QD_MotorStep == 0)
  283. {
  284. cZipCnt++;
  285. QD_PARAM_NOW_CNT++;
  286. cTableCnt++;
  287. AddToTal(QD_TOTAL_ADDR);
  288. AddToTal(CT_WORKTOTAL_ADDR);
  289. CalProSP(QD_PROSPEED_ADDR);
  290. if(cTableCnt >= QD_PARAM_TABLE_NUM)
  291. {
  292. cTableCnt = 0;
  293. QD_TABLE_VAVLE = 1;
  294. QD_TBDelay = dwTickCount + QD_PARAM_TB_TIME;
  295. }
  296. if( SingOneFlg)
  297. {
  298. {
  299. bRunning = 0;
  300. QD_AutoStep = 0;
  301. SingOneFlg = 0;
  302. }
  303. // if(GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) QD_SetAlarmCode(QD_TOTAL_ALARM);
  304. }
  305. else
  306. {
  307. QD_AutoStep = 1;
  308. if((QD_PARAM_NOW_CNT >= QD_PARAM_ZHA_SHU) && (QD_PARAM_ZHA_SHU > 0))
  309. {
  310. QD_AutoDelay = dwTickCount + QD_PARAM_ZS_STOP_TIME;
  311. QD_PARAM_NOW_CNT = 0;
  312. if(QD_PARAM_ZS_STOP_TIME == 0)
  313. {
  314. bRunning = 0;
  315. QD_AutoStep = 0;
  316. SingOneFlg = 0;
  317. QD_SetAlarmCode(QD_TOTAL_ALARM);
  318. }
  319. }
  320. else
  321. QD_AutoDelay = dwTickCount + QD_PARAM_CYCLE_DELAY;
  322. }
  323. }
  324. break;
  325. }
  326. }
  327. }
  328. void QueDuan_StepCheckStart(void)
  329. {
  330. // 启动
  331. if((START_IN_UP) || bStart || QD_bSingle)
  332. {
  333. bStart = 0;
  334. if(!bRunning && (QD_AutoStep == 0))
  335. {
  336. if(QD_XIA_MU_LIMIT_IN && !QD_PARAM_XM_ENABLE)QD_SetAlarmCode(QD_XM_DAOWEI);
  337. // else if(GetAlarmCode(QD_ALARM_ADDR) != 0);
  338. //else if(GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) QD_SetAlarmCode(QD_TOTAL_ALARM);
  339. // else if(QD_BL_VAVLE)QD_SetAlarmCode(QD_BL_ALARM);
  340. else if(QD_SM_VAVLE)QD_SetAlarmCode(QD_SM_ALARM);
  341. else
  342. {
  343. bRunning = 1;
  344. QD_AutoStep = 1;
  345. if(QD_bSingle)
  346. SingOneFlg= 1;
  347. cZipCnt = 0;
  348. cTuiFangKuaiCnt = 0;
  349. QD_BL_VAVLE = 0; //并链关
  350. QD_DGLG_VAVLE = 0; //顶过链杆关
  351. SetAlarmCode(QD_ALARM_ADDR,0);
  352. }
  353. }
  354. QD_bSingle = 0;
  355. }
  356. //停止
  357. if(STOP_IN_UP || bStop)
  358. {
  359. bStop = 0;
  360. if(bRunning)
  361. {
  362. QD_AutoDelay = dwTickCount;
  363. QD_MotorDelay = dwTickCount;
  364. QD_XiaQieDelay = dwTickCount;
  365. QD_KaDaiDelay = dwTickCount;
  366. QD_CSDelay = dwTickCount;
  367. QD_TBDelay = dwTickCount;
  368. QD_TFKDelay = dwTickCount;
  369. QD_TLDelay = dwTickCount;
  370. dwTickCount = QD_TBDelay;
  371. SingOneFlg = 0;
  372. QD_JD_VAVLE = 0;
  373. QD_SM_VAVLE = 0;
  374. QD_XM_VAVLE = 0;
  375. QD_YD_VAVLE = 0;
  376. QD_TFK_VAVLE= 0;
  377. QD_TL_VAVLE = 0;
  378. QD_HL_VAVLE = 0;
  379. QD_CS_OUT = 0;
  380. QD_XiaQieStep = 0;
  381. QD_MotorStep = 0;
  382. QD_TuiLianStep = 0;
  383. //QD_SZ_OUT = 1;
  384. QD_GZ_VAVLE = 0;
  385. QD_TABLE_VAVLE = 0;
  386. QD_DGLG_VAVLE = 0; //顶过链杆关
  387. AxisDecStop(X_AXIS);
  388. QD_BinLianStep = 0;
  389. QD_BL_VAVLE = 0;
  390. user_datas[121] = 0;
  391. user_datas[122] = 0;
  392. SetAlarmCode(QD_ALARM_ADDR,0);
  393. }
  394. else
  395. {
  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. dwTickCount = QD_TBDelay;
  405. SingOneFlg = 0;
  406. QD_JD_VAVLE = 0;
  407. QD_SM_VAVLE = 0;
  408. QD_XM_VAVLE = 0;
  409. QD_YD_VAVLE = 0;
  410. QD_TFK_VAVLE= 0;
  411. QD_YX_VAVLE = 0;
  412. QD_HL_VAVLE = 0;
  413. QD_TL_VAVLE = 0;
  414. QD_DGLG_VAVLE = 0; //顶过链杆关
  415. QD_CS_OUT = 0;
  416. QD_XiaQieStep = 0;
  417. QD_MotorStep = 0;
  418. QD_TuiLianStep = 0;
  419. QD_SZ_OUT = 1;
  420. QD_GZ_VAVLE = 0;
  421. QD_TABLE_VAVLE = 0;
  422. AxisDecStop(X_AXIS);
  423. QD_BinLianStep = 0;
  424. QD_BL_VAVLE = 0;
  425. SetAlarmCode(QD_ALARM_ADDR,0);
  426. }
  427. bRunning = 0;
  428. QD_XiaQieStep = 0;
  429. QD_AutoStep = 0;
  430. QD_MotorStep = 0;
  431. QD_TuiLianStep = 0;
  432. }
  433. if(bAlarmStop)
  434. {
  435. bAlarmStop = 0;
  436. QD_XiaQieStep = 0;
  437. QD_AutoStep = 0;
  438. QD_MotorStep = 0;
  439. QD_TuiLianStep = 0;
  440. QD_XiaQieStep = 0;
  441. QD_MotorStep = 0;
  442. QD_TuiLianStep = 0;
  443. QD_AutoDelay = dwTickCount;
  444. QD_MotorDelay = dwTickCount;
  445. QD_XiaQieDelay = dwTickCount;
  446. QD_KaDaiDelay = dwTickCount;
  447. QD_CSDelay = dwTickCount;
  448. QD_TBDelay = dwTickCount;
  449. QD_TFKDelay = dwTickCount;
  450. QD_TLDelay = dwTickCount;
  451. SingOneFlg = 0;
  452. bRunning = 0;
  453. AxisDecStop(X_AXIS);
  454. dwTickCount = QD_TBDelay;
  455. QD_TABLE_VAVLE = 0;
  456. QD_JD_VAVLE=0;
  457. QD_GZ_VAVLE=0;
  458. }
  459. }
  460. //记忆长度模式误差检测
  461. void QueDuan_CheckLength(long zip_length)
  462. {
  463. static long start_dist;
  464. switch(QD_CheckLengthStep)
  465. {
  466. case 0:break;
  467. case 1:
  468. start_dist = cRealPos;
  469. dwSaveLength = 0;
  470. QD_CheckLengthStep = 2;
  471. break;
  472. case 2:
  473. if(QD_GUO_LIAN_IN_DW){
  474. dwSaveLength = cRealPos - start_dist;
  475. // user_datas[127] = cRealPos;
  476. }
  477. break;
  478. }
  479. }
  480. #if !QD_KB_MODE //开口
  481. //开口切专用
  482. //30步开始后拉开始,分解4种工作模式
  483. //40步开始用切断后拉动作
  484. //60步开始为前方向,开闭口一样
  485. void QueDuan_Motor_KK(void)
  486. {
  487. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  488. unsigned short ch;
  489. user_datas[121]= QD_MotorStep;
  490. user_datas[122]= length_buff;
  491. user_datas[123] = cRealPos;
  492. user_datas[124] = GetCurSpeed(X_AXIS);
  493. user_datas[125] = QD_AutoStep;
  494. user_datas[126] = QD_XiaQieStep;
  495. // user_datas[127] = QD_XiaQieStep;
  496. QueDuan_CheckLength(length_buff);
  497. switch(QD_MotorStep)
  498. {
  499. case 30:
  500. switch(QD_PARAM_BACK_MODE) //开口分四种模式
  501. {
  502. case 0: //单数控模式
  503. QD_MotorStep = 310; //每种模式留20步
  504. QD_DGLG_VAVLE = 1; //顶过链杆关
  505. break;
  506. case 1://单感应模式
  507. QD_MotorStep = 330; //每种模式留20步
  508. break;
  509. case 2: //先感应后数控模式+检测
  510. QD_MotorStep = 350; //每种模式留20步
  511. break;
  512. default: //数控模式+过链检测长度
  513. QD_MotorStep = 370; //每种模式留20步
  514. break;
  515. }
  516. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  517. break;
  518. //310步到315步为数控模式
  519. case 310:
  520. QD_MotorStep = 311;
  521. SetDir(X_AXIS, QD_DIR_P);
  522. if(QD_PARAM_BL_ENABLE)
  523. QD_BinLianStep = 1; //并链起动
  524. break;
  525. case 311:
  526. if(dwTickCount >= QD_MotorDelay)
  527. {
  528. length_buffer = &QD_PARAM_OFFSET_LENGTH;
  529. //李永庆代码
  530. //两段速度移动距离 拉链长度+慢速长度停止
  531. // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
  532. AxisMoveTwoPos(X_AXIS,QD_PARAM_BACK_SPEED,QD_PARAM_ZIPPER_LENGTH + (*length_buffer)-QD_PARAM_BACK_LOW_SPEED_LENGTH,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_BACK_LOW_SPEED_LENGTH,QD_DIR_P);
  533. back_buff = cRealPos;
  534. gou_zhen_buff = cRealPos;
  535. save_buff = cRealPos;
  536. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  537. QD_MotorStep = 312;
  538. }
  539. break;
  540. case 312:
  541. //勾针提前输出 ,争取时间推方块
  542. if (!QD_GZ_VAVLE && (cRealPos >= (QD_PARAM_ZIPPER_LENGTH- 230)))
  543. QD_GZ_VAVLE = 1;
  544. if((cRealPos) > (QD_PARAM_ZIPPER_LENGTH + (*length_buffer)-QD_PARAM_BACK_LOW_SPEED_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)))))
  545. {
  546. QD_MotorStep = 313;
  547. }
  548. else if(cRealPos >= (QD_PARAM_ZIPPER_LENGTH + (*length_buffer) + QD_PARAM_ERROR_LENGTH))
  549. {
  550. QD_SetAlarmCode(QD_GZ_ALARM);
  551. }
  552. break;
  553. case 313:
  554. if(!QD_GZ_VAVLE && ((cRealPos) > (QD_PARAM_ZIPPER_LENGTH - 230)))
  555. QD_GZ_VAVLE = 1;
  556. if(!X_DRV)
  557. {
  558. AxisEgmStop(X_AXIS);
  559. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  560. QD_MotorStep = 314;
  561. QD_BL_VAVLE = 0; //停止时并链一定要打开
  562. if((QD_PARAM_BACK_MODE == 2) && !QD_DGLG_VAVLE) //模式2,先检测长度后数控
  563. {//对比长度 ,发须要有过链信号,模式2,3. 模式0,1不用在这里经
  564. if(cZipCnt > 1) //长度检测
  565. {
  566. if(QD_PARAM_ERROR_LENGTH != 0) //长度误差值不能为0
  567. {
  568. if(((dwSaveLength + QD_PARAM_MOTOR_DELAY_LENGTH) > (length_buff + QD_PARAM_ERROR_LENGTH)) || (dwSaveLength == 0))
  569. {
  570. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);//拉链变长,对比警告
  571. }
  572. else if((dwSaveLength + QD_PARAM_MOTOR_DELAY_LENGTH+ QD_PARAM_ERROR_LENGTH) < length_buff)
  573. {
  574. QD_SetAlarmCode(QD_LENGTH_SHORT_ALARM); ////拉链变短
  575. }
  576. QD_CheckLengthStep = 0;
  577. }
  578. }
  579. }
  580. }
  581. break;
  582. case 314:
  583. if(!X_DRV && (dwTickCount >= QD_MotorDelay)) //数控到停止
  584. {
  585. QD_MotorStep = 0;
  586. QD_TFK_VAVLE = 1; //推方块输出
  587. }
  588. break;
  589. //330步到349步单感应模式
  590. case 330:
  591. back_buff = cRealPos;
  592. gou_zhen_buff = cRealPos;
  593. SetDir(X_AXIS, QD_DIR_P);
  594. QD_MotorStep = 331;
  595. user_datas[127] = 0;
  596. break;
  597. case 331:
  598. if(dwTickCount >= QD_MotorDelay)
  599. {
  600. QD_MotorStep = 332;
  601. if(cZipCnt < 2)
  602. {
  603. if(QD_PARAM_BL_ENABLE)
  604. QD_BinLianStep = 10; //并链起动
  605. //第一条都是过链感应,后拉速度减半//原来QD_PARAM_CHECK_BACK_HSPEED/2
  606. // X轴 运行速度 启动速度 加速度 减速度
  607. AxisContinueMoveAcc(X_AXIS,9000,QD_DIR_P,QD_PARAM_START_SPEED,8,13);
  608. // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
  609. // AxisMoveTwoPos(X_AXIS,QD_PARAM_BACK_SPEED,QD_PARAM_ZIPPER_LENGTH + (*length_buffer)-QD_PARAM_BACK_LOW_SPEED_LENGTH,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_BACK_LOW_SPEED_LENGTH,QD_DIR_P);
  610. }
  611. else
  612. {
  613. if(QD_PARAM_BL_ENABLE)
  614. QD_BinLianStep = 1; //并链起动
  615. //因为每条都是过链感应,所以直接运行检测模式后拉速度
  616. // X轴 运行速度 启动速度 加速度 减速度
  617. AxisContinueMoveAcc(X_AXIS,QD_PARAM_CHECK_BACK_HSPEED,QD_DIR_P,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  618. }
  619. }
  620. break;
  621. case 332:
  622. if(cZipCnt > 1) //第二条开始数控降速
  623. {
  624. if((cRealPos + QD_PARAM_BACK_LOW_SPEED_LENGTH + 600)>= length_buff)
  625. {
  626. CancelPmoveState(X_AXIS); //长度模式去掉
  627. AxisChangeSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  628. user_datas[127] = cRealPos;
  629. QD_MotorStep = 334; //到检测定位
  630. }
  631. if(QD_GUO_LIAN_IN_DW) //重新到链上
  632. {
  633. CancelPmoveState(X_AXIS);
  634. AxisChangeSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  635. gou_zhen_buff = cRealPos;
  636. QD_MotorStep = 335; //到检测定位
  637. }
  638. //
  639. // if((cRealPos >= (QD_PARAM_BACK_LOW_SPEED_LENGTH + 60)) && QD_GUO_LIAN_IN)
  640. // {
  641. // }
  642. }
  643. else //第一条工作
  644. {
  645. if(QD_GUO_LIAN_IN_UP)
  646. {
  647. checkdelay_buff = cRealPos;
  648. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  649. QD_MotorDelay = dwTickCount + 0;//QD_PARAM_DELAY_XM;
  650. QD_MotorStep = 333;
  651. }
  652. else if((cRealPos >= QD_PARAM_RUN_LENGTH) && (QD_PARAM_RUN_LENGTH >= 5000)) //模组最长限制
  653. {
  654. // QD_SetAlarmCode(QD_PARAM_RUN_LENGTH_ALARM); //超出轨道运行长度
  655. }
  656. }
  657. break;
  658. case 333:
  659. if(dwTickCount >= QD_MotorDelay)
  660. {
  661. QD_MotorStep = 334;
  662. }
  663. break;
  664. case 334:
  665. if(QD_GUO_LIAN_IN_DW) //下降沿,定位长度
  666. {
  667. //滤波有待调试
  668. // 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)))
  669. // {
  670. if(QD_GUO_LIAN_IN_DW)
  671. {
  672. gou_zhen_buff = cRealPos;
  673. QD_MotorStep = 335;
  674. }
  675. // }
  676. }
  677. break;
  678. case 335:
  679. if(QD_GUO_LIAN_IN_DW)
  680. {
  681. gou_zhen_buff = cRealPos;
  682. }
  683. //在空们都把延时清零
  684. if(QD_GUO_LIAN_IN)
  685. {
  686. gou_zhen_buff = cRealPos;
  687. }
  688. //定位停止
  689. if(((cRealPos - gou_zhen_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH) && !QD_GUO_LIAN_IN)
  690. {
  691. AxisEgmStop(X_AXIS);
  692. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  693. QD_MotorStep = 336;
  694. QD_GZ_VAVLE = 1;
  695. }
  696. break;
  697. case 336:
  698. if(!X_DRV)
  699. {
  700. QD_GZ_VAVLE = 1;
  701. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  702. // QD_XM_VAVLE = 1;
  703. QD_MotorStep = 337;
  704. }
  705. break;
  706. case 337:
  707. if(1)
  708. {
  709. QD_MotorStep = 338;
  710. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  711. }
  712. // else if(dwTickCount >= QD_MotorDelay) QD_SetAlarmCode(QD_XM_DAOWEI);
  713. break;
  714. case 338:
  715. if((dwTickCount >= QD_MotorDelay))
  716. {
  717. QD_TFK_VAVLE = 1; //推方块输出
  718. QD_MotorStep = 339;
  719. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  720. }
  721. break;
  722. case 339:
  723. if(cZipCnt == 1)
  724. {
  725. length_buff = cRealPos - save_buff;
  726. SetData32bits(QD_PARAM_ZIPPER_LENGTH_ADDR,length_buff);
  727. }
  728. else if(cZipCnt > 1) //长度检测
  729. {
  730. if(QD_PARAM_ERROR_LENGTH != 0) //长度误差值不能为0
  731. {
  732. if(cRealPos >= length_buff) //拉链变长,对比警告
  733. {
  734. if((cRealPos - save_buff) > (length_buff+QD_PARAM_ERROR_LENGTH))
  735. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  736. }
  737. else //拉链变短
  738. {
  739. if((cRealPos - save_buff + QD_PARAM_ERROR_LENGTH) < (length_buff))
  740. QD_SetAlarmCode(QD_LENGTH_SHORT_ALARM);
  741. }
  742. }
  743. }
  744. QD_MotorStep = 0;
  745. break;
  746. //350步到369步单感应模式
  747. case 350:
  748. back_buff = cRealPos;
  749. gou_zhen_buff = cRealPos;
  750. SetDir(X_AXIS, QD_DIR_P);
  751. QD_MotorStep = 351;
  752. break;
  753. case 351:
  754. if(dwTickCount >= QD_MotorDelay)
  755. {
  756. QD_MotorStep = 352;
  757. //第一,二条都是过链感应,测量长度
  758. if(cZipCnt < 2)
  759. {
  760. if(QD_PARAM_BL_ENABLE) //因为长度未知,只能通过过链退合链
  761. QD_BinLianStep = 10; //并链起动
  762. QD_DGLG_VAVLE = 0; //顶过链杆关
  763. // X轴 运行速度 启动速度 加速度 减速度
  764. AxisContinueMoveAcc(X_AXIS,9000,QD_DIR_P,QD_PARAM_START_SPEED,8,12);
  765. }
  766. else
  767. {
  768. if(QD_PARAM_BL_ENABLE)
  769. QD_BinLianStep = 1; //并链起动
  770. QD_DGLG_VAVLE = 1; //顶过链杆关
  771. QD_CheckLengthStep = 1; //长度检测,第3条才有对比
  772. //走数控方式,因第二条中已经测量出来拉链长度,可以直接按长度数控方式走
  773. QD_MotorStep = 311;
  774. }
  775. }
  776. break;
  777. case 352:
  778. //前两条都按最低速度工作
  779. if(QD_GUO_LIAN_IN_UP)
  780. {
  781. checkdelay_buff = cRealPos;
  782. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  783. QD_MotorDelay = dwTickCount + 2;//因慢速,加8MS滤波
  784. QD_MotorStep = 353;
  785. }
  786. else if((cRealPos >= QD_PARAM_RUN_LENGTH) && (QD_PARAM_RUN_LENGTH >= 5000)) //模组最长限制
  787. {
  788. // QD_SetAlarmCode(QD_PARAM_RUN_LENGTH_ALARM); //超出轨道运行长度
  789. }
  790. break;
  791. case 353:
  792. if(dwTickCount >= QD_MotorDelay)
  793. {
  794. QD_MotorStep = 354;
  795. }
  796. break;
  797. case 354:
  798. if(QD_GUO_LIAN_IN_DW) //下降沿,定位长度
  799. {
  800. if(QD_GUO_LIAN_IN_DW)
  801. {
  802. gou_zhen_buff = cRealPos;
  803. QD_MotorStep = 355;
  804. }
  805. }
  806. break;
  807. case 355:
  808. if(QD_GUO_LIAN_IN_DW)
  809. {
  810. gou_zhen_buff = cRealPos;
  811. }
  812. //在空们都把延时清零
  813. if(QD_GUO_LIAN_IN)
  814. {
  815. gou_zhen_buff = cRealPos;
  816. }
  817. //定位停止
  818. if(((cRealPos - gou_zhen_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH) && !QD_GUO_LIAN_IN)
  819. {
  820. AxisEgmStop(X_AXIS);
  821. QD_MotorStep = 356;
  822. QD_GZ_VAVLE = 1;
  823. }
  824. break;
  825. case 356:
  826. if(!X_DRV)
  827. {
  828. QD_GZ_VAVLE = 1;
  829. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  830. // QD_XM_VAVLE = 1;
  831. QD_MotorStep = 357;
  832. }
  833. break;
  834. case 357:
  835. if(1)
  836. {
  837. QD_MotorStep = 358;
  838. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  839. }
  840. break;
  841. case 358:
  842. if((dwTickCount >= QD_MotorDelay))
  843. {
  844. QD_TFK_VAVLE = 1; //推方块输出
  845. QD_MotorStep = 359;
  846. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  847. }
  848. break;
  849. case 359:
  850. if(cZipCnt == 1)
  851. {
  852. length_buff = cRealPos - save_buff;
  853. //测量出来长度
  854. SetData32bits(QD_PARAM_ZIPPER_LENGTH_ADDR,length_buff);
  855. }
  856. QD_MotorStep = 0;
  857. break;
  858. //370步到389步为数控模式
  859. case 370:
  860. QD_MotorStep = 371;
  861. SetDir(X_AXIS, QD_DIR_P);
  862. if(QD_PARAM_BL_ENABLE)
  863. QD_BinLianStep = 1; //并链起动
  864. QD_CheckLengthStep = 1; //长度检测开始
  865. break;
  866. case 371:
  867. if(dwTickCount >= QD_MotorDelay)
  868. {
  869. back_buff = cRealPos;
  870. gou_zhen_buff = cRealPos;
  871. save_buff = cRealPos;
  872. //李永庆代码
  873. //两段速度移动距离 拉链长度+慢速长度停止
  874. // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
  875. AxisMoveTwoPos(X_AXIS,QD_PARAM_BACK_SPEED,QD_PARAM_ZIPPER_LENGTH-QD_PARAM_BACK_LOW_SPEED_LENGTH,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_BACK_LOW_SPEED_LENGTH,QD_DIR_P);
  876. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  877. QD_MotorStep = 372;
  878. }
  879. break;
  880. case 372:
  881. //勾针提前输出 ,争取时间推方块
  882. if (!QD_GZ_VAVLE && (cRealPos >= (QD_PARAM_ZIPPER_LENGTH - 230)))
  883. QD_GZ_VAVLE = 1;
  884. if((cRealPos) > (QD_PARAM_ZIPPER_LENGTH-QD_PARAM_BACK_LOW_SPEED_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)))))
  885. {
  886. QD_MotorStep = 373;
  887. }
  888. break;
  889. case 373:
  890. if(!QD_GZ_VAVLE && ((cRealPos) > (QD_PARAM_ZIPPER_LENGTH - 230)))
  891. QD_GZ_VAVLE = 1;
  892. if(!X_DRV)
  893. {
  894. AxisEgmStop(X_AXIS);
  895. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  896. QD_MotorStep = 374;
  897. QD_BL_VAVLE = 0; //停止时并链一定要打开
  898. //对比长度 ,发须要有过链信号,模式2,3. 模式0,1不用在这里经
  899. if(cZipCnt > 1) //长度检测
  900. {
  901. if((QD_PARAM_ERROR_LENGTH != 0) && length_buff) //长度误差值不能为0
  902. {
  903. if((dwSaveLength > (length_buff + QD_PARAM_ERROR_LENGTH)) || (dwSaveLength == 0))
  904. {
  905. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);//拉链变长,对比警告
  906. }
  907. //上升沿的长度
  908. else if((dwSaveLength + QD_PARAM_ERROR_LENGTH) < length_buff)
  909. {
  910. QD_SetAlarmCode(QD_LENGTH_SHORT_ALARM); ////拉链变短
  911. }
  912. QD_CheckLengthStep = 0;
  913. }
  914. }
  915. else if(cZipCnt == 1) //长度检测
  916. {
  917. if(dwSaveLength)
  918. length_buff = dwSaveLength;
  919. }
  920. }
  921. break;
  922. case 374:
  923. if(!X_DRV && (dwTickCount >= QD_MotorDelay)) //数控到停止
  924. {
  925. QD_MotorStep = 0;
  926. QD_TFK_VAVLE = 1; //推方块输出
  927. }
  928. break;
  929. //切完延时后拉带松夹子
  930. case 40:
  931. if(QD_PARAM_SJZ_LENGTH == 0)
  932. {
  933. QD_JD_VAVLE = 0;
  934. }
  935. QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  936. SetDir(X_AXIS, QD_DIR_P);
  937. QD_MotorStep = 41;
  938. break;
  939. case 41:
  940. if((dwTickCount >= QD_MotorDelay))
  941. {
  942. jz_buff = cRealPos;
  943. if(QD_JD_VAVLE)
  944. //两段速度移动距离
  945. { // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
  946. AxisMoveTwoPos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,QD_PARAM_SJZ_LENGTH,5000,QD_PARAM_BACK_LENGTH,QD_DIR_P);
  947. }
  948. else
  949. {//夹子已经张开
  950. SetDir(X_AXIS,QD_DIR_P);
  951. AxisMovePosAccDec(X_AXIS,QD_PARAM_CUT_BACK_SPEED,(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH),QD_PARAM_START_SPEED,10,10);
  952. } // AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH));
  953. QD_MotorStep = 42;
  954. }
  955. break;
  956. case 42:
  957. if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - jz_buff)))
  958. {
  959. QD_JD_VAVLE = 0;
  960. QD_MotorStep = 43;
  961. }
  962. if(!X_DRV)
  963. {
  964. QD_JD_VAVLE = 0;
  965. QD_MotorStep = 43;
  966. }
  967. break;
  968. case 43: // 切断完成后拉电机动作
  969. if(!X_DRV)
  970. {
  971. QD_MotorStep = 0;
  972. QD_MotorDelay = dwTickCount;
  973. }
  974. break;
  975. case 61: // 前点定位数控模式
  976. if(QD_SZ_OUT)
  977. {
  978. QD_SZ_OUT = 0;
  979. QD_MotorDelay = dwTickCount + 150;
  980. SetDir(X_AXIS, QD_DIR_N);
  981. SetPos(X_AXIS, 0);
  982. }
  983. else
  984. QD_MotorDelay = dwTickCount;
  985. QD_BL_VAVLE = 0;//并链也要打开
  986. // QD_JZ_DIR = QD_YDIR_N;
  987. if(!QD_TL_VAVLE && cZipCnt) //没送链情况下主动送链
  988. {
  989. if(!QD_SHANG_MU_LIMIT_IN && (QD_TuiLianStep == 0))
  990. {
  991. QD_TuiLianStep = 1;
  992. QD_MotorStep = 62;
  993. }
  994. }
  995. else
  996. QD_MotorStep = 62;
  997. break;
  998. case 62:
  999. if(dwTickCount >= QD_MotorDelay)
  1000. {
  1001. if(QD_QIAN_LIMIT_IN)
  1002. {
  1003. SetPos(X_AXIS, 0);//在前点,直接置零点
  1004. // QD_JZ_DIR = QD_YDIR_P;
  1005. //前点亮的情况下先退出
  1006. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,1000);
  1007. QD_MotorDelay = dwTickCount + 300;
  1008. }
  1009. QD_MotorStep = 63;
  1010. QD_JD_VAVLE = 0;
  1011. }
  1012. break;
  1013. case 63:
  1014. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))// && !QD_SHANG_MU_LIMIT_IN)
  1015. {
  1016. // QD_JZ_DIR = QD_YDIR_N;
  1017. SetDir(X_AXIS, QD_DIR_N);
  1018. go_buff = cRealPos;
  1019. QD_YD_VAVLE = 1;
  1020. QD_HL_VAVLE = 1;
  1021. QD_YX_VAVLE = 1;
  1022. //李永庆代码,当位置在慢速之外,走数控到慢速点
  1023. if(cZipCnt > 0)
  1024. {
  1025. if(cRealPos>(QD_PARAM_GO_LOW_SPEED_LENGTH))
  1026. {
  1027. AxisMoveThreePosNoStop(X_AXIS,QD_PARAM_GO_HIGH_SPEED,cRealPos -QD_PARAM_GO_LOW_SPEED_LENGTH-300,
  1028. QD_PARAM_GO_HIGH_SPEED*2/3,350,
  1029. QD_PARAM_GO_LOW_SPEED,QD_PARAM_GO_LOW_SPEED_LENGTH,QD_DIR_N) ;
  1030. }
  1031. else
  1032. {
  1033. // X轴 运行速度 启动速度 加速度 减速度
  1034. AxisContinueMoveAcc(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_DIR_N,QD_PARAM_GO_LOW_SPEED/3,15,15);
  1035. }
  1036. }
  1037. else
  1038. {
  1039. // X轴 运行速度 启动速度 加速度 减速度
  1040. AxisContinueMoveAcc(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_DIR_N,QD_PARAM_GO_LOW_SPEED/3,15,15);
  1041. }
  1042. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1043. QD_MotorStep =64;
  1044. }
  1045. break;
  1046. case 64:
  1047. if(cZipCnt > 1)
  1048. {
  1049. //李永庆代码
  1050. if(((cRealPos) < (QD_PARAM_GO_LOW_SPEED_LENGTH+1200)))// || (QD_QIAN_DEC_IN))
  1051. {
  1052. user_datas[126]= GetCurSpeed(X_AXIS);
  1053. // MoveChangSpeedDec(X_AXIS,QD_PARAM_GO_HIGH_SPEED*2/3,6,8);
  1054. // AxisChangeSpeed(X_AXIS,40);
  1055. QD_MotorStep =65;
  1056. }
  1057. if(QD_QIAN_LIMIT_IN) //前点限位
  1058. {
  1059. AxisEgmStop(X_AXIS);
  1060. QD_MotorStep = 66;
  1061. }
  1062. }
  1063. else
  1064. {
  1065. if(QD_QIAN_LIMIT_IN) //前点限位
  1066. {
  1067. AxisEgmStop(X_AXIS);
  1068. QD_MotorStep = 66;
  1069. }
  1070. }
  1071. break;
  1072. case 65:
  1073. if(QD_QIAN_LIMIT_IN)
  1074. {
  1075. AxisEgmStop(X_AXIS);
  1076. QD_MotorStep = 66;
  1077. }
  1078. else if(dwTickCount >= QD_MotorDelay)
  1079. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1080. break;
  1081. case 66:
  1082. if(!X_DRV)
  1083. {
  1084. SetPos(X_AXIS, 0);
  1085. QD_MotorDelay = dwTickCount;
  1086. QD_MotorStep = 67;
  1087. }
  1088. break;
  1089. case 67: //等推链完成后,
  1090. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1091. {
  1092. if(bRunning)
  1093. {
  1094. QD_JD_VAVLE = 1;
  1095. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1096. }
  1097. QD_MotorStep = 68;
  1098. }
  1099. break;
  1100. case 68:
  1101. if(dwTickCount >= QD_MotorDelay)
  1102. {
  1103. QD_YD_VAVLE = 0;
  1104. QD_HL_VAVLE = 0;
  1105. QD_YX_VAVLE = 0;
  1106. QD_TL_VAVLE = 0;
  1107. QD_MotorStep = 0;
  1108. QD_MotorDelay = dwTickCount;
  1109. }
  1110. break;
  1111. }
  1112. }
  1113. #endif
  1114. void QueDuan_BingLian(void)
  1115. {
  1116. static long bl_pos_buff,HL_delay;
  1117. switch(QD_BinLianStep)
  1118. {
  1119. case 0:break;
  1120. case 1:
  1121. bl_pos_buff = cRealPos;
  1122. QD_BinLianStep = 2;
  1123. break;
  1124. case 2:
  1125. if((cRealPos - bl_pos_buff) >= QD_PARAM_DELAY_HL_LENGTH)
  1126. {
  1127. QD_BL_VAVLE = 1;
  1128. QD_BinLianStep = 3;
  1129. }
  1130. break;
  1131. case 3://有过链检测
  1132. if(QD_GUO_LIAN_IN_DW || ((cRealPos - bl_pos_buff) >= (QD_PARAM_ZIPPER_LENGTH - QD_PARAM_HL_DELAY_BACK)))
  1133. {
  1134. QD_BL_VAVLE = 0;
  1135. QD_BinLianStep = 0;
  1136. }
  1137. break;
  1138. case 10:
  1139. bl_pos_buff = cRealPos;
  1140. QD_BinLianStep = 11;
  1141. break;
  1142. case 11:
  1143. if((cRealPos - bl_pos_buff) >= QD_PARAM_DELAY_HL_LENGTH)
  1144. {
  1145. QD_BL_VAVLE = 1;
  1146. QD_BinLianStep = 12;
  1147. }
  1148. break;
  1149. case 12://有过链检测
  1150. if(QD_GUO_LIAN_IN_DW)
  1151. {
  1152. QD_BL_VAVLE = 0;
  1153. QD_BinLianStep = 0;
  1154. }
  1155. break;
  1156. default:;
  1157. }
  1158. }
  1159. #if QD_KB_MODE==1 //闭口
  1160. //作闭口专用程序
  1161. //不带过链感应长度输入电机长度 闭口有勾针到位
  1162. void QueDuan_Motor_NoGL(void)
  1163. {
  1164. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  1165. long pulse_buff;
  1166. unsigned short ch,kk;
  1167. user_datas[121] = QD_MotorStep;
  1168. user_datas[122] = QD_AutoStep;
  1169. user_datas[124]= cRealPos;
  1170. user_datas[125]= bRunning;
  1171. // user_datas[123] = length_buff - (*length_buffer);
  1172. // user_datas[127] = cRealPos;
  1173. // user_datas[126] = go_buff - cRealPos;
  1174. if((QD_MotorStep >= 101) && (QD_MotorStep <= 103))
  1175. {
  1176. if(QD_QIAN_LIMIT_IN_DW)QD_HL_VAVLE = 0;
  1177. }
  1178. switch(QD_MotorStep)
  1179. {
  1180. case 30:
  1181. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1182. length_buffer = &QD_PARAM_OFFSET_LENGTH;
  1183. if(QD_PARAM_BL_ENABLE) //
  1184. QD_BinLianStep = 1;
  1185. if(QD_MACHINE_TYPE == QD_CS_TUIFANGKUAI) //双开带过链感应
  1186. {
  1187. if(QD_PARAM_DEC_MODE == QD_BACK_NOMAL_DEC_MODE)//测长数控
  1188. QD_MotorStep = 101;
  1189. else
  1190. QD_MotorStep = 31;
  1191. }
  1192. else //闭口走长度
  1193. QD_MotorStep = 31;
  1194. break;
  1195. case 31:
  1196. if(dwTickCount >= QD_MotorDelay)
  1197. {
  1198. back_buff = cRealPos;
  1199. gou_zhen_buff = cRealPos;
  1200. save_buff = cRealPos;
  1201. length_buffer = &QD_PARAM_OFFSET_LENGTH;
  1202. //李永庆代码
  1203. SetDir(X_AXIS, QD_DIR_P);
  1204. //两段速度移动距离
  1205. // 轴 第一段速度 第一段长度要减去送链长度 第二段速度 第二段长度 方向
  1206. AxisMoveTwoPos(X_AXIS,QD_PARAM_BACK_SPEED,QD_PARAM_ZIPPER_LENGTH-QD_PARAM_BACK_LOW_SPEED_LENGTH-200,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_BACK_LOW_SPEED_LENGTH + (*length_buffer),QD_DIR_P);
  1207. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1208. QD_MotorStep = 32;
  1209. }
  1210. break;
  1211. case 32:
  1212. //勾针提前输出
  1213. if (!QD_GZ_VAVLE && ((cRealPos + QD_PARAM_GOUZHEN_LENGTH + 200) >= (QD_PARAM_ZIPPER_LENGTH )))
  1214. QD_GZ_VAVLE = 1;
  1215. if((cRealPos) > (QD_PARAM_ZIPPER_LENGTH-QD_PARAM_BACK_LOW_SPEED_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)))))
  1216. {
  1217. QD_MotorDelay = dwTickCount + 2000; //钩针未到位延时警告
  1218. QD_MotorStep = 33;
  1219. }
  1220. else if(cRealPos >= (QD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)))//QD_PARAM_ERROR_LENGTH))
  1221. {
  1222. QD_SetAlarmCode(QD_GZ_ALARM);
  1223. }
  1224. break;
  1225. case 33:
  1226. if(!QD_GZ_VAVLE && (cRealPos + QD_PARAM_GOUZHEN_LENGTH + 200) > (QD_PARAM_ZIPPER_LENGTH ))
  1227. {
  1228. QD_GZ_VAVLE = 1;
  1229. QD_MotorDelay = dwTickCount + 2000; //钩针未到位延时警告
  1230. }
  1231. //提前12MM取消数控模式,进入连续运动
  1232. // if((cRealPos + 180 + 200) > (QD_PARAM_ZIPPER_LENGTH ))
  1233. // {
  1234. // CancelPmoveState(X_AXIS);
  1235. // SetStartSpeed(X_AXIS,1500);
  1236. // AxisChangeSpeed(X_AXIS,1500);
  1237. // }
  1238. if(QD_GOUZHEN_IN)
  1239. {
  1240. AxisEgmStop(X_AXIS);
  1241. QD_MotorDelay = dwTickCount + 10;
  1242. QD_YD_VAVLE = 1;
  1243. QD_MotorStep = 34;
  1244. QD_BL_VAVLE = 0; //停止时并链一定要打开
  1245. }
  1246. else if((cRealPos >= QD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)))// && dwTickCount >= QD_MotorDelay)
  1247. {
  1248. AxisEgmStop(X_AXIS);
  1249. if(dwTickCount >= QD_MotorDelay)
  1250. QD_SetAlarmCode(QD_GZ_ALARM);
  1251. }
  1252. break;
  1253. case 34:
  1254. if(!X_DRV && (dwTickCount >= QD_MotorDelay))
  1255. {
  1256. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1257. QD_YD_VAVLE = 1;
  1258. QD_MotorStep = 35;
  1259. }
  1260. break;
  1261. case 35:
  1262. if(cZipCnt == 0)
  1263. {
  1264. ch = QD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)-90;
  1265. kk = QD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)+90;
  1266. }
  1267. else
  1268. {
  1269. ch = QD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)-70;
  1270. kk = QD_PARAM_ZIPPER_LENGTH - 200 + (*length_buffer)+70;
  1271. }user_datas[128] = ch;
  1272. user_datas[127] = kk;
  1273. if(((cRealPos) < (ch)))
  1274. {
  1275. SetAlarmCode(QD_ALARM_ADDR,QD_LENGTH_LONG_ALARM);
  1276. if(dwTickCount >= QD_MotorDelay)
  1277. bAlarmStop = 1;
  1278. }
  1279. else if((cRealPos > kk))//(QD_PARAM_ERROR_LENGTH - 200 + (*length_buffer)+50)))
  1280. {
  1281. SetAlarmCode(QD_ALARM_ADDR,QD_LENGTH_LONG_ALARM);
  1282. if(dwTickCount >= QD_MotorDelay)
  1283. bAlarmStop = 1;
  1284. }
  1285. else
  1286. {
  1287. SetDir(X_AXIS, QD_DIR_P);
  1288. AxisMovePosAccDec(X_AXIS,QD_PARAM_BACK_LOW_SPEED,-QD_PARAM_FZ_LENGTH,3000,QD_PARAM_ACC,QD_PARAM_DCC);
  1289. SetDir(X_AXIS, QD_DIR_P);
  1290. QD_MotorStep = 0;
  1291. }
  1292. break;
  1293. case 101:
  1294. if(dwTickCount >= QD_MotorDelay)
  1295. {
  1296. back_buff = cRealPos;
  1297. gou_zhen_buff = cRealPos;
  1298. save_buff = cRealPos;
  1299. if(cZipCnt <= 2)
  1300. {
  1301. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1302. MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,QD_PARAM_FIRST_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  1303. QD_MotorStep = 102;
  1304. }
  1305. else
  1306. {
  1307. MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,QD_PARAM_BACK_SPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  1308. QD_MotorStep = 102;
  1309. }
  1310. }
  1311. break;
  1312. case 102:
  1313. if(cZipCnt <= 2)
  1314. {
  1315. //拉链上升沿,就是到空位
  1316. if(QD_GUO_LIAN_IN_UP)
  1317. {
  1318. QD_MotorDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  1319. if(X_DRV)
  1320. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED); //降速
  1321. QD_MotorStep = 103;
  1322. }
  1323. }
  1324. else
  1325. {
  1326. //1为双开
  1327. if((QD_SK_MODE) && (((cRealPos + QD_PARAM_YALIAN_LENGTH- gou_zhen_buff) > (length_buff - QD_PARAM_GOUZHEN_LENGTH))))
  1328. {
  1329. QD_YX_VAVLE = 1;
  1330. QD_HL_VAVLE = 1;
  1331. }
  1332. if(((cRealPos - gou_zhen_buff) > (length_buff - QD_PARAM_GOUZHEN_LENGTH)) && !QD_GZ_VAVLE)
  1333. {
  1334. QD_GZ_VAVLE = 1;
  1335. QD_YX_VAVLE = 1;
  1336. }
  1337. 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))))
  1338. {
  1339. if(X_DRV)
  1340. {
  1341. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1342. }
  1343. QD_MotorStep = 103;
  1344. }
  1345. }
  1346. break;
  1347. case 103:
  1348. if(cZipCnt <= 2)
  1349. {//双开暂不用,先保留
  1350. #if QD_SK_MODE
  1351. if((QD_SK_MODE) && ((dwTickCount + QD_PARAM_GZ_DELAY/2) >= QD_MotorDelay))
  1352. {
  1353. QD_YX_VAVLE = 1;
  1354. QD_HL_VAVLE = 1;
  1355. }
  1356. #endif
  1357. if(dwTickCount >= QD_MotorDelay)
  1358. {
  1359. QD_GZ_VAVLE = 1;
  1360. QD_YX_VAVLE = 1;
  1361. #if QD_SK_MODE //双开暂不用,先保留
  1362. if(QD_SK_MODE)
  1363. QD_MotorStep = 154;
  1364. else
  1365. #endif
  1366. QD_MotorStep = 160;
  1367. }
  1368. }
  1369. else
  1370. {
  1371. #if QD_SK_MODE //双开暂不用,先保留
  1372. if((QD_SK_MODE) && (((cRealPos + QD_PARAM_YALIAN_LENGTH- gou_zhen_buff) > (length_buff - QD_PARAM_GOUZHEN_LENGTH))))
  1373. {
  1374. QD_YX_VAVLE = 1;
  1375. QD_HL_VAVLE = 1;
  1376. }
  1377. #endif
  1378. if(((cRealPos - gou_zhen_buff) > (length_buff - QD_PARAM_GOUZHEN_LENGTH)))
  1379. {
  1380. QD_GZ_VAVLE = 1;
  1381. QD_YX_VAVLE = 1;
  1382. #if QD_SK_MODE //双开暂不用,先保留
  1383. if(QD_SK_MODE)
  1384. QD_MotorStep = 154;
  1385. else
  1386. #endif
  1387. QD_MotorStep = 160;
  1388. }
  1389. if(((cRealPos - save_buff) >= (QD_PARAM_ERROR_LENGTH + length_buff)) && QD_GZ_VAVLE)
  1390. {
  1391. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1392. }
  1393. }
  1394. break;
  1395. case 154:
  1396. #if QD_SK_MODE //双开暂不用,先保留
  1397. if(QD_GZ_UP_IN)
  1398. {
  1399. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_CHECK_GZ;
  1400. QD_MotorStep = 104;
  1401. }
  1402. #endif
  1403. break;
  1404. case 160:
  1405. if(QD_GOUZHEN_IN)
  1406. {
  1407. AxisEgmStop(X_AXIS);
  1408. QD_YD_VAVLE = 1;
  1409. QD_MotorStep = 105;
  1410. }
  1411. else if(((cRealPos - save_buff) >= (QD_PARAM_ERROR_LENGTH + length_buff)) && QD_GZ_VAVLE && (cZipCnt > 2))
  1412. {
  1413. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1414. }
  1415. break;
  1416. case 104:
  1417. #if QD_SK_MODE //双开暂不用,先保留
  1418. if(dwTickCount >= QD_MotorDelay)
  1419. {
  1420. //勾针离开就是到位
  1421. if(!QD_GOUZHEN_IN && QD_GZ_UP_IN)
  1422. {
  1423. AxisEgmStop(X_AXIS);
  1424. QD_MotorStep = 105;
  1425. }
  1426. }
  1427. #endif
  1428. break;
  1429. case 105:
  1430. if(!X_DRV)
  1431. {
  1432. QD_MotorStep = 0;
  1433. QD_HL_VAVLE = 1;
  1434. QD_YD_VAVLE = 1;
  1435. if(cZipCnt == 1)
  1436. {
  1437. go_length_buff = cRealPos - back_buff;
  1438. }
  1439. else if(cZipCnt == 2)
  1440. {
  1441. length_buff = cRealPos - back_buff;
  1442. }
  1443. else if(cZipCnt > 2)
  1444. {
  1445. if(((cRealPos - save_buff) < (length_buff - QD_PARAM_ERROR_LENGTH- (*length_buffer))))QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1446. else if(((cRealPos - save_buff) > (QD_PARAM_ERROR_LENGTH + length_buff - (*length_buffer))))QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1447. else
  1448. {
  1449. }
  1450. }
  1451. AxisMovePosAccDec(X_AXIS,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_FZ_LENGTH,1,QD_PARAM_ACC,QD_PARAM_DCC);
  1452. }
  1453. break;
  1454. case 106:
  1455. if(!X_DRV)
  1456. {
  1457. QD_SetAlarmCode(QD_GZ_ALARM);
  1458. }
  1459. else
  1460. {
  1461. if(QD_GOUZHEN_IN)
  1462. {
  1463. AxisEgmStop(X_AXIS);
  1464. QD_YD_VAVLE = 1;
  1465. QD_MotorStep = 0;
  1466. }
  1467. }
  1468. break;
  1469. case 40:
  1470. QD_JD_VAVLE = 0;
  1471. SetDir(X_AXIS, QD_DIR_P);
  1472. QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  1473. QD_MotorStep = 41;
  1474. break;
  1475. case 41:
  1476. if((dwTickCount >= QD_MotorDelay))
  1477. {
  1478. //夹子已经张开
  1479. AxisMovePosAccDec(X_AXIS,QD_PARAM_CUT_BACK_SPEED,(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH),QD_PARAM_START_SPEED,10,10);
  1480. // AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH));
  1481. QD_MotorStep = 42;
  1482. }
  1483. break;
  1484. case 42:
  1485. // if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - jz_buff)))
  1486. // {
  1487. // QD_JD_VAVLE = 0;
  1488. // QD_MotorStep = 43;
  1489. // }
  1490. // else
  1491. if(!X_DRV)
  1492. {
  1493. QD_JD_VAVLE = 0;
  1494. QD_MotorStep = 43;
  1495. }
  1496. break;
  1497. case 43: // 切断完成后拉电机动作
  1498. if(!X_DRV)
  1499. {
  1500. QD_MotorStep = 0;
  1501. QD_MotorDelay = dwTickCount;
  1502. }
  1503. break;
  1504. case 61: // 前点定位数控模式
  1505. if(QD_SZ_OUT)
  1506. {
  1507. QD_SZ_OUT = 0;
  1508. QD_MotorDelay = dwTickCount + 150;
  1509. SetPos(X_AXIS, 0);
  1510. }
  1511. else
  1512. QD_MotorDelay = dwTickCount;
  1513. QD_BL_VAVLE = 0;//并链也要打开
  1514. SetDir(X_AXIS,QD_DIR_N);
  1515. if(!QD_TL_VAVLE && cZipCnt) //没送链情况下主动送链
  1516. {
  1517. if(!QD_SHANG_MU_LIMIT_IN && (QD_TuiLianStep == 0))
  1518. {
  1519. QD_TuiLianStep = 1;
  1520. QD_MotorStep = 62;
  1521. }
  1522. }
  1523. else
  1524. QD_MotorStep = 62;
  1525. break;
  1526. case 62:
  1527. if(dwTickCount >= QD_MotorDelay)
  1528. {
  1529. if(QD_QIAN_LIMIT_IN)
  1530. {
  1531. SetPos(X_AXIS, 0);//在前点,直接置零点
  1532. SetDir(X_AXIS,QD_DIR_P);
  1533. //前点亮的情况下先退出
  1534. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,1000);
  1535. QD_MotorDelay = dwTickCount + 300;
  1536. }
  1537. QD_MotorStep = 63;
  1538. QD_JD_VAVLE = 0;
  1539. }
  1540. break;
  1541. case 63:
  1542. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))// && !QD_SHANG_MU_LIMIT_IN)
  1543. {
  1544. SetDir(X_AXIS, QD_DIR_N);
  1545. go_buff = cRealPos;
  1546. QD_YD_VAVLE = 1;
  1547. QD_HL_VAVLE = 1;
  1548. QD_YX_VAVLE = 1;
  1549. //李永庆代码,当位置在慢速之外,走数控到慢速点
  1550. if(cZipCnt > 0)
  1551. {
  1552. if(cRealPos>(QD_PARAM_GO_LOW_SPEED_LENGTH))
  1553. {
  1554. // AxisMovePosAccDecNotStop(X_AXIS,QD_PARAM_GO_HIGH_SPEED,cRealPos-QD_PARAM_GO_LOW_SPEED_LENGTH,QD_PARAM_GO_LOW_SPEED,QD_PARAM_GO_LOW_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  1555. // SetStartSpeed(X_AXIS,QD_PARAM_START_SPEED);
  1556. // SetAccTime(X_AXIS,QD_PARAM_ACC);
  1557. // SetDecTime(X_AXIS,QD_PARAM_DCC);
  1558. //两段速度移动距离
  1559. // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
  1560. // AxisMoveTwoPos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,cRealPos-QD_PARAM_GO_LOW_SPEED_LENGTH,QD_PARAM_GO_LOW_SPEED,QD_PARAM_GO_LOW_SPEED_LENGTH+ 100,QD_DIR_N);
  1561. //跑三段速度
  1562. AxisMoveThreePosNoStop(X_AXIS,QD_PARAM_GO_HIGH_SPEED,cRealPos -QD_PARAM_GO_LOW_SPEED_LENGTH-300,
  1563. QD_PARAM_GO_HIGH_SPEED*2/3,350,
  1564. QD_PARAM_GO_LOW_SPEED,QD_PARAM_GO_LOW_SPEED_LENGTH,QD_DIR_N) ;
  1565. }
  1566. else
  1567. {
  1568. // X轴 运行速度 启动速度 加速度 减速度
  1569. AxisContinueMoveAcc(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_DIR_N,QD_PARAM_GO_LOW_SPEED/3,15,15);
  1570. // MoveAction_Const_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_GO_LOW_SPEED_LENGTH,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);
  1571. }
  1572. }
  1573. else
  1574. {
  1575. // X轴 运行速度 启动速度 加速度 减速度
  1576. AxisContinueMoveAcc(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_DIR_N,QD_PARAM_GO_LOW_SPEED/3,15,15);
  1577. // MoveAction_Const_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_FIRST_GO_HIGHSPEED,QD_PARAM_START_SPEED,QD_PARAM_ACC,QD_PARAM_DCC);//
  1578. }
  1579. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1580. QD_MotorStep =64;
  1581. }
  1582. break;
  1583. case 64:
  1584. if(cZipCnt > 1)
  1585. {
  1586. //李永庆代码
  1587. if(((cRealPos) < (QD_PARAM_GO_LOW_SPEED_LENGTH+1200)))// || (QD_QIAN_DEC_IN))
  1588. {
  1589. user_datas[126]= GetCurSpeed(X_AXIS);
  1590. // MoveChangSpeedDec(X_AXIS,QD_PARAM_GO_HIGH_SPEED*2/3,6,8);
  1591. // AxisChangeSpeed(X_AXIS,40);
  1592. QD_MotorStep =65;
  1593. }
  1594. if(QD_QIAN_LIMIT_IN) //前点限位
  1595. {
  1596. AxisEgmStop(X_AXIS);
  1597. QD_MotorStep = 66;
  1598. }
  1599. }
  1600. else
  1601. {
  1602. if(QD_QIAN_LIMIT_IN) //前点限位
  1603. {
  1604. AxisEgmStop(X_AXIS);
  1605. QD_MotorStep = 66;
  1606. }
  1607. }
  1608. break;
  1609. case 65:
  1610. if(QD_QIAN_LIMIT_IN)
  1611. {
  1612. AxisEgmStop(X_AXIS);
  1613. QD_MotorStep = 66;
  1614. }
  1615. else if(dwTickCount >= QD_MotorDelay)
  1616. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1617. break;
  1618. case 66:
  1619. if(!X_DRV)
  1620. {
  1621. SetPos(X_AXIS, 0);
  1622. QD_MotorDelay = dwTickCount;
  1623. QD_MotorStep = 67;
  1624. }
  1625. break;
  1626. case 67: //等推链完成后,
  1627. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1628. {
  1629. if(bRunning)
  1630. {
  1631. QD_JD_VAVLE = 1;
  1632. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1633. }
  1634. QD_MotorStep = 68;
  1635. }
  1636. break;
  1637. case 68:
  1638. if(dwTickCount >= QD_MotorDelay)
  1639. {
  1640. QD_YD_VAVLE = 0;
  1641. QD_HL_VAVLE = 0;
  1642. QD_YX_VAVLE = 0;
  1643. QD_TL_VAVLE = 0;
  1644. QD_MotorStep = 0;
  1645. QD_MotorDelay = dwTickCount;
  1646. }
  1647. break;
  1648. }
  1649. }
  1650. #endif
  1651. //电机动作
  1652. void QueDuan_Motor(void)
  1653. {
  1654. if(QD_KB_MODE) //闭口
  1655. {
  1656. #if QD_KB_MODE //闭口
  1657. QueDuan_Motor_NoGL();
  1658. #endif
  1659. }
  1660. else //开口
  1661. {
  1662. #if !QD_KB_MODE //开口
  1663. QueDuan_Motor_KK(); //
  1664. #endif
  1665. }
  1666. }
  1667. //超声方式下切,开口专用
  1668. void QueDuan_XiaQue_KK(void)
  1669. {
  1670. switch(QD_XiaQieStep)
  1671. {
  1672. case 0:
  1673. break;
  1674. case 1:
  1675. QD_XiaQieStep = 2;
  1676. break;
  1677. case 2:
  1678. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1679. QD_XiaQieStep = 3;
  1680. break;
  1681. case 3:
  1682. if(1)
  1683. {
  1684. QD_XiaQieDelay = dwTickCount + 0;//QD_PARAM_GZ_DELAY;
  1685. QD_XiaQieStep = 4;
  1686. }
  1687. else if(dwTickCount >= QD_XiaQieDelay)
  1688. {
  1689. QD_SetAlarmCode(QD_XM_DAOWEI);
  1690. }
  1691. break;
  1692. case 4:
  1693. if(QD_GZ_VAVLE) //勾针已经有输出就不需要延时
  1694. {
  1695. QD_XiaQieDelay = dwTickCount + 0;
  1696. }
  1697. else
  1698. QD_XiaQieDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  1699. QD_GZ_VAVLE = 1;
  1700. cTuiFangKuaiCnt=0;
  1701. QD_XiaQieStep = 5;
  1702. break;
  1703. case 5:
  1704. if(dwTickCount >= QD_XiaQieDelay)
  1705. {
  1706. QD_TFK_VAVLE = 1;
  1707. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1708. QD_XiaQieStep = 6;
  1709. }
  1710. break;
  1711. case 6:
  1712. if(1)
  1713. {
  1714. QD_XiaQieStep = 7;
  1715. QD_XiaQieDelay = dwTickCount + 1000;
  1716. }
  1717. else if(dwTickCount >= QD_XiaQieDelay)
  1718. {
  1719. QD_SetAlarmCode(QD_XM_DAOWEI);
  1720. }
  1721. break;
  1722. case 7:
  1723. if(QD_GOUZHEN_IN)
  1724. {
  1725. cTuiFangKuaiCnt = 0;
  1726. QD_YD_VAVLE = 1;
  1727. if(!bRunning)
  1728. QD_XiaQieDelay = dwTickCount + 200;
  1729. else
  1730. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1731. if(!QD_QIAN_LIMIT_IN)
  1732. QD_XiaQieStep = 8;
  1733. else
  1734. QD_SetAlarmCode(QD_QIAN_LIMIT_ALARM);
  1735. }
  1736. else if((dwTickCount >= QD_XiaQieDelay))
  1737. {
  1738. if(cTuiFangKuaiCnt < QD_PARAM_TFK_NUMBER)
  1739. {
  1740. QD_TFK_VAVLE = 0;
  1741. cTuiFangKuaiCnt++;
  1742. QD_XiaQieDelay = dwTickCount + 500;
  1743. QD_XiaQieStep = 100;
  1744. }
  1745. else
  1746. QD_SetAlarmCode(QD_GZ_ALARM);
  1747. }
  1748. break;
  1749. case 100:
  1750. if((dwTickCount >= QD_XiaQieDelay))
  1751. {
  1752. QD_XiaQieStep = 5;
  1753. }
  1754. break;
  1755. case 8://上下模同时输出
  1756. if(dwTickCount >= QD_XiaQieDelay)
  1757. {
  1758. QD_SM_VAVLE = 1;
  1759. if(QD_PARAM_XM_ENABLE == 0) //配置下模动
  1760. QD_XM_VAVLE = 1;
  1761. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1762. QD_XiaQieStep = 9;
  1763. }
  1764. break;
  1765. case 9://上下模到位,调试模下的话,等按下一步按键 下模不动
  1766. if(QD_SHANG_MU_LIMIT_IN && (QD_XIA_MU_LIMIT_IN || QD_PARAM_XM_ENABLE) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1767. {
  1768. if(!QD_PARAM_CS_MODE) //无超声配置
  1769. {
  1770. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAYBACK_SM; //
  1771. QD_XiaQieStep = 12;
  1772. }
  1773. else
  1774. {
  1775. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAY_CS; //
  1776. QD_XiaQieStep = 10;
  1777. }
  1778. }
  1779. else if(dwTickCount >= QD_XiaQieDelay)
  1780. {
  1781. if(!QD_SHANG_MU_LIMIT_IN)QD_SetAlarmCode(QD_SM_DAOWEI);
  1782. else QD_SetAlarmCode(QD_XM_DAOWEI);
  1783. }
  1784. break;
  1785. case 10:
  1786. if(dwTickCount >= QD_XiaQieDelay)
  1787. {
  1788. QD_CS_OUT = 1;
  1789. //
  1790. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_TIME; //
  1791. QD_XiaQieStep = 11;
  1792. }
  1793. break;
  1794. case 11:
  1795. if(dwTickCount >= QD_XiaQieDelay)
  1796. {
  1797. QD_CS_OUT = 0;
  1798. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_COLD_TIME; //
  1799. QD_XiaQieStep = 12;
  1800. }
  1801. break;
  1802. case 12:
  1803. if(dwTickCount >= QD_XiaQieDelay)
  1804. {
  1805. QD_SM_VAVLE = 0;
  1806. if(QD_PARAM_XM_ENABLE == 0) //配置下模动
  1807. QD_XM_VAVLE = 0;
  1808. QD_TFK_VAVLE = 0;
  1809. QD_GZ_VAVLE = 0;
  1810. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  1811. QD_XiaQieStep = 13;
  1812. }//
  1813. break;
  1814. case 13:
  1815. if(!QD_SHANG_MU_LIMIT_IN)
  1816. {
  1817. //启动推链(送链)
  1818. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE)
  1819. QD_TuiLianStep = 1;
  1820. }
  1821. if(!QD_SHANG_MU_LIMIT_IN && (!QD_XIA_MU_LIMIT_IN || QD_PARAM_XM_ENABLE))
  1822. {
  1823. QD_XiaQieStep = 0;
  1824. }
  1825. else if(dwTickCount >= QD_XiaQieDelay)
  1826. {
  1827. QD_SetAlarmCode(QD_SM_YUANWEI);
  1828. }
  1829. break;
  1830. }
  1831. }
  1832. void QueDuan_TuiLianAction(void)
  1833. {
  1834. if(QD_PARAM_XM_ENABLE == 0)
  1835. {
  1836. QD_TuiLianStep = 0;
  1837. }
  1838. else
  1839. {
  1840. switch(QD_TuiLianStep)
  1841. {
  1842. case 1:
  1843. QD_TuiLianStep = 2;
  1844. break;
  1845. case 2:
  1846. QD_TLDelay = dwTickCount + QD_PARAM_YD_DELAY;
  1847. QD_TuiLianStep = 3;
  1848. break;
  1849. case 3:
  1850. if(!QD_SM_VAVLE && !QD_SHANG_MU_LIMIT_IN)//dwTickCount >= QD_TLDelay)
  1851. {
  1852. QD_TL_VAVLE = 1;
  1853. if(!bRunning)QD_TFK_VAVLE = 0;
  1854. QD_TLDelay = dwTickCount + QD_PARAM_TL_DELAY;
  1855. QD_TuiLianStep = 4;
  1856. }
  1857. break;
  1858. case 4:
  1859. if(dwTickCount >= QD_TLDelay)
  1860. {
  1861. QD_TuiLianStep = 0;
  1862. }
  1863. break;
  1864. case 10:
  1865. QD_TuiLianStep = 11;
  1866. break;
  1867. case 11:
  1868. if(!Y_DRV)
  1869. {
  1870. {
  1871. QD_TuiLianStep = 0;
  1872. }
  1873. }
  1874. break;
  1875. }
  1876. }
  1877. }
  1878. //闭口专用
  1879. void QueDuan_XiaQue_NO_GL(void)
  1880. {
  1881. switch(QD_XiaQieStep)
  1882. {
  1883. case 0:
  1884. break;
  1885. case 1:
  1886. if(!bRunning)
  1887. {
  1888. if((QD_MACHINE_TYPE == QD_CS_TUIFANGKUAI) && QD_SK_MODE)
  1889. {
  1890. //跳到双开
  1891. // QD_YD_VAVLE = 1;
  1892. QD_HL_VAVLE = 1; //护链
  1893. QD_YX_VAVLE = 1; //压带
  1894. QD_GZ_VAVLE = 1; //勾针
  1895. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1896. QD_XiaQieStep = 100;
  1897. }
  1898. else
  1899. {
  1900. // QD_GZ_VAVLE = 1; //勾针
  1901. // QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1902. // QD_XiaQieStep = 100;
  1903. QD_YD_VAVLE = 1;
  1904. QD_XiaQieStep = 2;
  1905. QD_XiaQieDelay = dwTickCount + 30;
  1906. }
  1907. }
  1908. else
  1909. {
  1910. QD_YD_VAVLE = 1;
  1911. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  1912. QD_XiaQieStep = 2;
  1913. }
  1914. break;
  1915. case 2:
  1916. if(dwTickCount >= QD_XiaQieDelay)
  1917. {
  1918. QD_XiaQieStep = 3;
  1919. QD_XiaQieDelay = dwTickCount;
  1920. }
  1921. break;
  1922. case 3:
  1923. if(dwTickCount >= QD_XiaQieDelay)
  1924. {
  1925. if((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0))
  1926. {
  1927. QD_SM_VAVLE = 1;
  1928. QD_XM_VAVLE = 1;
  1929. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1930. QD_XiaQieStep = 4;
  1931. }
  1932. }
  1933. break;
  1934. case 4://永兴为下模固定
  1935. if(QD_SHANG_MU_LIMIT_IN && (QD_XIA_MU_LIMIT_IN || QD_PARAM_XM_ENABLE))
  1936. {
  1937. QD_GZ_VAVLE = 0;
  1938. if(!QD_PARAM_CS_MODE) //气切
  1939. {
  1940. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAYBACK_SM; //
  1941. QD_XiaQieStep = 5;
  1942. }
  1943. else
  1944. {
  1945. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAY_CS; //
  1946. QD_XiaQieStep = 10;
  1947. } //
  1948. }
  1949. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  1950. break;
  1951. case 5:
  1952. if(dwTickCount >= QD_XiaQieDelay)
  1953. {
  1954. QD_SM_VAVLE = 0;
  1955. QD_XM_VAVLE = 0;
  1956. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  1957. QD_XiaQieStep = 6;
  1958. }
  1959. break;
  1960. case 6:
  1961. if(!QD_SHANG_MU_LIMIT_IN && (!QD_XIA_MU_LIMIT_IN || QD_PARAM_XM_ENABLE)) //下模不动就不用判断
  1962. {
  1963. if(QD_TuiLianStep == 0)
  1964. QD_TuiLianStep = 1;
  1965. if(!bRunning)
  1966. QD_JD_VAVLE = 0;
  1967. QD_XiaQieStep = 0;
  1968. }
  1969. else if(dwTickCount >= QD_XiaQieDelay)
  1970. {
  1971. QD_SetAlarmCode(QD_SM_YUANWEI);
  1972. }
  1973. break;
  1974. //10~11步为超声
  1975. case 10:
  1976. if(dwTickCount >= QD_XiaQieDelay)
  1977. {
  1978. if(QD_PARAM_CS_ENABLE)QD_CS_OUT = 1;
  1979. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_TIME; //
  1980. QD_XiaQieStep = 11;
  1981. }
  1982. break;
  1983. case 11:
  1984. if(dwTickCount >= QD_XiaQieDelay)
  1985. {
  1986. QD_CS_OUT = 0;
  1987. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_COLD_TIME; //
  1988. QD_XiaQieStep = 5;
  1989. }
  1990. break;
  1991. case 100:
  1992. if(dwTickCount >= QD_XiaQieDelay)
  1993. {
  1994. //这是双开程序,暂时不考虑
  1995. #if 1
  1996. if(QD_GOUZHEN_IN)
  1997. {
  1998. QD_YD_VAVLE = 1;
  1999. QD_XiaQieStep = 3;
  2000. }
  2001. #endif
  2002. }
  2003. break;
  2004. }
  2005. }
  2006. //切断动作
  2007. void QueDuan_XiaQue(void)
  2008. {
  2009. if(QD_KB_MODE) //闭口
  2010. {
  2011. QueDuan_XiaQue_NO_GL(); //
  2012. }
  2013. else //开口
  2014. {
  2015. QueDuan_XiaQue_KK();
  2016. }
  2017. #if 0
  2018. switch(QD_MACHINE_TYPE)
  2019. {
  2020. case QD_NO_CS_TUIFANGKUAI:QueDuan_XiaQue_CS();break;
  2021. case QD_NO_GL_TUIFANGKUAI:QueDuan_XiaQue_NO_GL();break;
  2022. case QD_CS_TUIFANGKUAI:QueDuan_XiaQue_NO_GL();break;
  2023. default:;
  2024. }
  2025. #endif
  2026. }
  2027. #endif