HYJinShuDinCun.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. #include "global.h"
  2. #if HONG_YE_MACHINE
  3. unsigned char JSDC_cFirstFlg = 0,JSDC_cSeBiaoStep = 0;
  4. unsigned short JSDC_SecondToothNum = 0;
  5. unsigned char JSDC_cCntEn = 0;
  6. unsigned long JSDC_dwSeBiaoDelayCnt = 0;
  7. long JSDC_RemainLength = 0;
  8. unsigned long CalEncodePulse(void);
  9. void JSDC_DelayAction(void);
  10. void JSDC_InitAction(void);
  11. void JSDC_ExtiActionX30(void);
  12. void JSDC_Action(void);
  13. void JSDC_ModeSelect(void);
  14. void JSDC_ChuiQi(void);
  15. void JSDC_XiaChong(void);
  16. void JSDC_SetAlarmCode(unsigned alarm_code);
  17. void JSDC_StartStopAction(void);
  18. void JSDC_AutoRunStep(void);
  19. void JSDC_SetAlarmCode(unsigned alarm_code)
  20. {
  21. SetAlarmCode(JSDC_ALARM_ADDR,alarm_code);
  22. JSDC_bAlarmStop = 1;
  23. }
  24. void JSDC_InitAction(void)
  25. {
  26. float buff_pulse,buff_dist;
  27. buff_pulse = JSDC_PARAM_CYCLE_PULSE;
  28. buff_dist = JSDC_PARAM_CYCLE_LENGTH;
  29. XGearRatio = buff_pulse/buff_dist;
  30. if(JSDC_XC_MODE)JSDC_XiaChong_MOTOR = 1;
  31. }
  32. //手动动作
  33. void JSDC_ManualAction(void)
  34. {
  35. //清理产量
  36. if(bClearTotal)
  37. {
  38. bClearTotal = 0;
  39. ClrcToTal(JSDC_TOTAL_ADDR);
  40. }
  41. if(!JSDC_bRunning)
  42. {
  43. if(JSDC_bAdd)
  44. {
  45. JSDC_bAdd = 0;
  46. if(JSDC_SET_ALL_LENGTH < 9999999)
  47. {
  48. SetData32bits(12,JSDC_SET_ALL_LENGTH+50);
  49. JSDC_bSetCM = 1;
  50. }
  51. }
  52. if(JSDC_bDec)
  53. {
  54. JSDC_bDec = 0;
  55. if(JSDC_SET_ALL_LENGTH >= 50)
  56. {
  57. SetData32bits(12,JSDC_SET_ALL_LENGTH-50);
  58. JSDC_bSetCM = 1;
  59. }
  60. }
  61. if(JSDC_bLeftFZ)
  62. {
  63. JSDC_bLeftFZ = 0;
  64. JSDC_LFZ_VAVLE = ~JSDC_LFZ_VAVLE;
  65. }
  66. if(JSDC_bRightFZ)
  67. {
  68. JSDC_bRightFZ = 0;
  69. JSDC_RFZ_VAVLE = ~JSDC_RFZ_VAVLE;
  70. }
  71. if(JSDC_bYD)
  72. {
  73. JSDC_bYD = 0;
  74. JSDC_YD_VAVLE = ~JSDC_YD_VAVLE;
  75. }
  76. if(JSDC_bGZ)
  77. {
  78. JSDC_bGZ = 0;
  79. JSDC_GZ_VAVLE = ~JSDC_GZ_VAVLE;
  80. }
  81. if(JSDC_bXC || JSDC_ManXiaChong_UP)
  82. {
  83. JSDC_bXC = 0;
  84. if(JSDC_XiaChongStep == 0)
  85. {
  86. JSDC_XiaChongStep = 1;
  87. }
  88. }
  89. if(JSDC_bCQ)
  90. {
  91. JSDC_bCQ = 0;
  92. JSDC_ChuiQi_VAVLE = 1;
  93. JSDC_ChuiQiDelay = dwTickCount + JSDC_PARAM_CHUIQI_TIME;
  94. }
  95. if(JSDC_bMotor)
  96. {
  97. if(!X_DRV)AxisContinueMove(X_AXIS,JSDC_PARAM_HIGH_SPEED,JSDC_DIR_P);
  98. }
  99. else
  100. {
  101. if(X_DRV)AxisDecStop(X_AXIS);
  102. }
  103. if(JSDC_bSetCM)
  104. {
  105. JSDC_bSetCM = 0;
  106. SetData32bits(8,CalInch(JSDC_SET_ZIPPER_LENGTH));
  107. JSDC_SET_KONGWEI_LENGTH_INCH = CalInch(JSDC_SET_KONGWEI_LENGTH);
  108. SetData32bits(14,CalInch(JSDC_SET_ALL_LENGTH));
  109. }
  110. if(JSDC_bSetInch)
  111. {
  112. JSDC_bSetInch = 0;
  113. SetData32bits(6,CalLengthCM(JSDC_SET_ZIPPER_LENGTH));
  114. JSDC_SET_KONGWEI_LENGTH = CalLengthCM(JSDC_SET_KONGWEI_LENGTH_INCH);
  115. SetData32bits(12,CalLengthCM(JSDC_SET_ALL_LENGTH));
  116. JSDC_bSetCM = 1;
  117. }
  118. }
  119. }
  120. //高速输入X30/X16定时器中断
  121. void JSDC_ExtiActionX30(void)
  122. {
  123. }
  124. //高速输入X31/X17外部色标信号中断
  125. void JSDC_ExtiActionX31(void)
  126. {
  127. }
  128. //胶牙定寸动作
  129. void JSDC_Action(void)
  130. {
  131. JSDC_ManualAction();
  132. JSDC_ChuiQi();
  133. JSDC_XiaChong();
  134. JSDC_StartStopAction();
  135. JSDC_AutoRunStep();
  136. }
  137. //输入拉链长度返回所输入拉链长度所对应的齿数
  138. unsigned long JS_GetToothNum(unsigned long zipper_length)
  139. {
  140. float length_buff1,tooth_buff,length_buff2;
  141. length_buff1 = zipper_length;
  142. tooth_buff = JY_JIZHUN_CISHU;
  143. length_buff2 = JY_JIZHUN_LEN;
  144. return (unsigned long)round(length_buff1 * tooth_buff / length_buff2);
  145. }
  146. //吹气动作
  147. void JSDC_ChuiQi(void)
  148. {
  149. if(JSDC_ChuiQi_VAVLE)
  150. {
  151. if(JSDC_ChuiQiDelay < dwTickCount)JSDC_ChuiQi_VAVLE = 0;
  152. }
  153. }
  154. //下冲动作
  155. void JSDC_XiaChong(void)
  156. {
  157. if(JSDC_XiaChongStep == 1)
  158. {
  159. if(JSDC_XC_MODE)
  160. {
  161. JSDC_XiaChongDelay = dwTickCount + XIACONG_DELAY_TIME;
  162. JSDC_ShaChe_VAVLE = 0;
  163. JSDC_XiaChongStep = 2;
  164. }
  165. else
  166. {
  167. if(JSDC_XC_ORIGIN_IN)
  168. {
  169. JSDC_XiaChongDelay = dwTickCount + XIACONG_DELAY_TIME;
  170. JSDC_XiaChongStep = 20;
  171. }
  172. else
  173. {
  174. JSDC_SetAlarmCode(JSDC_XIACHONG_LIMIT_ALARM);
  175. }
  176. }
  177. }
  178. else if((JSDC_XiaChongStep == 2) && (dwTickCount >= JSDC_XiaChongDelay))
  179. {
  180. JSDC_LiHe_VAVLE = 1;
  181. JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_XC_ALARM_TIME;
  182. JSDC_XiaChongStep = 3;
  183. }
  184. else if(JSDC_XiaChongStep == 3)
  185. {
  186. if(JSDC_XC_ORIGIN_IN_UP)
  187. {
  188. JSDC_LiHe_VAVLE = 0;
  189. JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_SHACHE_DELAY_TIME;
  190. JSDC_XiaChongStep = 4;
  191. }
  192. else if(dwTickCount >= JSDC_XiaChongDelay)
  193. {
  194. JSDC_SetAlarmCode(JSDC_XIACHONG_LIMIT_ALARM);
  195. JSDC_XiaChong_MOTOR = 0;
  196. JSDC_ShaChe_VAVLE = 0;
  197. }
  198. }
  199. else if((JSDC_XiaChongStep == 4) && (dwTickCount >= JSDC_XiaChongDelay))
  200. {
  201. JSDC_ShaChe_VAVLE = 1;
  202. if(JSDC_SC_MODE)
  203. {
  204. JSDC_XiaChongStep = 6;
  205. }
  206. else
  207. {
  208. JSDC_XiaChongStep = 5;
  209. JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_SHACHE_TIME;
  210. }
  211. }
  212. else if((JSDC_XiaChongStep == 5) && (dwTickCount >= JSDC_XiaChongDelay))
  213. {
  214. JSDC_ShaChe_VAVLE = 0;
  215. JSDC_XiaChongStep = 6;
  216. }
  217. else if(JSDC_XiaChongStep == 6)
  218. {
  219. JSDC_GZ_VAVLE = 0;
  220. JSDC_XiaChongStep = 0;
  221. }
  222. else if((JSDC_XiaChongStep == 20) && (dwTickCount >= JSDC_XiaChongDelay))
  223. {
  224. JSDC_XiaChong_MOTOR = 1;
  225. JSDC_XiaChongStep = 21;
  226. JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_XC_ALARM_TIME;
  227. }
  228. else if(JSDC_XiaChongStep == 21)
  229. {
  230. if(JSDC_XC_LIMIT_IN)
  231. {
  232. JSDC_XiaChong_MOTOR = 0;
  233. JSDC_GZ_VAVLE = 0;
  234. JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_XC_ALARM_TIME;
  235. JSDC_XiaChongStep = 22;
  236. }
  237. else if(dwTickCount >= JSDC_XiaChongDelay)
  238. {
  239. JSDC_SetAlarmCode(JSDC_XIACHONG_LIMIT_ALARM);
  240. }
  241. }
  242. else if(JSDC_XiaChongStep == 22)
  243. {
  244. if(JSDC_XC_ORIGIN_IN)
  245. {
  246. JSDC_XiaChongStep = 0;
  247. }
  248. else if(dwTickCount >= JSDC_XiaChongDelay)
  249. {
  250. JSDC_SetAlarmCode(JSDC_XIACHONG_ORIGIN_ALARM);
  251. }
  252. }
  253. }
  254. //启动停止故障停止动作
  255. void JSDC_StartStopAction(void)
  256. {
  257. if((START_IN_UP || JSDC_bStart) && !JSDC_bRunning && (JSDC_AutoStep ==0))
  258. {
  259. if(!JSDC_XC_ORIGIN_IN)JSDC_SetAlarmCode(JSDC_START_XIACHONG_ALARM);
  260. else if(GetTotal(JSDC_TOTAL_ADDR) >= SET_TOTAL)JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
  261. else
  262. {
  263. JSDC_AutoStep = 1;
  264. JSDC_bRunning = 1;
  265. JSDC_AutoDelay = 0;
  266. }
  267. JSDC_bStart = 0;
  268. }
  269. if(STOP_IN_UP || JSDC_bStop)
  270. {
  271. JSDC_bStop = 0;
  272. if(JSDC_bRunning && (SingOneFlg == 0))
  273. {
  274. SingOneFlg = 1;
  275. }
  276. else
  277. {
  278. JSDC_ChuiQi_VAVLE = 1;
  279. JSDC_ChuiQiDelay = dwTickCount + JSDC_PARAM_CHUIQI_TIME * 10;
  280. JSDC_bRunning = 0;
  281. JSDC_AutoStep = 0;
  282. AxisEgmStop(X_AXIS);
  283. SingOneFlg = 0;
  284. }
  285. }
  286. if(JSDC_bAlarmStop)
  287. {
  288. JSDC_bAlarmStop = 0;
  289. AxisEgmStop(X_AXIS);
  290. JSDC_AutoStep = 0;
  291. JSDC_bRunning = 0;
  292. SingOneFlg = 0;
  293. }
  294. }
  295. unsigned long JSDC_ToothTransPulse(unsigned long tooth)
  296. {
  297. return(JY_JIZHUN_LEN * tooth * 2000 / 250 / JY_JIZHUN_CISHU);
  298. }
  299. long GetEnCodePos(void)
  300. {
  301. return 0;
  302. }
  303. //电机控制动作
  304. void JSDC_Motor(void) //
  305. {
  306. static long save_buff,length_buff;
  307. switch(JSDC_MotorStep)
  308. {
  309. case 0: break;
  310. case 1://使用电机长度定寸
  311. JSDC_MotorStep = 2;
  312. break;
  313. case 2:
  314. AxisMovePos(X_AXIS,JSDC_PARAM_HIGH_SPEED,JSDC_SET_ALL_LENGTH);
  315. JSDC_MotorStep = 3;
  316. break;
  317. case 3:
  318. if(!X_DRV)JSDC_MotorStep = 0;
  319. break;
  320. case 20://使用勾针定寸
  321. JSDC_MotorStep = 21;
  322. break;
  323. case 21:
  324. if(dwTickCount >= JSDC_MotorDelay)
  325. {
  326. save_buff = GetPos(X_AXIS);
  327. if(dwZipCnt == 0)AxisContinueMove(X_AXIS,JSDC_PARAM_LOW_SPEED,JSDC_DIR_P); //第一条走低速
  328. else
  329. AxisMoveTwoPos(X_AXIS,JSDC_PARAM_HIGH_SPEED,(length_buff - JSDC_PARAM_LOWSPEED_LENGTH),JSDC_PARAM_LOW_SPEED,0xFFFFFF,JSDC_DIR_P);
  330. JSDC_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
  331. JSDC_MotorStep = 22;
  332. }
  333. break;
  334. case 22:
  335. if(JSDC_GUO_LIAN_IN_UP)
  336. {
  337. JSDC_MotorDelay = dwTickCount + JSDC_PARAM_GZ_DELAY;
  338. JSDC_MotorStep = 23;
  339. }
  340. else if(dwTickCount >= JSDC_MotorDelay)
  341. {
  342. JSDC_SetAlarmCode(JSDC_NO_ZIPPER_ALARM);
  343. }
  344. break;
  345. case 23:
  346. if(JSDC_GZ_RESET_MODE)
  347. {
  348. if(dwZipCnt < 2) //第一第二条勾针自己复位
  349. {
  350. if(dwTickCount >= JSDC_MotorDelay)
  351. {
  352. JSDC_GZ_VAVLE = 1;
  353. JSDC_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  354. JSDC_MotorStep = 24;
  355. }
  356. }
  357. else
  358. {
  359. if((GetPos(X_AXIS) - save_buff) >= JSDC_GZ_RESET_LENGTH)
  360. {
  361. JSDC_GZ_VAVLE = 1;
  362. JSDC_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  363. JSDC_MotorStep = 24;
  364. }
  365. }
  366. }
  367. else
  368. {
  369. if(dwTickCount >= JSDC_MotorDelay)
  370. {
  371. JSDC_GZ_VAVLE = 1;
  372. JSDC_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
  373. JSDC_MotorStep = 24;
  374. }
  375. }
  376. break;
  377. case 24:
  378. if(JSDC_GZ_IN)
  379. {
  380. AxisEgmStop(X_AXIS);
  381. JSDC_MotorStep = 25;
  382. }
  383. else if(dwTickCount >= JSDC_MotorDelay)
  384. {
  385. JSDC_SetAlarmCode(JSDC_GZ_ALARM);
  386. }
  387. break;
  388. case 25:
  389. if(!X_DRV)
  390. {
  391. JSDC_YD_VAVLE = 1;
  392. JSDC_MotorDelay = dwTickCount + JSDC_PARAM_YD_DELAY;
  393. JSDC_MotorStep = 26;
  394. }
  395. break;
  396. case 26:
  397. if(dwTickCount >= JSDC_MotorDelay)
  398. {
  399. if(dwZipCnt == 1)length_buff = GetPos(X_AXIS) - save_buff;
  400. JSDC_MotorStep = 27;
  401. }
  402. break;
  403. case 27:
  404. JSDC_MotorStep = 0;
  405. break;
  406. }
  407. }
  408. //自动运行动作
  409. void JSDC_AutoRunStep(void)
  410. {
  411. SetData32bits(16,GetEncodeCount());//刷新编码器位置
  412. if(JSDC_bRunning)
  413. {
  414. if(JSDC_AutoStep == 1)
  415. {
  416. JSDC_AutoStep = 2;
  417. }
  418. else if((JSDC_AutoStep == 2))
  419. {
  420. JSDC_AutoStep = 3;
  421. JSDC_RemainLength = JSDC_SET_KONGWEI_LENGTH;
  422. }
  423. else if(JSDC_AutoStep == 3)
  424. {
  425. if(JSDC_MotorStep == 0)JSDC_MotorStep = 1;
  426. JSDC_AutoStep = 4;
  427. }
  428. else if((JSDC_AutoStep == 4) && !X_DRV)
  429. {
  430. if(JSDC_MotorStep == 0)
  431. {
  432. if(JSDC_XiaChongStep == 0)JSDC_XiaChongStep = 1;
  433. JSDC_AutoStep = 5;
  434. }
  435. }
  436. else if(JSDC_AutoStep == 5)
  437. {
  438. if(JSDC_XiaChongStep == 0)
  439. {
  440. JSDC_AutoStep = 6;
  441. if(JSDC_RemainLength >= JSDC_PARAM_DAOKOU_LENGTH)
  442. {
  443. JSDC_RemainLength -= JSDC_PARAM_DAOKOU_LENGTH;
  444. JSDC_AutoStep = 3;
  445. }
  446. else
  447. {
  448. JSDC_RemainLength = 0;
  449. JSDC_AutoStep = 6;
  450. }
  451. }
  452. }
  453. else if(JSDC_AutoStep == 6)
  454. {
  455. AddToTal(JSDC_TOTAL_ADDR);
  456. if((GetTotal(JSDC_TOTAL_ADDR) >= SET_TOTAL) || JSDC_bStop || SingOneFlg)
  457. {
  458. if(JSDC_bStop || SingOneFlg)
  459. {
  460. JSDC_bStop = 0;
  461. JSDC_AutoStep = 0;
  462. JSDC_bRunning = 0;
  463. SingOneFlg = 0;
  464. JSDC_XiaChong_MOTOR = 0;
  465. }
  466. else
  467. {
  468. JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
  469. }
  470. }
  471. else
  472. {
  473. JSDC_AutoStep = 1;
  474. JSDC_AutoDelay = JSDC_PARAM_CYCLE_DELAY + dwTickCount;
  475. CalProSP(JSDC_PROSPEED_ADDR);
  476. }
  477. }
  478. else if(JSDC_AutoStep == 7)
  479. {
  480. }
  481. else if((JSDC_AutoStep == 8))
  482. {
  483. }
  484. else if((JSDC_AutoStep == 20) && (dwTickCount >= JSDC_AutoDelay)) //色标动作
  485. {
  486. }
  487. else if(JSDC_AutoStep == 21)
  488. {
  489. }
  490. else if(JSDC_AutoStep == 22)
  491. {
  492. JSDC_AutoStep = 23;
  493. }
  494. else if((JSDC_AutoStep == 23) && (dwTickCount >= JSDC_AutoDelay))
  495. {
  496. }
  497. else if(JSDC_AutoStep == 24)
  498. {
  499. }
  500. else if(JSDC_AutoStep == 25)
  501. {
  502. }
  503. else if(JSDC_AutoStep == 26)
  504. {
  505. }
  506. else if((JSDC_AutoStep == 27))
  507. {
  508. }
  509. }
  510. }
  511. #endif