PWCQueDuanJi.c 107 KB

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