#include "global.h" #if YOU_GUAN_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; 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_SetAlarmCode(unsigned alarm_code) { SetAlarmCode(JSDC_ALARM_ADDR,alarm_code); JSDC_bAlarmStop = 1; } void JSDC_InitAction(void) { float buff_pulse,buff_dist; 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_bYD) { JSDC_bYD = 0; JSDC_YD_VAVLE = ~JSDC_YD_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,JSDC_PARAM_HIGH_SPEED,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_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_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_LiHe_VAVLE = 1; JSDC_XiaChongDelay = dwTickCount + JSDC_PARAM_XC_ALARM_TIME; JSDC_XiaChongStep = 3; } else if(JSDC_XiaChongStep == 3) { if(JSDC_XC_ORIGIN_IN_UP) { JSDC_LiHe_VAVLE = 0; 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); } long GetEnCodePos(void) { return 0; } //电机控制动作 void JSDC_Motor(void) // { static long save_buff,length_buff; switch(JSDC_MotorStep) { case 0: break; case 1://使用电机长度定寸 JSDC_MotorStep = 2; break; case 2: AxisMovePos(X_AXIS,JSDC_PARAM_HIGH_SPEED,JSDC_SET_ALL_LENGTH); JSDC_MotorStep = 3; break; case 3: 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(JSDC_GUO_LIAN_IN_UP) { 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_YD_VAVLE = 1; 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) { SetData32bits(16,GetEncodeCount());//刷新编码器位置 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) && !X_DRV) { if(JSDC_MotorStep == 0) { if(JSDC_XiaChongStep == 0)JSDC_XiaChongStep = 1; JSDC_AutoStep = 5; } } else if(JSDC_AutoStep == 5) { if(JSDC_XiaChongStep == 0) { JSDC_AutoStep = 6; if(JSDC_RemainLength >= JSDC_PARAM_DAOKOU_LENGTH) { JSDC_RemainLength -= JSDC_PARAM_DAOKOU_LENGTH; JSDC_AutoStep = 3; } else { JSDC_RemainLength = 0; JSDC_AutoStep = 6; } } } else if(JSDC_AutoStep == 6) { 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 == 7) { } 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