YGDaKong.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. #include "global.h"
  2. #if YOU_GUAN_MACHINE
  3. void DK_InitAction(void);
  4. void DK_ChuiQi(void);
  5. void DK_Action(void);
  6. void DK_XiaChong(void);
  7. void DK_SetAlarmCode(unsigned alarm_code);
  8. void DK_StartStopAction(void);
  9. void DK_AutoRunStep(void);
  10. void DK_Motor(void);
  11. void DK_SetAlarmCode(unsigned alarm_code)
  12. {
  13. SetAlarmCode(DK_ALARM_ADDR,alarm_code);
  14. DK_bAlarmStop = 1;
  15. }
  16. void DK_InitAction(void)
  17. {
  18. float buff_pulse,buff_dist;
  19. buff_pulse = DK_PARAM_CYCLE_PULSE;
  20. buff_dist = DK_PARAM_CYCLE_LENGTH;
  21. XGearRatio = buff_pulse/buff_dist;
  22. }
  23. void DK_ChuiQi(void)
  24. {
  25. if(DK_XC_ORIGIN_IN_UP)
  26. {
  27. DK_CQ_VAVLE = 1;
  28. DK_CQ_Delay = dwTickCount + DK_PARAM_CQ_TIME;
  29. }
  30. if(DK_CQ_VAVLE && (dwTickCount >= DK_CQ_Delay))
  31. {
  32. DK_CQ_VAVLE = 0;
  33. }
  34. }
  35. //手动动作
  36. void DK_ManualAction(void)
  37. {
  38. if(!DK_bRunning)
  39. {
  40. //警告跳出
  41. if(bClearTotal)
  42. {
  43. bClearTotal = 0;
  44. ClrcToTal(DK_TOTAL_ADDR);
  45. }
  46. if(DK_bMotor)
  47. {
  48. if(!X_DRV)AxisContinueMove(X_AXIS,DK_PARAM_HIGH_SPEED,DK_DIR_N);
  49. }
  50. if(DK_bBackMotor)
  51. {
  52. if(!X_DRV)AxisContinueMove(X_AXIS,DK_PARAM_HIGH_SPEED,DK_DIR_P);
  53. }
  54. if(!DK_bMotor && !DK_bBackMotor)
  55. {
  56. if(X_DRV)AxisDecStop(X_AXIS);
  57. }
  58. if(DK_bCQ)
  59. {
  60. DK_bCQ = 0;
  61. DK_CQ_VAVLE = 1;
  62. DK_CQ_Delay = dwTickCount + DK_PARAM_CQ_TIME;
  63. }
  64. if(DK_bManXiaChong || (DK_MANAL_XC_IN && !DK_MANAL_XC_IN_UP))
  65. {
  66. DK_bManXiaChong = 0;
  67. if(DK_XiaChongStep == 0)
  68. {
  69. DK_XiaChongStep = 1;
  70. }
  71. }
  72. }
  73. }
  74. //打孔动作
  75. void DK_Action(void)
  76. {
  77. DISPLAY_DATA0 = GetEncodeCount();
  78. DK_ManualAction();
  79. DK_ChuiQi();
  80. DK_XiaChong();
  81. DK_StartStopAction();
  82. DK_AutoRunStep();
  83. DK_Motor();
  84. }
  85. //下冲动作
  86. void DK_XiaChong(void)
  87. {
  88. if(DK_XiaChongStep == 1)
  89. {
  90. if(DK_bRunning)DK_XiaChongDelay = dwTickCount + DK_PARAM_XC_DELAY + 50;
  91. else
  92. DK_XiaChongDelay = dwTickCount + 50;
  93. DK_SC_VAVLE = 0;
  94. DK_XiaChongStep = 2;
  95. }
  96. else if((DK_XiaChongStep == 2) && (dwTickCount >= DK_XiaChongDelay))
  97. {
  98. DK_XC_MOTOR = 1;
  99. if(DK_bRunning)DK_XiaChongDelay = dwTickCount + DK_PARAM_XC_ALARM_TIME;
  100. else
  101. DK_XiaChongDelay = dwTickCount + 5000;
  102. DK_XiaChongStep = 3;
  103. }
  104. else if(DK_XiaChongStep == 3)
  105. {
  106. if(DK_XC_ORIGIN_IN_UP)
  107. {
  108. DK_XC_MOTOR = 0;
  109. if(DK_bRunning)DK_XiaChongDelay = dwTickCount + DK_PARAM_XC_DELAY_STOP_TIME;
  110. else
  111. DK_XiaChongDelay = dwTickCount + 10;
  112. DK_XiaChongStep = 4;
  113. }
  114. else if(dwTickCount >= DK_XiaChongDelay)
  115. {
  116. DK_SC_VAVLE = 1;
  117. DK_XC_MOTOR = 0;
  118. DK_SetAlarmCode(DK_XM_LIMIT_ALARM);
  119. }
  120. }
  121. else if((DK_XiaChongStep == 4) && (dwTickCount >= DK_XiaChongDelay))
  122. {
  123. DK_SC_VAVLE = 1;
  124. DK_XiaChongStep = 0;
  125. }
  126. else if((DK_XiaChongStep == 5) && (dwTickCount >= DK_XiaChongDelay))
  127. {
  128. DK_SC_VAVLE = 0;
  129. DK_XiaChongStep = 0;
  130. }
  131. }
  132. //启动停止故障停止动作
  133. void DK_StartStopAction(void)
  134. {
  135. if((START_IN_UP || DK_bStart) && !DK_bRunning && (DK_AutoStep ==0))
  136. {
  137. if(GetTotal(DK_TOTAL_ADDR) >= SET_TOTAL)DK_SetAlarmCode(DK_TOTAL_ALARM);
  138. else
  139. {
  140. DK_AutoStep = 1;
  141. DK_bRunning = 1;
  142. DK_AutoDelay = 0;
  143. }
  144. DK_bStart = 0;
  145. }
  146. if(DK_KaDai_IN && (GetAlarmCode(DK_ALARM_ADDR) == 0))
  147. {
  148. DK_SetAlarmCode(DK_KADAI_ALARM);
  149. }
  150. if(STOP_IN_UP || DK_bStop)
  151. {
  152. DK_bStop = 0;
  153. if(DK_bRunning && (SingOneFlg == 0))
  154. {
  155. SingOneFlg = 1;
  156. }
  157. else
  158. {
  159. DK_CQ_VAVLE = 0;
  160. DK_bRunning = 0;
  161. DK_AutoStep = 0;
  162. AxisEgmStop(X_AXIS);
  163. }
  164. }
  165. if(DK_bAlarmStop)
  166. {
  167. DK_bAlarmStop = 0;
  168. AxisEgmStop(X_AXIS);
  169. DK_AutoStep = 0;
  170. DK_XiaChongStep = 0;
  171. DK_bRunning = 0;
  172. SingOneFlg = 0;
  173. }
  174. }
  175. //电机动作
  176. void DK_Motor(void) //
  177. {
  178. static long save_buff,length_buff;
  179. switch(DK_MotorStep)
  180. {
  181. case 0:
  182. break;
  183. case 1:
  184. QD_MotorStep = 2;
  185. break;
  186. case 2:
  187. if(!X_DRV)AxisMoveTwoPos(X_AXIS,DK_PARAM_HIGH_SPEED,(DK_PARAM_ZIPRER_LENGTH - DK_PARAM_LOWSPEED_LENGTH),DK_PARAM_LOW_SPEED,DK_PARAM_LOWSPEED_LENGTH,DK_DIR_N);
  188. QD_MotorStep = 3;
  189. break;
  190. case 3:
  191. if(!X_DRV)
  192. {
  193. QD_MotorStep = 0;
  194. }
  195. break;
  196. case 10:
  197. QD_MotorStep = 11;
  198. break;
  199. case 11:
  200. QD_MotorStep = 12;
  201. if(!X_DRV)AxisMovePos(X_AXIS,DK_PARAM_HIGH_SPEED,-DK_PARAM_BACK_LENGTH);
  202. break;
  203. case 12:
  204. if(!X_DRV)
  205. {
  206. QD_MotorStep = 0;
  207. }
  208. break;
  209. }
  210. }
  211. //自动运行动作
  212. void DK_AutoRunStep(void)
  213. {
  214. if(DK_bRunning)
  215. {
  216. if(DK_AutoStep == 1)
  217. {
  218. DK_AutoStep = 2;
  219. }
  220. else if((DK_AutoStep == 2) && (dwTickCount >= DK_AutoDelay))
  221. {
  222. if(QD_MotorStep == 0)QD_MotorStep = 1;
  223. DK_AutoStep = 3;
  224. }
  225. else if(DK_AutoStep == 3)
  226. {
  227. if(QD_MotorStep == 0)
  228. {
  229. DK_AutoStep = 4;
  230. }
  231. }
  232. else if(DK_AutoStep == 4)
  233. {
  234. if(QD_MotorStep == 0)QD_MotorStep = 10;
  235. DK_AutoStep = 5;
  236. }
  237. else if(DK_AutoStep == 5)
  238. {
  239. if(QD_MotorStep == 0)
  240. {
  241. DK_AutoStep = 6;
  242. }
  243. }
  244. else if(DK_AutoStep == 6)
  245. {
  246. if(DK_XiaChongStep == 0)
  247. {
  248. DK_XiaChongStep = 1;
  249. DK_XiaChongDelay = dwTickCount + DK_PARAM_XC_DELAY;
  250. }
  251. DK_AutoStep = 7;
  252. }
  253. else if(DK_AutoStep == 7)
  254. {
  255. if(DK_XiaChongStep == 0)
  256. {
  257. DK_AutoStep = 8;
  258. }
  259. }
  260. else if(DK_AutoStep == 8)
  261. {
  262. AddToTal(DK_TOTAL_ADDR);
  263. if((GetTotal(DK_TOTAL_ADDR) >= DK_PARAM_SET_TOTAL) || SingOneFlg)
  264. {
  265. if(SingOneFlg)
  266. {
  267. DK_AutoStep = 0;
  268. DK_bRunning = 0;
  269. SingOneFlg = 0;
  270. }
  271. else
  272. {
  273. DK_SetAlarmCode(DK_TOTAL_ALARM);
  274. }
  275. }
  276. else
  277. {
  278. DK_AutoStep = 2;
  279. DK_AutoDelay = DK_PARAM_CYCLE_DELAY + dwTickCount;
  280. CalProSP(DK_PROSPEED_ADDR);
  281. }
  282. }
  283. }
  284. }
  285. #endif