#include "global.h" #if JIA_CHENG_WEI_YE_MACHINE void HuaXian_AlarmProtect(void); void HuaXian_ManualAction(void); void HuaXian_AutoAction(void); void HuaXian_StepCheckStart(void); void HuaXian_Motor(void); void HuaXian_ActionStep(void); static unsigned long cZipCnt = 0; static unsigned short cHuaXianTimesCnt = 0; void HX_SetAlarmCode(unsigned alarm_code) { SetAlarmCode(HX_ALARM_ADDR,alarm_code); bAlarmStop = 1; } void HuaXian_InitAction(void) { float length_buff,pulse_buff; length_buff = HX_PARAM_CYCLE_LENGTH; pulse_buff = HX_PARAM_CYCLE_PULSE; XGearRatio = pulse_buff/length_buff; CalFreqTab_X_Free(15); HX_SZ_OUT = 1; } void HuaXian_Action(void) { HuaXian_AlarmProtect(); HuaXian_Motor(); HuaXian_ManualAction(); HuaXian_ActionStep(); HuaXian_AutoAction(); HuaXian_StepCheckStart(); // 调用脚踏开关检测程序 } //手动动作 void HuaXian_ManualAction(void) { if(bRunning == 0) { if(HX_bClearTotal) //切断计数清零 { HX_bClearTotal = 0; ClrcToTal(HX_TOTAL_ADDR); } if(HX_bDown) { HX_bDown = 0; HX_DOWN_VAVLE = ~HX_DOWN_VAVLE; } if(HX_bHX) { HX_bHX = 0; HX_HX_VAVLE = ~HX_HX_VAVLE; } if(HX_bGZ) { HX_bGZ = 0; HX_GZ_VAVLE = ~HX_GZ_VAVLE; } if(HX_bHXRun) { HX_bHXRun = 0; if(HX_HuaXianStep==0)HX_HuaXianStep=1; } //电机控制 if(HX_bGoMotor) { HX_SZ_OUT = 0; if(!X_DRV)MoveAction_Const_AccDec(X_AXIS, HX_DIR_N, 5,1,5,30); } if(HX_bBackMotor) { HX_SZ_OUT = 0; if(!X_DRV)MoveAction_Const_AccDec(X_AXIS, HX_DIR_P, 5,1,5,30); } if(!HX_bGoMotor && !HX_bBackMotor && (HX_MotorStep == 0)) { if(X_DRV)AxisDecStop(X_AXIS); } } } void HuaXian_AlarmProtect(void) { dwRealPos = GetPos(X_AXIS); } void HuaXian_ActionStep(void) { switch(HX_HuaXianStep) { case 0:break; case 1: HX_HuaXianStep = 2; HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME; break; case 2: if(HX_DOWN_UP_IN) { HX_HuaXianStep = 3; HX_HXDelay = dwTickCount+HX_PARAM_DELAY_DOWN; } else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_DW_UP_ALARM); break; case 3: if(dwTickCount >= HX_HXDelay) { HX_DOWN_VAVLE = 1; HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME; HX_HuaXianStep = 4; } break; case 4: if(HX_DOWN_DOWN_IN) { HX_HuaXianStep = 5; HX_HXDelay = dwTickCount+HX_PARAM_DELAY_HX; } else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_DW_DOWN_ALARM); break; case 5: if(dwTickCount >= HX_HXDelay) { HX_HX_VAVLE = 1; HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME; HX_HuaXianStep = 6; } break; case 6: if(HX_HX_LIMIT_IN) { HX_HuaXianStep = 7; HX_HXDelay = dwTickCount+HX_PARAM_DELAY_DOWNBACK; } else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_HX_LIMIT); break; case 7: if(dwTickCount >= HX_HXDelay) { HX_DOWN_VAVLE = 0; HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME; HX_HuaXianStep = 8; } break; case 8: if(!HX_DOWN_DOWN_IN) { HX_HuaXianStep = 9; HX_HXDelay = dwTickCount+HX_PARAM_DELAY_HXBACK; } else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_DW_DOWN_ALARM); break; case 9: if(dwTickCount >= HX_HXDelay) { HX_HX_VAVLE = 0; cHuaXianTimesCnt++; if((cHuaXianTimesCnt >= HX_PARAM_HX_TIMES) || !bRunning)HX_GZ_VAVLE = 0; HX_HXDelay = dwTickCount+VAVLE_ALARM_TIME; HX_HuaXianStep = 10; } else if(dwTickCount >= HX_HXDelay)HX_SetAlarmCode(HX_HX_LIMIT); break; case 10: if(HX_DOWN_UP_IN && HX_HX_ORIGIN_IN) { if((cHuaXianTimesCnt >= HX_PARAM_HX_TIMES) || !bRunning) { HX_HuaXianStep = 0; HX_HXDelay = dwTickCount; } else { HX_HuaXianStep = 1; HX_HXDelay = dwTickCount; } } else if(dwTickCount >= HX_HXDelay) { if(!HX_DOWN_UP_IN) HX_SetAlarmCode(HX_DW_UP_ALARM); else HX_SetAlarmCode(HX_HX_ORIGIN); } break; default:; } } void HuaXian_AutoAction(void) { if(bRunning) { switch(HX_AutoStep) { case 1: if(dwTickCount >= HX_AutoDelay) { if(HX_MotorStep == 0) { HX_MotorStep = 30; HX_AutoStep = 2; } } break; case 2: if(HX_MotorStep == 0) { HX_AutoStep = 3; } break; case 3: if(HX_HuaXianStep == 0) { cHuaXianTimesCnt = 0; HX_HuaXianStep = 1; HX_AutoStep = 4; } break; case 4: if(HX_HuaXianStep == 0) { HX_AutoStep = 5; } break; case 5: cZipCnt++; AddToTal(HX_TOTAL_ADDR); CalProSP(HX_PROSPEED_ADDR); if((GetTotal(HX_TOTAL_ADDR) >= HX_PARAM_SET_TOTAL) || SingOneFlg) { bRunning = 0; HX_AutoStep = 0; SingOneFlg = 0; if(GetTotal(HX_TOTAL_ADDR) >= HX_PARAM_SET_TOTAL) HX_SetAlarmCode(HX_TOTAL_ALARM); } else { HX_AutoStep = 1; HX_AutoDelay = dwTickCount + HX_PARAM_DELAY_DELAY_START; } break; } } } void HuaXian_StepCheckStart(void) { // 启动 if((START_IN_UP) || bStart || HX_bSingle) { bStart = 0; if(!bRunning && (HX_AutoStep == 0)) { if(!HX_DOWN_UP_IN)HX_SetAlarmCode(HX_DW_UP_ALARM); else if(!HX_HX_ORIGIN_IN)HX_SetAlarmCode(HX_HX_ORIGIN); else if(HX_GOUZHEN_IN)HX_SetAlarmCode(HX_GZ_ALARM); else if(HX_GZ_VAVLE)HX_SetAlarmCode(HX_GZ_OUT_ALARM); else if(GetAlarmCode(HX_ALARM_ADDR) != 0); else if(GetTotal(HX_TOTAL_ADDR) >= HX_PARAM_SET_TOTAL) HX_SetAlarmCode(HX_TOTAL_ALARM); else { bRunning = 1; HX_AutoStep = 1; if(HX_bSingle) SingOneFlg= 1; cZipCnt = 0; } } HX_bSingle = 0; } //停止 if(STOP_IN_UP || bStop) { bStop = 0; if(bRunning) { bRunning = 0; HX_AutoStep = 0; HX_MotorStep = 0; HX_HuaXianStep=0; HX_AutoDelay = dwTickCount; HX_MotorDelay = dwTickCount; HX_HXDelay = dwTickCount; SingOneFlg = 0; AxisDecStop(X_AXIS); } else { bRunning = 0; HX_AutoStep = 0; HX_MotorStep = 0; HX_HuaXianStep=0; HX_AutoDelay = dwTickCount; HX_MotorDelay = dwTickCount; HX_HXDelay = dwTickCount; SingOneFlg = 0; HX_GZ_VAVLE = 0; HX_DOWN_VAVLE = 0; HX_HX_VAVLE = 0; HX_SZ_OUT = 1; AxisDecStop(X_AXIS); if(GetAlarmCode(HX_ALARM_ADDR) != 0)SetAlarmCode(HX_ALARM_ADDR,0); } } if(bAlarmStop) { bAlarmStop = 0; bRunning = 0; HX_AutoStep = 0; HX_MotorStep = 0; HX_HuaXianStep=0; HX_AutoDelay = dwTickCount; HX_MotorDelay = dwTickCount; HX_HXDelay = dwTickCount; SingOneFlg = 0; AxisDecStop(X_AXIS); } } //电机动作 void HuaXian_Motor(void) // { switch(HX_MotorStep) { case 30: if(HX_SZ_OUT) { HX_SZ_OUT = 0; HX_MotorDelay = dwTickCount + 50; } HX_MotorStep = 31; break; case 31: if(dwTickCount>=HX_MotorDelay) { MoveAction_Const_AccDec(X_AXIS, HX_DIR_P,HX_PARAM_HIGH_SPEED,1,5,30); HX_MotorDelay = dwTickCount + HX_PARAM_MOTOR_ALARM_TIME; HX_MotorStep = 32; } break; case 32: if(HX_GOUZHEN_IN) { AxisEgmStop(X_AXIS); HX_MotorStep = 35; } if(HX_GUO_LIAN_IN_UP) { if(X_DRV)MoveChangSpeed(X_AXIS,HX_PARAM_LOW_SPEED); HX_MotorDelay = dwTickCount + HX_PARAM_DELAY_GZ; HX_MotorStep = 33; } else if(dwTickCount>=HX_MotorDelay)HX_SetAlarmCode(HX_NO_ZIPPER_ALARM); break; case 33: if(dwTickCount>=HX_MotorDelay) { HX_GZ_VAVLE = 1; HX_MotorDelay = dwTickCount + HX_PARAM_MOTOR_ALARM_TIME; HX_MotorStep = 34; } break; case 34: if(HX_GOUZHEN_IN) { AxisEgmStop(X_AXIS); HX_MotorStep = 35; } else if(dwTickCount>=HX_MotorDelay)HX_SetAlarmCode(HX_GZ_ALARM); break; case 35: if(!X_DRV) { AxisMovePos(X_AXIS,HX_PARAM_LOW_SPEED,QD_PARAM_FZ_LENGTH); HX_MotorStep = 36; } break; case 36: if(!X_DRV) { HX_MotorDelay = dwTickCount; HX_MotorStep = 0; } break; } } #endif