123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Routine;
- using MECF.Framework.Common.Routine;
- using PunkHPX8_Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MECF.Framework.Common.Beckhoff.ModuleIO;
- using MECF.Framework.Common.TwinCat;
- using MECF.Framework.Common.IOCore;
- using Aitex.Core.RT.Log;
- namespace PunkHPX8_RT.Devices.Safety
- {
- public class SafetyResetRoutine : RoutineBase, IRoutine
- {
- private enum SafetyResetStep
- {
- RunStop,
- ErrAck,
- LockCasseteDoors,
- LockCellDoors,
- LockAlignerDoors,
- FacilityStoEstopRestart,
- FacilityEstopDelay,
- PlatingCell12Sto1EstopRestart,
- PlatingCell12Sto1EstopDelay,
- PlatingCell12Sto2EstopRestart,
- PlatingCell12Sto2EstopDelay,
- PlatingCell34Sto1EstopRestart,
- PlatingCell34Sto1EstopDelay,
- PlatingCell34Sto2EstopRestart,
- PlatingCell34Sto2EstopDelay,
- Res12StoEstopRestart,
- Res12StoEstopDelay,
- Res34StoEstopRestart,
- Res34StoEstopDelay,
- VpwStoEstopRestart,
- VpwStoEstopDelay,
- SrdStoEstopRestart,
- SrdStoEstopDelay,
- SlsRestart,
- End
- }
- #region 常量
- private const string RUNSTOP = "RunStop";
- #endregion
- #region 内部变量
- private SafetyToggleRoutine _errAckToggleRoutine;
- private SafetyToggleRoutine _facilityStoEstopRestart;
- private SafetyToggleRoutine _platingCell12Sto1EstopRestart;
- private SafetyToggleRoutine _platingCell12Sto2EstopRestart;
- private SafetyToggleRoutine _platingCell34Sto1EstopRestart;
- private SafetyToggleRoutine _platingCell34Sto2EstopRestart;
- private SafetyToggleRoutine _res12StoEstopRestart;
- private SafetyToggleRoutine _res34StoEstopRestart;
- private SafetyToggleRoutine _vpwStoEstopRestart;
- private SafetyToggleRoutine _srdStoEstopRestart;
- private SafetyDevice _device;
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="module"></param>
- public SafetyResetRoutine(string module) : base(module)
- {
- _errAckToggleRoutine = new SafetyToggleRoutine(module);
- _facilityStoEstopRestart = new SafetyToggleRoutine(module);
- _platingCell12Sto1EstopRestart=new SafetyToggleRoutine(module);
- _platingCell12Sto2EstopRestart=new SafetyToggleRoutine(module);
- _platingCell34Sto1EstopRestart= new SafetyToggleRoutine(module);
- _platingCell34Sto2EstopRestart = new SafetyToggleRoutine(module);
- _res12StoEstopRestart=new SafetyToggleRoutine(module);
- _res34StoEstopRestart=new SafetyToggleRoutine(module);
- _vpwStoEstopRestart = new SafetyToggleRoutine(module);
- _srdStoEstopRestart=new SafetyToggleRoutine (module);
- }
- /// <summary>
- /// 中止
- /// </summary>
- public void Abort()
- {
- Runner.Stop("Manaul abort safety reset");
- }
- /// <summary>
- /// 监控
- /// </summary>
- /// <returns></returns>
- public RState Monitor()
- {
- Runner.Run(SafetyResetStep.RunStop, RunStop, _delay_1ms)
- .Run(SafetyResetStep.ErrAck, () => { return _errAckToggleRoutine.Start("ErrAck") == RState.Running; },
- () => { return CheckRoutineStatus(_errAckToggleRoutine); }, _delay_1s)
- .Run(SafetyResetStep.LockCasseteDoors, () => { return _device.LockCasseteDoor(); },CheckCasseteLocked, _delay_5s)
- .Run(SafetyResetStep.LockCellDoors, LockCellDoors,CheckCellLocked, _delay_1ms)
- .Run(SafetyResetStep.LockAlignerDoors, () => { return _device.LockAlignerDoor(); },CheckAlignerLocked, _delay_1ms)
- .Run(SafetyResetStep.FacilityStoEstopRestart, () => { return _facilityStoEstopRestart.Start("FacilityStoEstopRestart") == RState.Running; },
- () => { return CheckRoutineStatus(_facilityStoEstopRestart); }, _delay_1s)
- .Delay(SafetyResetStep.FacilityEstopDelay,100)//100 delay
- .Run(SafetyResetStep.PlatingCell12Sto1EstopDelay, () => { return _platingCell12Sto1EstopRestart.Start("PlatingCell12Sto1EstopRestart") == RState.Running; },
- () => { return CheckRoutineStatus(_platingCell12Sto1EstopRestart); }, _delay_1s)
- .Delay(SafetyResetStep.PlatingCell12Sto1EstopDelay, 100)//100 delay
- .Run(SafetyResetStep.PlatingCell12Sto2EstopDelay, () => { return _platingCell12Sto2EstopRestart.Start("PlatingCell12Sto2EstopRestart") == RState.Running; },
- () => { return CheckRoutineStatus(_platingCell12Sto2EstopRestart); }, _delay_1s)
- .Delay(SafetyResetStep.PlatingCell12Sto1EstopDelay, 100)//100 delay
- .Run(SafetyResetStep.PlatingCell34Sto1EstopDelay, () => { return _platingCell34Sto1EstopRestart.Start("PlatingCell34Sto1EstopRestart") == RState.Running; },
- () => { return CheckRoutineStatus(_platingCell34Sto1EstopRestart); }, _delay_1s)
- .Delay(SafetyResetStep.PlatingCell34Sto1EstopDelay, 100)//100 delay
- .Run(SafetyResetStep.PlatingCell34Sto2EstopDelay, () => { return _platingCell34Sto1EstopRestart.Start("PlatingCell34Sto2EstopRestart") == RState.Running; },
- () => { return CheckRoutineStatus(_platingCell34Sto2EstopRestart); }, _delay_1s)
- .Delay(SafetyResetStep.PlatingCell34Sto1EstopDelay, 100)//100 delay
- .Run(SafetyResetStep.Res12StoEstopDelay, () => { return _res12StoEstopRestart.Start("Res12StoEstopRestart") == RState.Running; },
- () => { return CheckRoutineStatus(_res12StoEstopRestart); }, _delay_1s)
- .Delay(SafetyResetStep.Res12StoEstopDelay, 100)//100 delay
- .Run(SafetyResetStep.Res34StoEstopDelay, () => { return _res34StoEstopRestart.Start("Res34StoEstopRestart") == RState.Running; },
- () => { return CheckRoutineStatus(_res34StoEstopRestart); }, _delay_1s)
- .Delay(SafetyResetStep.Res34StoEstopDelay, 100)//100 delay
- .Run(SafetyResetStep.VpwStoEstopRestart, () => { return _vpwStoEstopRestart.Start("VpwStoEstopRestart") == RState.Running; },
- () => { return CheckRoutineStatus(_vpwStoEstopRestart); }, _delay_1s)
- .Delay(SafetyResetStep.VpwStoEstopDelay, 100)//100 delay
- .Run(SafetyResetStep.SrdStoEstopRestart, () => { return _srdStoEstopRestart.Start("SrdStoEstopRestart") == RState.Running; },
- () => { return CheckRoutineStatus(_srdStoEstopRestart); }, _delay_1s)
- .Delay(SafetyResetStep.SrdStoEstopRestart, 100)//100 delay
- .End(SafetyResetStep.End, NullFun, _delay_1ms);
- return Runner.Status;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- private bool RunStop()
- {
- string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{RUNSTOP}");
- return IOModuleManager.Instance.WriteIoValue(ioName, true);
- }
- /// <summary>
- /// 检验是否完成
- /// </summary>
- /// <param name="routine"></param>
- /// <returns></returns>
- private bool CheckRoutineStatus (IRoutine routine)
- {
- RState rsState = routine.Monitor();
- return rsState == RState.End;
- }
- /// <summary>
- /// 检验Process door locked状态
- /// </summary>
- /// <returns></returns>
- private bool CheckCasseteLocked()
- {
- return _device.SafetyData.CassetteDoorsLeftLocked&& _device.SafetyData.CassetteDoorsRightLocked;
- }
- /// <summary>
- /// lock cell doors
- /// </summary>
- /// <returns></returns>
- private bool LockCellDoors()
- {
- return _device.LockCell12Door() && _device.LockCell34Door();
- }
- /// <summary>
- /// 检验Cell locked状态
- /// </summary>
- /// <returns></returns>
- private bool CheckCellLocked()
- {
- return _device.SafetyData.Cell12DoorsLeftLocked && _device.SafetyData.Cell12DoorsRightLocked && _device.SafetyData.Cell34DoorsLeftLocked &&
- _device.SafetyData.Cell34DoorsRightLocked;
- }
- /// <summary>
- /// 检验Aligner door locked
- /// </summary>
- /// <returns></returns>
- private bool CheckAlignerLocked()
- {
- return _device.SafetyData.AlignerDoorClosed;
- }
- /// <summary>
- /// 启动
- /// </summary>
- /// <param name="objs"></param>
- /// <returns></returns>
- public RState Start(params object[] objs)
- {
- _device = DEVICE.GetDevice<SafetyDevice>("Safety");
- return Runner.Start(Module, "Start Reset safety");
- }
- }
- }
|