JLTieBuJi-SF.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  1. #include "global.h"
  2. #if JIN_LONG_MACHINE == 1
  3. unsigned short Prv_SQJCOUNT,Prv_XQJCOUNT;
  4. void TBJ_InitAction(void);
  5. void TBJ_Action(void);
  6. void TBJ_ChuiQi(void);
  7. void TBJ_ChaoShengHeMo(void);
  8. void TBJ_SetAlarmCode(unsigned alarm_code); //等待调用
  9. void TBJ_StartStopAction(void);
  10. void TBJ_AutoRunStep(void);
  11. void TBJ_Motor(void);
  12. void TBJ_SongJiao(void);
  13. void TBJ_STOP_Action(void);
  14. void TBJ_ChuiQi_Stop(void);
  15. void TBJ_QJCount(void);
  16. void TBJ_QieJiao_Proc(void);
  17. void TBJ_XCReset_Proc(void);
  18. void TBJ_SFHeMo_Proc(void);
  19. void TBJ_ChaoShengHeMo_SF(void);
  20. void TBJ_QJCQ_Stop(void);
  21. void TBJ_Action(void)
  22. {
  23. //步骤显示
  24. DISPLAY_DATA0 = dwYRealPos_com;//TBJ_XC_RstStep;//TBJ_Auto_Step;
  25. DISPLAY_DATA1 = dwYRealPos;//TBJ_Motor_Step;
  26. DISPLAY_DATA2 = TBJ_HMCS_Step;
  27. DISPLAY_DATA3 = TBJ_HeMo_Step;//TBJ_SJ_FJ_Step;
  28. DISPLAY_DATA4 = TBJ_Auto_Step;//TBJ_XC_CS_LOCAL;//servo_y.IO_TO_COM;//TBJ_STOP_Step;
  29. DISPLAY_DATA5 = TBJ_FIRST_CS_Y_LOCAL;//TBJ_Motor_Step;//GetTarr(Y_AXIS);//dwXRealPos;
  30. DISPLAY_DATA6 = TBJ_CS_Y_Local;
  31. DISPLAY_DATA7 = TBJ_GH_Y_Local;
  32. CTHL_bServo_Com_Y=servo_y.IO_TO_COM;
  33. dwXRealPos = GetPos(X_AXIS);
  34. dwYRealPos = GetPos(Y_AXIS);
  35. dwYRealPos_com=get_encode_value(Y_AXIS)/4;//减速比
  36. TBJ_ManualAction();
  37. //TBJ_ChaoShengHeMo();
  38. TBJ_ChaoShengHeMo_SF();
  39. TBJ_StartStopAction();
  40. TBJ_AutoRunStep();
  41. TBJ_Motor();
  42. TBJ_SongJiao();
  43. TBJ_STOP_Action();
  44. TBJ_ChuiQi_Stop();
  45. TBJ_QJCQ_Stop();
  46. TBJ_QJCount();
  47. servo_com_run();
  48. TBJ_QieJiao_Proc();
  49. TBJ_XCReset_Proc();
  50. TBJ_SFHeMo_Proc();
  51. }
  52. void TBJ_QJCount(void)
  53. {
  54. if(TBJ_SQJGY_IN_UP)
  55. {
  56. TBJ_PARAM_SQJCOUNT++;
  57. }
  58. if(TBJ_XQJGY_IN_UP)
  59. {
  60. TBJ_PARAM_XQJCOUNT++;
  61. }
  62. }
  63. //故障报警
  64. void TBJ_SetAlarmCode(unsigned alarm_code)
  65. {
  66. SetAlarmCode(TBJ_ALARM_ADDR, alarm_code);
  67. TBJ_bAlarmStop = 1;
  68. }
  69. void TBJ_InitAction(void)
  70. {
  71. float buff_pulse, buff_dist;
  72. //电机脉冲与距离比例计算
  73. buff_pulse = TBJ_PARAM_CYCLE_PULSE; //电机走一圈所需的脉冲
  74. buff_dist = TBJ_PARAM_CYCLE_LENGTH; //电机走一圈长度
  75. XGearRatio = buff_pulse / buff_dist; //可根据距离换算所需脉冲,反之一样
  76. buff_pulse = TBJ_PARAM_YCYCLE_PULSE; //电机走一圈所需的脉冲
  77. buff_dist = TBJ_PARAM_YCYCLE_LENGTH; //电机走一圈长度
  78. YGearRatio= buff_pulse / buff_dist; //可根据距离换算所需脉冲,反之一样
  79. TBJ_CHENGXU_UPDATE = 1; //便于屏幕判断程序有无更新
  80. SetDirReverse(X_AXIS, 1);
  81. //传递伺服齿轮比参数
  82. set_com_servo_param(Y_AXIS,TBJ_PARAM_YCYCLE_PULSE,TBJ_PARAM_YCYCLE_LENGTH);
  83. SetServoComUse(X_AXIS,0);//X轴正常模式。
  84. SetServoComUse(Y_AXIS,1);//Y轴伺服扭矩通讯。
  85. ReadServoAlarm_Enable(Y_AXIS,1);
  86. ReadServoEncode_Enable(Y_AXIS,1);
  87. SetEnReverse(X_AXIS, 1);
  88. SetEnReverse(Y_AXIS, 0);
  89. //电机松轴
  90. SetEn(X_AXIS, TBJ_MOTOR_DISEN);
  91. SetEn(Y_AXIS, TBJ_MOTOR_DISEN);
  92. SetAlarmCode(TBJ_ALARM_ADDR, TBJ_NO_ALARM); //警告要清除
  93. TBJ_Hemo_flag=0;
  94. TBJ_XC_Reset_flag=1;
  95. if(TBJ_PARAM_XCRest_MODE)TBJ_bXCRest=1;
  96. }
  97. //吹气
  98. void TBJ_ChuiQi(void)
  99. {
  100. if (!TBJ_CQ_VAVLE)
  101. {
  102. TBJ_CQ_VAVLE = 1;
  103. TBJ_CQ_Delay = dwTickCount + TBJ_PARAM_ChuiQi_TIME;
  104. }
  105. }
  106. //停止吹气
  107. void TBJ_ChuiQi_Stop(void)
  108. {
  109. if (TBJ_CQ_VAVLE && dwTickCount >= TBJ_CQ_Delay)// && dwTickCount >= TBJ_CS_Delay)
  110. TBJ_CQ_VAVLE = 0;
  111. }
  112. //切胶吹气
  113. void TBJ_QJCQ_Start(void)
  114. {
  115. if (!TBJ_QJCQ_VAVLE)
  116. {
  117. TBJ_QJCQ_VAVLE = 1;
  118. TBJ_QJCQ_Delay = dwTickCount + TBJ_PARAM_QJCQ_TIME;
  119. }
  120. }
  121. //停止吹气
  122. void TBJ_QJCQ_Stop(void)
  123. {
  124. if (TBJ_QJCQ_VAVLE && dwTickCount >= TBJ_QJCQ_Delay)// && dwTickCount >= TBJ_CS_Delay)
  125. TBJ_QJCQ_VAVLE = 0;
  126. }
  127. //红外算出来的时间重新赋值
  128. void TBJ_ResetCsTime(void)
  129. {
  130. if (TBJ_PARAM_CS_MODE == 0)
  131. user_datas[33] = user_datas[57];
  132. else
  133. user_datas[6] = user_datas[57];
  134. }
  135. //超声时间选择
  136. unsigned short TBJ_Choose_CSTime(void)
  137. {
  138. if (TBJ_PARAM_CS_MODE == 0) //超声模式 0为透明胶 1为布胶
  139. return TBJ_PARAM_TMJ_CS_TIME; //透明胶超声时间
  140. else
  141. return TBJ_PARAM_BJ_CS_TIME; //布胶超声时间
  142. }
  143. //固化时间选择
  144. unsigned short TBJ_Choose_COLDTime(void)
  145. {
  146. if (TBJ_PARAM_CS_MODE == 0)
  147. return TBJ_PARAM_TMJ_GH_TIME; //透明胶固化时间
  148. else
  149. return TBJ_PARAM_BJ_GH_TIME; //布胶固化时间
  150. }
  151. //手动动作
  152. void TBJ_ManualAction(void)
  153. {
  154. #if 1
  155. if (!TBJ_bRunning)
  156. {
  157. //屏幕按钮手动钩针
  158. if (TBJ_bGZ)
  159. {
  160. TBJ_bGZ = 0;
  161. if (TBJ_GZ_VAVLE)
  162. TBJ_GZ_VAVLE = 0;
  163. else
  164. TBJ_GZ_VAVLE = 1;
  165. }
  166. //手动分胶
  167. if (TBJ_bFJ &&((TBJ_PARAM_SGZSelect) //单钩针模式下的判断
  168. || ((TBJ_PARAM_SGZSelect == 0) && !TBJ_GZ_LIMIT_IN )) //双钩针模式下的判断
  169. &&TBJ_Y_ORIGIN_IN //上模在原点
  170. && (TBJ_FJ_VAVLE || (!TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN)) //未进分胶,送胶不能输出,进完分胶后,无视送胶状态,可退分胶
  171. )
  172. {
  173. TBJ_bFJ = 0;
  174. if (TBJ_FJ_VAVLE)
  175. TBJ_FJ_VAVLE = 0;
  176. else
  177. TBJ_FJ_VAVLE = 1;
  178. }
  179. else if (TBJ_bFJ)
  180. {
  181. TBJ_bFJ = 0;
  182. if (!((TBJ_PARAM_SGZSelect) || ((TBJ_PARAM_SGZSelect == 0) && !TBJ_GZ_LIMIT_IN)))
  183. TBJ_SetAlarmCode(34); //E34 手动分胶停止,钩针未退位;
  184. else if (!TBJ_Y_ORIGIN_IN)//上摸不在原点
  185. TBJ_SetAlarmCode(36); //E36 手动分胶停止,下冲气缸未退位或X14下冲到位感应异常
  186. else if (TBJ_SJ_LIMIT_IN)
  187. TBJ_SetAlarmCode(38); //E38 手动分胶停止,送胶阀未退回,或X16送胶到位感应异常
  188. else if (!TBJ_SJ_ORIGIN_IN)
  189. TBJ_SetAlarmCode(39); //E39 手动分胶停止,送胶阀未退回,或X17退胶到位感应异常
  190. }
  191. //手动切胶
  192. if(TBJ_bQJ)
  193. {
  194. if(TBJ_SJ_ORIGIN_IN)TBJ_QJ_Step=1;
  195. else
  196. TBJ_SetAlarmCode(TBJ_QJ_SJNORIGIN_ALARM); //E43 手动切胶,送胶不在原位
  197. TBJ_bQJ=0;
  198. }
  199. //手动送胶
  200. if (((TBJ_bSJ && !TBJ_SJ_VAVLE))) //按钮按下 送胶阀未输出 进行送胶
  201. { //手动送胶 || (按钮送胶 && 送胶阀没输出)&& (!1二次拖带的情况下考虑钩针阀没有输出)
  202. if ((TBJ_PARAM_SGZSelect || ((TBJ_PARAM_SGZSelect == 0) &&!TBJ_GZ_LIMIT_IN) ) //单钩针模式,钩针与送胶阀错位,不用考虑相撞,双钩针模式下的判断,钩针钩住拖带后退,可能会与送胶阀产生碰撞
  203. && (TBJ_FJ_LIMIT_IN ^ TBJ_FJ_ORIGIN_IN) && TBJ_SJ_ORIGIN_IN //判断分胶阀有无出错,只能到位或原位 送胶阀后感应亮
  204. && TBJ_Y_ORIGIN_IN //上模原点 超声未打开
  205. && !TBJ_GZ_VAVLE) //考虑钩针有无退回
  206. {
  207. TBJ_SJ_FJ_Step=20;
  208. TBJ_bSJ = 0;
  209. }
  210. else if (TBJ_bSJ) //送胶失败,发送警告
  211. {
  212. TBJ_bSJ = 0;
  213. if (!(TBJ_PARAM_SGZSelect || ((TBJ_PARAM_SGZSelect == 0) &&!TBJ_GZ_LIMIT_IN)))
  214. TBJ_SetAlarmCode(40); //E40 手动送胶停止,双钩针模式下钩针未退回
  215. else if (!(TBJ_FJ_LIMIT_IN ^ TBJ_FJ_ORIGIN_IN))
  216. TBJ_SetAlarmCode(41); //E41 手动送胶停止,分胶阀处于异常状态,X12,X13前后感应灯同亮或同灭
  217. else if (!TBJ_SJ_VAVLE && !TBJ_SJ_ORIGIN_IN)
  218. TBJ_SetAlarmCode(42); //E42 手动送胶停止,X17送胶后感应异常
  219. else if (!TBJ_Y_ORIGIN_IN)
  220. TBJ_SetAlarmCode(44); //E44 手动送胶停止,下冲气缸未退回,或X14 下冲到位感应异常
  221. if (TBJ_SJ_VAVLE)
  222. TBJ_SJ_VAVLE = 0;
  223. }
  224. }
  225. else if (((TBJ_bSJ && TBJ_SJ_VAVLE))) //送胶阀已输出,进行退胶
  226. {
  227. TBJ_SJ_FJ_Step=25;
  228. TBJ_bSJ = 0;
  229. }
  230. //手动合模
  231. if (TBJ_bHM&&TBJ_Hemo_flag==0)//&& !TBJ_SM_VAVLE) //屏幕按钮按下 || 上模没输出 && 手动合模输入
  232. {
  233. if ( !TBJ_XC_Reset_flag&&TBJ_FJ_ORIGIN_IN && !TBJ_FJ_LIMIT_IN //分胶阀感应判断
  234. && ((!TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN) || TBJ_PARAM_SongJiaoMode) //送胶阀原点,或者滚筒模式 //送胶阀感应判断
  235. && !TBJ_FJ_VAVLE && !TBJ_SJ_VAVLE && !TBJ_CS_OUT //分胶阀,送胶阀、超声未动作 //分胶阀判断 送胶阀判断 超声判断
  236. && ((TBJ_PARAM_SGZSelect) || ((TBJ_PARAM_SGZSelect == 0) &&!TBJ_GZ_LIMIT_IN)))//双钩钩针在原点、或单钩针 //双钩针模式需考虑钩针有无输出
  237. {
  238. if(TBJ_PARAM_XiaChong_MODE==0)
  239. {
  240. TBJ_SM_VAVLE = 1;//气缸合模
  241. TBJ_Hand_Hemo_flag=1;
  242. }
  243. else
  244. {
  245. TBJ_HeMo_Step=1;//伺服合模
  246. TBJ_GZ_VAVLE = 0;//钩针
  247. TBJ_FJ_VAVLE = 0; //分胶
  248. TBJ_DZ_VAVLE=0;//顶针
  249. TBJ_SJ_VAVLE=0;//送胶
  250. TBJ_HeMo_Delay=dwTickCount+100;
  251. set_servo_postotarr_limit(Y_AXIS,SERVO_PARAM_TRARR_BD_LIMITMIN,
  252. TBJ_PARAM_Y_LOW_SPEED,TBJ_PARAM_Y_LOW_SPEED,SERVO_TARR_CW);
  253. }
  254. if (TBJ_PARAM_XiaMo_Mode == 0)TBJ_XM_VAVLE = 1; //下模活动
  255. TBJ_bHM = 0;
  256. }
  257. else
  258. {
  259. TBJ_bHM = 0;
  260. if (!TBJ_FJ_ORIGIN_IN)
  261. TBJ_SetAlarmCode(46); //E46 手动合模停止,分胶阀未退位,或 X13分胶后感应异常
  262. else if (TBJ_FJ_LIMIT_IN)
  263. TBJ_SetAlarmCode(47); //E47 手动合模停止,分胶阀未退位,或 X12分胶前感应异常
  264. else if (TBJ_SJ_LIMIT_IN)
  265. TBJ_SetAlarmCode(48); //E48 手动合模停止,送胶阀未退位,或 X16送胶前感应异常
  266. else if (!TBJ_SJ_ORIGIN_IN)
  267. TBJ_SetAlarmCode(49); //E49 手动合模停止,送胶阀未退位,或 X17分胶后感应异常
  268. else if (TBJ_CS_OUT)
  269. TBJ_SetAlarmCode(50); //E50 手动合模停止,超声未关闭
  270. else if(TBJ_XC_Reset_flag)
  271. TBJ_SetAlarmCode(TBJ_XC_NO_REST); //E09 下冲电机未复位
  272. }
  273. }
  274. else if (TBJ_bHM&&TBJ_Hemo_flag)// && TBJ_SM_VAVLE) //屏幕按钮按下 && 上模已输出 && 手动合模没输入
  275. {
  276. if(TBJ_PARAM_XiaChong_MODE==0)TBJ_SM_VAVLE = 0; //上模退回
  277. else
  278. {
  279. TBJ_HeMo_Step=20;//伺服合模
  280. SetPos(Y_AXIS,dwYRealPos_com);
  281. Set_Ctrlmode_trans(Y_AXIS,POS_MODE);
  282. TBJ_HeMo_Delay=dwTickCount+100;
  283. }
  284. if (TBJ_PARAM_XiaMo_Mode == 0)TBJ_XM_VAVLE = 0; //下模退回 //双钩针模式下 或下模活动模式
  285. TBJ_bHM = 0;
  286. }
  287. //合模后吹气一次
  288. if (TBJ_SM_LIMIT_IN&&TBJ_Hand_Hemo_flag) //合模到位
  289. {
  290. TBJ_ChuiQi(); //启动吹气
  291. TBJ_Hand_Hemo_flag = 0;
  292. }
  293. //连续超声
  294. if(TBJ_bCS)
  295. {
  296. if ((!TBJ_FJ_LIMIT_IN && TBJ_FJ_ORIGIN_IN ) //分胶阀判断
  297. && ( !TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN || TBJ_PARAM_SongJiaoMode)) //送胶阀判断
  298. {
  299. if (TBJ_bCS && !TBJ_bCS_FLAG) //按钮已按下,超声未开始
  300. {
  301. TBJ_bCS_FLAG = 1; //cMidleCoil[0] |= (1<<10); //M10
  302. TBJ_CS_OUT = 1; //发超声
  303. TBJ_CS_Delay = dwTickCount + TBJ_Choose_CSTime(); //限长时间1.5
  304. }
  305. }
  306. TBJ_bCS=0;
  307. }
  308. if(TBJ_bCS_FLAG&&dwTickCount >= TBJ_CS_Delay)
  309. {
  310. TBJ_bCS_FLAG=0;
  311. TBJ_bCS_FLAG = 0; //超声标志位清零
  312. TBJ_CS_OUT = 0; //关闭超声
  313. TBJ_ChuiQi(); //开启吹气
  314. }
  315. //合模+超声
  316. if(TBJ_bSC&& !TBJ_bSC_FLAG)
  317. {
  318. TBJ_bSC=0;
  319. if (!TBJ_XC_Reset_flag&&(!TBJ_FJ_VAVLE && !TBJ_FJ_LIMIT_IN && TBJ_FJ_ORIGIN_IN || TBJ_PARAM_FenJiaoSelect) //分胶阀判断
  320. && (!TBJ_SJ_VAVLE && !TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN || TBJ_PARAM_SongJiaoMode) //送胶阀判断
  321. && (dwTickCount >= TBJ_CS_Delay))
  322. {
  323. if ((TBJ_PARAM_SGZSelect || ((TBJ_PARAM_SGZSelect == 0) &&!TBJ_GZ_LIMIT_IN)))
  324. {
  325. TBJ_bSC_FLAG = 1;
  326. TBJ_HMCS_Step = 1; //整个合模超声过程
  327. TBJ_GZ_VAVLE = 0;//钩针
  328. TBJ_FJ_VAVLE = 0; //分胶
  329. TBJ_DZ_VAVLE=0;//顶针
  330. TBJ_SJ_VAVLE=0;//送胶
  331. set_servo_postotarr_limit(Y_AXIS,SERVO_PARAM_TRARR_BD_LIMITMIN,
  332. TBJ_PARAM_Y_LOW_SPEED,TBJ_PARAM_Y_LOW_SPEED,SERVO_TARR_CW);
  333. }
  334. }
  335. else
  336. {
  337. if (TBJ_FJ_VAVLE)
  338. TBJ_SetAlarmCode(57); //E57 手动上超停止,分胶阀未退回
  339. else if (TBJ_FJ_LIMIT_IN)
  340. TBJ_SetAlarmCode(58); //E58 手动上超停止,分胶阀未退回,或X12分胶前感应异常
  341. else if (!TBJ_PARAM_FenJiaoSelect && !TBJ_FJ_ORIGIN_IN)
  342. TBJ_SetAlarmCode(59); //E59 手动上超停止,分胶阀未退回,或X13分胶后感应异常
  343. else if (TBJ_PARAM_SongJiaoMode == 0)
  344. {
  345. if (TBJ_SJ_VAVLE)
  346. TBJ_SetAlarmCode(60); //E60 手动上超停止,送胶阀未退回
  347. if (TBJ_SJ_LIMIT_IN)
  348. TBJ_SetAlarmCode(61); //E61 手动上超停止,送胶阀未退回,或X16送胶到位感应异常
  349. if (!TBJ_SJ_ORIGIN_IN)
  350. TBJ_SetAlarmCode(62); //E62 手动上超停止,送胶阀未退回,或X17退胶到位感应异常
  351. }
  352. else if(TBJ_XC_Reset_flag)
  353. TBJ_SetAlarmCode(TBJ_XC_NO_REST); //E50 手动合模停止,超声未关闭
  354. }
  355. }
  356. //手动夹胶(压带)
  357. if (TBJ_bJJ)
  358. {
  359. if (TBJ_JJ_VAVLE)
  360. TBJ_JJ_VAVLE = 0;
  361. else
  362. TBJ_JJ_VAVLE = 1;
  363. TBJ_bJJ = 0;
  364. }
  365. //手动压带
  366. if (TBJ_bYD)
  367. {
  368. if (TBJ_YD_VAVLE)
  369. TBJ_YD_VAVLE = 0;
  370. else
  371. TBJ_YD_VAVLE = 1;
  372. TBJ_bYD = 0;
  373. }
  374. //顶针
  375. if (TBJ_bDZ)
  376. {
  377. if (TBJ_DZ_VAVLE)
  378. TBJ_DZ_VAVLE = 0;
  379. else
  380. TBJ_DZ_VAVLE = 1;
  381. TBJ_bDZ = 0;
  382. }
  383. //松带
  384. if (TBJ_bSD)
  385. {
  386. if (TBJ_SD_VAVLE)
  387. TBJ_SD_VAVLE = 0;
  388. else
  389. TBJ_SD_VAVLE = 1;
  390. TBJ_bSD = 0;
  391. }
  392. //风扇
  393. if (TBJ_bFS)
  394. {
  395. if (TBJ_LQFS_OUT){
  396. SetEn(X_AXIS, TBJ_MOTOR_DISEN);
  397. SetEn(Y_AXIS, TBJ_MOTOR_DISEN);
  398. TBJ_XC_Reset_flag=1;
  399. TBJ_LQFS_OUT = 0;
  400. }
  401. else
  402. {
  403. SetEn(X_AXIS, TBJ_MOTOR_EN);
  404. SetEn(Y_AXIS, TBJ_MOTOR_EN);
  405. TBJ_LQFS_OUT = 1;
  406. }
  407. TBJ_bFS = 0;
  408. }
  409. //手动拖带
  410. if(TBJ_bMotor_N)
  411. {
  412. SetEn(X_AXIS, TBJ_MOTOR_EN);
  413. if(!X_DRV)
  414. {
  415. AxisContinueMoveAcc(X_AXIS,1000,DIR_N,1000,1000,10,12);
  416. }
  417. }
  418. else if(TBJ_bMotor_P)
  419. {
  420. SetEn(X_AXIS, TBJ_MOTOR_EN);
  421. if(TBJ_GZ_LIMIT_IN)
  422. {
  423. TBJ_bMotor_N=0;
  424. AxisEgmStop(X_AXIS);
  425. }
  426. if(!X_DRV&&!TBJ_GZ_LIMIT_IN)
  427. {
  428. AxisContinueMoveAcc(X_AXIS,1000,DIR_P,1000,1000,10,12);
  429. }
  430. }
  431. else
  432. {
  433. if(X_DRV)
  434. {
  435. AxisEgmStop(X_AXIS);
  436. }
  437. }
  438. //手动下冲
  439. if(TBJ_bYMotor_N)
  440. {
  441. SetEn(Y_AXIS, TBJ_MOTOR_EN);
  442. if(TBJ_Y_ORIGIN_IN)AxisEgmStop(Y_AXIS);
  443. if(!Y_DRV&&!TBJ_Y_ORIGIN_IN)
  444. {
  445. AxisContinueMoveAcc(Y_AXIS,800,DIR_N,800,800,10,12);
  446. }
  447. }
  448. else if(TBJ_bYMotor_P)
  449. {
  450. SetEn(Y_AXIS, TBJ_MOTOR_EN);
  451. if(TBJ_Y_RUNING_IN)AxisEgmStop(Y_AXIS);
  452. if(!Y_DRV&&TBJ_FJ_ORIGIN_IN&&TBJ_SJ_ORIGIN_IN&&!TBJ_Y_RUNING_IN)
  453. {
  454. AxisContinueMoveAcc(Y_AXIS,800,DIR_P,800,1000,10,12);
  455. }
  456. }
  457. else
  458. {
  459. if(Y_DRV&&!TBJ_bXCResting&&TBJ_HMCS_Step==0&&TBJ_HeMo_Step==0)
  460. {
  461. AxisEgmStop(Y_AXIS);
  462. }
  463. }
  464. //复位下冲
  465. if(TBJ_bXCRest&&GetServoComState(Y_AXIS))
  466. {
  467. TBJ_bXCRest=0;
  468. TBJ_bXCResting=1;
  469. TBJ_XC_RstStep=1;
  470. TBJ_GZ_VAVLE = 0;//钩针
  471. TBJ_FJ_VAVLE = 0; //分胶
  472. TBJ_DZ_VAVLE=0;//顶针
  473. TBJ_SJ_VAVLE=0;//送胶
  474. SetEn(Y_AXIS, TBJ_MOTOR_EN);
  475. TBJ_XCRst_Delay=dwTickCount+100;
  476. Set_Ctrlmode_trans(Y_AXIS,POS_MODE);
  477. set_servo_postotarr_limit(Y_AXIS,SERVO_PARAM_TRARR_BD_LIMITMIN,TBJ_PARAM_SFZSY_SPEED,TBJ_PARAM_SFZSY_SPEED,SERVO_TARR_CW);
  478. }
  479. }
  480. #endif
  481. }
  482. //伺服合模处理
  483. void TBJ_SFHeMo_Proc(void)
  484. {
  485. switch(TBJ_HeMo_Step)
  486. {
  487. case 1:
  488. if(dwTickCount>=TBJ_HeMo_Delay)
  489. {
  490. TBJ_LENTH=TBJ_PARAM_Y_Work_Local-dwYRealPos;
  491. AxisMovePosAccDec(Y_AXIS, TBJ_PARAM_Y_HIGH_SPEED,TBJ_LENTH,1000,1000,20,20,10);
  492. TBJ_HeMo_Step++;
  493. }
  494. break;
  495. case 2:
  496. if(!Y_DRV)
  497. {
  498. TBJ_HeMo_Step=3;
  499. Set_Ctrlmode_trans(Y_AXIS,TARR_MODE);
  500. TBJ_HeMo_Delay=dwTickCount+100;
  501. }
  502. break;
  503. case 3:
  504. if(dwTickCount>=TBJ_HeMo_Delay)
  505. {
  506. TBJ_HeMo_Step=0;
  507. TBJ_Hemo_flag=1;
  508. SetPos(Y_AXIS,dwYRealPos_com);
  509. }
  510. break;
  511. case 20:
  512. if(dwTickCount>=TBJ_HeMo_Delay)
  513. {
  514. TBJ_LENTH=dwYRealPos-0;
  515. AxisMovePosAccDec(Y_AXIS, TBJ_PARAM_Y_HIGH_SPEED, -TBJ_LENTH, 1000,
  516. 1000, 20, 20, 10);
  517. TBJ_HeMo_Step++;
  518. }
  519. break;
  520. case 21:
  521. if(!Y_DRV)
  522. {
  523. TBJ_HeMo_Step=0;
  524. TBJ_Hemo_flag=0;
  525. TBJ_ChuiQi(); //启动吹气
  526. }
  527. break;
  528. }
  529. }
  530. //下冲复位处理
  531. void TBJ_XCReset_Proc(void)
  532. {
  533. switch(TBJ_XC_RstStep)
  534. {
  535. case 1:
  536. if(TBJ_XC_Reset_flag)
  537. {
  538. AxisDisableSoftwarelmt(Y_AXIS);
  539. if(TBJ_Y_ORIGIN_IN&&dwTickCount>=TBJ_XCRst_Delay)
  540. {
  541. TBJ_XC_RstStep=4;
  542. AxisContinueMove(Y_AXIS,200,DIR_P);
  543. }
  544. else
  545. {
  546. TBJ_XC_RstStep++;
  547. AxisContinueMove(Y_AXIS,800,DIR_N);
  548. }
  549. }
  550. else
  551. {
  552. TBJ_XC_RstStep=14;
  553. SetPos(Y_AXIS,dwYRealPos_com);
  554. }
  555. break;
  556. case 2:
  557. if(TBJ_Y_ORIGIN_IN)
  558. {
  559. TBJ_XC_RstStep++;
  560. AxisEgmStop(Y_AXIS);
  561. TBJ_XCRst_Delay=dwTickCount+10;
  562. }
  563. break;
  564. case 3:
  565. if(dwTickCount>=TBJ_XCRst_Delay)
  566. {
  567. TBJ_XC_RstStep++;
  568. AxisContinueMove(Y_AXIS,200,DIR_P);
  569. }
  570. break;
  571. case 4:
  572. if(!TBJ_Y_ORIGIN_IN)
  573. {
  574. TBJ_XC_RstStep++;
  575. AxisEgmStop(Y_AXIS);
  576. TBJ_XCRst_Delay=dwTickCount+10;
  577. }
  578. break;
  579. case 5:
  580. TBJ_XC_RstStep++;
  581. AxisMovePosAccDec(Y_AXIS,800,10,800,800,10,10,0);
  582. break;
  583. case 6:
  584. if(dwTickCount>=TBJ_XCRst_Delay&&!Y_DRV)
  585. {
  586. TBJ_XC_RstStep++;
  587. AxisContinueMove(Y_AXIS,200,DIR_N);
  588. }
  589. break;
  590. case 7:
  591. if(TBJ_Y_ORIGIN_IN)
  592. {
  593. TBJ_XC_RstStep++;
  594. AxisEgmStop(Y_AXIS);
  595. TBJ_XCRst_Delay=dwTickCount+10;
  596. }
  597. break;
  598. case 8:
  599. if(dwTickCount>=TBJ_XCRst_Delay&&!Y_DRV)
  600. {
  601. TBJ_XC_RstStep++;
  602. //AxisMovePos(Y_AXIS,400,-10);
  603. AxisMovePosAccDec(Y_AXIS,400,-10,400,400,10,10,0);
  604. }
  605. break;
  606. case 9:
  607. if(!Y_DRV)
  608. {
  609. /*if(TBJ_PARAM_SFXC_MODE)
  610. {
  611. if(get_tarr_set(Y_AXIS)!=2)//伺服配置转矩限制失败
  612. {
  613. TBJ_XC_RstStep=0;
  614. SetEn(Y_AXIS, MOTOR_DISEN);//设置扭矩做准备
  615. TBJ_XC_Reset_flag=1;
  616. TBJ_SetAlarmCode(65);//伺服转矩配置失败
  617. }
  618. }*/
  619. TBJ_XC_RstStep++;
  620. TBJ_XCRst_Delay=dwTickCount+100;
  621. }
  622. break;
  623. case 10:
  624. if(dwTickCount>=TBJ_XCRst_Delay&&!Y_DRV)
  625. {
  626. SetPos(Y_AXIS, 0);
  627. axis_set_com_pos(Y_AXIS,0);
  628. //if(TBJ_PARAM_SFXC_MODE==0)
  629. {
  630. TBJ_XC_RstStep=0;
  631. TBJ_bXCResting=0;
  632. TBJ_XC_Reset_flag=0;
  633. AxisEnableSoftwarelmt(Y_AXIS,TBJ_PARAM_Y_SOFT_PLIMIT,0);
  634. }
  635. /*else
  636. {
  637. TBJ_XC_RstStep++;
  638. TBJ_XCRst_Delay=dwTickCount+10;
  639. }*/
  640. }
  641. break;
  642. case 11:
  643. if(dwTickCount>=TBJ_XCRst_Delay)
  644. {
  645. TBJ_XC_RstStep++;
  646. Set_Ctrlmode_trans(Y_AXIS,TARR_MODE);
  647. TBJ_XCRst_Delay=dwTickCount+100;
  648. }
  649. break;
  650. case 12://扭矩到达
  651. if (dwTickCount >= TBJ_XCRst_Delay)
  652. {
  653. TBJ_XC_RstStep ++;
  654. TBJ_XCRst_Delay = dwTickCount + 500;
  655. }
  656. break;
  657. case 13://扭矩到达并维持10ms
  658. if (!(GetTarr(Y_AXIS)))
  659. {
  660. if((dwTickCount >= TBJ_XCRst_Delay))
  661. {
  662. TBJ_XC_RstStep++;
  663. TBJ_PARAM_Y_Work_Local= dwYRealPos_com-30;
  664. TBJ_PARAM_Y_SOFT_PLIMIT=dwYRealPos_com-20;
  665. //AxisEnableSoftwarelmt(Y_AXIS,TBJ_PARAM_Y_SOFT_PLIMIT,0);
  666. SetPos(Y_AXIS,dwYRealPos_com);
  667. Set_Ctrlmode_trans(Y_AXIS,POS_MODE);
  668. TBJ_XCRst_Delay = dwTickCount + 10;
  669. }
  670. }
  671. else
  672. {
  673. TBJ_XCRst_Delay = dwTickCount + 100;
  674. }
  675. break;
  676. case 14://扭矩到达
  677. if(dwTickCount>=TBJ_XCRst_Delay)
  678. {
  679. TBJ_XC_RstStep ++;
  680. AxisMovePosAccDec(Y_AXIS, TBJ_PARAM_Y_HIGH_SPEED, -dwYRealPos, 1000,
  681. 1000, 20, 20, 10) ;
  682. }
  683. break;
  684. case 15://扭矩到达
  685. if(!Y_DRV)
  686. {
  687. TBJ_XCRst_Delay = dwTickCount + 100;
  688. TBJ_XC_RstStep = 16;
  689. }
  690. break;
  691. case 16://扭矩到达
  692. if(dwTickCount>=TBJ_XCRst_Delay)
  693. {
  694. if(TBJ_Y_ORIGIN_IN)
  695. {
  696. TBJ_XC_RstStep = 0;
  697. TBJ_bXCResting=0;
  698. TBJ_XC_Reset_flag=0;
  699. }
  700. else
  701. {
  702. TBJ_XC_RstStep = 1;
  703. TBJ_bXCResting=1;
  704. TBJ_XC_Reset_flag=1;
  705. }
  706. }
  707. break;
  708. }
  709. }
  710. //送胶动作
  711. void TBJ_SongJiao(void)
  712. {
  713. #if 1
  714. if (TBJ_bStop)
  715. return;
  716. switch (TBJ_SJ_FJ_Step)
  717. {
  718. case 0:
  719. break;
  720. case 1:
  721. TBJ_SJ_FJ_Step = 2;
  722. TBJ_SJ_Delay = dwTickCount + TBJ_PARAM_FJ_DELAY;
  723. break;
  724. case 2:
  725. if (dwTickCount >= TBJ_SJ_Delay)
  726. {
  727. TBJ_SJ_FJ_Step = 3;
  728. TBJ_FJ_VAVLE = 1; //分胶阀输出
  729. //TBJ_JJ_VAVLE = 1; //夹胶阀输出
  730. TBJ_JJ_VAVLE = 0; //2024-0903
  731. TBJ_FJ_Delay = dwTickCount + 1; //分胶阀输出时间
  732. TBJ_SJ_ErrorTime = dwTickCount + ERRORTIME; //分胶阀输出容错时间
  733. }
  734. break;
  735. case 3:
  736. if (TBJ_FJ_LIMIT_IN )
  737. {
  738. TBJ_SJ_FJ_Step = 4;
  739. TBJ_SJ_VAVLE = 1; //送胶输出
  740. TBJ_SJ_ErrorTime = dwTickCount + ERRORTIME;
  741. TBJ_FJ_Delay = dwTickCount + TBJ_PARAM_SJ_TIME;
  742. }
  743. else if (dwTickCount > TBJ_SJ_ErrorTime)
  744. {
  745. TBJ_SetAlarmCode(10); //E10 分胶未到位或 X12分胶前感应异常,无法送胶
  746. }
  747. break;
  748. case 4:
  749. TBJ_SJ_FJ_Step = 5;
  750. /*
  751. if ((TBJ_PARAM_SGZSelect || (TBJ_Motor_Step == 0)) && (dwTickCount >= TBJ_SJ_Delay))
  752. {
  753. if (TBJ_FJ_LIMIT_IN && TBJ_FJ_VAVLE)
  754. {
  755. TBJ_SJ_FJ_Step = 5;
  756. TBJ_SJ_VAVLE = 1; //送胶输出
  757. TBJ_SJ_ErrorTime = dwTickCount + ERRORTIME;
  758. TBJ_FJ_Delay = dwTickCount + TBJ_PARAM_SJ_TIME;
  759. }
  760. else if (dwTickCount > TBJ_SJ_ErrorTime)
  761. {
  762. TBJ_SetAlarmCode(10); //E10 分胶未到位或 X12分胶前感应异常,无法送胶
  763. }
  764. }*/
  765. break;
  766. case 5:
  767. if (TBJ_SJ_LIMIT_IN_UP || (TBJ_PARAM_SongJiaoMode && (dwTickCount > TBJ_FJ_Delay)))
  768. {
  769. TBJ_SJ_FJ_Step = 6;
  770. TBJ_FJ_Delay = dwTickCount + 20;
  771. }
  772. else if (dwTickCount > TBJ_SJ_ErrorTime)
  773. {
  774. TBJ_SetAlarmCode(4); //E04 送胶不到位或 X07送胶前感应异常
  775. }
  776. break;
  777. case 6:
  778. if ((dwTickCount >= TBJ_FJ_Delay) && (!X_DRV || TBJ_GUO_LIAN_IN_UP))
  779. {
  780. TBJ_SJ_FJ_Step = 7;
  781. TBJ_QJ_Step=1;
  782. TBJ_FJ_VAVLE = 0; //关分胶
  783. //TBJ_JJ_VAVLE = 0; //关夹胶
  784. TBJ_JJ_VAVLE=1;//2024-0903
  785. TBJ_FJ_Delay = dwTickCount + 10;
  786. TBJ_SJ_ErrorTime = dwTickCount + ERRORTIME;
  787. }
  788. break;
  789. case 7:
  790. if (!TBJ_FJ_LIMIT_IN && (dwTickCount >= TBJ_FJ_Delay) )
  791. {
  792. TBJ_SJ_FJ_Step = 8;
  793. if (TBJ_PARAM_SongJiaoMode == 0)TBJ_SJ_VAVLE = 0; //气缸送胶先退,滚轮送胶先不退或是触摸屏手动退送胶
  794. TBJ_SJ_ErrorTime = dwTickCount + ERRORTIME;
  795. }
  796. else if (dwTickCount >= TBJ_SJ_ErrorTime)
  797. {
  798. TBJ_SetAlarmCode(6); //E06 退分胶不到位警告或 X13分胶后感应异常
  799. }
  800. break;
  801. case 8:
  802. if ((TBJ_PARAM_SongJiaoMode)||(!TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN))
  803. {
  804. TBJ_SJ_FJ_Step = 0;
  805. TBJ_JJ_VAVLE=0;//2024-0903
  806. }
  807. else if (dwTickCount >= TBJ_SJ_ErrorTime)
  808. {
  809. TBJ_SetAlarmCode(5); //E05 退胶不到位警告 或 X16、X17送胶前后感应异常
  810. }
  811. break;
  812. //手动送胶
  813. case 20://手动送胶
  814. TBJ_JJ_VAVLE = 0; //压胶阀输出
  815. TBJ_SJ_Delay = dwTickCount + 70; //延迟70ms输出送胶阀
  816. TBJ_SJ_FJ_Step = 21;
  817. break;
  818. case 21:
  819. if (dwTickCount >= TBJ_SJ_Delay)
  820. {
  821. TBJ_SJ_VAVLE = 1; //压胶阀输出
  822. TBJ_SJ_FJ_Step = 22;
  823. }
  824. break;
  825. case 22:
  826. if (TBJ_SJ_LIMIT_IN)
  827. {
  828. //TBJ_JJ_VAVLE = 1; //压胶阀输出
  829. TBJ_SJ_FJ_Step = 23;
  830. TBJ_FJ_Delay = dwTickCount + 100;
  831. }
  832. break;
  833. case 23:
  834. if (dwTickCount>=TBJ_FJ_Delay)
  835. {
  836. TBJ_JJ_VAVLE = 1; //压胶阀输出
  837. TBJ_SJ_FJ_Step = 0;
  838. TBJ_FJ_Delay = dwTickCount + 50;
  839. }
  840. break;
  841. case 25://手动退送胶
  842. TBJ_JJ_VAVLE = 1; //压胶阀输出
  843. TBJ_SJ_Delay = dwTickCount + 50; //延迟120ms退回送胶阀
  844. TBJ_SJ_FJ_Step = 26;
  845. break;
  846. case 26:
  847. if (dwTickCount >= TBJ_SJ_Delay)
  848. {
  849. TBJ_SJ_VAVLE = 0; //压胶阀输出
  850. TBJ_SJ_FJ_Step = 27;
  851. TBJ_QJ_Step=1;
  852. }
  853. break;
  854. case 27:
  855. if (TBJ_SJ_ORIGIN_IN)
  856. {
  857. //判断是否使用切胶
  858. //TBJ_YD_VAVLE = 0; //压胶阀输出
  859. //TBJ_SJ_FJ_Step = 0;
  860. //TBJ_QJ_Step=1;
  861. TBJ_SJ_FJ_Step = 28;
  862. TBJ_SJ_Delay = dwTickCount + 50; //延迟120ms退回送胶阀
  863. }
  864. break;
  865. case 28:
  866. if (TBJ_QJ_Step==0&& (dwTickCount >= TBJ_SJ_Delay))
  867. {
  868. TBJ_JJ_VAVLE = 0;
  869. TBJ_SJ_FJ_Step = 0;
  870. }
  871. break;
  872. }
  873. #endif
  874. }
  875. //切胶处理
  876. void TBJ_QieJiao_Proc(void)
  877. {
  878. switch (TBJ_QJ_Step)
  879. {
  880. case 1:
  881. if(TBJ_SJ_ORIGIN_IN)
  882. {
  883. TBJ_QJ_Step=2;
  884. TBJ_QJ_VAVLE=1;
  885. TBJ_QieJiao_Delay=dwTickCount+ERRORTIME;
  886. }
  887. break;
  888. case 2:
  889. if(TBJ_QJ_LIMIT_IN)
  890. {
  891. TBJ_QJ_Step=3;
  892. TBJ_QJCQ_Start();
  893. TBJ_QieJiao_Delay=dwTickCount+10;
  894. }
  895. else if(dwTickCount>=TBJ_QieJiao_Delay)
  896. {
  897. TBJ_SetAlarmCode(TBJ_QJLIMIT_ALARM); //E15 切胶到位异常,检查X11
  898. }
  899. break;
  900. case 3:
  901. TBJ_QJ_Step=0;
  902. TBJ_QJ_VAVLE=0;
  903. break;
  904. }
  905. }
  906. //合模超声动作
  907. void TBJ_ChaoShengHeMo(void)
  908. {
  909. #if 1
  910. unsigned short cs_time;
  911. switch (TBJ_HMCS_Step)
  912. {
  913. case 0:
  914. break;
  915. case 1:
  916. if (!TBJ_FJ_VAVLE && (!TBJ_SJ_VAVLE || TBJ_PARAM_SongJiaoMode) //输出阀判断
  917. && !TBJ_FJ_LIMIT_IN && TBJ_FJ_ORIGIN_IN //分胶阀位置判断
  918. && (!TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN || (TBJ_PARAM_SongJiaoMode == 1)) //送胶阀位置判断
  919. && (TBJ_PARAM_SGZSelect || ((TBJ_PARAM_SGZSelect == 0) &&!TBJ_GZ_LIMIT_IN))) //钩针阀判断
  920. {
  921. TBJ_SM_VAVLE = 1; // 下冲
  922. TBJ_SFHM_Step=1;
  923. if ((TBJ_PARAM_XiaMo_Mode == 0) && (TBJ_PARAM_SGZSelect != 0))
  924. TBJ_XM_VAVLE = 1;
  925. TBJ_HMCS_Step = 2;
  926. TBJ_SM_ErrorTime = dwTickCount + (unsigned long)ERRORTIME; //上模下冲容错时间
  927. }
  928. else if (!TBJ_bRunning)
  929. TBJ_HMCS_Step = 0;
  930. break;
  931. case 2:
  932. if (TBJ_SM_LIMIT_IN && ((TBJ_PARAM_SGZSelect || ((TBJ_PARAM_SGZSelect == 0) &&!TBJ_GZ_LIMIT_IN)) || TBJ_PARAM_XiaMo_Mode)) //1 下模不动
  933. {
  934. TBJ_CS_Delay = dwTickCount + TBJ_PARAM_CS_DELAY; //延时超声
  935. TBJ_HMCS_Step = 3;
  936. if (TBJ_PARAM_TuiGouZhen_Mode == 1) //0 先超声后下勾针,1 先下勾针后超声
  937. TBJ_GZ_VAVLE = 0;
  938. }
  939. else if ((dwTickCount >= TBJ_SM_ErrorTime) && !TBJ_SM_LIMIT_IN)
  940. {
  941. TBJ_SetAlarmCode(26); //E26 超声停止,合模不到位或 X03下冲到位感应异常
  942. }
  943. else if ((dwTickCount >= TBJ_SM_ErrorTime) && (TBJ_GZ_LIMIT_IN))
  944. {
  945. TBJ_SetAlarmCode(27); //E27 超声停止,钩针不到位或 TBJ_GZ_ORIGIN_IN钩针复位感应异常
  946. }
  947. break;
  948. case 3:
  949. if (dwTickCount >= TBJ_CS_Delay)
  950. {
  951. TBJ_bCS = 0;
  952. TBJ_CS_OUT = 1; //超声打开
  953. cs_time = TBJ_Choose_CSTime();
  954. if (cs_time > 1500)
  955. cs_time = 1500; //超声时间上限为1.5 S
  956. TBJ_CS_Delay = dwTickCount + cs_time;
  957. TBJ_HMCS_Step = 4;
  958. }
  959. TBJ_SJ_VAVLE = 0;
  960. break;
  961. case 4:
  962. if (dwTickCount >= TBJ_CS_Delay)
  963. {
  964. TBJ_HMCS_Step = 5;
  965. TBJ_CS_OUT = 0;
  966. TBJ_CS_Delay = dwTickCount + (TBJ_Choose_COLDTime() / 3); //固化一半时间
  967. }
  968. break;
  969. case 5:
  970. if (dwTickCount >= TBJ_CS_Delay)
  971. {
  972. TBJ_HMCS_Step = 6;
  973. TBJ_ChuiQi();
  974. TBJ_GZ_VAVLE = 0;
  975. TBJ_CS_Delay = dwTickCount + (TBJ_Choose_COLDTime()*2 / 3);
  976. }
  977. break;
  978. case 6:
  979. if (dwTickCount >= TBJ_CS_Delay)
  980. {
  981. if (TBJ_PARAM_HONGWAI_GanYin != 0)
  982. {
  983. //重新算温度
  984. cs_time = user_datas[55];
  985. if (user_datas[39] == 0)
  986. user_datas[39] = 1;
  987. //测温值 降时间阀值
  988. if ((cs_time >= user_datas[37]) && (cs_time >= user_datas[58]))
  989. {
  990. cs_time = (cs_time - user_datas[58]) / user_datas[39];
  991. cs_time *= user_datas[38];
  992. if (cs_time > 3)
  993. cs_time = 3;
  994. if ((user_datas[59] + cs_time) < 4)
  995. user_datas[59] += cs_time;
  996. else if (user_datas[59] < 4)
  997. {
  998. cs_time = 3 - user_datas[59];
  999. user_datas[59] = 3;
  1000. }
  1001. else
  1002. cs_time = 0;
  1003. }
  1004. else
  1005. cs_time = 0;
  1006. user_datas[57] = TBJ_Choose_CSTime();
  1007. user_datas[57] -= cs_time;
  1008. TBJ_ResetCsTime();
  1009. }
  1010. user_datas[56] = user_datas[55];
  1011. if (user_datas[56] > user_datas[58])
  1012. user_datas[58] = user_datas[55];
  1013. TBJ_SM_VAVLE = 0;
  1014. TBJ_XM_VAVLE = 0;
  1015. TBJ_HMCS_Step = 0;
  1016. TBJ_CS_Delay = dwTickCount + 350;
  1017. }
  1018. break;
  1019. }
  1020. #endif
  1021. }
  1022. //合模超声动作,伺服合模
  1023. void TBJ_ChaoShengHeMo_SF(void)
  1024. {
  1025. #if 1
  1026. unsigned short cs_time;
  1027. static unsigned char JLXL_flag=0,JLXL_flag1=0;
  1028. switch (TBJ_HMCS_Step)
  1029. {
  1030. case 0:
  1031. break;
  1032. case 1://走位置
  1033. if (!TBJ_FJ_VAVLE && (!TBJ_SJ_VAVLE || TBJ_PARAM_SongJiaoMode) //输出阀判断
  1034. && !TBJ_FJ_LIMIT_IN && TBJ_FJ_ORIGIN_IN //分胶阀位置判断
  1035. && (!TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN || (TBJ_PARAM_SongJiaoMode == 1)) //送胶阀位置判断
  1036. ) //钩针阀判断
  1037. {
  1038. if(TBJ_PARAM_TuiGouZhen_Mode)//先下钩针
  1039. {
  1040. TBJ_GZ_VAVLE=0;
  1041. TBJ_CS_Delay = dwTickCount + TBJ_PARAM_GZREBACK_TIME;
  1042. TBJ_HMCS_Step = 2;
  1043. }
  1044. else//先超声
  1045. {
  1046. TBJ_HMCS_Step = 3;
  1047. TBJ_CS_Delay = dwTickCount + 0;
  1048. }
  1049. }
  1050. else if (!TBJ_bRunning)
  1051. TBJ_HMCS_Step = 0;
  1052. break;
  1053. case 2://转扭矩
  1054. if(dwTickCount>=TBJ_CS_Delay)
  1055. {
  1056. TBJ_DZ_VAVLE=0;
  1057. TBJ_HMCS_Step = 3;
  1058. TBJ_CS_Delay = dwTickCount+10;
  1059. }
  1060. break;
  1061. case 3://转扭矩
  1062. if(dwTickCount>=TBJ_CS_Delay)
  1063. {
  1064. if(TBJ_PARAM_SFXC_MODE&&TEST1<1) //自适应模式第一条走扭矩
  1065. {
  1066. TBJ_LENTH=100-dwYRealPos;
  1067. AxisMovePosAccDec(Y_AXIS, TBJ_PARAM_Y_HIGH_SPEED, TBJ_LENTH, 1000,
  1068. 1000, 20, 20, 10);
  1069. }
  1070. else
  1071. {
  1072. TBJ_LENTH=TBJ_PARAM_Y_Work_Local-dwYRealPos;
  1073. AxisMovePosAccDec(Y_AXIS, TBJ_PARAM_Y_HIGH_SPEED, TBJ_LENTH, 1000,
  1074. 1000, 20, 20, 10);
  1075. }
  1076. TBJ_HMCS_Step = 4;
  1077. }
  1078. break;
  1079. case 4://转扭矩
  1080. if (!Y_DRV)
  1081. {
  1082. TBJ_HMCS_Step = 5;
  1083. Set_Ctrlmode_trans(Y_AXIS,TARR_MODE);
  1084. TBJ_CS_Delay = dwTickCount + 10;
  1085. if (TBJ_PARAM_TuiGouZhen_Mode == 1)TBJ_GZ_VAVLE = 0;//0 先超声后下勾针,1 先下勾针后超声
  1086. }
  1087. break;
  1088. case 5://扭矩到达
  1089. if (!GetTarr(Y_AXIS))
  1090. {
  1091. if(dwTickCount >= TBJ_CS_Delay)
  1092. {
  1093. TBJ_HMCS_Step = 6;
  1094. TBJ_CS_Delay = dwTickCount + 10;
  1095. }
  1096. }
  1097. else
  1098. {
  1099. TBJ_CS_Delay = dwTickCount + 10;
  1100. }
  1101. break;
  1102. case 6://扭矩到达并维持10ms
  1103. if (!GetTarr(Y_AXIS)&&(dwTickCount >= TBJ_CS_Delay))
  1104. {
  1105. //获取Y轴位置
  1106. if(TBJ_PARAM_SFXC_MODE&&TEST1<1)
  1107. TBJ_CS_Delay = dwTickCount + 200; //延时超声
  1108. else
  1109. TBJ_CS_Delay = dwTickCount + TBJ_PARAM_CS_DELAY; //延时超声
  1110. TBJ_HMCS_Step = 7;
  1111. }
  1112. break;
  1113. case 7:
  1114. if (dwTickCount >= TBJ_CS_Delay)
  1115. {
  1116. TBJ_CS_Y_Local=dwYRealPos_com;
  1117. if(TEST1<=1)TBJ_FIRST_CS_Y_LOCAL=dwYRealPos_com;
  1118. if(abs(TBJ_FIRST_CS_Y_LOCAL-TBJ_CS_Y_Local)<=3)
  1119. {
  1120. TBJ_bCS = 0;
  1121. TBJ_CS_OUT = 1; //超声打开
  1122. cs_time = TBJ_Choose_CSTime();
  1123. if (cs_time > 1500)
  1124. cs_time = 1500; //超声时间上限为1.5 S
  1125. TBJ_CS_Delay = dwTickCount + cs_time;
  1126. if(TBJ_PARAM_CS_MODE)
  1127. TBJ_HeMo_JLXL_Delay=dwTickCount+TBJ_PARAM_JL_BD_DELAY;
  1128. else
  1129. TBJ_HeMo_JLXL_Delay=dwTickCount+TBJ_PARAM_JL_TM_DELAY;
  1130. JLXL_flag=1;
  1131. TBJ_HMCS_Step = 8;
  1132. }
  1133. else
  1134. {
  1135. TBJ_HMCS_Step = 10;
  1136. TBJ_CS_Delay = dwTickCount + 100;
  1137. }
  1138. }
  1139. break;
  1140. case 8:
  1141. if(dwTickCount>=TBJ_HeMo_JLXL_Delay&&JLXL_flag)
  1142. {
  1143. JLXL_flag=0;
  1144. JLXL_flag1=1;
  1145. if(TBJ_PARAM_CS_MODE)TBJ_NJ_SEL=SERVO_PARAM_TRARR_BD_LIMITMAX;
  1146. else TBJ_NJ_SEL=SERVO_PARAM_TRARR_TM_LIMITMAX;
  1147. set_servo_postotarr_limit(Y_AXIS,TBJ_NJ_SEL,TBJ_PARAM_Y_LOW_SPEED,TBJ_PARAM_Y_LOW_SPEED,SERVO_TARR_CW);
  1148. if(TBJ_PARAM_CS_MODE)
  1149. TBJ_HeMo_JLXL_Delay=dwTickCount+TBJ_PARAM_XL_BD_DELAY;
  1150. else
  1151. TBJ_HeMo_JLXL_Delay=dwTickCount+TBJ_PARAM_XL_TM_DELAY;
  1152. }
  1153. if(dwTickCount>=TBJ_HeMo_JLXL_Delay&&JLXL_flag1)
  1154. {
  1155. JLXL_flag1=0;
  1156. if(TBJ_PARAM_CS_MODE)TBJ_NJ_SEL=SERVO_PARAM_TRARR_BD_LIMITMIN;
  1157. else TBJ_NJ_SEL=SERVO_PARAM_TRARR_TM_LIMITMIN;
  1158. set_servo_postotarr_limit(Y_AXIS,TBJ_NJ_SEL,TBJ_PARAM_Y_LOW_SPEED,TBJ_PARAM_Y_LOW_SPEED,SERVO_TARR_CW);
  1159. }
  1160. if (dwTickCount >= TBJ_CS_Delay)
  1161. {
  1162. TBJ_HMCS_Step = 9;
  1163. TBJ_GH_Y_Local=dwYRealPos_com;
  1164. TBJ_CS_OUT = 0;
  1165. TBJ_CS_Delay = dwTickCount + (TBJ_Choose_COLDTime() / 3); //固化一半时间
  1166. if(JLXL_flag)
  1167. {
  1168. if(TBJ_PARAM_CS_MODE)TBJ_NJ_SEL=SERVO_PARAM_TRARR_BD_LIMITMAX;
  1169. else TBJ_NJ_SEL=SERVO_PARAM_TRARR_TM_LIMITMAX;
  1170. set_servo_postotarr_limit(Y_AXIS,TBJ_NJ_SEL,TBJ_PARAM_Y_LOW_SPEED,TBJ_PARAM_Y_LOW_SPEED,SERVO_TARR_CW);
  1171. if(TBJ_PARAM_CS_MODE)
  1172. TBJ_HeMo_JLXL_Delay=dwTickCount+TBJ_PARAM_XL_BD_DELAY;
  1173. else
  1174. TBJ_HeMo_JLXL_Delay=dwTickCount+TBJ_PARAM_XL_TM_DELAY;
  1175. JLXL_flag1=1;
  1176. }
  1177. }
  1178. break;
  1179. case 9:
  1180. if(dwTickCount>=TBJ_HeMo_JLXL_Delay&&JLXL_flag1)
  1181. {
  1182. JLXL_flag1=0;
  1183. if(TBJ_PARAM_CS_MODE)TBJ_NJ_SEL=SERVO_PARAM_TRARR_BD_LIMITMIN;
  1184. else TBJ_NJ_SEL=SERVO_PARAM_TRARR_TM_LIMITMIN;
  1185. set_servo_postotarr_limit(Y_AXIS,TBJ_NJ_SEL,TBJ_PARAM_Y_LOW_SPEED,TBJ_PARAM_Y_LOW_SPEED,SERVO_TARR_CW);
  1186. }
  1187. if (dwTickCount >= TBJ_CS_Delay)
  1188. {
  1189. TBJ_HMCS_Step = 10;
  1190. TBJ_ChuiQi();
  1191. TBJ_GZ_VAVLE = 0;
  1192. TBJ_CS_Delay = dwTickCount + (TBJ_Choose_COLDTime()*2 / 3);
  1193. }
  1194. break;
  1195. case 10:
  1196. if(dwTickCount>=TBJ_HeMo_JLXL_Delay&&JLXL_flag1)
  1197. {
  1198. JLXL_flag1=0;
  1199. if(TBJ_PARAM_CS_MODE)TBJ_NJ_SEL=SERVO_PARAM_TRARR_BD_LIMITMIN;
  1200. else TBJ_NJ_SEL=SERVO_PARAM_TRARR_TM_LIMITMIN;
  1201. set_servo_postotarr_limit(Y_AXIS,TBJ_NJ_SEL,TBJ_PARAM_Y_LOW_SPEED,TBJ_PARAM_Y_LOW_SPEED,SERVO_TARR_CW);
  1202. }
  1203. if (dwTickCount >= TBJ_CS_Delay)
  1204. {
  1205. TBJ_XM_VAVLE = 0;
  1206. TBJ_HMCS_Step = 11;
  1207. SetPos(Y_AXIS,dwYRealPos_com);
  1208. Set_Ctrlmode_trans(Y_AXIS,POS_MODE);
  1209. TBJ_XC_CS_LOCAL=dwYRealPos_com;
  1210. if(TEST1<1)
  1211. {
  1212. TBJ_PARAM_Y_Work_Local= dwYRealPos_com-25;
  1213. TBJ_PARAM_Y_SOFT_PLIMIT=dwYRealPos_com-15;
  1214. AxisEnableSoftwarelmt(Y_AXIS,TBJ_PARAM_Y_SOFT_PLIMIT,0);
  1215. }
  1216. TBJ_CS_Delay = dwTickCount + 10;
  1217. }
  1218. break;
  1219. case 11:
  1220. if (dwTickCount >= TBJ_CS_Delay)
  1221. {
  1222. TBJ_LENTH=dwYRealPos-0;
  1223. TBJ_CS_Delay = dwTickCount+1500;
  1224. AxisMovePosAccDec(Y_AXIS, TBJ_PARAM_Y_HIGH_SPEED, -TBJ_LENTH, 1000,
  1225. 1000, 20, 20, 10);
  1226. TBJ_HMCS_Step = 12;
  1227. }
  1228. break;
  1229. case 12:
  1230. if (TBJ_Y_ORIGIN_IN)
  1231. {
  1232. TBJ_GZ_VAVLE=0;
  1233. TBJ_YD_VAVLE=0;
  1234. TBJ_DZ_VAVLE=0;
  1235. TBJ_HMCS_Step = 0;
  1236. TBJ_bSC_FLAG=0;
  1237. }
  1238. else if(dwTickCount >= TBJ_CS_Delay)
  1239. {
  1240. TBJ_SetAlarmCode(TBJ_NO_YORIGIN_ALARM);//E19 超声结束后伺服未复位到原点
  1241. }
  1242. break;
  1243. }
  1244. #endif
  1245. }
  1246. //启动停止故障停止动作
  1247. void TBJ_StartStopAction(void)
  1248. {
  1249. #if 1
  1250. //告警灯
  1251. if(GetAlarmCode(TBJ_ALARM_ADDR)==0)
  1252. {
  1253. TBJ_LED_R_OUT=0;
  1254. TBJ_LED_Y_OUT=0;
  1255. TBJ_LED_G_OUT=0;
  1256. if(TBJ_bRunning)TBJ_LED_G_OUT=1;
  1257. else TBJ_LED_Y_OUT=1;
  1258. }
  1259. else
  1260. {
  1261. TBJ_LED_R_OUT=1;
  1262. TBJ_LED_Y_OUT=0;
  1263. TBJ_LED_G_OUT=0;
  1264. }
  1265. //卡带感应
  1266. if(TBJ_KADAI_IN)
  1267. {
  1268. TBJ_SetAlarmCode(TBJ_KADAI_ALARM);
  1269. }
  1270. else
  1271. {
  1272. if(GetAlarmCode(TBJ_ALARM_ADDR) == TBJ_KADAI_ALARM)SetAlarmCode(TBJ_ALARM_ADDR,0);
  1273. }
  1274. if(GetAlarm(Y_AXIS)==1)
  1275. {
  1276. TBJ_SetAlarmCode(TBJ_SERVO_ALARM);
  1277. }
  1278. else
  1279. {
  1280. if(GetAlarmCode(TBJ_ALARM_ADDR) == TBJ_SERVO_ALARM)SetAlarmCode(TBJ_ALARM_ADDR,0);
  1281. }
  1282. if ((TBJ_START_IN_UP || TBJ_bStart||TBJ_bSingle||TBJ_HandWork) && !TBJ_bRunning && (TBJ_Auto_Step == 0))
  1283. {
  1284. if (GetTotal(TBJ_TOTAL_ADDR) >= TBJ_SET_TOTAL)
  1285. TBJ_SetAlarmCode(TBJ_TOTAL_ALARM);
  1286. else if(!(GetServoComState(Y_AXIS)))
  1287. TBJ_SetAlarmCode(TBJ_SERVO_COM_ALARM);
  1288. else
  1289. {
  1290. if(TBJ_XC_Reset_flag||!TBJ_Y_ORIGIN_IN)
  1291. {
  1292. TBJ_bXCRest=0;
  1293. TBJ_bXCResting=1;
  1294. TBJ_XC_RstStep=1;
  1295. SetEn(Y_AXIS, TBJ_MOTOR_EN);
  1296. Set_Ctrlmode_trans(Y_AXIS,POS_MODE);
  1297. set_servo_postotarr_limit(Y_AXIS,SERVO_PARAM_TRARR_BD_LIMITMIN,
  1298. TBJ_PARAM_SFZSY_SPEED,TBJ_PARAM_SFZSY_SPEED,SERVO_TARR_CW);
  1299. }
  1300. SetEn(X_AXIS, TBJ_MOTOR_EN);
  1301. TBJ_Auto_Delay = dwTickCount + 100;
  1302. TBJ_Auto_Step = 1;
  1303. TBJ_bRunning = 1;
  1304. TBJ_Auto_Delay = 0;
  1305. TBJ_PARAM_SQJCOUNT=0;
  1306. TBJ_PARAM_XQJCOUNT=0;
  1307. TBJ_SD_VAVLE=1;
  1308. TBJ_GZ_VAVLE = 0;//钩针
  1309. TBJ_FJ_VAVLE = 0; //分胶
  1310. TBJ_DZ_VAVLE=0;//顶针
  1311. TBJ_SJ_VAVLE=0;//送胶
  1312. TBJ_YD_VAVLE=0;
  1313. if(TBJ_bSingle)TBJ_bSingleOne=1;
  1314. if(TBJ_HandWork)
  1315. {
  1316. TBJ_HandWorking=1;
  1317. TBJ_bSingleOne=1;
  1318. }
  1319. }
  1320. TBJ_HandWork=0;
  1321. TBJ_bStart = 0;
  1322. TBJ_bSingle=0;
  1323. TBJ_bSC_FLAG=0;
  1324. TBJ_LLPL_flag=0;
  1325. }
  1326. if (TBJ_STOP_IN_UP || TBJ_bStop)
  1327. {
  1328. /*当自动步骤达到4,已完成送胶动作,将本次贴胶动作做完*/
  1329. if (TBJ_bRunning && !TBJ_bSingleOne)
  1330. {
  1331. TBJ_bStop = 0;
  1332. TBJ_bSingleOne = 1;
  1333. }
  1334. else
  1335. {
  1336. TBJ_bStart = 0;
  1337. TBJ_bRunning = 0;
  1338. TBJ_bSingleOne=0;
  1339. TBJ_HandWorking=0;
  1340. TBJ_bAlarmStop = 0;
  1341. TBJ_bStop = 0;
  1342. TBJ_HMCS_Step = 0;
  1343. TBJ_Auto_Step = 0;
  1344. TBJ_SJ_FJ_Step = 0;
  1345. TBJ_Motor_Step = 0;
  1346. TBJ_bXCResting=0;
  1347. TBJ_XC_RstStep=0;
  1348. TBJ_QJ_Step=0;
  1349. TBJ_HeMo_Step=0;
  1350. TBJ_QJ_Step=0;
  1351. AxisEgmStop(X_AXIS); //刹停电机
  1352. SetEn(X_AXIS, TBJ_MOTOR_DISEN); //松轴
  1353. AxisEgmStop(Y_AXIS); //刹停电机
  1354. if(GetAlarm(Y_AXIS)==1)SetClr(Y_AXIS, 1);
  1355. //SetEn(Y_AXIS, TBJ_MOTOR_DISEN); //松轴
  1356. TBJ_GZ_VAVLE = 0; //Y01钩针
  1357. TBJ_FJ_VAVLE = 0; //Y02分胶
  1358. TBJ_SM_VAVLE = 0; //Y03上模(下冲)
  1359. TBJ_CS_OUT = 0; //Y10超声
  1360. TBJ_MOTOR_OUT = 0; //Y11拖带电机
  1361. TBJ_XM_VAVLE = 0; //Y12下模
  1362. TBJ_DZ_VAVLE=0;
  1363. TBJ_YD_VAVLE=0;
  1364. //TBJ_SD_VAVLE=0;
  1365. if (TBJ_PARAM_SHENGJIAO == 1)
  1366. TBJ_STOP_Step = 1; //停机节省布胶动作
  1367. else
  1368. {
  1369. TBJ_JJ_VAVLE = 0; //Y05压带
  1370. TBJ_SJ_VAVLE = 0; //Y04送胶退回
  1371. }
  1372. TBJ_bSC_FLAG=0;
  1373. TBJ_XC_RstStep=0;
  1374. TBJ_bXCResting=0;
  1375. }
  1376. }
  1377. if (TBJ_bAlarmStop)
  1378. {
  1379. TBJ_bAlarmStop = 0;
  1380. AxisEgmStop(X_AXIS);
  1381. TBJ_Auto_Step = 0;
  1382. TBJ_HMCS_Step = 0;
  1383. TBJ_Motor_Step = 0;
  1384. TBJ_SJ_FJ_Step = 0;
  1385. TBJ_bRunning = 0;
  1386. SingOneFlg = 0;
  1387. SetEn(X_AXIS, TBJ_MOTOR_DISEN); //松轴
  1388. }
  1389. #endif
  1390. }
  1391. void TBJ_STOP_Action(void)
  1392. {
  1393. #if 1
  1394. switch (TBJ_STOP_Step)
  1395. {
  1396. case 0:
  1397. break;
  1398. case 1:
  1399. {
  1400. TBJ_JJ_VAVLE = 0;
  1401. TBJ_STOP_Delay = dwTickCount + 50;
  1402. TBJ_STOP_Step = 2;
  1403. }
  1404. break;
  1405. case 2:
  1406. if (dwTickCount >= TBJ_STOP_Delay)
  1407. {
  1408. TBJ_SJ_VAVLE = 0;
  1409. TBJ_STOP_Step = 3;
  1410. }
  1411. break;
  1412. case 3:
  1413. if (TBJ_SJ_ORIGIN_IN)
  1414. {
  1415. TBJ_JJ_VAVLE = 0;
  1416. TBJ_STOP_Step = 0;
  1417. }
  1418. break;
  1419. }
  1420. #endif
  1421. }
  1422. //电机动作
  1423. void TBJ_Motor(void) //
  1424. {
  1425. #if 1
  1426. switch (TBJ_Motor_Step)
  1427. {
  1428. case 0:
  1429. //AxisDecStop(X_AXIS); //上钩针后减速停,保证拉链到位
  1430. break;
  1431. case 1:
  1432. TBJ_Motor_Step = 2;
  1433. SetPos(X_AXIS, 0);
  1434. TBJ_DJ_ErrorTime = dwTickCount + TBJ_PARAM_DJ_AUTO_STOP_TIME; //电机容错时间
  1435. if(TBJ_PARAM_DEC_MODE)
  1436. {
  1437. if (TEST1 > 1 )
  1438. {
  1439. //第三条,开始走数控长度
  1440. AxisMovePosAccDecNotStop(X_AXIS, TBJ_PARAM_HIGH_SPEED, TBJ_SAVE_POS - TNJ_PARAM_TD_LENGTH - 200,
  1441. TBJ_PARAM_MOTOR_START_SPEED, TBJ_PARAM_NULL_SPEED, TBJ_PARAM_MOTOR_ADD, TBJ_PARAM_MOTOR_ADD, 0);
  1442. }
  1443. else
  1444. {
  1445. AxisContinueMoveAcc(X_AXIS, TBJ_PARAM_HIGH_SPEED*2/3, TBJ_DIR_P, TBJ_PARAM_MOTOR_START_SPEED,
  1446. TBJ_PARAM_NULL_SPEED, TBJ_PARAM_MOTOR_ADD, TBJ_PARAM_MOTOR_ADD);
  1447. }
  1448. }
  1449. else
  1450. {
  1451. AxisContinueMoveAcc(X_AXIS, TBJ_PARAM_HIGH_SPEED, TBJ_DIR_P, TBJ_PARAM_MOTOR_START_SPEED,
  1452. TBJ_PARAM_NULL_SPEED, TBJ_PARAM_MOTOR_ADD, TBJ_PARAM_MOTOR_ADD);
  1453. }
  1454. break;
  1455. case 2:
  1456. if (TEST1 > 1 && TBJ_PARAM_DEC_MODE)
  1457. {
  1458. if (!TBJ_GUO_LIAN_IN)
  1459. {
  1460. TBJ_Motor_Step = 3;
  1461. TBJ_Motor_Delay = dwTickCount + 10; //防震时间
  1462. TBJ_DJ_ErrorTime = dwTickCount + ERRORTIME;
  1463. if(dwXRealPos<(TBJ_SAVE_POS - TNJ_PARAM_TD_LENGTH - 600))
  1464. AxisContinueMoveChangeSpeed(X_AXIS,TBJ_PARAM_NULL_SPEED,1000,20,20);
  1465. }
  1466. if ((TBJ_PARAM_LL_PRETECT_LENGTH > 0) && (GetPos(X_AXIS) >= TBJ_SAVE_POS + TBJ_PARAM_LL_PRETECT_LENGTH))
  1467. {
  1468. TBJ_SetAlarmCode(8); //E8 拉链长度异常,超过拉链保护长度
  1469. }
  1470. }
  1471. else
  1472. {
  1473. if (!TBJ_GUO_LIAN_IN )
  1474. {
  1475. TBJ_Motor_Step = 3;
  1476. TBJ_Motor_Delay = dwTickCount + 10; //防震时间
  1477. TBJ_DJ_ErrorTime = dwTickCount + ERRORTIME;
  1478. AxisContinueMoveChangeSpeed(X_AXIS,TBJ_PARAM_NULL_SPEED,1000,20,20);
  1479. }
  1480. }
  1481. if ((dwTickCount > TBJ_DJ_ErrorTime) && (TBJ_PARAM_DJ_AUTO_STOP_TIME ))
  1482. {
  1483. TBJ_SetAlarmCode(24); //E24 拉拉链时间过长,可能由以下原因:①超出保护时间,请检查保护时间是否设置过短②电机是否启动,速度是否过慢③拉链过紧,电机没拉动
  1484. }
  1485. break;
  1486. case 3: //防震
  1487. if (TBJ_GUO_LIAN_IN)
  1488. {
  1489. TBJ_Motor_Step = 2;
  1490. }
  1491. if (dwTickCount >= TBJ_Motor_Delay)
  1492. {
  1493. TBJ_Motor_Step = 4;
  1494. }
  1495. break;
  1496. case 4:
  1497. if (TBJ_GUO_LIAN_IN || (TBJ_TEST_MODE && (dwTickCount > TBJ_TEST_TIME))) //过链上升沿
  1498. {
  1499. if (TBJ_PARAM_TWOTD_SELECT == 0)
  1500. {
  1501. TBJ_Motor_Step = 5;
  1502. TBJ_DJ_ErrorTime = dwTickCount + 5000; //电机容错时间
  1503. AxisMovePosAccDec(X_AXIS, TBJ_PARAM_NULL_SPEED, TNJ_PARAM_TD_LENGTH, TBJ_PARAM_NULL_SPEED,
  1504. 1000, 50, 50, 20); //普通拖带,根据脉冲走一定距离
  1505. TBJ_GZ_Delay = dwTickCount + TBJ_PARAM_GZ_DELAY; //钩针延时输出
  1506. }
  1507. else//二次拖带是,双钩针带缺口,防止撞送带增加的,要等送胶到位后,才能下钩针
  1508. {
  1509. AxisMovePosAccDec(X_AXIS, TBJ_PARAM_NULL_SPEED, TBJ_PARAM_TWOTD_LENGTH, TBJ_PARAM_NULL_SPEED,
  1510. 1000,50, 50, 0); //二次拖带,根据脉冲走不同距离
  1511. TBJ_Motor_Step = 40;
  1512. }
  1513. }
  1514. else if (dwTickCount > TBJ_DJ_ErrorTime) //一直处于空位,没拉链警告
  1515. {
  1516. TBJ_SetAlarmCode(1); //E01 没拉链警告 请检查 X15 过链接近开关
  1517. }
  1518. break;
  1519. case 40:
  1520. if (!X_DRV) //轴停
  1521. {
  1522. TBJ_GZ_VAVLE = 1; //输出钩针
  1523. if (!TBJ_SJ_VAVLE&&TBJ_SJ_LIMIT_IN) //分胶送胶已完成
  1524. {
  1525. TBJ_Motor_Delay = dwTickCount + 10; //二次拖带电机延时输出
  1526. TBJ_Motor_Step = 41;
  1527. }
  1528. }
  1529. break;
  1530. case 41:
  1531. if (dwTickCount > TBJ_Motor_Delay) //二次拖带电机延时已过
  1532. {
  1533. TBJ_Motor_Step = 5;
  1534. TBJ_DJ_ErrorTime = dwTickCount + 500; //电机容错时间
  1535. AxisMovePosAccDec(X_AXIS, TBJ_PARAM_NULL_SPEED, TNJ_PARAM_TD_LENGTH, 1000,
  1536. 1000, 20, 20, 0); //根据脉冲走一定距离
  1537. }
  1538. break;
  1539. case 5:
  1540. if (dwTickCount > TBJ_GZ_Delay)
  1541. {
  1542. TBJ_GZ_VAVLE = 1; //上钩针
  1543. }
  1544. if(TBJ_PARAM_SGZSelect==0)//双钩针模式
  1545. {
  1546. if(TBJ_GZ_LIMIT_IN)
  1547. {
  1548. TBJ_LLPL_flag=0;
  1549. AxisEgmStop(X_AXIS); //急停电机
  1550. TBJ_Motor_Step = 6;
  1551. TBJ_DZ_VAVLE=1;
  1552. TBJ_Motor_Delay = dwTickCount + 10; //延时压带
  1553. if(GetAlarmCode(TBJ_ALARM_ADDR)==TBJ_LLPL_ALARM)
  1554. SetAlarmCode(TBJ_ALARM_ADDR, 0);
  1555. }
  1556. else if (dwTickCount >= TBJ_DJ_ErrorTime)
  1557. {
  1558. if(TEST1<2||TBJ_LLPL_flag)
  1559. {
  1560. TBJ_SetAlarmCode(25); //E25 钩针未到位或 TBJ_TD_LIMIT_IN 钩针到位感应异常警告,电机停止
  1561. }
  1562. else
  1563. {
  1564. TBJ_LLPL_flag++;
  1565. SetAlarmCode(TBJ_ALARM_ADDR, TBJ_LLPL_ALARM);
  1566. }
  1567. }
  1568. }
  1569. else //单钩针模式
  1570. {
  1571. if(!X_DRV)
  1572. {
  1573. TBJ_GZ_VAVLE = 1; //上钩针
  1574. TBJ_Motor_Step = 0; //单钩针方式便完成电机动作
  1575. }
  1576. else if (dwTickCount >= TBJ_DJ_ErrorTime)
  1577. {
  1578. TBJ_SetAlarmCode(25); //E25 钩针未到位或 TBJ_TD_LIMIT_IN 钩针到位感应异常警告,电机停止
  1579. }
  1580. }
  1581. break;
  1582. /*以下为双钩针模式进行*/
  1583. case 6:
  1584. if (dwTickCount > TBJ_Motor_Delay)
  1585. {
  1586. TBJ_Motor_Step = 7;
  1587. TBJ_YD_VAVLE = 1; //压带输出
  1588. TBJ_Motor_Delay = dwTickCount + TBJ_PARAM_YD_TIME; //压带输出延时退勾针
  1589. }
  1590. break;
  1591. case 7:
  1592. if (dwTickCount > TBJ_Motor_Delay) //过了钩针延时
  1593. {
  1594. //TBJ_GZ_VAVLE = 0; //钩针退出
  1595. TBJ_Motor_Step = 0;
  1596. TBJ_DJ_ErrorTime = dwTickCount + ERRORTIME; //钩针退回容错时间
  1597. }
  1598. break;
  1599. case 8:
  1600. if (!TBJ_GZ_LIMIT_IN) //钩针返回原位感应
  1601. {
  1602. TBJ_Motor_Step = 0; //完成双钩针模式
  1603. }
  1604. else if (dwTickCount > TBJ_DJ_ErrorTime) //钩针长时间不退回
  1605. {
  1606. TBJ_SetAlarmCode(2); //E02 退勾针不到位或 TBJ_GZ_ORIGIN_IN 钩针复位感应异常,当前程序处于电机第七步
  1607. }
  1608. break;
  1609. //电机退链
  1610. case 20:
  1611. //SetEn(X_AXIS, TBJ_MOTOR_EN); //锁轴
  1612. //SetPos(X_AXIS, 0); //设当前位置pos为0
  1613. TBJ_Motor_Step = 21;
  1614. TBJ_Motor_Delay = dwTickCount + 5; //电机延时启动,等待锁轴
  1615. if (TBJ_PARAM_DJ_FANZHUAN == 0) //电机如果没有选择反转退链,则关闭该步骤
  1616. TBJ_Motor_Step = 0;
  1617. break;
  1618. case 21:
  1619. if (dwTickCount > TBJ_Motor_Delay) //锁轴完成
  1620. {
  1621. TBJ_Motor_Step = 22;
  1622. AxisMovePosAccDec(X_AXIS, TBJ_PARAM_NULL_SPEED, -TBJ_TUILIAN_LENGTH, TBJ_PARAM_NULL_SPEED,
  1623. TBJ_PARAM_NULL_SPEED, 20, 20, 0); //根据脉冲走一定距离
  1624. }
  1625. break;
  1626. case 22:
  1627. //if (!X_DRV) //电机移动到退链长度
  1628. {
  1629. TBJ_Motor_Step = 0;
  1630. if (TBJ_FJBACKMode)
  1631. TBJ_FJ_VAVLE = 0; //二次拖带退分胶
  1632. }
  1633. break;
  1634. }
  1635. #endif
  1636. }
  1637. int TBJ_QieJiao_Check(void)
  1638. {
  1639. switch(TBJ_PARAM_QJCheck_MODE)
  1640. {
  1641. case 0://不检测
  1642. return 1;
  1643. break;
  1644. case 1://信号检测
  1645. if(TBJ_XQJGY_IN)
  1646. {
  1647. TBJ_SetAlarmCode(TBJ_NoJiao_W);
  1648. return 0;
  1649. }
  1650. else
  1651. {
  1652. return 1;
  1653. }
  1654. break;
  1655. case 2://码盘检测
  1656. if((TEST1>5)&&((TBJ_PARAM_SQJCOUNT<TBJ_PARAM_SET_SQJCOUNT)&&TBJ_PARAM_SET_SQJCOUNT
  1657. ||(TBJ_PARAM_XQJCOUNT<TBJ_PARAM_SET_XQJCOUNT)&&(TBJ_PARAM_SET_XQJCOUNT)))
  1658. {
  1659. if(TBJ_PARAM_SQJCOUNT<TBJ_PARAM_SET_SQJCOUNT)
  1660. TBJ_SetAlarmCode(TBJ_NoSJiao_W); //E63 上胶已用完,请补充胶 或检查X01上胶感应信号
  1661. else
  1662. TBJ_SetAlarmCode(TBJ_NoXJiao_W); //E64 下胶已用完,请补充胶,或检查X00下胶感应信号
  1663. return 0;
  1664. }
  1665. else
  1666. {
  1667. TBJ_PARAM_SQJCOUNT=0;
  1668. TBJ_PARAM_XQJCOUNT=0;
  1669. return 1;
  1670. }
  1671. break;
  1672. }
  1673. return 0;
  1674. }
  1675. //自动运行动作
  1676. void TBJ_AutoRunStep(void)
  1677. {
  1678. #if 1
  1679. if (TBJ_bRunning)
  1680. {
  1681. switch (TBJ_Auto_Step)
  1682. {
  1683. case 0:
  1684. break;
  1685. case 1:
  1686. if(TBJ_Y_ORIGIN_IN&&TBJ_XC_Reset_flag==0&&(dwTickCount > TBJ_Auto_Delay))
  1687. {
  1688. TBJ_Auto_Step = 2;
  1689. TBJ_Auto_Delay = dwTickCount + 1;
  1690. TEST1 = 0; //当前为第一条拉链
  1691. TBJ_SAVE_POS = 0; //用来保存第二条长度,置零
  1692. }
  1693. break;
  1694. case 2: //第一条时
  1695. if (dwTickCount > TBJ_Auto_Delay&&TBJ_Y_ORIGIN_IN)
  1696. {
  1697. if(TBJ_PARAM_CS_MODE)TBJ_NJ_SEL=SERVO_PARAM_TRARR_BD_LIMITMIN;
  1698. else TBJ_NJ_SEL=SERVO_PARAM_TRARR_TM_LIMITMIN;
  1699. set_servo_postotarr_limit(Y_AXIS,TBJ_NJ_SEL,TBJ_PARAM_Y_LOW_SPEED,TBJ_PARAM_Y_LOW_SPEED,SERVO_TARR_CW);
  1700. Set_Ctrlmode_trans(Y_AXIS,POS_MODE);
  1701. if(TBJ_QieJiao_Check())//缺胶检测
  1702. {
  1703. TBJ_Auto_Step = 3;
  1704. TBJ_SJ_FJ_Step = 1; //开始分胶送胶,送胶分胶需电机动作完成后才能完成
  1705. SetPos(X_AXIS, 0);
  1706. if(!TBJ_HandWorking)
  1707. {
  1708. if(TBJ_PARAM_SGZSelect)//单钩针
  1709. {
  1710. if (!TBJ_GZ_VAVLE)TBJ_Motor_Step = 1; //开始电机动作
  1711. else TBJ_SetAlarmCode(QD_GZOut_W); //E18 钩针阀未退回,无法启动
  1712. }
  1713. else//双钩针
  1714. {
  1715. if(!TBJ_GZ_LIMIT_IN)TBJ_Motor_Step = 1; //开始电机动作
  1716. else TBJ_SetAlarmCode(QD_GZOut_W); //E18 钩针阀未退回,无法启动
  1717. }
  1718. }
  1719. }
  1720. }
  1721. break;
  1722. case 3:
  1723. if ((TBJ_SJ_FJ_Step == 0) && (TBJ_Motor_Step == 0))
  1724. {
  1725. TBJ_Auto_Step = 4;
  1726. if (TEST1 == 1) //第二条拉链
  1727. TBJ_SAVE_POS = GetPos(X_AXIS); //保存第二条拉链的长度数据
  1728. if (TBJ_PARAM_DJ_FANZHUAN == 1&&!TBJ_HandWorking)
  1729. TBJ_Motor_Step = 20;
  1730. if(TBJ_HandWorking)
  1731. {
  1732. TBJ_GZ_VAVLE=1;
  1733. }
  1734. TBJ_Auto_Delay = dwTickCount + 1000; //延迟执行超声合模动作
  1735. }
  1736. break;
  1737. case 4:
  1738. if ((!TBJ_FJ_LIMIT_IN && TBJ_FJ_ORIGIN_IN) //分胶没输出 到位没感应 原位有感应 没有分胶阀则不考虑前面条件
  1739. && ((!TBJ_SJ_LIMIT_IN && TBJ_SJ_ORIGIN_IN) || TBJ_PARAM_SongJiaoMode) //送胶没输出 到位没感应 原位有感应 滚轮送胶则不考虑前面条件
  1740. && (TBJ_PARAM_SGZSelect || ((TBJ_PARAM_SGZSelect == 0) &&TBJ_GZ_LIMIT_IN))) //双钩针模式需要考虑钩针退回原位 拖带到位感应不亮 单钩针模式不考虑
  1741. {
  1742. if (TBJ_Motor_Step == 0) //反转完成
  1743. {
  1744. TBJ_Auto_Step = 5;
  1745. TBJ_HMCS_Step = 1; //执行合模超声动作
  1746. }
  1747. }
  1748. else if (dwTickCount >= TBJ_Auto_Delay&&!TBJ_HandWorking)
  1749. {
  1750. if (TBJ_FJ_LIMIT_IN)
  1751. TBJ_SetAlarmCode(29); //E29 自动停止,分胶未退位或分胶前感应异常
  1752. else if (!TBJ_FJ_ORIGIN_IN )
  1753. TBJ_SetAlarmCode(30); //E30 自动停止,分胶未退位或分胶后感应异常
  1754. else if (TBJ_SJ_LIMIT_IN && !TBJ_PARAM_SongJiaoMode)
  1755. TBJ_SetAlarmCode(32); //E32 自动停止,送胶未退位或送胶前感应异常
  1756. else if (!TBJ_SJ_ORIGIN_IN && !TBJ_PARAM_SongJiaoMode)
  1757. TBJ_SetAlarmCode(33); //E33 自动停止,送胶未退位或送胶后感应异常
  1758. else if(!(TBJ_PARAM_SGZSelect || ((TBJ_PARAM_SGZSelect == 0) &&TBJ_GZ_LIMIT_IN)))
  1759. {
  1760. TBJ_SetAlarmCode(QD_GZDaoWei_W); //E03 钩针未退位或 X20 钩针到位感应异常警告,无法启动
  1761. }
  1762. }
  1763. break;
  1764. case 5:
  1765. if (TBJ_HMCS_Step == 0)
  1766. {
  1767. TBJ_Auto_Step = 6;
  1768. TBJ_GZ_VAVLE = 0; //退钩针
  1769. CalProSP(TBJ_SPEED_ADDR); //计算生产速度
  1770. AddToTal(TBJ_TOTAL_ADDR); //产量增加
  1771. }
  1772. break;
  1773. case 6:
  1774. if (TBJ_Y_ORIGIN_IN && //上模已离开
  1775. ((TBJ_PARAM_SGZSelect || ((TBJ_PARAM_SGZSelect == 0) &&!TBJ_GZ_LIMIT_IN)) //双钩针模式,钩针已回到原位,拖带到位感应不亮(该感应需要上钩针配合,不亮代表无钩针配合)
  1776. || ((TBJ_PARAM_XiaMo_Mode == 0) && !TBJ_GZ_LIMIT_IN) //下模不动模式,钩针与上下模位置错开,不相互影响,不需要回到原位
  1777. || ((TBJ_PARAM_XiaMo_Mode == 1) && TBJ_PARAM_SGZSelect))) //下模活动模式,单钩针模式,钩针与上下模位置错开
  1778. {
  1779. TBJ_Auto_Step = 7;
  1780. TBJ_CQ_VAVLE = 1;
  1781. TBJ_CQ_Delay = dwTickCount + 100;
  1782. TBJ_Auto_Delay = dwTickCount + TBJ_PARAM_KAIMO_TD_DELAY + 20; //开模后延时拖带,45为下限时间
  1783. }
  1784. break;
  1785. case 7:
  1786. if (dwTickCount > TBJ_Auto_Delay)
  1787. {
  1788. if (GetTotal(TBJ_TOTAL_ADDR) >= TBJ_SET_TOTAL)
  1789. {
  1790. TBJ_SetAlarmCode(TBJ_TOTAL_ALARM);
  1791. TBJ_Auto_Step = 0;
  1792. TBJ_bRunning = 0;
  1793. TBJ_bSingleOne=0;
  1794. TBJ_HandWorking=0;
  1795. }
  1796. else if(TBJ_bSingleOne||TBJ_HandWorking)
  1797. {
  1798. TBJ_bSingleOne=0;
  1799. TBJ_HandWorking=0;
  1800. TBJ_Auto_Step = 0;
  1801. TBJ_bRunning = 0;
  1802. }
  1803. else
  1804. {
  1805. TBJ_Auto_Step = 2;
  1806. }
  1807. TEST1++;
  1808. if (TEST1 > 10)
  1809. TEST1 = 10;
  1810. }
  1811. break;
  1812. }
  1813. }
  1814. #endif
  1815. }
  1816. #endif