123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491 |
- #include "global.h"
- #if JIN_HONG_MACHINE ==1
- void KK_QueDuan_AlarmProtect(void);
- void KK_QueDuan_ManualAction(void);
- void KK_QueDuan_AutoAction(void);
- void KK_QueDuan_StepCheckStart(void);
- void KK_QueDuan_XiaQue(void);
- void KK_QueDuan_Motor(void);
- void KK_QueDuan_YuanDianAction(void);
- void KK_QueDuan_TuiLianAction(void);
- void KK_QueDuan_ExtiActionX31(void);
- void KK_QueDuan_BingLian(void);
- void KKQD_TuiDaiAction(void);
- void KK_StopCode(void);
- void KK_Motor_SZ(unsigned char En);
- short *KK_length_buffer;
- void KK_QueDuan_ExtiActionX31(void)
- {
- KK_cCheckLianFlg = 1;
- }
- void KKQD_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(KKQD_ALARM_ADDR,alarm_code);
- bAlarmStop = 1;
- }
- void KK_StopCode(void)
- {
- switch(BKQD_StopStep)
- {
- case 1:
- KKQD_StopStep=2;
- if(X_DRV)
- {
- AxisChangeSpeedDirect(X_AXIS,GetCurSpeed(X_AXIS) * 2/3);
- AxisDecStop(X_AXIS);
- }
- break;
- case 2:
- if(!X_DRV || (dwXRealPos < 10))
- {
- KKQD_StopCodeDelay=dwTickCount+350;
- KKQD_StopStep = 3;
- AxisEgmStop(X_AXIS);
- }
- break;
- case 3:
- if(dwTickCount >= BKQD_StopCodeDelay)
- {
- // if(!cSTOPONE)
- {
- KKQD_StopStep=0;
- }
- // else
- // {
- // QD_SetAlarmCode(QD_PARAM_ANQUANMEN_ALARM);
- // BKQD_StopStep=0;
- // cSTOPONE=0;
- // }
- AxisEgmStop(X_AXIS);
- KK_Motor_SZ(KKQD_MOTOR_DIS); //电机松轴
- }
- break;
- }
- }
- //电机松轴
- void KK_Motor_SZ(unsigned char En)
- {
- if(En) //使能
- {
- if(KKQD_PARAM_MOTOR_SELECT)
- KKQD_SZ_OUT = 1; //伺服电机
- else
- KKQD_SZ_OUT = 0; //步进电机
- }
- else //松轴
- {
- if(KKQD_PARAM_MOTOR_SELECT)
- KKQD_SZ_OUT = 0; //伺服电机
- else
- KKQD_SZ_OUT = 1; //步进电机
- }
- }
- void KK_QueDuan_InitAction(void)
- {
- float length_buff,pulse_buff;
-
-
- length_buff = KKQD_PARAM_CYCLE_LENGTH;
- pulse_buff = KKQD_PARAM_CYCLE_PULSE;
- XGearRatio = pulse_buff/length_buff;
- KK_Motor_SZ(KKQD_MOTOR_DIS); //电机松轴
- SetDirReverse(X_AXIS, 0);
- axis_set_parameter(axis_x, AXIS_ACCDEC_MODE,0);
-
-
- }
- void KK_QueDuan_Action(void)
- {
- KK_QueDuan_AlarmProtect();
- KK_StopCode();
- KK_QueDuan_Motor();
- KK_QueDuan_XiaQue();
- KK_QueDuan_ManualAction();
- KK_QueDuan_TuiLianAction();
- KK_QueDuan_BingLian();
- KK_QueDuan_AutoAction();
- KK_QueDuan_StepCheckStart(); // 调用脚踏开关检测程序
- }
- //手动动作
- void KK_QueDuan_ManualAction(void)
- {
- if(bRunning == 0)
- {
- KK_cGoLimitEn = 0;
- if(KKQD_bClearTotal) //切断计数清零
- {
- KKQD_bClearTotal = 0;
- ClrcToTal(KKQD_TOTAL_ADDR);
- }
-
- if(KKQD_bClearNowTotal)
- {
- KKQD_bClearNowTotal = 0;
- KKQD_PARAM_NOW_CNT = 0;
- }
-
- if(KKQD_bXiaQie)
- {
- KKQD_bXiaQie = 0;
- if((KKQD_XiaQieStep == 0) && !KKQD_TL_VAVLE)
- {
- KKQD_XiaQieStep = 1;
- }
- }
-
- if(KKQD_bQianDianDW)
- {
- KKQD_bQianDianDW = 0;
- if(KKQD_MotorStep == 0)
- {
- KKQD_MotorStep = 61;
- KK_cZipCnt = 0;
- KK_Motor_SZ(KKQD_MOTOR_EN); //电机锁轴
- KKQD_MotorDelay = dwTickCount + 150;
- }
- }
-
- if(KKQD_bTL)
- {
- KKQD_bTL = 0;
- if(KKQD_TL_VAVLE)
- {
- KKQD_TL_VAVLE = 0;
- }
- else if(!KKQD_GZ_VAVLE && !KKQD_SM_VAVLE)
- {
- KKQD_TL_VAVLE = ~KKQD_TL_VAVLE;
- }
- }
-
-
- if(KKQD_bYD)
- {
- KKQD_bYD = 0;
- KKQD_YD_VAVLE = ~KKQD_YD_VAVLE;
- }
-
- if(KKQD_bGZ)
- {
- KKQD_bGZ = 0;
- KKQD_GZ_VAVLE = ~KKQD_GZ_VAVLE;
- }
-
- if(KKQD_bJD)
- {
- KKQD_bJD = 0;
- KKQD_JD_VAVLE = ~KKQD_JD_VAVLE;
- }
-
- if(KKQD_bXM)
- {
- KKQD_bXM = 0;
- if(KKQD_XM_KAIKOU_VAVLE)
- {
- KKQD_XM_KAIKOU_VAVLE = 0;
- }
- else
- {
- KKQD_XM_KAIKOU_VAVLE = 1;
- }
- }
-
- if(KKQD_bSM)
- {
- KKQD_bSM = 0;
- if(KKQD_SM_VAVLE)
- KKQD_SM_VAVLE = 0;
- else if(!KKQD_TL_VAVLE)
- KKQD_SM_VAVLE = 1;
- }
- //推方块
- if(KKQD_bTFK)
- {
- KKQD_bTFK = 0;
- KKQD_TFK_VAVLE = ~KKQD_TFK_VAVLE;
- }
- //台面电机
- if(KKQD_bTB)
- {
- KKQD_bTB = 0;
- KKQD_TABLE_VAVLE = ~KKQD_TABLE_VAVLE;
- }
-
- // if(KKQD_bYBD)
- // / {
- // KKQD_bYBD = 0;
- // KKQD_YBD_VAVLE = ~KKQD_YBD_VAVLE;
- // }
-
- if(KKQD_bTestCS)
- {
- KKQD_bTestCS = 0;
- KKQD_CS_OUT = 1;
- KKQD_CSDelay = dwTickCount + KKQD_PARAM_CS_TIME;
- }
-
- if(KKQD_bBL)//合链
- {
- KKQD_bBL = 0;
- KKQD_BL_VAVLE = ~KKQD_BL_VAVLE;
- }
-
- if(KKQD_bHL) //护链,双开用
- {
- KKQD_bHL = 0;
- // KKQD_HL_VAVLE = ~KKQD_HL_VAVLE;
- }
-
- if(KKQD_bYX)
- {
- KKQD_bYX = 0;
- // KKQD_YX_VAVLE = ~KKQD_YX_VAVLE;
- }
- if(KKQD_XiaQieStep == 0)
- {
- if(dwTickCount >= KKQD_CSDelay) KKQD_CS_OUT = 0;
- }
-
- //电机控制
- if(KKQD_bGoMotor && !KKQD_QIAN_LIMIT_IN)
- {
- KK_Motor_SZ(KKQD_MOTOR_EN); //电机锁轴
- KKQD_STOPINDelay = dwTickCount;
- if(!X_DRV)
- {
-
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED,KKQD_PARAM_GO_LOW_SPEED,10,12);
-
- }
- }
-
- if(KKQD_bBackMotor) //后退限位已经取消
- {
- KK_Motor_SZ(KKQD_MOTOR_EN); //电机锁轴
- KKQD_STOPINDelay = dwTickCount;
- if(!X_DRV)
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_P,KKQD_PARAM_GO_LOW_SPEED,KKQD_PARAM_GO_LOW_SPEED,10,12);
- }
-
- if(!KKQD_bGoMotor && !KKQD_bBackMotor && (KKQD_MotorStep == 0) && (dwTickCount >= KKQD_STOPINDelay))
- {
- if(X_DRV) AxisEgmStop(X_AXIS);
- }
-
- if(KKQD_QIAN_LIMIT_IN && (KKQD_MotorStep == 0) && !KKQD_bBackMotor &&(KKQD_AutoStep == 0))
- {
- if(X_DRV)AxisEgmStop(X_AXIS);
- }
- }
- }
- void KK_QueDuan_AlarmProtect(void)
- {
- dwXRealPos = GetPos(X_AXIS);
- if(!bRunning)
- {
- ;
- }
- else
- {
- if(KKQD_PARAM_RUN_LENGTH < 5000)
- KKQD_PARAM_RUN_LENGTH= 5000;
- if((dwXRealPos > KKQD_PARAM_RUN_LENGTH) && (KK_cGoLimitEn != 0)) //第一条手动时不保护
- {
- //AxisEgmStop(X_AXIS);
- KK_cGoLimitEn = 0;
- bStop = 1;
- KKQD_StopStep = 1;
- KKQD_JD_VAVLE = 0;
- KKQD_SetAlarmCode(KKQD_BACK_ALARM);
- }
- }
- }
- void KK_QueDuan_AutoAction(void)
- {
- if(bRunning)
- {//台面电机定时关掉
- if(dwTickCount >= KKQD_TBDelay)
- KKQD_TABLE_VAVLE = 0;
- switch(KKQD_AutoStep)
- {
- case 1:
- if(dwTickCount >= KKQD_AutoDelay)
- {
- KKQD_AutoStep = 2;
- if(KKQD_MotorStep == 0)
- {
- KKQD_MotorStep = 61; //前点定位
- }
- KK_cGoLimitEn = 0;
- }
- break;
- case 2:
- if(KKQD_MotorStep == 0)
- {
- KKQD_MotorStep = 30;
- KKQD_AutoStep = 3;
- KK_cGoLimitEn = 1;
- }
- break;
- case 3: //后面两步为延时反转步
- if((KKQD_MotorStep == 0) || (KKQD_MotorStep == 390) || (KKQD_MotorStep == 391))
- {
- if(KKQD_SAFE_IN)
- {
- bStop = 1;
- }
- else
- {
-
- if(KKQD_XiaQieStep == 0)
- KKQD_XiaQieStep = 1;
- KKQD_AutoStep = 4;
- }
- }
- break;
- case 4:
-
- // if((KKQD_MACHINE_TYPE == KKQD_NO_GL_TUIFANGKUAI) || (KKQD_MACHINE_TYPE == KKQD_CS_TUIFANGKUAI))
- // {
- // 闭口
- if((KKQD_XiaQieStep == 0) || ((KKQD_XiaQieStep == 6) && (KKQD_PARAM_KAIBEE_SELECT == 1))|| ((KKQD_XiaQieStep == 13) && (KKQD_PARAM_KAIBEE_SELECT == 0)))// && !KKQD_SHANG_MU_LIMIT_IN)
- {
- if(KKQD_MotorStep == 0)
- {
- KKQD_MotorStep = 40; //切完后退
-
- }
- KKQD_AutoStep = 5;
- }
- /*
- // }
- // else
- // {
- if(((KKQD_XiaQieStep == 0) || (KKQD_XiaQieStep == 13)) && !KKQD_SHANG_MU_LIMIT_IN && !KKQD_XIA_MU_LIMIT_IN)
- {
- if(KKQD_MotorStep == 0)
- {
- KKQD_MotorStep = 40; //切完后退
- KKQD_AutoStep = 5;
- }
- }
- }
- */
- break;
- case 5:
- if(KKQD_MotorStep == 0)
- {
- KK_cZipCnt++;
- KKQD_PARAM_NOW_CNT++;
- KK_cTableCnt++;
- AddToTal(KKQD_TOTAL_ADDR);
- AddToTal(CT_WORKTOTAL_ADDR);
- CalProSP(KKQD_PROSPEED_ADDR);
-
- if(KK_cTableCnt >= KKQD_PARAM_TABLE_NUM)
- {
- KK_cTableCnt = 0;
- KKQD_TABLE_VAVLE = 1;
- KKQD_TBDelay = dwTickCount + KKQD_PARAM_TB_TIME;
- }
-
- if(/*(GetTotal(KKQD_TOTAL_ADDR) >= KKQD_PARAM_SET_TOTAL) ||*/KK_QDSingOneFlg)
- {
-
- bRunning = 0;
- KKQD_AutoStep = 0;
- KK_QDSingOneFlg = 0;
- KKQD_TABLE_VAVLE = 0;
-
- // if(GetTotal(KKQD_TOTAL_ADDR) >= KKQD_PARAM_SET_TOTAL) KKQD_SetAlarmCode(KKQD_TOTAL_ALARM);
- }
- else
-
- {
- KKQD_AutoStep = 1;
-
- if((KKQD_PARAM_NOW_CNT >= KKQD_PARAM_ZHA_SHU) && (KKQD_PARAM_ZHA_SHU > 0))
- {
- KKQD_AutoDelay = dwTickCount + KKQD_PARAM_ZS_STOP_TIME;
- KKQD_PARAM_NOW_CNT = 0;
- if(KKQD_PARAM_ZS_STOP_TIME == 0)
- {
- bRunning = 0;
- KKQD_AutoStep = 0;
- KK_QDSingOneFlg = 0;
- KKQD_SetAlarmCode(KKQD_TOTAL_ALARM);
- KKQD_TABLE_VAVLE = 0;
- }
- }
- else
- KKQD_AutoDelay = dwTickCount + KKQD_PARAM_CYCLE_DELAY;
- }
- }
- break;
- }
- }
- }
- void KK_QueDuan_StepCheckStart(void)
- {
- // 启动
- if((KKQD_START_IN_UP) || bStart || KKQD_bSingle)
- {
- bStart = 0;
-
- if(!bRunning && (KKQD_AutoStep == 0))
- {
- if((KKQD_XIA_MU_LIMIT_IN|| KKQD_KAIKUO_XIAMO_LIMIT_IN) && !KKQD_PARAM_XM_ENABLE)KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
-
- // else if(GetAlarmCode(KKQD_ALARM_ADDR) != 0);
- //else if(GetTotal(KKQD_TOTAL_ADDR) >= KKQD_PARAM_SET_TOTAL) KKQD_SetAlarmCode(KKQD_TOTAL_ALARM);
- // else if(KKQD_BL_VAVLE)KKQD_SetAlarmCode(KKQD_BL_ALARM);
- else if(KKQD_SM_VAVLE)KKQD_SetAlarmCode(KKQD_SM_ALARM);
- else
- {
- bRunning = 1;
- KKQD_AutoStep = 1;
- if(KKQD_bSingle)
- KK_QDSingOneFlg= 0;
- KK_cZipCnt = 0;
- KK_cTuiFangKuaiCnt = 0;
- KKQD_BL_VAVLE = 0; //并链关
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- SetAlarmCode(KKQD_ALARM_ADDR,0);
- KK_Motor_SZ(KKQD_MOTOR_EN); //电机锁轴
- KKQD_AutoDelay = dwTickCount + 150;
- }
- }
- KKQD_bSingle = 0;
- }
- //停止
- if((KKQD_STOP_IN_UP && (dwTickCount >= KKQD_STOPINDelay)) || bStop)
- {
- bStop = 0;
- KKQD_STOPINDelay = dwTickCount + 100;
- if(bRunning)
- {
- KKQD_AutoDelay = dwTickCount;
- KKQD_MotorDelay = dwTickCount;
- KKQD_XiaQieDelay = dwTickCount;
- KKQD_KaDaiDelay = dwTickCount;
- KKQD_CSDelay = dwTickCount;
- KKQD_TBDelay = dwTickCount;
- KKQD_TFKDelay = dwTickCount;
- KKQD_TLDelay = dwTickCount;
- KK_QDSingOneFlg = 0;
- KKQD_JD_VAVLE = 0;
- KKQD_SM_VAVLE = 0;
- KKQD_YD_VAVLE = 0;
- KKQD_TFK_VAVLE= 0;
- KKQD_TL_VAVLE = 0;
- // KKQD_HL_VAVLE = 0;
- KKQD_CS_OUT = 0;
- KKQD_XiaQieStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- KKQD_GZ_VAVLE = 0;
- KKQD_TABLE_VAVLE = 0;
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- if((KKQD_StopStep == 0) && X_DRV)
- KKQD_StopStep = 1;
- // AxisDecStop(X_AXIS);
- KKQD_BinLianStep = 0;
- KKQD_BL_VAVLE = 0;
- user_datas[121] = 0;
- user_datas[122] = 0;
-
- SetAlarmCode(KKQD_ALARM_ADDR,0);
- }
- else
- {
- KKQD_AutoDelay = dwTickCount;
- KKQD_MotorDelay = dwTickCount;
- KKQD_XiaQieDelay = dwTickCount;
- KKQD_KaDaiDelay = dwTickCount;
- KKQD_CSDelay = dwTickCount;
- KKQD_TBDelay = dwTickCount;
- KKQD_TFKDelay = dwTickCount;
- KKQD_TLDelay = dwTickCount;
- dwTickCount = KKQD_TBDelay;
- KK_QDSingOneFlg = 0;
- KKQD_JD_VAVLE = 0;
- KKQD_SM_VAVLE = 0;
- KKQD_XM_KAIKOU_VAVLE = 0;
- KKQD_YD_VAVLE = 0;
- KKQD_TFK_VAVLE= 0;
- // KKQD_YX_VAVLE = 0;
- // KKQD_HL_VAVLE = 0;
- KKQD_TL_VAVLE = 0;
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- KKQD_GZ_VAVLE = 0;
- KKQD_CS_OUT = 0;
- KKQD_XiaQieStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- KKQD_TABLE_VAVLE = 0;
-
- // KK_Motor_SZ(KKQD_MOTOR_DIS); //电机松轴
- if((KKQD_StopStep == 0))
- {
- AxisEgmStop(X_AXIS);
- KK_Motor_SZ(KKQD_MOTOR_DIS); //电机松轴
- }
-
- KKQD_BinLianStep = 0;
- KKQD_BL_VAVLE = 0;
- SetAlarmCode(KKQD_ALARM_ADDR,0);
- }
- bRunning = 0;
- KKQD_XiaQieStep = 0;
- KKQD_AutoStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- }
- if(bAlarmStop)
- {
- bAlarmStop = 0;
- KKQD_XiaQieStep = 0;
- KKQD_AutoStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
-
- KKQD_XiaQieStep = 0;
- KKQD_MotorStep = 0;
- KKQD_TuiLianStep = 0;
- KKQD_AutoDelay = dwTickCount;
- KKQD_MotorDelay = dwTickCount;
- KKQD_XiaQieDelay = dwTickCount;
- KKQD_KaDaiDelay = dwTickCount;
- KKQD_CSDelay = dwTickCount;
- KKQD_TBDelay = dwTickCount;
- KKQD_TFKDelay = dwTickCount;
- KKQD_TLDelay = dwTickCount;
- KK_QDSingOneFlg = 0;
- bRunning = 0;
- if(X_DRV)
- KKQD_StopStep=1;
- // AxisEgmStop(X_AXIS);
- dwTickCount = KKQD_TBDelay;
- KKQD_TABLE_VAVLE = 0;
- KKQD_JD_VAVLE=0;
- KKQD_GZ_VAVLE=0;
- }
-
- }
- //记忆长度模式误差检测
- void KK_QueDuan_CheckLength(long zip_length)
- {
- static long start_dist;
- switch(KKQD_CheckLengthStep)
- {
- case 0:break;
- case 1:
- start_dist = dwXRealPos;
- KK_dwSaveLength = 0;
- KKQD_CheckLengthStep = 2;
- break;
- case 2:
- if(KKQD_GUO_LIAN_IN_DW){
- KK_dwSaveLength = dwXRealPos - start_dist;
- }
- break;
- }
- }
- #if 1//!KKQD_KB_MODE //开口
- //开口切专用
- //30步开始后拉开始,分解4种工作模式
- //40步开始用切断后拉动作
- //60步开始为前方向,开闭口一样
- void KK_QueDuan_Motor_KK(void)
- {
- static long save_buff,length_buff,gou_zhen_buff,checkdelay_buff,dandao_buff,back_buff,gouzhen_buff,go_length_buff,jz_buff;
- unsigned short ch;
- user_datas[121]= KKQD_MotorStep;
- user_datas[122]= length_buff;
- user_datas[123] = dwXRealPos;
- user_datas[124] = KK_QDSingOneFlg;
- user_datas[125] = KKQD_AutoStep;
- user_datas[126] = KKQD_XiaQieStep;
- // user_datas[127] = KKQD_XiaQieStep;
- KK_QueDuan_CheckLength(length_buff);
-
- switch(KKQD_MotorStep)
- {
- case 30:
- switch(KKQD_PARAM_BACK_MODE) //开口分四种模式
- {
- case 0: //单数控模式
- KKQD_MotorStep = 310; //每种模式留20步
- KKQD_DGLG_VAVLE = 1; //顶过链杆关
- break;
- case 1://单感应模式
- KKQD_MotorStep = 330; //每种模式留20步
-
- break;
- case 2: //先感应后数控模式+检测
- KKQD_MotorStep = 350; //每种模式留20步
- break;
- default: //数控模式+过链检测长度
- KKQD_MotorStep = 370; //每种模式留20步
- break;
- }
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_DELAY_BACK;
- SetPos(X_AXIS, 0);
- dwXRealPos = 0;
- back_buff = 0;
- gou_zhen_buff = 0;
- save_buff = 0;
- break;
- //310步到315步为数控模式
- case 310:
- KKQD_MotorStep = 311;
- // KKQD_JZ_DIR = KKQD_YDIR_P;
- if(KKQD_PARAM_BL_ENABLE)
- KKQD_BinLianStep = 1; //并链起动
- break;
- case 311:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KK_length_buffer = &KKQD_PARAM_OFFSET_LENGTH;
- //李永庆代码
- //两段速度移动距离 拉链长度+慢速长度停止
- // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
- KK_DCC_TIME_BL = KKQD_PARAM_DCC + KKQD_PARAM_BACK_SPEED/500;
- AxisMovePosAccDec(X_AXIS,KKQD_PARAM_BACK_SPEED,KKQD_PARAM_ZIPPER_LENGTH + (*KK_length_buffer), KKQD_PARAM_START_SPEED,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_ACC,KK_DCC_TIME_BL,KKQD_PARAM_BACK_LOW_SPEED_LENGTH);
- KKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
- KKQD_MotorStep = 312;
- }
- break;
- case 312:
- if(dwXRealPos >= 10)
- KKQD_TL_VAVLE = 0;
- //勾针提前输出 ,争取时间推方块
- if (!KKQD_GZ_VAVLE && (dwXRealPos >= (KKQD_PARAM_ZIPPER_LENGTH- 230)))
- {
- KKQD_GZ_VAVLE = 1;
- KKQD_XM_KAIKOU_VAVLE=1;
- }
- //电机停止
- if(!X_DRV)
- {
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
- KKQD_MotorStep = 314;
- KKQD_BL_VAVLE = 0; //停止时并链一定要打开
- if((KKQD_PARAM_BACK_MODE == 2) && !KKQD_DGLG_VAVLE) //模式2,先检测长度后数控
- {//对比长度 ,发须要有过链信号,模式2,3. 模式0,1不用在这里对比长度
- if(KK_cZipCnt > 1) //长度检测
- {
- if(KKQD_PARAM_ERROR_LENGTH != 0) //长度误差值不能为0
- {
- if(((KK_dwSaveLength + KKQD_PARAM_MOTOR_DELAY_LENGTH) > (length_buff + KKQD_PARAM_ERROR_LENGTH)) || (KK_dwSaveLength == 0))
- {
- KKQD_SetAlarmCode(KKQD_LENGTH_LONG_ALARM);//拉链变长,对比警告
- }
- else if((KK_dwSaveLength + KKQD_PARAM_MOTOR_DELAY_LENGTH+ KKQD_PARAM_ERROR_LENGTH) < length_buff)
- {
- KKQD_SetAlarmCode(KKQD_LENGTH_SHORT_ALARM); ////拉链变短
- }
- KKQD_CheckLengthStep = 0;
- }
- }
- }
- }
- break;
- case 314:
- if(!X_DRV && (dwTickCount >= KKQD_MotorDelay)) //数控到停止
- {
- KKQD_MotorStep = 0;
- KKQD_TFK_VAVLE = 1; //推方块输出
- }
- break;
- //330步到349步单感应模式
- case 330:
- KKQD_MotorStep = 331;
- break;
- case 331:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KKQD_MotorStep = 332;
- if(KK_cZipCnt < 2)
- {
- if(KKQD_PARAM_BL_ENABLE)
- KKQD_BinLianStep = 10; //并链起动
- //第一条都是过链感应,后拉速度减半//原来KKQD_PARAM_CHECK_BACK_HSPEED/2
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,8000,KKQD_DIR_P,KKQD_PARAM_START_SPEED,KKQD_PARAM_START_SPEED,8,13);
-
- // 轴 第一段速度 第一段长度 第二段速度 第二段长度 方向
- // AxisMoveTwoPos(X_AXIS,KKQD_PARAM_BACK_SPEED,KKQD_PARAM_ZIPPER_LENGTH + (*KK_length_buffer)-KKQD_PARAM_BACK_LOW_SPEED_LENGTH,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED_LENGTH,KKQD_DIR_P);
-
- }
- else
- {
- KK_QD_DCC_TIME_BL = KKQD_PARAM_DCC+ KKQD_PARAM_CHECK_BACK_HSPEED/500;
- if(KKQD_PARAM_BL_ENABLE)
- KKQD_BinLianStep = 1; //并链起动
- //因为每条都是过链感应,所以直接运行检测模式后拉速度
- // X轴 运行速度 启动速度 停止速度 加速度 减速度
- //AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_CHECK_BACK_HSPEED,KKQD_DIR_P,KKQD_PARAM_START_SPEED,KKQD_PARAM_START_SPEED,KKQD_PARAM_ACC,KKQD_PARAM_DCC);
- AxisMovePosAccDecNotStop(X_AXIS,KKQD_PARAM_CHECK_BACK_HSPEED,KKQD_PARAM_ZIPPER_LENGTH , KKQD_PARAM_START_SPEED,KKQD_PARAM_START_SPEED*9/5,KKQD_PARAM_ACC,KK_QD_DCC_TIME_BL,KKQD_PARAM_BACK_LOW_SPEED_LENGTH + 500);
- }
- }
- break;
- case 332:
- if(dwXRealPos >= 10)
- KKQD_TL_VAVLE = 0;
- if(KK_cZipCnt > 1) //第二条开始数控降速
- {
-
- if(KKQD_GUO_LIAN_IN_DW) //重新到链上
- {
-
- AxisChangeSpeed(X_AXIS,KKQD_PARAM_BACK_LOW_SPEED);
- gou_zhen_buff = dwXRealPos;
- KKQD_MotorStep = 335; //到检测定位
- }
- //
- // if((dwXRealPos >= (KKQD_PARAM_BACK_LOW_SPEED_LENGTH + 60)) && KKQD_GUO_LIAN_IN)
- // {
-
- // }
- }
- else //第一条工作
- {
- if(KKQD_GUO_LIAN_IN_UP)
- {
- checkdelay_buff = dwXRealPos;
- AxisContinueMoveChangeSpeed(X_AXIS,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED/2,25,15);
-
- KKQD_MotorDelay = dwTickCount + 0;//KKQD_PARAM_DELAY_XM;
- KKQD_MotorStep = 333;
- }
- // else if((dwXRealPos >= KKQD_PARAM_RUN_LENGTH) && (KKQD_PARAM_RUN_LENGTH >= 5000)) //模组最长限制
- // {
- // KKQD_SetAlarmCode(KKQD_PARAM_RUN_LENGTH_ALARM); //超出轨道运行长度
- // }
- }
- break;
- case 333:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KKQD_MotorStep = 334;
- }
- break;
- case 334:
- if(KKQD_GUO_LIAN_IN_DW) //下降沿,定位长度
- {
- //滤波有待调试
- // if((((dwXRealPos - checkdelay_buff) >= KKQD_PARAM_DELAY_CHECK) && (KKQD_PARAM_LT_ENABLE)) || (((dwXRealPos - checkdelay_buff) >= KKQD_PARAM_NO_LT_DELAY_CHECK) && (KKQD_PARAM_LT_ENABLE == 0)))
- // {
- if(KKQD_GUO_LIAN_IN_DW)
- {
- gou_zhen_buff = dwXRealPos;
- KKQD_MotorStep = 335;
- }
- // }
- }
- break;
- case 335:
- if(KKQD_GUO_LIAN_IN_DW)
- {
- gou_zhen_buff = dwXRealPos;
-
- }
- //在空们都把延时清零
- if(KKQD_GUO_LIAN_IN)
- {
- gou_zhen_buff = dwXRealPos;
- }
- if(((dwXRealPos - gou_zhen_buff) >= KKQD_PARAM_MOTOR_DELAY_LENGTH/2) && !KKQD_GUO_LIAN_IN)
- {
- KKQD_GZ_VAVLE = 1;
- KKQD_XM_KAIKOU_VAVLE=1;
-
- }
- //定位停止
- if(((dwXRealPos - gou_zhen_buff) >= KKQD_PARAM_MOTOR_DELAY_LENGTH) && !KKQD_GUO_LIAN_IN)
- {
- AxisEgmStop(X_AXIS);
- KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- KKQD_MotorStep = 336;
- KKQD_GZ_VAVLE = 1;
-
- }
- break;
- case 336:
- if(!X_DRV)
- {
- KKQD_GZ_VAVLE = 1;
- KKQD_XM_KAIKOU_VAVLE=1;
- KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- //KKQD_XM_VAVLE = 1;
-
- KKQD_MotorStep = 337;
- }
- break;
- case 337:
- if(1)
- {
- KKQD_MotorStep = 338;
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
- }
- // else if(dwTickCount >= KKQD_MotorDelay) KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
- break;
- case 338:
- if((dwTickCount >= KKQD_MotorDelay))
- {
- KKQD_TFK_VAVLE = 1; //推方块输出
- KKQD_MotorStep = 339;
- KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- }
- break;
- case 339:
- if(KK_cZipCnt == 1)
- {
- length_buff = dwXRealPos - save_buff;
- SetData32bits(KKQD_PARAM_ZIPPER_LENGTH_ADDR,length_buff);
- }
- else if(KK_cZipCnt > 1) //长度检测
- {
- if(KKQD_PARAM_ERROR_LENGTH != 0) //长度误差值不能为0
- {
- if(dwXRealPos >= length_buff) //拉链变长,对比警告
- {
- if((dwXRealPos - save_buff) > (length_buff+KKQD_PARAM_ERROR_LENGTH))
- KKQD_SetAlarmCode(KKQD_LENGTH_LONG_ALARM);
- }
- else //拉链变短
- {
- if((dwXRealPos - save_buff + KKQD_PARAM_ERROR_LENGTH) < (length_buff))
- KKQD_SetAlarmCode(KKQD_LENGTH_SHORT_ALARM);
- }
- }
- }
- KKQD_MotorStep = 0;
- break;
- //350步到369步单感应模式
- case 350:
- back_buff = dwXRealPos;
- gou_zhen_buff = dwXRealPos;
-
- KKQD_MotorStep = 351;
- // KKQD_JZ_DIR = KKQD_YDIR_P;
-
-
- break;
- case 351:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KKQD_MotorStep = 352;
- //第一,二条都是过链感应,测量长度
- if(KK_cZipCnt < 2)
- {
- if(KKQD_PARAM_BL_ENABLE) //因为长度未知,只能通过过链退合链
- KKQD_BinLianStep = 10; //并链起动
- KKQD_DGLG_VAVLE = 0; //顶过链杆关
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,9000,KKQD_DIR_P,KKQD_PARAM_START_SPEED,KKQD_PARAM_START_SPEED,8,12);
-
- }
- else
- {
- if(KKQD_PARAM_BL_ENABLE)
- KKQD_BinLianStep = 1; //并链起动
- KKQD_DGLG_VAVLE = 1; //顶过链杆关
- KKQD_CheckLengthStep = 1; //长度检测,第3条才有对比
- //走数控方式,因第二条中已经测量出来拉链长度,可以直接按长度数控方式走
- KKQD_MotorStep = 311;
- }
- }
- break;
- case 352:
- if(dwXRealPos >= 10)
- KKQD_TL_VAVLE = 0;
- //前两条都按最低速度工作
- if(KKQD_GUO_LIAN_IN_UP)
- {
- checkdelay_buff = dwXRealPos;
- AxisContinueMoveChangeSpeed(X_AXIS,KKQD_PARAM_BACK_LOW_SPEED,KKQD_PARAM_BACK_LOW_SPEED/2,25,15);
-
-
-
- KKQD_MotorDelay = dwTickCount + 2;//因慢速,加8MS滤波
- KKQD_MotorStep = 353;
- }
- else if((dwXRealPos >= KKQD_PARAM_RUN_LENGTH) && (KKQD_PARAM_RUN_LENGTH >= 5000)) //模组最长限制
- {
- // KKQD_SetAlarmCode(KKQD_PARAM_RUN_LENGTH_ALARM); //超出轨道运行长度
- }
-
- break;
- case 353:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KKQD_MotorStep = 354;
- }
- break;
- case 354:
- if(KKQD_GUO_LIAN_IN_DW) //下降沿,定位长度
- {
- //滤波有待调试
- // if((((dwXRealPos - checkdelay_buff) >= KKQD_PARAM_DELAY_CHECK) && (KKQD_PARAM_LT_ENABLE)) || (((dwXRealPos - checkdelay_buff) >= KKQD_PARAM_NO_LT_DELAY_CHECK) && (KKQD_PARAM_LT_ENABLE == 0)))
- // {
- if(KKQD_GUO_LIAN_IN_DW)
- {
- gou_zhen_buff = dwXRealPos;
- KKQD_MotorStep = 355;
- }
- // }
- }
- break;
- case 355:
- if(KKQD_GUO_LIAN_IN_DW)
- {
- gou_zhen_buff = dwXRealPos;
-
- }
- //在空们都把延时清零
- if(KKQD_GUO_LIAN_IN)
- {
- gou_zhen_buff = dwXRealPos;
- }
- if(((dwXRealPos - gou_zhen_buff) >= KKQD_PARAM_MOTOR_DELAY_LENGTH/2) && !KKQD_GUO_LIAN_IN)
- {
- KKQD_GZ_VAVLE = 1;
- KKQD_XM_KAIKOU_VAVLE=1;
- }
- //定位停止
- if(((dwXRealPos - gou_zhen_buff) >= KKQD_PARAM_MOTOR_DELAY_LENGTH) && !KKQD_GUO_LIAN_IN)
- {
- AxisEgmStop(X_AXIS);
- KKQD_MotorStep = 356;
-
- }
- break;
- case 356:
- if(!X_DRV)
- {
- KKQD_GZ_VAVLE = 1;
- KKQD_XM_KAIKOU_VAVLE=1;
- KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- // KKQD_XM_VAVLE = 1;
- KKQD_MotorStep = 357;
- }
- break;
- case 357:
- if(1)
- {
- KKQD_MotorStep = 358;
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
- }
- break;
- case 358:
- if((dwTickCount >= KKQD_MotorDelay))
- {
- KKQD_TFK_VAVLE = 1; //推方块输出
- KKQD_MotorStep = 359;
- KKQD_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- }
- break;
- case 359:
- if(KK_cZipCnt == 1)
- {
- length_buff = dwXRealPos - save_buff;
- //测量出来长度
- SetData32bits(KKQD_PARAM_ZIPPER_LENGTH_ADDR,length_buff);
- }
- KKQD_MotorStep = 0;
- break;
- case 40:
- if(KKQD_PARAM_SJZ_LENGTH == 0)
- {
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_CUT_BACK_DELAY;
- KKQD_JD_VAVLE = 0;
- }
- else
- KKQD_MotorDelay = dwTickCount + 3;
- KKQD_MotorStep = 41;
- jz_buff = dwXRealPos;
- break;
- case 41:
- if((dwTickCount >= KKQD_MotorDelay))
- {
- //夹子已经张开
- AxisMovePosAccDec(X_AXIS,KKQD_PARAM_CUT_BACK_SPEED,(KKQD_PARAM_SJZ_LENGTH+KKQD_PARAM_BACK_LENGTH),1000,1000,10,10,0);
- KKQD_MotorStep = 42;
- }
- break;
- case 42:
-
- if( (dwXRealPos - jz_buff) >= KKQD_PARAM_SJZ_LENGTH)
- {
- KKQD_JD_VAVLE = 0;
- }
- if(!X_DRV)
- {
- KKQD_JD_VAVLE = 0;
- KKQD_MotorStep = 43;
- }
- break;
- case 43: // 切断完成后拉电机动作
- if(!X_DRV)
- {
- KKQD_MotorStep = 0;
- KKQD_MotorDelay = dwTickCount;
- }
- break;
- case 61: // 前点定位数控模式
- KKQD_BL_VAVLE = 0;//并链也要打开
- if(dwTickCount >= KKQD_MotorDelay)
- {
- // KKQD_JZ_DIR = KKQD_YDIR_N;
- if(!KKQD_TL_VAVLE && KK_cZipCnt && (KKQD_TuiLianStep == 0)) //没送链情况下主动送链
- {
- if(!KKQD_SHANG_MU_LIMIT_IN)
- {
- KKQD_TuiLianStep = 1;
- }
- }
- KKQD_MotorStep = 62;
- }
- break;
- case 62:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- if(KKQD_QIAN_LIMIT_IN)
- {
- //前点亮的情况下先后退离开信号后再前进定位 ,10公分
- AxisMovePosAccDec(X_AXIS,3000,1000,2000,2000,10,10,30);
- KKQD_MotorDelay = dwTickCount + 300;
- }
- KKQD_MotorStep = 63;
- KKQD_JD_VAVLE = 0;
- }
- break;
- case 63:
- if(!X_DRV && !KKQD_QIAN_LIMIT_IN && (dwTickCount >= KKQD_MotorDelay))// && !KKQD_SHANG_MU_LIMIT_IN)
- {
- KKQD_YD_VAVLE = 1;
- if(KK_cZipCnt > 0)
- {
- if(dwXRealPos>(KKQD_PARAM_GO_LOW_SPEED_LENGTH))
- {
-
- KK_DCC_TIME_BL = KKQD_PARAM_DCC + KKQD_PARAM_GO_HIGH_SPEED/500;
- AxisMovePosAccDecNotStop(X_AXIS,KKQD_PARAM_GO_HIGH_SPEED,-dwXRealPos,
- KKQD_PARAM_START_SPEED,KKQD_PARAM_GO_LOW_SPEED,KKQD_PARAM_ACC,KK_DCC_TIME_BL,
- KKQD_PARAM_GO_LOW_SPEED_LENGTH);
- }
- else
- {
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED/3,KKQD_PARAM_GO_LOW_SPEED/3,15,15);
-
- // MoveAction_Const_AccDec(X_AXIS, KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED_LENGTH,KKQD_PARAM_START_SPEED,KKQD_PARAM_ACC,KKQD_PARAM_DCC);
- }
-
- }
- else
- {
- // X轴 运行速度 启动速度 加速度 减速度
- AxisContinueMoveAcc(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,KKQD_DIR_N,KKQD_PARAM_GO_LOW_SPEED/3,KKQD_PARAM_GO_LOW_SPEED/3,15,15);
- // MoveAction_Const_AccDec(X_AXIS, KKQD_DIR_N,KKQD_PARAM_FIRST_GO_HIGHSPEED,KKQD_PARAM_START_SPEED,KKQD_PARAM_ACC,KKQD_PARAM_DCC);//
- }
-
- KKQD_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
- KKQD_MotorStep =64;
- }
-
- break;
- case 64:
- if(KK_cZipCnt > 1)
- {
-
- if(KKQD_QIAN_LIMIT_IN) //前点限位
- {
- if(KKQD_PARAM_GO_DW_LENGTH)
- {
- SetPos(X_AXIS, KKQD_PARAM_GO_DW_LENGTH);
- AxisMovePosAccDec(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,-KKQD_PARAM_GO_DW_LENGTH,1200,1000,5,5,00);
- }
- else
- AxisEgmStop(X_AXIS);
- KKQD_MotorStep = 66;
- }
- }
- else
- {
- if(KKQD_QIAN_LIMIT_IN) //前点限位
- {
- if(KKQD_PARAM_GO_DW_LENGTH)
- {
- SetPos(X_AXIS, KKQD_PARAM_GO_DW_LENGTH);
- AxisMovePosAccDec(X_AXIS,KKQD_PARAM_GO_LOW_SPEED,-KKQD_PARAM_GO_DW_LENGTH,1200,1000,5,5,00);
- }
- else
- AxisEgmStop(X_AXIS);
- KKQD_MotorStep = 66;
- }
- }
-
- break;
- case 66:
- if(!X_DRV || (dwXRealPos <= 0))
- {
- SetPos(X_AXIS, 0);
- KKQD_MotorDelay = dwTickCount + 5;
- KKQD_MotorStep = 67;
- }
- break;
- case 67: //等推链完成后,
- if((dwTickCount >= KKQD_MotorDelay) && (KKQD_TuiLianStep == 0) && ((KKQD_PARAM_TIAOSHI_MODE && KKQD_bTS) || (KKQD_PARAM_TIAOSHI_MODE == 0)) )
- {
- if(bRunning)
- {
- KKQD_JD_VAVLE = 1;
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_DELAY_BACK * 3/5;
- }
- KKQD_MotorStep = 68;
- }
- break;
- case 68:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KKQD_YD_VAVLE = 0;
- // KKQD_HL_VAVLE = 0;
- // KKQD_YX_VAVLE = 0;
-
- KKQD_MotorStep = 69;
- KKQD_MotorDelay = dwTickCount + KKQD_PARAM_DELAY_BACK*2/5;
- }
- break;
-
- case 69:
- if(dwTickCount >= KKQD_MotorDelay)
- {
- KKQD_MotorStep = 0;
- KKQD_MotorDelay = dwTickCount;
- }
- break;
- }
- }
- #endif
- void KK_QueDuan_BingLian(void)
- {
- static long bl_pos_buff,HL_delay;
-
- switch(KKQD_BinLianStep)
- {
- case 0:break;
- case 1:
- bl_pos_buff = dwXRealPos;
- KKQD_BinLianStep = 2;
- break;
- case 2:
- if((dwXRealPos - bl_pos_buff) >= KKQD_PARAM_DELAY_HL_LENGTH)
- {
- KKQD_BL_VAVLE = 1;
- KKQD_BinLianStep = 3;
- }
- break;
- case 3://有过链检测
- if(KKQD_GUO_LIAN_IN_DW || ((dwXRealPos - bl_pos_buff) >= (KKQD_PARAM_ZIPPER_LENGTH - KKQD_PARAM_HL_DELAY_BACK)))
- {
- KKQD_BL_VAVLE = 0;
- KKQD_BinLianStep = 0;
- }
- break;
- case 10:
- bl_pos_buff = dwXRealPos;
- KKQD_BinLianStep = 11;
- break;
- case 11:
- if((dwXRealPos - bl_pos_buff) >= KKQD_PARAM_DELAY_HL_LENGTH)
- {
- KKQD_BL_VAVLE = 1;
- KKQD_BinLianStep = 12;
- }
- break;
- case 12://有过链检测
- if(KKQD_GUO_LIAN_IN_DW)
- {
- KKQD_BL_VAVLE = 0;
- KKQD_BinLianStep = 0;
- }
- break;
- default:;
- }
-
- }
- //电机动作
- void KK_QueDuan_Motor(void)
- {
- KK_QueDuan_Motor_KK(); //
- }
- //超声方式下切,开口专用
- void KK_QueDuan_XiaQue_KK(void)
- {
- switch(KKQD_XiaQieStep)
- {
- case 0:
- break;
- case 1:
-
- if(bRunning)
- {
- KKQD_XiaQieStep = 6;
- KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
- }
- else
- KKQD_XiaQieStep = 2;
- break;
- case 2:
- KKQD_XM_KAIKOU_VAVLE=1;
- KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
- KKQD_XiaQieStep = 3;
- break;
- case 3:
- if(KKQD_KAIKUO_XIAMO_LIMIT_IN || KKQD_PARAM_XM_ENABLE)
- {
- KKQD_XiaQieDelay = dwTickCount + 0;//KKQD_PARAM_GZ_DELAY;
- KKQD_XiaQieStep = 4;
- }
- else if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
- }
- break;
- case 4:
- if(KKQD_GZ_VAVLE) //勾针已经有输出就不需要延时
- {
- KKQD_XiaQieDelay = dwTickCount + 0;
- }
- else
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_TFK_DELAY;
- KKQD_GZ_VAVLE = 1;
- KK_cTuiFangKuaiCnt=0;
- KKQD_XiaQieStep = 5;
- break;
- case 5:
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_TFK_VAVLE = 1;
- KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
- KKQD_XiaQieStep = 6;
- }
- break;
- case 6:
- if(1)
- {
- KKQD_XiaQieStep = 7;
- KKQD_XiaQieDelay = dwTickCount + 1000;
- }
- else if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
- }
- break;
- case 7:
- if(KKQD_GOUZHEN_IN)
- {
- KK_cTuiFangKuaiCnt = 0;
- KKQD_YD_VAVLE = 1;
- if(!bRunning)
- KKQD_XiaQieDelay = dwTickCount + 200;
- else
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_CUT_DELAY;
-
- if(!KKQD_QIAN_LIMIT_IN)
- KKQD_XiaQieStep = 8;
- else
- KKQD_SetAlarmCode(KKQD_QIAN_LIMIT_ALARM);
- }
- else if((dwTickCount >= KKQD_XiaQieDelay))
- {
- if(KK_cTuiFangKuaiCnt < KKQD_PARAM_TFK_NUMBER)
- {
- KKQD_TFK_VAVLE = 0;
- KK_cTuiFangKuaiCnt++;
- KKQD_XiaQieDelay = dwTickCount + 500;
- KKQD_XiaQieStep = 100;
- }
- else
-
- KKQD_SetAlarmCode(KKQD_GZ_ALARM);
- }
- break;
- case 100:
- if((dwTickCount >= KKQD_XiaQieDelay))
- {
- KKQD_XiaQieStep = 5;
- }
- break;
- case 8://上下模同时输出
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_SM_VAVLE = 1;
- if(KKQD_PARAM_XM_ENABLE == 0) //配置下模动
- KKQD_XM_KAIKOU_VAVLE = 1;
- KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
- KKQD_XiaQieStep = 9;
- }
- break;
- case 9://上下模到位,调试模下的话,等按下一步按键 下模不动
- if(KKQD_SHANG_MU_LIMIT_IN && (KKQD_KAIKUO_XIAMO_LIMIT_IN || KKQD_PARAM_XM_ENABLE) && ((KKQD_PARAM_TIAOSHI_MODE && KKQD_bTS) || (KKQD_PARAM_TIAOSHI_MODE == 0)) )
- {
- if(!KKQD_PARAM_CS_MODE) //无超声配置
- {
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_DELAYBACK_SM; //
- KKQD_XiaQieStep = 12;
- }
- else
- {
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_DELAY_CS; //
- KKQD_XiaQieStep = 10;
- }
- }
- else if(dwTickCount >= KKQD_XiaQieDelay)
- {
- if(!KKQD_SHANG_MU_LIMIT_IN)KKQD_SetAlarmCode(KKQD_SM_DAOWEI);
- else KKQD_SetAlarmCode(KKQD_XM_DAOWEI);
- }
- break;
- case 10:
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
-
- KKQD_CS_OUT = 1;
- //
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_CS_TIME; //
- KKQD_XiaQieStep = 11;
- }
- break;
- case 11:
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_CS_OUT = 0;
- KKQD_XiaQieDelay = dwTickCount + KKQD_PARAM_CS_COLD_TIME; //
- KKQD_XiaQieStep = 12;
- }
- break;
- case 12:
- if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_SM_VAVLE = 0;
- if(KKQD_PARAM_XM_ENABLE == 0) //配置下模动
- KKQD_XM_KAIKOU_VAVLE=0;
- KKQD_TFK_VAVLE = 0;
- KKQD_GZ_VAVLE = 0;
- KKQD_XiaQieDelay = dwTickCount + VAVLE_ALARM_TIME;
- KKQD_XiaQieStep = 13;
- }//
- break;
- case 13:
- if(!KKQD_SHANG_MU_LIMIT_IN)
- {
- //启动推链(送链)
- if((KKQD_TuiLianStep == 0) && !KKQD_TL_VAVLE)
- KKQD_TuiLianStep = 1;
- }
- if(!KKQD_SHANG_MU_LIMIT_IN && (!KKQD_KAIKUO_XIAMO_LIMIT_IN || KKQD_PARAM_XM_ENABLE))
- {
- KKQD_XiaQieStep = 0;
- }
- else if(dwTickCount >= KKQD_XiaQieDelay)
- {
- KKQD_SetAlarmCode(KKQD_SM_YUANWEI);
- }
- break;
- }
- }
- void KK_QueDuan_TuiLianAction(void)
- {
- if(KKQD_PARAM_XM_ENABLE == 0) //下模动不用推链动作
- {
- KKQD_TuiLianStep = 0;
- }
- else
- {
- switch(KKQD_TuiLianStep)
- {
- case 1:
- KKQD_TuiLianStep = 2;
- break;
- case 2:
- KKQD_TLDelay = dwTickCount + KKQD_PARAM_YD_DELAY;
- KKQD_TuiLianStep = 3;
- break;
- case 3:
- if(!KKQD_SM_VAVLE && !KKQD_SHANG_MU_LIMIT_IN)//dwTickCount >= KKQD_TLDelay)
- {
- KKQD_TL_VAVLE = 1;
- if(!bRunning)KKQD_TFK_VAVLE = 0;
- KKQD_TLDelay = dwTickCount + KKQD_PARAM_TL_DELAY;
- KKQD_TuiLianStep = 4;
- }
- break;
- case 4:
- if(dwTickCount >= KKQD_TLDelay)
- {
- KKQD_TuiLianStep = 0;
- }
- break;
- }
- }
- }
- //切断动作
- void KK_QueDuan_XiaQue(void)
- {
- KK_QueDuan_XiaQue_KK();
-
- }
- #endif
|