#include "global.h" #if CHANG_SHENG_GEI_LI_MACHINE void TBJ_InitAction(void); void TBJ_Action(void); void TBJ_ChuiQi(void); void TBJ_ChaoSheng(void); void TBJ_HeMo(void); void TBJ_SetAlarmCode(unsigned alarm_code); void TBJ_StartStopAction(void); void TBJ_AutoRunStep(void); void TBJ_Motor(void); void TBJ_SongJiao(void); void TBJ_SetAlarmCode(unsigned alarm_code) { SetAlarmCode(TBJ_ALARM_ADDR,alarm_code); TBJ_bAlarmStop = 1; } void TBJ_InitAction(void) { XGearRatio = 1; } void TBJ_ChuiQi(void) { if(TBJ_CQ_VAVLE && (dwTickCount >= TBJ_CQ_Delay)) { TBJ_CQ_VAVLE = 0; } } void TBJ_ChaoSheng(void) { if(TBJ_CS_OUT && (dwTickCount >= TBJ_CS_Delay)) { TBJ_CS_OUT = 0; } } //手动动作 void TBJ_ManualAction(void) { if(!TBJ_bRunning) { //警告跳出 if(bClearTotal) { bClearTotal = 0; ClrcToTal(TBJ_TOTAL_ADDR); } if(TBJ_bMotor) { if(!X_DRV)AxisContinueMove(X_AXIS,TBJ_PARAM_HIGH_SPEED,TBJ_DIR_P); } else { if(X_DRV)AxisDecStop(X_AXIS); } if(TBJ_bGouZhen) { TBJ_bGouZhen = 0; TBJ_GZ_VAVLE = ~TBJ_GZ_VAVLE; } if(TBJ_bQianDao) { TBJ_bQianDao = 0; TBJ_QDB_VAVLE = ~TBJ_QDB_VAVLE; } if(TBJ_bJiaJiao) { TBJ_bJiaJiao = 0; TBJ_JJ_VAVLE = ~TBJ_JJ_VAVLE; } if(TBJ_bSongJiao) { TBJ_bSongJiao = 0; TBJ_SJ_VAVLE = ~TBJ_SJ_VAVLE; } if(TBJ_bCS) { TBJ_bCS = 0; TBJ_CS_OUT = 1; TBJ_CS_Delay = dwTickCount + TBJ_PARAM_CS_TIME; } if(TBJ_bChuiQi) { TBJ_bChuiQi = 0; TBJ_CQ_VAVLE = 1; TBJ_CQ_Delay = dwTickCount + TBJ_PARAM_CQ_TIME; } if(TBJ_bSM) { TBJ_bSM = 0; TBJ_SM_VAVLE = ~TBJ_SM_VAVLE; } if(TBJ_bXM) { TBJ_bXM = 0; TBJ_XM_VAVLE = ~TBJ_XM_VAVLE; } if(TBJ_bHeMo) { TBJ_bHeMo = 0; if(TBJ_HeMoStep == 0)TBJ_HeMoStep = 1; } if(TBJ_bFenJiao) { TBJ_bFenJiao = 0; TBJ_FJ_VAVLE = ~TBJ_FJ_VAVLE; } } } void TBJ_SongJiao(void) { if(TBJ_SongJiaoStep == 1) { TBJ_SongJiaoStep = 2; } else if(TBJ_SongJiaoStep == 2) { TBJ_SongJiaoStep = 3; } else if(TBJ_SongJiaoStep == 3) { TBJ_SongJiaoStep = 4; } else if(TBJ_SongJiaoStep == 4) { TBJ_SongJiaoStep = 5; } else if(TBJ_SongJiaoStep == 5) { TBJ_SongJiaoStep = 6; } else if(TBJ_SongJiaoStep == 6) { TBJ_SongJiaoStep = 0; } } //打孔动作 void TBJ_Action(void) { TBJ_ManualAction(); TBJ_ChuiQi(); TBJ_ChaoSheng(); TBJ_HeMo(); TBJ_StartStopAction(); TBJ_AutoRunStep(); TBJ_Motor(); TBJ_SongJiao(); } //合模动作 void TBJ_HeMo(void) { if(TBJ_HeMoStep == 1) { TBJ_HeMoDelay = dwTickCount + TBJ_PARAM_HM_DELAY; TBJ_HeMoStep = 2; } else if((TBJ_HeMoStep == 2) && (dwTickCount >= TBJ_HeMoDelay)) { TBJ_XM_VAVLE = 1; TBJ_HeMoDelay = dwTickCount + VAVLE_ALARM_TIME; TBJ_HeMoStep = 3; } else if(TBJ_HeMoStep == 3) { if(TBJ_XM_LIMIT_IN) { TBJ_SM_VAVLE = 1; TBJ_HeMoDelay = dwTickCount + VAVLE_ALARM_TIME; TBJ_HeMoStep = 4; } else if(dwTickCount >= TBJ_HeMoDelay) { TBJ_SetAlarmCode(TBJ_HM_LIMIT_ALARM); } } else if(TBJ_HeMoStep == 4) { if(TBJ_SM_LIMIT_IN) { TBJ_HeMoDelay = dwTickCount + TBJ_PARAM_DELAY_CS; TBJ_HeMoStep = 5; } else if(dwTickCount >= TBJ_HeMoDelay) { TBJ_SetAlarmCode(TBJ_HM_LIMIT_ALARM); } } else if((TBJ_HeMoStep == 5) && (dwTickCount >= TBJ_HeMoDelay)) { TBJ_CS_OUT = 1; TBJ_CS_Delay = dwTickCount + TBJ_PARAM_CS_TIME; TBJ_HeMoStep = 6; } else if((TBJ_HeMoStep == 6) && (TBJ_CS_OUT == 0)) { TBJ_HeMoDelay = dwTickCount + TBJ_PARAM_COLD_TIME; TBJ_HeMoStep = 7; } else if((TBJ_HeMoStep == 7) && (dwTickCount >= TBJ_HeMoDelay)) { TBJ_SM_VAVLE = 0; TBJ_XM_VAVLE = 0; TBJ_HeMoDelay = dwTickCount + VAVLE_ALARM_TIME; TBJ_HeMoStep = 7; } else if(TBJ_HeMoStep == 7) { if(!TBJ_SM_LIMIT_IN && !TBJ_XM_LIMIT_IN) { TBJ_HeMoStep = 0; } else if(dwTickCount >= TBJ_HeMoDelay) { if(TBJ_SM_LIMIT_IN)TBJ_SetAlarmCode(TBJ_HM_LIMIT_ALARM); else if(TBJ_XM_LIMIT_IN)TBJ_SetAlarmCode(TBJ_HM_LIMIT_ALARM); } } } //启动停止故障停止动作 void TBJ_StartStopAction(void) { if((START_IN_UP || TBJ_bStart) && !TBJ_bRunning && (TBJ_AutoStep ==0)) { if(GetTotal(TBJ_TOTAL_ADDR) >= SET_TOTAL)TBJ_SetAlarmCode(TBJ_TOTAL_ALARM); else { TBJ_AutoStep = 1; TBJ_bRunning = 1; TBJ_AutoDelay = 0; } TBJ_bStart = 0; } if(TBJ_KaDai_IN && (GetAlarmCode(TBJ_ALARM_ADDR) == 0)) { TBJ_SetAlarmCode(TBJ_KADAI_ALARM); } if(STOP_IN_UP || TBJ_bStop) { TBJ_bStop = 0; if(TBJ_bRunning && (SingOneFlg == 0)) { SingOneFlg = 1; } else { TBJ_GZ_VAVLE = 0; TBJ_QDB_VAVLE = 0; TBJ_JJ_VAVLE = 0; TBJ_SJ_VAVLE = 0; TBJ_FJ_VAVLE = 0; TBJ_SM_VAVLE = 0; TBJ_XM_VAVLE = 0; TBJ_CQ_VAVLE = 0; TBJ_CS_OUT = 0; TBJ_HeMoStep = 0; TBJ_bRunning = 0; TBJ_AutoStep = 0; AxisEgmStop(X_AXIS); } } if(TBJ_bAlarmStop) { TBJ_bAlarmStop = 0; AxisEgmStop(X_AXIS); TBJ_AutoStep = 0; TBJ_HeMoStep = 0; TBJ_bRunning = 0; SingOneFlg = 0; } } //电机动作 void TBJ_Motor(void) // { static long save_buff,length_buff; switch(TBJ_MotorStep) { case 0: break; case 1: QD_MotorStep = 2; break; case 2: save_buff = GetPos(X_AXIS); if(dwZipCnt <= 1) { AxisContinueMove(X_AXIS,TBJ_PARAM_LOW_SPEED,TBJ_DIR_P); //第一条走低速 } else { AxisMoveTwoPos(X_AXIS,TBJ_PARAM_HIGH_SPEED,(length_buff - TBJ_PARAM_LOWSPEED_LENGTH),TBJ_PARAM_LOW_SPEED,0xFFFFFF,TBJ_DIR_P);//第二条开始走两段速 } TBJ_MotorDelay = dwTickCount + GUO_LIAN_OVER_TIME; QD_MotorStep = 3; break; case 3: if(TBJ_GUO_LIAN_IN_UP) { QD_MotorStep = 4; TBJ_MotorDelay = dwTickCount + TBJ_PARAM_DELAY_GZ; } else if(dwTickCount >= TBJ_MotorDelay) { } if(TBJ_GZ_IN) { AxisEgmStop(X_AXIS); QD_MotorStep = 6; } break; case 4: if(dwTickCount >= TBJ_MotorDelay) { TBJ_GZ_VAVLE = 1; QD_MotorStep = 5; } if(TBJ_GZ_IN) { AxisEgmStop(X_AXIS); QD_MotorStep = 6; } break; case 5: if(TBJ_GZ_IN) { AxisEgmStop(X_AXIS); QD_MotorStep = 6; } break; case 6: if(!X_DRV) { if(dwZipCnt == 1)length_buff = GetPos(X_AXIS) - save_buff; //以第二条测量出来的长度为准来做减速 QD_MotorStep = 0; } break; } } //自动运行动作 void TBJ_AutoRunStep(void) { if(TBJ_bRunning) { if(TBJ_AutoStep == 1) { dwZipCnt = 0; TBJ_AutoStep = 2; } else if((TBJ_AutoStep == 2) && (dwTickCount >= TBJ_AutoDelay)) { if(QD_MotorStep == 0)QD_MotorStep = 1; TBJ_AutoStep = 3; } else if(TBJ_AutoStep == 3) { if(QD_MotorStep == 0) { TBJ_AutoStep = 4; } } else if(TBJ_AutoStep == 4) { if(TBJ_HeMoStep == 0)TBJ_HeMoStep = 1; TBJ_AutoStep = 5; } else if(TBJ_AutoStep == 5) { if(TBJ_HeMoStep == 0) { TBJ_AutoStep = 6; } } else if(TBJ_AutoStep == 6) { AddToTal(TBJ_TOTAL_ADDR); dwZipCnt++; if((GetTotal(TBJ_TOTAL_ADDR) >= TBJ_PARAM_SET_TOTAL) || SingOneFlg) { if(SingOneFlg) { TBJ_AutoStep = 0; TBJ_bRunning = 0; SingOneFlg = 0; } else { TBJ_SetAlarmCode(TBJ_TOTAL_ALARM); } } else { TBJ_AutoStep = 2; TBJ_AutoDelay = TBJ_PARAM_CYCLE_DELAY + dwTickCount; CalProSP(TBJ_PROSPEED_ADDR); } } } } #endif