XDQueDuanJi.c 108 KB

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