YWXTieBuJi.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. #include "global.h"
  2. #if YU_WEN_XUAN_MACHINE
  3. void TBJ_InitAction(void);
  4. void TBJ_Action(void);
  5. void TBJ_ChuiQi(void);
  6. void TBJ_ChaoSheng(void);
  7. void TBJ_HeMo(void);
  8. void TBJ_SetAlarmCode(unsigned alarm_code);
  9. void TBJ_StartStopAction(void);
  10. void TBJ_AutoRunStep(void);
  11. void TBJ_Motor(void);
  12. void TBJ_SongJiao(void);
  13. void TBJ_SetAlarmCode(unsigned alarm_code)
  14. {
  15. SetAlarmCode(TBJ_ALARM_ADDR,alarm_code);
  16. TBJ_bAlarmStop = 1;
  17. }
  18. void TBJ_InitAction(void)
  19. {
  20. XGearRatio = 1;
  21. }
  22. void TBJ_ChuiQi(void)
  23. {
  24. if(TBJ_CQ_VAVLE && (dwTickCount >= TBJ_CQ_Delay))
  25. {
  26. TBJ_CQ_VAVLE = 0;
  27. }
  28. }
  29. void TBJ_ChaoSheng(void)
  30. {
  31. if(TBJ_CS_OUT && (dwTickCount >= TBJ_CS_Delay))
  32. {
  33. TBJ_CS_OUT = 0;
  34. }
  35. }
  36. //手动动作
  37. void TBJ_ManualAction(void)
  38. {
  39. if(!TBJ_bRunning)
  40. {
  41. //警告跳出
  42. if(bClearTotal)
  43. {
  44. bClearTotal = 0;
  45. ClrcToTal(TBJ_TOTAL_ADDR);
  46. }
  47. if(TBJ_bMotor)
  48. {
  49. if(!X_DRV)AxisContinueMove(X_AXIS,TBJ_PARAM_HIGH_SPEED,TBJ_DIR_P);
  50. }
  51. else
  52. {
  53. if(X_DRV)AxisDecStop(X_AXIS);
  54. }
  55. if(TBJ_bGouZhen)
  56. {
  57. TBJ_bGouZhen = 0;
  58. TBJ_GZ_VAVLE = ~TBJ_GZ_VAVLE;
  59. }
  60. if(TBJ_bQianDao)
  61. {
  62. TBJ_bQianDao = 0;
  63. TBJ_QDB_VAVLE = ~TBJ_QDB_VAVLE;
  64. }
  65. if(TBJ_bJiaJiao)
  66. {
  67. TBJ_bJiaJiao = 0;
  68. TBJ_JJ_VAVLE = ~TBJ_JJ_VAVLE;
  69. }
  70. if(TBJ_bSongJiao)
  71. {
  72. TBJ_bSongJiao = 0;
  73. TBJ_SJ_VAVLE = ~TBJ_SJ_VAVLE;
  74. }
  75. if(TBJ_bCS)
  76. {
  77. TBJ_bCS = 0;
  78. TBJ_CS_OUT = 1;
  79. TBJ_CS_Delay = dwTickCount + TBJ_PARAM_CS_TIME;
  80. }
  81. if(TBJ_bChuiQi)
  82. {
  83. TBJ_bChuiQi = 0;
  84. TBJ_CQ_VAVLE = 1;
  85. TBJ_CQ_Delay = dwTickCount + TBJ_PARAM_CQ_TIME;
  86. }
  87. if(TBJ_bSM)
  88. {
  89. TBJ_bSM = 0;
  90. TBJ_SM_VAVLE = ~TBJ_SM_VAVLE;
  91. }
  92. if(TBJ_bXM)
  93. {
  94. TBJ_bXM = 0;
  95. TBJ_XM_VAVLE = ~TBJ_XM_VAVLE;
  96. }
  97. if(TBJ_bHeMo)
  98. {
  99. TBJ_bHeMo = 0;
  100. if(TBJ_HeMoStep == 0)TBJ_HeMoStep = 1;
  101. }
  102. if(TBJ_bFenJiao)
  103. {
  104. TBJ_bFenJiao = 0;
  105. TBJ_FJ_VAVLE = ~TBJ_FJ_VAVLE;
  106. }
  107. }
  108. }
  109. void TBJ_SongJiao(void)
  110. {
  111. if(TBJ_SongJiaoStep == 1)
  112. {
  113. TBJ_SongJiaoStep = 2;
  114. }
  115. else if(TBJ_SongJiaoStep == 2)
  116. {
  117. TBJ_SongJiaoStep = 3;
  118. }
  119. else if(TBJ_SongJiaoStep == 3)
  120. {
  121. TBJ_SongJiaoStep = 4;
  122. }
  123. else if(TBJ_SongJiaoStep == 4)
  124. {
  125. TBJ_SongJiaoStep = 5;
  126. }
  127. else if(TBJ_SongJiaoStep == 5)
  128. {
  129. TBJ_SongJiaoStep = 6;
  130. }
  131. else if(TBJ_SongJiaoStep == 6)
  132. {
  133. TBJ_SongJiaoStep = 0;
  134. }
  135. }
  136. //打孔动作
  137. void TBJ_Action(void)
  138. {
  139. TBJ_ManualAction();
  140. TBJ_ChuiQi();
  141. TBJ_ChaoSheng();
  142. TBJ_HeMo();
  143. TBJ_StartStopAction();
  144. TBJ_AutoRunStep();
  145. TBJ_Motor();
  146. TBJ_SongJiao();
  147. }
  148. //合模动作
  149. void TBJ_HeMo(void)
  150. {
  151. if(TBJ_HeMoStep == 1)
  152. {
  153. TBJ_HeMoDelay = dwTickCount + TBJ_PARAM_HM_DELAY;
  154. TBJ_HeMoStep = 2;
  155. }
  156. else if((TBJ_HeMoStep == 2) && (dwTickCount >= TBJ_HeMoDelay))
  157. {
  158. TBJ_XM_VAVLE = 1;
  159. TBJ_HeMoDelay = dwTickCount + VAVLE_ALARM_TIME;
  160. TBJ_HeMoStep = 3;
  161. }
  162. else if(TBJ_HeMoStep == 3)
  163. {
  164. if(TBJ_XM_LIMIT_IN)
  165. {
  166. TBJ_SM_VAVLE = 1;
  167. TBJ_HeMoDelay = dwTickCount + VAVLE_ALARM_TIME;
  168. TBJ_HeMoStep = 4;
  169. }
  170. else if(dwTickCount >= TBJ_HeMoDelay)
  171. {
  172. TBJ_SetAlarmCode(TBJ_HM_LIMIT_ALARM);
  173. }
  174. }
  175. else if(TBJ_HeMoStep == 4)
  176. {
  177. if(TBJ_SM_LIMIT_IN)
  178. {
  179. TBJ_HeMoDelay = dwTickCount + TBJ_PARAM_DELAY_CS;
  180. TBJ_HeMoStep = 5;
  181. }
  182. else if(dwTickCount >= TBJ_HeMoDelay)
  183. {
  184. TBJ_SetAlarmCode(TBJ_HM_LIMIT_ALARM);
  185. }
  186. }
  187. else if((TBJ_HeMoStep == 5) && (dwTickCount >= TBJ_HeMoDelay))
  188. {
  189. TBJ_CS_OUT = 1;
  190. TBJ_CS_Delay = dwTickCount + TBJ_PARAM_CS_TIME;
  191. TBJ_HeMoStep = 6;
  192. }
  193. else if((TBJ_HeMoStep == 6) && (TBJ_CS_OUT == 0))
  194. {
  195. TBJ_HeMoDelay = dwTickCount + TBJ_PARAM_COLD_TIME;
  196. TBJ_HeMoStep = 7;
  197. }
  198. else if((TBJ_HeMoStep == 7) && (dwTickCount >= TBJ_HeMoDelay))
  199. {
  200. TBJ_SM_VAVLE = 0;
  201. TBJ_XM_VAVLE = 0;
  202. TBJ_HeMoDelay = dwTickCount + VAVLE_ALARM_TIME;
  203. TBJ_HeMoStep = 7;
  204. }
  205. else if(TBJ_HeMoStep == 7)
  206. {
  207. if(!TBJ_SM_LIMIT_IN && !TBJ_XM_LIMIT_IN)
  208. {
  209. TBJ_HeMoStep = 0;
  210. }
  211. else if(dwTickCount >= TBJ_HeMoDelay)
  212. {
  213. if(TBJ_SM_LIMIT_IN)TBJ_SetAlarmCode(TBJ_HM_LIMIT_ALARM);
  214. else if(TBJ_XM_LIMIT_IN)TBJ_SetAlarmCode(TBJ_HM_LIMIT_ALARM);
  215. }
  216. }
  217. }
  218. //启动停止故障停止动作
  219. void TBJ_StartStopAction(void)
  220. {
  221. if((START_IN_UP || TBJ_bStart) && !TBJ_bRunning && (TBJ_AutoStep ==0))
  222. {
  223. if(GetTotal(TBJ_TOTAL_ADDR) >= SET_TOTAL)TBJ_SetAlarmCode(TBJ_TOTAL_ALARM);
  224. else
  225. {
  226. TBJ_AutoStep = 1;
  227. TBJ_bRunning = 1;
  228. TBJ_AutoDelay = 0;
  229. }
  230. TBJ_bStart = 0;
  231. }
  232. if(TBJ_KaDai_IN && (GetAlarmCode(TBJ_ALARM_ADDR) == 0))
  233. {
  234. TBJ_SetAlarmCode(TBJ_KADAI_ALARM);
  235. }
  236. if(STOP_IN_UP || TBJ_bStop)
  237. {
  238. TBJ_bStop = 0;
  239. if(TBJ_bRunning && (SingOneFlg == 0))
  240. {
  241. SingOneFlg = 1;
  242. }
  243. else
  244. {
  245. TBJ_GZ_VAVLE = 0;
  246. TBJ_QDB_VAVLE = 0;
  247. TBJ_JJ_VAVLE = 0;
  248. TBJ_SJ_VAVLE = 0;
  249. TBJ_FJ_VAVLE = 0;
  250. TBJ_SM_VAVLE = 0;
  251. TBJ_XM_VAVLE = 0;
  252. TBJ_CQ_VAVLE = 0;
  253. TBJ_CS_OUT = 0;
  254. TBJ_HeMoStep = 0;
  255. TBJ_bRunning = 0;
  256. TBJ_AutoStep = 0;
  257. AxisEgmStop(X_AXIS);
  258. }
  259. }
  260. if(TBJ_bAlarmStop)
  261. {
  262. TBJ_bAlarmStop = 0;
  263. AxisEgmStop(X_AXIS);
  264. TBJ_AutoStep = 0;
  265. TBJ_HeMoStep = 0;
  266. TBJ_bRunning = 0;
  267. SingOneFlg = 0;
  268. }
  269. }
  270. //电机动作
  271. void TBJ_Motor(void) //
  272. {
  273. static long save_buff,length_buff;
  274. switch(TBJ_MotorStep)
  275. {
  276. case 0:
  277. break;
  278. case 1:
  279. QD_MotorStep = 2;
  280. break;
  281. case 2:
  282. save_buff = GetPos(X_AXIS);
  283. if(dwZipCnt <= 1)
  284. {
  285. AxisContinueMove(X_AXIS,TBJ_PARAM_LOW_SPEED,TBJ_DIR_P); //第一条走低速
  286. }
  287. else
  288. {
  289. AxisMoveTwoPos(X_AXIS,TBJ_PARAM_HIGH_SPEED,(length_buff - TBJ_PARAM_LOWSPEED_LENGTH),TBJ_PARAM_LOW_SPEED,0xFFFFFF,TBJ_DIR_P);//第二条开始走两段速
  290. }
  291. TBJ_MotorDelay = dwTickCount + GUO_LIAN_OVER_TIME;
  292. QD_MotorStep = 3;
  293. break;
  294. case 3:
  295. if(TBJ_GUO_LIAN_IN_UP)
  296. {
  297. QD_MotorStep = 4;
  298. TBJ_MotorDelay = dwTickCount + TBJ_PARAM_DELAY_GZ;
  299. }
  300. else if(dwTickCount >= TBJ_MotorDelay)
  301. {
  302. }
  303. if(TBJ_GZ_IN)
  304. {
  305. AxisEgmStop(X_AXIS);
  306. QD_MotorStep = 6;
  307. }
  308. break;
  309. case 4:
  310. if(dwTickCount >= TBJ_MotorDelay)
  311. {
  312. TBJ_GZ_VAVLE = 1;
  313. QD_MotorStep = 5;
  314. }
  315. if(TBJ_GZ_IN)
  316. {
  317. AxisEgmStop(X_AXIS);
  318. QD_MotorStep = 6;
  319. }
  320. break;
  321. case 5:
  322. if(TBJ_GZ_IN)
  323. {
  324. AxisEgmStop(X_AXIS);
  325. QD_MotorStep = 6;
  326. }
  327. break;
  328. case 6:
  329. if(!X_DRV)
  330. {
  331. if(dwZipCnt == 1)length_buff = GetPos(X_AXIS) - save_buff; //以第二条测量出来的长度为准来做减速
  332. QD_MotorStep = 0;
  333. }
  334. break;
  335. }
  336. }
  337. //自动运行动作
  338. void TBJ_AutoRunStep(void)
  339. {
  340. if(TBJ_bRunning)
  341. {
  342. if(TBJ_AutoStep == 1)
  343. {
  344. dwZipCnt = 0;
  345. TBJ_AutoStep = 2;
  346. }
  347. else if((TBJ_AutoStep == 2) && (dwTickCount >= TBJ_AutoDelay))
  348. {
  349. if(QD_MotorStep == 0)QD_MotorStep = 1;
  350. TBJ_AutoStep = 3;
  351. }
  352. else if(TBJ_AutoStep == 3)
  353. {
  354. if(QD_MotorStep == 0)
  355. {
  356. TBJ_AutoStep = 4;
  357. }
  358. }
  359. else if(TBJ_AutoStep == 4)
  360. {
  361. if(TBJ_HeMoStep == 0)TBJ_HeMoStep = 1;
  362. TBJ_AutoStep = 5;
  363. }
  364. else if(TBJ_AutoStep == 5)
  365. {
  366. if(TBJ_HeMoStep == 0)
  367. {
  368. TBJ_AutoStep = 6;
  369. }
  370. }
  371. else if(TBJ_AutoStep == 6)
  372. {
  373. AddToTal(TBJ_TOTAL_ADDR);
  374. dwZipCnt++;
  375. if((GetTotal(TBJ_TOTAL_ADDR) >= TBJ_PARAM_SET_TOTAL) || SingOneFlg)
  376. {
  377. if(SingOneFlg)
  378. {
  379. TBJ_AutoStep = 0;
  380. TBJ_bRunning = 0;
  381. SingOneFlg = 0;
  382. }
  383. else
  384. {
  385. TBJ_SetAlarmCode(TBJ_TOTAL_ALARM);
  386. }
  387. }
  388. else
  389. {
  390. TBJ_AutoStep = 2;
  391. TBJ_AutoDelay = TBJ_PARAM_CYCLE_DELAY + dwTickCount;
  392. CalProSP(TBJ_PROSPEED_ADDR);
  393. }
  394. }
  395. }
  396. }
  397. #endif