YGQueduanChuantou.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. #include "global.h"
  2. #if YOU_GUAN_MACHINE
  3. unsigned short cTaiMiamMotor;
  4. unsigned long cSlowPusle;
  5. unsigned char bDecEn;
  6. unsigned char bStartOnceTime;
  7. unsigned short cWorkCnt;
  8. unsigned char TryCnt = 0;
  9. unsigned short cZhaCnt = 0;
  10. unsigned char ZhuangLiaoOkFlg = 0;
  11. unsigned char SongLaTouOkFlg = 0;
  12. static long save_limit_pos;
  13. static unsigned long cZipCnt = 0;
  14. void QDCT_ManualAction(void);
  15. void QDCT_JiaLianAction(void);
  16. void QDCT_AutoStepAction(void);
  17. void QDCT_ZhenDongAction(void);
  18. void QDCT_TableAction(void);
  19. void QDCT_GL_Step(void);
  20. void QDCT_Motor(void);
  21. void QDCT_CheckStart(void);
  22. void QDCT_SL_Step(void);
  23. void QDCT_XiaQieAction(void);
  24. void QDCT_ExtiActionX31(void)
  25. {
  26. if(cSeBiaoEn && !cSeBiaoOk)
  27. {
  28. cSeBiaoEn = 0;
  29. cSeBiaoOk = 1;
  30. SetRemainLength(X_AXIS,QDCT_SEBIAO_LENGTH,10);
  31. }
  32. }
  33. //故障报警
  34. void QDCT_SetAlarmCode(unsigned alarm_code)
  35. {
  36. SetAlarmCode(QDCT_ALARM_ADDR,alarm_code);
  37. QDCT_bAlarmStop = 1;
  38. }
  39. //初始化动作
  40. void QDCT_InitAction(void)
  41. {
  42. float buff_pulse,buff_dist;
  43. buff_pulse = QDCT_PARAM_CYCLE_PULSE;
  44. buff_dist = QDCT_PARAM_CYCLE_LENGTH;
  45. XGearRatio = buff_pulse/buff_dist;
  46. }
  47. void QDCT_Action(void)
  48. {
  49. QDCT_CheckStart();
  50. QDCT_ZhenDongAction();
  51. QDCT_TableAction();
  52. QDCT_SL_Step();
  53. QDCT_JiaLianAction();
  54. QDCT_XiaQieAction();
  55. QDCT_Motor();
  56. QDCT_ManualAction();
  57. QDCT_AutoStepAction();
  58. }
  59. void QDCT_AlarmProtect(void)
  60. {
  61. dwRealPos = GetPos(X_AXIS);
  62. if(QDCT_PARAM_BACK_ALARM_MODE)
  63. { //感应后限模式
  64. if(!bRunning)
  65. {
  66. if(QDCT_BACK_LIMIT_IN_UP)
  67. {
  68. if((QDCT_MotorStep == 0) && X_DRV && QDCT_bMotorBack) //到后限不能再后退但可以点前进
  69. {
  70. QDCT_bMotorBack = 0;
  71. AxisDecStop(X_AXIS);
  72. QDCT_JD_OUT = 0;
  73. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  74. }
  75. }
  76. }
  77. else
  78. {
  79. if(QDCT_BACK_LIMIT_IN_UP)
  80. {
  81. AxisDecStop(X_AXIS);
  82. QDCT_JD_OUT = 0;
  83. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  84. }
  85. }
  86. }
  87. else
  88. {
  89. if(QDCT_GO_LIMIT_IN_UP) //数控后限模式
  90. {
  91. save_limit_pos = dwRealPos;
  92. SetData32bits(200,save_limit_pos);
  93. }
  94. if(QDCT_PARAM_MAX_BACK_LENGTH < (dwRealPos - save_limit_pos))
  95. {
  96. if(!bRunning)
  97. {
  98. if((QDCT_MotorStep == 0) && X_DRV && QDCT_bMotorBack) //到后限不能再后退但可以点前进
  99. {
  100. QDCT_bMotorBack = 0;
  101. AxisDecStop(X_AXIS);
  102. QDCT_JD_OUT = 0;
  103. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  104. }
  105. }
  106. else
  107. {
  108. AxisDecStop(X_AXIS);
  109. QDCT_JD_OUT = 0;
  110. QDCT_SetAlarmCode(QDCT_BACK_LIMIT_ALARM);
  111. }
  112. }
  113. }
  114. }
  115. void QDCT_JiaLianAction(void)
  116. {
  117. if(QDCT_JiaLianStep == 1)
  118. {
  119. // QDCT_JD_Delay = dwTickCount + QDCT_PARAM_JD_DELAY;
  120. QDCT_JiaLianStep = 2;
  121. }
  122. else if((QDCT_JiaLianStep == 2) && (dwTickCount >= QDCT_JD_Delay))
  123. {
  124. QDCT_JD_OUT = 1;
  125. QDCT_JD_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  126. QDCT_JiaLianStep = 3;
  127. }
  128. else if(QDCT_JiaLianStep == 3)
  129. {
  130. if(QDCT_JZ_LEFT_IN && QDCT_JZ_RIGHT_IN)
  131. {
  132. QDCT_JiaLianStep = 4;
  133. }
  134. else if(dwTickCount >= QDCT_JD_Delay)
  135. {
  136. if(!QDCT_JZ_LEFT_IN)QDCT_SetAlarmCode(QDCT_JD_LEFT_ALARM);
  137. else if(!QDCT_JZ_RIGHT_IN)QDCT_SetAlarmCode(QDCT_JD_RIGHT_ALARM);
  138. }
  139. }
  140. else if(QDCT_JiaLianStep == 4)
  141. {
  142. if(QDCT_PARAM_KL_TIME)
  143. {
  144. // QDCT_JD_Delay = dwTickCount + QDCT_PARAM_KL_DELAY;
  145. QDCT_JiaLianStep = 5;
  146. }
  147. else
  148. {
  149. QDCT_JiaLianStep = 7;
  150. }
  151. }
  152. else if((QDCT_JiaLianStep == 5) && (dwTickCount >= QDCT_JD_Delay))
  153. {
  154. QDCT_KL_OUT = 1;
  155. QDCT_JiaLianStep = 6;
  156. QDCT_JD_Delay = dwTickCount + QDCT_PARAM_KL_TIME;
  157. }
  158. else if((QDCT_JiaLianStep == 6) && (dwTickCount >= QDCT_JD_Delay))
  159. {
  160. QDCT_KL_OUT = 0;
  161. QDCT_JiaLianStep = 7;
  162. }
  163. else if((QDCT_JiaLianStep == 7))
  164. {
  165. QDCT_JiaLianStep = 0;
  166. }
  167. }
  168. //自动动作
  169. void QDCT_AutoStepAction(void)
  170. {
  171. if(bRunning)
  172. {
  173. if(QDCT_AutoStep == 1)
  174. {
  175. QDCT_AutoStep = 2;
  176. QDCT_ZhenDongStep = 1;
  177. }
  178. else if((QDCT_AutoStep == 2) && (dwTickCount >= QDCT_AutoDelay))
  179. {
  180. QDCT_AutoStep = 3;
  181. }
  182. else if(QDCT_AutoStep == 3)
  183. {
  184. if(QDCT_MotorStep == 0)
  185. {
  186. QDCT_MotorStep = 1;
  187. ZhuangLiaoOkFlg = 0;
  188. QDCT_AutoStep = 4;
  189. }
  190. }
  191. else if(QDCT_AutoStep == 4)
  192. {
  193. QDCT_AutoStep = 5;
  194. }
  195. else if(QDCT_AutoStep == 5)
  196. {
  197. if(QDCT_ZhuangLiaoStep == 0)
  198. {
  199. QDCT_ZhuangLiaoStep = 1;
  200. QDCT_AutoStep = 6;
  201. }
  202. }
  203. else if(QDCT_AutoStep == 6)
  204. {
  205. if(QDCT_ZhuangLiaoStep == 0)
  206. {
  207. QDCT_AutoStep = 7;
  208. }
  209. }
  210. else if(QDCT_AutoStep == 7)
  211. {
  212. QDCT_AutoStep = 8;
  213. }
  214. else if(QDCT_AutoStep == 8)
  215. {
  216. QDCT_AutoStep = 9;
  217. }
  218. else if(QDCT_AutoStep == 9)
  219. {
  220. if(QDCT_MotorStep == 0)
  221. {
  222. QDCT_AutoStep = 10;
  223. }
  224. }
  225. else if(QDCT_AutoStep == 10)
  226. {
  227. QDCT_AutoStep = 11;
  228. }
  229. else if(QDCT_AutoStep == 11)
  230. {
  231. if(QDCT_MotorStep == 0) //
  232. {
  233. if(QDCT_SEBIAO_MODE)
  234. QDCT_MotorStep = 1;
  235. else
  236. QDCT_MotorStep = 30;
  237. QDCT_AutoStep = 12;
  238. }
  239. }
  240. else if(QDCT_AutoStep == 12)
  241. {
  242. if(QDCT_MotorStep == 0)
  243. {
  244. QDCT_AutoStep = 13;
  245. }
  246. }
  247. else if(QDCT_AutoStep == 13)
  248. {
  249. QDCT_AutoStep = 14;
  250. }
  251. else if(QDCT_AutoStep == 14)
  252. {
  253. if(QDCT_XiaQieStep == 0)
  254. {
  255. QDCT_XiaQieStep = 1;
  256. QDCT_AutoStep = 15;
  257. }
  258. }
  259. else if(QDCT_AutoStep == 15)
  260. {
  261. if(QDCT_XiaQieStep == 0)
  262. {
  263. QDCT_AutoStep = 16;
  264. }
  265. }
  266. else if(QDCT_AutoStep == 16)
  267. {
  268. CalProSP(QDCT_SPEED_ADDR); //计算生产速度
  269. AddToTal(QDCT_TOTAL_ADDR); //生产总量加1并保存
  270. AddToTal(QDCT_NOWTOTAL_ADDR); //生产总量加1并保存
  271. cWorkCnt++;
  272. cZhaCnt++;
  273. cZipCnt++;
  274. if(GetTotal(QDCT_NOWTOTAL_ADDR) >= GetTotal(QDCT_SETTOTAL_ADDR))
  275. {
  276. ClrcToTal(QDCT_NOWTOTAL_ADDR);
  277. bStartOnceTime = 0;
  278. QDCT_SetAlarmCode(QDCT_TOTAL_ALARM);
  279. }
  280. else
  281. {
  282. if(bStartOnceTime)
  283. {
  284. bStartOnceTime = 0;
  285. QDCT_AutoStep = 0;
  286. bRunning = 0;
  287. }
  288. else
  289. QDCT_AutoStep = 17;
  290. }
  291. }
  292. else if(QDCT_AutoStep == 17)
  293. {
  294. if(cZhaCnt >= QDCT_ZHA_NO)
  295. {
  296. cZhaCnt = 0;
  297. QDCT_AutoDelay = dwTickCount + QDCT_ZHA_STOP_TIME;
  298. QDCT_AutoStep = 2;
  299. }
  300. else
  301. {
  302. QDCT_AutoDelay = dwTickCount + QDCT_PARAM_CYCLE_DELAY;
  303. QDCT_AutoStep = 2;
  304. }
  305. /* if(!QDCT_LTCZ_IN)
  306. {
  307. QDCT_AutoStep = 2;
  308. }
  309. else
  310. {
  311. QDCT_SetAlarmCode(QDCT_LTCZ_ALARM);
  312. }*/
  313. }
  314. }
  315. }
  316. //振动盘控制
  317. void QDCT_ZhenDongAction(void)
  318. {
  319. if(QDCT_ZhenDongStep == 1)
  320. {
  321. QDCT_ZhenDongStep = 2;
  322. }
  323. else if(QDCT_ZhenDongStep == 2)
  324. {
  325. if(QDCT_LT_IN)
  326. {
  327. }
  328. else
  329. {
  330. QDCT_ZDP_OUT = 1;
  331. QDCT_ZhenDongStep = 3;
  332. }
  333. }
  334. else if(QDCT_ZhenDongStep == 3)
  335. {
  336. if(QDCT_PARAM_ZD_MODE)
  337. {
  338. QDCT_ZhenDongStep = 0;
  339. }
  340. else
  341. {
  342. QDCT_ZhenDongStep = 4;
  343. QDCT_ZhenDongDelay = dwTickCount + QDCT_PARAM_ZD_WORK_TIME ;
  344. }
  345. }
  346. else if((QDCT_ZhenDongStep == 4) && (dwTickCount >= QDCT_ZhenDongDelay))
  347. {
  348. QDCT_ZDP_OUT = 0;
  349. QDCT_ZhenDongStep = 2;
  350. }
  351. else if(QDCT_ZhenDongStep == 6)
  352. {
  353. QDCT_ZhenDongStep = 0;
  354. }
  355. }
  356. //台面电机动作
  357. void QDCT_TableAction(void)
  358. {
  359. if(QDCT_TB_OUT && (dwTickCount >= QDCT_TableDelay))QDCT_TB_OUT = 0;
  360. }
  361. void QDCT_CheckStart(void)
  362. {
  363. //启动 自动启动 单一自动
  364. if(START_IN_UP || bStart || QDCT_bOnceStart)
  365. {
  366. if(QDCT_bOnceStart)
  367. {
  368. QDCT_bOnceStart = 0;
  369. bStartOnceTime = 1;
  370. }
  371. bStart = 0;
  372. if(!QDCT_NO_ZIPPER_CHECK_IN)QDCT_SetAlarmCode(QDCT_START_NO_ZIPPER_ALARM);
  373. else if(QDCT_JLT_IN)QDCT_SetAlarmCode(QDCT_START_JLT_ALARM);
  374. else if(QDCT_LTCZ_IN)QDCT_SetAlarmCode(QDCT_START_LTCZ_ALARM);
  375. else if(!QDCT_HSL_ORIGIN_IN)QDCT_SetAlarmCode(QDCT_START_GL_ORIGIN_ALARM);
  376. else if(QDCT_HSL_LIMIT_IN)QDCT_SetAlarmCode(QDCT_START_SL_LIMIT_ALARM);
  377. else if(!QDCT_SQ_LIMIT_IN)QDCT_SetAlarmCode(QDCT_START_SQ_ORIGIN_ALARM);
  378. else if(!QDCT_XQ_ORIGIN_IN)QDCT_SetAlarmCode(QDCT_START_XQ_ORIGIN_ALARM);
  379. else if(!QDCT_XM_ORIGIN_IN)QDCT_SetAlarmCode(QDCT_START_SM_ORIGIN_ALARM);
  380. else
  381. {
  382. if(!bRunning && (QDCT_AutoStep == 0) && (GetAlarmCode(QDCT_ALARM_ADDR) == 0))
  383. {
  384. bRunning = 1;
  385. QDCT_AutoStep = 1;
  386. cWorkCnt = 0;
  387. TryCnt = 0;
  388. SongLaTouOkFlg = 1;
  389. cZipCnt = 0;
  390. }
  391. }
  392. }
  393. //停止
  394. if(STOP_IN_UP|| bStop)
  395. {
  396. AxisDecStop(X_AXIS);
  397. bRunning = 0;
  398. QDCT_bOnceStart = 0;
  399. bStop = 0;
  400. bStartOnceTime = 0;
  401. QDCT_SQ_OUT = 0;
  402. QDCT_XQ_OUT = 0;
  403. QDCT_XM_OUT = 0;
  404. QDCT_JD_OUT = 0;
  405. QDCT_SL_OUT = 0;
  406. QDCT_JLT_OUT= 0;
  407. QDCT_HSL_OUT = 0;
  408. QDCT_KL_OUT = 0;
  409. QDCT_ZDP_OUT= 0;
  410. QDCT_SLT_OUT= 0;
  411. if(GetAlarmCode(QDCT_ALARM_ADDR) != 0)QDCT_SetAlarmCode(QDCT_NO_ALARM);
  412. }
  413. if(bAlarmStop)
  414. {
  415. QDCT_bOnceStart = 0;
  416. bAlarmStop = 0;
  417. bStartOnceTime = 0;
  418. QDCT_ZDP_OUT = 0;
  419. AxisDecStop(X_AXIS);
  420. }
  421. }
  422. //电机控制动作
  423. void QDCT_Motor(void) //
  424. {
  425. static long save_buff,length_buff,gou_zhen_buff,back_dec_buff,dandao_buff,back_buff,gouzhen_buff,go_buff,go_length_buff,jz_buff;
  426. user_datas[123] = QD_PARAM_ON_BACK_LENGTH;
  427. user_datas[124] = QD_AutoStep;
  428. user_datas[127] = QDCT_MotorStep;
  429. switch(QDCT_MotorStep)
  430. {
  431. case 1:
  432. QDCT_MotorDelay = dwTickCount + QD_PARAM_DELAY_BACK;
  433. QDCT_MotorStep = 2;
  434. break;
  435. case 2:
  436. if(dwTickCount >= QDCT_MotorDelay)
  437. {
  438. back_dec_buff = dwRealPos;
  439. if(cZipCnt == 0)
  440. {
  441. cSeBiaoOk = 0;
  442. cSeBiaoEn = 1;
  443. AxisContinueMove(X_AXIS,QDCT_BACK_LOWSPEED,QDCT_DIR_P);
  444. }
  445. else
  446. {
  447. AxisContinueMove(X_AXIS,QDCT_PARAM_JJBACK_SPEED,QDCT_DIR_P);
  448. }
  449. QDCT_MotorStep = 3;
  450. }
  451. break;
  452. case 3:
  453. if(cZipCnt != 0)
  454. {
  455. if(QDCT_PARAM_SET_ZIPPER_LENGTH >= (QDCT_SEBIAO_LENGTH + QDCT_REMAIN_CHECK_LENGTH))
  456. {
  457. cSeBiaoOk = 0;
  458. cSeBiaoEn = 1;
  459. }
  460. else
  461. {
  462. if((dwRealPos - back_dec_buff) >= (QDCT_PARAM_SET_ZIPPER_LENGTH - QDCT_SEBIAO_LENGTH - QDCT_REMAIN_CHECK_LENGTH))
  463. {
  464. cSeBiaoOk = 0;
  465. cSeBiaoEn = 1;
  466. }
  467. }
  468. }
  469. if((dwRealPos - back_dec_buff) > (QDCT_PARAM_SET_ZIPPER_LENGTH - (QDCT_BACK_LOWSPEED_LENGTH + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QDCT_PARAM_JJBACK_SPEED,QDCT_BACK_LOWSPEED,30)))))
  470. {
  471. if(X_DRV)MoveChangSpeed(X_AXIS,QDCT_BACK_LOWSPEED);
  472. }
  473. if(cSeBiaoOk)
  474. {
  475. cSeBiaoOk = 0;
  476. cSeBiaoEn = 0;
  477. QDCT_MotorStep = 4;
  478. }
  479. break;
  480. case 4:
  481. if(!X_DRV)
  482. {
  483. QDCT_MotorStep = 0;
  484. }
  485. break;
  486. case 30:
  487. QDCT_MotorDelay = dwTickCount + QDCT_PARAM_DELAY_BACK;
  488. QDCT_MotorStep = 31;
  489. break;
  490. case 31:
  491. if(dwTickCount >= QDCT_MotorDelay)
  492. {
  493. back_buff = dwRealPos;
  494. gou_zhen_buff = dwRealPos;
  495. save_buff = dwRealPos;
  496. MoveAction_Pulse2(X_AXIS,PosToPulse(X_AXIS,QDCT_PARAM_SET_ZIPPER_LENGTH),PosToPulse(X_AXIS,QDCT_PARAM_PUTIN_SPEED_LENGTH),PosToPulse(X_AXIS,QDCT_BACK_LOWSPEED_LENGTH),QDCT_PARAM_JJBACK_SPEED,QDCT_PARAM_PUTIN_SPEED);
  497. QDCT_MotorStep = 33;
  498. }
  499. break;
  500. case 32:
  501. if((dwRealPos - back_buff) >= (QDCT_PARAM_PUTIN_LENGTH + QDCT_PARAM_PUTIN_START_LENGTH))
  502. {
  503. QDCT_JLT_OUT = 0;
  504. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  505. QDCT_MotorStep = 33;
  506. }
  507. else if(!X_DRV)
  508. {
  509. QDCT_JLT_OUT = 0;
  510. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  511. QDCT_MotorStep = 33;
  512. }
  513. break;
  514. case 33:
  515. if(!QDCT_JLT_IN)
  516. {
  517. QDCT_XM_OUT = 0;
  518. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  519. QDCT_MotorStep = 34;
  520. }
  521. else if(!X_DRV)
  522. {
  523. QDCT_XM_OUT = 0;
  524. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  525. QDCT_MotorStep = 34;
  526. }
  527. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_JLT_ALARM);
  528. break;
  529. case 34:
  530. if(!X_DRV && QDCT_XM_ORIGIN_IN && !QDCT_XM_LIMIT_IN)
  531. {
  532. // AxisMovePos(X_AXIS,QDCT_BACK_LOWSPEED,QDCT_PARAM_JJFZ_LENGTH);
  533. QDCT_MotorStep = 35;
  534. }
  535. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_XM_ORIGIN_ALARM);
  536. break;
  537. case 35:
  538. if(!X_DRV)
  539. {
  540. QDCT_MotorStep = 36;
  541. }
  542. break;
  543. case 36:
  544. QDCT_MotorStep = 0;
  545. break;
  546. case 40:
  547. if(dwTickCount >= QDCT_MotorDelay)
  548. {
  549. jz_buff = dwRealPos;
  550. if(QDCT_PARAM_SJZ_LENGTH == 0)
  551. {
  552. QDCT_JD_OUT = 0;
  553. }
  554. QDCT_MotorDelay = dwTickCount + QDCT_PARAN_SJ_TIME;
  555. QDCT_MotorStep = 41;
  556. }
  557. break;
  558. case 41:
  559. if(QDCT_JD_OUT && (dwTickCount >= QDCT_MotorDelay))
  560. {
  561. AxisMovePos(X_AXIS,QDCT_PARAM_CUTBACK_SPEED,-(QDCT_PARAM_SJZ_LENGTH + QDCT_PARAM_CUT_BACK_LENGTH));
  562. QDCT_MotorStep = 42;
  563. }
  564. break;
  565. case 42: // 切断完成后拉电机动作
  566. if(((QDCT_PARAM_SJZ_LENGTH) <= (dwRealPos - jz_buff)))
  567. {
  568. QDCT_JD_OUT = 0;
  569. QDCT_MotorStep = 43;
  570. }
  571. else if(!X_DRV)
  572. {
  573. QDCT_JD_OUT = 0;
  574. QDCT_MotorStep = 43;
  575. }
  576. break;
  577. case 43: // 切断完成后拉电机动作
  578. if(!X_DRV)
  579. {
  580. QDCT_MotorStep = 0;
  581. QDCT_MotorDelay = dwTickCount;
  582. }
  583. break;
  584. case 61: // 前点定位数控模式
  585. if(QDCT_JD_OUT)
  586. {
  587. QDCT_JD_OUT = 0;
  588. QDCT_MotorDelay = dwTickCount + 50;
  589. }
  590. if(!QDCT_TL_OUT)
  591. {
  592. //if(QD_TuiLianStep == 0)
  593. {
  594. QDCT_MotorStep = 62;
  595. }
  596. }
  597. else
  598. QDCT_MotorStep = 62;
  599. break;
  600. case 62:
  601. if(dwTickCount >= QDCT_MotorDelay)
  602. {
  603. if(QDCT_GO_LIMIT_IN || QDCT_GO_DEC_IN)
  604. {
  605. AxisMovePos(X_AXIS,QDCT_BACK_LOWSPEED,-QDCT_PARAM_ON_BACK_LENGTH);
  606. QDCT_MotorDelay = dwTickCount + 1000;
  607. }
  608. QDCT_MotorStep = 63;
  609. QDCT_JD_OUT = 0;
  610. }
  611. break;
  612. case 63:
  613. if(!X_DRV && !QDCT_GO_LIMIT_IN && (dwTickCount >= QDCT_MotorDelay) && QDCT_XM_ORIGIN_IN)
  614. {
  615. go_buff = dwRealPos;
  616. if(dwZipCnt > 0)
  617. {
  618. MoveAction_Const_Stop(X_AXIS, QDCT_DIR_N,QDCT_PARAM_JJGO_SPEED);//
  619. }
  620. else
  621. {
  622. MoveAction_Const_Stop(X_AXIS, QDCT_DIR_N,QDCT_PARAM_GO_LOWSPEED);
  623. }
  624. QDCT_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  625. QDCT_MotorStep = 64;
  626. }
  627. break;
  628. case 64:
  629. if(((go_buff - dwRealPos) > ((QDCT_PARAM_SET_ZIPPER_LENGTH - QDCT_PARAM_OFFSET_LENGTH) - (QDCT_PARAM_GO_LOWSPEED + PulseToPos(X_AXIS,MV_Cal_Dec_pulse(QDCT_PARAM_JJBACK_SPEED,QDCT_BACK_LOWSPEED,30))) + QDCT_BACK_LOWSPEED_LENGTH + QDCT_PARAM_SJZ_LENGTH + QDCT_PARAM_CUT_BACK_LENGTH)) || QDCT_GO_DEC_IN_UP)
  630. {
  631. MoveChangSpeed(X_AXIS,QDCT_PARAM_GO_LOWSPEED);
  632. QDCT_MotorStep =65;
  633. }
  634. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_NO_ZIPPER_ALARM);
  635. break;
  636. case 65:
  637. if(QDCT_GO_LIMIT_IN_UP)
  638. {
  639. AxisEgmStop(X_AXIS);
  640. QDCT_MotorStep = 66;
  641. }
  642. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_NO_ZIPPER_ALARM);
  643. else if(QDCT_JD_ALARM)QDCT_SetAlarmCode(QDCT_JD_ALARM);
  644. break;
  645. case 66:
  646. if(!X_DRV)
  647. {
  648. QDCT_MotorDelay = dwTickCount;
  649. QDCT_MotorStep = 67;
  650. }
  651. break;
  652. case 67:
  653. if(dwTickCount >= QDCT_MotorDelay)
  654. {
  655. if(bRunning)
  656. {
  657. QDCT_JD_OUT = 1;
  658. QDCT_MotorDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  659. QDCT_MotorStep = 68;
  660. }
  661. else
  662. {
  663. QDCT_MotorStep = 0;
  664. }
  665. }
  666. break;
  667. case 68:
  668. if(QDCT_JZ_LEFT_IN && QDCT_JZ_RIGHT_IN)
  669. {
  670. QDCT_MotorDelay = dwTickCount + QDCT_PARAM_JD_DELAY;
  671. QDCT_MotorStep = 69;
  672. }
  673. else if(dwTickCount >= QDCT_MotorDelay)QDCT_SetAlarmCode(QDCT_JD_ALARM);
  674. break;
  675. case 69:
  676. if(dwTickCount >= QDCT_MotorDelay)QDCT_MotorStep = 0;
  677. break;
  678. }
  679. }
  680. //切断动作
  681. void QDCT_XiaQieAction(void)
  682. {
  683. if(QDCT_XiaQieStep == 1)
  684. {
  685. QDCT_XiaQieStep = 2;
  686. QDCT_XiaQieDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  687. QDCT_XQ_OUT = 1;
  688. }
  689. else if(QDCT_XiaQieStep == 2)
  690. {
  691. if(QDCT_XQ_LIMIT_IN)
  692. {
  693. QDCT_XiaQieStep = 3;
  694. }
  695. else if(dwTickCount >= QDCT_XiaQieDelay)
  696. {
  697. QDCT_SetAlarmCode(14);
  698. }
  699. }
  700. else if(QDCT_XiaQieStep == 3)
  701. {
  702. QDCT_SQ_OUT = 1;
  703. QDCT_XiaQieDelay = dwTickCount + QDCT_PARAM_CUTBACK_DELAY;
  704. QDCT_XiaQieStep = 4;
  705. }
  706. else if((QDCT_XiaQieStep == 4) && (dwTickCount >= QDCT_XiaQieDelay))
  707. {
  708. QDCT_SQ_OUT = 0;
  709. QDCT_XQ_OUT = 0;
  710. QDCT_XiaQieDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  711. QDCT_XiaQieStep = 5;
  712. }
  713. else if(QDCT_XiaQieStep == 5)
  714. {
  715. if(!QDCT_SQ_LIMIT_IN && QDCT_XQ_ORIGIN_IN)
  716. {
  717. QDCT_XiaQieStep = 0;
  718. }
  719. else if(dwTickCount >= QDCT_XiaQieDelay)
  720. {
  721. if(!QDCT_SQ_LIMIT_IN) QDCT_SetAlarmCode(QDCT_SQ_ORIGIN_ALARM);
  722. else if(!QDCT_XQ_ORIGIN_IN)QDCT_SetAlarmCode(QDCT_XQ_ORIGIN_ALARM);
  723. }
  724. }
  725. }
  726. //装拉头动作
  727. void QDCT_ZLT_Step(void)
  728. {
  729. if(QDCT_ZhuangLiaoStep == 1)
  730. {
  731. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  732. QDCT_ZhuangLiaoStep = 2;
  733. }
  734. else if(QDCT_ZhuangLiaoStep == 2)
  735. {
  736. if(QDCT_SongLiaoStep == 0)
  737. {
  738. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  739. QDCT_ZhuangLiaoStep = 3;
  740. }
  741. }
  742. else if(QDCT_ZhuangLiaoStep == 3)
  743. {
  744. if(QDCT_HSL_ORIGIN_IN)
  745. {
  746. QDCT_HSL_OUT = 1;
  747. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  748. QDCT_ZhuangLiaoStep = 4;
  749. }
  750. else if(dwTickCount >= QDCT_XiaQieDelay)
  751. {
  752. QDCT_SetAlarmCode(QDCT_HSL_ORIGIN_ALARM);
  753. }
  754. }
  755. else if(QDCT_ZhuangLiaoStep == 4)
  756. {
  757. if(QDCT_HSL_LIMIT_IN)
  758. {
  759. QDCT_JLT_OUT = 1;
  760. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  761. QDCT_ZhuangLiaoStep = 5;
  762. }
  763. else if(dwTickCount >= QDCT_XiaQieDelay)
  764. {
  765. QDCT_SetAlarmCode(QDCT_HSL_LIMIT_ALARM);
  766. }
  767. }
  768. else if(QDCT_ZhuangLiaoStep == 5)
  769. {
  770. if(QDCT_JLT_IN)
  771. {
  772. QDCT_ZhuangLiaoStep = 6;
  773. }
  774. else if(dwTickCount >= QDCT_XiaQieDelay)
  775. {
  776. QDCT_SetAlarmCode(QDCT_JLT_ALARM);
  777. }
  778. }
  779. else if(QDCT_ZhuangLiaoStep == 6)
  780. {
  781. QDCT_HSL_OUT = 0;
  782. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  783. QDCT_ZhuangLiaoStep = 7;
  784. }
  785. else if(QDCT_ZhuangLiaoStep == 7)
  786. {
  787. if(!QDCT_HSL_LIMIT_IN)
  788. {
  789. QDCT_XM_OUT = 1;
  790. if(QDCT_SongLiaoStep == 0)QDCT_SongLiaoStep = 1;
  791. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  792. QDCT_ZhuangLiaoStep = 8;
  793. }
  794. else if(dwTickCount >= QDCT_XiaQieDelay)
  795. {
  796. QDCT_SetAlarmCode(QDCT_HSL_LIMIT_ALARM);
  797. }
  798. }
  799. else if(QDCT_ZhuangLiaoStep == 8)
  800. {
  801. if(QDCT_XM_LIMIT_IN)
  802. {
  803. QDCT_ZhuangLiaoStep = 9;
  804. QDCT_ZhuangLiaoDelay = dwTickCount + 1000;
  805. }
  806. else if(dwTickCount >= QDCT_XiaQieDelay)
  807. {
  808. QDCT_SetAlarmCode(QDCT_XM_LIMIT_ALARM);
  809. }
  810. }
  811. else if(QDCT_ZhuangLiaoStep == 9)
  812. {
  813. if(QDCT_LTCZ_IN)
  814. {
  815. if(QDCT_PARAM_LOCK_TIME)
  816. {
  817. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_PARAM_LOCK_TIME;
  818. QDCT_SLT_OUT = 1;
  819. QDCT_ZhuangLiaoStep = 20;
  820. }
  821. else
  822. {
  823. QDCT_ZhuangLiaoStep = 0;
  824. ZhuangLiaoOkFlg = 1;
  825. }
  826. TryCnt = 0;
  827. }
  828. else if(dwTickCount >= QDCT_XiaQieDelay)
  829. {
  830. TryCnt++;
  831. if(TryCnt > 4)
  832. {
  833. QDCT_SetAlarmCode(QDCT_ZLT_ALARM);
  834. }
  835. else
  836. {
  837. QDCT_ZhuangLiaoStep = 10;
  838. }
  839. }
  840. SongLaTouOkFlg = 0;
  841. }
  842. else if(QDCT_ZhuangLiaoStep == 10) //装拉头失败重复装几次拉头
  843. {
  844. QDCT_XM_OUT = 0;
  845. QDCT_JLT_OUT = 0;
  846. QDCT_ZhuangLiaoDelay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  847. QDCT_ZhuangLiaoStep = 11;
  848. }
  849. else if(QDCT_ZhuangLiaoStep == 11)
  850. {
  851. if(QDCT_XM_ORIGIN_IN)
  852. {
  853. QDCT_ZhuangLiaoStep = 12;
  854. }
  855. else if(dwTickCount >= QDCT_XiaQieDelay)
  856. {
  857. QDCT_SetAlarmCode(QDCT_XM_ORIGIN_ALARM);
  858. }
  859. }
  860. else if(QDCT_ZhuangLiaoStep == 12)
  861. {
  862. QDCT_ZhuangLiaoStep = 1;
  863. }
  864. else if(QDCT_ZhuangLiaoStep == 20)
  865. {
  866. QDCT_ZhuangLiaoStep = 0;
  867. QDCT_ZhuangLiaoDelay = dwTickCount;
  868. ZhuangLiaoOkFlg = 1;
  869. }
  870. }
  871. void QDCT_SL_Step(void)
  872. {
  873. if(QDCT_SongLiaoStep == 1)
  874. {
  875. if(SongLaTouOkFlg)
  876. {
  877. QDCT_SongLiaoStep = 0;
  878. }
  879. else
  880. {
  881. QDCT_SL_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  882. QDCT_SongLiaoStep = 2;
  883. }
  884. }
  885. else if(QDCT_SongLiaoStep == 2)
  886. {
  887. if(QDCT_HSL_ORIGIN_IN)
  888. {
  889. QDCT_SL_OUT = 1;
  890. QDCT_SL_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  891. QDCT_SongLiaoStep = 3;
  892. }
  893. else if(dwTickCount >= QDCT_SL_Delay)
  894. QDCT_SetAlarmCode(QDCT_SL_ALARM);
  895. }
  896. else if(QDCT_SongLiaoStep == 3)
  897. {
  898. if(QDCT_HSL_LIMIT_IN)
  899. {
  900. QDCT_SL_OUT = 0;
  901. QDCT_SL_Delay = dwTickCount + QDCT_VAVLE_ERROR_TIME;
  902. QDCT_SongLiaoStep = 4;
  903. }
  904. else if(dwTickCount >= QDCT_SL_Delay)
  905. QDCT_SetAlarmCode(QDCT_SL_ALARM);
  906. }
  907. else if(QDCT_SongLiaoStep == 4)
  908. {
  909. if(!QDCT_HSL_LIMIT_IN)
  910. {
  911. QDCT_SongLiaoStep = 0;
  912. }
  913. else if(dwTickCount >= QDCT_SL_Delay)
  914. QDCT_SetAlarmCode(QDCT_SL_ALARM);
  915. }
  916. }
  917. //手动动作
  918. void QDCT_ManualAction(void)
  919. {
  920. if(bRunning == 0)
  921. {
  922. if(bClearTotal) //切断计数清零
  923. {
  924. bClearTotal = 0;
  925. ClrcToTal(QDCT_TOTAL_ADDR);
  926. }
  927. if(QDCT_bClerNowTotal)
  928. {
  929. QDCT_bClerNowTotal = 0;
  930. ClrcToTal(QDCT_NOWTOTAL_ADDR);
  931. }
  932. if(QDCT_bManXQ)
  933. {
  934. QDCT_bManXQ = 0;
  935. if(QDCT_XiaQieStep == 0)QDCT_XiaQieStep = 1;
  936. }
  937. if(QDCT_bQianDianDW)
  938. {
  939. QDCT_bQianDianDW = 0;
  940. if(QDCT_MotorStep == 0)
  941. {
  942. QDCT_MotorStep = 61;
  943. dwZipCnt = 0;
  944. }
  945. }
  946. if(QDCT_bManXM)
  947. {
  948. QDCT_bManXM = 0;
  949. QDCT_XM_OUT = ~QDCT_XM_OUT;
  950. }
  951. if(QDCT_bManSQ)
  952. {
  953. QDCT_bManSQ = 0;
  954. QDCT_SQ_OUT = ~QDCT_SQ_OUT;
  955. }
  956. if(QDCT_bManJD)
  957. {
  958. QDCT_bManJD = 0;
  959. QDCT_JD_OUT = ~QDCT_JD_OUT;
  960. }
  961. if(QDCT_bManSL)
  962. {
  963. QDCT_bManSL = 0;
  964. QDCT_SL_OUT = ~QDCT_SL_OUT;
  965. }
  966. if(QDCT_bManHSL)
  967. {
  968. QDCT_bManHSL = 0;
  969. QDCT_HSL_OUT = ~QDCT_HSL_OUT;
  970. }
  971. if(QDCT_bManZD)
  972. {
  973. QDCT_bManZD = 0;
  974. if(QDCT_ZDP_OUT == 0)
  975. {
  976. QDCT_ZDP_OUT = 1;
  977. QDCT_ZhenDongDelay = dwTickCount + QDCT_PARAM_ZD_WORK_TIME;
  978. }
  979. }
  980. if(QDCT_bManKL)
  981. {
  982. QDCT_bManKL = 0;
  983. if(QDCT_KL_OUT == 0)
  984. {
  985. QDCT_KL_OUT = 1;
  986. QDCT_KL_Delay = dwTickCount + QDCT_PARAM_KL_DELAY;
  987. }
  988. }
  989. if(QDCT_bManSLT)
  990. {
  991. QDCT_bManSLT = 0;
  992. QDCT_SLT_OUT = ~QDCT_SLT_OUT;
  993. }
  994. if(QDCT_bManJLT)
  995. {
  996. QDCT_bManJLT = 0;
  997. QDCT_JLT_OUT = ~QDCT_JLT_OUT;
  998. }
  999. if(QDCT_bZhuangLiao)
  1000. {
  1001. QDCT_bZhuangLiao = 0;
  1002. if(QDCT_ZhuangLiaoStep == 0)QDCT_ZhuangLiaoStep = 1;
  1003. }
  1004. if(QDCT_bSongLT)
  1005. {
  1006. QDCT_bSongLT = 0;
  1007. if(QDCT_SongLiaoStep == 0)
  1008. {
  1009. QDCT_SongLiaoStep = 1;
  1010. SongLaTouOkFlg = 0;
  1011. }
  1012. }
  1013. if(QDCT_bChuanLT)
  1014. {
  1015. QDCT_bChuanLT = 0;
  1016. if(QDCT_MotorStep == 0)QDCT_MotorStep = 30;
  1017. }
  1018. //电机控制
  1019. if(QDCT_bMotorGo && !QDCT_GO_LIMIT_IN)
  1020. {
  1021. QDCT_JD_OUT = 0;
  1022. if(!X_DRV)AxisContinueMove(X_AXIS,QDCT_PARAM_JJGO_SPEED,QDCT_DIR_P);
  1023. }
  1024. if(QDCT_bMotorBack && !QDCT_BACK_LIMIT_IN)
  1025. {
  1026. QDCT_JD_OUT = 0;
  1027. if(!X_DRV)AxisContinueMove(X_AXIS,QDCT_PARAM_JJGO_SPEED,QDCT_DIR_N);
  1028. }
  1029. if(!QDCT_bMotorGo && !QDCT_bMotorBack && (QDCT_MotorStep == 0))
  1030. {
  1031. if(X_DRV)AxisDecStop(X_AXIS);
  1032. }
  1033. if(QDCT_GO_LIMIT_IN && (QDCT_MotorStep == 0) && !QDCT_bMotorBack &&(QDCT_AutoStep == 0))
  1034. {
  1035. if(X_DRV)AxisEgmStop(X_AXIS);
  1036. }
  1037. }
  1038. }
  1039. #endif