YXJinShuDinCun.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. #include "global.h"
  2. #if FJ_YING_XING_MACHINE==1
  3. void JSDC_CheckStart(void);
  4. void JSDC_Motor(void);
  5. void JSDC_XiaChong(void);
  6. void JSDC_ChuiQi(void);
  7. void JSDC_ValveAction(void);
  8. void JSDC_ManualAction(void);
  9. void JSDC_AutoAction(void);
  10. unsigned char JSDC_cLFengTimer,JSDC_cRFengTimer;
  11. unsigned char JSDC_cGZDW_CNT=0,JSDC_SingOne=0,JSDC_oneDEL=0,JSDC_twoDEL=0;
  12. unsigned char JSDC_SingOneFlag = 0,JSDC_FirstFlg = 0;
  13. unsigned char JSDC_cAlarmStopFlg = 0;
  14. //故障报警
  15. void JSDC_SetAlarmCode(unsigned alarm_code)
  16. {
  17. SetAlarmCode(JSDC_ALARM_ADDR,alarm_code);
  18. JSDC_bAlarmStop = 1;
  19. }
  20. void JSDC_InitAction(void)
  21. {
  22. float length_buff,pulse_buff;
  23. length_buff = JSDC_PARAM_DAILUN_LENGTH;
  24. pulse_buff = JSDC_PARAM_CYCLE_PULSE;
  25. XGearRatio = pulse_buff/length_buff;
  26. JSDC_SZ_OUT = 1;
  27. }
  28. void JSDC_Action(void)
  29. {
  30. JSDC_CheckStart(); //启动
  31. JSDC_XiaChong(); //下冲
  32. JSDC_ChuiQi();
  33. JSDC_ValveAction();
  34. JSDC_Motor(); //拖带控制
  35. JSDC_ManualAction();
  36. JSDC_AutoAction();
  37. }
  38. void JSDC_ManualAction(void)
  39. {
  40. if((JSDC_bRunning) == 0) ////手动
  41. {
  42. if(JSDC_bXiaChong | JSDC_ManualXC_IN_UP)
  43. {
  44. JSDC_bXiaChong = 0;
  45. JSDC_twoDEL=1;
  46. JSDC_cValveStep=1;
  47. if(JSDC_cXiaChongStep == 0)
  48. JSDC_cXiaChongStep = 1;
  49. }
  50. if(JSDC_bMotorSZ)
  51. {
  52. JSDC_bMotorSZ = 0;
  53. JSDC_SZ_OUT = ~JSDC_SZ_OUT;
  54. }
  55. //手动测试气缸
  56. if(JSDC_bDingZhen)
  57. {
  58. JSDC_bDingZhen = 0;
  59. JSDC_DingZhen_VAVLE = ~JSDC_DingZhen_VAVLE;
  60. }
  61. if(JSDC_bRightXuanChi)
  62. {
  63. JSDC_bRightXuanChi = 0;
  64. JSDC_RightXC_VAVLE = ~JSDC_RightXC_VAVLE;
  65. }
  66. if(JSDC_bLeftXuanChi)
  67. {
  68. JSDC_bLeftXuanChi = 0;
  69. JSDC_LeftXC_VAVLE = ~JSDC_LeftXC_VAVLE;
  70. }
  71. //点动下冲
  72. if((JSDC_bDotXiaChong))
  73. {
  74. JSDC_bDotXiaChong = 0;
  75. if(JSDC_cXiaChongStep == 0)JSDC_cXiaChongStep = 20;
  76. }
  77. }
  78. }
  79. void JSDC_AutoAction(void)
  80. {
  81. //监控参数
  82. user_datas[121] = JSDC_cAutoStep;
  83. user_datas[122] = JSDC_cMotorStep;
  84. user_datas[123] = 1;
  85. user_datas[124] = JSDC_cXiaChongStep;
  86. user_datas[125] = 2;
  87. user_datas[126] = 3;
  88. user_datas[127] = dwRealPos;
  89. user_datas[128]= dwRealPos;
  90. dwRealPos = GetPos(X_AXIS);
  91. if(JSDC_bRunning)
  92. {
  93. switch(JSDC_cAutoStep)
  94. {
  95. case 0:
  96. break;
  97. case 1:
  98. if(dwTickCount >= JSDC_cAutoDelay)
  99. {
  100. JSDC_cAutoStep = 2;
  101. }
  102. break;
  103. case 2:
  104. if(dwTickCount >= JSDC_cAutoDelay)
  105. {
  106. JSDC_cAutoStep = 3;
  107. JSDC_cMotorStep = 1; //启动拖带
  108. }
  109. break;
  110. case 3:
  111. //拖带已经完成
  112. if(JSDC_cMotorStep == 0)
  113. {
  114. JSDC_cValveStep=1;
  115. JSDC_cAutoStep = 4;
  116. }
  117. break;
  118. case 4:
  119. if(JSDC_cValveStep == 0)
  120. {
  121. JSDC_cAutoStep = 5;
  122. }
  123. break;
  124. case 5:
  125. if(JSDC_cXiaChongStep == 0)
  126. {
  127. JSDC_cXiaChongStep = 1; //下冲电机启动
  128. JSDC_cAutoStep = 6;
  129. }
  130. break;
  131. case 6: //下冲已完成
  132. if((JSDC_cXiaChongStep == 0) || (JSDC_cXiaChongStep == 6))
  133. {
  134. DISPLAY_DATA0 =1;
  135. dwZipCnt++;
  136. if(JSDC_cGZDW_CNT < 3)
  137. JSDC_cGZDW_CNT++;
  138. if(!JSDC_SingOneFlag)
  139. {
  140. AddToTal(JSDC_TOTAL_ADDR); //计数增加和保存
  141. CalProSP(JSDC_PROSPEED_ADDR);
  142. }
  143. JSDC_cAutoStep = 7;
  144. }
  145. break;
  146. case 7:
  147. if(!JSDC_GouZhen_IN)
  148. {
  149. if(GetTotal(JSDC_TOTAL_ADDR) >= JSDC_SET_TOTAL)
  150. {
  151. JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
  152. }
  153. JSDC_cAutoStep = 8;
  154. }
  155. break;
  156. case 8:
  157. JSDC_cAutoDelay = dwTickCount + JSDC_PARAM_MOTOR_DELAY;
  158. JSDC_cAutoStep = 1;
  159. if(JSDC_SingOneFlag)
  160. {
  161. JSDC_cGZDW_CNT=0;
  162. dwZipCnt = 0;
  163. JSDC_SingOneFlag = 0;
  164. JSDC_SingOne=1;
  165. JSDC_cAutoStep = 0;
  166. JSDC_bRunning = 0;
  167. }
  168. break;
  169. }
  170. }
  171. }
  172. // 检测是否踏了脚踏开关
  173. void JSDC_CheckStart(void)
  174. {
  175. // 停止键 不能在工作,手动,停止过程中
  176. if((JSDC_bRunning == 0) && (JSDC_START_IN_UP || JSDC_bStart || JSDC_Single))
  177. {
  178. if(GetTotal(JSDC_TOTAL_ADDR) >= JSDC_SET_TOTAL)JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
  179. else if(JSDC_KaDai_IN)JSDC_SetAlarmCode(JSDC_KA_DAI_ALARM);
  180. else
  181. {
  182. if(JSDC_Single)
  183. {
  184. JSDC_SingOneFlag = 1;
  185. JSDC_Single = 0;
  186. }
  187. JSDC_bRunning = 1;
  188. JSDC_twoDEL=0;
  189. JSDC_cAutoStep = 1;
  190. JSDC_SingOne=0;
  191. JSDC_GouZhen_VAVLE = 1;
  192. JSDC_cGZDW_CNT = 0;
  193. JSDC_cGouZhenTime = 1;
  194. dwZipCnt = 0;
  195. JSDC_cAutoDelay = dwTickCount;
  196. JSDC_cMotorDelay = dwTickCount;
  197. JSDC_cXiaChongDelay = dwTickCount;
  198. }
  199. JSDC_bStart = 0;
  200. JSDC_Single = 0;
  201. }
  202. //卡带感应
  203. if(JSDC_KaDai_IN)
  204. {
  205. JSDC_SetAlarmCode(JSDC_KA_DAI_ALARM);
  206. }
  207. else
  208. {
  209. if(GetAlarmCode(JSDC_ALARM_ADDR) == JSDC_KA_DAI_ALARM)SetAlarmCode(JSDC_ALARM_ADDR,0);
  210. }
  211. if(JSDC_KaDai_IN_UP)
  212. {
  213. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  214. }
  215. if(JSDC_bStop)
  216. {
  217. JSDC_bStop = 0;
  218. if(JSDC_bRunning)JSDC_SingOneFlag = 1;
  219. }
  220. if(JSDC_START_IN_UP || JSDC_bStop)
  221. {
  222. JSDC_bStop = 0;
  223. if(JSDC_bRunning)
  224. {
  225. if(JSDC_cXiaChongStep==0)
  226. {
  227. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  228. }
  229. JSDC_cGZDW_CNT=0;
  230. JSDC_SingOne=0;
  231. JSDC_twoDEL=1;
  232. JSDC_bRunning = 0;
  233. JSDC_cAutoStep = 0;
  234. JSDC_cMotorStep = 0;
  235. AxisEgmStop(X_AXIS);
  236. JSDC_SingOneFlag = 0;
  237. }
  238. else
  239. {
  240. JSDC_bRunning = 0;
  241. JSDC_cAutoStep = 0;
  242. JSDC_cMotorStep = 0;
  243. JSDC_cXiaChongStep = 0;
  244. JSDC_SingOne=0;
  245. JSDC_SingOneFlag = 0;
  246. if((JSDC_cChuiQiStep == 0) &&(JSDC_cXiaChongStep==0))
  247. JSDC_cChuiQiStep = 1;
  248. AxisEgmStop(X_AXIS);
  249. SetAlarmCode(JSDC_ALARM_ADDR,0);//报警清零
  250. JSDC_SetAlarmCode(0);//报警清零
  251. }
  252. }
  253. if(JSDC_bAlarmStop)
  254. {
  255. JSDC_bAlarmStop = 0;
  256. JSDC_Single = 0;
  257. JSDC_bRunning = 0;
  258. JSDC_cAutoStep = 0;
  259. JSDC_SingOne=0;
  260. JSDC_cMotorStep = 0;
  261. JSDC_SingOneFlag = 0;
  262. AxisEgmStop(X_AXIS);
  263. }
  264. }
  265. void JSDC_ValveAction(void)
  266. {
  267. switch(JSDC_cValveStep)
  268. {
  269. }
  270. }
  271. void JSDC_ChuiQi(void)
  272. {
  273. //吹气
  274. if(JSDC_XiaChong_IN_UP)
  275. {
  276. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  277. }
  278. switch(JSDC_cChuiQiStep)
  279. {
  280. case 1:
  281. JSDC_cChuiQiStep = 2;
  282. JSDC_cChuiQiDelay = dwTickCount+JSDC_PARAM_DELAY_CHUIQI_TIME;
  283. break;
  284. case 2:
  285. if(dwTickCount >= JSDC_cChuiQiDelay)
  286. {
  287. JSDC_cChuiQiDelay = dwTickCount + JSDC_PARAM_CHUIQI_TIME;
  288. JSDC_ChuiQi_VAVLE = 1;//
  289. JSDC_cChuiQiStep = 3;
  290. }
  291. break;
  292. case 3:
  293. if(dwTickCount >= JSDC_cChuiQiDelay)
  294. {
  295. JSDC_ChuiQi_VAVLE = 0;//
  296. JSDC_cChuiQiStep = 0;
  297. }
  298. break;
  299. case 6:
  300. JSDC_cChuiQiDelay = dwTickCount + JSDC_TDCQ_TIME;
  301. JSDC_ChuiQi_VAVLE = 1;//
  302. JSDC_cChuiQiStep = 7;
  303. break;
  304. case 7:
  305. if(dwTickCount >= JSDC_cChuiQiDelay)
  306. {
  307. JSDC_ChuiQi_VAVLE = 0;//
  308. JSDC_cChuiQiStep = 0;
  309. }
  310. break;
  311. }
  312. }
  313. void JSDC_Motor(void)
  314. {
  315. switch(JSDC_cMotorStep)
  316. {
  317. }
  318. }
  319. //下冲
  320. void JSDC_XiaChong(void)
  321. {
  322. switch(JSDC_cXiaChongStep)
  323. {
  324. }
  325. }
  326. #endif