JXTieBuJi.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  1. #include "global.h"
  2. #if JU_XING_MACHINE == 1
  3. void TBJ_InitAction(void);
  4. void TBJ_Action(void);
  5. void TBJ_ChuiQi(void);
  6. void TBJ_ChaoShengHeMo(void);
  7. void TBJ_SetAlarmCode(unsigned alarm_code); //等待调用
  8. void TBJ_StartStopAction(void);
  9. void TBJ_AutoRunStep(void);
  10. void TBJ_Motor(void);
  11. void TBJ_SongJiao(void);
  12. void TBJ_STOP_Action(void);
  13. void TBJ_ChuiQi_Stop(void);
  14. void TBJ_Action(void)
  15. {
  16. //步骤显示
  17. DISPLAY_DATA0 = TBJ_Auto_Step;
  18. DISPLAY_DATA1 = TBJ_Motor_Step;
  19. DISPLAY_DATA2 = TBJ_HMCS_Step;
  20. DISPLAY_DATA3 = TBJ_SJ_FJ_Step;
  21. DISPLAY_DATA4 = TBJ_SAVE_POS;
  22. DISPLAY_DATA5 = GetPos(X_AXIS);
  23. // InputPinConfig();
  24. TBJ_ManualAction();
  25. TBJ_ChaoShengHeMo();
  26. TBJ_StartStopAction();
  27. TBJ_AutoRunStep();
  28. TBJ_Motor();
  29. TBJ_SongJiao();
  30. // OutputPinConfig();
  31. TBJ_STOP_Action();
  32. TBJ_ChuiQi_Stop();
  33. }
  34. //故障报警
  35. void TBJ_SetAlarmCode(unsigned alarm_code)
  36. {
  37. SetAlarmCode(TBJ_ALARM_ADDR, alarm_code);
  38. TBJ_bAlarmStop = 1;
  39. }
  40. void TBJ_InitAction(void)
  41. {
  42. float buff_pulse, buff_dist;
  43. //电机松轴
  44. SetEn(X_AXIS, TBJ_MOTOR_DISEN);
  45. //电机脉冲与距离比例计算
  46. buff_pulse = TBJ_PARAM_CYCLE_PULSE; //电机走一圈所需的脉冲
  47. buff_dist = TBJ_PARAM_CYCLE_LENGTH; //电机走一圈长度
  48. XGearRatio = buff_pulse / buff_dist; //可根据距离换算所需脉冲,反之一样
  49. TBJ_CHENGXU_UPDATE = 1; //便于屏幕判断程序有无更新
  50. SetDirReverse(X_AXIS, 0);
  51. SetAlarmCode(TBJ_ALARM_ADDR, TBJ_NO_ALARM); //警告要清除
  52. }
  53. //吹气
  54. void TBJ_ChuiQi(void)
  55. {
  56. if (!TBJ_CQ_VAVLE)
  57. {
  58. TBJ_CQ_VAVLE = 1;
  59. TBJ_CQ_Delay = dwTickCount + TBJ_PARAM_ChuiQi_TIME;
  60. }
  61. }
  62. //停止吹气
  63. void TBJ_ChuiQi_Stop(void)
  64. {
  65. if (TBJ_CQ_VAVLE && dwTickCount >= TBJ_CQ_Delay && dwTickCount >= TBJ_CS_Delay)
  66. TBJ_CQ_VAVLE = 0;
  67. }
  68. //红外算出来的时间重新赋值
  69. void TBJ_ResetCsTime(void)
  70. {
  71. if (TBJ_PARAM_CS_MODE == 0)
  72. user_datas[33] = user_datas[57];
  73. else
  74. user_datas[6] = user_datas[57];
  75. }
  76. //超声时间选择
  77. unsigned short TBJ_Choose_CSTime(void)
  78. {
  79. if (TBJ_PARAM_CS_MODE == 0) //超声模式 0为透明胶 1为布胶
  80. return TBJ_PARAM_TMJ_CS_TIME; //透明胶超声时间
  81. else
  82. return TBJ_PARAM_BJ_CS_TIME; //布胶超声时间
  83. }
  84. //固化时间选择
  85. unsigned short TBJ_Choose_COLDTime(void)
  86. {
  87. if (TBJ_PARAM_CS_MODE == 0)
  88. return TBJ_PARAM_TMJ_GH_TIME; //透明胶固化时间
  89. else
  90. return TBJ_PARAM_BJ_GH_TIME; //布胶固化时间
  91. }
  92. //手动动作
  93. void TBJ_ManualAction(void)
  94. {
  95. if (!TBJ_bRunning)
  96. {
  97. //手动钩针输出
  98. if (TBJ_HAND_GOUZHEN) //X02手动钩针触发
  99. {
  100. //X02上升沿 送胶到位感应 单钩针模式 滚轮模式
  101. if (TBJ_HAND_GOUZHEN_UP && (!TBJ_SJ_LIMIT_IN || TBJ_PARAM_SGZSelect || TBJ_PARAM_SongJiaoMode))
  102. TBJ_GZ_VAVLE = 1; //钩针输出
  103. else if (TBJ_PARAM_SGZSelect == 0) //双钩针模式
  104. {
  105. if (TBJ_GZ_VAVLE && TBJ_TD_LIMIT_IN && !TBJ_XM_VAVLE) //钩针已输出 拖带到位感应亮 下模无输出
  106. {
  107. TBJ_XM_VAVLE = 1; //下模输出
  108. TBJ_GZ_Delay = dwTickCount + TBJ_PARAM_JJ_TIME; //下模输出时间
  109. }
  110. if (TBJ_XM_VAVLE && (dwTickCount > TBJ_GZ_Delay))
  111. {
  112. TBJ_GZ_VAVLE = 0;
  113. }
  114. }
  115. }
  116. //屏幕按钮手动钩针
  117. if (TBJ_bGZ)
  118. {
  119. TBJ_bGZ = 0;
  120. if (TBJ_GZ_VAVLE)
  121. TBJ_GZ_VAVLE = 0;
  122. else
  123. TBJ_GZ_VAVLE = 1;
  124. }
  125. //手动分胶
  126. if ((TBJ_HAND_FENJIAO_UP || TBJ_bFJ) &&
  127. (((!TBJ_GZ_ORIGIN_IN) && (TBJ_PARAM_SGZSelect == 1)) //单钩针模式下的判断
  128. || ((TBJ_PARAM_SGZSelect == 0) && TBJ_GZ_ORIGIN_IN && !TBJ_TD_LIMIT_IN)) //双钩针模式下的判断
  129. && !TBJ_SM_VAVLE && !TBJ_SM_LIMIT_IN && !TBJ_HAND_CHAOSHENG //下模判断 超声未打开
  130. && (TBJ_FJ_VAVLE || (!TBJ_SJ_VAVLE && !TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN)) //未进分胶,送胶不能输出,进完分胶后,无视送胶状态,可退分胶
  131. )
  132. {
  133. TBJ_bFJ = 0;
  134. if (TBJ_FJ_VAVLE && !TBJ_HAND_FENJIAO)
  135. TBJ_FJ_VAVLE = 0;
  136. else
  137. TBJ_FJ_VAVLE = 1;
  138. }
  139. else if (TBJ_HAND_FENJIAO_DW)
  140. TBJ_FJ_VAVLE = 0;
  141. else if (TBJ_bFJ)
  142. {
  143. TBJ_bFJ = 0;
  144. if (!(((!TBJ_GZ_ORIGIN_IN) && (TBJ_PARAM_SGZSelect == 1)) || ((TBJ_PARAM_SGZSelect == 0) && TBJ_GZ_ORIGIN_IN && !TBJ_TD_LIMIT_IN)))
  145. TBJ_SetAlarmCode(34); //E34 手动分胶停止,原因可能如下①夹胶非单独气缸,压胶阀未关闭;②单钩针模式下,钩针退位了;③双钩针模式下,钩针未退位;
  146. else if (TBJ_SM_VAVLE)
  147. TBJ_SetAlarmCode(35); //E35 手动分胶停止,下冲气缸未退位
  148. else if (TBJ_SM_LIMIT_IN)
  149. TBJ_SetAlarmCode(36); //E36 手动分胶停止,下冲气缸未退位或X14下冲到位感应异常
  150. else if (TBJ_HAND_CHAOSHENG)
  151. TBJ_SetAlarmCode(37); //E37 手动分胶停止,超声未关闭
  152. else if (TBJ_SJ_LIMIT_IN)
  153. TBJ_SetAlarmCode(38); //E38 手动分胶停止,送胶阀未退回,或X16送胶到位感应异常
  154. else if (!TBJ_SJ_ORIGIN_IN)
  155. TBJ_SetAlarmCode(39); //E39 手动分胶停止,送胶阀未退回,或X17退胶到位感应异常
  156. }
  157. //手动送胶
  158. if ((TBJ_HAND_SONGJIAO_UP || (TBJ_bSJ && !TBJ_SJ_VAVLE))) //按钮按下 送胶阀未输出 进行送胶
  159. { //手动送胶 || (按钮送胶 && 送胶阀没输出)&& (!1二次拖带的情况下考虑钩针阀没有输出)
  160. if ((TBJ_PARAM_SGZSelect || (TBJ_GZ_ORIGIN_IN && !TBJ_TD_LIMIT_IN)) //单钩针模式,钩针与送胶阀错位,不用考虑相撞,双钩针模式下的判断,钩针钩住拖带后退,可能会与送胶阀产生碰撞
  161. && (TBJ_FJ_LIMIT_IN ^ TBJ_FJ_ORIGIN_IN) && TBJ_SJ_ORIGIN_IN //判断分胶阀有无出错,只能到位或原位 送胶阀后感应亮
  162. && !TBJ_SM_VAVLE && !TBJ_SM_LIMIT_IN && !TBJ_HAND_CHAOSHENG //上模判断 超声未打开
  163. && (!TBJ_PARAM_TWOTD_SELECT || !TBJ_GZ_VAVLE)) //二次拖带下需考虑钩针有无退回
  164. {
  165. if (!TBJ_YD_VAVLE) //压胶阀没输出
  166. {
  167. TBJ_YD_VAVLE = 1; //压胶阀输出
  168. TBJ_SJ_Delay = dwTickCount + 70; //延迟70ms输出送胶阀
  169. }
  170. else if (TBJ_YD_VAVLE && (dwTickCount > TBJ_SJ_Delay))
  171. {
  172. TBJ_SJ_VAVLE = 1; //送胶阀输出
  173. TBJ_bSJ = 0;
  174. }
  175. }
  176. else if (TBJ_bSJ) //送胶失败,发送警告
  177. {
  178. TBJ_bSJ = 0;
  179. if (!(TBJ_PARAM_SGZSelect || (TBJ_GZ_ORIGIN_IN && !TBJ_TD_LIMIT_IN)))
  180. TBJ_SetAlarmCode(40); //E40 手动送胶停止,双钩针模式下钩针未退回
  181. else if (!(TBJ_FJ_LIMIT_IN ^ TBJ_FJ_ORIGIN_IN))
  182. TBJ_SetAlarmCode(41); //E41 手动送胶停止,分胶阀处于异常状态,X12,X13前后感应灯同亮或同灭
  183. else if (!TBJ_SJ_VAVLE && !TBJ_SJ_ORIGIN_IN)
  184. TBJ_SetAlarmCode(42); //E42 手动送胶停止,X17送胶后感应异常
  185. else if (TBJ_SM_VAVLE)
  186. TBJ_SetAlarmCode(43); //E43 手动送胶停止,下冲气缸输出中
  187. else if (TBJ_SM_LIMIT_IN)
  188. TBJ_SetAlarmCode(44); //E44 手动送胶停止,下冲气缸未退回,或X14 下冲到位感应异常
  189. else if (TBJ_HAND_CHAOSHENG)
  190. TBJ_SetAlarmCode(45); //E45 手动送胶停止,超声未关闭
  191. if (TBJ_SJ_VAVLE)
  192. TBJ_SJ_VAVLE = 0;
  193. }
  194. }
  195. else if ((TBJ_HAND_SONGJIAO_DW || (TBJ_bSJ && TBJ_SJ_VAVLE))) //送胶阀已输出,进行退胶
  196. {
  197. if (TBJ_YD_VAVLE)
  198. {
  199. TBJ_YD_VAVLE = 0; //压胶阀关闭
  200. TBJ_SJ_Delay = dwTickCount + 120; //延迟120ms退回送胶阀
  201. }
  202. else if (!TBJ_YD_VAVLE && (dwTickCount > TBJ_SJ_Delay))
  203. {
  204. TBJ_SJ_VAVLE = 0;
  205. TBJ_bSJ = 0;
  206. }
  207. }
  208. //手动合模
  209. if ((TBJ_bHM || TBJ_HAND_HEMO_UP) && !TBJ_SM_VAVLE) //屏幕按钮按下 || 上模没输出 && 手动合模输入
  210. {
  211. if ((TBJ_HAND_HEMO_UP || TBJ_bHM) && (TBJ_FJ_ORIGIN_IN || TBJ_PARAM_FenJiaoSelect) && (!TBJ_FJ_LIMIT_IN) //分胶阀感应判断
  212. && (((!TBJ_SJ_LIMIT_IN) && TBJ_SJ_ORIGIN_IN) || (TBJ_PARAM_SongJiaoMode)) //送胶阀感应判断
  213. && (!TBJ_FJ_VAVLE) && (!TBJ_SJ_VAVLE) && (!TBJ_CS_OUT) //分胶阀判断 送胶阀判断 超声判断
  214. && ((TBJ_GZ_ORIGIN_IN && !TBJ_TD_LIMIT_IN) || TBJ_PARAM_SGZSelect)) //双钩针模式需考虑钩针有无输出
  215. {
  216. TBJ_SM_VAVLE = 1;
  217. if (TBJ_PARAM_XiaMo_Mode == 0) //下模活动
  218. {
  219. TBJ_XM_VAVLE = 1;
  220. }
  221. TBJ_Hand_Hemo_flag = 1;
  222. TBJ_bHM = 0;
  223. }
  224. else if (TBJ_bHM)
  225. {
  226. TBJ_bHM = 0;
  227. if (!(TBJ_FJ_ORIGIN_IN))
  228. TBJ_SetAlarmCode(46); //E46 手动合模停止,分胶阀未退位,或 X13分胶后感应异常
  229. else if (TBJ_FJ_LIMIT_IN)
  230. TBJ_SetAlarmCode(47); //E47 手动合模停止,分胶阀未退位,或 X12分胶前感应异常
  231. else if (TBJ_SJ_LIMIT_IN)
  232. TBJ_SetAlarmCode(48); //E48 手动合模停止,送胶阀未退位,或 X16送胶前感应异常
  233. else if (!TBJ_SJ_ORIGIN_IN)
  234. TBJ_SetAlarmCode(49); //E49 手动合模停止,送胶阀未退位,或 X17分胶后感应异常
  235. else if (TBJ_CS_OUT)
  236. TBJ_SetAlarmCode(50); //E50 手动合模停止,超声未关闭
  237. }
  238. }
  239. else if ((TBJ_bHM || TBJ_HAND_HEMO_UP) && TBJ_SM_VAVLE) //屏幕按钮按下 && 上模已输出 && 手动合模没输入
  240. {
  241. TBJ_SM_VAVLE = 0; //上模退回
  242. if (TBJ_PARAM_XiaMo_Mode == 0) //双钩针模式下 或下模活动模式
  243. {
  244. TBJ_XM_VAVLE = 0; //下模退回
  245. }
  246. TBJ_bHM = 0;
  247. }
  248. //合模后吹气一次
  249. if (TBJ_SM_LIMIT_IN && TBJ_Hand_Hemo_flag) //合模到位
  250. {
  251. TBJ_ChuiQi(); //启动吹气
  252. TBJ_Hand_Hemo_flag = 0;
  253. }
  254. //手动超声
  255. if (TBJ_HAND_CHAOSHENG || ((TBJ_bCS || TBJ_bCS_FLAG) && !TBJ_HAND_CHAOSHENG_DW) && (!TBJ_FJ_VAVLE && !TBJ_FJ_LIMIT_IN && TBJ_FJ_ORIGIN_IN || TBJ_PARAM_FenJiaoSelect) //分胶阀判断
  256. && (!TBJ_SJ_VAVLE && !TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN || TBJ_PARAM_SongJiaoMode) //送胶阀判断
  257. && (dwTickCount >= TBJ_CS_Delay) //超声间隔
  258. )
  259. {
  260. if ((TBJ_GZ_ORIGIN_IN && TBJ_TD_LIMIT_IN || TBJ_PARAM_SGZSelect) && !TBJ_SHANGCHAO_IN && !TBJ_bSC_FLAG) //钩针阀判断
  261. {
  262. if (TBJ_PARAM_XiaMo_Mode) //下模不动 超声不烧坏焊头
  263. {
  264. if (TBJ_SM_LIMIT_IN) //已经合模
  265. {
  266. if ((TBJ_HAND_CHAOSHENG_UP || TBJ_bCS) && (TBJ_HMCS_Step == 0))
  267. {
  268. TBJ_HMCS_Step = 3; //直接发超声(按设定时间)
  269. TBJ_bCS_FLAG = 1;
  270. }
  271. }
  272. else //直接超声
  273. {
  274. if ((TBJ_HAND_CHAOSHENG_UP || TBJ_bCS) && !TBJ_bCS_FLAG) //按钮已按下,超声未开始
  275. {
  276. TBJ_bCS_FLAG = 1; //cMidleCoil[0] |= (1<<10); //M10
  277. TBJ_CS_OUT = 1; //发超声
  278. TBJ_CS_Delay = dwTickCount + TBJ_Choose_CSTime(); //限长时间1.5
  279. }
  280. else if (((!TBJ_bCS && !TBJ_HAND_CHAOSHENG) || (dwTickCount >= TBJ_CS_Delay)) && TBJ_CS_OUT) //直至按钮取消或到达超声时间 关闭超声
  281. {
  282. TBJ_bCS = 0;
  283. TBJ_bCS_FLAG = 0; //超声标志位清零
  284. TBJ_CS_OUT = 0; //关闭超声
  285. TBJ_ChuiQi(); //开启吹气
  286. }
  287. }
  288. }
  289. /*下模活动 取消注释*/
  290. // else if(TBJ_PARAM_SGZSelect == 1)//下模活动,勾针为单勾针,超声会烧坏焊头,需要合模才能超声
  291. // {
  292. // if((TBJ_HAND_CHAOSHENG_UP || TBJ_bCS) && !TBJ_XM_VAVLE)//下模未输出
  293. // {
  294. // TBJ_bCS = 1;
  295. // TBJ_XM_VAVLE = 1; // 输出下模,需合模才能超声
  296. // TBJ_CS_Delay = dwTickCount + 100; // 下模上升时间
  297. // }
  298. // if(TBJ_XM_VAVLE && TBJ_SM_LIMIT_IN_UP && !TBJ_bCS_FLAG && (dwTickCount >= TBJ_CS_Delay))//老款下模启动 上模到位
  299. // {
  300. // TBJ_bCS_FLAG = 1;
  301. // TBJ_CS_OUT = 1; //发超声
  302. // TBJ_CS_Delay = dwTickCount + 2000; //限长时间2秒
  303. // }
  304. // if((!TBJ_bCS || (dwTickCount >= TBJ_CS_Delay)) && TBJ_CS_OUT)
  305. // {
  306. // TBJ_bCS = 0;
  307. // TBJ_CS_OUT = 0;
  308. // TBJ_HMCS_Step = 4;
  309. // }
  310. // }
  311. //超声完成
  312. if (!TBJ_bCS && !TBJ_CS_OUT && !TBJ_HAND_CHAOSHENG) //按钮清零 超声关闭 手动超声关闭
  313. {
  314. TBJ_bCS_FLAG = 0; //cMidleCoil[0] &= ~(1<<10); //M10
  315. TBJ_HMCS_Step = 0;
  316. if (TBJ_PARAM_XiaMo_Mode == 0) //下模活动
  317. {
  318. TBJ_XM_VAVLE = 0; //退回下模
  319. }
  320. }
  321. }
  322. else
  323. TBJ_bCS = 0;
  324. }
  325. else if (TBJ_HAND_CHAOSHENG_DW)
  326. {
  327. TBJ_bCS_FLAG = 0; //超声标志清零
  328. TBJ_bCS = 0; //超声按钮清零
  329. TBJ_CS_OUT = 0; //关闭超声
  330. TBJ_HMCS_Step = 0;
  331. TBJ_CS_Delay = dwTickCount + 300;
  332. if (TBJ_PARAM_XiaMo_Mode == 0) //下模活动
  333. {
  334. TBJ_XM_VAVLE = 0;
  335. }
  336. }
  337. else if (TBJ_bCS)
  338. {
  339. TBJ_bCS = 0;
  340. if (TBJ_FJ_VAVLE)
  341. TBJ_SetAlarmCode(51); //E51 手动超声停止,分胶阀未退回
  342. else if (TBJ_SJ_VAVLE)
  343. TBJ_SetAlarmCode(52); //E52 手动超声停止,送胶阀未退回
  344. else if (TBJ_FJ_LIMIT_IN)
  345. TBJ_SetAlarmCode(53); //E53 手动超声停止,分胶阀未退回,或X12分胶前感应异常
  346. else if (!TBJ_FJ_ORIGIN_IN && !TBJ_PARAM_FenJiaoSelect)
  347. TBJ_SetAlarmCode(54); //E54 手动超声停止,分胶阀未退回,或X13分胶后感应异常
  348. else if (TBJ_SJ_LIMIT_IN)
  349. TBJ_SetAlarmCode(55); //E55 手动超声停止,送胶阀未退回,或X16送胶到位感应异常
  350. else if (!TBJ_SJ_ORIGIN_IN)
  351. TBJ_SetAlarmCode(56); //E56 手动超声停止,送胶阀未退回,或X17退胶到位感应异常
  352. }
  353. //手动上超
  354. if (((TBJ_SHANGCHAO_IN_UP || TBJ_bSC) && !TBJ_bSC_FLAG) && (!TBJ_FJ_VAVLE && !TBJ_FJ_LIMIT_IN && TBJ_FJ_ORIGIN_IN || TBJ_PARAM_FenJiaoSelect) //分胶阀判断
  355. && (!TBJ_SJ_VAVLE && !TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN || TBJ_PARAM_SongJiaoMode) //送胶阀判断
  356. && (dwTickCount >= TBJ_CS_Delay)) //超声间隔
  357. {
  358. if (!TBJ_TD_LIMIT_IN && TBJ_GZ_ORIGIN_IN || TBJ_PARAM_SGZSelect)
  359. {
  360. TBJ_bSC_FLAG = 1;
  361. TBJ_HMCS_Step = 1; //整个合模超声过程
  362. }
  363. TBJ_bSC = 0;
  364. }
  365. else if (TBJ_SHANGCHAO_IN_DW || (TBJ_bSC_FLAG && (TBJ_HMCS_Step == 0)) || (TBJ_bSC_FLAG && TBJ_bSC))
  366. {
  367. TBJ_bSC_FLAG = 0;
  368. TBJ_bSC = 0;
  369. TBJ_SM_VAVLE = 0;
  370. TBJ_CS_OUT = 0;
  371. TBJ_CS_Delay = dwTickCount + 300;
  372. }
  373. else if (TBJ_bSC)
  374. {
  375. if (TBJ_FJ_VAVLE)
  376. TBJ_SetAlarmCode(57); //E57 手动上超停止,分胶阀未退回
  377. else if (TBJ_FJ_LIMIT_IN)
  378. TBJ_SetAlarmCode(58); //E58 手动上超停止,分胶阀未退回,或X12分胶前感应异常
  379. else if (!TBJ_PARAM_FenJiaoSelect && !TBJ_FJ_ORIGIN_IN)
  380. TBJ_SetAlarmCode(59); //E59 手动上超停止,分胶阀未退回,或X13分胶后感应异常
  381. else if (TBJ_PARAM_SongJiaoMode == 0)
  382. {
  383. if (TBJ_SJ_VAVLE)
  384. TBJ_SetAlarmCode(60); //E60 手动上超停止,送胶阀未退回
  385. if (TBJ_SJ_LIMIT_IN)
  386. TBJ_SetAlarmCode(61); //E61 手动上超停止,送胶阀未退回,或X16送胶到位感应异常
  387. if (!TBJ_SJ_ORIGIN_IN)
  388. TBJ_SetAlarmCode(62); //E62 手动上超停止,送胶阀未退回,或X17退胶到位感应异常
  389. }
  390. TBJ_bSC = 0;
  391. TBJ_bSC_FLAG = 0;
  392. }
  393. //手动夹胶(压带)
  394. if (TBJ_bYD)
  395. {
  396. if (TBJ_YD_VAVLE)
  397. TBJ_YD_VAVLE = 0;
  398. else
  399. TBJ_YD_VAVLE = 1;
  400. TBJ_bYD = 0;
  401. }
  402. }
  403. }
  404. //送胶动作
  405. void TBJ_SongJiao(void)
  406. {
  407. if (TBJ_bStop)
  408. return;
  409. switch (TBJ_SJ_FJ_Step)
  410. {
  411. case 0:
  412. break;
  413. case 1:
  414. TBJ_SJ_FJ_Step = 2;
  415. TBJ_SJ_Delay = dwTickCount + TBJ_PARAM_FJ_DELAY;
  416. break;
  417. case 2:
  418. if (dwTickCount >= TBJ_SJ_Delay)
  419. {
  420. TBJ_SJ_FJ_Step = 3;
  421. TBJ_FJ_VAVLE = 1; //分胶阀输出
  422. TBJ_YD_VAVLE = 1; //夹胶阀输出
  423. TBJ_FJ_Delay = dwTickCount + 60; //分胶阀输出时间
  424. TBJ_SJ_ErrorTime = dwTickCount + ERRORTIME; //分胶阀输出容错时间
  425. }
  426. break;
  427. case 3:
  428. if ( (dwTickCount > TBJ_FJ_Delay) ||TBJ_TEST_MODE || (!TBJ_bRunning || TBJ_OneTimes)) //
  429. {
  430. TBJ_SJ_FJ_Step = 4;
  431. }
  432. else if (!TBJ_FJ_LIMIT_IN && (dwTickCount >= TBJ_SJ_ErrorTime))
  433. {
  434. TBJ_SetAlarmCode(10); //E10 分胶未到位或 X12分胶前感应异常,无法送胶
  435. }
  436. break;
  437. case 4:
  438. if (TBJ_PARAM_SGZSelect || (TBJ_Motor_Step == 0))
  439. {
  440. if (TBJ_FJ_LIMIT_IN && TBJ_FJ_VAVLE)
  441. {
  442. TBJ_SJ_FJ_Step = 5;
  443. TBJ_SJ_VAVLE = 1; //送胶输出
  444. TBJ_SJ_ErrorTime = dwTickCount + ERRORTIME;
  445. TBJ_FJ_Delay = dwTickCount + TBJ_PARAM_SJ_TIME;
  446. }
  447. else if (dwTickCount > TBJ_SJ_ErrorTime)
  448. {
  449. TBJ_SetAlarmCode(10); //E10 分胶未到位或 X12分胶前感应异常,无法送胶
  450. }
  451. }
  452. break;
  453. case 5:
  454. if (TBJ_SJ_LIMIT_IN_UP || (TBJ_PARAM_SongJiaoMode && TBJ_PARAM_GUNLUN_SIGN && (dwTickCount > TBJ_FJ_Delay)))
  455. {
  456. if (TBJ_bRunning)
  457. {
  458. TBJ_SJ_FJ_Step = 6;
  459. TBJ_FJ_Delay = dwTickCount + 15;
  460. }
  461. else
  462. TBJ_SJ_FJ_Step = 0;
  463. }
  464. else if (dwTickCount > TBJ_SJ_ErrorTime)
  465. {
  466. TBJ_SetAlarmCode(4); //E04 送胶不到位或 X16送胶前感应异常
  467. }
  468. if (TBJ_NOJIAO_IN && TBJ_bRunning)
  469. {
  470. TBJ_SetAlarmCode(7); //E07 胶已用完,请补充胶
  471. TBJ_OneTimes = 1;
  472. }
  473. break;
  474. case 6:
  475. if ((dwTickCount >= TBJ_FJ_Delay) && ((!X_DRV) || ((TBJ_Auto_Step == 2) && TBJ_GUO_LIAN_IN)))
  476. {
  477. TBJ_SJ_FJ_Step = 7;
  478. if (!TBJ_FJBACKMode)
  479. TBJ_FJ_VAVLE = 0; //关分胶
  480. TBJ_YD_VAVLE = 0; //关夹胶
  481. TBJ_FJ_Delay = dwTickCount + 50;
  482. TBJ_SJ_ErrorTime = dwTickCount + ERRORTIME;
  483. }
  484. break;
  485. case 7:
  486. if ((!TBJ_FJ_LIMIT_IN || (TBJ_FJBACKMode == 1)) && (dwTickCount >= TBJ_FJ_Delay) || TBJ_TEST_MODE)
  487. {
  488. TBJ_SJ_FJ_Step = 8;
  489. if ((TBJ_PARAM_SongJiaoMode == 0) || (!TBJ_bRunning)) //气缸送胶先退,滚轮送胶先不退或是触摸屏手动退送胶
  490. TBJ_SJ_VAVLE = 0;
  491. TBJ_SJ_ErrorTime = dwTickCount + ERRORTIME;
  492. }
  493. else if (dwTickCount >= TBJ_SJ_ErrorTime)
  494. {
  495. TBJ_SetAlarmCode(6); //E06 退分胶不到位警告或 X13分胶后感应异常
  496. }
  497. break;
  498. case 8:
  499. if (((TBJ_PARAM_SongJiaoMode == 1) || (!TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN)))
  500. {
  501. TBJ_SJ_FJ_Step = 0;
  502. M0019 = 0;
  503. }
  504. else if (dwTickCount >= TBJ_SJ_ErrorTime)
  505. {
  506. TBJ_SetAlarmCode(5); //E05 退胶不到位警告 或 X16、X17送胶前后感应异常
  507. }
  508. break;
  509. }
  510. }
  511. //合模超声动作
  512. void TBJ_ChaoShengHeMo(void)
  513. {
  514. unsigned short cs_time;
  515. switch (TBJ_HMCS_Step)
  516. {
  517. case 0:
  518. break;
  519. case 1:
  520. if ((!TBJ_FJ_VAVLE) && ((!TBJ_SJ_VAVLE) || (TBJ_PARAM_SongJiaoMode)) //输出阀判断
  521. && (!TBJ_FJ_LIMIT_IN) && (TBJ_FJ_ORIGIN_IN || TBJ_PARAM_FenJiaoSelect) //分胶阀位置判断
  522. && (((!TBJ_SJ_LIMIT_IN) && TBJ_SJ_ORIGIN_IN) || (TBJ_PARAM_SongJiaoMode == 1)) //送胶阀位置判断
  523. && (TBJ_GZ_ORIGIN_IN || (TBJ_PARAM_SGZSelect))) //钩针阀判断
  524. {
  525. TBJ_SM_VAVLE = 1; // 下冲
  526. if ((TBJ_PARAM_XiaMo_Mode == 0) && (TBJ_PARAM_SGZSelect != 0))
  527. TBJ_XM_VAVLE = 1;
  528. TBJ_HMCS_Step = 2;
  529. TBJ_SM_ErrorTime = dwTickCount + (unsigned long)ERRORTIME; //上模下冲容错时间
  530. }
  531. else if (!TBJ_bRunning)
  532. {
  533. TBJ_HMCS_Step = 0;
  534. }
  535. break;
  536. case 2:
  537. if (TBJ_SM_LIMIT_IN && ((TBJ_GZ_ORIGIN_IN && (TBJ_PARAM_SGZSelect != 0)) || TBJ_PARAM_XiaMo_Mode)) //1 下模不动
  538. {
  539. TBJ_CS_Delay = dwTickCount + TBJ_PARAM_CS_DELAY; //延时超声
  540. TBJ_HMCS_Step = 3;
  541. if (TBJ_PARAM_TuiGouZhen_Mode == 1) //0 先超声后下勾针,1 先下勾针后超声
  542. TBJ_GZ_VAVLE = 0;
  543. }
  544. else if ((dwTickCount >= TBJ_SM_ErrorTime) && (!X14))
  545. {
  546. TBJ_SetAlarmCode(26); //E26 超声停止,合模不到位或 X14下冲到位感应异常
  547. }
  548. else if ((dwTickCount >= TBJ_SM_ErrorTime) && (!TBJ_GZ_ORIGIN_IN))
  549. {
  550. TBJ_SetAlarmCode(27); //E27 超声停止,钩针不到位或 TBJ_GZ_ORIGIN_IN钩针复位感应异常
  551. }
  552. break;
  553. case 3:
  554. if (dwTickCount >= TBJ_CS_Delay)
  555. {
  556. TBJ_bCS = 0;
  557. TBJ_CS_OUT = 1; //超声打开
  558. cs_time = TBJ_Choose_CSTime();
  559. if (cs_time > 1500)
  560. cs_time = 1500; //超声时间上限为1.5 S
  561. TBJ_CS_Delay = dwTickCount + cs_time;
  562. TBJ_HMCS_Step = 4;
  563. }
  564. TBJ_SJ_VAVLE = 0;
  565. break;
  566. case 4:
  567. if (dwTickCount >= TBJ_CS_Delay)
  568. {
  569. TBJ_HMCS_Step = 5;
  570. TBJ_CS_OUT = 0;
  571. TBJ_CS_Delay = dwTickCount + (TBJ_Choose_COLDTime() / 2); //固化一半时间
  572. }
  573. break;
  574. case 5:
  575. if (dwTickCount >= TBJ_CS_Delay)
  576. {
  577. TBJ_HMCS_Step = 6;
  578. TBJ_ChuiQi();
  579. TBJ_GZ_VAVLE = 0;
  580. TBJ_CS_Delay = dwTickCount + (TBJ_Choose_COLDTime() / 2);
  581. }
  582. break;
  583. case 6:
  584. if (dwTickCount >= TBJ_CS_Delay)
  585. {
  586. if (TBJ_PARAM_HONGWAI_GanYin != 0)
  587. {
  588. //重新算温度
  589. cs_time = user_datas[55];
  590. if (user_datas[39] == 0)
  591. user_datas[39] = 1;
  592. //测温值 降时间阀值
  593. if ((cs_time >= user_datas[37]) && (cs_time >= user_datas[58]))
  594. {
  595. cs_time = (cs_time - user_datas[58]) / user_datas[39];
  596. cs_time *= user_datas[38];
  597. if (cs_time > 3)
  598. cs_time = 3;
  599. if ((user_datas[59] + cs_time) < 4)
  600. user_datas[59] += cs_time;
  601. else if (user_datas[59] < 4)
  602. {
  603. cs_time = 3 - user_datas[59];
  604. user_datas[59] = 3;
  605. }
  606. else
  607. cs_time = 0;
  608. }
  609. else
  610. cs_time = 0;
  611. user_datas[57] = TBJ_Choose_CSTime();
  612. user_datas[57] -= cs_time;
  613. TBJ_ResetCsTime();
  614. }
  615. user_datas[56] = user_datas[55];
  616. if (user_datas[56] > user_datas[58])
  617. user_datas[58] = user_datas[55];
  618. TBJ_SM_VAVLE = 0;
  619. TBJ_XM_VAVLE = 0;
  620. TBJ_HMCS_Step = 0;
  621. //TBJ_CS_Delay = dwTickCount + 350;
  622. }
  623. break;
  624. }
  625. }
  626. //启动停止故障停止动作
  627. void TBJ_StartStopAction(void)
  628. {
  629. if ((TBJ_START_IN_UP || TBJ_bStart || TBJ_bSingle) && !TBJ_bRunning && (TBJ_Auto_Step == 0))
  630. {
  631. if(TBJ_bSingle)
  632. {
  633. if(TBJ_GZ_VAVLE && !TBJ_PARAM_AOKO_MODE)
  634. {
  635. TBJ_bSingleone=1;
  636. TBJ_SJ_FJ_Step = 1; //开始分胶送胶,送胶分胶需电机动作完成后才能完成
  637. TBJ_Auto_Step = 3;
  638. TBJ_bRunning = 1;
  639. TBJ_Auto_Delay = 0;
  640. }
  641. else
  642. {
  643. ;
  644. }
  645. }
  646. else
  647. {
  648. if (TBJ_NOJIAO_IN)
  649. {
  650. TBJ_SetAlarmCode(7); //E07 胶已用完,请补充胶
  651. }
  652. else
  653. {
  654. TBJ_bSingleone=0;
  655. TBJ_Auto_Step = 1;
  656. TBJ_bRunning = 1;
  657. TBJ_Auto_Delay = 0;
  658. }
  659. }
  660. TBJ_bStart = 0;
  661. TBJ_bSingle=0;
  662. }
  663. if (TBJ_bStop)
  664. {
  665. /*当自动步骤达到4,已完成送胶动作,将本次贴胶动作做完*/
  666. TBJ_bSingleone=0;//单循环标志位
  667. TBJ_bSingle=0;
  668. TBJ_bStart = 0;
  669. TBJ_bRunning = 0;
  670. TBJ_bAlarmStop = 0;
  671. TBJ_bStop = 0;
  672. TBJ_HMCS_Step = 0;
  673. TBJ_Auto_Step = 0;
  674. TBJ_SJ_FJ_Step = 0;
  675. TBJ_Motor_Step = 0;
  676. AxisEgmStop(X_AXIS); //刹停电机
  677. SetEn(X_AXIS, TBJ_MOTOR_DISEN); //松轴
  678. TBJ_GZ_VAVLE = 0; //Y01钩针
  679. TBJ_FJ_VAVLE = 0; //Y02分胶
  680. TBJ_SM_VAVLE = 0; //Y03上模(下冲)
  681. TBJ_CS_OUT = 0; //Y10超声
  682. TBJ_MOTOR_OUT = 0; //Y11拖带电机
  683. TBJ_XM_VAVLE = 0; //Y12下模
  684. TBJ_OneTimes = 0; //清除单次标志
  685. TBJ_SetAlarmCode(0);
  686. if (TBJ_PARAM_SHENGJIAO == 1)
  687. TBJ_STOP_Step = 1; //停机节省布胶动作
  688. else
  689. {
  690. TBJ_YD_VAVLE = 0; //Y05压带
  691. TBJ_SJ_VAVLE = 0; //Y04送胶退回
  692. }
  693. }
  694. if (TBJ_STOP_IN_UP )
  695. {
  696. /*当自动步骤达到4,已完成送胶动作,将本次贴胶动作做完*/
  697. TBJ_bSingleone=0;//单循环标志位
  698. TBJ_bSingle=0;
  699. TBJ_bStart = 0;
  700. TBJ_bRunning = 0;
  701. TBJ_bAlarmStop = 0;
  702. TBJ_bStop = 0;
  703. TBJ_HMCS_Step = 0;
  704. TBJ_Auto_Step = 0;
  705. TBJ_SJ_FJ_Step = 0;
  706. TBJ_Motor_Step = 0;
  707. AxisEgmStop(X_AXIS); //刹停电机
  708. SetEn(X_AXIS, TBJ_MOTOR_DISEN); //松轴
  709. TBJ_GZ_VAVLE = 0; //Y01钩针
  710. TBJ_FJ_VAVLE = 0; //Y02分胶
  711. TBJ_SM_VAVLE = 0; //Y03上模(下冲)
  712. TBJ_CS_OUT = 0; //Y10超声
  713. TBJ_MOTOR_OUT = 0; //Y11拖带电机
  714. TBJ_XM_VAVLE = 0; //Y12下模
  715. TBJ_OneTimes = 0; //清除单次标志
  716. TBJ_SetAlarmCode(0);
  717. if (TBJ_PARAM_SHENGJIAO == 1)
  718. TBJ_STOP_Step = 1; //停机节省布胶动作
  719. else
  720. {
  721. TBJ_YD_VAVLE = 0; //Y05压带
  722. TBJ_SJ_VAVLE = 0; //Y04送胶退回
  723. }
  724. }
  725. if (TBJ_bAlarmStop)
  726. {
  727. TBJ_bAlarmStop = 0;
  728. AxisEgmStop(X_AXIS);
  729. TBJ_Auto_Step = 0;
  730. TBJ_HMCS_Step = 0;
  731. TBJ_Motor_Step = 0;
  732. TBJ_SJ_FJ_Step = 0;
  733. TBJ_GZ_VAVLE = 0; //Y01钩针
  734. TBJ_FJ_VAVLE = 0; //Y02分胶
  735. TBJ_SM_VAVLE = 0; //Y03上模(下冲)
  736. TBJ_CS_OUT = 0; //Y10超声
  737. TBJ_SJ_VAVLE=0;
  738. TBJ_YD_VAVLE=0;
  739. TBJ_XM_VAVLE = 0; //Y12下模
  740. TBJ_bRunning = 0;
  741. SingOneFlg = 0;
  742. SetEn(X_AXIS, TBJ_MOTOR_DISEN); //松轴
  743. }
  744. }
  745. void TBJ_STOP_Action(void)
  746. {
  747. switch (TBJ_STOP_Step)
  748. {
  749. case 0:
  750. break;
  751. case 1:
  752. {
  753. TBJ_YD_VAVLE = 1;
  754. TBJ_STOP_Delay = dwTickCount + 50;
  755. TBJ_STOP_Step = 2;
  756. }
  757. break;
  758. case 2:
  759. if (dwTickCount >= TBJ_STOP_Delay)
  760. {
  761. TBJ_SJ_VAVLE = 0;
  762. TBJ_STOP_Step = 3;
  763. }
  764. break;
  765. case 3:
  766. if (TBJ_SJ_ORIGIN_IN)
  767. {
  768. TBJ_YD_VAVLE = 0;
  769. TBJ_STOP_Step = 0;
  770. }
  771. break;
  772. }
  773. }
  774. //电机动作
  775. void TBJ_Motor(void) //
  776. {
  777. switch (TBJ_Motor_Step)
  778. {
  779. case 0:
  780. //AxisDecStop(X_AXIS); //上钩针后减速停,保证拉链到位
  781. break;
  782. case 1:
  783. TBJ_Motor_Step = 2;
  784. SetPos(X_AXIS, 0);
  785. if (TBJ_TEST_MODE)
  786. TBJ_TEST_TIME = dwTickCount + (unsigned long)500;
  787. TBJ_DJ_ErrorTime = dwTickCount + TBJ_PARAM_DJ_AUTO_STOP_TIME; //电机容错时间
  788. if (TEST1 > 1 && TBJ_PARAM_DEC_MODE)
  789. {
  790. //第三条,开始走数控长度
  791. AxisMovePosAccDecNotStop(X_AXIS, TBJ_PARAM_HIGH_SPEED, TBJ_SAVE_POS - TNJ_PARAM_TD_LENGTH - TBJ_PARAM_DEC_LEN, TBJ_PARAM_MOTOR_START_SPEED, TBJ_PARAM_NULL_SPEED, TBJ_PARAM_MOTOR_ADD, TBJ_PARAM_MOTOR_ADD + 10, 0);
  792. }
  793. else
  794. {
  795. AxisContinueMoveAcc(X_AXIS, TBJ_PARAM_HIGH_SPEED, TBJ_DIR_P, TBJ_PARAM_MOTOR_START_SPEED,
  796. TBJ_PARAM_NULL_SPEED, TBJ_PARAM_MOTOR_ADD, TBJ_PARAM_MOTOR_ADD);
  797. }
  798. break;
  799. case 2:
  800. if (TEST1 > 1 && TBJ_PARAM_DEC_MODE)
  801. {
  802. if (!TBJ_GUO_LIAN_IN)
  803. {
  804. TBJ_Motor_Step = 50;
  805. TBJ_Motor_Delay = dwTickCount + 10; //防震时间
  806. if (TBJ_TEST_MODE)
  807. TBJ_TEST_TIME = dwTickCount + (unsigned long)200;
  808. else
  809. TBJ_TEST_TIME = dwTickCount + (unsigned long)5;
  810. TBJ_DJ_ErrorTime = dwTickCount + (unsigned long)ERRORTIME;
  811. }
  812. if ((TBJ_PARAM_LL_PRETECT_LENGTH > 0) && (GetPos(X_AXIS) >= TBJ_SAVE_POS + TBJ_PARAM_LL_PRETECT_LENGTH))
  813. {
  814. TBJ_SetAlarmCode(8); //E8 拉链长度异常,超过拉链保护长度
  815. }
  816. }
  817. else
  818. {
  819. if (TBJ_GUO_LIAN_IN_DOWN || (TBJ_TEST_MODE && (dwTickCount > TBJ_TEST_TIME)))
  820. {
  821. TBJ_Motor_Step = 50;
  822. TBJ_Motor_Delay = dwTickCount + 10; //防震时间
  823. if (TBJ_TEST_MODE)
  824. TBJ_TEST_TIME = dwTickCount + (unsigned long)200;
  825. else
  826. TBJ_TEST_TIME = dwTickCount + (unsigned long)5;
  827. TBJ_DJ_ErrorTime = dwTickCount + (unsigned long)ERRORTIME;
  828. AxisChangeSpeed(X_AXIS, TBJ_PARAM_NULL_SPEED);
  829. }
  830. }
  831. if ((dwTickCount > TBJ_DJ_ErrorTime) && (TBJ_PARAM_DJ_AUTO_STOP_TIME != 0))
  832. {
  833. TBJ_SetAlarmCode(24); //E24 拉拉链时间过长,可能由以下原因:①超出保护时间,请检查保护时间是否设置过短②电机是否启动,速度是否过慢③拉链过紧,电机没拉动
  834. }
  835. break;
  836. case 50: //防震
  837. if (TBJ_GUO_LIAN_IN)
  838. {
  839. TBJ_Motor_Step = 2;
  840. }
  841. if (dwTickCount >= TBJ_Motor_Delay)
  842. {
  843. TBJ_Motor_Step = 3;
  844. }
  845. break;
  846. case 3:
  847. if (TBJ_GUO_LIAN_IN_UP || (TBJ_TEST_MODE && (dwTickCount > TBJ_TEST_TIME))) //过链上升沿
  848. {
  849. if (TBJ_PARAM_TWOTD_SELECT == 0)
  850. {
  851. TBJ_Motor_Step = 4;
  852. TBJ_DJ_ErrorTime = dwTickCount + 500; //电机容错时间
  853. AxisMovePosAccDec(X_AXIS, TBJ_PARAM_NULL_SPEED, TNJ_PARAM_TD_LENGTH, TBJ_PARAM_NULL_SPEED,
  854. TBJ_PARAM_NULL_SPEED, 5, 5, 0); //普通拖带,根据脉冲走一定距离
  855. TBJ_GZ_Delay = dwTickCount + TBJ_PARAM_GZ_DELAY; //钩针延时输出
  856. }
  857. else
  858. {
  859. AxisMovePosAccDec(X_AXIS, TBJ_PARAM_NULL_SPEED, TBJ_PARAM_TWOTD_LENGTH, TBJ_PARAM_NULL_SPEED,
  860. TBJ_PARAM_NULL_SPEED, 5, 5, 0); //二次拖带,根据脉冲走不同距离
  861. TBJ_Motor_Step = 40;
  862. }
  863. }
  864. else if (dwTickCount > TBJ_DJ_ErrorTime) //一直处于空位,没拉链警告
  865. {
  866. TBJ_SetAlarmCode(1); //E01 没拉链警告 请检查 X11 过链接近开关
  867. }
  868. break;
  869. case 40:
  870. if (!X_DRV) //轴停
  871. {
  872. //TBJ_CLUTH_VAVLE = 0; //关离合
  873. AxisEgmStop(X_AXIS); //停止电机,未松轴
  874. TBJ_SJ_VAVLE=0;
  875. TBJ_GZ_VAVLE = 1; //输出钩针
  876. if (TBJ_SJ_FJ_Step == 0) //分胶送胶已完成
  877. {
  878. TBJ_Motor_Delay = dwTickCount + TBJ_PARAM_TWOTD_DELAY; //二次拖带电机延时输出
  879. TBJ_Motor_Step = 41;
  880. }
  881. }
  882. break;
  883. case 41:
  884. if (dwTickCount > TBJ_Motor_Delay) //二次拖带电机延时已过
  885. TBJ_Motor_Step = 4;
  886. TBJ_DJ_ErrorTime = dwTickCount + 500; //电机容错时间
  887. AxisMovePosAccDec(X_AXIS, TBJ_PARAM_NULL_SPEED, TNJ_PARAM_TD_LENGTH, TBJ_PARAM_NULL_SPEED,
  888. TBJ_PARAM_NULL_SPEED, 5, 5, 0); //根据脉冲走一定距离
  889. //TBJ_CLUTH_VAVLE = 1; //开离合
  890. break;
  891. case 4:
  892. if (dwTickCount > TBJ_GZ_Delay)
  893. {
  894. TBJ_GZ_VAVLE = 1; //上钩针
  895. }
  896. if (!X_DRV && (TBJ_PARAM_SGZSelect == 1) || (TBJ_TD_LIMIT_IN || TBJ_TEST_MODE))
  897. {
  898. TBJ_GZ_VAVLE = 1; //上钩针
  899. AxisEgmStop(X_AXIS); //急停电机
  900. if (TBJ_PARAM_SGZSelect == 0) //选择双沟针方式
  901. {
  902. TBJ_Motor_Step = 5;
  903. TBJ_Motor_Delay = dwTickCount + 1; //延时压带
  904. }
  905. else
  906. {
  907. TBJ_Motor_Step = 0; //单钩针方式便完成电机动作
  908. }
  909. }
  910. else if (dwTickCount >= TBJ_DJ_ErrorTime)
  911. {
  912. TBJ_SetAlarmCode(25); //E25 钩针未到位或 TBJ_TD_LIMIT_IN 钩针到位感应异常警告,电机停止
  913. }
  914. break;
  915. /*以下为双钩针模式进行*/
  916. case 5:
  917. if (dwTickCount > TBJ_Motor_Delay)
  918. {
  919. TBJ_Motor_Step = 6;
  920. TBJ_YD_VAVLE = 1; //压带输出
  921. TBJ_PARAM_GZ_DELAY = dwTickCount + TBJ_PARAM_JJ_TIME; //压带输出延时退勾针
  922. }
  923. break;
  924. case 6:
  925. if (dwTickCount > TBJ_PARAM_GZ_DELAY) //过了钩针延时
  926. {
  927. TBJ_GZ_VAVLE = 0; //钩针退出
  928. TBJ_Motor_Step = 7;
  929. ///SetEn(X_AXIS, TBJ_MOTOR_DISEN); //松轴
  930. TBJ_DJ_ErrorTime = dwTickCount + ERRORTIME; //钩针退回容错时间
  931. }
  932. break;
  933. case 7:
  934. if (TBJ_GZ_ORIGIN_IN) //钩针返回原位感应
  935. {
  936. TBJ_Motor_Step = 0; //完成双钩针模式
  937. }
  938. else if (dwTickCount > TBJ_DJ_ErrorTime) //钩针长时间不退回
  939. {
  940. TBJ_SetAlarmCode(2); //E02 退勾针不到位或 TBJ_GZ_ORIGIN_IN 钩针复位感应异常,当前程序处于电机第七步
  941. }
  942. break;
  943. //电机退链
  944. case 20:
  945. //SetEn(X_AXIS, TBJ_MOTOR_EN); //锁轴
  946. //SetPos(X_AXIS, 0); //设当前位置pos为0
  947. TBJ_Motor_Step = 21;
  948. TBJ_Motor_Delay = dwTickCount + 10; //电机延时启动,等待锁轴
  949. if (TBJ_PARAM_DJ_FANZHUAN == 0) //电机如果没有选择反转退链,则关闭该步骤
  950. TBJ_Motor_Step = 0;
  951. break;
  952. case 21:
  953. if (dwTickCount > TBJ_Motor_Delay) //锁轴完成
  954. {
  955. TBJ_Motor_Step = 22;
  956. AxisMovePosAccDec(X_AXIS, TBJ_PARAM_NULL_SPEED, -TBJ_TUILIAN_LENGTH, TBJ_PARAM_NULL_SPEED,
  957. TBJ_PARAM_NULL_SPEED, 5, 5, 0); //根据脉冲走一定距离
  958. }
  959. break;
  960. case 22:
  961. if (!X_DRV) //电机移动到退链长度
  962. {
  963. TBJ_Motor_Step = 0;
  964. if (TBJ_FJBACKMode)
  965. TBJ_FJ_VAVLE = 0; //二次拖带退分胶
  966. }
  967. break;
  968. }
  969. }
  970. //自动运行动作
  971. void TBJ_AutoRunStep(void)
  972. {
  973. if (TBJ_bRunning)
  974. {
  975. switch (TBJ_Auto_Step)
  976. {
  977. case 0:
  978. break;
  979. case 1:
  980. TBJ_Auto_Step = 2;
  981. SetEn(X_AXIS, TBJ_MOTOR_EN); //锁轴
  982. TBJ_Auto_Delay = dwTickCount + 200;
  983. TEST1 = 0; //当前为第一条拉链
  984. TBJ_SAVE_POS = 0; //用来保存第二条长度,置零
  985. break;
  986. case 2: //第一条时
  987. if (dwTickCount > TBJ_Auto_Delay)
  988. {
  989. TBJ_Auto_Step = 3;
  990. TBJ_SJ_FJ_Step = 1; //开始分胶送胶,送胶分胶需电机动作完成后才能完成
  991. SetPos(X_AXIS, 0);
  992. if (!TBJ_GZ_VAVLE)
  993. {
  994. TBJ_Motor_Step = 1; //开始电机动作
  995. }
  996. else
  997. {
  998. TBJ_SetAlarmCode(QD_GZOut_W); //E18 钩针阀未退回,无法启动
  999. }
  1000. }
  1001. break;
  1002. case 3:
  1003. if ((TBJ_SJ_FJ_Step == 0) && (TBJ_Motor_Step == 0))
  1004. {
  1005. TBJ_Auto_Step = 4;
  1006. if (TEST1 == 1) //第二条拉链
  1007. TBJ_SAVE_POS = GetPos(X_AXIS); //保存第二条拉链的长度数据
  1008. if (TBJ_PARAM_DJ_FANZHUAN == 1)
  1009. TBJ_Motor_Step = 20;
  1010. TBJ_Auto_Delay = dwTickCount + 1000; //延迟执行超声合模动作
  1011. }
  1012. break;
  1013. case 4:
  1014. if (((!TBJ_FJ_VAVLE && !TBJ_FJ_LIMIT_IN && TBJ_FJ_ORIGIN_IN) || TBJ_PARAM_FenJiaoSelect) //分胶没输出 到位没感应 原位有感应 没有分胶阀则不考虑前面条件
  1015. && ((!TBJ_SJ_VAVLE && !TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN) || TBJ_PARAM_SongJiaoMode) //送胶没输出 到位没感应 原位有感应 滚轮送胶则不考虑前面条件
  1016. && ((!TBJ_PARAM_SGZSelect && TBJ_GZ_ORIGIN_IN && !TBJ_TD_LIMIT_IN) || TBJ_PARAM_SGZSelect)) //双钩针模式需要考虑钩针退回原位 拖带到位感应不亮 单钩针模式不考虑
  1017. {
  1018. if (TBJ_Motor_Step == 0) //反转完成
  1019. {
  1020. TBJ_Auto_Step = 5;
  1021. TBJ_HMCS_Step = 1; //执行合模超声动作
  1022. }
  1023. }
  1024. else if (dwTickCount >= TBJ_Auto_Delay)
  1025. {
  1026. if (TBJ_FJ_VAVLE && !TBJ_PARAM_FenJiaoSelect)
  1027. TBJ_SetAlarmCode(28); //E28 自动停止,分胶阀退位异常
  1028. else if (TBJ_FJ_LIMIT_IN && !TBJ_PARAM_FenJiaoSelect)
  1029. TBJ_SetAlarmCode(29); //E29 自动停止,分胶未退位或分胶前感应异常
  1030. else if (!TBJ_FJ_ORIGIN_IN && !TBJ_PARAM_FenJiaoSelect)
  1031. TBJ_SetAlarmCode(30); //E30 自动停止,分胶未退位或分胶后感应异常
  1032. else if (TBJ_SJ_VAVLE && !TBJ_PARAM_SongJiaoMode)
  1033. TBJ_SetAlarmCode(31); //E31 自动停止,送胶阀退位异常
  1034. else if (TBJ_SJ_LIMIT_IN && !TBJ_PARAM_SongJiaoMode)
  1035. TBJ_SetAlarmCode(32); //E32 自动停止,送胶未退位或送胶前感应异常
  1036. else if (!TBJ_SJ_ORIGIN_IN && !TBJ_PARAM_SongJiaoMode)
  1037. TBJ_SetAlarmCode(33); //E33 自动停止,送胶未退位或送胶后感应异常
  1038. else
  1039. {
  1040. TBJ_SetAlarmCode(QD_GZDaoWei_W); //E03 钩针未退位或 X20 钩针到位感应异常警告,无法启动
  1041. }
  1042. }
  1043. break;
  1044. case 5:
  1045. if (TBJ_HMCS_Step == 0)
  1046. {
  1047. TBJ_Auto_Step = 6;
  1048. TBJ_GZ_VAVLE = 0; //退钩针
  1049. if(TBJ_bSingleone==1)
  1050. {
  1051. SetEn(X_AXIS, TBJ_MOTOR_DISEN); //松轴
  1052. TBJ_bStop = 1;
  1053. }
  1054. if(!TBJ_bSingleone)
  1055. {
  1056. AddToTal(TBJ_TOTAL_ADDR); //产量增加
  1057. CalProSP(TBJ_SPEED_ADDR); //计算生产速度
  1058. }
  1059. }
  1060. break;
  1061. case 6:
  1062. if (!TBJ_SM_LIMIT_IN && //上模已离开
  1063. (((TBJ_PARAM_SGZSelect == 0) && TBJ_GZ_ORIGIN_IN && !TBJ_TD_LIMIT_IN) //双钩针模式,钩针已回到原位,拖带到位感应不亮(该感应需要上钩针配合,不亮代表无钩针配合)
  1064. || ((TBJ_PARAM_XiaMo_Mode == 0) && !TBJ_GZ_ORIGIN_IN) //下模不动模式,钩针与上下模位置错开,不相互影响,不需要回到原位
  1065. || ((TBJ_PARAM_XiaMo_Mode == 1) && TBJ_PARAM_SGZSelect))) //下模活动模式,单钩针模式,钩针与上下模位置错开
  1066. {
  1067. TBJ_Auto_Step = 7;
  1068. TBJ_Auto_Delay = dwTickCount + TBJ_PARAM_KAIMO_TD_DELAY + 45; //开模后延时拖带,45为下限时间
  1069. }
  1070. break;
  1071. case 7:
  1072. if (dwTickCount > TBJ_Auto_Delay)
  1073. {
  1074. TBJ_Auto_Step = 2;
  1075. TEST1++;
  1076. if (TEST1 > 2)
  1077. TEST1 = 3;
  1078. }
  1079. break;
  1080. }
  1081. }
  1082. }
  1083. /*以下为 给力贴布机 2024.3.23 旧板设置默认参数*/
  1084. //void CSTieBu_SetDefault()
  1085. //{
  1086. // unsigned char i = 0;
  1087. // if(TBJ_Frist_SetDefa == 0)
  1088. // {
  1089. // user_datas[0] = 9;
  1090. // user_datas[1] = 0;
  1091. // user_datas[2] = 2;
  1092. // user_datas[3] = 0;
  1093. // user_datas[4] = 5;
  1094. // user_datas[5] = 260;
  1095. // user_datas[6] = 14;
  1096. // user_datas[7] = 120;
  1097. // user_datas[8] = 40;
  1098. // user_datas[9] = 0;
  1099. // user_datas[10] = 10;
  1100. // user_datas[11] = 15;
  1101. // user_datas[12] = 30;
  1102. // user_datas[13] = 7;
  1103. // user_datas[14] = 0;
  1104. // user_datas[15] = 1;
  1105. // user_datas[16] = 0;
  1106. // user_datas[17] = 1;
  1107. // user_datas[18] = 0;
  1108. // user_datas[19] = 0;
  1109. // user_datas[20] = 1;
  1110. // user_datas[21] = 0;
  1111. // user_datas[22] = 0;
  1112. // user_datas[23] = 0;
  1113. // user_datas[24] = 90;
  1114. // user_datas[25] = 0;
  1115. // user_datas[26] = 0;
  1116. // user_datas[27] = 30;
  1117. // user_datas[28] = 0;
  1118. // user_datas[29] = 0;
  1119. // user_datas[30] = 0;
  1120. // user_datas[31] = 0;
  1121. // user_datas[32] = 0;
  1122. // user_datas[33] = 0;
  1123. // user_datas[34] = 0;
  1124. // user_datas[35] = 0;
  1125. // user_datas[36] = 0;
  1126. // user_datas[37] = 0;
  1127. // user_datas[38] = 0;
  1128. // user_datas[39] = 0;
  1129. // user_datas[40] = 0;
  1130. // user_datas[41] = 0;
  1131. // user_datas[42] = 0;
  1132. // user_datas[43] = 0;
  1133. // user_datas[44] = 0;
  1134. // user_datas[45] = 0;
  1135. // user_datas[46] = 0;
  1136. // user_datas[47] = 0;
  1137. // user_datas[48] = 0;
  1138. // user_datas[49] = 0;
  1139. // user_datas[50] = 0;
  1140. // user_datas[51] = 0;
  1141. // user_datas[52] = 0;
  1142. // user_datas[53] = 0;
  1143. // user_datas[54] = 0;
  1144. // user_datas[55] = 0;
  1145. // user_datas[56] = 0;
  1146. // user_datas[57] = 0;
  1147. // user_datas[58] = 0;
  1148. // user_datas[59] = 0;
  1149. // user_datas[60] = 0;
  1150. // user_datas[61] = 0;
  1151. // user_datas[62] = 0;
  1152. // user_datas[63] = 0;
  1153. // user_datas[64] = 2;
  1154. // user_datas[65] = 0;
  1155. // user_datas[66] = 0;
  1156. // user_datas[67] = 0;
  1157. // while(i < 68)
  1158. // {
  1159. // Write24C04(2*i, cDataArea[i] >> 8);
  1160. // Write24C04(2*i+1, cDataArea[i]);
  1161. // i++;
  1162. // }
  1163. // Frist_SetDefa = 0x3E7;
  1164. // Write24C04(2*95,cDataArea[71] >> 8);
  1165. // Write24C04(2*95+1,cDataArea[71]);
  1166. // }
  1167. //}
  1168. #endif