JCWYQueDuanJi.c 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650
  1. #include "global.h"
  2. #if JIA_CHENG_WEI_YE_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_TuiFangKuai(void);
  12. void QueDuan_ExtiActionX31(void);
  13. void QueDuan_BingLian(void);
  14. static unsigned long cZipCnt = 0,cTableCnt = 0,cTuiFangKuaiCnt = 0;
  15. static long save_limit_pos,cRealPos,dwZipper_length;
  16. static long dwSaveLength;
  17. unsigned char cCheckLianFlg = 0;
  18. unsigned char cCheckLianFlgEN = 0;
  19. unsigned char cGoLimitEn = 0;
  20. unsigned char cCheckLengthEn = 0;
  21. long TestDisplay;
  22. void QueDuan_ExtiActionX31(void)
  23. {
  24. cCheckLianFlg = 1;
  25. }
  26. void QD_SetAlarmCode(unsigned alarm_code)
  27. {
  28. SetAlarmCode(QD_ALARM_ADDR,alarm_code);
  29. bAlarmStop = 1;
  30. }
  31. void QueDuan_InitAction(void)
  32. {
  33. float length_buff,pulse_buff;
  34. save_limit_pos = QD_SAVE_POS;
  35. axis_x->speed_unit = 500;
  36. SetAccTime(X_AXIS,10);
  37. SetDecTime(X_AXIS,10);
  38. length_buff = QD_PARAM_CYCLE_LENGTH;
  39. pulse_buff = QD_PARAM_CYCLE_PULSE;
  40. XGearRatio = pulse_buff/length_buff;
  41. axis_y->speed_unit = 300;
  42. SetAccTime(Y_AXIS,3);
  43. SetDecTime(Y_AXIS,3);
  44. length_buff = QD_PARAM_TL_CYCLE_LENGTH;
  45. pulse_buff = QD_PARAM_TL_CYCLE_PULSE;
  46. YGearRatio = pulse_buff/length_buff;
  47. CalFreqTab_X_Free(15);
  48. QD_SZ_OUT = 1;
  49. }
  50. void QueDuan_Action(void)
  51. {
  52. QueDuan_AlarmProtect();
  53. QueDuan_TuiFangKuai();
  54. QueDuan_Motor();
  55. QueDuan_XiaQue();
  56. QueDuan_ManualAction();
  57. QueDuan_YuanDianAction();
  58. QueDuan_TuiLianAction();
  59. QueDuan_BingLian();
  60. QueDuan_AutoAction();
  61. QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
  62. }
  63. //手动动作
  64. void QueDuan_ManualAction(void)
  65. {
  66. if(bRunning == 0)
  67. {
  68. if(QD_bClearTotal) //切断计数清零
  69. {
  70. QD_bClearTotal = 0;
  71. ClrcToTal(QD_TOTAL_ADDR);
  72. }
  73. if(QD_bClearNowTotal)
  74. {
  75. QD_bClearNowTotal = 0;
  76. QD_PARAM_NOW_CNT = 0;
  77. }
  78. if(QD_bXiaQie)
  79. {
  80. QD_bXiaQie = 0;
  81. if(QD_XiaQieStep == 0)QD_XiaQieStep = 1;
  82. }
  83. if(QD_bQianDianDW)
  84. {
  85. QD_bQianDianDW = 0;
  86. if(QD_MotorStep == 0)
  87. {
  88. QD_MotorStep = 61;
  89. cZipCnt = 0;
  90. }
  91. }
  92. if(QD_bTL)
  93. {
  94. if(QD_PARAM_TL_MODE)
  95. {
  96. if(!Y_DRV)AxisMovePos(Y_AXIS,QD_PARAM_TL_SPEED,QD_PARAM_TL_LENGTH);
  97. }
  98. else
  99. {
  100. QD_bTL = 0;
  101. QD_TL_VAVLE = ~QD_TL_VAVLE;
  102. }
  103. }
  104. if(!Y_DRV)QD_bTL = 0;
  105. if(QD_bYD)
  106. {
  107. QD_bYD = 0;
  108. QD_YD_VAVLE = ~QD_YD_VAVLE;
  109. }
  110. if(QD_bGZ)
  111. {
  112. QD_bGZ = 0;
  113. QD_GZ_VAVLE = ~QD_GZ_VAVLE;
  114. }
  115. if(QD_bJD)
  116. {
  117. QD_bJD = 0;
  118. QD_JD_VAVEL = ~QD_JD_VAVEL;
  119. }
  120. if(QD_bXM)
  121. {
  122. QD_bXM = 0;
  123. QD_XM_VAVLE = ~QD_XM_VAVLE;
  124. }
  125. if(QD_bSM)
  126. {
  127. QD_bSM = 0;
  128. QD_SM_VAVLE = ~QD_SM_VAVLE;
  129. }
  130. if(QD_bTFK)
  131. {
  132. QD_bTFK = 0;
  133. QD_TFK_VAVEL = ~QD_TFK_VAVEL;
  134. }
  135. if(QD_bTB)
  136. {
  137. QD_bTB = 0;
  138. QD_TABLE_VAVLE = ~QD_TABLE_VAVLE;
  139. }
  140. if(QD_bYBD)
  141. {
  142. QD_bYBD = 0;
  143. QD_YBD_VAVLE = ~QD_YBD_VAVLE;
  144. }
  145. if(QD_bTestCS)
  146. {
  147. QD_bTestCS = 0;
  148. QD_CS_OUT = 1;
  149. QD_CSDelay = dwTickCount + QD_PARAM_CS_TIME;
  150. }
  151. if(QD_bBL)
  152. {
  153. QD_bBL = 0;
  154. QD_BL_VAVLE = ~QD_BL_VAVLE;
  155. }
  156. if(QD_XiaQieStep == 0)
  157. {
  158. if(dwTickCount >= QD_CSDelay)QD_CS_OUT = 0;
  159. }
  160. if(QD_bYuanDianDW)
  161. {
  162. QD_bYuanDianDW = 0;
  163. if(QD_YuanDianStep == 0)QD_YuanDianStep = 1;
  164. }
  165. //电机控制
  166. if(QD_bGoMotor && !QD_QIAN_LIMIT_IN)
  167. {
  168. QD_SZ_OUT = 0;
  169. // if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_N;
  170. if(!X_DRV)AxisContinueMove(X_AXIS,10,QD_DIR_N);
  171. }
  172. if(QD_bBackMotor && !QD_BACK_LIMIT_IN)
  173. {
  174. QD_SZ_OUT = 0;
  175. // if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  176. if(!X_DRV)AxisContinueMove(X_AXIS,10,QD_DIR_P);
  177. }
  178. if(!QD_bGoMotor && !QD_bBackMotor && (QD_MotorStep == 0))
  179. {
  180. if(X_DRV)AxisDecStop(X_AXIS);
  181. }
  182. if(QD_QIAN_LIMIT_IN && (QD_MotorStep == 0) && !QD_bBackMotor &&(QD_AutoStep == 0))
  183. {
  184. if(X_DRV)AxisEgmStop(X_AXIS);
  185. }
  186. }
  187. }
  188. void QueDuan_YuanDianAction(void)
  189. {
  190. switch(QD_YuanDianStep)
  191. {
  192. case 0:break;
  193. case 1:
  194. if(QD_MotorStep == 0)QD_MotorStep = 61;
  195. QD_YuanDianStep = 2;
  196. break;
  197. case 2:
  198. if(QD_MotorStep == 0)
  199. {
  200. QD_MotorStep = 30;
  201. QD_YuanDianStep = 3;
  202. QD_JD_VAVEL = 1;
  203. }
  204. break;
  205. case 3:
  206. if(QD_MotorStep == 0)
  207. {
  208. QD_MotorStep = 0;
  209. QD_YuanDianStep = 0;
  210. }
  211. break;
  212. }
  213. }
  214. void QueDuan_AlarmProtect(void)
  215. {
  216. cRealPos = GetPos(X_AXIS);
  217. if(QD_PARAM_BACK_ALARM_MODE)
  218. { //感应后限模式
  219. if(!bRunning)
  220. {
  221. if(QD_BACK_LIMIT_IN_UP)
  222. {
  223. if((QD_MotorStep == 0) && X_DRV && QD_bBackMotor) //到后限不能再后退但可以点前进
  224. {
  225. QD_bBackMotor = 0;
  226. AxisDecStop(X_AXIS);
  227. QD_JD_VAVEL = 0;
  228. QD_SetAlarmCode(QD_BACK_ALARM);
  229. }
  230. }
  231. }
  232. else
  233. {
  234. if(QD_BACK_LIMIT_IN_UP)
  235. {
  236. AxisDecStop(X_AXIS);
  237. QD_JD_VAVEL = 0;
  238. QD_SetAlarmCode(QD_BACK_ALARM);
  239. }
  240. }
  241. }
  242. else
  243. {
  244. if(QD_QIAN_LIMIT_IN_UP) //数控后限模式
  245. {
  246. save_limit_pos = cRealPos;
  247. SetData32bits(200,save_limit_pos);
  248. }
  249. if(QD_PARAM_MAX_BACK_LENGTH < (cRealPos - save_limit_pos))
  250. {
  251. if(!bRunning)
  252. {
  253. if((QD_MotorStep == 0) && X_DRV && QD_bBackMotor) //到后限不能再后退但可以点前进
  254. {
  255. QD_bBackMotor = 0;
  256. AxisDecStop(X_AXIS);
  257. QD_JD_VAVEL = 0;
  258. QD_SetAlarmCode(QD_BACK_ALARM);
  259. }
  260. }
  261. else
  262. {
  263. AxisDecStop(X_AXIS);
  264. QD_JD_VAVEL = 0;
  265. QD_SetAlarmCode(QD_BACK_ALARM);
  266. }
  267. }
  268. }
  269. // if(!QD_KADAI_IN)QD_KaDaiDelay = dwTickCount + 3000;
  270. /* if(bRunning)
  271. {
  272. if(dwTickCount >= QD_KaDaiDelay)QD_SetAlarmCode(QD_KA_DAI_ALARM);
  273. }*/
  274. }
  275. void QueDuan_AutoAction(void)
  276. {
  277. if(bRunning)
  278. {
  279. if(dwTickCount >= QD_TBDelay)QD_TABLE_VAVLE = 0;
  280. switch(QD_AutoStep)
  281. {
  282. case 1:
  283. if(dwTickCount >= QD_AutoDelay)
  284. {
  285. QD_AutoStep = 2;
  286. if(QD_MotorStep == 0)
  287. {
  288. QD_MotorStep = 61; //前点定位
  289. }
  290. }
  291. break;
  292. case 2:
  293. if(QD_MotorStep == 0)
  294. {
  295. if(QD_PARAM_DC_MODE == 0)
  296. QD_MotorStep = 20; //后退到位
  297. else
  298. QD_MotorStep = 30;
  299. QD_AutoStep = 3;
  300. }
  301. break;
  302. case 3:
  303. if(QD_MotorStep == 0)
  304. {
  305. if(QD_XiaQieStep == 0)
  306. {
  307. QD_XiaQieStep = 1;
  308. QD_AutoStep = 4;
  309. }
  310. }
  311. break;
  312. case 4:
  313. if(QD_MACHINE_TYPE == QD_QQ_TUIFANGKUAI)
  314. {
  315. if(((QD_XiaQieStep == 0) || (QD_XiaQieStep >= 4)) && !QD_SHANG_MU_LIMIT_IN)
  316. {
  317. if(QD_MotorStep == 0)
  318. {
  319. QD_MotorStep = 40; //切完后退
  320. QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  321. }
  322. QD_AutoStep = 5;
  323. }
  324. }
  325. else if(QD_MACHINE_TYPE == QD_NO_GL_TUIFANGKUAI)
  326. {
  327. if(((QD_XiaQieStep == 0) || (QD_XiaQieStep == 13)) && !QD_SHANG_MU_LIMIT_IN && !QD_XIA_MU_LIMIT_IN)
  328. {
  329. if(QD_MotorStep == 0)
  330. {
  331. QD_MotorStep = 40; //切完后退
  332. QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  333. }
  334. QD_AutoStep = 5;
  335. }
  336. }
  337. else
  338. {
  339. if(((QD_XiaQieStep == 0) || (QD_XiaQieStep == 13)) && !QD_SHANG_MU_LIMIT_IN && !QD_XIA_MU_LIMIT_IN)
  340. {
  341. if(QD_MotorStep == 0)
  342. {
  343. QD_MotorStep = 40; //切完后退
  344. // QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  345. }
  346. QD_AutoStep = 5;
  347. }
  348. }
  349. break;
  350. case 5:
  351. if(QD_MotorStep == 0)
  352. {
  353. cZipCnt++;
  354. QD_PARAM_NOW_CNT++;
  355. cTableCnt++;
  356. AddToTal(QD_TOTAL_ADDR);
  357. CalProSP(QD_PROSPEED_ADDR);
  358. if(cTableCnt >= QD_PARAM_TABLE_NUM)
  359. {
  360. cTableCnt = 0;
  361. QD_TABLE_VAVLE = 1;
  362. QD_TBDelay = dwTickCount + QD_PARAM_TB_TIME;
  363. }
  364. if((GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) || SingOneFlg)
  365. {
  366. bRunning = 0;
  367. QD_AutoStep = 0;
  368. SingOneFlg = 0;
  369. if(GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) QD_SetAlarmCode(QD_TOTAL_ALARM);
  370. }
  371. else
  372. {
  373. QD_AutoStep = 1;
  374. if(QD_PARAM_NOW_CNT >= QD_PARAM_ZHA_SHU)
  375. {
  376. QD_AutoDelay = dwTickCount + QD_PARAM_ZS_STOP_TIME + 50;
  377. QD_PARAM_NOW_CNT = 0;
  378. }
  379. else
  380. QD_AutoDelay = dwTickCount + QD_PARAM_CYCLE_DELAY;
  381. }
  382. }
  383. break;
  384. }
  385. }
  386. }
  387. void QueDuan_StepCheckStart(void)
  388. {
  389. // 启动
  390. if((START_IN_UP) || bStart || QD_bSingle)
  391. {
  392. bStart = 0;
  393. if(!bRunning && (QD_AutoStep == 0))
  394. {
  395. if(!QD_SHANG_MU_ORIGIN_IN)QD_SetAlarmCode(QD_SM_YUANWEI);
  396. else if(QD_XIA_MU_LIMIT_IN)QD_SetAlarmCode(QD_XM_DAOWEI);
  397. else if(GetAlarmCode(QD_ALARM_ADDR) != 0);
  398. else if(GetTotal(QD_TOTAL_ADDR) >= QD_PARAM_SET_TOTAL) QD_SetAlarmCode(QD_TOTAL_ALARM);
  399. else if(QD_BL_VAVLE)QD_SetAlarmCode(QD_BL_ALARM);
  400. else if(QD_SM_VAVLE)QD_SetAlarmCode(QD_SM_ALARM);
  401. else
  402. {
  403. bRunning = 1;
  404. QD_AutoStep = 1;
  405. if(QD_bSingle) SingOneFlg= 1;
  406. cZipCnt = 0;
  407. cTuiFangKuaiCnt = 0;
  408. if(QD_PARAM_TL_MODE)
  409. {
  410. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  411. }
  412. }
  413. }
  414. QD_bSingle = 0;
  415. }
  416. //停止
  417. if(STOP_IN_UP || bStop)
  418. {
  419. bStop = 0;
  420. user_datas[127] = 0;
  421. /* if(bRunning)
  422. {
  423. if(SingOneFlg)
  424. {
  425. bRunning = 0;
  426. QD_XiaQieStep = 0;
  427. QD_AutoStep = 0;
  428. QD_MotorStep = 0;
  429. QD_TuiLianStep = 0;
  430. QD_TuiFangKuaiStep = 0;
  431. QD_YuanDianStep = 0;
  432. QD_BinLianStep = 0;
  433. SingOneFlg = 0;
  434. QD_JD_VAVEL = 0;
  435. QD_SM_VAVLE = 0;
  436. QD_XM_VAVLE = 0;
  437. QD_YD_VAVLE = 0;
  438. QD_XHG_VAVLE = 0;
  439. // QD_CS_OUT = 0;
  440. QD_TL_VAVLE = 0;
  441. QD_SZ_OUT = 1;
  442. QD_GZ_VAVLE = 0;
  443. QD_YBD_VAVLE = 0;
  444. QD_TFK_VAVEL = 0;
  445. QD_TABLE_VAVLE = 0;
  446. QD_BL_VAVLE = 0;
  447. QD_AutoDelay = dwTickCount;
  448. QD_MotorDelay = dwTickCount;
  449. QD_XiaQieDelay = dwTickCount;
  450. QD_KaDaiDelay = dwTickCount;
  451. QD_CSDelay = dwTickCount;
  452. QD_TBDelay = dwTickCount;
  453. QD_TFKDelay = dwTickCount;
  454. QD_TLDelay = dwTickCount;
  455. QD_CheckDelay = dwTickCount;
  456. AxisDecStop(X_AXIS);
  457. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  458. }
  459. else
  460. {
  461. SingOneFlg = 1;
  462. }
  463. }
  464. else
  465. {
  466. bRunning = 0;
  467. QD_XiaQieStep = 0;
  468. QD_AutoStep = 0;
  469. QD_MotorStep = 0;
  470. QD_TuiLianStep = 0;
  471. QD_TuiFangKuaiStep = 0;
  472. QD_YuanDianStep = 0;
  473. QD_AutoDelay = dwTickCount;
  474. QD_MotorDelay = dwTickCount;
  475. QD_XiaQieDelay = dwTickCount;
  476. QD_KaDaiDelay = dwTickCount;
  477. QD_CSDelay = dwTickCount;
  478. QD_TBDelay = dwTickCount;
  479. QD_TFKDelay = dwTickCount;
  480. QD_TLDelay = dwTickCount;
  481. QD_CheckDelay = dwTickCount;
  482. SingOneFlg = 0;
  483. QD_JD_VAVEL = 0;
  484. QD_SM_VAVLE = 0;
  485. QD_XM_VAVLE = 0;
  486. QD_YD_VAVLE = 0;
  487. QD_TFK_VAVEL= 0;
  488. QD_TL_VAVLE = 0;
  489. QD_YBD_VAVLE = 0;
  490. //QD_CS_OUT = 0;
  491. QD_XiaQieStep = 0;
  492. QD_MotorStep = 0;
  493. QD_TuiLianStep = 0;
  494. QD_TuiFangKuaiStep = 0;
  495. QD_SZ_OUT = 1;
  496. QD_GZ_VAVLE = 0;
  497. QD_TABLE_VAVLE = 0;
  498. QD_XHG_VAVLE = 0;
  499. AxisDecStop(X_AXIS);
  500. QD_YuanDianStep = 0;
  501. QD_BinLianStep = 0;
  502. QD_BL_VAVLE = 0;
  503. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  504. }*/
  505. if(bRunning)
  506. {
  507. bRunning = 0;
  508. QD_XiaQieStep = 0;
  509. QD_AutoStep = 0;
  510. QD_MotorStep = 0;
  511. QD_TuiLianStep = 0;
  512. QD_TuiFangKuaiStep = 0;
  513. QD_YuanDianStep = 0;
  514. QD_AutoDelay = dwTickCount;
  515. QD_MotorDelay = dwTickCount;
  516. QD_XiaQieDelay = dwTickCount;
  517. QD_KaDaiDelay = dwTickCount;
  518. QD_CSDelay = dwTickCount;
  519. QD_TBDelay = dwTickCount;
  520. QD_TFKDelay = dwTickCount;
  521. QD_TLDelay = dwTickCount;
  522. QD_CheckDelay = dwTickCount;
  523. dwTickCount = QD_TBDelay;
  524. SingOneFlg = 0;
  525. QD_JD_VAVEL = 0;
  526. QD_SM_VAVLE = 0;
  527. QD_XM_VAVLE = 0;
  528. QD_YD_VAVLE = 0;
  529. QD_TFK_VAVEL= 0;
  530. QD_TL_VAVLE = 0;
  531. QD_YBD_VAVLE = 0;
  532. QD_CS_OUT = 0;
  533. QD_XiaQieStep = 0;
  534. QD_MotorStep = 0;
  535. QD_TuiLianStep = 0;
  536. QD_TuiFangKuaiStep = 0;
  537. //QD_SZ_OUT = 1;
  538. QD_GZ_VAVLE = 0;
  539. QD_TABLE_VAVLE = 0;
  540. QD_XHG_VAVLE = 0;
  541. AxisDecStop(X_AXIS);
  542. QD_YuanDianStep = 0;
  543. QD_BinLianStep = 0;
  544. QD_BL_VAVLE = 0;
  545. user_datas[121] = 0;
  546. user_datas[122] = 0;
  547. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  548. QD_CheckLengthStep = 0;
  549. }
  550. else
  551. {
  552. bRunning = 0;
  553. QD_XiaQieStep = 0;
  554. QD_AutoStep = 0;
  555. QD_MotorStep = 0;
  556. QD_TuiLianStep = 0;
  557. QD_TuiFangKuaiStep = 0;
  558. QD_YuanDianStep = 0;
  559. QD_AutoDelay = dwTickCount;
  560. QD_MotorDelay = dwTickCount;
  561. QD_XiaQieDelay = dwTickCount;
  562. QD_KaDaiDelay = dwTickCount;
  563. QD_CSDelay = dwTickCount;
  564. QD_TBDelay = dwTickCount;
  565. QD_TFKDelay = dwTickCount;
  566. QD_TLDelay = dwTickCount;
  567. QD_CheckDelay = dwTickCount;
  568. dwTickCount = QD_TBDelay;
  569. SingOneFlg = 0;
  570. QD_JD_VAVEL = 0;
  571. QD_SM_VAVLE = 0;
  572. QD_XM_VAVLE = 0;
  573. QD_YD_VAVLE = 0;
  574. QD_TFK_VAVEL= 0;
  575. QD_TL_VAVLE = 0;
  576. QD_YBD_VAVLE = 0;
  577. QD_CS_OUT = 0;
  578. QD_XiaQieStep = 0;
  579. QD_MotorStep = 0;
  580. QD_TuiLianStep = 0;
  581. QD_TuiFangKuaiStep = 0;
  582. QD_SZ_OUT = 1;
  583. QD_GZ_VAVLE = 0;
  584. QD_TABLE_VAVLE = 0;
  585. QD_XHG_VAVLE = 0;
  586. AxisDecStop(X_AXIS);
  587. QD_YuanDianStep = 0;
  588. QD_BinLianStep = 0;
  589. QD_BL_VAVLE = 0;
  590. user_datas[121] = 0;
  591. user_datas[122] = 0;
  592. if(GetAlarmCode(QD_ALARM_ADDR) != 0)SetAlarmCode(QD_ALARM_ADDR,0);
  593. QD_CheckLengthStep = 0;
  594. }
  595. }
  596. if(bAlarmStop)
  597. {
  598. bAlarmStop = 0;
  599. QD_XiaQieStep = 0;
  600. QD_AutoStep = 0;
  601. QD_MotorStep = 0;
  602. QD_TuiLianStep = 0;
  603. QD_TuiFangKuaiStep = 0;
  604. QD_YuanDianStep = 0;
  605. QD_XiaQieStep = 0;
  606. QD_MotorStep = 0;
  607. QD_TuiLianStep = 0;
  608. QD_TuiFangKuaiStep = 0;
  609. QD_AutoDelay = dwTickCount;
  610. QD_MotorDelay = dwTickCount;
  611. QD_XiaQieDelay = dwTickCount;
  612. QD_KaDaiDelay = dwTickCount;
  613. QD_CSDelay = dwTickCount;
  614. QD_TBDelay = dwTickCount;
  615. QD_TFKDelay = dwTickCount;
  616. QD_TLDelay = dwTickCount;
  617. QD_CheckDelay = dwTickCount;
  618. SingOneFlg = 0;
  619. bRunning = 0;
  620. AxisDecStop(X_AXIS);
  621. dwTickCount = QD_TBDelay;
  622. QD_TABLE_VAVLE = 0;
  623. QD_CheckLengthStep = 0;
  624. }
  625. }
  626. void QueDuan_CheckLength(long zip_length)
  627. {
  628. static long start_dist,checkdelay_buff;
  629. switch(QD_CheckLengthStep)
  630. {
  631. case 0:break;
  632. case 1:
  633. start_dist = cRealPos;
  634. QD_CheckLengthStep = 2;
  635. dwSaveLength = 0;
  636. break;
  637. case 2:
  638. if(QD_GUO_LIAN_IN_UP)
  639. {
  640. QD_CheckLengthStep = 3;
  641. checkdelay_buff = cRealPos;
  642. }
  643. break;
  644. case 3:
  645. 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)))
  646. {
  647. if(QD_GUO_LIAN_IN_UP)
  648. {
  649. dwSaveLength = cRealPos - start_dist;
  650. // QD_CheckLengthStep = 0;
  651. }
  652. if(QD_GUO_LIAN_IN_DW)
  653. {
  654. dwSaveLength = cRealPos - start_dist;
  655. // QD_CheckLengthStep = 0;
  656. }
  657. }
  658. break;
  659. }
  660. }
  661. void QueDuan_Motor_CS(void)
  662. {
  663. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  664. user_datas[124]= QD_MotorStep;
  665. user_datas[125]= dwSaveLength;
  666. user_datas[123] = length_buff;
  667. user_datas[127] = cRealPos - save_buff;
  668. // user_datas[126] = go_buff - cRealPos;
  669. // user_datas[121] = QD_XiaQieStep;
  670. /* if(cCheckLengthEn)
  671. {
  672. if(QD_GUO_LIAN_IN_DW)
  673. {
  674. if((cRealPos - back_buff) >= (length_buff+QD_PARAM_ERROR_LENGTH-QD_PARAM_MOTOR_DELAY_LENGTH))QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  675. if((cRealPos - back_buff) <= (length_buff-QD_PARAM_ERROR_LENGTH-QD_PARAM_MOTOR_DELAY_LENGTH))QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  676. cCheckLengthEn = 0;
  677. }
  678. } */
  679. QueDuan_CheckLength(length_buff);
  680. switch(QD_MotorStep)
  681. {
  682. case 0:
  683. break;
  684. case 1: // 前点定位数控模式
  685. if(QD_SZ_OUT)
  686. {
  687. QD_SZ_OUT = 0;
  688. QD_MotorDelay = dwTickCount + 50;
  689. }
  690. // if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  691. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE && !QD_PARAM_TL_MODE)QD_TuiLianStep = 1;
  692. QD_MotorStep = 2;
  693. break;
  694. case 2:
  695. if(dwTickCount >= QD_MotorDelay)
  696. {
  697. if(QD_QIAN_LIMIT_IN)
  698. {
  699. // if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_P;
  700. MV_Set_Acc_CPU(X_AXIS, 10);
  701. AxisMovePos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_ON_BACK_LENGTH);
  702. QD_MotorDelay = dwTickCount + 1000;
  703. }
  704. QD_MotorStep = 3;
  705. QD_JD_VAVEL = 0;
  706. }
  707. break;
  708. case 3:
  709. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  710. {
  711. if(cZipCnt == 0)
  712. {
  713. // if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  714. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P); //第一条走低速
  715. }
  716. else
  717. {
  718. // if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  719. AxisMoveTwoPos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,(length_buff - QD_PARAM_Go_LOW_SPEED_LENGTH + QD_PARAM_BACK_LENGTH +QD_PARAM_SJZ_LENGTH),QD_PARAM_GO_LOW_SPEED,0xFFFFFF,QD_DIR_P);//第二条开始走两段速
  720. }
  721. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  722. QD_MotorStep = 4;
  723. }
  724. break;
  725. case 4:
  726. if(QD_QIAN_LIMIT_IN_UP)
  727. {
  728. AxisEgmStop(X_AXIS);
  729. QD_MotorStep = 5;
  730. }
  731. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  732. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  733. break;
  734. case 5:
  735. if(!X_DRV)
  736. {
  737. QD_MotorDelay = dwTickCount;
  738. QD_MotorStep = 6;
  739. }
  740. break;
  741. case 6:
  742. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0))
  743. {
  744. if(bRunning)
  745. {
  746. QD_JD_VAVEL = 1;
  747. }
  748. QD_MotorStep = 7;
  749. QD_MotorDelay = dwTickCount + 100;
  750. }
  751. break;
  752. case 7:
  753. if(dwTickCount >= QD_MotorDelay)
  754. {
  755. QD_YBD_VAVLE = 0;
  756. QD_TL_VAVLE = 0;
  757. QD_MotorStep = 0;
  758. }
  759. break;
  760. case 20:// 后退使用电机定长
  761. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  762. QD_MotorStep = 21;
  763. break;
  764. case 21:
  765. if(dwTickCount >= QD_MotorDelay)
  766. {
  767. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  768. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-QD_PARAM_ZIPPER_LENGTH);
  769. QD_MotorStep = 22;
  770. }
  771. break;
  772. case 22:
  773. if(!X_DRV)
  774. {
  775. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_FZ;
  776. QD_MotorStep = 23;
  777. }
  778. break;
  779. case 23:
  780. if(dwTickCount >= QD_MotorDelay)
  781. {
  782. // if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_P;
  783. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  784. QD_MotorStep = 24;
  785. }
  786. break;
  787. case 24:
  788. if(!X_DRV)
  789. {
  790. QD_MotorStep = 0;
  791. QD_MotorDelay = dwTickCount;
  792. }
  793. break;
  794. case 30:
  795. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  796. QD_MotorStep = 31;
  797. if(QD_PARAM_BL_ENABLE)QD_BinLianStep = 1;
  798. break;
  799. case 31: // 后退使用钩针定长
  800. if(dwTickCount >= QD_MotorDelay)
  801. {
  802. save_buff = cRealPos;
  803. back_buff = cRealPos;
  804. if(QD_PARAM_DEC_MODE == 0)
  805. {
  806. if(QD_PARAM_BACK_MODE)
  807. {
  808. if(cZipCnt < 2)
  809. {
  810. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P);
  811. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  812. QD_MotorStep = 32;
  813. }
  814. else
  815. {
  816. // if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  817. AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_P);
  818. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  819. QD_MotorStep = 32;
  820. }
  821. }
  822. else
  823. {
  824. // if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  825. AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_P);
  826. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  827. QD_MotorStep = 32;
  828. }
  829. }
  830. else
  831. {
  832. if(cZipCnt < 2)
  833. {
  834. MoveAction_Const_AccDec(X_AXIS,QD_DIR_P,QD_PARAM_FIRST_SPEED,1,10,20);
  835. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  836. QD_MotorStep = 32;
  837. }
  838. else
  839. {
  840. gouzhen_buff = cRealPos;
  841. MV_Set_Acc_CPU(X_AXIS, 10);
  842. AxisMovePosAccDec(X_AXIS,QD_PARAM_BACK_SPEED,-length_buff,1,10,20);
  843. // AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-length_buff);
  844. 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,10)));
  845. QD_MotorDelay = dwTickCount;
  846. QD_MotorStep = 33;
  847. QD_CheckLengthStep = 1;
  848. }
  849. }
  850. }
  851. break;
  852. case 32:
  853. if(QD_PARAM_DEC_MODE)
  854. {
  855. if(cZipCnt < 2)
  856. {
  857. if(QD_GUO_LIAN_IN_UP)
  858. {
  859. checkdelay_buff = cRealPos;
  860. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  861. QD_MotorStep = 33;
  862. QD_MotorDelay = dwTickCount = + QD_PARAM_GZ_DELAY;
  863. QD_XMDelay = dwTickCount = + QD_PARAM_DELAY_XM;
  864. }
  865. else if(dwTickCount >= QD_MotorDelay)
  866. {
  867. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  868. }
  869. }
  870. else
  871. {
  872. dwTickCount = QD_MotorDelay;
  873. QD_MotorStep = 34;
  874. }
  875. }
  876. else
  877. {
  878. if(QD_PARAM_BACK_MODE)
  879. {
  880. if(cZipCnt < 2)
  881. {
  882. if(QD_GUO_LIAN_IN_UP)
  883. {
  884. checkdelay_buff = cRealPos;
  885. QD_MotorDelay = dwTickCount;
  886. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  887. QD_MotorStep = 33;
  888. }
  889. else if(dwTickCount >= QD_MotorDelay)
  890. {
  891. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  892. }
  893. }
  894. else
  895. {
  896. 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,10)))))
  897. {
  898. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  899. }
  900. if(QD_GUO_LIAN_IN_UP)
  901. {
  902. checkdelay_buff = cRealPos;
  903. QD_MotorDelay = dwTickCount;
  904. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  905. QD_MotorStep = 33;
  906. }
  907. else if(dwTickCount >= QD_MotorDelay)
  908. {
  909. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  910. }
  911. }
  912. }
  913. else
  914. {
  915. if(QD_GUO_LIAN_IN_UP)
  916. {
  917. checkdelay_buff = cRealPos;
  918. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  919. QD_MotorDelay = dwTickCount;
  920. QD_MotorStep = 33;
  921. }
  922. else if(dwTickCount >= QD_MotorDelay)
  923. {
  924. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  925. }
  926. }
  927. }
  928. break;
  929. case 33:
  930. if((cZipCnt < 2) || (QD_PARAM_DEC_MODE == 0))
  931. {
  932. if(QD_PARAM_XM_ENABLE)
  933. {
  934. if(dwTickCount >= QD_XMDelay)QD_XM_VAVLE = 1;
  935. }
  936. if(dwTickCount >= QD_MotorDelay)
  937. {
  938. QD_GZ_VAVLE = 1;
  939. if(QD_PARAM_XM_ENABLE)QD_XM_VAVLE = 1;
  940. QD_MotorStep = 34;
  941. }
  942. }
  943. else
  944. {
  945. if((cRealPos - back_buff) > (length_buff - QD_PARAM_Back_LOW_SPEED_LENGTH))
  946. {
  947. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  948. QD_MotorStep = 34;
  949. }
  950. }
  951. break;
  952. case 34:
  953. if((cZipCnt < 2) || (QD_PARAM_DEC_MODE == 0))
  954. {
  955. 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)))
  956. {
  957. if(QD_GUO_LIAN_IN_DW)
  958. {
  959. gou_zhen_buff = cRealPos;
  960. QD_MotorStep = 35;
  961. }
  962. }
  963. }
  964. else
  965. {
  966. if(QD_PARAM_XM_ENABLE)
  967. {
  968. if((cRealPos - gouzhen_buff) >= (length_buff - (QD_PARAM_DELAY_XM_LENGTH)))QD_XM_VAVLE = 1;
  969. }
  970. if(QD_PARAM_GOUZHEN_LENGTH != 0)
  971. {
  972. // if((cRealPos - gouzhen_buff) >= (length_buff - (QD_PARAM_DELAY_XM_LENGTH)))QD_XM_VAVLE = 1;
  973. if((cRealPos - gouzhen_buff) >= (length_buff - QD_PARAM_GOUZHEN_LENGTH))
  974. {
  975. if(QD_PARAM_XM_ENABLE) QD_XM_VAVLE = 1;
  976. QD_GZ_VAVLE = 1;
  977. QD_MotorStep = 36;
  978. }
  979. }
  980. else
  981. {
  982. if((cRealPos - gouzhen_buff) >= (length_buff - (QD_PARAM_DELAY_XM_LENGTH)))
  983. {
  984. if(QD_PARAM_XM_ENABLE) QD_XM_VAVLE = 1;
  985. QD_MotorStep = 36;
  986. }
  987. }
  988. }
  989. user_datas[121] = gouzhen_buff;
  990. user_datas[126] = QD_PARAM_DELAY_XM_LENGTH;
  991. break;
  992. case 35:
  993. if(QD_GUO_LIAN_IN_DW)
  994. {
  995. gou_zhen_buff = cRealPos;
  996. }
  997. if(QD_GUO_LIAN_IN_UP)
  998. {
  999. gou_zhen_buff = cRealPos;
  1000. }
  1001. if((cRealPos - gou_zhen_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  1002. {
  1003. AxisEgmStop(X_AXIS);
  1004. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1005. QD_MotorStep = 36;
  1006. }
  1007. break;
  1008. case 36:
  1009. if(!X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  1010. {
  1011. if(QD_PARAM_GOUZHEN_LENGTH == 0)QD_GZ_VAVLE = 1;
  1012. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1013. QD_MotorStep = 37;
  1014. }
  1015. break;
  1016. case 37:
  1017. // if(QD_XIA_MU_LIMIT_IN)
  1018. {
  1019. QD_MotorStep = 38;
  1020. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  1021. }
  1022. // else if(dwTickCount >= QD_MotorDelay) QD_SetAlarmCode(QD_XM_DAOWEI);
  1023. break;
  1024. case 38:
  1025. if(dwTickCount >= QD_MotorDelay)
  1026. {
  1027. QD_TFK_VAVEL = 1;
  1028. QD_MotorStep = 39;
  1029. }
  1030. break;
  1031. case 39:
  1032. if(!X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  1033. {
  1034. if(cZipCnt == 1)
  1035. {
  1036. length_buff = cRealPos - save_buff;
  1037. SetData32bits(1,length_buff + QD_PARAM_OFFSET_LENGTH);
  1038. }
  1039. if(cZipCnt == 0)
  1040. {
  1041. go_length_buff = cRealPos - save_buff;
  1042. }
  1043. if(QD_PARAM_DEC_MODE)
  1044. {
  1045. if(((dwSaveLength > (length_buff-QD_PARAM_MOTOR_DELAY_LENGTH+QD_PARAM_ERROR_LENGTH+20)) || (dwSaveLength < (length_buff-QD_PARAM_MOTOR_DELAY_LENGTH-QD_PARAM_ERROR_LENGTH-20))) && (QD_PARAM_BACK_MODE == 1) && (cZipCnt >= 2))
  1046. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1047. else
  1048. QD_MotorStep = 0;
  1049. }
  1050. else
  1051. {
  1052. if((((cRealPos - save_buff) > (length_buff+QD_PARAM_ERROR_LENGTH+20)) || ((cRealPos - save_buff) < (length_buff-QD_PARAM_ERROR_LENGTH-20))) && (QD_PARAM_BACK_MODE == 1) && (cZipCnt >= 2))
  1053. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1054. else
  1055. QD_MotorStep = 0;
  1056. }
  1057. }
  1058. break;
  1059. case 40:
  1060. QD_MotorDelay = dwTickCount + QD_PARAM_CUT_BACK_DELAY;
  1061. QD_MotorStep = 41;
  1062. break;
  1063. case 41:
  1064. if(dwTickCount >= QD_MotorDelay)
  1065. {
  1066. jz_buff = cRealPos;
  1067. if(QD_PARAM_SJZ_LENGTH == 0)
  1068. {
  1069. QD_JD_VAVEL = 0;
  1070. }
  1071. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_SJ_TIME;
  1072. QD_MotorStep = 45;
  1073. }
  1074. break;
  1075. case 45: if((dwTickCount >= QD_MotorDelay) || (QD_JD_VAVEL == 1))
  1076. {
  1077. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH));
  1078. QD_MotorStep = 43;
  1079. }
  1080. break;
  1081. case 43:
  1082. // 切断完成后拉电机动作
  1083. if(dwTickCount >= QD_MotorDelay)
  1084. {
  1085. if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - jz_buff)))
  1086. {
  1087. user_datas[126] = cRealPos - jz_buff;
  1088. QD_JD_VAVEL = 0;
  1089. QD_MotorStep = 44;
  1090. }
  1091. else if(!X_DRV)
  1092. {
  1093. QD_JD_VAVEL = 0;
  1094. QD_MotorStep = 44;
  1095. }
  1096. }
  1097. break;
  1098. case 44: // 切断完成后拉电机动作
  1099. if(!X_DRV)
  1100. {
  1101. QD_MotorStep = 0;
  1102. QD_MotorDelay = dwTickCount;
  1103. }
  1104. break;
  1105. case 61: // 前点定位数控模式
  1106. if(QD_SZ_OUT)
  1107. {
  1108. QD_SZ_OUT = 0;
  1109. QD_MotorDelay = dwTickCount + 50;
  1110. }
  1111. if(QD_PARAM_TL_MODE)
  1112. {
  1113. }
  1114. else
  1115. {
  1116. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE)QD_TuiLianStep = 1;
  1117. }
  1118. QD_MotorStep = 62;
  1119. break;
  1120. case 62:
  1121. if(dwTickCount >= QD_MotorDelay)
  1122. {
  1123. if(QD_QIAN_LIMIT_IN)
  1124. {
  1125. MV_Set_Acc_CPU(X_AXIS, 10);
  1126. AxisMovePos(X_AXIS,QD_PARAM_FIRST_SPEED,-QD_PARAM_ON_BACK_LENGTH);
  1127. QD_MotorDelay = dwTickCount + 1000;
  1128. }
  1129. QD_MotorStep = 63;
  1130. QD_JD_VAVEL = 0;
  1131. }
  1132. break;
  1133. case 63:
  1134. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  1135. {
  1136. go_buff = cRealPos;
  1137. if(cZipCnt > 0)
  1138. {
  1139. MoveAction_Const_Stop_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED,1,10,20);
  1140. }
  1141. else
  1142. {
  1143. MoveAction_Const_Stop_AccDec(X_AXIS, QD_DIR_N,QD_PARAM_FIRST_GO_HIGHSPEED,1,10,20);
  1144. }
  1145. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1146. QD_MotorStep = 64;
  1147. }
  1148. break;
  1149. case 64:
  1150. if(QD_PARAM_GO_MODE)
  1151. {
  1152. if(cZipCnt > 0)
  1153. {
  1154. 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))
  1155. {
  1156. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1157. QD_MotorStep =65;
  1158. }
  1159. }
  1160. else
  1161. {
  1162. if(QD_QIAN_DEC_IN_UP)
  1163. {
  1164. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1165. QD_MotorStep =65;
  1166. }
  1167. }
  1168. }
  1169. else
  1170. {
  1171. QD_MotorStep =65;
  1172. }
  1173. break;
  1174. case 65:
  1175. if(QD_QIAN_LIMIT_IN_UP)
  1176. {
  1177. if(QD_PARAM_DAO_MODE)
  1178. {
  1179. dandao_buff = cRealPos;
  1180. QD_MotorStep = 70;
  1181. }
  1182. else
  1183. {
  1184. AxisEgmStop(X_AXIS);
  1185. QD_MotorStep = 66;
  1186. }
  1187. }
  1188. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1189. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1190. break;
  1191. case 70:
  1192. if((dandao_buff - cRealPos) >= QD_PARAM_DANDAO_MODE_LENGTH)
  1193. {
  1194. AxisEgmStop(X_AXIS);
  1195. QD_MotorStep = 66;
  1196. }
  1197. break;
  1198. case 66:
  1199. if(!X_DRV)
  1200. {
  1201. QD_MotorDelay = dwTickCount;
  1202. QD_MotorStep = 67;
  1203. }
  1204. break;
  1205. case 67:
  1206. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1207. {
  1208. if(bRunning)
  1209. {
  1210. QD_JD_VAVEL = 1;
  1211. }
  1212. QD_MotorStep = 68;
  1213. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1214. }
  1215. break;
  1216. case 68:
  1217. if(dwTickCount >= QD_MotorDelay)
  1218. {
  1219. QD_YD_VAVLE = 0;
  1220. QD_MotorStep = 0;
  1221. }
  1222. break;
  1223. }
  1224. }
  1225. //推方块动作
  1226. void QueDuan_TuiFangKuai(void)
  1227. {
  1228. }
  1229. void QueDuan_BingLian(void)
  1230. {
  1231. static long bl_pos_buff;
  1232. switch(QD_BinLianStep)
  1233. {
  1234. case 0:break;
  1235. case 1:
  1236. bl_pos_buff = cRealPos;
  1237. QD_BinLianStep = 2;
  1238. break;
  1239. case 2:
  1240. if((cRealPos - bl_pos_buff) >= QD_PARAM_DELAY_HL_LENGTH)
  1241. {
  1242. QD_BL_VAVLE = 1;
  1243. QD_BinLianStep = 3;
  1244. }
  1245. break;
  1246. case 3:
  1247. if(QD_SM_VAVLE)QD_BL_VAVLE = 0;
  1248. break;
  1249. default:;
  1250. }
  1251. }
  1252. void QueDuan_Motor_QD(void)
  1253. {
  1254. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  1255. user_datas[124]= QD_MotorStep;
  1256. // user_datas[125]= go_length_buff;
  1257. // user_datas[123] = length_buff;
  1258. user_datas[127] = cRealPos;
  1259. user_datas[126] = go_buff - cRealPos;
  1260. user_datas[121] = dwSaveLength;
  1261. if(QD_GUO_LIAN_IN_DW)user_datas[122]++;
  1262. switch(QD_MotorStep)
  1263. {
  1264. case 0:
  1265. break;
  1266. case 1: // 前点定位数控模式
  1267. if(QD_SZ_OUT)
  1268. {
  1269. QD_SZ_OUT = 0;
  1270. QD_MotorDelay = dwTickCount + 50;
  1271. }
  1272. // if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1273. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE && !QD_PARAM_TL_MODE)QD_TuiLianStep = 1;
  1274. QD_MotorStep = 2;
  1275. break;
  1276. case 2:
  1277. if(dwTickCount >= QD_MotorDelay)
  1278. {
  1279. if(QD_QIAN_LIMIT_IN)
  1280. {
  1281. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_P;
  1282. MV_Set_Acc_CPU(X_AXIS, 10);
  1283. AxisMovePos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,QD_PARAM_ON_BACK_LENGTH);
  1284. QD_MotorDelay = dwTickCount + 1000;
  1285. }
  1286. QD_MotorStep = 3;
  1287. QD_JD_VAVEL = 0;
  1288. }
  1289. break;
  1290. case 3:
  1291. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  1292. {
  1293. if(cZipCnt == 0)
  1294. {
  1295. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1296. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P); //第一条走低速
  1297. }
  1298. else
  1299. {
  1300. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1301. AxisMoveTwoPos(X_AXIS,QD_PARAM_GO_HIGH_SPEED,(length_buff - QD_PARAM_Go_LOW_SPEED_LENGTH + QD_PARAM_BACK_LENGTH +QD_PARAM_SJZ_LENGTH),QD_PARAM_GO_LOW_SPEED,0xFFFFFF,QD_DIR_P);//第二条开始走两段速
  1302. }
  1303. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1304. QD_MotorStep = 4;
  1305. }
  1306. break;
  1307. case 4:
  1308. if(QD_QIAN_LIMIT_IN_UP)
  1309. {
  1310. AxisEgmStop(X_AXIS);
  1311. QD_MotorStep = 5;
  1312. }
  1313. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1314. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1315. break;
  1316. case 5:
  1317. if(!X_DRV)
  1318. {
  1319. QD_MotorDelay = dwTickCount;
  1320. QD_MotorStep = 6;
  1321. }
  1322. break;
  1323. case 6:
  1324. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0))
  1325. {
  1326. if(bRunning)
  1327. {
  1328. QD_JD_VAVEL = 1;
  1329. }
  1330. QD_MotorStep = 7;
  1331. QD_MotorDelay = dwTickCount + 100;
  1332. }
  1333. break;
  1334. case 7:
  1335. if(dwTickCount >= QD_MotorDelay)
  1336. {
  1337. QD_YBD_VAVLE = 0;
  1338. QD_TL_VAVLE = 0;
  1339. QD_MotorStep = 0;
  1340. }
  1341. break;
  1342. case 20:// 后退使用电机定长
  1343. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1344. QD_MotorStep = 21;
  1345. break;
  1346. case 21:
  1347. if(dwTickCount >= QD_MotorDelay)
  1348. {
  1349. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_N;
  1350. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-QD_PARAM_ZIPPER_LENGTH);
  1351. QD_MotorStep = 22;
  1352. }
  1353. break;
  1354. case 22:
  1355. if(!X_DRV)
  1356. {
  1357. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_FZ;
  1358. QD_MotorStep = 23;
  1359. }
  1360. break;
  1361. case 23:
  1362. if(dwTickCount >= QD_MotorDelay)
  1363. {
  1364. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_DIR_P;
  1365. AxisMovePos(X_AXIS,QD_PARAM_GO_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  1366. QD_MotorStep = 24;
  1367. }
  1368. break;
  1369. case 24:
  1370. if(!X_DRV)
  1371. {
  1372. QD_MotorStep = 0;
  1373. QD_MotorDelay = dwTickCount;
  1374. }
  1375. break;
  1376. case 30:
  1377. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1378. QD_MotorStep = 31;
  1379. if(QD_PARAM_BL_ENABLE)QD_BinLianStep = 1;
  1380. break;
  1381. case 31: // 后退使用钩针定长
  1382. if(dwTickCount >= QD_MotorDelay)
  1383. {
  1384. save_buff = cRealPos;
  1385. back_buff = cRealPos;
  1386. SetAccTime(X_AXIS,5);
  1387. SetDecTime(X_AXIS,5);
  1388. if(QD_PARAM_DEC_MODE == 0)
  1389. {
  1390. if(QD_PARAM_BACK_MODE)
  1391. {
  1392. if(cZipCnt < 2)
  1393. {
  1394. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P);
  1395. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1396. QD_MotorStep = 32;
  1397. }
  1398. else
  1399. {
  1400. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1401. AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_P);
  1402. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1403. QD_MotorStep = 32;
  1404. }
  1405. }
  1406. else
  1407. {
  1408. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1409. AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_P);
  1410. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1411. QD_MotorStep = 32;
  1412. }
  1413. }
  1414. else
  1415. {
  1416. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1417. if(cZipCnt < 2)
  1418. {
  1419. QD_XHG_VAVLE = 0;
  1420. AxisContinueMove(X_AXIS,QD_PARAM_FIRST_SPEED,QD_DIR_P);
  1421. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1422. QD_MotorStep = 32;
  1423. }
  1424. else
  1425. {
  1426. gouzhen_buff = cRealPos;
  1427. QD_XHG_VAVLE = 1;
  1428. //AxisMoveTwoPos(X_AXIS,QD_PARAM_BACK_SPEED,(length_buff - QD_PARAM_Back_LOW_SPEED_LENGTH),QD_PARAM_GO_LOW_SPEED,QD_PARAM_Back_LOW_SPEED_LENGTH,QD_DIR_N);
  1429. MV_Set_Acc_CPU(X_AXIS, 10);
  1430. AxisMovePos(X_AXIS,QD_PARAM_BACK_SPEED,-length_buff);
  1431. 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,10)));
  1432. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1433. QD_MotorStep = 33;
  1434. }
  1435. // AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_N);
  1436. }
  1437. }
  1438. break;
  1439. case 32:
  1440. if(QD_PARAM_DEC_MODE)
  1441. {
  1442. if(cZipCnt < 2)
  1443. {
  1444. if(QD_GUO_LIAN_IN_UP)
  1445. {
  1446. checkdelay_buff = cRealPos;
  1447. QD_MotorDelay = dwTickCount;
  1448. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1449. QD_MotorStep = 33;
  1450. }
  1451. else if(dwTickCount >= QD_MotorDelay)
  1452. {
  1453. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1454. }
  1455. }
  1456. else
  1457. {
  1458. QD_MotorStep = 36;
  1459. }
  1460. }
  1461. else
  1462. {
  1463. if(QD_PARAM_BACK_MODE)
  1464. {
  1465. if(cZipCnt < 2)
  1466. {
  1467. if(QD_GUO_LIAN_IN_UP)
  1468. {
  1469. checkdelay_buff = cRealPos;
  1470. QD_MotorDelay = dwTickCount;
  1471. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1472. QD_MotorStep = 33;
  1473. }
  1474. else if(dwTickCount >= QD_MotorDelay)
  1475. {
  1476. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1477. }
  1478. }
  1479. else
  1480. {
  1481. 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,10)))))
  1482. {
  1483. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1484. }
  1485. if(QD_GUO_LIAN_IN_UP)
  1486. {
  1487. checkdelay_buff = cRealPos;
  1488. QD_MotorDelay = dwTickCount;
  1489. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1490. QD_MotorStep = 33;
  1491. }
  1492. else if(dwTickCount >= QD_MotorDelay)
  1493. {
  1494. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1495. }
  1496. }
  1497. }
  1498. else
  1499. {
  1500. if(QD_GUO_LIAN_IN_UP)
  1501. {
  1502. checkdelay_buff = cRealPos;
  1503. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1504. QD_MotorDelay = dwTickCount;
  1505. QD_MotorStep = 33;
  1506. }
  1507. else if(dwTickCount >= QD_MotorDelay)
  1508. {
  1509. QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1510. }
  1511. }
  1512. }
  1513. break;
  1514. case 33:
  1515. if((cZipCnt < 2) || (QD_PARAM_DEC_MODE == 0))
  1516. {
  1517. 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)))
  1518. {
  1519. if(QD_PARAM_GOUZHEN_LENGTH != 0)QD_GZ_VAVLE = 1;
  1520. QD_MotorStep = 34;
  1521. }
  1522. }
  1523. else
  1524. {
  1525. if((cRealPos - back_buff) > (length_buff - QD_PARAM_Back_LOW_SPEED_LENGTH))
  1526. {
  1527. if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1528. QD_MotorStep = 34;
  1529. }
  1530. }
  1531. break;
  1532. case 34:
  1533. if((cZipCnt < 2) || (QD_PARAM_DEC_MODE == 0))
  1534. {
  1535. if(QD_GUO_LIAN_IN_DW)
  1536. {
  1537. gou_zhen_buff = cRealPos;
  1538. QD_MotorStep = 35;
  1539. }
  1540. }
  1541. else
  1542. {
  1543. if(QD_PARAM_GOUZHEN_LENGTH != 0)
  1544. {
  1545. if((cRealPos - gouzhen_buff) >= (length_buff - QD_PARAM_GOUZHEN_LENGTH))
  1546. {
  1547. if(QD_PARAM_GOUZHEN_LENGTH != 0)QD_GZ_VAVLE = 1;
  1548. QD_MotorStep = 36;
  1549. }
  1550. }
  1551. else
  1552. {
  1553. QD_MotorStep = 36;
  1554. }
  1555. }
  1556. break;
  1557. case 35:
  1558. if(QD_GUO_LIAN_IN_DW)
  1559. {
  1560. gou_zhen_buff = cRealPos;
  1561. }
  1562. if(QD_GUO_LIAN_IN_UP)
  1563. {
  1564. gou_zhen_buff = cRealPos;
  1565. }
  1566. if((cRealPos - gou_zhen_buff) >= QD_PARAM_MOTOR_DELAY_LENGTH)
  1567. {
  1568. AxisEgmStop(X_AXIS);
  1569. QD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  1570. QD_MotorStep = 36;
  1571. }
  1572. break;
  1573. case 36:
  1574. if(!X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  1575. {
  1576. if(QD_PARAM_GOUZHEN_LENGTH == 0)QD_GZ_VAVLE = 1;
  1577. if(QD_PARAM_DEC_MODE == 0)QD_GZ_VAVLE = 1;
  1578. if(!QD_PARAM_TL_MODE)QD_YBD_VAVLE = 1;
  1579. QD_MotorDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  1580. QD_MotorStep = 37;
  1581. }
  1582. break;
  1583. case 37:
  1584. if(dwTickCount >= QD_MotorDelay)
  1585. {
  1586. QD_TFK_VAVEL = 1;
  1587. QD_MotorDelay = dwTickCount + 1000;
  1588. QD_MotorStep = 38;
  1589. }
  1590. break;
  1591. case 38:
  1592. if(QD_GOUZHEN_IN && !X_DRV && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)))
  1593. {
  1594. if(QD_PARAM_TL_MODE)QD_YBD_VAVLE = 1;
  1595. if(cZipCnt == 1)
  1596. {
  1597. length_buff = cRealPos - save_buff - QD_PARAM_OFFSET_LENGTH;
  1598. }
  1599. if(cZipCnt == 0)
  1600. {
  1601. go_length_buff = cRealPos - save_buff;
  1602. }
  1603. cTuiFangKuaiCnt = 0;
  1604. QD_MotorStep = 0;
  1605. }
  1606. else if(dwTickCount >= QD_MotorDelay)
  1607. {
  1608. if(cTuiFangKuaiCnt == 0)
  1609. {
  1610. QD_MotorStep = 100;
  1611. QD_TFK_VAVEL = 0;
  1612. cTuiFangKuaiCnt++;
  1613. QD_MotorDelay = dwTickCount + 1000;
  1614. }
  1615. else
  1616. QD_SetAlarmCode(QD_GZ_ALARM);
  1617. }
  1618. break;
  1619. case 100:
  1620. if(dwTickCount >= QD_MotorDelay)
  1621. {
  1622. QD_MotorStep = 37;
  1623. }
  1624. break;
  1625. case 40:
  1626. if(dwTickCount >= QD_MotorDelay)
  1627. {
  1628. jz_buff = cRealPos;
  1629. if(QD_PARAM_SJZ_LENGTH == 0)
  1630. {
  1631. QD_JD_VAVEL = 0;
  1632. }
  1633. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_SJ_TIME;
  1634. QD_MotorStep = 45;
  1635. }
  1636. break;
  1637. case 45: if((dwTickCount >= QD_MotorDelay) || (QD_JD_VAVEL == 1))
  1638. {
  1639. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH));
  1640. QD_MotorStep = 43;
  1641. }
  1642. break;
  1643. case 41:
  1644. if(!X_DRV)
  1645. {
  1646. QD_JD_VAVEL = 0;
  1647. QD_MotorDelay = dwTickCount + 20;
  1648. QD_MotorStep = 42;
  1649. }
  1650. break;
  1651. case 42:
  1652. if(dwTickCount >= QD_MotorDelay)
  1653. {
  1654. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1655. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_BACK_LENGTH));
  1656. QD_MotorStep = 44;
  1657. }
  1658. break;
  1659. case 43:
  1660. // 切断完成后拉电机动作
  1661. if(dwTickCount >= QD_MotorDelay)
  1662. {
  1663. if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - jz_buff)))
  1664. {
  1665. user_datas[126] = cRealPos - jz_buff;
  1666. QD_JD_VAVEL = 0;
  1667. QD_MotorStep = 44;
  1668. }
  1669. else if(!X_DRV)
  1670. {
  1671. QD_JD_VAVEL = 0;
  1672. QD_MotorStep = 44;
  1673. }
  1674. }
  1675. break;
  1676. case 44: // 切断完成后拉电机动作
  1677. if(!X_DRV)
  1678. {
  1679. QD_MotorStep = 0;
  1680. QD_MotorDelay = dwTickCount;
  1681. }
  1682. break;
  1683. case 61: // 前点定位数控模式
  1684. if(QD_SZ_OUT)
  1685. {
  1686. QD_SZ_OUT = 0;
  1687. QD_MotorDelay = dwTickCount + 50;
  1688. }
  1689. if(QD_PARAM_TL_MODE)
  1690. {
  1691. // if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  1692. }
  1693. else
  1694. {
  1695. if((QD_TuiLianStep == 0) && !QD_TL_VAVLE)QD_TuiLianStep = 1;
  1696. }
  1697. QD_MotorStep = 62;
  1698. break;
  1699. case 62:
  1700. if(dwTickCount >= QD_MotorDelay)
  1701. {
  1702. if(QD_QIAN_LIMIT_IN)
  1703. {
  1704. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_P;
  1705. MV_Set_Acc_CPU(X_AXIS, 10);
  1706. AxisMovePos(X_AXIS,QD_PARAM_FIRST_SPEED,-QD_PARAM_ON_BACK_LENGTH);
  1707. QD_MotorDelay = dwTickCount + 1000;
  1708. }
  1709. QD_MotorStep = 63;
  1710. QD_JD_VAVEL = 0;
  1711. }
  1712. break;
  1713. case 63:
  1714. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay))
  1715. {
  1716. //if(QD_PARAM_TL_MODE)QD_JZ_DIR = QD_YDIR_N;
  1717. go_buff = cRealPos;
  1718. if(cZipCnt > 0)
  1719. {
  1720. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED);//
  1721. }
  1722. else
  1723. {
  1724. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_LOW_SPEED);
  1725. }
  1726. // MoveAction_Const_Stop(X_AXIS, QD_DIR_P,QD_PARAM_GO_HIGH_SPEED);//
  1727. // AxisContinueMove(X_AXIS,QD_PARAM_GO_HIGH_SPEED,QD_DIR_P); //第一条走低速
  1728. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1729. QD_MotorStep =64;
  1730. }
  1731. break;
  1732. case 64:
  1733. if(QD_PARAM_GO_MODE)
  1734. {
  1735. if(cZipCnt > 0)
  1736. {
  1737. if(((go_buff - cRealPos) > (go_length_buff - (QD_PARAM_Go_LOW_SPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QD_PARAM_GO_HIGH_SPEED,QD_PARAM_GO_LOW_SPEED,30))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) || QD_QIAN_DEC_IN_UP)
  1738. {
  1739. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1740. QD_MotorStep =65;
  1741. }
  1742. }
  1743. else
  1744. {
  1745. // if(QD_QIAN_DEC_IN)
  1746. {
  1747. // if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);//AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1748. QD_MotorStep =65;
  1749. }
  1750. }
  1751. }
  1752. else
  1753. {
  1754. // if(QD_QIAN_DEC_IN)
  1755. {
  1756. // if(X_DRV)MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);//AxisChangeSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1757. QD_MotorStep =65;
  1758. }
  1759. }
  1760. break;
  1761. case 65:
  1762. if(QD_QIAN_LIMIT_IN_UP)
  1763. {
  1764. if(QD_PARAM_DAO_MODE)
  1765. {
  1766. dandao_buff = cRealPos;
  1767. QD_MotorStep = 70;
  1768. }
  1769. else
  1770. {
  1771. AxisEgmStop(X_AXIS);
  1772. QD_MotorStep = 66;
  1773. }
  1774. }
  1775. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1776. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  1777. break;
  1778. case 70:
  1779. if((dandao_buff - cRealPos) >= QD_PARAM_DANDAO_MODE_LENGTH)
  1780. {
  1781. AxisEgmStop(X_AXIS);
  1782. QD_MotorStep = 66;
  1783. }
  1784. break;
  1785. case 66:
  1786. if(!X_DRV)
  1787. {
  1788. QD_MotorDelay = dwTickCount;
  1789. QD_MotorStep = 67;
  1790. }
  1791. break;
  1792. case 67:
  1793. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  1794. {
  1795. if(bRunning)
  1796. {
  1797. QD_JD_VAVEL = 1;
  1798. }
  1799. QD_MotorStep = 68;
  1800. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1801. }
  1802. break;
  1803. case 68:
  1804. if(dwTickCount >= QD_MotorDelay)
  1805. {
  1806. QD_YBD_VAVLE = 0;
  1807. QD_TL_VAVLE = 0;
  1808. QD_MotorStep = 0;
  1809. }
  1810. break;
  1811. }
  1812. }
  1813. //不带过链感应长度输入电机长度
  1814. void QueDuan_Motor_NoGL(void)
  1815. {
  1816. static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  1817. user_datas[124]= QD_MotorStep;
  1818. // user_datas[125]= go_length_buff;
  1819. // user_datas[123] = length_buff;
  1820. // user_datas[127] = cRealPos;
  1821. // user_datas[126] = go_buff - cRealPos;
  1822. // user_datas[121] = QD_PARAM_GOUZHEN_LENGTH;
  1823. if(QD_GUO_LIAN_IN_DW)user_datas[122]++;
  1824. switch(QD_MotorStep)
  1825. {
  1826. case 30:
  1827. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  1828. QD_MotorStep = 31;
  1829. if(QD_PARAM_BL_ENABLE)QD_BinLianStep = 1;
  1830. break;
  1831. case 31:
  1832. if(dwTickCount >= QD_MotorDelay)
  1833. {
  1834. back_buff = cRealPos;
  1835. gou_zhen_buff = cRealPos;
  1836. save_buff = cRealPos;
  1837. // AxisContinueMove(X_AXIS,QD_PARAM_BACK_SPEED,QD_DIR_P);
  1838. MoveAction_Const_Back(X_AXIS,QD_DIR_P,QD_PARAM_BACK_SPEED,QD_PARAM_BACK_LOW_SPEED,PosToPulse(X_AXIS,((QD_PARAM_ZIPPER_LENGTH - 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))))));
  1839. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1840. QD_MotorStep = 33;
  1841. }
  1842. break;
  1843. case 32:
  1844. if(((cRealPos - gou_zhen_buff) > ((QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH) - QD_PARAM_GOUZHEN_LENGTH)) && !QD_GZ_VAVLE)
  1845. {
  1846. save_buff = cRealPos;
  1847. QD_GZ_VAVLE = 1;
  1848. }
  1849. if((cRealPos - back_buff) > ((QD_PARAM_ZIPPER_LENGTH - 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)))))
  1850. {
  1851. if(X_DRV)
  1852. {
  1853. MoveChangSpeed(X_AXIS,QD_PARAM_BACK_LOW_SPEED);
  1854. }
  1855. QD_MotorStep = 33;
  1856. }
  1857. else if(dwTickCount >= QD_MotorDelay)
  1858. {
  1859. QD_SetAlarmCode(QD_GZ_ALARM);
  1860. }
  1861. break;
  1862. case 33:
  1863. if(((cRealPos - gou_zhen_buff) > ((QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH) - QD_PARAM_GOUZHEN_LENGTH)) && !QD_GZ_VAVLE)
  1864. {
  1865. QD_GZ_VAVLE = 1;
  1866. }
  1867. if(QD_GOUZHEN_IN)
  1868. {
  1869. // AxisEgmStop(X_AXIS);
  1870. QD_YD_VAVLE = 1;
  1871. QD_MotorDelay = dwTickCount + 5;
  1872. QD_MotorStep = 34;
  1873. }
  1874. else if(((cRealPos - save_buff) >= (QD_PARAM_ERROR_LENGTH + QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH)) && QD_GZ_VAVLE)
  1875. {
  1876. QD_SetAlarmCode(QD_LENGTH_LONG_ALARM);
  1877. }
  1878. else if(dwTickCount >= QD_MotorDelay)
  1879. {
  1880. QD_SetAlarmCode(QD_GZ_ALARM);
  1881. }
  1882. break;
  1883. case 34:
  1884. if(!X_DRV && (dwTickCount >= QD_MotorDelay))
  1885. {
  1886. AxisMovePos(X_AXIS,QD_PARAM_BACK_LOW_SPEED,QD_PARAM_FZ_LENGTH);
  1887. QD_MotorStep = 35;
  1888. }
  1889. break;
  1890. case 35:
  1891. if(!X_DRV)
  1892. {
  1893. QD_MotorStep = 36;
  1894. }
  1895. break;
  1896. case 36:
  1897. QD_MotorStep = 0;
  1898. break;
  1899. case 40:
  1900. if(dwTickCount >= QD_MotorDelay)
  1901. {
  1902. jz_buff = cRealPos;
  1903. if(QD_PARAM_SJZ_LENGTH == 0)
  1904. {
  1905. QD_JD_VAVEL = 0;
  1906. }
  1907. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_SJ_TIME;
  1908. QD_MotorStep = 45;
  1909. }
  1910. break;
  1911. case 45: if((dwTickCount >= QD_MotorDelay) || (QD_JD_VAVEL == 1))
  1912. {
  1913. AxisMovePos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,-(QD_PARAM_SJZ_LENGTH+QD_PARAM_BACK_LENGTH));
  1914. QD_MotorStep = 43;
  1915. }
  1916. break;
  1917. case 43:
  1918. // 切断完成后拉电机动作
  1919. if(dwTickCount >= QD_MotorDelay)
  1920. {
  1921. if(((QD_PARAM_SJZ_LENGTH) <= (cRealPos - jz_buff)))
  1922. {
  1923. QD_JD_VAVEL = 0;
  1924. QD_MotorStep = 44;
  1925. }
  1926. else if(!X_DRV)
  1927. {
  1928. QD_JD_VAVEL = 0;
  1929. QD_MotorStep = 44;
  1930. }
  1931. }
  1932. break;
  1933. case 44: // 切断完成后拉电机动作
  1934. if(!X_DRV)
  1935. {
  1936. QD_MotorStep = 0;
  1937. QD_MotorDelay = dwTickCount;
  1938. }
  1939. break;
  1940. case 61: // 前点定位数控模式
  1941. if(QD_SZ_OUT)
  1942. {
  1943. QD_SZ_OUT = 0;
  1944. QD_MotorDelay = dwTickCount + 50;
  1945. }
  1946. if(!QD_TL_VAVLE)
  1947. {
  1948. if(!QD_SHANG_MU_LIMIT_IN && (QD_TuiLianStep == 0))
  1949. {
  1950. QD_TuiLianStep = 1;
  1951. QD_MotorStep = 62;
  1952. }
  1953. }
  1954. else
  1955. QD_MotorStep = 62;
  1956. break;
  1957. case 62:
  1958. if(dwTickCount >= QD_MotorDelay)
  1959. {
  1960. if(QD_QIAN_LIMIT_IN)
  1961. {
  1962. AxisMovePos(X_AXIS,QD_PARAM_FIRST_SPEED,-QD_PARAM_ON_BACK_LENGTH);
  1963. QD_MotorDelay = dwTickCount + 1000;
  1964. }
  1965. QD_MotorStep = 63;
  1966. QD_JD_VAVEL = 0;
  1967. }
  1968. break;
  1969. case 63:
  1970. if(!X_DRV && !QD_QIAN_LIMIT_IN && (dwTickCount >= QD_MotorDelay) && !QD_SHANG_MU_LIMIT_IN)
  1971. {
  1972. go_buff = cRealPos;
  1973. if(cZipCnt > 0)
  1974. {
  1975. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_HIGH_SPEED);//
  1976. }
  1977. else
  1978. {
  1979. MoveAction_Const_Stop(X_AXIS, QD_DIR_N,QD_PARAM_GO_LOW_SPEED);
  1980. }
  1981. QD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  1982. QD_MotorStep =64;
  1983. }
  1984. break;
  1985. case 64:
  1986. if(((go_buff - cRealPos) > ((QD_PARAM_ZIPPER_LENGTH - QD_PARAM_TC_LENGTH - 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,30))) + QD_PARAM_BACK_LENGTH + QD_PARAM_SJZ_LENGTH)) || QD_QIAN_DEC_IN_UP)
  1987. {
  1988. MoveChangSpeed(X_AXIS,QD_PARAM_GO_LOW_SPEED);
  1989. QD_MotorStep =65;
  1990. }
  1991. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  1992. break;
  1993. case 65:
  1994. if(QD_QIAN_LIMIT_IN_UP)
  1995. {
  1996. AxisEgmStop(X_AXIS);
  1997. QD_MotorStep = 66;
  1998. }
  1999. else if(dwTickCount >= QD_MotorDelay)QD_SetAlarmCode(QD_NO_ZIPPER_ALARM);
  2000. else if(QD_JD_ORIGIN_IN)QD_SetAlarmCode(QD_JD_ORIGIN_ALARM);
  2001. break;
  2002. case 66:
  2003. if(!X_DRV)
  2004. {
  2005. QD_MotorDelay = dwTickCount;
  2006. QD_MotorStep = 67;
  2007. }
  2008. break;
  2009. case 67:
  2010. if((dwTickCount >= QD_MotorDelay) && (QD_TuiLianStep == 0) && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  2011. {
  2012. if(bRunning)
  2013. {
  2014. QD_JD_VAVEL = 1;
  2015. }
  2016. QD_MotorStep = 68;
  2017. QD_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  2018. }
  2019. break;
  2020. case 68:
  2021. if(dwTickCount >= QD_MotorDelay)
  2022. {
  2023. QD_YD_VAVLE = 0;
  2024. QD_TL_VAVLE = 0;
  2025. QD_MotorStep = 0;
  2026. }
  2027. break;
  2028. }
  2029. }
  2030. //电机动作
  2031. void QueDuan_Motor(void) //
  2032. {
  2033. switch(QD_MACHINE_TYPE)
  2034. {
  2035. case QD_CS_TUIFANGKUAI:
  2036. {
  2037. QueDuan_Motor_CS();
  2038. }break;
  2039. case QD_NO_CS_TUIFANGKUAI: QueDuan_Motor_CS();break;
  2040. case QD_QQ_TUIFANGKUAI: QueDuan_Motor_QD();break;
  2041. case QD_NO_GL_TUIFANGKUAI:QueDuan_Motor_NoGL();break;
  2042. default:;
  2043. }
  2044. }
  2045. //超声方式下切
  2046. void QueDuan_XiaQue_CS(void)
  2047. {
  2048. switch(QD_XiaQieStep)
  2049. {
  2050. case 0:
  2051. break;
  2052. case 1:
  2053. if(bRunning)
  2054. {
  2055. QD_XiaQieStep = 6;
  2056. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  2057. }
  2058. else
  2059. QD_XiaQieStep = 2;
  2060. break;
  2061. case 2:
  2062. if(QD_PARAM_XM_ENABLE) QD_XM_VAVLE = 1;
  2063. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  2064. QD_XiaQieStep = 3;
  2065. break;
  2066. case 3:
  2067. if(QD_PARAM_XM_ENABLE)
  2068. {
  2069. if(QD_XIA_MU_LIMIT_IN)
  2070. {
  2071. QD_XiaQieDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  2072. QD_XiaQieStep = 4;
  2073. }
  2074. else if(dwTickCount >= QD_XiaQieDelay)
  2075. {
  2076. QD_SetAlarmCode(QD_XM_DAOWEI);
  2077. }
  2078. }
  2079. else
  2080. {
  2081. QD_XiaQieDelay = dwTickCount + QD_PARAM_GZ_DELAY;
  2082. QD_XiaQieStep = 4;
  2083. }
  2084. break;
  2085. case 4:
  2086. QD_GZ_VAVLE = 1;
  2087. QD_XiaQieDelay = dwTickCount + QD_PARAM_TFK_DELAY;
  2088. QD_XiaQieStep = 5;
  2089. break;
  2090. case 5:
  2091. QD_TFK_VAVEL = 1;
  2092. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  2093. QD_XiaQieStep = 6;
  2094. break;
  2095. case 6:
  2096. if(QD_PARAM_XM_ENABLE)
  2097. {
  2098. if(QD_XIA_MU_LIMIT_IN)
  2099. {
  2100. QD_XiaQieStep = 7;
  2101. QD_XiaQieDelay = dwTickCount + 1000;
  2102. }
  2103. else if(dwTickCount >= QD_XiaQieDelay)
  2104. {
  2105. QD_SetAlarmCode(QD_XM_DAOWEI);
  2106. }
  2107. }
  2108. else
  2109. {
  2110. QD_XiaQieStep = 7;
  2111. QD_XiaQieDelay = dwTickCount + 1000;
  2112. }
  2113. break;
  2114. case 7:
  2115. if(QD_GOUZHEN_IN)
  2116. {
  2117. QD_YD_VAVLE = 1;
  2118. cTuiFangKuaiCnt = 0;
  2119. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  2120. QD_XiaQieStep = 8;
  2121. }
  2122. else if((dwTickCount >= QD_XiaQieDelay))
  2123. {
  2124. if(cTuiFangKuaiCnt == 0)
  2125. {
  2126. QD_TFK_VAVEL = 0;
  2127. cTuiFangKuaiCnt++;
  2128. QD_XiaQieDelay = dwTickCount + 1000;
  2129. QD_XiaQieStep = 100;
  2130. }
  2131. else
  2132. QD_SetAlarmCode(QD_GZ_ALARM);
  2133. }
  2134. break;
  2135. case 100:
  2136. if((dwTickCount >= QD_XiaQieDelay))
  2137. {
  2138. QD_XiaQieStep = 5;
  2139. }
  2140. break;
  2141. case 8:
  2142. if(dwTickCount >= QD_XiaQieDelay)
  2143. {
  2144. QD_XM_VAVLE = 1;
  2145. QD_SM_VAVLE = 1;
  2146. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  2147. QD_XiaQieStep = 9;
  2148. }
  2149. break;
  2150. case 9:
  2151. if(QD_SHANG_MU_LIMIT_IN && QD_XIA_MU_LIMIT_IN && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  2152. {
  2153. if(QD_MACHINE_TYPE == QD_NO_CS_TUIFANGKUAI)
  2154. {
  2155. QD_XiaQieDelay = QD_PARAM_DELAY_CS; //
  2156. QD_XiaQieStep = 12;
  2157. }
  2158. else
  2159. {
  2160. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAY_CS; //
  2161. QD_XiaQieStep = 10;
  2162. }
  2163. }
  2164. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  2165. break;
  2166. case 10:
  2167. if(dwTickCount >= QD_XiaQieDelay)
  2168. {
  2169. if(QD_PARAM_CS_ENABLE)QD_CS_OUT = 1;
  2170. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_TIME; //
  2171. QD_XiaQieStep = 11;
  2172. }
  2173. break;
  2174. case 11:
  2175. if(dwTickCount >= QD_XiaQieDelay)
  2176. {
  2177. QD_CS_OUT = 0;
  2178. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_COLD_TIME; //
  2179. QD_XiaQieStep = 12;
  2180. }
  2181. break;
  2182. case 12:
  2183. if(dwTickCount >= QD_XiaQieDelay)
  2184. {
  2185. QD_SM_VAVLE = 0;
  2186. QD_XM_VAVLE = 0;
  2187. QD_TFK_VAVEL = 0;
  2188. QD_GZ_VAVLE = 0;
  2189. if(!bRunning)QD_JD_VAVEL = 0;
  2190. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
  2191. QD_XiaQieStep = 13;
  2192. }//
  2193. break;
  2194. case 13:
  2195. if(QD_SHANG_MU_ORIGIN_IN && !QD_XIA_MU_LIMIT_IN)
  2196. {
  2197. QD_XiaQieStep = 0;
  2198. }
  2199. else if(dwTickCount >= QD_XiaQieDelay)
  2200. {
  2201. QD_SetAlarmCode(QD_SM_YUANWEI);
  2202. }
  2203. break;
  2204. }
  2205. }
  2206. void QueDuan_TuiLianNormal(void)
  2207. {
  2208. switch(QD_TuiLianStep)
  2209. {
  2210. case 0:
  2211. break;
  2212. case 1:
  2213. QD_TuiLianStep = 2;
  2214. break;
  2215. case 2:
  2216. QD_YBD_VAVLE = 1;
  2217. QD_TLDelay = dwTickCount + QD_PARAM_YD_DELAY;
  2218. QD_TuiLianStep = 3;
  2219. break;
  2220. case 3:
  2221. if(dwTickCount >= QD_TLDelay)
  2222. {
  2223. if(QD_PARAM_TL_MODE)
  2224. {
  2225. QD_TuiLianStep = 10;
  2226. }
  2227. else
  2228. {
  2229. QD_TL_VAVLE = 1;
  2230. if(!bRunning)QD_TFK_VAVEL = 0;
  2231. QD_TLDelay = dwTickCount + QD_PARAM_TL_DELAY;
  2232. QD_TuiLianStep = 4;
  2233. }
  2234. }
  2235. break;
  2236. case 4:
  2237. if(dwTickCount >= QD_TLDelay)
  2238. {
  2239. // QD_TL_VAVLE = 0;
  2240. QD_TuiLianStep = 0;
  2241. }
  2242. break;
  2243. case 10:
  2244. if(bRunning && QD_PARAM_TL_MODE)AxisMovePos(Y_AXIS,QD_PARAM_TL_SPEED,QD_PARAM_TL_LENGTH);
  2245. QD_TuiLianStep = 11;
  2246. break;
  2247. case 11:
  2248. if(!Y_DRV)
  2249. {
  2250. {
  2251. QD_TuiLianStep = 0;
  2252. }
  2253. }
  2254. break;
  2255. }
  2256. }
  2257. void QueDuan_TuiLianNoGL(void)
  2258. {
  2259. switch(QD_TuiLianStep)
  2260. {
  2261. case 0:
  2262. break;
  2263. case 1:
  2264. QD_TuiLianStep = 2;
  2265. break;
  2266. case 2:
  2267. if(!QD_YD_VAVLE)QD_TLDelay = dwTickCount + QD_PARAM_YD_DELAY;
  2268. QD_YD_VAVLE = 1;
  2269. QD_TuiLianStep = 3;
  2270. break;
  2271. case 3:
  2272. if(dwTickCount >= QD_TLDelay)
  2273. {
  2274. QD_TL_VAVLE = 1;
  2275. QD_TLDelay = dwTickCount + QD_PARAM_TL_DELAY;
  2276. QD_TuiLianStep = 4;
  2277. }
  2278. break;
  2279. case 4:
  2280. if(dwTickCount >= QD_TLDelay)
  2281. {
  2282. QD_TuiLianStep = 0;
  2283. }
  2284. break;
  2285. }
  2286. }
  2287. void QueDuan_TuiLianAction(void)
  2288. {
  2289. switch(QD_MACHINE_TYPE)
  2290. {
  2291. case QD_NO_GL_TUIFANGKUAI: QueDuan_TuiLianNoGL();break;
  2292. default:QueDuan_TuiLianNormal();
  2293. }
  2294. }
  2295. //气动推方块方式下切
  2296. void QueDuan_XiaQue_QD(void)
  2297. {
  2298. switch(QD_XiaQieStep)
  2299. {
  2300. case 0:
  2301. break;
  2302. case 1:
  2303. if(!bRunning)
  2304. {
  2305. QD_XiaQieDelay = dwTickCount + 50;
  2306. QD_GZ_VAVLE = 1;
  2307. QD_XiaQieStep = 20;
  2308. }
  2309. else
  2310. {
  2311. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  2312. QD_XiaQieStep = 2;
  2313. }
  2314. break;
  2315. case 20:
  2316. if(dwTickCount >= QD_XiaQieDelay)
  2317. {
  2318. QD_XiaQieDelay = dwTickCount + 1000;
  2319. QD_YBD_VAVLE = 1;
  2320. QD_TFK_VAVEL = 1;
  2321. QD_XiaQieStep = 21;
  2322. }
  2323. break;
  2324. case 21:
  2325. if(QD_GOUZHEN_IN)
  2326. {
  2327. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  2328. cTuiFangKuaiCnt = 0;
  2329. QD_XiaQieStep = 2;
  2330. }
  2331. else if(dwTickCount >= QD_XiaQieDelay)
  2332. {
  2333. QD_SetAlarmCode(QD_GZ_ALARM);
  2334. }
  2335. break;
  2336. case 22:
  2337. if(dwTickCount >= QD_XiaQieDelay)
  2338. {
  2339. QD_XiaQieStep = 20;
  2340. }
  2341. break;
  2342. case 2:
  2343. if(dwTickCount >= QD_XiaQieDelay)
  2344. {
  2345. QD_SM_VAVLE = 1;
  2346. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  2347. QD_XiaQieStep = 3;
  2348. }
  2349. break;
  2350. case 3:
  2351. if(QD_SHANG_MU_LIMIT_IN && ((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0)) )
  2352. {
  2353. QD_XiaQieStep = 4;
  2354. QD_XiaQieDelay = dwTickCount + 100;
  2355. }
  2356. else if(dwTickCount >= QD_XiaQieDelay)QD_SetAlarmCode(QD_SM_DAOWEI);
  2357. break;
  2358. case 4:
  2359. if(dwTickCount >= QD_XiaQieDelay)
  2360. {
  2361. QD_SM_VAVLE = 0;
  2362. if(bRunning)QD_TFK_VAVEL = 0;
  2363. QD_GZ_VAVLE = 0;
  2364. if(!QD_PARAM_TL_MODE)
  2365. {
  2366. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  2367. }
  2368. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  2369. QD_XiaQieStep = 5;
  2370. }
  2371. break;
  2372. case 5:
  2373. if(QD_SHANG_MU_ORIGIN_IN && (QD_TuiLianStep == 0))
  2374. {
  2375. if(QD_PARAM_TL_MODE)
  2376. {
  2377. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  2378. }
  2379. QD_XiaQieStep = 0;
  2380. QD_XiaQieDelay = dwTickCount + QD_PARAM_TL_DELAY;
  2381. }
  2382. else if(dwTickCount >= QD_XiaQieDelay)
  2383. {
  2384. QD_SetAlarmCode(QD_SM_YUANWEI);
  2385. }
  2386. break;
  2387. }
  2388. }
  2389. void QueDuan_XiaQue_NO_GL(void)
  2390. {
  2391. switch(QD_XiaQieStep)
  2392. {
  2393. case 0:
  2394. break;
  2395. case 1:
  2396. QD_YD_VAVLE = 1;
  2397. QD_XiaQieDelay = dwTickCount + QD_PARAM_CUT_DELAY;
  2398. QD_XiaQieStep = 2;
  2399. break;
  2400. case 2:
  2401. if(dwTickCount >= QD_XiaQieDelay)
  2402. {
  2403. QD_XiaQieStep = 3;
  2404. }
  2405. break;
  2406. case 3:
  2407. if(dwTickCount >= QD_XiaQieDelay)
  2408. {
  2409. if((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0))
  2410. {
  2411. QD_SM_VAVLE = 1;
  2412. QD_XM_VAVLE = 1;
  2413. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  2414. QD_XiaQieStep = 4;
  2415. }
  2416. }
  2417. break;
  2418. case 4:
  2419. if(QD_SHANG_MU_LIMIT_IN && QD_XIA_MU_LIMIT_IN)
  2420. {
  2421. QD_XiaQieStep = 5;
  2422. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAYBACK_SM; //
  2423. }
  2424. else if(dwTickCount >= QD_XiaQieDelay)
  2425. {
  2426. if(!QD_SHANG_MU_LIMIT_IN)
  2427. QD_SetAlarmCode(QD_SM_DAOWEI);
  2428. else
  2429. QD_SetAlarmCode(QD_XM_DAOWEI);
  2430. }
  2431. break;
  2432. case 5:
  2433. if(dwTickCount >= QD_XiaQieDelay)
  2434. {
  2435. if((QD_PARAM_TIAOSHI_MODE && QD_bTS) || (QD_PARAM_TIAOSHI_MODE == 0))
  2436. {
  2437. QD_XiaQieDelay = dwTickCount + QD_PARAM_DELAY_CS; //
  2438. QD_XiaQieStep = 6;
  2439. }
  2440. }
  2441. break;
  2442. case 6:
  2443. if(dwTickCount >= QD_XiaQieDelay)
  2444. {
  2445. if(QD_PARAM_CS_ENABLE)QD_CS_OUT = 1;
  2446. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_TIME; //
  2447. QD_XiaQieStep = 7;
  2448. }
  2449. break;
  2450. case 7:
  2451. if(dwTickCount >= QD_XiaQieDelay)
  2452. {
  2453. QD_CS_OUT = 0;
  2454. QD_XiaQieDelay = dwTickCount + QD_PARAM_CS_COLD_TIME; //
  2455. QD_XiaQieStep = 8;
  2456. }
  2457. break;
  2458. case 8:
  2459. if(dwTickCount >= QD_XiaQieDelay)
  2460. {
  2461. QD_GZ_VAVLE = 0;
  2462. QD_SM_VAVLE = 0;
  2463. QD_XM_VAVLE = 0;
  2464. QD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME; //
  2465. QD_XiaQieStep = 9;
  2466. }
  2467. break;
  2468. case 9:
  2469. if(QD_SHANG_MU_ORIGIN_IN && !QD_SHANG_MU_LIMIT_IN && !QD_XIA_MU_LIMIT_IN)
  2470. {
  2471. if(QD_TuiLianStep == 0)QD_TuiLianStep = 1;
  2472. if(!bRunning)QD_JD_VAVEL = 0;
  2473. QD_XiaQieStep = 0;
  2474. }
  2475. else if(dwTickCount >= QD_XiaQieDelay)
  2476. {
  2477. QD_SetAlarmCode(QD_SM_YUANWEI);
  2478. }
  2479. break;
  2480. }
  2481. }
  2482. //切断动作
  2483. void QueDuan_XiaQue(void)
  2484. {
  2485. switch(QD_MACHINE_TYPE)
  2486. {
  2487. case QD_CS_TUIFANGKUAI:QueDuan_XiaQue_CS();break;
  2488. case QD_NO_CS_TUIFANGKUAI:QueDuan_XiaQue_CS();break;
  2489. case QD_QQ_TUIFANGKUAI:QueDuan_XiaQue_QD();break;
  2490. case QD_NO_GL_TUIFANGKUAI:QueDuan_XiaQue_NO_GL();break;
  2491. default:;
  2492. }
  2493. }
  2494. #endif