#OnInit state_estop = 0; state_idle = 1; state_pause = 2; state_run = 3; state_alarm = 4; state_alarm_cleared = 5; _no_pressure = _extin1|3; _door_open = _extin1|1; door_error = 1; pressure_error = 2; alarm_from_init = 0; timer=0; estop = _hw_estop && _hw_idle; if(estop, state=state_estop); idle = (_hw_buffempty && !_hw_run) && !_hw_estop && _alarm_cleared; if(idle, state=state_idle); _no_pressure = _extin1|3; alarm = !_hw_estop && (!_alarm_cleared || _no_pressure); _no_pressure = _extin1|3; if(alarm, if(_no_pressure, exec(state=state_alarm, alarm_from_init=1, msg('INIT: NO PRESSURE')), if(!_alarm_cleared, exec(state=state_alarm, alarm_from_init=1, msg('INIT: Please Reset Error',_last_status)) ) ) ); if(!_alarm_cleared, If(_last_status==door_error, status("Last error: Open Door Error"), status("Last error: No Pressure error") ), status("No error") ); ;*************************************************************** #Loop ;izvede se vsakih 100ms if (state == state_estop, exec('#StateEStop')); if (state == state_idle, exec('#StateIdle')); if (state == state_run, exec('#StateRun')); if (state == state_pause, exec('#StatePause')); if (state == state_alarm, exec('#StateAlarm')); if (state == state_alarm_cleared, exec('#StateAlarmCleared')); timer=timer+1; if(GE(timer,8), exec(timer=0, if(state==state_alarm, _extout1|4=~_extout1|4) ) ); ;*************************************************************** #StateEStop if (state != state_estop, return(0)); if (_state_last != state_estop, exec('#StateEStopInit')); ;tu preverjamo pogoje za prehod stanj. Kateri pogoji so to, je pa odvisno od prehodov iz posameznih stanj (glej tablo) idle = (_hw_buffempty && !_hw_run) && !_hw_estop && _alarm_cleared; if(idle, exec('#StateEStopEnd', state = state_idle,alarm_from_estop=0, return())); if((!_alarm_cleared && !_hw_estop), exec('#StateEStopEnd',alarm_from_estop =1, state = state_alarm, return())); #StateEStopInit _state_last = state_estop; print('EStop: ',estop); _extout1|5 = 1; _extout1|1 = 0; _extout1|2 = 0; _extout1|3 = 0; #StateEStopEnd ;*************************************************************** #StateIdle if (state != state_idle, return(0)); if (_state_last != state_idle, exec('#StateIdleInit')); ;tu preverjamo pogoje za prehod stanj. Kateri pogoji so to, je pa odvisno od prehodov iz posameznih stanj (glej tablo) estop = _hw_estop && _hw_idle; if(estop, exec('#StateIdleEnd', state = state_estop, return())); run = !_hw_idle && !_hw_pause && !_hw_estop && !_hw_isjog; if(run, exec('#StateIdleEnd', state = state_run, return())); pause = _hw_pause && !_hw_estop; if(pause, exec('#StateRunEnd', state = state_pause, return())); alarm = !_hw_estop && _extin1|3; if(alarm, exec('#StateIdleEnd', state = state_alarm, _no_pressure=_extin1|3, return())); #StateIdleInit _state_last = state_idle; _extout1|5 = 0; _extout1|1 = 1; _extout1|2 = 0; _extout1|3 = 0; _extout1|4 = 0; #StateIdleEnd print('Idle: ', idle); ;*************************************************************** #StateRun if (state != state_run, return(0)); if (_state_last != state_run, exec('#StateRunInit')); estop = _hw_estop && _hw_idle; if(estop, exec('#StateRunEnd', state = state_estop, return())); idle = (_hw_buffempty && !_hw_run) && !_hw_estop; if(idle, exec('#StateRunEnd', state = state_idle, return())); alarm = !_hw_estop && (_extin1|1 || _extin1|3); if(alarm, if(_extin1|1, exec('#StateRunEnd', state = state_alarm,_door_open=_extin1|1, return()), if(_extin1|3, exec('#StateRunEnd', state = state_alarm,_no_pressure=_extin1|3, return()) ) ) ); pause = _hw_pause && !_hw_estop; if(pause, exec('#StateRunEnd', state = state_pause, return())); #StateRunInit _state_last = state_run; _extout1|5 = 0; _extout1|1 = 0; _extout1|2 = 1; _extout1|3 = 0; #StateRunEnd ;*************************************************************** #StatePause if (state != state_pause, return(0)); if (_state_last != state_pause, exec('#StatePauseInit')); estop = _hw_estop && _hw_idle; if(estop, exec('#StatePauseEnd', state = state_estop, return())); run = !_hw_idle && !_hw_pause && !_hw_estop; if(run, exec('#StatePauseEnd', state = state_run, return())); alarm = !_hw_estop && (_extin1|1 || _extin1|3); if(alarm, if(_extin1|1, exec('#StateRunEnd', state = state_alarm,_door_open=_extin1|1, return()), if(_extin1|3, exec('#StateRunEnd', state = state_alarm,_no_pressure=_extin1|3, return()) ) ) ); idle = (_hw_buffempty && !_hw_run) && !_hw_estop; if(idle, exec('#StatePauseEnd', state = state_idle, return())); #StatePauseInit _state_last = state_pause; _extout1|5 = 0; _extout1|1 = 0; _extout1|2 = 1; _extout1|3 = 1; #StatePauseEnd ;*************************************************************** #StateAlarm if (state != state_alarm, return(0)); if (_state_last != state_alarm, exec('#StateAlarmInit')); estop = _hw_estop && _hw_idle; if( estop, exec( '#StateAlarmEnd', state = state_estop, return() ) ); alarm_cleared = !_hw_estop && !_extin1|1 && !_extin1|3 && _extin1|2; if(alarm_cleared,exec(state = state_alarm_cleared,_door_open= _extin1|1,_no_pressure = _extin1|3, return())); #StateAlarmInit _alarm_cleared=0; _state_last = state_alarm; _extout1|5 = 0; _extout1|1 = 0; _extout1|2 = 0; _extout1|3 = 0; _extout1|4 = 1; exec('#ErrorDefine'); #StateAlarmEnd ;*************************************************************** #StateAlarmCleared if (state != state_alarm_cleared, return(0)); if (_state_last != state_alarm_cleared, exec('#StateAlarmClearedInit')); #StateAlarmClearedInit _state_last = state_alarm_cleared; _extout1|5 = 0; _extout1|1 = 1; _extout1|2 = 0; _extout1|3 = 0; _extout1|4 = 0; _alarm_cleared = 1; status("NO ERROR"); state=state_idle; print('alarm cleared: ', _alarm_cleared); ;*************************************************************** #Loop5 #Loop15 #Loop60 #Loop300 #OnShutdown print('OnShutdown'); ;************************************************* #OnStart status(); if(_alarm_cleared,return(0), (exec(msg('ON START: Please reset error:',_last_status),state=state_alarm,return(nan))) ); ;************************************************* #OnEnd status("NC Program finished with normal stop"); ;************************************************* #OnStop if(arg1 == 0, exec(status("Manual stop by user")) ); if(arg1 == 3, exec(status("SW Error:Abort"),return(0)) ); if(arg1 == 10,exec(status("SW Error:GCodeAbort"),return(0))); if(arg1 == 11,exec(status("SW Error:GCodeError"),return(0))); if(arg1 == 12,exec(status("SW Error:GCodeAbort"),return(0))); if(arg1 == 13,exec(status("SW Error:LimitError"),return(0))); if(arg1 == 14,exec(status("SW Error:SyncError"),return(0))); if(arg1 == 15,status("SW Error:OutputError"),return(0)); if(arg1 == 16,status("SW Error:BeginError"),return(0)); if(arg1 == 17,status("SW Error:ProbeError"),return(0)); if(arg1 == 18,status("SW Error:LicenseError"),return(0)); ;************************************************* ;no error stop arg1= 0 ;Abort = 3 ;GCodeAbort = 10, ;GCodeError, =11 ;SpeedError, =12 ;LimitError, =13 ;SyncError, =14 ;OutputError, =15 ;BeginError, =16 ;ProbeError, =17 ;LicenseError, =18 #OnEStop #OnJog #OnWheel #OnCmd ;************************************************* #ErrorDefine if(alarm_from_init || alarm_from_estop, if(alarm_from_init, exec(alarm_from_init = 0,return()), exec(alarm_from_estop = 0,return()) ), if(_door_open, exec(stop(),beep(220,1),msg('Door is open!'),status("OPEN DOOR"),_last_status = door_error), if(_no_pressure, exec(stop(),beep(220,1),msg('NO PRESSURE!'),status("NO PRESSURE"),_last_status = pressure_error)) ) ); ;*************************************************