YWXJinShuDinCun.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. #include "global.h"
  2. #if YU_WEN_XUAN_MACHINE
  3. void JSDC_CheckStart(void);
  4. void JSDC_Motor(void);
  5. void JSDC_XiaChong(void);
  6. void JSDC_FenZhen(void);
  7. void JSDC_ChuiQi(void);
  8. void JSDC_SD(void);
  9. void JSDC_ManualAction(void);
  10. void JSDC_AutoAction(void);
  11. unsigned char JSDC_CheckPos(void);
  12. unsigned long JSDC_cZipperLength[2];
  13. unsigned char JSDC_cCheckLengthOk=0;
  14. unsigned char JSDC_STOP_IN_FLAG,JSDC_STOP_IN_FLAG_OLD,JSDC_STOP_FILTER;
  15. unsigned char JSDC_SingOneFlag = 0,JSDC_FirstFlg = 0;
  16. unsigned char JSDC_cAlarmStopFlg = 0;
  17. long JSDC_dwEncPos = 0;
  18. long JSDC_SaveLength = 0;
  19. unsigned short JSDC_cRFengTimer,JSDC_cLFengTimer;
  20. //故障报警
  21. void JSDC_SetAlarmCode(unsigned alarm_code)
  22. {
  23. SetAlarmCode(JSDC_ALARM_ADDR,alarm_code);
  24. JSDC_bAlarmStop = 1;
  25. JSDC_cAlarmStopFlg = 1;
  26. }
  27. //高速输入X20外部色标信号中断
  28. void JSDC_ExtiActionX20(void)
  29. {
  30. }
  31. void JSDC_InitAction(void)
  32. {
  33. float length_buff,pulse_buff;
  34. CalFreqTab_X_Free(25);
  35. length_buff = JSDC_PARAM_DAILUN_LENGTH;
  36. pulse_buff = JSDC_PARAM_CYCLE_PULSE;
  37. XGearRatio = pulse_buff/length_buff;
  38. length_buff = JSDC_BM_LENGTH;
  39. pulse_buff = 1000;
  40. BMGearRatio = pulse_buff/length_buff;
  41. JSDC_SZ_OUT = JSDC_SERVER_DISEN;
  42. JSDC_STOP_IN_FLAG = STOP_IN;
  43. JSDC_STOP_IN_FLAG_OLD = JSDC_STOP_IN_FLAG;
  44. JSDC_SaveLength = 0;
  45. }
  46. void JSDC_Action(void)
  47. {
  48. JSDC_CheckStart(); //启动
  49. JSDC_FenZhen(); //左分针
  50. JSDC_XiaChong(); //下冲
  51. JSDC_ChuiQi();
  52. JSDC_SD();
  53. JSDC_Motor(); //拖带控制
  54. JSDC_ManualAction();
  55. JSDC_AutoAction();
  56. }
  57. void JSDC_ManualAction(void)
  58. {
  59. long i;
  60. short *len_buff;
  61. //清总产量
  62. if(JSDC_bClear) //清总产量
  63. {
  64. JSDC_bClear = 0;
  65. ClrcToTal(JSDC_TOTAL_ADDR);
  66. JSDC_bSaveWorkData = 1;
  67. }
  68. //当长度改变时,生产总量自动清零
  69. if(JSDC_bChangeLength)
  70. {
  71. JSDC_bChangeLength = 0;
  72. JSDC_SaveLength = 0;
  73. JSDC_bClear = 1;
  74. }
  75. //加10
  76. if(JSDC_bAddLength)
  77. {
  78. JSDC_bAddLength = 0;
  79. i = JSDC_SET_ALL_LENGTH;
  80. i += 10;
  81. SetData32bits(20,i);
  82. SetData32bits(22,CalInch(JSDC_SET_ALL_LENGTH));
  83. }
  84. //减10
  85. if(JSDC_bDecLength)
  86. {
  87. JSDC_bDecLength = 0;
  88. i = JSDC_SET_ALL_LENGTH;
  89. i -= 10;
  90. SetData32bits(20,i);
  91. SetData32bits(22,CalInch(JSDC_SET_ALL_LENGTH));
  92. }
  93. //工作方式选择(数控定寸和勾针定寸) 
  94. if(JSDC_bSetDCMode)
  95. {
  96. JSDC_bSetDCMode = 0;
  97. JSDC_SaveLength = 0;
  98. if(JSDC_DC_MODE != 0)
  99. {
  100. JSDC_GouZhen_VAVLE = 1;
  101. JSDC_cGouZhenTime = 300;
  102. }
  103. if(JSDC_DC_MODE == JSDC_DC_SF_MODE)
  104. {
  105. MV_Set_Command_Pos_CPU(X_AXIS,0);
  106. }
  107. }
  108. if(JSDC_bSetLength)
  109. {
  110. JSDC_bSetLength = 0;
  111. SetData32bits(18,CalInch(JSDC_SET_ZIPPER_LENGTH));
  112. JSDC_PARAM_KONG_WEI_LENGTH_INCH = CalInch(JSDC_PARAM_KONG_WEI_LENGTH);
  113. SetData32bits(20,JSDC_SET_ZIPPER_LENGTH+JSDC_PARAM_KONG_WEI_LENGTH);
  114. SetData32bits(22,CalInch(JSDC_SET_ZIPPER_LENGTH+JSDC_PARAM_KONG_WEI_LENGTH));
  115. JSDC_SaveLength = 0;
  116. }
  117. if((JSDC_bRunning) == 0) ////手动
  118. {
  119. if(JSDC_bXiaChong || JSDC_Man_XiaChong_IN_UP)
  120. {
  121. JSDC_bXiaChong = 0;
  122. JSDC_SaveLength = 0;
  123. if(JSDC_cXiaChongStep == 0)JSDC_cXiaChongStep = 1;
  124. }
  125. if(JSDC_bLeftFenZhen)
  126. {
  127. JSDC_bLeftFenZhen = 0;
  128. if(JSDC_cXiaChongStep == 0) JSDC_LeftFenZhen_VAVLE = ~JSDC_LeftFenZhen_VAVLE;
  129. }
  130. if(JSDC_bChuiQi)
  131. {
  132. JSDC_bChuiQi = 0;
  133. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  134. }
  135. if(JSDC_bYD)
  136. {
  137. JSDC_bYD = 0;
  138. JSDC_YD_VAVLE = ~JSDC_YD_VAVLE;
  139. }
  140. if(JSDC_bRightFenZhen)
  141. {
  142. JSDC_bRightFenZhen = 0;
  143. if(JSDC_cXiaChongStep == 0) JSDC_RightFenZhen_VAVLE = ~JSDC_RightFenZhen_VAVLE;
  144. }
  145. if(JSDC_bLeftSongDai)
  146. {
  147. JSDC_bLeftSongDai = 0;
  148. JSDC_Left_SD = ~JSDC_Left_SD;
  149. }
  150. //点动下冲
  151. if((JSDC_bDotXiaChong))
  152. {
  153. JSDC_bDotXiaChong = 0;
  154. if(JSDC_cXiaChongStep == 0)JSDC_cXiaChongStep = 20;
  155. }
  156. if(JSDC_bGouZhen)
  157. {
  158. JSDC_bGouZhen = 0;
  159. JSDC_cGouZhenTime = dwTickCount + 300;
  160. JSDC_GouZhen_VAVLE = ~JSDC_GouZhen_VAVLE;
  161. }
  162. if(JSDC_DC_MODE != JSDC_DC_GZ_MODE)
  163. {
  164. JSDC_GouZhen_VAVLE = 1;
  165. }
  166. else
  167. {
  168. if(dwTickCount >= JSDC_cGouZhenTime) JSDC_GouZhen_VAVLE = 0;
  169. }
  170. if(JSDC_bTestMotor)
  171. {
  172. if(!X_DRV && JSDC_CheckPos())
  173. {
  174. MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P, 10,1,5,5);
  175. if(JSDC_cSDStep == 0)JSDC_cSDStep = 1;
  176. }
  177. }
  178. else
  179. {
  180. if(X_DRV)
  181. {
  182. AxisDecStop(X_AXIS);
  183. JSDC_cSDStep = 0;
  184. }
  185. }
  186. }
  187. }
  188. void JSDC_AutoAction(void)
  189. {
  190. if(JSDC_bRunning)
  191. {
  192. switch(JSDC_cAutoStep)
  193. {
  194. case 0:
  195. break;
  196. case 1:
  197. if(dwTickCount >= JSDC_cAutoDelay)
  198. {
  199. JSDC_cAutoStep = 2;
  200. }
  201. break;
  202. case 2:
  203. //左右分针要退到位,过链到位要离开
  204. if(dwTickCount >= JSDC_cAutoDelay)
  205. {
  206. JSDC_cAutoStep = 3;
  207. switch(JSDC_DC_MODE)
  208. {
  209. case JSDC_DC_SF_MODE:JSDC_cMotorStep = 20; break; //伺服
  210. case JSDC_DC_BMQ_MODE:JSDC_cMotorStep = 60; break; //编码器
  211. default:JSDC_cMotorStep = 1; //启动拖带 ;//勾针
  212. }
  213. }
  214. break;
  215. case 3:
  216. //拖带已经完成
  217. if(JSDC_cMotorStep == 0)
  218. {
  219. {
  220. JSDC_cAutoStep = 4;
  221. }
  222. }
  223. break;
  224. case 4:
  225. JSDC_cAutoStep = 5;
  226. break;
  227. case 5:
  228. if(JSDC_cXiaChongStep == 0)
  229. {
  230. JSDC_cXiaChongStep = 1; //下冲电机启动
  231. JSDC_cAutoStep = 6;
  232. }
  233. break;
  234. case 6: //下冲已完成
  235. if(JSDC_cXiaChongStep == 0)
  236. {
  237. if(JSDC_DC_MODE == JSDC_DC_BMQ_MODE)
  238. {
  239. JSDC_SaveLength += JSDC_PARAM_DAOKOU_LENGTH;
  240. if(JSDC_SaveLength >= JSDC_PARAM_KONG_WEI_LENGTH)
  241. {
  242. dwZipCnt++;
  243. JSDC_SaveLength = 0;
  244. SetEncodePos(0);
  245. AddToTal(JSDC_TOTAL_ADDR); //计数增加和保存
  246. CalProSP(JSDC_PROSPEED_ADDR);
  247. JSDC_cAutoStep = 7;
  248. }
  249. else
  250. {
  251. if((JSDC_PARAM_KONG_WEI_LENGTH - JSDC_SaveLength) >= JSDC_PARAM_DAOKOU_LENGTH)
  252. {
  253. JSDC_cAutoStep = 2;
  254. }
  255. else
  256. {
  257. JSDC_SaveLength = JSDC_PARAM_KONG_WEI_LENGTH - JSDC_PARAM_DAOKOU_LENGTH;
  258. JSDC_cAutoStep = 2;
  259. }
  260. }
  261. }
  262. else
  263. {
  264. dwZipCnt++;
  265. JSDC_SaveLength = 0;
  266. AddToTal(JSDC_TOTAL_ADDR); //计数增加和保存
  267. CalProSP(JSDC_PROSPEED_ADDR);
  268. JSDC_cAutoStep = 7;
  269. }
  270. }
  271. break;
  272. case 7:
  273. if(!JSDC_GouZhen_IN)
  274. {
  275. if(GetTotal(JSDC_TOTAL_ADDR) >= JSDC_SET_TOTAL)JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
  276. JSDC_cAutoStep = 8;
  277. }
  278. break;
  279. case 8:
  280. JSDC_cAutoDelay = dwTickCount + JSDC_PARAM_MOTOR_DELAY;
  281. JSDC_cAutoStep = 1;
  282. if(JSDC_SingOneFlag)
  283. {
  284. dwZipCnt = 0;
  285. JSDC_SingOneFlag = 0;
  286. JSDC_cAutoStep = 0;
  287. JSDC_bRunning = 0;
  288. }
  289. break;
  290. }
  291. }
  292. }
  293. void JSDC_SD(void)
  294. {
  295. }
  296. // 检测是否踏了脚踏开关
  297. void JSDC_CheckStart(void)
  298. {
  299. // 停止键 不能在工作,手动,停止过程中
  300. if((JSDC_bRunning == 0) && (START_IN_UP || JSDC_bStart || JSDC_bNext))
  301. {
  302. if(GetTotal(JSDC_TOTAL_ADDR) >= JSDC_SET_TOTAL)JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
  303. else if((JSDC_PARAM_SEBIAO_DW_LENGTH > JSDC_SET_ZIPPER_LENGTH) && (JSDC_DC_MODE==2))JSDC_SetAlarmCode(JSDC_SEBIAO_ZIPPER_LENGTH_ALARM);
  304. else if(JSDC_KaDai_IN)JSDC_SetAlarmCode(JSDC_KA_DAI_ALARM);
  305. else
  306. {
  307. if(JSDC_bNext)
  308. {
  309. JSDC_SingOneFlag = 1;
  310. JSDC_bNext = 0;
  311. }
  312. JSDC_bRunning = 1;
  313. JSDC_cAutoStep = 1;
  314. if(JSDC_cSDStep == 0)JSDC_cSDStep = 1;
  315. JSDC_cGouZhenTime = 1;
  316. JSDC_cCheckLengthOk = 0;
  317. JSDC_cZipperLength[0] = 0;
  318. JSDC_cZipperLength[1] = 0;
  319. dwZipCnt = 0;
  320. JSDC_cAutoDelay = dwTickCount;
  321. JSDC_cMotorDelay = dwTickCount;
  322. JSDC_cXiaChongDelay = dwTickCount;
  323. if(GetAlarmCode(JSDC_ALARM_ADDR) != 0)SetAlarmCode(JSDC_ALARM_ADDR,0);
  324. }
  325. JSDC_bStart = 0;
  326. }
  327. //卡带感应
  328. if(JSDC_KaDai_IN)
  329. JSDC_SetAlarmCode(JSDC_KA_DAI_ALARM);
  330. else
  331. {
  332. if(GetAlarmCode(JSDC_ALARM_ADDR) == JSDC_KA_DAI_ALARM)SetAlarmCode(JSDC_ALARM_ADDR,0);
  333. }
  334. if(JSDC_KaDai_IN_UP)
  335. {
  336. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  337. }
  338. //停止
  339. JSDC_STOP_IN_FLAG_OLD = JSDC_STOP_IN_FLAG;
  340. if(STOP_IN)
  341. {
  342. if(JSDC_STOP_FILTER < 50)
  343. {
  344. JSDC_STOP_FILTER++;
  345. }
  346. else
  347. JSDC_STOP_IN_FLAG = 1;
  348. }
  349. else if(JSDC_STOP_FILTER > 25)
  350. {
  351. JSDC_STOP_FILTER--;
  352. }
  353. else
  354. JSDC_STOP_IN_FLAG = 0;
  355. if(JSDC_bStop)
  356. {
  357. JSDC_bStop = 0;
  358. if(JSDC_bRunning)JSDC_SingOneFlag = 1;
  359. }
  360. if(((JSDC_STOP_IN_FLAG && !JSDC_STOP_IN_FLAG_OLD)))
  361. {
  362. JSDC_bStop = 0;
  363. if(JSDC_bRunning)
  364. {
  365. if(JSDC_cXiaChongStep==0)
  366. {
  367. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  368. // if(!JSDC_XiaChong_MOTOR)JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
  369. }
  370. JSDC_bRunning = 0;
  371. JSDC_cAutoStep = 0;
  372. JSDC_cMotorStep = 0;
  373. JSDC_cSDStep = 0;
  374. JSDC_cSDStep = 0;
  375. JSDC_SD_MOTOR = 0;
  376. AxisDecStop(X_AXIS);
  377. JSDC_cJiaoDaoStep = 0;
  378. JSDC_SingOneFlag = 0;
  379. }
  380. else
  381. {
  382. JSDC_bRunning = 0;
  383. JSDC_cAutoStep = 0;
  384. JSDC_cMotorStep = 0;
  385. JSDC_cXiaChongStep = 0;
  386. JSDC_cLeftFenZhenStep = 0;
  387. JSDC_cRightFenZhenStep = 0;
  388. JSDC_cJiaoDaoStep = 0;
  389. JSDC_cSDStep = 0;
  390. JSDC_SD_MOTOR = 0;
  391. JSDC_LeftFenZhen_VAVLE = 0;
  392. JSDC_RightFenZhen_VAVLE = 0;
  393. JSDC_XiaChong_MOTOR = 0;
  394. JSDC_YD_VAVLE = 0;
  395. JSDC_Left_SD = 0;
  396. JSDC_SingOneFlag = 0;
  397. if((JSDC_cChuiQiStep == 0) &&(JSDC_cXiaChongStep==0))JSDC_cChuiQiStep = 1;
  398. AxisDecStop(X_AXIS);
  399. SetAlarmCode(JSDC_ALARM_ADDR,JSDC_NO_ALARM);
  400. }
  401. }
  402. if(JSDC_bAlarmStop)
  403. {
  404. JSDC_bAlarmStop = 0;
  405. JSDC_bRunning = 0;
  406. JSDC_cAutoStep = 0;
  407. JSDC_cMotorStep = 0;
  408. JSDC_cXiaChongStep = 0;
  409. JSDC_cLeftFenZhenStep = 0;
  410. JSDC_cRightFenZhenStep = 0;
  411. JSDC_LeftFenZhen_VAVLE = 0;
  412. JSDC_RightFenZhen_VAVLE = 0;
  413. JSDC_SingOneFlag = 0;
  414. JSDC_cSDStep = 0;
  415. JSDC_SD_MOTOR = 0;
  416. AxisDecStop(X_AXIS);
  417. }
  418. }
  419. void JSDC_ChuiQi(void)
  420. {
  421. //吹气
  422. if(JSDC_XiaChong_IN_UP)
  423. {
  424. if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
  425. }
  426. switch(JSDC_cChuiQiStep)
  427. {
  428. case 1:
  429. JSDC_cChuiQiStep = 2;
  430. if(JSDC_bRunning)JSDC_cChuiQiDelay = dwTickCount+JSDC_PARAM_DELAY_CHUIQI_TIME;
  431. break;
  432. case 2:
  433. if(dwTickCount >= JSDC_cChuiQiDelay)
  434. {
  435. JSDC_cChuiQiDelay = dwTickCount + JSDC_PARAM_CHUIQI_TIME;
  436. JSDC_ChuiQi_VAVLE = 1;//
  437. JSDC_cChuiQiStep = 3;
  438. }
  439. break;
  440. case 3:
  441. if(dwTickCount >= JSDC_cChuiQiDelay)
  442. {
  443. JSDC_ChuiQi_VAVLE = 0;//
  444. JSDC_cChuiQiStep = 0;
  445. }
  446. break;
  447. }
  448. }
  449. unsigned char JSDC_ComPareLength(void)
  450. {
  451. if((JSDC_cZipperLength[0] != 0) && (JSDC_cZipperLength[1] != 0))
  452. {
  453. if(JSDC_cZipperLength[0] > JSDC_cZipperLength[1])
  454. {
  455. if((JSDC_cZipperLength[0] - JSDC_cZipperLength[1]) > 200)
  456. {
  457. return 0;
  458. }
  459. else
  460. return 1;
  461. }
  462. else
  463. {
  464. if((JSDC_cZipperLength[1] - JSDC_cZipperLength[0]) > 200)
  465. {
  466. return 0;
  467. }
  468. else
  469. return 1;
  470. }
  471. }
  472. else
  473. return 0;
  474. }
  475. unsigned char JSDC_CheckPos(void)
  476. {
  477. unsigned long zipper_length;
  478. short *revise_buff;
  479. if(JSDC_DC_MODE == JSDC_DC_GZ_MODE)
  480. {
  481. if(JSDC_GouZhen_IN)
  482. return 0;
  483. else
  484. return 1;
  485. }
  486. else
  487. {
  488. revise_buff = &user_datas[17];
  489. zipper_length = JSDC_SET_ZIPPER_LENGTH + (*revise_buff) + JSDC_PARAM_DAOKOU_LENGTH;
  490. if(JSDC_dwEncPos >= zipper_length)return 0;
  491. else
  492. return 1;
  493. }
  494. }
  495. void JSDC_Motor(void)
  496. {
  497. static long save_buff,gou_zhen_buff,zipper_length_buff;
  498. static unsigned long zipper_length;
  499. short *revise_buff;
  500. DISPLAY_DATA0 = JSDC_cAutoStep;
  501. DISPLAY_DATA1 = JSDC_cMotorStep;
  502. DISPLAY_DATA2 = JSDC_cLeftFenZhenStep;
  503. DISPLAY_DATA3 = JSDC_cRightFenZhenStep;
  504. DISPLAY_DATA4 = JSDC_cXiaChongStep;
  505. DISPLAY_DATA5 = dwRealPos;
  506. DISPLAY_DATA6 = JSDC_dwEncPos;
  507. // DISPLAY_DATA7 = user_datas[100];
  508. dwRealPos = GetPos(X_AXIS);
  509. JSDC_dwEncPos = GetEncodePos();
  510. if(JSDC_DC_MODE == JSDC_DC_BMQ_MODE)
  511. SetData32bits(JSDC_NOW_POS_ADDR,JSDC_dwEncPos);
  512. else
  513. SetData32bits(JSDC_NOW_POS_ADDR,dwRealPos);
  514. if(!JSDC_bRunning)
  515. {
  516. if(JSDC_CheckPos() == 0)AxisEgmStop(X_AXIS);
  517. }
  518. switch(JSDC_cMotorStep)
  519. {
  520. case 0:
  521. break;
  522. case 1:
  523. if(JSDC_SZ_OUT == JSDC_SERVER_DISEN)
  524. {
  525. JSDC_SZ_OUT = JSDC_SERVER_EN;
  526. JSDC_cMotorDelay = dwTickCount + 50; //先锁轴
  527. }
  528. JSDC_cMotorStep = 2;
  529. break;
  530. case 2://勾针模式
  531. if(dwTickCount >= JSDC_cMotorDelay)
  532. {
  533. save_buff = dwRealPos;
  534. if(JSDC_cCheckLengthOk)
  535. {
  536. MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P,JSDC_PARAM_SET_SPEED,1,5,1);
  537. }
  538. else
  539. {
  540. if(JSDC_cCheckLengthOk == 0)
  541. {
  542. JSDC_cZipperLength[0] = JSDC_cZipperLength[1];
  543. JSDC_cZipperLength[1] = dwRealPos - zipper_length_buff;
  544. zipper_length_buff = dwRealPos;
  545. if(JSDC_ComPareLength())
  546. {
  547. JSDC_cCheckLengthOk = 1;
  548. }
  549. }
  550. if(JSDC_cCheckLengthOk)zipper_length = JSDC_cZipperLength[1];
  551. MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P,JSDC_PARAM_FIRST_SPEED,1,5,1);
  552. }
  553. JSDC_cMotorDelay = dwTickCount + JSDC_PARAM_MOTOR_ALARM_TIME;
  554. JSDC_cGouZhenTime = dwTickCount + 300;
  555. JSDC_cMotorStep = 3;
  556. }
  557. break;
  558. case 3:
  559. if(((dwTickCount >= JSDC_cGouZhenTime)&&(JSDC_PARAM_GZ_RESET_MODE==0)) || (JSDC_cCheckLengthOk == 0))JSDC_GouZhen_VAVLE = 0;
  560. if(JSDC_cCheckLengthOk)
  561. {
  562. if(((dwRealPos - save_buff) >= (zipper_length - JSDC_PARAM_GZ_LENGTH))&&JSDC_PARAM_GZ_RESET_MODE)JSDC_GouZhen_VAVLE = 0;
  563. if((dwRealPos - save_buff) >= (zipper_length - JSDC_PARAM_LOWSPEED_LENGTH))
  564. {
  565. AxisChangeSpeed(X_AXIS,JSDC_PARAM_LOW_SPEED);
  566. JSDC_cMotorStep = 4;
  567. }
  568. }
  569. else
  570. {
  571. if(JSDC_GouZhen_IN)
  572. {
  573. JSDC_GouZhen_VAVLE = 0;
  574. JSDC_cMotorStep = 5;
  575. AxisEgmStop(X_AXIS);
  576. }
  577. else
  578. {
  579. if(dwTickCount >= JSDC_cGouZhenTime)JSDC_GouZhen_VAVLE = 0;
  580. JSDC_cMotorStep = 4;
  581. }
  582. }
  583. if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  584. break;
  585. case 4:
  586. if(((dwTickCount >= JSDC_cGouZhenTime)&&(JSDC_PARAM_GZ_RESET_MODE==0)) || (JSDC_cCheckLengthOk == 0))JSDC_GouZhen_VAVLE = 0;
  587. if(((dwRealPos - save_buff) >= (zipper_length - JSDC_PARAM_GZ_LENGTH))&&JSDC_PARAM_GZ_RESET_MODE &&JSDC_cCheckLengthOk)JSDC_GouZhen_VAVLE = 0;
  588. if(JSDC_GouZhen_IN)
  589. {
  590. JSDC_GouZhen_VAVLE = 0;
  591. JSDC_cMotorStep = 5;
  592. AxisEgmStop(X_AXIS);
  593. }
  594. if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  595. break;
  596. case 5:
  597. if(((dwTickCount >= JSDC_cGouZhenTime)&&(JSDC_PARAM_GZ_RESET_MODE==0)) || (JSDC_cCheckLengthOk == 0))JSDC_GouZhen_VAVLE = 0;
  598. if(!X_DRV)
  599. {
  600. JSDC_cMotorStep = 0;
  601. JSDC_cMotorDelay = dwTickCount;
  602. }
  603. else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  604. break;
  605. case 20:
  606. if(JSDC_SZ_OUT == JSDC_SERVER_DISEN)
  607. {
  608. JSDC_SZ_OUT = JSDC_SERVER_EN;
  609. JSDC_cMotorDelay = dwTickCount + 50; //先锁轴
  610. }
  611. JSDC_cMotorStep = 21;
  612. break;
  613. case 21:
  614. if(dwTickCount >= JSDC_cMotorDelay) //电机定寸模式
  615. {
  616. revise_buff = &user_datas[17];
  617. if(JSDC_cAlarmStopFlg)
  618. {
  619. zipper_length = JSDC_SET_ZIPPER_LENGTH + (*revise_buff) + JSDC_PARAM_DAOKOU_LENGTH;
  620. JSDC_cAlarmStopFlg = 0;
  621. }
  622. else
  623. {
  624. zipper_length = JSDC_SET_ZIPPER_LENGTH + (*revise_buff) + JSDC_PARAM_DAOKOU_LENGTH;
  625. if((0 - dwRealPos) > zipper_length)
  626. zipper_length = JSDC_SET_ZIPPER_LENGTH + (*revise_buff) + JSDC_PARAM_DAOKOU_LENGTH;
  627. else
  628. zipper_length = JSDC_SET_ZIPPER_LENGTH + (*revise_buff) + JSDC_PARAM_DAOKOU_LENGTH - (0 - dwRealPos);
  629. }
  630. AxisMovePosAccDec(X_AXIS,JSDC_PARAM_SET_SPEED,zipper_length,1,5,1);
  631. JSDC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀
  632. JSDC_cMotorStep = 22;
  633. JSDC_cMotorDelay = dwTickCount + JSDC_PARAM_MOTOR_ALARM_TIME;
  634. }
  635. break;
  636. case 22:
  637. if(!X_DRV)
  638. {
  639. MV_Set_Command_Pos_CPU(X_AXIS,0);
  640. JSDC_cMotorStep = 0;
  641. JSDC_cMotorDelay = dwTickCount;
  642. }
  643. else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  644. break;
  645. case 60:
  646. if(JSDC_SZ_OUT == JSDC_SERVER_DISEN)
  647. {
  648. JSDC_SZ_OUT = JSDC_SERVER_EN;
  649. JSDC_cMotorDelay = dwTickCount + 50; //先锁轴
  650. }
  651. JSDC_cMotorStep = 61;
  652. break;
  653. case 61:
  654. if(dwTickCount >= JSDC_cMotorDelay)
  655. {
  656. save_buff = JSDC_dwEncPos;
  657. zipper_length = JSDC_SET_ALL_LENGTH - JSDC_PARAM_KONG_WEI_LENGTH + JSDC_PARAM_DAOKOU_LENGTH + JSDC_SaveLength;
  658. MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P,JSDC_PARAM_SET_SPEED,JSDC_PARAM_START_SPEED,JSDC_PARAM_ACC,JSDC_PARAM_DEC);
  659. JSDC_cMotorDelay = dwTickCount + JSDC_PARAM_MOTOR_ALARM_TIME;
  660. JSDC_cMotorStep = 62;
  661. }
  662. break;
  663. case 62:
  664. if((JSDC_dwEncPos) >= (zipper_length - JSDC_PARAM_LOWSPEED_LENGTH))
  665. {
  666. AxisChangeSpeed(X_AXIS,JSDC_PARAM_LOW_SPEED);
  667. JSDC_cMotorStep = 63;
  668. }
  669. else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  670. break;
  671. case 63:
  672. if((JSDC_dwEncPos) >= zipper_length)
  673. {
  674. JSDC_cMotorStep = 64;
  675. AxisEgmStop(X_AXIS);
  676. }
  677. else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  678. break;
  679. case 64:
  680. if(!X_DRV)
  681. {
  682. JSDC_cMotorStep = 0;
  683. JSDC_cMotorDelay = dwTickCount;
  684. }
  685. else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
  686. break;
  687. }
  688. }
  689. //下冲
  690. void JSDC_XiaChong(void)
  691. {
  692. switch(JSDC_cXiaChongStep)
  693. {
  694. case 0:
  695. return;
  696. break;
  697. case 1:
  698. JSDC_XC_ShaChe = JSDC_SC_DISEN;
  699. JSDC_cRightFenZhenStep = 1;
  700. JSDC_cXiaChongStep = 2;
  701. break;
  702. case 2:
  703. if((JSDC_cLeftFenZhenStep==0) && (JSDC_cRightFenZhenStep == 0))
  704. {
  705. JSDC_cXiaChongStep = 3;
  706. if(JSDC_bRunning)JSDC_cXiaChongDelay = dwTickCount + JSDC_PARAM_DELAY_XC;
  707. }
  708. break;
  709. case 3:
  710. if(dwTickCount >= JSDC_cXiaChongDelay)
  711. {
  712. JSDC_cXiaChongStep = 4;
  713. JSDC_XiaChong_MOTOR = 1; //下冲电机
  714. if(!JSDC_bRunning)SetEncodePos(0);
  715. JSDC_cXiaChongDelay = dwTickCount + (unsigned long)JSDC_ERRORTIME; //下冲最长时间
  716. if(JSDC_XiaChongMotorMode == 1)
  717. {
  718. AxisMoveTwoPos(Y_AXIS,JSDC_XiaChongSpeed,2000,JSDC_XiaChongLowSpeed,9999999,0);
  719. }
  720. }
  721. break;
  722. case 4: //碰到右大微动,延时停
  723. if(JSDC_XiaChong_IN_UP)
  724. {
  725. JSDC_cXiaChongDelay = dwTickCount + JSDC_PARAM_XC_DELAY;
  726. JSDC_cSDDelay = dwTickCount + JSDC_DELAY_LSD_BACK;
  727. JSDC_cXiaChongStep = 5;
  728. JSDC_LeftFenZhen_VAVLE = 0; //退左分针
  729. JSDC_RightFenZhen_VAVLE = 0;
  730. JSDC_YD_VAVLE = 0;
  731. if(JSDC_bRunning)
  732. {
  733. JSDC_GouZhen_VAVLE = 1;
  734. JSDC_cGouZhenTime = dwTickCount + 300;
  735. }
  736. }
  737. else if(dwTickCount >= JSDC_cXiaChongDelay) //自动停机
  738. {
  739. JSDC_cXiaChongStep = 0;
  740. JSDC_XiaChong_MOTOR = 0;// //下冲电机
  741. JSDC_SetAlarmCode(JSDC_XC_ALARM);
  742. }
  743. break;
  744. case 5:
  745. if(dwTickCount >= JSDC_cSDDelay)JSDC_Left_SD = 0;
  746. if(dwTickCount >= JSDC_cXiaChongDelay)
  747. {
  748. AxisEgmStop(Y_AXIS);
  749. JSDC_XiaChong_MOTOR = 0; //延时刹车
  750. if(JSDC_PARAM_SC_MODE)
  751. {
  752. JSDC_cXiaChongStep = 0;
  753. }
  754. else
  755. {
  756. JSDC_cXiaChongStep = 6;
  757. }
  758. }
  759. break;
  760. case 6:
  761. {
  762. if(dwTickCount >= JSDC_cSDDelay)JSDC_Left_SD = 0;
  763. JSDC_cXiaChongStep = 7;
  764. JSDC_cXiaChongDelay = dwTickCount + JSDC_PARAM_SC_DELAY;
  765. }
  766. break;
  767. case 7:
  768. if(dwTickCount >= JSDC_cSDDelay)JSDC_Left_SD = 0;
  769. if((dwTickCount >= JSDC_cXiaChongDelay))
  770. {
  771. JSDC_cXiaChongStep = 8;
  772. JSDC_cXiaChongDelay = dwTickCount+ 150;
  773. // JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
  774. JSDC_XC_ShaChe = JSDC_SC_EN;
  775. }
  776. break;
  777. case 8:
  778. if((dwTickCount >= JSDC_cXiaChongDelay) && (dwTickCount >= JSDC_cSDDelay))
  779. {
  780. JSDC_Left_SD = 0;
  781. JSDC_cXiaChongStep = 0;
  782. if(!JSDC_bRunning)MV_Set_Command_Pos_CPU(X_AXIS,0);
  783. // JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
  784. JSDC_XC_ShaChe = JSDC_SC_DISEN;
  785. }
  786. break;
  787. case 20: // 点动普通下冲动作
  788. // JSDC_XC_SongZhou = JSDC_SERVER_EN;
  789. JSDC_XC_ShaChe = JSDC_SC_DISEN;
  790. JSDC_cXiaChongDelay = dwTickCount + 50;
  791. JSDC_cXiaChongStep = 21;
  792. break;
  793. case 21:
  794. if((dwTickCount >= JSDC_cXiaChongDelay))
  795. {
  796. JSDC_XiaChong_MOTOR = 1;
  797. JSDC_cXiaChongDelay = dwTickCount + 50;
  798. JSDC_cXiaChongStep = 22;
  799. }
  800. break;
  801. case 22:
  802. if((dwTickCount >= JSDC_cXiaChongDelay))
  803. {
  804. JSDC_XiaChong_MOTOR = 0;
  805. // JSDC_XC_SongZhou = JSDC_SERVER_EN;
  806. if(JSDC_XiaChongMotorMode)
  807. JSDC_cXiaChongStep = 0;
  808. else
  809. {
  810. JSDC_XC_ShaChe = JSDC_SC_EN;
  811. JSDC_cXiaChongDelay = dwTickCount + 150;
  812. JSDC_cXiaChongStep = 23;
  813. }
  814. }
  815. break;
  816. case 23:
  817. if((dwTickCount >= JSDC_cXiaChongDelay))
  818. {
  819. //JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
  820. JSDC_XC_ShaChe = JSDC_SC_DISEN;
  821. JSDC_cXiaChongStep = 0;
  822. }
  823. break;
  824. case 40: // 点动电机下冲动作
  825. //JSDC_XC_SongZhou = JSDC_SERVER_EN;
  826. JSDC_cXiaChongDelay = dwTickCount + 50;
  827. JSDC_cXiaChongStep = 41;
  828. break;
  829. case 41:
  830. if(!Y_DRV)AxisMovePos(Y_AXIS,20,10);
  831. JSDC_cXiaChongStep = 42;
  832. break;
  833. case 42:
  834. if(!Y_DRV)
  835. {
  836. JSDC_cXiaChongStep = 0;
  837. }
  838. break;
  839. }
  840. }
  841. //分针
  842. void JSDC_FenZhen(void)
  843. {
  844. if(JSDC_FZ_SELECT)
  845. {
  846. }
  847. else
  848. {
  849. JSDC_cRightFenZhenStep = 0;
  850. JSDC_cLeftFenZhenStep = 0;
  851. }
  852. //右分针
  853. switch(JSDC_cRightFenZhenStep)
  854. {
  855. case 0:
  856. break;
  857. case 1:
  858. JSDC_cFenZhenRightDelay = JSDC_PARAM_R_FZ_DELAY+dwTickCount;
  859. JSDC_cRightFenZhenStep = 2;
  860. break;
  861. case 2:
  862. if(dwTickCount >= JSDC_cFenZhenRightDelay)
  863. {
  864. JSDC_cRightFenZhenStep = 3;
  865. JSDC_RightFenZhen_VAVLE = 1;//右分针电磁阀
  866. JSDC_cFenZhenRightDelay = dwTickCount + JSDC_FenZhengErrorTime;
  867. }
  868. break;
  869. case 3: //碰到右大微动,延时停
  870. JSDC_cFenZhenRightDelay = dwTickCount + JSDC_FenZhengErrorTime;
  871. JSDC_cRightFenZhenStep = 4;
  872. break;
  873. case 4:
  874. if(JSDC_RightFenZhen_IN) //插针到位
  875. {
  876. JSDC_cRightFenZhenStep = 0;
  877. JSDC_YD_VAVLE = 1;
  878. JSDC_cLeftFenZhenStep = 1; //左分针延时启动
  879. }
  880. else if(dwTickCount >= JSDC_cFenZhenRightDelay)
  881. {
  882. JSDC_SetAlarmCode(JSDC_RFZ_LIMIT_ALARM);
  883. }
  884. break;
  885. }
  886. //左分针
  887. switch(JSDC_cLeftFenZhenStep)
  888. {
  889. case 0:
  890. break;
  891. case 1:
  892. JSDC_cFenZhenLeftDelay = JSDC_PARAM_L_FZ_DELAY+dwTickCount;
  893. JSDC_cLeftFenZhenStep = 2;
  894. break;
  895. case 2:
  896. if(dwTickCount >= JSDC_cFenZhenLeftDelay)
  897. {
  898. JSDC_cLeftFenZhenStep = 3;
  899. JSDC_LeftFenZhen_VAVLE = 1; //左分针电磁阀
  900. JSDC_cFenZhenLeftDelay = dwTickCount + JSDC_FenZhengErrorTime;
  901. }
  902. break;
  903. case 3: //离开左分针原点
  904. {
  905. JSDC_cFenZhenLeftDelay = dwTickCount + JSDC_FenZhengErrorTime;
  906. JSDC_cLeftFenZhenStep = 4;
  907. }
  908. break;
  909. case 4:
  910. if(JSDC_LeftFenZhen_IN) //插针到位
  911. {
  912. JSDC_cLeftFenZhenStep = 0;
  913. JSDC_Left_SD = 1;
  914. }
  915. else if(dwTickCount >= JSDC_cFenZhenLeftDelay)
  916. {
  917. JSDC_SetAlarmCode(JSDC_LFZ_LIMIT_ALARM);
  918. }
  919. break;
  920. }
  921. }
  922. #endif