12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235 |
- #include "global.h"
- #if FJ_YING_XING_MACHINE == 1
- //盈兴穿头机
- void ChuanTou_AlarmProtect(void);
- void ChuanTou_ManualAction(void);
- void ChuanTou_AutoAction(void);
- void ChuanTou_StepCheckStart(void);
- void ChuanTou_Motor(void);
- void ChuanTou_SongLiaoAction(void);
- void ChuanTou_HengSongLiao_Action(void); //横送料
- void ChuanTou_ZhuangLiaoStep(void); //装料
- void ChuanTou_HeMo(void); //合模动作
- void ChuanTou_CLT_Step(void); //穿拉头动作
- void ChuanTou_ZhenDongAction(void);
-
- static unsigned char cSongLiaoOk = 0,cMotorDinWei_OK = 0;
- static unsigned char cZhuangLiaoOk = 0;
- static unsigned char cZLCnt = 0;
- unsigned long Zipper_Length = 0;
- void CT_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(CT_ALARM_ADDR,alarm_code);
- bAlarmStop = 1;
- }
- void ChuanTou_InitAction(void)
- {
- float length_buff,pulse_buff;
-
- axis_x->speed_unit = 1; //速度频率倍率单位
- length_buff = CT_PARAM_CYCLE_LENGTH;
- pulse_buff = CT_PARAM_CYCLE_PULSE;
-
- XGearRatio = pulse_buff/length_buff;
- YGearRatio = 1;
- SetEn(X_AXIS,CT_MOTOR_DISEN);
- CT_ZhenDongPian_OUT = 1;
- }
- void ChuanTou_Action(void)
- {
- //数据监控
- dwRealPos = GetPos(X_AXIS);
- user_datas[121] = CT_MotorStep;
- user_datas[122] = CT_AutoStep;
- user_datas[123] = dwRealPos;
- user_datas[124] = CT_HeMoStep;
- // user_datas[125] = CT_SL_Step;
- //user_datas[126] = CT_HSL_Step;
- // user_datas[127] = dwZipCnt;
- user_datas[128] = CT_CLT_Step;
-
- ChuanTou_AlarmProtect();
- ChuanTou_StepCheckStart(); // 调用脚踏开关检测程序
- ChuanTou_Motor();
- ChuanTou_ManualAction();
- ChuanTou_AutoAction();
- ChuanTou_ZhenDongAction();
- ChuanTou_SongLiaoAction();
- ChuanTou_HengSongLiao_Action(); //横送料
- ChuanTou_ZhuangLiaoStep(); //装料
- ChuanTou_HeMo(); //合模动作
- ChuanTou_CLT_Step();
- }
- //手动动作
- void ChuanTou_ManualAction(void)
- { static unsigned long CheckTime;
- if(bRunning == 0)
- {
- if(bClearTotal) //切断计数清零
- {
- bClearTotal = 0;
- ClrcToTal(CT_TOTAL_ADDR);
- }
- //手动分带
- if(CT_bFD)
- {
- CT_bFD = 0;
- CT_FenDai_VAVLE = ~CT_FenDai_VAVLE;
- }
- //手动下模
- if(CT_bXM)
- {
- CT_bXM = 0;
- if(CT_XiaMo_VAVLE)
- CT_XiaMo_VAVLE = 0;
- else if(CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE)
- CT_XiaMo_VAVLE = 1;
- else //下模输出条件警告
- {
- SetAlarmCode(CT_ALARM_ADDR,CT_XiaMo_out_ALARM); //横送料在原点才能输出
- }
- }
- if(CT_DZ_IN)
- CT_GouZhen_VAVLE = 1;
- if(CT_GUO_LIAN_IN_UP)
- CT_GouZhen_VAVLE = 0;
- //手动送料
- if(CT_bSL)
- {
- CT_bSL = 0;
- CT_SongLiao_VAVLE = ~CT_SongLiao_VAVLE;
- }
- // 手动合链
- if(CT_bHL)
- {
- CT_bHL = 0;
- CT_HeLian_VAVLE = ~CT_HeLian_VAVLE;
- }
-
- // 手动横送料
- if(CT_bHSL)
- {
- CT_bHSL = 0;
- if(CT_HangSongLiao_VAVLE)
- {
- CT_HangSongLiao_VAVLE = 0;
- } //送料电磁阀 接料电磁阀 下模电磁阀 保证没拉头
- else if(!CT_SongLiao_VAVLE && !CT_JieLiao_VAVLE && !CT_XiaMo_VAVLE && (!CT_MaGou_VAVLE || (CT_MaGou_VAVLE && CT_MG_IN)))
- {
- CT_MaGou_VAVLE = 0;
- CT_HangSongLiao_VAVLE = 1;
- }
- else //警告代码
- {
- if(CT_SongLiao_VAVLE)
- SetAlarmCode(CT_ALARM_ADDR,CT_SongLiao_VAVLE_Not_ALARM); //送料不能有输出
- else if(CT_JieLiao_VAVLE)
- SetAlarmCode(CT_ALARM_ADDR,CT_JieLiao_VAVLE_Not_ALARM); //接料不能有输出
- else if(CT_XiaMo_VAVLE)//下模不能有输出
- SetAlarmCode(CT_ALARM_ADDR,CT_XiaMo_VAVLE_Not_ALARM);
- else //已经有拉头
- SetAlarmCode(CT_ALARM_ADDR,CT_LaTuo_Not_ALARM); //不能有拉头
- }
- }
- //手动接料
- if(CT_bJL)
- {
- CT_bJL = 0;
- if(CT_JieLiao_VAVLE)
- {
- //如果接料输出后,没马勾或横送料已回到原位才能退
- if((!CT_HangSongLiao_VAVLE && CT_HSL_ORIGIN_IN) || !CT_MaGou_VAVLE)
- CT_JieLiao_VAVLE = 0;
- else //退接料警告
- {
- SetAlarmCode(CT_ALARM_ADDR,CT_TuiJieLiao_ALARM); //码勾输出情况下横送料要退回原点
-
- }
- }
- else if(!CT_MaGou_VAVLE || (CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE))
- {
- CT_JieLiao_VAVLE = 1;
- }
- else //接料警告
- {
- SetAlarmCode(CT_ALARM_ADDR,CT_JieLiao_out_ALARM); //码勾没输出或横送料在原点才能输出
-
- }
- }
- if(CT_bGM) //手动勾码
- {
- CT_bGM = 0;
- CT_MaGou_VAVLE = ~CT_MaGou_VAVLE;
- }
- if(CT_bHC) //手动护齿
- {
- CT_bHC = 0;
- CT_HuChi_VAVLE = ~CT_HuChi_VAVLE;
- }
- //手动装料
- if(CT_bZL)
- {
- CT_bZL = 0;
- if(CT_ZL_Step == 0)
- {
- cSongLiaoOk = 1;
- cZhuangLiaoOk = 0;
- CT_ZL_Step = 1;
- }
- }
- //
-
- //手动定位
- if(CT_bMotorDW)
- {
- CT_bMotorDW = 0;
-
- if(CT_MotorStep == 0)
- {
- if(!CT_FenDai_VAVLE)
- {
- CT_HuChi_VAVLE = 0;
- CT_HeLian_VAVLE = 0;
- CT_MotorStep = 1;
- }
- else
- {
- if(CT_FenDai_VAVLE) SetAlarmCode(CT_ALARM_ADDR,CT_FenDai_out_ALARM); //分带输出不能拖带
- //护链输出不能拖带
- }
- }
- }
- //自动装料
- if(CT_bZL)
- {
- CT_bZL = 0;
- if(CT_ZL_Step == 0)
- CT_ZL_Step = 1;
- }
- //合模 (半自动)
- if(CT_bHM)
- {
- CT_bHM = 0;
-
- if(CT_XiaMo_VAVLE && CT_FenDai_VAVLE)
- {
- CT_XiaMo_VAVLE = 0;
- CT_FenDai_VAVLE = 0;
- CT_HeLian_VAVLE = 0;
- CT_HuChi_VAVLE = 0;
- CT_JieLiao_VAVLE = 0;
- CT_MaGou_VAVLE = 0;
- CT_HeMoStep = 0;
- }
- else if(CT_HeMoStep == 0)
- {
- if(CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE)
- {
- CT_HeMoStep = 1;
- CT_MaGou_VAVLE = 1;
- CT_HeMoDelay = dwTickCount +70; //给码勾检测是否有拉头
- }
- else //合模条件不满足
- {
- SetAlarmCode(CT_ALARM_ADDR,CT_XiaMo_out_ALARM); //横送料在原点才能输出
- }
- }
- if(!CT_GUO_LIAN_IN)
- SetAlarmCode(CT_ALARM_ADDR,CT_Guo_Lian_IN_ALARM); //拉链在空位上容易爆链
- }
- //
- if(CT_bMotorH)
- {
- if(!X_DRV)AxisContinueMove(X_AXIS,20,CT_DIR_N);
- }
-
- if((QD_MotorStep == 0) && !CT_bMotorH && (CT_AutoStep == 0))
- {
- if(X_DRV)AxisEgmStop(X_AXIS);
- }
- //振动盘
- if(CT_bZDP)
- {
- CT_bZDP = 0;
- CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_STOP_TIME;
- CT_ZhenDongPian_OUT = 1;
- }
- }
- }
- void ChuanTou_AlarmProtect(void)
- {
- }
- //振动盘控制
- void ChuanTou_ZhenDongAction(void)
- {
- if((CT_bDLP || bRunning) && CT_ZhenDongPian_OUT && CT_PARAM_DALIAOPIAN)
- {
- if(CT_DLP_Time >= dwTickCount)
- {
- CT_ZDP_Delay = dwTickCount + CT_PARAM_DLP_TIME + 40;
- CT_DaLaPian_VAVLE = ~CT_DaLaPian_VAVLE;
- }
- }
- else
- CT_DaLaPian_VAVLE = 0;
-
- #if 1
- // if(bRunning)
- // {
- // if(CT_PARAM_ZDP_MODE)
- // {
- if(CT_ZhenDongPian_OUT == 0)
- {
- if(!CT_ZDP_IN)
- {
- CT_ZhenDongPian_OUT = 1;
- CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_STOP_TIME+ 50;
- }
- else
- {
- CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_START_TIME;
- }
- }
- else
- {
- if(CT_ZDP_IN)
- {
- if((dwTickCount >= CT_ZDP_Delay))
- {
- CT_ZhenDongPian_OUT = 0;
- }
- }
- else
- CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_STOP_TIME+ 50;
- }
- // }
- // else
- // {
- // if(CT_ZDP_IN_DW)CT_ZenDongPian_OUT = 0;
- // if(CT_ZDP_IN_UP)CT_ZenDongPian_OUT = 1;
- // }
- // }
- #if 0
- else
- {
- if(!CT_ZDP_IN && (CT_ZhenDongPian_OUT == 0))
- {
- CT_ZhenDongPian_OUT = 1;
- CT_ZDP_Delay = dwTickCount + CT_PARAM_ZDP_TIME + 20;
- }
-
- if((dwTickCount >= CT_ZDP_Delay) && CT_ZhenDongPian_OUT)
- {
- CT_ZhenDongPian_OUT = 0;
- }
- }
- #endif
- #endif
- }
- //送料
- void ChuanTou_SongLiaoAction(void)
- {
- #if 1
- switch(CT_SL_Step)
- {
- case 1:
- if(cSongLiaoOk)
- {
- CT_SL_Step = 0;
- }
- else
- {
- // if(CT_PARAM_SL_MODE == 0)//横送模式
- // {
- CT_SL_Step = 2;
- CT_SL_Delay = dwTickCount + VAVLE_ALARM_TIME;
- // }
- // else //直送料
- // {
- // ;
- // }
- }
- break;
- case 2:
- {
- //横送料必须保持在原位
- if(CT_HSL_ORIGIN_IN && !CT_HSL_LIMIT_IN && !CT_HangSongLiao_VAVLE)
- {
- CT_SongLiao_VAVLE = 1;
- CT_SL_Delay = dwTickCount + VAVLE_ALARM_TIME;
- CT_SL_Step = 3;
- }
- else if(dwTickCount >= CT_SL_Delay)
- {
- if(!CT_HSL_ORIGIN_IN)CT_SetAlarmCode(CT_HSL_ORIGIN_ALARM);
- else if(CT_HSL_LIMIT_IN)CT_SetAlarmCode(CT_HSL_LIMIT_ALARM);
- else if(!CT_HangSongLiao_VAVLE)CT_SetAlarmCode(CT_HangSongLiao_Out_ALARM);
- }
- }
- break;
- case 3:
- {//送料离开原位
- if(!CT_SL_ORIGIN_IN)
- {
- CT_SL_Step = 4;
- CT_SL_Delay = dwTickCount + CT_PARAM_SL_DELAY_BACK;
- }
- else if(dwTickCount >= CT_SL_Delay)
- {
- CT_SetAlarmCode(CT_SL_ORIGIN_ALARM);
- }
- }break;
- case 4:
- {//送料时间到延时返回
- if(dwTickCount >= CT_SL_Delay)
- {
- CT_SongLiao_VAVLE = 0;
- CT_SL_Delay = dwTickCount + VAVLE_ALARM_TIME;
- CT_SL_Step = 5;
- }
- }break;
- case 5:
- {
- if(CT_SL_ORIGIN_IN)
- {
- cSongLiaoOk = 1;
- CT_SL_Step = 0;
- }
- else if(dwTickCount >= CT_SL_Delay)
- {
- CT_SetAlarmCode(CT_SL_ORIGIN_ALARM);
- }
- }
- break;
- }
- #endif
- }
- //横送料
- void ChuanTou_HengSongLiao_Action(void)
- {
- #if 1
- switch(CT_HSL_Step)
- {
- case 1:
- {//送料,下模,马勾在原位,电磁阀不能有输出
- if(CT_SL_ORIGIN_IN && CT_XM_ORIGIN_IN && !CT_JieLiao_VAVLE && !CT_XiaMo_VAVLE)
- {
- CT_HSL_Step = 2;
-
- CT_MaGou_VAVLE = 0; //马勾自动打开
- CT_JieLiao_VAVLE = 0; //接料也要关掉
- }
- else if(!bRunning)
- {
- CT_HSL_Step = 0;
- }
- }
- break;
- case 2:
- if(CT_SL_Step == 0)
- {
- CT_HangSongLiao_VAVLE = 1;
- CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
- CT_HSL_Step = 3;
- }
- break;
- case 3:
- {
- if(CT_HSL_LIMIT_IN)
- {
- //横送到位延接料,等待拉片稳定
- CT_HSL_Delay = dwTickCount + CT_PARAM_JIELIAO_DELAY;
- CT_HSL_Step = 4;
- }
- else if(dwTickCount >= CT_HSL_Delay) //横送料到位异常
- {
- CT_SetAlarmCode(CT_HSL_LIMIT_ALARM);
- }
- }
- break;
- case 4:
- if(dwTickCount >= CT_HSL_Delay)
- {
- CT_HSL_Step = 5;
- CT_JieLiao_VAVLE = 1; //接料输出上升
- CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
- }
- break;
- case 5:
- {
- if(!CT_XM_ORIGIN_IN)//下模离开后,延时输出马勾
- {
- cSongLiaoOk = 0;
- CT_HSL_Delay = dwTickCount + CT_PARAM_GJ_TIME; //延时码勾输出
- CT_HSL_Step = 6;
- }
- else if(dwTickCount >= CT_HSL_Delay) //下模没法离开,电磁阀没有输出
- {
- CT_HSL_Step = 0;
- CT_SetAlarmCode(CT_XM_ORIGIN_ALARM);
- }
- }
- break;
- case 6:
- if(dwTickCount >= CT_HSL_Delay)
- {
- CT_MaGou_VAVLE = 1;
- CT_HSL_Delay = dwTickCount + CT_PARAM_HSL_BACK_DELAY;
- CT_HSL_Step = 7;
- }
- break;
- case 7:
- if(dwTickCount >= CT_HSL_Delay) //码勾输出后横送料退
- {
- CT_HangSongLiao_VAVLE = 0;
- CT_HSL_Delay = dwTickCount + VAVLE_ALARM_TIME;
- CT_HSL_Step = 8;
- CT_SL_Step = 1;
- }
- break;
- case 8://横送料退回
- if(CT_HSL_ORIGIN_IN && !CT_HSL_LIMIT_IN)
- {
- CT_HSL_Step = 0;
-
-
- }
- else if(dwTickCount >= CT_HSL_Delay)
- {
- CT_SetAlarmCode(CT_HSL_ORIGIN_ALARM);
- }
- break;
- case 9:
-
- break;
- }
- #endif
- }
- //装料
- void ChuanTou_ZhuangLiaoStep(void)
- {
- #if 1
- switch(CT_ZL_Step)
- {
- case 1:
- {
- if(cZhuangLiaoOk || (CT_MaGou_VAVLE && !CT_MG_IN))
- {
- CT_ZL_Step = 0;
- cZhuangLiaoOk = 1;
- }
- else
- {
- CT_ZL_Delay = dwTickCount + VAVLE_ALARM_TIME;
- CT_ZL_Step = 2;
- cZLCnt = 0;
- CT_ZL_Delay = dwTickCount + 60;
- cSongLiaoOk = 1;
- CT_MaGou_VAVLE = 1;
- }
- }
- break;
- case 2:
-
- if((dwTickCount >= CT_ZL_Delay) || CT_MG_IN)
- {
- // if(CT_SL_Step == 0)
- // CT_SL_Step = 1;
- CT_ZL_Step = 3;
- if(CT_MaGou_VAVLE && !CT_MG_IN)
- {
- CT_ZL_Step = 0;
- cZhuangLiaoOk = 1;
- }
- }
- break;
- case 3:
- {
- if(CT_SL_Step == 0)
- {
- CT_ZL_Step = 4;
- CT_HSL_Step = 1;
- }
- }
- break;
- case 4:
- {
- if(CT_HSL_Step == 0)
- {
- CT_ZL_Step = 0;
- cZhuangLiaoOk = 1;
-
- if(CT_MG_IN && CT_MaGou_VAVLE)
- {
- cZhuangLiaoOk = 0;
- CT_MaGou_VAVLE = 0;
- CT_JieLiao_VAVLE = 0;
- CT_ZL_Delay = dwTickCount + 600;
- cZLCnt++;
- if(cZLCnt>= 3)
- {
- CT_ZL_Delay = dwTickCount + 0;
- CT_ZL_Step = 0;
- CT_SetAlarmCode(CT_ZhuangLiao_ALARM);
- }
- else
- CT_ZL_Step = 2;
- }
- }
- }
- break;
-
- default:break;
- }
- #endif
- }
- //合模动作
- void ChuanTou_HeMo(void)
- {
- switch(CT_HeMoStep)
- {
- case 1:
- if(CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE && !CT_HSL_LIMIT_IN && (dwTickCount >= CT_HeMoDelay))
- {
- CT_HeMoStep = 2;
-
- if(CT_MaGou_VAVLE)
- {
- if(CT_MG_IN)
- {
- cZhuangLiaoOk = 0;
- CT_MaGou_VAVLE = 0;
- }
- }
- else
- {
- CT_MaGou_VAVLE = 1;
- }
- CT_ZL_Step = 1;
- CT_HuChi_VAVLE = 1;
-
- if(!bRunning || (dwZipCnt <= 2))
- CT_HeMoDelay = dwTickCount +70; //给码勾检测是否有拉头
- else
- CT_HeMoDelay = dwTickCount +CT_PARAM_FD_DELAY; //延时分带
- if((CT_PARAM_HouMa_MODE != HouMa_MODE_YOUHOUMA)) //有后码时不能有输出
- {
- CT_HeLian_VAVLE = 1;
- if(bRunning)
- CT_HeMoDelay = dwTickCount; //
- }
- CT_ZL_Step = 1;
- }
- break;
- case 2:
- if(dwTickCount >= CT_HeMoDelay)
- {
- CT_HeMoStep = 3;
- CT_FenDai_VAVLE = 1; //
- CT_HeMoDelay = dwTickCount +VAVLE_ALARM_TIME; //延时分带
- if(CT_MG_IN)
- {
- cZhuangLiaoOk = 0;
- CT_MaGou_VAVLE = 0;
- if(CT_ZL_Step == 0)
- CT_ZL_Step = 1;
- }
- }
- break;
- case 3:
- if(CT_FD_IN)
- {
- //装已经完成或在手动情况下
- if(cZhuangLiaoOk && !CT_MG_IN)
- {
- if(CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE && !CT_HSL_LIMIT_IN)
- {
- CT_HeMoStep = 4;
- CT_XiaMo_VAVLE = 1;
- CT_HeMoDelay = dwTickCount + 50; //延时退接料
- }
- }
- else if(CT_MaGou_VAVLE && CT_MG_IN)
- {
- if(CT_ZL_Step == 0)
- {
- CT_MaGou_VAVLE = 0;
- CT_ZL_Step = 2;
- CT_ZL_Delay = dwTickCount + 0;
- }
- }
- }
- else if(dwTickCount >= CT_HeMoDelay)
- {
- if(bRunning)
- {
- CT_SetAlarmCode(CT_FD_IN_ALARM);
- CT_HeMoStep = 0;
- }
- }
- break;
- case 4:
- if(dwTickCount >= CT_HeMoDelay)
- CT_JieLiao_VAVLE = 0;
- //下模离开原点,拉头顶到顶针处,或手动
- if(!CT_XM_ORIGIN_IN && CT_DZ_IN)
- {
- CT_HeMoStep = 5;
- CT_JieLiao_VAVLE = 0;
- CT_GouZhen_VAVLE = 1;
- CT_HeMoDelay = dwTickCount + 20; //退勾针延时拖带
- }
- break;
- case 5:
- if(dwTickCount >= CT_HeMoDelay)
- {
- CT_HeMoStep = 0;
- }
- break;
- }
- }
- void ChuanTou_CLT_Step(void)
- {
- static long xm_buff;
- long ch;
- #if 1
- switch(CT_CLT_Step)
- {
- case 1:
- SetPos(X_AXIS, 0); //开始穿入位为零点
- dwRealPos = GetPos(X_AXIS);
- CT_CLT_Step = 2;
-
- break;
- case 2:
- //两段速度移动距离
- // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
- // AxisMoveTwoPos(X_AXIS,QD_PARAM_CUT_BACK_SPEED,QD_PARAM_SJZ_LENGTH,5000,QD_PARAM_BACK_LENGTH,QD_DIR_P);
- AxisMovePosAccDec(X_AXIS,CT_PARAM_CR_SPEED,CT_PARAM_CR_LENGTH + 230 - CT_PARAM_STOP_LENGTH ,3000,8,12);
- // SetDir(X_AXIS, CT_DIR_P);
- CT_HuChi_VAVLE = 0;
- CT_CLT_Step = 3;
- xm_buff = 0;
- cMotorDinWei_OK = 0;
- break;
- case 3:
- //穿入过程,检测到空位
- if(CT_GUO_LIAN_IN_DW)
- {
- xm_buff = 0;
- CancelPmoveState(X_AXIS);
- AxisChangeSpeed(X_AXIS,CT_PARAM_LSPEED);
- }
- //在上升沿
- if(CT_GUO_LIAN_IN_UP)
- {
- xm_buff = dwRealPos;
- AxisEgmStop(X_AXIS);
- }
- //根据后码模式退合链
- if(CT_PARAM_HouMa_MODE == HouMa_MODE_DANKUAI)
- {
- if(dwRealPos >= CT_PARAM_TUIHELIAN_DELAY)
- CT_HeLian_VAVLE = 0;
- }
- //退分带动作//提前8MM退分带 或退长度到
- if(((dwRealPos + 80) >= CT_PARAM_CR_LENGTH) || (dwRealPos >= CT_PARAM_TUIFENGDAI_DELAY))
- CT_FenDai_VAVLE = 0;
- if((dwRealPos + 35) >= CT_PARAM_CR_LENGTH)
- {
- CT_MaGou_VAVLE = 0;
- }
- if((dwRealPos) >= CT_PARAM_CR_LENGTH)
- {
- AxisEgmStop(X_AXIS);
- }
- //穿入长度到
- if(!X_DRV)
- {//如果无后码单开模式长度过长时也强制打开 //双闭口要先慢速退
- if((CT_PARAM_HouMa_MODE == HouMa_MODE_DANKUAI) ||
- ((CT_PARAM_HouMa_MODE == HouMa_MODE_SHUANGBI) && (CT_PARAM_TUIHELIAN_DELAY == 0)))
- {
- CT_HeLian_VAVLE = 0; //合链关
- }
- CT_FenDai_VAVLE = 0; //分带关
- CT_XiaMo_VAVLE = 0; //下模关
- CT_MaGou_VAVLE = 0; //码勾关
- CT_CLT_Step = 4;
- }
- break;
- case 4:
- if(!CT_DZ_IN)
- {
- CT_CLT_Delay = dwTickCount + CT_PARAM_XM_BACK_DELAY_START;
- CT_CLT_Step = 5;
- }
- break;
- case 5:
- //下模退回
- if(((dwTickCount >= CT_CLT_Delay) || CT_XM_ORIGIN_IN) && !CT_FD_IN)
- {
- CT_ZL_Step = 2; //重装料
- cZLCnt = 0;
- CT_ZL_Delay = dwTickCount + 0;
- CT_MaGou_VAVLE = 0; //码勾输出检测拉头是否脱离模具
- if(xm_buff) //已经检测到拉链
- {
- CT_CLT_Step = 8;
- CT_MotorStep = 50; //只走定位长度步
- }
- else //没有检测到拉链
- {
- if((CT_PARAM_HouMa_MODE == HouMa_MODE_SHUANGBI) && CT_HeLian_VAVLE) //双闭口要先慢速退
- {
- xm_buff = dwRealPos;
- CT_CLT_Step = 6;
-
- ch = 1400;
- SetStartSpeed(X_AXIS,ch);
- if((Zipper_Length > (dwRealPos + 2000)) && (dwZipCnt > 2))
- {
- AxisContinueMove(X_AXIS,(CT_PARAM_HSPEED + CT_PARAM_HSPEED/3),CT_DIR_N); //主要生成高速表
- }
- else
- AxisContinueMove(X_AXIS,(CT_PARAM_HSPEED),CT_DIR_N);//主要生成高速表
- //低速走长度给合链退回争取时间,快转碰拉头,损坏拉链
- AxisChangeSpeed(X_AXIS,ch);
- //也进入过链检测状态
- CT_MotorStep = 3;
- CT_MotorDelay = dwTickCount + 0;
- }
- else
- {
- CT_CLT_Step = 8;
- CT_CLT_Delay = dwTickCount + 0;
- }
- }
- }
- break;
- case 6:
- ch = CT_PARAM_TUIHELIAN_DELAY;
- if(ch > 30) //最长限制1.5CM
- ch = 28;
- // if(dwRealPos >= (xm_buff + ch))
- {
- CT_HeLian_VAVLE = 0;
- CT_CLT_Delay = dwTickCount + 30; //延时时间再加速
- CT_CLT_Step = 7;
- }
- break;
- case 7:
- if(dwTickCount >= CT_CLT_Delay)
- {
- if(CT_MotorStep == 3) //如果电机还在检测拉链状态,就到变速程序
- CT_MotorStep = 40;
-
- CT_CLT_Step = 8;
- }
- break;
- case 8:
- CT_CLT_Step = 0;
- if((CT_MotorStep == 0) && (cMotorDinWei_OK == 0))
- CT_MotorStep = 1;
- break;
- }
- #endif
- }
- void ChuanTou_AutoAction(void)
- {
- if(bRunning)
- {
- #if 1
- switch(CT_AutoStep)
- {
- case 1:
- if(dwTickCount >= CT_AutoDelay)
- {
- CT_AutoStep = 2;
- if(CT_MotorStep == 0)
- {
- CT_MotorStep = 1;
- }
- }
- break;
- case 2:
- if(CT_MotorStep == 0) //电机定位完成
- {
- if(SingOneFlg) //当为单一自动时,装料
- {
- bRunning = 0;
- CT_AutoStep = 0;
- }
- else
- {
- if(dwZipCnt == 2)
- Zipper_Length = dwRealPos;
- CT_AutoStep = 3;
- CT_HeMoStep = 1;
- }
- }
- break;
- case 3:
- if((CT_MotorStep == 0) && (CT_HeMoStep == 0))
- {
- CT_CLT_Step = 1;
- CT_AutoStep = 4;
- }
- break;
- case 4:
- if(CT_CLT_Step >= 3)
- {
- AddToTal(CT_TOTAL_ADDR);
- AddToTal(CT_WORKTOTAL_ADDR);
- CalProSP(CT_PROSPEED_ADDR);
- CT_AutoStep = 5;
-
- }
- break;
- case 5:
- if(CT_CLT_Step == 0)
- {
- dwZipCnt++;
- dwZipCnt &= 7;
- CT_AutoStep = 1;
- CT_AutoDelay = dwTickCount + 0;
- }
- break;
- }
- #endif
- }
- }
- void ChuanTou_StepCheckStart(void)
- {
- // 启动
- if((CT_START_IN_UP) || bStart || CT_bSingle)
- {
- bStart = 0;
- #if 1
- if(!bRunning && (CT_AutoStep == 0))
- {
- if(!CT_HSL_ORIGIN_IN)CT_SetAlarmCode(CT_HSL_ORIGIN_ALARM);
- else if(CT_HSL_LIMIT_IN)CT_SetAlarmCode(CT_HSL_LIMIT_ALARM);
- else if(!CT_SL_ORIGIN_IN)CT_SetAlarmCode(CT_SL_ORIGIN_ALARM);
- {
- bRunning = 1;
- SetEn(X_AXIS,CT_MOTOR_EN);
- CT_AutoStep = 3;
- CT_HeMoStep = 1;
- // if(!cZhuangLiaoOk)
- // CT_ZL_Step = 1;
- SingOneFlg= 0;
- if(CT_bSingle) SingOneFlg= 1;
- dwZipCnt = 0;
- Zipper_Length = 0;
- CT_AutoDelay = dwTickCount + 30;
- CT_HeMoDelay = dwTickCount +70;
- CT_MaGou_VAVLE = 1;
- cZLCnt = 0;
- SetAlarmCode(CT_ALARM_ADDR,0);
- }
- }
- CT_bSingle = 0;
- #endif
- }
- #if 1
- //停止
- if(CT_STOP_IN_UP || bStop)
- {
- bStop = 0;
-
- if(bRunning)
- {
- bRunning = 0;
- CT_AutoStep = 0;
- CT_MotorStep = 0;
-
- CT_AutoDelay = dwTickCount;
- CT_MotorDelay = dwTickCount;
- AxisDecStop(X_AXIS);
- SingOneFlg = 0;
- }
- else
- {
- bRunning = 0;
- CT_AutoStep = 0;
- CT_MotorStep = 0;
- CT_HeMoStep = 0;
- CT_SL_Step = 0;
- CT_HSL_Step = 0;
- CT_ZL_Step = 0;
- CT_CLT_Step = 0;
- CT_ZD_Step = 0;
-
-
- CT_AutoDelay = dwTickCount;
- CT_MotorDelay = dwTickCount;
- CT_HeMoDelay = dwTickCount;
- CT_SL_Delay = dwTickCount;
- CT_HSL_Delay = dwTickCount;
- CT_ZL_Delay = dwTickCount;
- CT_XM_BACK_Delay = dwTickCount;
- CT_CLT_Delay = dwTickCount;
- CT_ZDP_Delay = dwTickCount;
-
- SingOneFlg = 0;
- AxisDecStop(X_AXIS);
-
- SetEn(X_AXIS,CT_MOTOR_DISEN);
-
-
-
- cSongLiaoOk = 0;
- cZhuangLiaoOk = 0;
-
- CT_XiaMo_VAVLE = 0; //下模
- CT_SongLiao_VAVLE = 0; //送料
- CT_GouZhen_VAVLE = 0; //勾针
-
- CT_DaLaPian_VAVLE = 0; //顶拉片(打拉片)
- CT_FenDai_VAVLE = 0; //分带
- CT_HeLian_VAVLE = 0; //合链(穿模后面)
- CT_ZhenDongPian_OUT = 0; //振动盘
- CT_HuChi_VAVLE = 0; //护齿
- CT_HangSongLiao_VAVLE = 0; //横送料
- if(!CT_MaGou_VAVLE || (CT_HSL_ORIGIN_IN && !CT_HangSongLiao_VAVLE))
- CT_JieLiao_VAVLE = 0; //接料下模
- CT_MaGou_VAVLE = 0; //马勾
- SetAlarmCode(CT_ALARM_ADDR,0);
- }
- }
- #endif
-
- #if 1
- if(bAlarmStop)
- {
- bAlarmStop = 0;
- bRunning = 0;
- CT_AutoStep = 0;
- // CT_MotorStep = 0;
- CT_HeMoStep = 0;
- CT_ZL_Step = 0;
- CT_HSL_Step = 0;
- CT_AutoDelay = dwTickCount;
- CT_MotorDelay = dwTickCount;
- SingOneFlg = 0;
- AxisEgmStop(X_AXIS);
- }
- #endif
- }
- //电机动作
- //第1~10前拖带定位
- //
- void ChuanTou_Motor(void) //
- {
- static long back_buff,save_buff;
- unsigned short ch;
-
- switch(CT_MotorStep)
- {
- case 0:
- break;
- //拖带定位动作
- case 1:
- if(cMotorDinWei_OK && bRunning)
- {
- CT_MotorStep = 0;
- break;
- }
- else
- {
- cMotorDinWei_OK = 0;
- if(!GetEn(X_AXIS))
- {
- SetEn(X_AXIS,CT_MOTOR_EN);
- // CT_SZ_OUT = CT_MOTOR_Y_EN;
- CT_MotorDelay = dwTickCount + 150;
- }
- else
- CT_MotorDelay = dwTickCount + 0;
- SetDir(X_AXIS, CT_DIR_N);
- CT_GouZhen_VAVLE = 1;
- CT_MotorStep = 2;
- }
- break;
- case 2:
- if(dwTickCount >= CT_MotorDelay)
- {
- save_buff = dwRealPos;
- SetDir(X_AXIS, CT_DIR_P);
- ch = CT_PARAM_HSPEED;
- SetDir(X_AXIS, CT_DIR_N);
- if((Zipper_Length > dwRealPos + 2000) && (dwZipCnt > 2))
- {
- ch += CT_PARAM_HSPEED/3;
- CT_MotorStep = 4;
- }
- else
- CT_MotorStep = 3;
-
- if(!X_DRV)
- AxisContinueMove(X_AXIS,ch,CT_DIR_N);
-
-
- }
- break;
- case 3: //不用变速
- if(!CT_GUO_LIAN_IN)
- {
- back_buff = dwRealPos;
- user_datas[127] = dwRealPos;//ch;
- AxisChangeSpeed(X_AXIS,CT_PARAM_LSPEED);
- CT_MotorStep = 5;
- CT_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- }
- else if(((dwRealPos - save_buff) >= CT_PARAM_MAX_LENGTH) && bRunning && CT_PARAM_MAX_LENGTH) //拖带拉链最大长度
- {
- CT_SetAlarmCode(CT_ZIPPER_MAXLENGHT_ALARM); //拉链长度保护
- CT_MotorStep = 0;
- }
- break;
- case 4://到空位
- if(((dwRealPos + 1700) >= Zipper_Length) && Zipper_Length && (dwZipCnt > 2) && (CT_CLT_Step== 0))
- {
- AxisChangeSpeed(X_AXIS,CT_PARAM_HSPEED);
-
- }
- if(!CT_GUO_LIAN_IN)
- {
- back_buff = dwRealPos;
- user_datas[127] = dwRealPos;//ch;
- AxisChangeSpeed(X_AXIS,CT_PARAM_LSPEED);
- CT_MotorStep = 5;
- CT_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- }
- else if(((dwRealPos - save_buff) >= CT_PARAM_MAX_LENGTH) && bRunning && CT_PARAM_MAX_LENGTH) //拖带拉链最大长度
- {
- CT_SetAlarmCode(CT_ZIPPER_MAXLENGHT_ALARM); //拉链长度保护
- CT_MotorStep = 0;
- }
- break;
- case 5:
- if(CT_GUO_LIAN_IN_UP)
- {
- back_buff = dwRealPos;
- AxisChangeSpeed(X_AXIS,CT_PARAM_LSPEED/2);
- CT_MotorStep = 6;
- }
- else if(dwTickCount >= CT_MotorDelay)//(dwRealPos - back_buff) >= 4500) //空位走25公分停止
- {
- CT_SetAlarmCode(CT_NO_ZIPPER_ALARM);
- CT_MotorStep = 0;
- }
- break;
- case 6:
- //延迟上勾针
- if((dwRealPos - back_buff) >= CT_PARAM_GZ_LENGTH)
- {
- CT_GouZhen_VAVLE = 0;
- if((CT_PARAM_HouMa_MODE == HouMa_MODE_DANKUAI) ||
- (CT_PARAM_HouMa_MODE == HouMa_MODE_SHUANGBI) )
- {
- CT_HeLian_VAVLE = 1; //合链关
- }
- }
- //定位长度
- if((dwRealPos - back_buff) >= CT_PARAM_STOP_LENGTH)
- {
- CT_GouZhen_VAVLE = 0;
- AxisEgmStop(X_AXIS);
- CT_MotorStep = 7;
- if((CT_PARAM_HouMa_MODE == HouMa_MODE_DANKUAI) ||
- (CT_PARAM_HouMa_MODE == HouMa_MODE_SHUANGBI) )
- {
- CT_HeLian_VAVLE = 1; //合链关
- }
- }
- break;
- case 7:
- if(!X_DRV)
- {
- CT_MotorStep = 0;
- cMotorDinWei_OK = 1;
- }
- break;
- case 40:
- save_buff = 0;
- ch = CT_PARAM_HSPEED;
- if((Zipper_Length > (dwRealPos + 1800)) && (dwZipCnt > 2))
- {
- ch += CT_PARAM_HSPEED/3;
- CT_MotorStep = 4;
- }
- else
- CT_MotorStep = 3;
- user_datas[125] = ch;
- user_datas[126] = Zipper_Length;
- user_datas[128] = dwRealPos;
- AxisChangeSpeed(X_AXIS,ch);
- break;
- case 50: //此步为穿链时已经检测到拉链上升沿
- back_buff = dwRealPos;
- SetStartSpeed(X_AXIS,CT_PARAM_LSPEED/2);
- AxisContinueMove(X_AXIS,CT_PARAM_LSPEED/2,CT_DIR_N);
- CT_MotorStep = 6;
- break;
- /*
- //穿入动作
- case 100: //穿入电机慢慢复位动作
-
- CT_MotorStep = 101;
- break;
- case 101:
- if(CT_CR_ORIGIN_IN)
- {
- AxisDecStop(Y_AXIS);
- CT_MotorStep = 102;
- }
- else if(dwTickCount >= CT_MotorDelay)
- CT_SetAlarmCode(CT_CR_ORIGIN_ALARM);
- break;
- case 102:
- if(!Y_DRV)
- {
- CT_MotorStep = 0;
- }
- break;
- */
- }
- }
- #endif
|