WYSQueDuanJi.c 106 KB

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