123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671 |
- #include "global.h"
- #if PENG_WEI_CHANG_MACHINE
- unsigned char JSDC_cFirstFlg = 0,JSDC_cSeBiaoStep = 0;
- unsigned short JSDC_SecondToothNum = 0;
- unsigned char JSDC_cCntEn = 0;
- unsigned long JSDC_dwSeBiaoDelayCnt = 0;
- long JSDC_RemainLength = 0;
- static unsigned char cFengZhenTimes = 0;
- static long cRealPos;
- unsigned long CalEncodePulse(void);
- void JSDC_DelayAction(void);
- void JSDC_InitAction(void);
- void JSDC_ExtiActionX30(void);
- void JSDC_Action(void);
- void JSDC_ModeSelect(void);
- void JSDC_ChuiQi(void);
- void JSDC_XiaChong(void);
- void JSDC_SetAlarmCode(unsigned alarm_code);
- void JSDC_StartStopAction(void);
- void JSDC_AutoRunStep(void);
- void JSDC_FenZhen(void);
- void JSDC_Motor(void);
- void JSDC_SetAlarmCode(unsigned alarm_code)
- {
- SetAlarmCode(JSDC_ALARM_ADDR,alarm_code);
- JSDC_bAlarmStop = 1;
- }
- void JSDC_InitAction(void)
- {
- float buff_pulse,buff_dist;
-
- if USE_ENCODE
- {
- buff_pulse = JSDC_PARAM_CYCLE_BM_PULSE;
- buff_dist = JSDC_PARAM_CYCLE_BM_LENGTH;
- }
- else
- {
- buff_pulse = JSDC_PARAM_CYCLE_PULSE;
- buff_dist = JSDC_PARAM_CYCLE_LENGTH;
- }
- XGearRatio = buff_pulse/buff_dist;
- if(JSDC_XC_MODE)JSDC_XiaChong_MOTOR = 1;
- }
- //手动动作
- void JSDC_ManualAction(void)
- {
- //清理产量
- if(bClearTotal)
- {
- bClearTotal = 0;
- ClrcToTal(JSDC_TOTAL_ADDR);
- }
-
- if(!JSDC_bRunning)
- {
- if(JSDC_bAdd)
- {
- JSDC_bAdd = 0;
- if(JSDC_SET_ALL_LENGTH < 9999999)
- {
- SetData32bits(12,JSDC_SET_ALL_LENGTH+50);
- JSDC_bSetCM = 1;
- }
- }
-
- if(JSDC_bDec)
- {
- JSDC_bDec = 0;
- if(JSDC_SET_ALL_LENGTH >= 50)
- {
- SetData32bits(12,JSDC_SET_ALL_LENGTH-50);
- JSDC_bSetCM = 1;
- }
- }
-
- if(JSDC_bLeftFZ)
- {
- JSDC_bLeftFZ = 0;
- JSDC_LFZ_VAVLE = ~JSDC_LFZ_VAVLE;
- }
-
- if(JSDC_bRightFZ)
- {
- JSDC_bRightFZ = 0;
- JSDC_RFZ_VAVLE = ~JSDC_RFZ_VAVLE;
- }
-
- if(JSDC_bLSD)
- {
- JSDC_bLSD = 0;
- JSDC_LSD_VAVLE = ~JSDC_LSD_VAVLE;
- }
-
- if(JSDC_bGZ)
- {
- JSDC_bGZ = 0;
- JSDC_GZ_VAVLE = ~JSDC_GZ_VAVLE;
- }
-
- if(JSDC_bXC || JSDC_ManXiaChong_UP)
- {
- JSDC_bXC = 0;
-
- if(JSDC_XiaChongStep == 0)
- {
- JSDC_XiaChongStep = 1;
- }
- }
-
- if(JSDC_bCQ)
- {
- JSDC_bCQ = 0;
- JSDC_ChuiQi_VAVLE = 1;
- JSDC_ChuiQiDelay = dwTickCount + JSDC_PARAM_CHUIQI_TIME;
- }
-
- if(JSDC_bMotor)
- {
- if(!X_DRV)AxisContinueMove(X_AXIS,20,JSDC_DIR_P);
- }
- else
- {
- if(X_DRV)AxisDecStop(X_AXIS);
- }
-
- if(JSDC_bSetCM)
- {
- JSDC_bSetCM = 0;
- SetData32bits(8,CalInch(JSDC_SET_ZIPPER_LENGTH));
- JSDC_SET_KONGWEI_LENGTH_INCH = CalInch(JSDC_SET_KONGWEI_LENGTH);
- SetData32bits(14,CalInch(JSDC_SET_ALL_LENGTH));
- }
-
- if(JSDC_bSetInch)
- {
- JSDC_bSetInch = 0;
- SetData32bits(6,CalLengthCM(JSDC_SET_ZIPPER_LENGTH));
- JSDC_SET_KONGWEI_LENGTH = CalLengthCM(JSDC_SET_KONGWEI_LENGTH_INCH);
- SetData32bits(12,CalLengthCM(JSDC_SET_ALL_LENGTH));
-
- JSDC_bSetCM = 1;
- }
- }
- }
- //高速输入X30/X16定时器中断
- void JSDC_ExtiActionX30(void)
- {
- }
- //高速输入X31/X17外部色标信号中断
- void JSDC_ExtiActionX31(void)
- {
- }
- //胶牙定寸动作
- void JSDC_Action(void)
- {
- JSDC_ManualAction();
- JSDC_ChuiQi();
- JSDC_Motor();
- JSDC_XiaChong();
- JSDC_StartStopAction();
- JSDC_AutoRunStep();
- }
- //输入拉链长度返回所输入拉链长度所对应的齿数
- unsigned long JS_GetToothNum(unsigned long zipper_length)
- {
- float length_buff1,tooth_buff,length_buff2;
- length_buff1 = zipper_length;
- tooth_buff = JY_JIZHUN_CISHU;
- length_buff2 = JY_JIZHUN_LEN;
- return (unsigned long)round(length_buff1 * tooth_buff / length_buff2);
- }
- //吹气动作
- void JSDC_ChuiQi(void)
- {
- if(JSDC_ChuiQi_VAVLE)
- {
- if(JSDC_ChuiQiDelay < dwTickCount)JSDC_ChuiQi_VAVLE = 0;
- }
- }
- void JSDC_FenZhen(void)
- {
- if(JSDC_SX_ENABLE == 0)JSDC_FenZhenStep = 0;
-
- if(bRunning)
- {
- if((dwTickCount >= JSDC_FenZhenDelay) && JSDC_LSD_VAVLE)JSDC_LSD_VAVLE = 0;
- }
- switch(JSDC_FenZhenStep)
- {
- case 0:
- break;
- case 1: //锁带(右分针)
- if(dwTickCount >= JSDC_FenZhenDelay)
- {
- JSDC_FenZhenStep = 2;
- JSDC_RFZ_VAVLE = 1;
- JSDC_FenZhenDelay = dwTickCount + JSDC_VAVLE_ALARM_TIME;
- }
- break;
- case 2:
- if(JSDC_RFZ_IN) //分针到位
- {
- JSDC_RSD_VAVLE = 1;
- cFengZhenTimes = 0;
- JSDC_FenZhenStep = 3;
- JSDC_FenZhenDelay = dwTickCount + JSDC_PARAM_LFZ_DELAY;
- }
- else if(dwTickCount >= JSDC_FenZhenDelay) //右分针不到位警告
- {
- cFengZhenTimes++;
- JSDC_RFZ_VAVLE = 0;
- if(cFengZhenTimes >= 3)
- {
- JSDC_SetAlarmCode(JSDC_RFZ_ALARM);
- }
- else
- {
- JSDC_FenZhenStep = 1;
- JSDC_FenZhenDelay = dwTickCount + 300;
- }
- }
- break;
- case 3:
- if(dwTickCount >= JSDC_FenZhenDelay)
- {
- JSDC_LFZ_VAVLE = 1;
- JSDC_FenZhenStep = 4;
- JSDC_FenZhenDelay = dwTickCount + JSDC_VAVLE_ALARM_TIME;
- }
- break;
- case 4:
- if(JSDC_LFZ_IN)
- {
- JSDC_LSD_VAVLE = 1;
- JSDC_FenZhenStep = 0;
- JSDC_LSDDelay = dwTickCount + JSDC_PARAM_LSD_DELAY;
- }
- else if(dwTickCount >= JSDC_FenZhenDelay) //左分针不到位警告
- {
- JSDC_SetAlarmCode(JSDC_LFZ_ALARM);
- }
- break;
- }
- }
- //下冲动作
- void JSDC_XiaChong(void)
- {
- if(JSDC_XiaChongStep == 1)
- {
- if(JSDC_XC_MODE)
- {
- JSDC_XiaChongDelay = dwTickCount + XIACONG_DELAY_TIME;
- JSDC_ShaChe_VAVLE = 0;
- JSDC_XiaChongStep = 2;
- }
- else
- {
- if(JSDC_XC_ORIGIN_IN)
- {
- JSDC_XiaChongDelay = dwTickCount + XIACONG_DELAY_TIME;
- JSDC_XiaChongStep = 20;
- }
- else
- {
- JSDC_SetAlarmCode(JSDC_XIACHONG_LIMIT_ALARM);
- }
- }
- }
- else if((JSDC_XiaChongStep == 2) && (dwTickCount >= JSDC_XiaChongDelay))
- {
- JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_XC_ALARM_TIME;
- JSDC_XiaChongStep = 3;
- }
- else if(JSDC_XiaChongStep == 3)
- {
- if(JSDC_XC_ORIGIN_IN_UP)
- {
- JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_SHACHE_DELAY_TIME;
- JSDC_XiaChongStep = 4;
- }
- else if(dwTickCount >= JSDC_XiaChongDelay)
- {
- JSDC_SetAlarmCode(JSDC_XIACHONG_LIMIT_ALARM);
- JSDC_XiaChong_MOTOR = 0;
- JSDC_ShaChe_VAVLE = 0;
- }
- }
- else if((JSDC_XiaChongStep == 4) && (dwTickCount >= JSDC_XiaChongDelay))
- {
- JSDC_ShaChe_VAVLE = 1;
-
- if(JSDC_SC_MODE)
- {
- JSDC_XiaChongStep = 6;
- }
- else
- {
- JSDC_XiaChongStep = 5;
- JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_SHACHE_TIME;
- }
- }
- else if((JSDC_XiaChongStep == 5) && (dwTickCount >= JSDC_XiaChongDelay))
- {
- JSDC_ShaChe_VAVLE = 0;
- JSDC_XiaChongStep = 6;
- }
- else if(JSDC_XiaChongStep == 6)
- {
- JSDC_GZ_VAVLE = 0;
- JSDC_XiaChongStep = 0;
- }
- else if((JSDC_XiaChongStep == 20) && (dwTickCount >= JSDC_XiaChongDelay))
- {
- JSDC_XiaChong_MOTOR = 1;
- JSDC_XiaChongStep = 21;
- JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_XC_ALARM_TIME;
- }
- else if(JSDC_XiaChongStep == 21)
- {
- if(JSDC_XC_LIMIT_IN)
- {
- JSDC_XiaChong_MOTOR = 0;
- JSDC_GZ_VAVLE = 0;
- JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_XC_ALARM_TIME;
- JSDC_XiaChongStep = 22;
- }
- else if(dwTickCount >= JSDC_XiaChongDelay)
- {
- JSDC_SetAlarmCode(JSDC_XIACHONG_LIMIT_ALARM);
- }
- }
- else if(JSDC_XiaChongStep == 22)
- {
- if(JSDC_XC_ORIGIN_IN)
- {
- JSDC_XiaChongStep = 0;
- }
- else if(dwTickCount >= JSDC_XiaChongDelay)
- {
- JSDC_SetAlarmCode(JSDC_XIACHONG_ORIGIN_ALARM);
- }
- }
- }
- //启动停止故障停止动作
- void JSDC_StartStopAction(void)
- {
- if((START_IN_UP || JSDC_bStart) && !JSDC_bRunning && (JSDC_AutoStep ==0))
- {
- if(!JSDC_XC_ORIGIN_IN)JSDC_SetAlarmCode(JSDC_START_XIACHONG_ALARM);
- else if(GetTotal(JSDC_TOTAL_ADDR) >= SET_TOTAL)JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
- else
- {
- JSDC_AutoStep = 1;
- JSDC_bRunning = 1;
- JSDC_AutoDelay = 0;
- }
- JSDC_bStart = 0;
- }
-
- if(STOP_IN_UP || JSDC_bStop)
- {
- JSDC_bStop = 0;
- if(JSDC_bRunning && (SingOneFlg == 0))
- {
- SingOneFlg = 1;
- }
- else
- {
- JSDC_ChuiQi_VAVLE = 1;
- JSDC_ChuiQiDelay = dwTickCount + JSDC_PARAM_CHUIQI_TIME * 10;
- JSDC_bRunning = 0;
- JSDC_AutoStep = 0;
- AxisEgmStop(X_AXIS);
- SingOneFlg = 0;
- }
- }
-
- if(JSDC_bAlarmStop)
- {
- JSDC_bAlarmStop = 0;
- AxisEgmStop(X_AXIS);
- JSDC_AutoStep = 0;
- JSDC_bRunning = 0;
- SingOneFlg = 0;
- }
- }
- unsigned long JSDC_ToothTransPulse(unsigned long tooth)
- {
- return(JY_JIZHUN_LEN * tooth * 2000 / 250 / JY_JIZHUN_CISHU);
- }
- //电机控制动作
- void JSDC_Motor(void) //
- {
- static long save_buff,length_buff,low_speed_buff,total_length,move_pos_buff;
- cRealPos = GetPos(X_AXIS);
- SetData32bits(16,cRealPos);//刷新编码器位置
- user_datas[121] = cRealPos;
- switch(JSDC_MotorStep)
- {
- case 0: break;
- case 1://使用编码器/电机长度定寸
- if(JSDC_NOW_POS >= JSDC_SET_ALL_LENGTH)
- JSDC_MotorStep = 0;
- else
- JSDC_MotorStep = 2;
- break;
- case 2:
- total_length = JSDC_SET_ALL_LENGTH - JSDC_NOW_POS;
- move_pos_buff = JSDC_NOW_POS;
- AxisMovePos(X_AXIS,JSDC_PARAM_HIGH_SPEED,total_length);
- MoveChangSpeedPos(X_AXIS, JSDC_PARAM_LOW_SPEED,(PosToPulse(X_AXIS,JSDC_PARAM_LOWSPEED_LENGTH) + MV_Cal_Dec_pulse(JSDC_PARAM_HIGH_SPEED,JSDC_PARAM_LOW_SPEED,30)));
- JSDC_MotorStep = 3;
- break;
- case 3:
- if((JSDC_NOW_POS - move_pos_buff) >= total_length)AxisEgmStop(X_AXIS);
- if(!X_DRV)JSDC_MotorStep = 0;
- break;
- case 10://使用电机长度定寸走刀口长度
- JSDC_MotorStep = 11;
- break;
- case 11:
- AxisMovePos(X_AXIS,JSDC_PARAM_HIGH_SPEED,JSDC_SET_ALL_LENGTH);
- JSDC_MotorStep = 12;
- break;
- case 12:
- if(!X_DRV)JSDC_MotorStep = 0;
- break;
- case 20://使用勾针定寸
- JSDC_MotorStep = 21;
- break;
- case 21:
- if(dwTickCount >= JSDC_MotorDelay)
- {
- save_buff = GetPos(X_AXIS);
- if(dwZipCnt == 0)AxisContinueMove(X_AXIS,JSDC_PARAM_LOW_SPEED,JSDC_DIR_P); //第一条走低速
- else
- AxisMoveTwoPos(X_AXIS,JSDC_PARAM_HIGH_SPEED,(length_buff - JSDC_PARAM_LOWSPEED_LENGTH),JSDC_PARAM_LOW_SPEED,0xFFFFFF,JSDC_DIR_P);
-
- JSDC_MotorDelay = dwTickCount + MOTOR_ALARM_TIME;
- JSDC_MotorStep = 22;
- }
- break;
- case 22:
- if(1)
- {
- JSDC_MotorDelay = dwTickCount + JSDC_PARAM_GZ_DELAY;
- JSDC_MotorStep = 23;
- }
- else if(dwTickCount >= JSDC_MotorDelay)
- {
- JSDC_SetAlarmCode(JSDC_NO_ZIPPER_ALARM);
- }
- break;
- case 23:
- if(JSDC_GZ_RESET_MODE)
- {
- if(dwZipCnt < 2) //第一第二条勾针自己复位
- {
- if(dwTickCount >= JSDC_MotorDelay)
- {
- JSDC_GZ_VAVLE = 1;
- JSDC_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- JSDC_MotorStep = 24;
- }
- }
- else
- {
- if((GetPos(X_AXIS) - save_buff) >= JSDC_GZ_RESET_LENGTH)
- {
- JSDC_GZ_VAVLE = 1;
- JSDC_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- JSDC_MotorStep = 24;
- }
- }
- }
- else
- {
- if(dwTickCount >= JSDC_MotorDelay)
- {
- JSDC_GZ_VAVLE = 1;
- JSDC_MotorDelay = dwTickCount + VAVLE_ALARM_TIME;
- JSDC_MotorStep = 24;
- }
- }
- break;
- case 24:
- if(JSDC_GZ_IN)
- {
- AxisEgmStop(X_AXIS);
- JSDC_MotorStep = 25;
- }
- else if(dwTickCount >= JSDC_MotorDelay)
- {
- JSDC_SetAlarmCode(JSDC_GZ_ALARM);
- }
- break;
- case 25:
- if(!X_DRV)
- {
- JSDC_MotorDelay = dwTickCount + JSDC_PARAM_YD_DELAY;
- JSDC_MotorStep = 26;
- }
- break;
- case 26:
- if(dwTickCount >= JSDC_MotorDelay)
- {
- if(dwZipCnt == 1)length_buff = GetPos(X_AXIS) - save_buff;
- JSDC_MotorStep = 27;
- }
- break;
- case 27:
- JSDC_MotorStep = 0;
- break;
-
- }
- }
- //自动运行动作
- void JSDC_AutoRunStep(void)
- {
- if(JSDC_bRunning)
- {
- if(JSDC_AutoStep == 1)
- {
- JSDC_AutoStep = 2;
- }
- else if((JSDC_AutoStep == 2))
- {
- JSDC_AutoStep = 3;
- JSDC_RemainLength = JSDC_SET_KONGWEI_LENGTH;
- }
- else if(JSDC_AutoStep == 3)
- {
- if(JSDC_MotorStep == 0)JSDC_MotorStep = 1;
- JSDC_AutoStep = 4;
- }
- else if(JSDC_AutoStep == 4)
- {
- if(JSDC_MotorStep == 0)
- {
- if(JSDC_FenZhenStep == 0)JSDC_FenZhenStep = 1;
- JSDC_AutoStep = 5;
- }
- }
- else if(JSDC_AutoStep == 5)
- {
- if(JSDC_FenZhenStep == 0)
- {
- JSDC_XiaChongStep = 1;
- JSDC_AutoStep = 6;
- }
- }
- else if(JSDC_AutoStep == 6)
- {
- if(JSDC_XiaChongStep == 0)
- {
- JSDC_AutoStep = 7;
- if(JSDC_RemainLength >= JSDC_PARAM_DAOKOU_LENGTH)
- {
- JSDC_RemainLength -= JSDC_PARAM_DAOKOU_LENGTH;
- JSDC_AutoStep = 3;
- }
- else
- {
- JSDC_RemainLength = 0;
- JSDC_AutoStep = 7;
- }
- }
- }
- else if(JSDC_AutoStep == 7)
- {
- AddToTal(JSDC_TOTAL_ADDR);
- if((GetTotal(JSDC_TOTAL_ADDR) >= SET_TOTAL) || JSDC_bStop || SingOneFlg)
- {
- if(JSDC_bStop || SingOneFlg)
- {
- JSDC_bStop = 0;
- JSDC_AutoStep = 0;
- JSDC_bRunning = 0;
- SingOneFlg = 0;
- JSDC_XiaChong_MOTOR = 0;
- }
- else
- {
- JSDC_SetAlarmCode(JSDC_TOTAL_ALARM);
- }
- }
- else
- {
- JSDC_AutoStep = 1;
- JSDC_AutoDelay = JSDC_PARAM_CYCLE_DELAY + dwTickCount;
- CalProSP(JSDC_PROSPEED_ADDR);
- }
- }
- else if(JSDC_AutoStep == 8)
- {
- }
- else if((JSDC_AutoStep == 8))
- {
- }
- else if((JSDC_AutoStep == 20) && (dwTickCount >= JSDC_AutoDelay)) //色标动作
- {
-
- }
- else if(JSDC_AutoStep == 21)
- {
- }
- else if(JSDC_AutoStep == 22)
- {
- JSDC_AutoStep = 23;
- }
- else if((JSDC_AutoStep == 23) && (dwTickCount >= JSDC_AutoDelay))
- {
- }
- else if(JSDC_AutoStep == 24)
- {
- }
- else if(JSDC_AutoStep == 25)
- {
- }
- else if(JSDC_AutoStep == 26)
- {
- }
- else if((JSDC_AutoStep == 27))
- {
- }
- }
- }
- #endif
|