#include "global.h" #if TONG_YONG_MACHINE void HMDZ_ManualAction(void); void HMDZ_AutoAction(void); void HMDZ_StepCheckStart(void); void HMDZ_Motor(void); void HMDZ_ExtiActionX31(void); static long save_limit_pos,cRealPos; void HMDZ_ExtiActionX31(void) { } void HMDZ_SetAlarmCode(unsigned alarm_code) { SetAlarmCode(HMDZ_ALARM_ADDR,alarm_code); bAlarmStop = 1; } void HMDZ_InitAction(void) { HMDZ_SZ_OUT = 1; } void HMDZ_Action(void) { HMDZ_Motor(); HMDZ_ManualAction(); HMDZ_AutoAction(); HMDZ_StepCheckStart(); // 调用脚踏开关检测程序 } //手动动作 void HMDZ_ManualAction(void) { if(HMDZ_bRunning == 0) { if(HMDZ_bClearTotal) //切断计数清零 { HMDZ_bClearTotal = 0; ClrcToTal(HMDZ_TOTAL_ADDR); } if(HMDZ_bSS) { HMDZ_bSS = 0; HMDZ_SS_VAVLE = ~HMDZ_SS_VAVLE; } if(HMDZ_bDL) { HMDZ_bDL = 0; HMDZ_DL_VAVLE = ~HMDZ_DL_VAVLE; } if(HMDZ_bQS) { HMDZ_bQS = 0; HMDZ_QS_VAVEL = ~HMDZ_QS_VAVEL; } if(HMDZ_bTS) { HMDZ_bTS = 0; HMDZ_TS_VAVLE = ~HMDZ_TS_VAVLE; } if(HMDZ_bJL) { HMDZ_bJL = 0; HMDZ_JL_VAVLE = ~HMDZ_JL_VAVLE; } if(HMDZ_bYL) { HMDZ_bYL = 0; HMDZ_CL_VAVLE = ~HMDZ_CL_VAVLE; } if(HMDZ_bCL) { HMDZ_bCL = 0; HMDZ_SS_VAVLE = ~HMDZ_SS_VAVLE; } //电机控制 if(HMDZ_bGoMotor) { HMDZ_SZ_OUT = 0; if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,HMDZ_DIR_N,5,1,5,5); } if(HMDZ_bBackMotor) { HMDZ_SZ_OUT = 0; if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,HMDZ_DIR_P,5,1,5,5); } if(!HMDZ_bGoMotor && !HMDZ_bBackMotor && (HMDZ_MotorStep == 0)) { if(X_DRV)AxisDecStop(X_AXIS); } } } void HMDZ_AutoAction(void) { if(HMDZ_bRunning) { switch(HMDZ_AutoStep) { case 1: if(dwTickCount >= HMDZ_AutoDelay) { HMDZ_AutoStep = 2; HMDZ_JL_VAVLE = 1; HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_YL_DELAY; } break; case 2: if(dwTickCount >= HMDZ_AutoDelay) { HMDZ_YL_VAVLE = 1; HMDZ_JL_VAVLE = 0; HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_DL_DELAY; HMDZ_AutoStep = 3; } break; case 3: if(dwTickCount >= HMDZ_AutoDelay) { HMDZ_DL_VAVLE = 1; HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 4; } break; case 4: if(HMDZ_DL_LIMIT_IN && HMDZ_SG_LIMIT_IN) { HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_SS_DELAY; HMDZ_AutoStep = 5; } else if(dwTickCount >= HMDZ_AutoDelay) { if(!HMDZ_DL_LIMIT_IN)HMDZ_SetAlarmCode(HMDZ_DL_LIMIT_ALARM); else HMDZ_SetAlarmCode(HMDZ_SG_LIMIT_ALARM); } break; case 5: if(dwTickCount >= HMDZ_AutoDelay) { HMDZ_SS_VAVLE = 1; HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 6; } break; case 6: if(HMDZ_SS_LIMIT_IN) { HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_SS_BACK_DELAY; HMDZ_AutoStep = 7; } else if(dwTickCount >= HMDZ_AutoDelay) HMDZ_SetAlarmCode(HMDZ_SS_LIMIT_ALARM); break; case 7: if(dwTickCount >= HMDZ_AutoDelay) { HMDZ_SS_VAVLE = 0; HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 8; } break; case 8: if(HMDZ_SS_ORIGIN_IN && !HMDZ_MOTOR_ORIGIN_IN) { HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_RS_MOTOR_DELAY+50; HMDZ_SZ_OUT = 0; HMDZ_AutoStep = 9; } else if(dwTickCount >= HMDZ_AutoDelay) { if(!HMDZ_SS_ORIGIN_IN) HMDZ_SetAlarmCode(HMDZ_SS_ORIGIN_ALARM); else HMDZ_SetAlarmCode(HMDZ_MOTOR_ORIGIN_ALARM); } break; case 9: if(dwTickCount >= HMDZ_AutoDelay) { if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,HMDZ_DIR_N,HMDZ_PARAM_RS_MOTOR_SPEED,HMDZ_PARAM_RS_MOTOR_START_SPEED,HMDZ_PARAM_RS_MOTOR_ACC,HMDZ_PARAM_RS_MOTOR_DEC); HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 10; } break; case 10: if(HMDZ_MOTOR_ORIGIN_IN) { HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 11; } else if(dwTickCount >= HMDZ_AutoDelay) HMDZ_SetAlarmCode(HMDZ_MOTOR_ORIGIN_ALARM); break; case 11: if(HMDZ_RS_LIMIT_IN) { HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_RS_MOTOR_STOP_DELAY; HMDZ_AutoStep = 12; } else if(dwTickCount >= HMDZ_AutoDelay) HMDZ_SetAlarmCode(HMDZ_RS_LIMIT_ALARM); break; case 12: if(dwTickCount >= HMDZ_AutoDelay) { if(X_DRV)AxisDecStop(X_AXIS); HMDZ_AutoStep = 13; } break; case 13: if(!X_DRV) { HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_TS_DELAY; HMDZ_AutoStep = 14; } break; case 14: if(dwTickCount >= HMDZ_AutoDelay) { HMDZ_TS_VAVLE = 1; HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 15; } break; case 15: if(HMDZ_TS_LIMIT_IN) { HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_QS_DELAY; HMDZ_AutoStep = 16; } else if(dwTickCount >= HMDZ_AutoDelay) HMDZ_SetAlarmCode(HMDZ_TS_LIMIT_ALARM); break; case 16: if(dwTickCount >= HMDZ_AutoDelay) { HMDZ_QS_VAVEL = 1; HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 17; } break; case 17: if(HMDZ_QS_LIMIT_IN) { HMDZ_AutoDelay = dwTickCount; HMDZ_AutoStep = 18; } else if(dwTickCount >= HMDZ_AutoDelay) HMDZ_SetAlarmCode(HMDZ_QS_LIMIT_ALARM); break; case 18: if(dwTickCount >= HMDZ_AutoDelay) { HMDZ_DL_VAVLE = 0; HMDZ_TS_VAVLE = 0; HMDZ_YL_VAVLE = 0; HMDZ_CL_VAVLE = 1; HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_CL_BACK_DELAY; HMDZ_AutoStep = 19; } break; case 19: if(dwTickCount >= HMDZ_AutoDelay) { HMDZ_CL_VAVLE = 0; HMDZ_QS_VAVEL = 0; HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 20; } break; case 20: if(HMDZ_DL_ORIGIN_IN && HMDZ_QS_ORIGIN_IN && HMDZ_TS_ORIGIN_IN && HMDZ_SS_ORIGIN_IN) { HMDZ_AutoDelay = dwTickCount; HMDZ_AutoStep = 21; } else if(dwTickCount >= HMDZ_AutoDelay) { if(!HMDZ_DL_ORIGIN_IN) HMDZ_SetAlarmCode(HMDZ_DL_ORIGIN_ALARM); else if(!HMDZ_QS_ORIGIN_IN) HMDZ_SetAlarmCode(HMDZ_QS_ORIGIN_ALARM); else if(!HMDZ_TS_ORIGIN_IN) HMDZ_SetAlarmCode(HMDZ_TS_ORIGIN_ALARM); else HMDZ_SetAlarmCode(HMDZ_SS_ORIGIN_ALARM); } break; case 21: if(dwTickCount >= HMDZ_AutoDelay) { if(!X_DRV)MoveAction_Const_AccDec(X_AXIS,HMDZ_DIR_P,HMDZ_PARAM_RS_MOTOR_SPEED,HMDZ_PARAM_RS_MOTOR_START_SPEED,HMDZ_PARAM_RS_MOTOR_ACC,HMDZ_PARAM_RS_MOTOR_DEC); HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 22; } break; case 22: if(HMDZ_MOTOR_ORIGIN_IN) { if(X_DRV)AxisDecStop(X_AXIS); HMDZ_AutoStep = 23; } else if(dwTickCount >= HMDZ_AutoDelay) HMDZ_SetAlarmCode(HMDZ_MOTOR_ORIGIN_ALARM); break; case 23: if(!X_DRV) { HMDZ_SS_VAVLE = 1; HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 24; } break; case 24: if(HMDZ_SS_LIMIT_IN) { HMDZ_SS_VAVLE = 0; HMDZ_QS_VAVEL = 1; HMDZ_AutoStep = 25; HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; } else if(dwTickCount >= HMDZ_AutoDelay) HMDZ_SetAlarmCode(HMDZ_SS_LIMIT_ALARM); break; case 25: if(HMDZ_QS_LIMIT_IN) { HMDZ_CL_VAVLE = 1; HMDZ_AutoStep = 26; HMDZ_AutoDelay = dwTickCount+HMDZ_PARAM_CL_BACK_DELAY; } else if(dwTickCount >= HMDZ_AutoDelay) HMDZ_SetAlarmCode(HMDZ_QS_LIMIT_ALARM); break; case 26: if(dwTickCount >= HMDZ_AutoDelay) { HMDZ_CL_VAVLE = 0; HMDZ_QS_VAVEL = 0; HMDZ_AutoDelay = dwTickCount+VAVLE_ALARM_TIME; HMDZ_AutoStep = 27; } break; case 27: if(HMDZ_QS_ORIGIN_IN) { HMDZ_AutoStep = 28; } else if(dwTickCount >= HMDZ_AutoDelay) HMDZ_SetAlarmCode(HMDZ_QS_ORIGIN_ALARM); break; case 28: if(HMDZ_MotorStep == 0) { AddToTal(HMDZ_TOTAL_ADDR); CalProSP(HMDZ_PROSPEED_ADDR); HMDZ_AutoStep = 1; } break; } } } void HMDZ_StepCheckStart(void) { // 启动 if((HMDZ_START_IN) || HMDZ_bStart) { HMDZ_bStart = 0; if(!HMDZ_bRunning && (HMDZ_AutoStep == 0)) { if(!HMDZ_MOTOR_ORIGIN_IN)HMDZ_SetAlarmCode(HMDZ_MOTOR_ORIGIN_ALARM); else if(!HMDZ_DL_ORIGIN_IN)HMDZ_SetAlarmCode(HMDZ_DL_ORIGIN_ALARM); else if(!HMDZ_QS_ORIGIN_IN)HMDZ_SetAlarmCode(HMDZ_QS_ORIGIN_ALARM); else if(!HMDZ_TS_ORIGIN_IN) HMDZ_SetAlarmCode(HMDZ_TS_ORIGIN_ALARM); else if(!HMDZ_SS_ORIGIN_IN)HMDZ_SetAlarmCode(HMDZ_SS_ORIGIN_ALARM); else { HMDZ_bRunning = 1; HMDZ_AutoStep = 1; } } } //停止 if(HMDZ_STOP_IN_UP || HMDZ_bStop) { HMDZ_bStop = 0; HMDZ_bRunning = 0; HMDZ_AutoStep = 0; HMDZ_MotorStep = 0; HMDZ_SS_VAVLE = 0; HMDZ_DL_VAVLE = 0; HMDZ_QS_VAVEL = 0; HMDZ_TS_VAVLE = 0; HMDZ_JL_VAVLE = 0; HMDZ_YL_VAVLE = 0; HMDZ_CL_VAVLE = 0; HMDZ_SZ_OUT = 1; AxisDecStop(X_AXIS); if(GetAlarmCode(HMDZ_ALARM_ADDR) != 0)SetAlarmCode(HMDZ_ALARM_ADDR,0); } if(HMDZ_bAlarmStop) { HMDZ_bAlarmStop = 0; HMDZ_bRunning = 0; HMDZ_AutoStep = 0; HMDZ_MotorStep = 0; HMDZ_SS_VAVLE = 0; HMDZ_DL_VAVLE = 0; HMDZ_QS_VAVEL = 0; HMDZ_TS_VAVLE = 0; HMDZ_JL_VAVLE = 0; HMDZ_YL_VAVLE = 0; HMDZ_CL_VAVLE = 0; } } void HMDZ_Motor(void) { user_datas[121]= HMDZ_MotorStep; user_datas[125] = HMDZ_AutoStep; switch(HMDZ_MotorStep) { } } #endif