123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989 |
- #include "global.h"
- #if JIN_HONG_MACHINE
- void JSDC_CheckStart(void);
- void JSDC_Motor(void);
- void JSDC_XiaChong(void);
- void JSDC_FenZhen(void);
- void JSDC_ChuiQi(void);
- void JSDC_SD(void);
- void JSDC_ManualAction(void);
- void JSDC_AutoAction(void);
- unsigned char JSDC_CheckPos(void);
- unsigned long JSDC_cZipperLength[2];
- unsigned char JSDC_cCheckLengthOk=0;
- unsigned char JSDC_STOP_IN_FLAG,JSDC_STOP_IN_FLAG_OLD,JSDC_STOP_FILTER;
- unsigned char JSDC_SingOneFlag = 0,JSDC_FirstFlg = 0;
- unsigned char JSDC_cAlarmStopFlg = 0;
- long JSDC_dwEncPos = 0;
- long JSDC_SaveLength = 0;
- unsigned short JSDC_cRFengTimer,JSDC_cLFengTimer;
- //故障报警
- void JSDC_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(JSDC_ALARM_ADDR,alarm_code);
- JSDC_bAlarmStop = 1;
- JSDC_cAlarmStopFlg = 1;
- }
- //高速输入X20外部色标信号中断
- void JSDC_ExtiActionX20(void)
- {
- }
- void JSDC_InitAction(void)
- {
- float length_buff,pulse_buff;
-
- CalFreqTab_X_Free(25);
- length_buff = JSDC_PARAM_DAILUN_LENGTH;
- pulse_buff = JSDC_PARAM_CYCLE_PULSE;
- XGearRatio = pulse_buff/length_buff;
-
- length_buff = JSDC_BM_LENGTH;
- pulse_buff = 1000;
- BMGearRatio = pulse_buff/length_buff;
-
- JSDC_SZ_OUT = JSDC_SERVER_DISEN;
-
- JSDC_STOP_IN_FLAG = STOP_IN;
- JSDC_STOP_IN_FLAG_OLD = JSDC_STOP_IN_FLAG;
- JSDC_SaveLength = 0;
- }
- void JSDC_Action(void)
- {
- JSDC_CheckStart(); //启动
- JSDC_FenZhen(); //左分针
- JSDC_XiaChong(); //下冲
- JSDC_ChuiQi();
- JSDC_SD();
- JSDC_Motor(); //拖带控制
- JSDC_ManualAction();
- JSDC_AutoAction();
- }
- void JSDC_ManualAction(void)
- {
- long i;
- short *len_buff;
- //清总产量
- if(JSDC_bClear) //清总产量
- {
- JSDC_bClear = 0;
- ClrcToTal(JSDC_TOTAL_ADDR);
- JSDC_bSaveWorkData = 1;
- }
- //当长度改变时,生产总量自动清零
- if(JSDC_bChangeLength)
- {
- JSDC_bChangeLength = 0;
- JSDC_SaveLength = 0;
- JSDC_bClear = 1;
- }
- //加10
- if(JSDC_bAddLength)
- {
- JSDC_bAddLength = 0;
- i = JSDC_SET_ALL_LENGTH;
- i += 10;
- SetData32bits(20,i);
- SetData32bits(22,CalInch(JSDC_SET_ALL_LENGTH));
- }
- //减10
- if(JSDC_bDecLength)
- {
- JSDC_bDecLength = 0;
- i = JSDC_SET_ALL_LENGTH;
- i -= 10;
- SetData32bits(20,i);
- SetData32bits(22,CalInch(JSDC_SET_ALL_LENGTH));
- }
- //工作方式选择(数控定寸和勾针定寸)
- if(JSDC_bSetDCMode)
- {
- JSDC_bSetDCMode = 0;
- JSDC_SaveLength = 0;
- if(JSDC_DC_MODE != 0)
- {
- JSDC_GouZhen_VAVLE = 1;
- JSDC_cGouZhenTime = 300;
- }
-
- if(JSDC_DC_MODE == JSDC_DC_SF_MODE)
- {
- MV_Set_Command_Pos_CPU(X_AXIS,0);
- }
- }
- if(JSDC_bSetLength)
- {
- JSDC_bSetLength = 0;
- SetData32bits(18,CalInch(JSDC_SET_ZIPPER_LENGTH));
- JSDC_PARAM_KONG_WEI_LENGTH_INCH = CalInch(JSDC_PARAM_KONG_WEI_LENGTH);
- SetData32bits(20,JSDC_SET_ZIPPER_LENGTH+JSDC_PARAM_KONG_WEI_LENGTH);
- SetData32bits(22,CalInch(JSDC_SET_ZIPPER_LENGTH+JSDC_PARAM_KONG_WEI_LENGTH));
- JSDC_SaveLength = 0;
- }
-
- if((JSDC_bRunning) == 0) ////手动
- {
- if(JSDC_bXiaChong || JSDC_Man_XiaChong_IN_UP)
- {
- JSDC_bXiaChong = 0;
- JSDC_SaveLength = 0;
- if(JSDC_cXiaChongStep == 0)JSDC_cXiaChongStep = 1;
- }
-
- if(JSDC_bLeftFenZhen)
- {
- JSDC_bLeftFenZhen = 0;
-
- if(JSDC_cXiaChongStep == 0) JSDC_LeftFenZhen_VAVLE = ~JSDC_LeftFenZhen_VAVLE;
-
- }
-
- if(JSDC_bChuiQi)
- {
- JSDC_bChuiQi = 0;
- if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
- }
-
- if(JSDC_bYD)
- {
- JSDC_bYD = 0;
- JSDC_YD_VAVLE = ~JSDC_YD_VAVLE;
- }
- if(JSDC_bRightFenZhen)
- {
- JSDC_bRightFenZhen = 0;
-
- if(JSDC_cXiaChongStep == 0) JSDC_RightFenZhen_VAVLE = ~JSDC_RightFenZhen_VAVLE;
-
- }
-
- if(JSDC_bLeftSongDai)
- {
- JSDC_bLeftSongDai = 0;
- JSDC_Left_SD = ~JSDC_Left_SD;
- }
- //点动下冲
- if((JSDC_bDotXiaChong))
- {
- JSDC_bDotXiaChong = 0;
- if(JSDC_cXiaChongStep == 0)JSDC_cXiaChongStep = 20;
- }
- if(JSDC_bGouZhen)
- {
- JSDC_bGouZhen = 0;
- JSDC_cGouZhenTime = dwTickCount + 300;
- JSDC_GouZhen_VAVLE = ~JSDC_GouZhen_VAVLE;
- }
-
- if(JSDC_DC_MODE != JSDC_DC_GZ_MODE)
- {
- JSDC_GouZhen_VAVLE = 1;
- }
- else
- {
- if(dwTickCount >= JSDC_cGouZhenTime) JSDC_GouZhen_VAVLE = 0;
- }
-
- if(JSDC_bTestMotor)
- {
- if(!X_DRV && JSDC_CheckPos())
- {
- MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P, 10,1,5,5);
- if(JSDC_cSDStep == 0)JSDC_cSDStep = 1;
- }
- }
- else
- {
- if(X_DRV)
- {
- AxisDecStop(X_AXIS);
- JSDC_cSDStep = 0;
- }
- }
- }
- }
- void JSDC_AutoAction(void)
- {
- if(JSDC_bRunning)
- {
- switch(JSDC_cAutoStep)
- {
- case 0:
- break;
- case 1:
- if(dwTickCount >= JSDC_cAutoDelay)
- {
- JSDC_cAutoStep = 2;
- }
- break;
- case 2:
- //左右分针要退到位,过链到位要离开
- if(dwTickCount >= JSDC_cAutoDelay)
- {
- JSDC_cAutoStep = 3;
- switch(JSDC_DC_MODE)
- {
- case JSDC_DC_SF_MODE:JSDC_cMotorStep = 20; break; //伺服
- case JSDC_DC_BMQ_MODE:JSDC_cMotorStep = 60; break; //编码器
- default:JSDC_cMotorStep = 1; //启动拖带 ;//勾针
- }
-
- }
- break;
- case 3:
- //拖带已经完成
- if(JSDC_cMotorStep == 0)
- {
- {
- JSDC_cAutoStep = 4;
- }
- }
- break;
- case 4:
- JSDC_cAutoStep = 5;
- break;
- case 5:
- if(JSDC_cXiaChongStep == 0)
- {
- JSDC_cXiaChongStep = 1; //下冲电机启动
- JSDC_cAutoStep = 6;
- }
- break;
- case 6: //下冲已完成
- if(JSDC_cXiaChongStep == 0)
- {
- if(JSDC_DC_MODE == JSDC_DC_BMQ_MODE)
- {
- JSDC_SaveLength += JSDC_PARAM_DAOKOU_LENGTH;
- if(JSDC_SaveLength >= JSDC_PARAM_KONG_WEI_LENGTH)
- {
- dwZipCnt++;
- JSDC_SaveLength = 0;
- AddToTal(JSDC_TOTAL_ADDR); //计数增加和保存
- CalProSP(JSDC_PROSPEED_ADDR);
- JSDC_cAutoStep = 7;
- }
- else
- {
- if((JSDC_PARAM_KONG_WEI_LENGTH - JSDC_SaveLength) >= JSDC_PARAM_DAOKOU_LENGTH)
- {
- JSDC_cAutoStep = 2;
- }
- else
- {
- JSDC_SaveLength = JSDC_PARAM_KONG_WEI_LENGTH - JSDC_PARAM_DAOKOU_LENGTH;
- JSDC_cAutoStep = 2;
- }
- }
- }
- else
- {
- dwZipCnt++;
- JSDC_SaveLength = 0;
- AddToTal(JSDC_TOTAL_ADDR); //计数增加和保存
- CalProSP(JSDC_PROSPEED_ADDR);
- JSDC_cAutoStep = 7;
- }
- }
- break;
- case 7:
- if(!JSDC_GouZhen_IN)
- {
- if(GetTotal(JSDC_TOTAL_ADDR) >= JSDC_SET_TOTAL)JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
- JSDC_cAutoStep = 8;
- }
- break;
- case 8:
- JSDC_cAutoDelay = dwTickCount + JSDC_PARAM_MOTOR_DELAY;
- JSDC_cAutoStep = 1;
- if(JSDC_SingOneFlag)
- {
- dwZipCnt = 0;
- JSDC_SingOneFlag = 0;
- JSDC_cAutoStep = 0;
- JSDC_bRunning = 0;
- }
-
- break;
- }
- }
- }
- void JSDC_SD(void)
- {
- }
- // 检测是否踏了脚踏开关
- void JSDC_CheckStart(void)
- {
- // 停止键 不能在工作,手动,停止过程中
- if((JSDC_bRunning == 0) && (START_IN_UP || JSDC_bStart || JSDC_bNext))
- {
- if(GetTotal(JSDC_TOTAL_ADDR) >= JSDC_SET_TOTAL)JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
- else if((JSDC_PARAM_SEBIAO_DW_LENGTH > JSDC_SET_ZIPPER_LENGTH) && (JSDC_DC_MODE==2))JSDC_SetAlarmCode(JSDC_SEBIAO_ZIPPER_LENGTH_ALARM);
- else if(JSDC_KaDai_IN)JSDC_SetAlarmCode(JSDC_KA_DAI_ALARM);
- else
- {
- if(JSDC_bNext)
- {
- JSDC_SingOneFlag = 1;
- JSDC_bNext = 0;
- }
- JSDC_bRunning = 1;
- JSDC_cAutoStep = 1;
- if(JSDC_cSDStep == 0)JSDC_cSDStep = 1;
- JSDC_cGouZhenTime = 1;
- JSDC_cCheckLengthOk = 0;
- JSDC_cZipperLength[0] = 0;
- JSDC_cZipperLength[1] = 0;
- dwZipCnt = 0;
- JSDC_cAutoDelay = dwTickCount;
- JSDC_cMotorDelay = dwTickCount;
- JSDC_cXiaChongDelay = dwTickCount;
- if(GetAlarmCode(JSDC_ALARM_ADDR) != 0)SetAlarmCode(JSDC_ALARM_ADDR,0);
- }
- JSDC_bStart = 0;
- }
- //卡带感应
- if(JSDC_KaDai_IN)
- JSDC_SetAlarmCode(JSDC_KA_DAI_ALARM);
- else
- {
- if(GetAlarmCode(JSDC_ALARM_ADDR) == JSDC_KA_DAI_ALARM)SetAlarmCode(JSDC_ALARM_ADDR,0);
- }
-
- if(JSDC_KaDai_IN_UP)
- {
- if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
- }
- //停止
- JSDC_STOP_IN_FLAG_OLD = JSDC_STOP_IN_FLAG;
-
- if(STOP_IN)
- {
- if(JSDC_STOP_FILTER < 50)
- {
- JSDC_STOP_FILTER++;
- }
- else
- JSDC_STOP_IN_FLAG = 1;
- }
- else if(JSDC_STOP_FILTER > 25)
- {
- JSDC_STOP_FILTER--;
- }
- else
- JSDC_STOP_IN_FLAG = 0;
-
- if(JSDC_bStop)
- {
- JSDC_bStop = 0;
- if(JSDC_bRunning)JSDC_SingOneFlag = 1;
- }
-
-
-
- if(((JSDC_STOP_IN_FLAG && !JSDC_STOP_IN_FLAG_OLD)))
- {
- JSDC_bStop = 0;
- if(JSDC_bRunning)
- {
- if(JSDC_cXiaChongStep==0)
- {
- if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
-
- // if(!JSDC_XiaChong_MOTOR)JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
- }
-
- JSDC_bRunning = 0;
- JSDC_cAutoStep = 0;
- JSDC_cMotorStep = 0;
- JSDC_cSDStep = 0;
- JSDC_cSDStep = 0;
- JSDC_SD_MOTOR = 0;
- AxisEgmStop(X_AXIS);
- JSDC_cJiaoDaoStep = 0;
- JSDC_SingOneFlag = 0;
- }
- else
- {
- JSDC_bRunning = 0;
- JSDC_cAutoStep = 0;
- JSDC_cMotorStep = 0;
- JSDC_cXiaChongStep = 0;
- JSDC_cLeftFenZhenStep = 0;
- JSDC_cRightFenZhenStep = 0;
- JSDC_cJiaoDaoStep = 0;
- JSDC_cSDStep = 0;
- JSDC_SD_MOTOR = 0;
- JSDC_LeftFenZhen_VAVLE = 0;
- JSDC_RightFenZhen_VAVLE = 0;
- JSDC_XiaChong_MOTOR = 0;
- JSDC_YD_VAVLE = 0;
- JSDC_Left_SD = 0;
- JSDC_SingOneFlag = 0;
-
- if((JSDC_cChuiQiStep == 0) &&(JSDC_cXiaChongStep==0))JSDC_cChuiQiStep = 1;
- AxisEgmStop(X_AXIS);
- SetAlarmCode(JSDC_ALARM_ADDR,JSDC_NO_ALARM);
- }
- }
-
- if(JSDC_bAlarmStop)
- {
- JSDC_bAlarmStop = 0;
- JSDC_bRunning = 0;
- JSDC_cAutoStep = 0;
- JSDC_cMotorStep = 0;
- JSDC_cLeftFenZhenStep = 0;
- JSDC_cRightFenZhenStep = 0;
- JSDC_LeftFenZhen_VAVLE = 0;
- JSDC_RightFenZhen_VAVLE = 0;
- JSDC_SingOneFlag = 0;
- JSDC_cSDStep = 0;
- JSDC_SD_MOTOR = 0;
- AxisEgmStop(X_AXIS);
- }
- }
- void JSDC_ChuiQi(void)
- {
- //吹气
- if(JSDC_XiaChong_IN_UP)
- {
- if(JSDC_cChuiQiStep == 0)JSDC_cChuiQiStep = 1;
- }
-
- switch(JSDC_cChuiQiStep)
- {
- case 1:
- JSDC_cChuiQiStep = 2;
- if(JSDC_bRunning)JSDC_cChuiQiDelay = dwTickCount+JSDC_PARAM_DELAY_CHUIQI_TIME;
- break;
- case 2:
- if(dwTickCount >= JSDC_cChuiQiDelay)
- {
- JSDC_cChuiQiDelay = dwTickCount + JSDC_PARAM_CHUIQI_TIME;
- JSDC_ChuiQi_VAVLE = 1;//
- JSDC_cChuiQiStep = 3;
- }
- break;
- case 3:
- if(dwTickCount >= JSDC_cChuiQiDelay)
- {
- JSDC_ChuiQi_VAVLE = 0;//
- JSDC_cChuiQiStep = 0;
- }
- break;
- }
- }
- unsigned char JSDC_ComPareLength(void)
- {
- if((JSDC_cZipperLength[0] != 0) && (JSDC_cZipperLength[1] != 0))
- {
- if(JSDC_cZipperLength[0] > JSDC_cZipperLength[1])
- {
- if((JSDC_cZipperLength[0] - JSDC_cZipperLength[1]) > 200)
- {
- return 0;
- }
- else
- return 1;
- }
- else
- {
- if((JSDC_cZipperLength[1] - JSDC_cZipperLength[0]) > 200)
- {
- return 0;
- }
- else
- return 1;
- }
- }
- else
- return 0;
- }
- unsigned char JSDC_CheckPos(void)
- {
- unsigned long zipper_length;
- short *revise_buff;
- if(JSDC_DC_MODE == JSDC_DC_GZ_MODE)
- {
- if(JSDC_GouZhen_IN)
- return 0;
- else
- return 1;
- }
- else
- {
- revise_buff = &user_datas[17];
- zipper_length = JSDC_SET_ZIPPER_LENGTH + (*revise_buff) + JSDC_PARAM_DAOKOU_LENGTH;
- if(JSDC_dwEncPos >= zipper_length)return 0;
- else
- return 1;
- }
- }
- void JSDC_Motor(void)
- {
- static long save_buff,gou_zhen_buff,zipper_length_buff;
- static unsigned long zipper_length;
- short *revise_buff;
- DISPLAY_DATA0 = JSDC_cAutoStep;
- DISPLAY_DATA1 = JSDC_cMotorStep;
- DISPLAY_DATA2 = JSDC_cLeftFenZhenStep;
- DISPLAY_DATA3 = JSDC_cRightFenZhenStep;
- DISPLAY_DATA4 = JSDC_cXiaChongStep;
- DISPLAY_DATA5 = dwRealPos;
- DISPLAY_DATA6 = JSDC_dwEncPos;
- // DISPLAY_DATA7 = user_datas[100];
- dwRealPos = GetPos(X_AXIS);
- JSDC_dwEncPos = GetEncodePos();
-
- if(JSDC_DC_MODE == JSDC_DC_BMQ_MODE)
- SetData32bits(JSDC_NOW_POS_ADDR,JSDC_dwEncPos);
- else
- SetData32bits(JSDC_NOW_POS_ADDR,dwRealPos);
-
- if(!JSDC_bRunning)
- {
- if(JSDC_CheckPos() == 0)AxisEgmStop(X_AXIS);
- }
-
- switch(JSDC_cMotorStep)
- {
- case 0:
- break;
- case 1:
- if(JSDC_SZ_OUT == JSDC_SERVER_DISEN)
- {
- JSDC_SZ_OUT = JSDC_SERVER_EN;
- JSDC_cMotorDelay = dwTickCount + 50; //先锁轴
- }
- JSDC_cMotorStep = 2;
- break;
- case 2://勾针模式
- if(dwTickCount >= JSDC_cMotorDelay)
- {
- save_buff = dwRealPos;
- if(JSDC_cCheckLengthOk)
- {
- MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P,JSDC_PARAM_SET_SPEED,1,5,1);
- }
- else
- {
- if(JSDC_cCheckLengthOk == 0)
- {
- JSDC_cZipperLength[0] = JSDC_cZipperLength[1];
- JSDC_cZipperLength[1] = dwRealPos - zipper_length_buff;
- zipper_length_buff = dwRealPos;
- if(JSDC_ComPareLength())
- {
- JSDC_cCheckLengthOk = 1;
- }
- }
- if(JSDC_cCheckLengthOk)zipper_length = JSDC_cZipperLength[1];
- MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P,JSDC_PARAM_FIRST_SPEED,1,5,1);
- }
- JSDC_cMotorDelay = dwTickCount + JSDC_PARAM_MOTOR_ALARM_TIME;
- JSDC_cGouZhenTime = dwTickCount + 300;
- JSDC_cMotorStep = 3;
- }
- break;
- case 3:
- if(((dwTickCount >= JSDC_cGouZhenTime)&&(JSDC_PARAM_GZ_RESET_MODE==0)) || (JSDC_cCheckLengthOk == 0))JSDC_GouZhen_VAVLE = 0;
- if(JSDC_cCheckLengthOk)
- {
- if(((dwRealPos - save_buff) >= (zipper_length - JSDC_PARAM_GZ_LENGTH))&&JSDC_PARAM_GZ_RESET_MODE)JSDC_GouZhen_VAVLE = 0;
-
- if((dwRealPos - save_buff) >= (zipper_length - JSDC_PARAM_LOWSPEED_LENGTH))
- {
- AxisChangeSpeed(X_AXIS,JSDC_PARAM_LOW_SPEED);
- JSDC_cMotorStep = 4;
- }
- }
- else
- {
- if(JSDC_GouZhen_IN)
- {
- JSDC_GouZhen_VAVLE = 0;
- JSDC_cMotorStep = 5;
- AxisEgmStop(X_AXIS);
- }
- else
- {
- if(dwTickCount >= JSDC_cGouZhenTime)JSDC_GouZhen_VAVLE = 0;
- JSDC_cMotorStep = 4;
- }
- }
-
- if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 4:
- if(((dwTickCount >= JSDC_cGouZhenTime)&&(JSDC_PARAM_GZ_RESET_MODE==0)) || (JSDC_cCheckLengthOk == 0))JSDC_GouZhen_VAVLE = 0;
- if(((dwRealPos - save_buff) >= (zipper_length - JSDC_PARAM_GZ_LENGTH))&&JSDC_PARAM_GZ_RESET_MODE &&JSDC_cCheckLengthOk)JSDC_GouZhen_VAVLE = 0;
-
- if(JSDC_GouZhen_IN)
- {
- JSDC_GouZhen_VAVLE = 0;
- JSDC_cMotorStep = 5;
- AxisEgmStop(X_AXIS);
- }
-
- if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 5:
- if(((dwTickCount >= JSDC_cGouZhenTime)&&(JSDC_PARAM_GZ_RESET_MODE==0)) || (JSDC_cCheckLengthOk == 0))JSDC_GouZhen_VAVLE = 0;
- if(!X_DRV)
- {
- JSDC_cMotorStep = 0;
- JSDC_cMotorDelay = dwTickCount;
- }
- else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 20:
- if(JSDC_SZ_OUT == JSDC_SERVER_DISEN)
- {
- JSDC_SZ_OUT = JSDC_SERVER_EN;
- JSDC_cMotorDelay = dwTickCount + 50; //先锁轴
- }
- JSDC_cMotorStep = 21;
- break;
- case 21:
- if(dwTickCount >= JSDC_cMotorDelay) //电机定寸模式
- {
- if(JSDC_cAlarmStopFlg)
- {
- zipper_length = JSDC_SET_ALL_LENGTH - JSDC_PARAM_KONG_WEI_LENGTH + JSDC_PARAM_DAOKOU_LENGTH;
- JSDC_cAlarmStopFlg = 0;
- }
- else
- {
- zipper_length = JSDC_SET_ALL_LENGTH - JSDC_PARAM_KONG_WEI_LENGTH + JSDC_PARAM_DAOKOU_LENGTH;
- if((0 - dwRealPos) > zipper_length)
- zipper_length = JSDC_SET_ALL_LENGTH - JSDC_PARAM_KONG_WEI_LENGTH + JSDC_PARAM_DAOKOU_LENGTH;
- else
- zipper_length = JSDC_SET_ALL_LENGTH - JSDC_PARAM_KONG_WEI_LENGTH + JSDC_PARAM_DAOKOU_LENGTH - (0 - dwRealPos);
- }
- AxisMovePosAccDec(X_AXIS,JSDC_PARAM_SET_SPEED,zipper_length,1,5,1);
- JSDC_GouZhen_VAVLE = 1; //定位(活动勾针)电磁阀
- JSDC_cMotorStep = 22;
- JSDC_cMotorDelay = dwTickCount + JSDC_PARAM_MOTOR_ALARM_TIME;
- }
- break;
- case 22:
- if(!X_DRV)
- {
- MV_Set_Command_Pos_CPU(X_AXIS,0);
- JSDC_cMotorStep = 0;
- JSDC_cMotorDelay = dwTickCount;
- }
- else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 60:
- if(JSDC_SZ_OUT == JSDC_SERVER_DISEN)
- {
- JSDC_SZ_OUT = JSDC_SERVER_EN;
- JSDC_cMotorDelay = dwTickCount + 50; //先锁轴
- }
- JSDC_cMotorStep = 61;
- break;
- case 61:
- if(dwTickCount >= JSDC_cMotorDelay)
- {
- save_buff = JSDC_dwEncPos;
- zipper_length = JSDC_SET_ALL_LENGTH - JSDC_PARAM_KONG_WEI_LENGTH + JSDC_PARAM_DAOKOU_LENGTH + JSDC_SaveLength;
- MoveAction_Const_AccDec(X_AXIS,JSDC_DIR_P,JSDC_PARAM_SET_SPEED,JSDC_PARAM_START_SPEED,JSDC_PARAM_ACC,JSDC_PARAM_DEC);
- JSDC_cMotorDelay = dwTickCount + JSDC_PARAM_MOTOR_ALARM_TIME;
- JSDC_cMotorStep = 62;
- }
- break;
- case 62:
- if((JSDC_dwEncPos) >= (zipper_length - JSDC_PARAM_LOWSPEED_LENGTH))
- {
- AxisChangeSpeed(X_AXIS,JSDC_PARAM_LOW_SPEED);
- JSDC_cMotorStep = 63;
- }
- else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 63:
- if((JSDC_dwEncPos) >= zipper_length)
- {
- JSDC_cMotorStep = 64;
- AxisEgmStop(X_AXIS);
- }
- else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- case 64:
- if(!X_DRV)
- {
- JSDC_cMotorStep = 0;
- JSDC_cMotorDelay = dwTickCount;
- }
- else if(dwTickCount >= JSDC_cMotorDelay)JSDC_SetAlarmCode(JSDC_LONG_TIME_NO_ZIPPER_ALARM);
- break;
- }
- }
- //下冲
- void JSDC_XiaChong(void)
- {
- switch(JSDC_cXiaChongStep)
- {
- case 0:
- return;
- break;
- case 1:
- JSDC_XC_ShaChe = JSDC_SC_DISEN;
- JSDC_cRightFenZhenStep = 1;
- JSDC_cXiaChongStep = 2;
- break;
- case 2:
- if((JSDC_cLeftFenZhenStep==0) && (JSDC_cRightFenZhenStep == 0))
- {
- JSDC_cXiaChongStep = 3;
- if(JSDC_bRunning)JSDC_cXiaChongDelay = dwTickCount + JSDC_PARAM_DELAY_XC;
- }
- break;
- case 3:
- if(dwTickCount >= JSDC_cXiaChongDelay)
- {
-
- JSDC_cXiaChongStep = 4;
- JSDC_XiaChong_MOTOR = 1; //下冲电机
- JSDC_cXiaChongDelay = dwTickCount + (unsigned long)JSDC_ERRORTIME; //下冲最长时间
- if(JSDC_XiaChongMotorMode == 1)
- {
- AxisMoveTwoPos(Y_AXIS,JSDC_XiaChongSpeed,2000,JSDC_XiaChongLowSpeed,9999999,0);
- }
- }
- break;
- case 4: //碰到右大微动,延时停
- if(JSDC_XiaChong_IN_UP)
- {
- JSDC_cXiaChongDelay = dwTickCount + JSDC_PARAM_XC_DELAY;
- JSDC_cSDDelay = dwTickCount + JSDC_DELAY_LSD_BACK;
- JSDC_cXiaChongStep = 5;
- JSDC_LeftFenZhen_VAVLE = 0; //退左分针
- JSDC_RightFenZhen_VAVLE = 0;
- JSDC_YD_VAVLE = 0;
- SetEncodePos(0);
- if(JSDC_bRunning)
- {
- JSDC_GouZhen_VAVLE = 1;
- JSDC_cGouZhenTime = dwTickCount + 300;
- }
- }
- else if(dwTickCount >= JSDC_cXiaChongDelay) //自动停机
- {
- JSDC_cXiaChongStep = 0;
- JSDC_XiaChong_MOTOR = 0;// //下冲电机
- JSDC_SetAlarmCode(JSDC_XC_ALARM);
- }
-
- break;
- case 5:
- if(dwTickCount >= JSDC_cSDDelay)JSDC_Left_SD = 0;
- if(dwTickCount >= JSDC_cXiaChongDelay)
- {
- AxisEgmStop(Y_AXIS);
- JSDC_XiaChong_MOTOR = 0; //延时刹车
- if(JSDC_PARAM_SC_MODE)
- {
- JSDC_cXiaChongStep = 0;
- }
- else
- {
- JSDC_cXiaChongStep = 6;
- }
- }
- break;
- case 6:
- {
- if(dwTickCount >= JSDC_cSDDelay)JSDC_Left_SD = 0;
- JSDC_cXiaChongStep = 7;
- JSDC_cXiaChongDelay = dwTickCount + JSDC_PARAM_SC_DELAY;
- }
- break;
- case 7:
- if(dwTickCount >= JSDC_cSDDelay)JSDC_Left_SD = 0;
- if((dwTickCount >= JSDC_cXiaChongDelay))
- {
- JSDC_cXiaChongStep = 8;
- JSDC_cXiaChongDelay = dwTickCount+ 150;
- // JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
- JSDC_XC_ShaChe = JSDC_SC_EN;
- }
- break;
- case 8:
- if((dwTickCount >= JSDC_cXiaChongDelay) && (dwTickCount >= JSDC_cSDDelay))
- {
- JSDC_Left_SD = 0;
- JSDC_cXiaChongStep = 0;
- if(!JSDC_bRunning)MV_Set_Command_Pos_CPU(X_AXIS,0);
- // JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
- JSDC_XC_ShaChe = JSDC_SC_DISEN;
- }
- break;
- case 20: // 点动普通下冲动作
- // JSDC_XC_SongZhou = JSDC_SERVER_EN;
- JSDC_XC_ShaChe = JSDC_SC_DISEN;
- JSDC_cXiaChongDelay = dwTickCount + 50;
- JSDC_cXiaChongStep = 21;
- break;
- case 21:
- if((dwTickCount >= JSDC_cXiaChongDelay))
- {
- JSDC_XiaChong_MOTOR = 1;
- JSDC_cXiaChongDelay = dwTickCount + 50;
- JSDC_cXiaChongStep = 22;
- }
- break;
- case 22:
- if((dwTickCount >= JSDC_cXiaChongDelay))
- {
- JSDC_XiaChong_MOTOR = 0;
- // JSDC_XC_SongZhou = JSDC_SERVER_EN;
-
- if(JSDC_XiaChongMotorMode)
- JSDC_cXiaChongStep = 0;
- else
- {
- JSDC_XC_ShaChe = JSDC_SC_EN;
- JSDC_cXiaChongDelay = dwTickCount + 150;
- JSDC_cXiaChongStep = 23;
- }
- }
- break;
- case 23:
- if((dwTickCount >= JSDC_cXiaChongDelay))
- {
- //JSDC_XC_SongZhou = JSDC_SERVER_DISEN;
- JSDC_XC_ShaChe = JSDC_SC_DISEN;
- JSDC_cXiaChongStep = 0;
- }
- break;
- case 40: // 点动电机下冲动作
- //JSDC_XC_SongZhou = JSDC_SERVER_EN;
- JSDC_cXiaChongDelay = dwTickCount + 50;
- JSDC_cXiaChongStep = 41;
- break;
- case 41:
- if(!Y_DRV)AxisMovePos(Y_AXIS,20,10);
- JSDC_cXiaChongStep = 42;
- break;
- case 42:
- if(!Y_DRV)
- {
- JSDC_cXiaChongStep = 0;
- }
- break;
- }
- }
- //分针
- void JSDC_FenZhen(void)
- {
- if(JSDC_FZ_SELECT)
- {
-
- }
- else
- {
- JSDC_cRightFenZhenStep = 0;
- JSDC_cLeftFenZhenStep = 0;
- }
- //右分针
- switch(JSDC_cRightFenZhenStep)
- {
- case 0:
- break;
- case 1:
- JSDC_cFenZhenRightDelay = JSDC_PARAM_R_FZ_DELAY+dwTickCount;
- JSDC_cRightFenZhenStep = 2;
- break;
- case 2:
- if(dwTickCount >= JSDC_cFenZhenRightDelay)
- {
- JSDC_cRightFenZhenStep = 3;
- JSDC_RightFenZhen_VAVLE = 1;//右分针电磁阀
- JSDC_cFenZhenRightDelay = dwTickCount + JSDC_FenZhengErrorTime;
- }
- break;
- case 3: //碰到右大微动,延时停
- JSDC_cFenZhenRightDelay = dwTickCount + JSDC_FenZhengErrorTime;
- JSDC_cRightFenZhenStep = 4;
- break;
- case 4:
- if(JSDC_RightFenZhen_IN) //插针到位
- {
- JSDC_cRightFenZhenStep = 0;
- JSDC_YD_VAVLE = 1;
- JSDC_cLeftFenZhenStep = 1; //左分针延时启动
- }
- else if(dwTickCount >= JSDC_cFenZhenRightDelay)
- {
- JSDC_SetAlarmCode(JSDC_RFZ_LIMIT_ALARM);
- }
- break;
- }
- //左分针
- switch(JSDC_cLeftFenZhenStep)
- {
- case 0:
- break;
- case 1:
- JSDC_cFenZhenLeftDelay = JSDC_PARAM_L_FZ_DELAY+dwTickCount;
- JSDC_cLeftFenZhenStep = 2;
- break;
- case 2:
- if(dwTickCount >= JSDC_cFenZhenLeftDelay)
- {
- JSDC_cLeftFenZhenStep = 3;
- JSDC_LeftFenZhen_VAVLE = 1; //左分针电磁阀
- JSDC_cFenZhenLeftDelay = dwTickCount + JSDC_FenZhengErrorTime;
- }
- break;
- case 3: //离开左分针原点
- {
- JSDC_cFenZhenLeftDelay = dwTickCount + JSDC_FenZhengErrorTime;
- JSDC_cLeftFenZhenStep = 4;
- }
- break;
- case 4:
- if(JSDC_LeftFenZhen_IN) //插针到位
- {
- JSDC_cLeftFenZhenStep = 0;
- JSDC_Left_SD = 1;
- }
- else if(dwTickCount >= JSDC_cFenZhenLeftDelay)
- {
- JSDC_SetAlarmCode(JSDC_LFZ_LIMIT_ALARM);
- }
- break;
- }
- }
- #endif
|