123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548 |
- #include "global.h"
- #if JIN_HONG_MACHINE==1
- void MXC_InitAction(void);
- void MXC_Action(void);
- void MXC_CheckStart(void);
- void MXC_ManualAction(void);
- void MXC_DC_AutoAction(void);
- void MXC_DC_Motor(void);
- void MXC_XiaChong(void);
- void MXC_ChuiQi(void);
- void MXC_FenZhen(void);
- void MXC_DC_SongDai(void);
- void MXC_DC_ShaChe(void);
- void MXC_DC_XC_BuJin_motor(void);
- void MXC_ExtiAcitionX20(void);
- unsigned long cZipperLength[2];
- #define SB_CHECK_IN !PAin(15)
- //故障报警
- void MXC_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(MXC_ALARM_ADDR,alarm_code);
- MXC_DC_bAlarmStop = 1;
- }
- //X20中断
- void MXC_ExtiAcitionX20(void)
- {
- if (cSeBiaoEn && !cSeBiaoOk)
- {
- cSeBiaoOk = 1;
- MXC_SB_SaveLength = GetPos(X_AXIS);
- MXC_SB_ENCODE_MIN=dwEnRealPos;
- //MXC_Clear_Servo_Pos=1;
- }
- }
- void MXC_SBCHECK_PROC(void)
- {
- static unsigned short flitering=0;
- if(SB_CHECK_IN)
- {
- flitering++;
- if(flitering>=2)
- {
- if (cSeBiaoEn && !cSeBiaoOk)
- {
- cSeBiaoOk = 1;
- MXC_SB_SaveLength = GetPos(X_AXIS);
- MXC_SB_ENCODE_MIN=dwEnRealPos;
- }
- }
- }
- else
- {
- flitering=0;
- }
- }
- unsigned char ComPareLength(void)//前后拉链对比
- {
- if ((cZipperLength[0] != 0) && (cZipperLength[1] != 0))
- {
- if (cZipperLength[0] > cZipperLength[1])
- {
- if ((cZipperLength[0] - cZipperLength[1]) > 50)
- {
- return 0;
- }
- else
- return 1;
- }
- else
- {
- if ((cZipperLength[1] - cZipperLength[0]) > 50)
- {
- return 0;
- }
- else
- return 1;
- }
- }
- else
- return 0;
- }
- void MXC_JiaoDao(void)
- {
- if (MXC_cJiaoDaoStep == 1)
- {
- MXC_cJiaoDaoDelay = dwTickCount + 500;
- MXC_SeBiao_JiaoDao = 1;
- MXC_cJiaoDaoStep = 2;
- }
- else if ((MXC_cJiaoDaoStep == 2) && (dwTickCount >= MXC_cJiaoDaoDelay))
- {
- MXC_SeBiao_JiaoDao = 0;
- MXC_cJiaoDaoStep = 0;
- }
- }
- //步进电机下冲
- void MXC_DC_XC_BuJin_motor(void)
- {
- switch(MXC_cXiaChongStep)
- {
- case 0:
- break;
- case 1:
- if(GetEn(Z_AXIS) == XC_MOTOR_DISEN)
- {
- SetEn(Z_AXIS,XC_MOTOR_EN);
- MXC_BUJIN_XC_Delay = dwTickCount + 170;
- }
- MXC_cXiaChongStep = 2;
- MXC_cRightFZStep = 1;//启动右分针
- MXC_cLeftFZStep = 0;
- break;
- case 2:
- if((MXC_cRightFZStep == 0) && (MXC_cLeftFZStep == 0) && MXC_RighttFenZhen_IN && MXC_LeftFenZhen_IN )
- {
- SetPos(Z_AXIS, 0);
- if (MXC_DC_bRunning)
- {
- MXC_BUJIN_XC_Delay = dwTickCount + MXC_PARAM_DELAY_XC;
- }
- MXC_cXiaChongStep = 3;
- }
- break;
- case 3:
- if(dwTickCount >= MXC_BUJIN_XC_Delay)
- {
- MXC_cXiaChongStep = 4;
- if(MXC_DC_bRunning) MXC_GouZhen_VAVLE = 1;
- AxisMovePosAccDecNotStop(Z_AXIS,MXC_DC_XC_MOTOR_HIGH_SPEED,2000,
- 1200,MXC_DC_XC_MOTOR_LOW_SPEED,
- 100,100,MXC_DC_XC_MOTOR_LOW_LENGTH);
- MXC_BUJIN_XC_Delay = dwTickCount + MXC_XIACHONG_EEROR_TIME;
- }
- break;
- case 4:
- if(MXC_XiaChong_IN_UP)
- {
- SetEncodePos(ENCODE_X22X23, 0);
- AxisMovePosAccDec(Z_AXIS,MXC_DC_XC_MOTOR_LOW_SPEED,MXC_DC_XC_MOTOR_GO_LENGTH,
- 1200,MXC_DC_XC_MOTOR_LOW_SPEED,
- 100,100,MXC_DC_XC_MOTOR_GO_LENGTH/3);
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_RightFenZhen_VAVLE = 0;
- MXC_cXiaChongStep = 5;
- MXC_BUJIN_XC_Delay = dwTickCount;
- }
- else if(dwTickCount >= MXC_BUJIN_XC_Delay)//步进异常
- {
- MXC_SetAlarmCode(MXC_XC_ALARM);
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_RightFenZhen_VAVLE = 0;
- MXC_cXiaChongStep = 0;
- }
- break;
- case 5:
- if(dwTickCount >= MXC_BUJIN_XC_Delay && !Z_DRV)
- {
- MXC_MOTOR_DATA_Num++;
- if(MXC_MOTOR_DATA_Num > 99)
- MXC_MOTOR_DATA_Num = 0;
- if(!MXC_DC_bRunning){
- SetEncodePos(ENCODE_X22X23, 0);
- SetPos(X_AXIS, 0);
- }
- MXC_cXiaChongStep = 0;
- }
- break;
- }
- }
- void MXC_InitAction(void)
- {
- float length_buff,pulse_buff;
-
- length_buff = MXC_MXC_PARAM_DAILUN_LENGTH;
- pulse_buff = MXC_MXC_PARAM_CYCLE_PULSE;
- XGearRatio = pulse_buff/length_buff;
- length_buff = MXC_BM_LENGTH;
- pulse_buff = MXC_BM_CYCLE_PULSE * 4;
- SetEncodeGearRatio(ENCODE_X22X23, pulse_buff/length_buff);
-
- ZGearRatio = 1;//z轴用脉冲数做单位
- SetEn(X_AXIS,DC_Motor_DISEN);
- SetEn(Y_AXIS,XZ_Motor_DISEN);
-
- SetDirReverse(X_AXIS, MXC_DC_Reverse_EN);
-
- MXC_STOP_IN_FLAG = MXC_STOP_IN;
- MXC_STOP_IN_FLAG_OLD = MXC_STOP_IN_FLAG;
- MXC_SaveLength = 0;
- //外部中断配置
- USE_X20_EXTI = 1;
- X20EXTI_DIR = 0;
- //设置X轴的加速模式
- axis_set_parameter(axis_x,AXIS_ACCDEC_MODE,4);
- //只有编码器的情况长度由编码器值确定
- SetEncode_enable(ENCODE_X22X23);
- MXC_DC_KongWei_Length = MXC_PARAM_DAOKOU_LENGTH;
- }
- void MXC_Action(void)
- {
- MXC_CheckStart(); //启动
- MXC_ManualAction();
- MXC_DC_AutoAction();
- MXC_DC_Motor(); //定寸电机控制
- if(!MXC_DC_XC_MODE)
- MXC_XiaChong(); //下冲
- else if(MXC_DC_XC_MODE)
- MXC_DC_XC_BuJin_motor();
- MXC_DC_ShaChe();
- MXC_FenZhen(); //分针
- MXC_ChuiQi(); //吹气
- MXC_DC_SongDai(); //送带控制
- MXC_JiaoDao(); //色标教导
-
- //servo_com_run();
- }
- void MXC_DC_SongDai(void)
- {
- if(!MXC_SongDai_MOTOR)
- {
- MXC_SongDai_LongTime = dwTickCount;
- }
- else//送带一直输出无法触发送带到位
- {
- if((dwTickCount - MXC_SongDai_LongTime) >= MXC_PARAM_SD_Pretect_TIME)
- {
- if(!MXC_DC_bRunning)
- {
- MXC_PARAM_SongDai_Switch = 0;
- MXC_SetAlarmCode(MXC_DC_SONGDAI_ALARM);
- }
- else
- {
- MXC_SongDai_MOTOR = 0;
- MXC_cSongDaiDelay = dwTickCount + MXC_PARAM_SongDai_Delay;
- }
- }
- }
- }
- void MXC_ManualAction(void)
- {
- char i;
- short *revise_buff;
- revise_buff =(short *)( &user_datas[17]);
- if(MXC_DATA_Clean)
- {
- i = 0;
- while(i < 100)
- {
- user_datas[200 + i] = 0;
- i++;
- }
- MXC_DATA_Clean = 0;
- MXC_MOTOR_DATA_Num = 0;
- }
- //清总产量
- if(MXC_bClear)
- {
- MXC_bClear = 0;
- ClrcToTal(MXC_DC_TOTAL_ADDR);
- }
-
- if(MXC_bAddLength)
- {
- MXC_bAddLength=0;
- *revise_buff += 5;
- }
- if(MXC_bDecLength)
- {
- MXC_bDecLength=0;
- *revise_buff -= 5;
- }
- //当长度改变时,生产总量自动清零
- if(MXC_bChangeLength)
- {
- MXC_bChangeLength = 0;
- MXC_SaveLength = 0;
- MXC_bClear = 1;
- }
- //工作方式选择(数控定寸和勾针定寸)
- if (MXC_bSetDCMode)
- {
- MXC_bSetDCMode = 0;
- if (!MXC_DC_bRunning)
- {
- MXC_DC_MODE++;
- if (MXC_DC_MODE > 2)
- MXC_DC_MODE = 0;
- if (MXC_DC_MODE != 0)
- {
- MXC_GouZhen_VAVLE = 1;
- }
- }
- }
-
- //有链感应
- if (MXC_DC_bRunning)//检测拉链,由于拉链有间隙,故需要延迟检测
- {
- if (MXC_Zipper_IN)
- {
- MXC_cBudaiCheckDelay = dwTickCount + MXC_PARAM_BUDAI_ALARM_TIME;
- }
- else if (dwTickCount >= MXC_cBudaiCheckDelay)
- {
- MXC_SetAlarmCode(MXC_NO_ZIPPER_ALARM); //没拉链
- }
- }
- if(MXC_PARAM_SongDai_Switch)
- {
- if(!MXC_SongDai_IN && MXC_Zipper_IN && (dwTickCount >= MXC_cSongDaiDelay))
- {
- MXC_SongDai_MOTOR = 1;
- }
- else if(MXC_SongDai_IN)
- {
- MXC_SongDai_MOTOR = 0;
- MXC_cSongDaiDelay = dwTickCount + MXC_PARAM_SongDai_Delay;
- }
- }
- else
- {
- MXC_SongDai_MOTOR = 0;
- MXC_cSongDaiDelay = dwTickCount + MXC_PARAM_SongDai_Delay;
- }
- if((MXC_DC_bRunning) == 0) ////手动
- {
- //送带
- if(MXC_bSongDai)
- {
- MXC_SongDai_MOTOR = 1;
- }
-
- //顶刀保护
- if(MXC_bDingDao_Baohu)
- {
- MXC_bDingDao_Baohu = 0;
- MXC_DingDao_BaoHu_VAVLE = ~MXC_DingDao_BaoHu_VAVLE;
- }
- //吹气
- if (MXC_bChuiQi)
- {
- MXC_bChuiQi = 0;
-
- if (MXC_cChuiQiStep == 0)
- MXC_cChuiQiStep = 1;
- }
-
- //定寸电机拖带
- if(MXC_bDCTD_P)
- {
- if(!X_DRV)
- {
- // MXC_TuoDaiSongZhou= MXC_SERVER_EN;
- SetEn(X_AXIS, DC_Motor_EN);
- AxisContinueMoveAcc(X_AXIS, MXC_DC_PARAM_MUL_SPEED, MXC_DC_DIR_P, 1200,
- 1200, 120, 120);
- }
- }
- if(X_DRV && !MXC_bDCTD_P && !MXC_DC_bRunning && (MXC_DC_cMotorStep == 0))
- {
- AxisEgmStop(X_AXIS);
- }
- //下冲电机正转
- if(MXC_bXCDJ_P)
- {
- if(!Z_DRV)
- {
- SetEn(Z_AXIS, XC_MOTOR_EN);
- AxisContinueMoveAcc(Z_AXIS, 3000, MXC_XC_DIR_P, 1200,
- 1200, 120, 120);
- }
- }
- if(Z_DRV && !MXC_bXCDJ_P && !MXC_DC_bRunning && (MXC_cXiaChongStep == 0))
- {
- // SetEn(Z_AXIS, XC_MOTOR_DISEN);
- AxisEgmStop(Z_AXIS);
- }
-
- //分针+下冲
- if (MXC_ManXiaChong_UP || MXC_bXiaChong)
- {
- MXC_bXiaChong = 0;
- if (MXC_cXiaChongStep == 0)
- MXC_cXiaChongStep = 1;
- }
- //下冲单一动作
- if (MXC_cXiaChongStep == 0)
- {
- if (MXC_bLeftFenZhen)
- {
- MXC_bLeftFenZhen = 0;
- MXC_LeftFenZhen_VAVLE = ~MXC_LeftFenZhen_VAVLE;
- }
-
- if (MXC_bRightFenZhen)
- {
- MXC_bRightFenZhen = 0;
- MXC_RightFenZhen_VAVLE = ~MXC_RightFenZhen_VAVLE;
- }
- if(MXC_bDotXiaChong && MXC_RighttFenZhen_IN && MXC_LeftFenZhen_IN)
- {
- MXC_bDotXiaChong = 0;
- if(MXC_cXiaChongStep == 0)
- MXC_cXiaChongStep = 1;
- }
- }
-
- if(MXC_bSeBiaoJiaoDao)
- {
- MXC_bSeBiaoJiaoDao = 0;
- MXC_cJiaoDaoStep = 1;
- }
- if(MXC_bGouZhen && MXC_DC_MODE == 0)
- {
- MXC_bGouZhen = 0;
- MXC_GouZhen_VAVLE = ~MXC_GouZhen_VAVLE;
- }
- if (MXC_DC_MODE != 0) //非钩针模式
- {
- MXC_GouZhen_VAVLE = 1;
- }
- }
- }
- void MXC_DC_AutoAction(void)
- {
- if(MXC_MOTOR_DATA_Num <= 99)user_datas[420+MXC_MOTOR_DATA_Num] = MXC_ENCODE_FENZHEN_Lenth;
- dwZRealPos = GetPos(Z_AXIS);
- //DISPLAY_DATA0 = cCheckLengthOk;//Cur_DC_length;//MXC_cXiaChongStep;//MXC_DC_cAutoStep;
- //DISPLAY_DATA1 = MXC_bSeBiao_CheckOK;//cZipperLength[0];//Cur_XZ_length;//MXC_XZ_cAutoStep;
- DISPLAY_DATA2 = MXC_bSeBiao_CheckOK;//cZipperLength[1];//
- DISPLAY_DATA3 = MXC_DC_cAutoStep;//MXC_XZ_cMotorStep;
- DISPLAY_DATA4 = MXC_SB_ENCODE_MIN;//MXC_DC_cMotorStep;
- DISPLAY_DATA5 = MXC_SB_SaveLength;//MXC_cXiaChongStep;
- DISPLAY_DATA6 = dwXRealPos;
- DISPLAY_DATA7 = dwEnRealPos;
- if(MXC_DC_bRunning)
- {
- switch(MXC_DC_cAutoStep)
- {
- case 0:
- break;
- case 1:
- if(dwTickCount >= MXC_DC_cAutoDelay)
- {
- SetEn(X_AXIS, DC_Motor_EN);
- MXC_DC_cAutoDelay = dwTickCount + 700; //先锁轴;
- MXC_DC_cAutoStep = 2;
- }
- break;
- case 2:
- //左右分针要退到位,过链到位要离开
- if((dwTickCount >= MXC_DC_cAutoDelay) && !MXC_RighttFenZhen_IN && !MXC_LeftFenZhen_IN && MXC_RightFenZhen_Origin_IN
- && MXC_LeftFenZhen_Origin_IN)
- {
- switch(MXC_DC_MODE)
- {
- case MXC_DC_SF_MODE:MXC_DC_cMotorStep = 1; break; //伺服
- case MXC_DC_GZ_MODE:MXC_DC_cMotorStep = 20;break; //钩针
- case MXC_DC_SB_MODE:MXC_DC_cMotorStep = 40;break; //色标
- //case MXC_DC_BMQ_MODE:MXC_DC_cMotorStep = 60; break; //编码器
- }
- MXC_DC_cAutoStep = 3;
- }
- else if(dwTickCount >= MXC_DC_cAutoDelay + MXC_ERRORTIME)
- {
- if (MXC_RighttFenZhen_IN)MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM);
- if (MXC_LeftFenZhen_IN)MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM);
- if (!MXC_RightFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);
- if (!MXC_LeftFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM);
- }
- break;
- case 3:
- //拖带已经完成
- if(MXC_DC_cMotorStep == 0)
- {
- MXC_cXiaChongStep = 1;
- MXC_DC_cAutoStep = 4;
- }
- break;
- case 4://下冲完成
- if((MXC_cXiaChongStep == 0) || (MXC_cXiaChongStep >= 5))
- {
- dwZipCnt++;
- MXC_DC_cAutoStep = 5;
- //除齿判断
- if(MXC_CRUKONGWEILENGTH >= MXC_DC_KongWei_Length || MXC_DC_MODE==0 || MXC_DC_MODE==2)
- {
- MXC_CRUKONGWEILENGTH = 0;
- if(!MXC_DC_SingOneFlag)
- {
- AddToTal(MXC_DC_TOTAL_ADDR);
- CalProSP(MXC_DC_PROSPEED_ADDR);
- }
- MXC_DC_cAutoStep = 5;
- }
- else
- {
- MXC_DC_cAutoStep = 2;
- MXC_DC_cAutoDelay = dwTickCount;
- }
- }
- break;
- case 5:
- if(GetTotal(MXC_DC_TOTAL_ADDR) >= MXC_SET_TOTAL)
- {
- MXC_SetAlarmCode(MXC_TOTAL_ALARM);
- MXC_DC_cAutoStep = 0;
- }
- else
- MXC_DC_cAutoStep = 6;
- break;
- case 6:
- MXC_DC_cAutoStep = 2;
- //MXC_Clear_Servo_Pos=0;
- MXC_DC_cAutoDelay = dwTickCount+1;
- if(MXC_DC_SingOneFlag || MXC_DC_Single_Stop)
- {
- dwZipCnt = 0;
- MXC_DC_bAlarmStop = 1;
- MXC_DC_SingOneFlag = 0;
- MXC_DC_cAutoStep = 0;
- MXC_DC_bRunning = 0;
- MXC_DC_Single_Stop = 0;
- }
- break;
- }
- }
- }
- // 检测是否踏了脚踏开关
- void MXC_CheckStart(void)
- {
- // 开始键
- if((MXC_START_IN_UP || MXC_DC_bStart || MXC_DC_bStart_Single))
- {
- if(MXC_DC_bStart_Single)
- {
- MXC_DC_bStart = 1;
- MXC_DC_SingOneFlag = 1;
- MXC_DC_bStart_Single = 0;
- }
- if(MXC_START_IN_UP || MXC_DC_bStart)
- {
- //定寸启动
- if(!MXC_DC_bRunning)
- {
- if (MXC_KaDai_IN)MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
- else if (!MXC_RightFenZhen_Origin_IN)MXC_SetAlarmCode(MXC_START_RFZ_ORIGIN_ALARM);
- else if (!MXC_Zipper_IN)MXC_SetAlarmCode(MXC_NO_ZIPPER_ALARM);
- else
- {
- dwZipCnt = 0;
- cZipperLength[0] = 0;
- cZipperLength[1] = 0;
- MXC_DC_cAutoStep = 1;
- MXC_DC_bRunning = 1;
- MXC_DC_cAutoDelay = dwTickCount;
- MXC_DC_cMotorDelay = dwTickCount;
- MXC_cXiaChongDelay = dwTickCount;
- MXC_cChuiQiDelay = dwTickCount;
- MXC_CRUKONGWEILENGTH=0;
- MXC_ENCODE_FENZHEN_Lenth = 0;
- cSeBiaoOk=0;
- }
- }
- cCheckLengthOk = 0;
- MXC_bSeBiao_Check=0;
- MXC_PARAM_SongDai_Switch = 1;
- }
- MXC_DC_bStart = 0;
- MXC_DC_bStart_Single = 0;
- }
-
- //卡带感应
- if(MXC_KaDai_IN)
- {
- MXC_SetAlarmCode(MXC_KA_DAI_ALARM);
- }
- else
- {
- if((GetAlarmCode(MXC_ALARM_ADDR) == MXC_KA_DAI_ALARM))
- SetAlarmCode(MXC_ALARM_ADDR,0);
- }
-
- if(MXC_KaDai_IN_UP)
- {
- if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
- }
- //停止
- MXC_STOP_IN_FLAG_OLD = MXC_STOP_IN_FLAG;
-
- if(MXC_STOP_IN)
- {
- if(MXC_STOP_FILTER < 50)
- {
- MXC_STOP_FILTER++;
- }
- else
- MXC_STOP_IN_FLAG = 1;
- }
- else if(MXC_STOP_FILTER > 25)
- {
- MXC_STOP_FILTER--;
- }
- else
- MXC_STOP_IN_FLAG = 0;
-
- //停止键
- if(MXC_STOP_IN_FLAG && !MXC_STOP_IN_FLAG_OLD || MXC_bStop)
- {
- MXC_bStop = 0;
- MXC_bSeBiao_Check=0;
- if(MXC_DC_bRunning)
- {
- if(MXC_DC_cMotorStep==0 && MXC_cXiaChongStep!=0)
- {
- MXC_DC_Single_Stop = 1;
- }
- else
- {
- if(MXC_cXiaChongStep==0)
- {
- if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
- }
- MXC_DC_SingOneFlag = 0;
- MXC_DC_bRunning = 0;
- MXC_DC_cAutoStep = 0;
- MXC_DC_cMotorStep = 0;
- MXC_cXiaChongStep = 0;
- AxisEgmStop(X_AXIS);
- AxisEgmStop(Z_AXIS);
- //MXC_cJiaoDaoStep = 0;
- MXC_Zipper_cnt = 0;
- //输出
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_SongDai_MOTOR = 0;
- MXC_RightFenZhen_VAVLE = 0;
- MXC_DingDao_BaoHu_VAVLE = 0;
- MXC_PARAM_SongDai_Switch = 0;
- cSeBiaoOk=0;
- if(MXC_DC_MODE==0)
- MXC_GouZhen_VAVLE = 0;
- }
- }
- else
- {
- MXC_DC_SingOneFlag = 0;
- MXC_DC_bRunning = 0;
- MXC_DC_cAutoStep = 0;
- MXC_DC_cMotorStep = 0;
- MXC_cXiaChongStep = 0;
- MXC_cXiaChongStep = 0;
- MXC_cRightFZStep = 0;
- MXC_cLeftFZStep = 0;
- SetEn(X_AXIS,DC_Motor_DISEN);
- SetEn(Z_AXIS,XC_MOTOR_DISEN);
- if((MXC_cChuiQiStep == 0) &&(MXC_cXiaChongStep==0))MXC_cChuiQiStep = 1;
- AxisEgmStop(X_AXIS);
- AxisEgmStop(Z_AXIS);
- MXC_SetAlarmCode(MXC_NO_ALARM);
- //输出
- if(MXC_cXiaChongStep == 0)
- {
- MXC_XiaChong_MOTOR = 0;
- }
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_SongDai_MOTOR = 0;
- MXC_RightFenZhen_VAVLE = 0;
- MXC_DingDao_BaoHu_VAVLE = 0;
- MXC_PARAM_SongDai_Switch = 0;
- MXC_MOTOR_DATA_Num = 0;
- cSeBiaoOk=0;
- if(MXC_DC_MODE==0)
- MXC_GouZhen_VAVLE = 0;
- }
- }
-
- if(MXC_DC_bAlarmStop)
- {
- MXC_DC_bAlarmStop = 0;
- MXC_DC_bRunning = 0;
- MXC_DC_cAutoStep = 0;
- MXC_DC_cMotorStep = 0;
- MXC_cXiaChongStep = 0;
-
- MXC_cRightFZStep = 0;
- MXC_cLeftFZStep = 0;
- MXC_DC_SingOneFlag = 0;
- MXC_cXiaChongStep = 0;
- MXC_XiaChong_MOTOR = 0;
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_RightFenZhen_VAVLE = 0;
- MXC_DingDao_BaoHu_VAVLE = 0;
- MXC_cShaCheStep = 1;
- AxisEgmStop(X_AXIS);
- }
- }
- void MXC_ChuiQi(void)
- {
- //吹气
- if(MXC_XiaChong_IN_DW && !MXC_DC_XC_MODE)
- {
- if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
- MXC_cDDBH_Step = 1;
- }
- if(MXC_DC_XC_MODE)
- {
- if(PosToPulse(Z_AXIS,GetPos(Z_AXIS)) >= MXC_DC_XC_CHUIQI_PULSE && PosToPulse(Z_AXIS,GetPos(Z_AXIS)) <= MXC_DC_XC_CHUIQI_PULSE + 30)
- if(MXC_cChuiQiStep == 0)MXC_cChuiQiStep = 1;
- if(PosToPulse(Z_AXIS,GetPos(Z_AXIS)) >= MXC_DC_XC_DINDAO_PULSE && PosToPulse(Z_AXIS,GetPos(Z_AXIS)) <= MXC_DC_XC_DINDAO_PULSE + 30)
- if(MXC_cDDBH_Step == 0)MXC_cDDBH_Step = 1;
- }
- switch(MXC_cChuiQiStep)
- {
- case 1:
- MXC_cChuiQiStep = 2;
- MXC_cChuiQiDelay = dwTickCount + MXC_PARAM_DELAY_CHUIQI_TIME;
- break;
- case 2:
- if(dwTickCount >= MXC_cChuiQiDelay)
- {
- MXC_cChuiQiDelay = dwTickCount + MXC_PARAM_CHUIQI_TIME;
- MXC_ChuiQi_VAVLE = 1;//
- MXC_cChuiQiStep = 3;
- }
- break;
- case 3:
- if(dwTickCount >= MXC_cChuiQiDelay)
- {
- MXC_ChuiQi_VAVLE = 0;//
- MXC_cChuiQiStep = 0;
- }
- break;
- }
- switch (MXC_cDDBH_Step)
- {
- case 1:
- MXC_cDDBH_Step = 2;
- MXC_cDDBHDelay = dwTickCount + MXC_PARAM_DDBH_delay;
- break;
- case 2:
- if(dwTickCount >= MXC_cDDBHDelay)
- {
- MXC_cDDBH_Step = 3;
- MXC_DingDao_BaoHu_VAVLE = 1;
- MXC_cDDBHDelay = dwTickCount + MXC_DDBH_TIME;
- }
- break;
- case 3:
- if(dwTickCount >= MXC_cDDBHDelay)
- {
- MXC_cDDBH_Step = 0;
- MXC_DingDao_BaoHu_VAVLE = 0;
- }
- break;
- }
- }
- void MXC_DC_Motor(void)
- {
- static long zipper_length;
- short *revise_buff;
- unsigned long cmp=0;
- unsigned long cyclenum=0;
- dwXRealPos = GetPos(X_AXIS);
- dwEnRealPos = GetEncodePos(ENCODE_X22X23);
- revise_buff = (short *)(&user_datas[17]);
- switch(MXC_DC_cMotorStep)
- {
- case 0:
- break;
- //电机定寸模式
- case 1:
- if(dwEnRealPos>(MXC_SET_ZIPPER_LENGTH + MXC_PARAM_DAOKOU_LENGTH) && MXC_CRUKONGWEILENGTH==0)
- {
- MXC_DC_cMotorStep = 0;
- MXC_CRUKONGWEILENGTH = MXC_PARAM_DAOKOU_LENGTH;
- MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
- SetEncodePos(ENCODE_X22X23, 0);
- }
- else
- {
- MXC_DC_cMotorStep = 2;
- MXC_DC_cMotorDelay = dwTickCount;
- SetPos(X_AXIS, 0);
- }
- break;
- case 2:
- if(dwTickCount >= MXC_DC_cMotorDelay)
- {
- if(MXC_CRUKONGWEILENGTH==0)//MXC_CRUKONGWEILENGTH 记录已除齿长度
- {
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH - dwEnRealPos;
- MXC_CRUKONGWEILENGTH=MXC_PARAM_DAOKOU_LENGTH;
- }
- else if(MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH>=MXC_PARAM_DAOKOU_LENGTH)
- {
- zipper_length=MXC_PARAM_DAOKOU_LENGTH;
- MXC_CRUKONGWEILENGTH+=zipper_length;
- }
- else
- {
- zipper_length=MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH;
- MXC_CRUKONGWEILENGTH+=zipper_length;
- }
- if(zipper_length>MXC_MXC_PARAM_DAILUN_LENGTH)
- {
- cmp=MXC_PARAM_LENGTH_CMP;
- cyclenum=zipper_length/MXC_MXC_PARAM_DAILUN_LENGTH;
- zipper_length=zipper_length+(zipper_length*cyclenum*cmp)/((cyclenum+1)*MXC_MXC_PARAM_DAILUN_LENGTH);
- DISPLAY_DATA0=zipper_length;
- }
- AxisMovePosAccDec(X_AXIS, MXC_PARAM_SK_HIGH_SPEED, zipper_length, 1000,
- MXC_PARAM_SK_SLOW_SPEED, 150, 150, MXC_PARAM_SK_SLOW_LENGTH);
- MXC_DC_cMotorStep = 3;
- MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
- }
- break;
- case 3:
- if(!X_DRV)
- {
- if(MXC_MOTOR_DATA_Num<=99)user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos;
- //SetEncodePos(ENCODE_X22X23, 0);
- MXC_DC_cMotorStep = 4;
- MXC_DC_cMotorDelay = dwTickCount + 20;
- }
- else if(dwTickCount >= MXC_DC_cMotorDelay)MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 4:
- if(dwTickCount >= MXC_DC_cMotorDelay)
- {
- MXC_DC_cMotorStep = 0;
- }
- break;
- //钩针定寸 step20-24
- case 20:
- if (MXC_DEC_MODE) //减速方式:1数控模式 0感应方式
- {
- SetPos(X_AXIS, 0);
- if (MXC_PARAM_AUTO_CHECK_MODE) //1为自动测长0为手动输入长度
- {
- if (cCheckLengthOk)
- {
- if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH)
- {
- AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_SET_SPEED,
- zipper_length - MXC_DC_PARAM_LOWSPEED_LENGTH,
- 2000, MXC_DC_PARAM_LOW_SPEED, 150,
- 150, 0);
- }
- else
- {
- AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length,
- 1000, MXC_DC_PARAM_LOW_SPEED, 30, 30, 0);
- }
- }
- else
- {
- if (cCheckLengthOk == 0)
- {
- cZipperLength[0] = cZipperLength[1];
- cZipperLength[1] = zipper_length_buff;
- if (ComPareLength())//返回1,前后拉链没有明显变化
- {
- cCheckLengthOk = 1;
- }
- }
-
- if (cCheckLengthOk)
- {
- zipper_length = cZipperLength[1];
- if (zipper_length > MXC_PARAM_DAOKOU_LENGTH)
- {
- SetData32bits(MXC_XC_ZIPPER_LENGTH_ADDR, zipper_length - MXC_PARAM_DAOKOU_LENGTH);
- }
- if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH)
- {
- AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_SET_SPEED,
- zipper_length - MXC_DC_PARAM_LOWSPEED_LENGTH,
- 2000, MXC_DC_PARAM_LOW_SPEED, 100,
- 100, 100);
- }
- else
- {
- AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length,
- 1000, MXC_DC_PARAM_LOW_SPEED, 30, 30, 0);
- }
- }
- else
- {
- AxisContinueMoveAcc(X_AXIS, MXC_PARAM_FIRST_SPEED, MXC_DC_DIR_P, 1200,
- 800, 80, 120);
- }
- }
- }
- else//手动输入长度模式
- {
- if (dwZipCnt == 0)
- AxisContinueMoveAcc(X_AXIS, MXC_PARAM_FIRST_SPEED, MXC_DC_DIR_P, 1200, 1200,
- 80, 120);
- else
- {
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH;
- //输入长度过大
- if (zipper_length > zipper_length_buff && dwZipCnt > 1)
- zipper_length = zipper_length_buff;
- if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH)
- {
- AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_SET_SPEED,
- zipper_length - MXC_DC_PARAM_LOWSPEED_LENGTH,
- 1000, MXC_DC_PARAM_LOW_SPEED, MXC_DC_PARAM_SET_SPEED / 300,
- MXC_DC_PARAM_SET_SPEED / 300, 0);
- }
- else
- {
- AxisMovePosAccDecNotStop(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length,
- 800, MXC_DC_PARAM_LOW_SPEED, 30, 30, 0);
- }
- }
- }
- MXC_DC_cMotorStep = 22;
- }
- else // 感应方式
- {
- AxisContinueMoveAcc(X_AXIS, MXC_DC_PARAM_SET_SPEED, MXC_DC_DIR_P,1000,1000,30,30);
- MXC_DC_cMotorStep = 21;
- }
- MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY;
- MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
- break;
- case 21:
- //if ((dwTickCount >= MXC_cGouZhenTime))
- // MXC_GouZhen_VAVLE = 0;
- if (MXC_DEC_MODE == 0) // 感应模式
- {
- if (MXC_JianSu_IN_DW)
- {
- AxisChangeSpeedDirect(X_AXIS, MXC_DC_PARAM_LOW_SPEED);
- //MXC_cGouZhenTime = dwTickCount + MXC_PARAM_GZ_DELAY;
- MXC_DC_cMotorStep = 23;
- }
- if (MXC_GouZhen_IN)
- {
- MXC_DC_cMotorStep = 24;
- AxisEgmStop(X_AXIS);
- }
- }
- if (dwTickCount >= MXC_DC_cMotorDelay)
- MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 22:
- // if ((dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 0))
- // MXC_GouZhen_VAVLE = 0;
- if (MXC_DEC_MODE) // 数控方式
- {
- if (MXC_PARAM_AUTO_CHECK_MODE)///1为自动测长0为手动输入长度
- {
- if (cCheckLengthOk)
- {
- if ((dwXRealPos >= (zipper_length - MXC_PARAM_GZ_LENGTH)) && MXC_PARAM_GZ_RESET_MODE)
- MXC_GouZhen_VAVLE = 0;
- }
- else
- {
- if (dwTickCount >= MXC_cGouZhenTime)
- MXC_GouZhen_VAVLE = 0;
- }
- }
- else
- {
- if ((dwXRealPos >= (zipper_length - MXC_PARAM_GZ_LENGTH)) && MXC_PARAM_GZ_RESET_MODE)
- MXC_GouZhen_VAVLE = 0;
- if ((dwZipCnt == 0) && (dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 1))
- MXC_GouZhen_VAVLE = 0;
- }
- if (MXC_JianSu_IN_DW)
- {
- if (cCheckLengthOk)
- {
- ;
- }
- else
- {
- AxisChangeSpeedDirect(X_AXIS, MXC_DC_PARAM_LOW_SPEED);
- }
- }
- if (MXC_GouZhen_IN_UP)
- {
- MXC_GouZhen_VAVLE = 0;
- MXC_DC_cMotorStep = 23;
- AxisEgmStop(X_AXIS);
- }
- }
- if (dwTickCount >= MXC_DC_cMotorDelay)
- MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 23:
- if ((dwTickCount >= MXC_cGouZhenTime) && (MXC_PARAM_GZ_RESET_MODE == 0))
- MXC_GouZhen_VAVLE = 0;
- if (MXC_DEC_MODE) // 数控方式
- {
- if (!X_DRV)
- {
- MXC_DC_cMotorStep = 0;
- zipper_length_buff = dwXRealPos;
- }
- }
- else // 感应方式
- {
- if (MXC_GouZhen_IN)
- {
- MXC_DC_cMotorStep = 24;
- AxisEgmStop(X_AXIS);
- }
- }
- if (dwTickCount >= MXC_DC_cMotorDelay)
- MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 24:
- if (!X_DRV)
- {
- MXC_DC_cMotorStep = 0;
- }
- if (dwTickCount >= MXC_DC_cMotorDelay)
- MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- //色标定寸 step 40-42
- case 40:
- SetPos(X_AXIS, 0);
- MCX_SB_ENCODE_END=dwEnRealPos;
- SetEncodePos(ENCODE_X22X23, 0);
- if ((dwZipCnt == 0) || SingOneFlg)
- {
- AxisContinueMoveAcc(X_AXIS, 1000, MXC_DC_DIR_P, 1000,
- 1000, 10, 10);
- MXC_DC_cMotorStep = 41;
- }
- else
- {
- zipper_length=MXC_SET_ZIPPER_LENGTH+ (*revise_buff)-MXC_DC_PARAM_SEBIAO_DW_LENGTH;
- if(zipper_length>MXC_MXC_PARAM_DAILUN_LENGTH)
- {
- cmp=MXC_PARAM_LENGTH_CMP;
- cyclenum=zipper_length/MXC_MXC_PARAM_DAILUN_LENGTH;
- zipper_length=zipper_length+(zipper_length*cyclenum*cmp)/((cyclenum+1)*MXC_MXC_PARAM_DAILUN_LENGTH);
- }
- if(zipper_length>0)
- {
- AxisMovePosAccDecNotStop(X_AXIS,MXC_PARAM_SB_HIGH_SPEED,zipper_length,
- 1500,MXC_PARAM_SB_LOW_SPEED,100,100,
- PosToPulse(X_AXIS,MXC_PARAM_SEBIAO_LOWSPEED_LENGTH));
- }
- else
- {
- MXC_SetAlarmCode(MXC_ZIPPER_SB_LENGTH_ALARM);
- }
- MXC_DC_cMotorStep = 41;
- }
- cSeBiaoOk = 0;
- cSeBiaoEn = 0;
- MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
- break;
- case 41://使能色标位置
- if (dwZipCnt == 0)
- {
- cSeBiaoOk = 0;
- cSeBiaoEn = 1;
- MXC_DC_cMotorStep = 42;
- }
- else
- {
- if (dwXRealPos>=zipper_length-MXC_PARAM_SEBIAO_LOWSPEED_LENGTH)
- {
- if ((dwXRealPos+MXC_PARAM_SEBIAO_TQ_LENGTH) >= zipper_length+MXC_PARAM_First_CMP)
- {
- cSeBiaoOk = 0;//开启色标中断
- cSeBiaoEn = 1;//色标中断使能
- MXC_DC_cMotorStep = 42;
- MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
- }
- else if (dwXRealPos > (zipper_length + MXC_PARAM_SEBIAO_ERROR_LENGTH+MXC_PARAM_First_CMP))
- {
- MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
-
- }
- }
- }
- break;
- case 42://色标定位
- if(cSeBiaoOk && cSeBiaoEn)
- {
- cSeBiaoEn = 0;
- if (dwZipCnt == 0)
- {
- zipper_length= MXC_DC_PARAM_SEBIAO_DW_LENGTH-(MXC_SB_SaveLength-MXC_SB_ENCODE_MIN);
- AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_SB_OFFSET_SPEED,
- MXC_DC_PARAM_SEBIAO_DW_LENGTH,
- 800, 800,
- 120, 100, 50);
- MXC_DC_cMotorStep = 44;
- MXC_Clear_Servo_Pos=1;
- }
- else
- {
- zipper_length= MXC_DC_PARAM_SEBIAO_DW_LENGTH-MXC_PARAM_First_CMP;
- AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_SB_OFFSET_SPEED,
- zipper_length,
- 800, 800,
- 120, 100, 50);
- MXC_DC_cMotorStep = 44;
- MCX_XPOS_BUFF=dwXRealPos;
- DISPLAY_DATA0=dwXRealPos-MXC_SB_SaveLength;
- }
- }
- break;
- case 44://色标定位
-
- if (dwZipCnt == 0&&!X_DRV)
- {
-
- MXC_DC_cMotorStep = 45;
- MXC_bSeBiao_Check=1;//第一条,屏幕弹出小窗口,人工确认色标定位位置
- MXC_bSeBiao_CheckOK=0;
- MXC_bSeBiao_CheckStop=0;
- MXC_Clear_Servo_Pos=0;
- }
- else if(!X_DRV)
- {
- MXC_DC_cMotorStep = 0;
- }
- else if (dwTickCount >= MXC_DC_cMotorDelay)
- {
- MXC_SetAlarmCode(MXC_NO_SEBIAO_ALARM);
-
- }
- break;
- case 45:
- if(MXC_bSeBiao_CheckOK)//人工确认位置色标定位位置正确
- {
- MXC_bSeBiao_CheckOK=0;
- MXC_DC_cMotorStep = 0;
- MXC_bSeBiao_Check=0;
- }
- if(MXC_bSeBiao_CheckStop)//位置不正确,停止
- {
- MXC_bSeBiao_CheckStop=0;
- dwZipCnt = 0;
- MXC_DC_bAlarmStop = 1;
- MXC_DC_SingOneFlag = 0;
- MXC_DC_cAutoStep = 0;
- MXC_DC_bRunning = 0;
- MXC_bSeBiao_Check=0;
- }
- break;
- #if 0
- //编码器定位
- case 60:
- if(dwEnRealPos>(MXC_SET_ZIPPER_LENGTH+MXC_PARAM_DAOKOU_LENGTH) && MXC_CRUKONGWEILENGTH==0)
- {
- MXC_DC_cMotorStep = 64;
- MXC_CRUKONGWEILENGTH = MXC_PARAM_DAOKOU_LENGTH;
- MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
- }
- else
- {
- MXC_DC_cMotorStep = 61;
- MXC_DC_cMotorDelay = dwTickCount;
- SetPos(X_AXIS, 0);
- }
- break;
- case 61:
- if(dwTickCount >= MXC_DC_cMotorDelay)
- {
- SetPos(X_AXIS, 0);
- if(MXC_CRUKONGWEILENGTH==0)
- {
- zipper_length = MXC_SET_ZIPPER_LENGTH + (*revise_buff) + MXC_PARAM_DAOKOU_LENGTH - dwEnRealPos ;//- MXC_ENCODE_FENZHEN_Lenth/3;//-(MXC_ENCODE_FENZHEN_Lenth); //
- MXC_CRUKONGWEILENGTH = MXC_PARAM_DAOKOU_LENGTH;
- }
- else if(MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH>=MXC_PARAM_DAOKOU_LENGTH)
- {
- zipper_length=MXC_PARAM_DAOKOU_LENGTH;
- MXC_CRUKONGWEILENGTH+=zipper_length;
- }
- else
- {
- zipper_length=MXC_DC_KongWei_Length-MXC_CRUKONGWEILENGTH;
- MXC_CRUKONGWEILENGTH+=zipper_length;
- }
- if(zipper_length<1400)
- {
- if (zipper_length > MXC_DC_PARAM_LOWSPEED_LENGTH)
- {
- AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_SET_SPEED * 3 / 4 + 600, zipper_length, 1200, MXC_DC_PARAM_LOW_SPEED, MXC_DC_PARAM_SET_SPEED/300, MXC_DC_PARAM_SET_SPEED/300, PosToPulse(X_AXIS, MXC_DC_PARAM_LOWSPEED_LENGTH)); //1200 600
- }
- else
- {
- AxisMovePosAccDec(X_AXIS, MXC_DC_PARAM_LOW_SPEED, zipper_length, 1200,
- MXC_DC_PARAM_LOW_SPEED, 50, 50, 0); //1200 600
- }
- }
- else if(zipper_length<2400)
- {
- AxisMovePosAccDec(X_AXIS,MXC_DC_PARAM_SET_SPEED*7/8,zipper_length,1200,MXC_DC_PARAM_LOW_SPEED,MXC_DC_PARAM_SET_SPEED/300,MXC_DC_PARAM_SET_SPEED/300,PosToPulse(X_AXIS, MXC_DC_PARAM_LOWSPEED_LENGTH));//1200 600
- }
- else
- {
- AxisMovePosAccDec(X_AXIS,MXC_DC_PARAM_SET_SPEED,zipper_length,1200,MXC_DC_PARAM_LOW_SPEED,MXC_DC_PARAM_SET_SPEED/300,MXC_DC_PARAM_SET_SPEED/300,PosToPulse(X_AXIS, MXC_DC_PARAM_LOWSPEED_LENGTH));//1200 600
- }
- MXC_DC_cMotorDelay = dwTickCount + MXC_MOTOR_ALALRM_TIME;
- MXC_DC_cMotorStep = 62;
- }
- break;
- case 62:
- if(!X_DRV)//||(dwEnRealPos>=dwXRealPos)&&(dwXRealPos>=MXC_PARAM_DAOKOU_LENGTH))
- {
- //AxisEgmStop(X_AXIS);
- MXC_DC_cMotorStep = 63;
- MXC_DC_cMotorDelay = dwTickCount+0;
- }
- else if(dwTickCount >= MXC_DC_cMotorDelay)
- MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 63:
- if(dwTickCount >= MXC_DC_cMotorDelay)
- {
- // if(MXC_MOTOR_DATA_Num<=99)user_datas[420+MXC_MOTOR_DATA_Num] = dwEnRealPos;
- if(dwEnRealPos<dwXRealPos)
- {
- zipper_length=(dwXRealPos-dwEnRealPos);
- AxisMovePosAccDec(X_AXIS,800,zipper_length,800,800,10,10,0);
- }
-
- MXC_DC_cMotorStep = 64;
- }
- break;
- case 64:
- if(!X_DRV)
- {
- if(MXC_MOTOR_DATA_Num<=99)user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos;
- MXC_DC_cMotorDelay = dwTickCount;
- MXC_DC_cMotorStep = 0;
- //SetEncodePos(ENCODE_X22X23, 0);
- }
- // else if(dwTickCount >= MXC_DC_cMotorDelay)
- // MXC_SetAlarmCode(MXC_LONG_TIME_NO_ZIPPER_ALARM, MXC_ALARM_DC);
- break;
- case 65:
- if(dwXRealPos<=zipper_length-500)//剩余长度小于5CM
- {
- AxisMovePosAccDec(X_AXIS,1000,300,600,600,20,20,0);
- MXC_DC_cMotorStep = 66;
- }
- else
- {
- MXC_DC_cMotorStep = 62;
- }
- break;
- case 66:
- if(!X_DRV)
- {
- MXC_DC_cAutoStep=2;
- MXC_DC_cMotorStep=0;
- MXC_CRUKONGWEILENGTH=0;
- }
- break;
- #endif
- }
- }
- //下冲
- void MXC_XiaChong(void)
- {
- switch(MXC_cXiaChongStep)
- {
- case 0:
- break;
- case 1:
- MXC_cXiaChongStep = 2;
- MXC_cRightFZStep = 1;//启动右分针
- MXC_cLeftFZStep = 0;
- break;
- case 2:
- if((MXC_cRightFZStep == 0) && (MXC_cLeftFZStep == 0) && MXC_RighttFenZhen_IN && MXC_LeftFenZhen_IN)
- {
-
- MXC_XC_ShaChe = 0;//打开刹车
- if (MXC_DC_bRunning)
- {
- MXC_cXiaChongDelay = dwTickCount + MXC_PARAM_DELAY_XC;
- }
- MXC_cXiaChongStep = 3;
- }
- break;
- case 3:
- if(dwTickCount >= MXC_cXiaChongDelay)
- {
- MXC_cXiaChongStep = 4;
- MXC_XiaChong_MOTOR = 1;
- if(MXC_DC_bRunning) MXC_GouZhen_VAVLE = 1;
- MXC_cXiaChongDelay = dwTickCount + MXC_XIACHONG_EEROR_TIME;
- }
- break;
- case 4:
- if(MXC_XiaChong_IN_UP)
- {
-
- SetEncodePos(ENCODE_X22X23, 0);
- // if(MXC_MOTOR_DATA_Num<=99)user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos;
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_RightFenZhen_VAVLE = 0;
- MXC_cXiaChongStep = 5;
- MXC_cShaCheStep = 1;
- MXC_cXiaChongDelay = dwTickCount + MXC_XC_Stop_Delay;
- }
- else if(dwTickCount >= MXC_cXiaChongDelay)//感应异常
- {
- MXC_SetAlarmCode(MXC_XC_ALARM);
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_RightFenZhen_VAVLE = 0;
- MXC_cXiaChongStep = 0;
- MXC_XiaChong_MOTOR = 0;
- MXC_cShaCheStep = 1;
- }
- break;
- case 5:
- if(dwTickCount >= MXC_cXiaChongDelay)
- {
- // user_datas[200+MXC_MOTOR_DATA_Num] = dwEnRealPos;
- MXC_MOTOR_DATA_Num++;
- if(MXC_MOTOR_DATA_Num > 99)
- MXC_MOTOR_DATA_Num = 0;
- if(!MXC_DC_bRunning){
- SetEncodePos(ENCODE_X22X23, 0);
- SetPos(X_AXIS, 0);
- }
- MXC_XiaChong_MOTOR = 0;
- MXC_cXiaChongStep = 0;
- }
- break;
- }
- }
- void MXC_DC_ShaChe(void)
- {
- //刹车
- switch(MXC_cShaCheStep)
- {
- case 1:
- MXC_cShaCheStep = 2;
- MXC_cShaCheDelay = dwTickCount + MXC_PARAM_ShaChe_Delay;
- break;
- case 2:
- if(dwTickCount >= MXC_cShaCheDelay)
- {
- MXC_cShaCheStep = 3;
- MXC_cShaCheDelay = dwTickCount + MXC_PARAM_ShaChe_TIME;
- MXC_XC_ShaChe = 1;
- }
- break;
- case 3:
- if(dwTickCount >= MXC_cShaCheDelay)
- {
- MXC_XC_ShaChe = 0;
- MXC_cShaCheStep = 0;
- }
- break;
- }
- }
- void MXC_FenZhen(void)
- {
- switch (MXC_cRightFZStep)
- {
- case 0:
- break;
- case 1:
- MXC_cRightFZ_Delay = MXC_RightFZ_Delay + dwTickCount;
- MXC_cRightFZStep = 2;
- break;
- case 2:
- if (dwTickCount >= MXC_cRightFZ_Delay)
- {
- MXC_cRightFZStep = 3;
- MXC_RightFenZhen_VAVLE = 1; //右分针电磁阀
- MXC_cRightFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME;
- }
- break;
- case 3:
- if (!MXC_RightFenZhen_Origin_IN) //右分针原点离开
- {
- MXC_cRightFZ_Delay = dwTickCount + MXC_DC_RightFZ_AGAIN_TIME;
- MXC_cRightFZStep = 4;
- } //右分针不下去
- else if (dwTickCount >= MXC_cRightFZ_Delay)
- {
- MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);//警告暂停 分针下冲步骤都清零
- MXC_RightFenZhen_VAVLE = 0;
- }
- break;
- case 4:
- if (MXC_RighttFenZhen_IN) //插针到位
- {
- MXC_ENcode_Cul = dwEnRealPos;
- MXC_cRFengTimer = 0;
- MXC_cRightFZStep = 0;
- MXC_cLeftFZStep = 1; //左分针延时启动
- }
- else if (dwTickCount >= MXC_cRightFZ_Delay)
- {
- MXC_RightFenZhen_VAVLE = 0; //右分针
- MXC_cRFengTimer++;
- //当右分针分不到位时,左分针也要重新分针
- MXC_LeftFenZhen_VAVLE = 0;
- MXC_cRightFZStep = 0;
- if (MXC_cRFengTimer < 4)//times 次数
- {
- MXC_cRightFZStep = 5;
- MXC_cRightFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME;
- }
- else
- {
- MXC_cRFengTimer = 0;
- MXC_SetAlarmCode(MXC_RFZ_LIMIT_ALARM);
- MXC_cRightFZStep = 0;
- MXC_RightFenZhen_VAVLE = 0;
- }
- }
- break;
- //5-6重新下右分针
- case 5:
- if (MXC_RightFenZhen_Origin_IN) //退到位
- {
- MXC_cRightFZStep = 2;
- }
- else if (dwTickCount >= MXC_cRightFZ_Delay)
- {
- MXC_SetAlarmCode(MXC_RFZ_ORIGIN_ALARM);
- MXC_RightFenZhen_VAVLE = 0;
- }
- break;
- }
- //左分针
- switch (MXC_cLeftFZStep)
- {
- case 0:
- break;
- case 1:
- MXC_cLeftFZ_Delay = MXC_LeftFZ_Delay + dwTickCount;
- MXC_cLeftFZStep = 2;
- break;
- case 2:
- if (dwTickCount >= MXC_cLeftFZ_Delay)
- {
- MXC_cLeftFZStep = 3;
- MXC_LeftFenZhen_VAVLE = 1; //左分针电磁阀
- MXC_cLeftFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME;
- }
- break;
- case 3: //离开左分针原点
- if (!MXC_LeftFenZhen_Origin_IN) //左分针原点离开
- {
- MXC_cLeftFZ_Delay = dwTickCount + MXC_DC_LeftFZ_AGAIN_TIME;
- MXC_cLeftFZStep = 4;
- } //左分针不下去
- else if (dwTickCount >= MXC_cLeftFZ_Delay)
- {
- MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM);
- MXC_LeftFenZhen_VAVLE = 0;
- }
- break;
- case 4:
- if (MXC_LeftFenZhen_IN) //左插针到位
- {
- MXC_ENCODE_FENZHEN_Lenth = dwEnRealPos - MXC_ENcode_Cul;
- MXC_cLFengTimer = 0;
- MXC_cLeftFZStep = 0;
-
- }
- else if (dwTickCount >= MXC_cLeftFZ_Delay)
- {
- MXC_LeftFenZhen_VAVLE = 0; //左分针
- MXC_cLFengTimer++;
- if (MXC_cLFengTimer < 6)
- {
- MXC_cLeftFZStep = 5;
- MXC_cLeftFZ_Delay = dwTickCount + MXC_FENZHEN_EEROR_TIME;
- if ((MXC_cLFengTimer % 2) == 0)
- {
- MXC_RightFenZhen_VAVLE = 0;
- MXC_cRightFZStep = 0;
- }
- }
- else
- {
- MXC_cLFengTimer = 0;
- MXC_SetAlarmCode(MXC_LFZ_LIMIT_ALARM);
- MXC_cLeftFZStep = 0;
- MXC_LeftFenZhen_VAVLE = 0;
- }
- }
- break;
- //5-6重新下左分针
- case 5:
- if (MXC_LeftFenZhen_Origin_IN) //退到位
- {
- MXC_cLeftFZStep = 6;
- }
- else if (dwTickCount >= MXC_cLeftFZ_Delay)
- {
- MXC_SetAlarmCode(MXC_LFZ_ORIGIN_ALARM);
- MXC_cLeftFZStep = 0;
- MXC_LeftFenZhen_VAVLE = 0;
- }
- break;
- case 6:
- if ((MXC_cLFengTimer % 2) == 0) //左边插两次都插不到,就退右边再同时插
- {
- if(MXC_RightFenZhen_Origin_IN)
- {
- MXC_cRightFZStep = 1;
- MXC_cRFengTimer = 0;
- MXC_cLeftFZStep = 0;
- }
- }
- else
- {
- MXC_cLeftFZStep = 2;
- }
- break;
- }
- }
- #endif
|