| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 | using Aitex.Core.RT.Routine;using MECF.Framework.Common.Device.LinMot;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 Aitex.Core.RT.Log;namespace PunkHPX8_RT.Devices.LinMot{       public class LinMotResetRoutine : RoutineBase, IRoutine    {        private enum LinMotResetStep        {            ClearError,            ClearErrorDelay,            SwitchOff,            SwitchOn,            Home,            HomeDelay,            HomeWait,            GoToInitialPosition,            ReDelay,            ReWait,            LastSwitchOn,            LastSwitchOff,            End        }        #region 内部变量        private LinMotAxis _axis;        private bool _lastNeedSwitchOff = false;        #endregion        public LinMotResetRoutine(string module,LinMotAxis axis) : base(module)        {            _axis = axis;        }        public void Abort()        {            Runner.Stop("Manual Abort");        }        public RState Monitor()        {            Runner .Run(LinMotResetStep.ClearError, () => { return _axis.SendOperation(LinMotOperation.ClearError); }, NullFun, 100)                .Delay(LinMotResetStep.ClearErrorDelay, 100)                .Run(LinMotResetStep.SwitchOff, () => { return _axis.SendOperation(LinMotOperation.SwitchOff); }, CheckSwitchOff, _delay_5s)                .Run(LinMotResetStep.SwitchOn, () => { return _axis.SendOperation(LinMotOperation.SwitchOn); }, CheckSwitchOn, _delay_5s)                .RunIf(LinMotResetStep.Home,CheckNotHome(), () => { return _axis.SendOperation(LinMotOperation.Home); }, NullFun, 100)                .Delay(LinMotResetStep.HomeDelay, 500)                .WaitWithStopCondition(LinMotResetStep.HomeWait,CheckHomed,CheckAxisHomeIsStop)                .Run(LinMotResetStep.GoToInitialPosition, () => { return _axis.SendOperation(LinMotOperation.GoToInitialPosition); },NullFun,_delay_1ms)                .Delay(LinMotResetStep.ReDelay,_delay_1s)                .Wait(LinMotResetStep.ReWait,CheckInTarget,_delay_5s)                .Run(LinMotResetStep.LastSwitchOn, () => { return  _axis.SendOperation(LinMotOperation.SwitchOn); }, CheckSwitchOn, _delay_5s)                .RunIf(LinMotResetStep.LastSwitchOff, _lastNeedSwitchOff, () => { return _axis.SendOperation(LinMotOperation.SwitchOff); },_delay_1ms)                .End(LinMotResetStep.End, NullFun);            return Runner.Status;        }        public RState Start(params object[] objs)        {            _lastNeedSwitchOff = objs.Length != 0 ? (bool)objs[0] : false;            return Runner.Start(Module, "Reset");        }        private bool CheckSwitchOff()        {            return !_axis.IsSwitchOn;        }        private bool CheckSwitchOn()        {            return _axis.IsSwitchOn;        }        private bool CheckNotHome()        {            return !_axis.IsHomed;        }        private bool CheckHomed()        {            return _axis.IsHomed;        }        private bool CheckInTarget()        {            return _axis.InTargetPosition;        }        private bool CheckAxisTargetIsStop()        {            if(_axis.InTargetPosition)            {                return false;            }            bool result= !_axis.IsMotorOn;            if(result)            {                LOG.WriteLog(eEvent.ERR_PREWET, Module, "Axis is Stop");                return true;            }            return false;        }        private bool CheckAxisHomeIsStop()        {            if (_axis.IsHomed)            {                return false;            }            bool result = !_axis.IsMotorOn;            if (result)            {                LOG.WriteLog(eEvent.ERR_PREWET, Module, "Axis is Stop");                return true;            }            return false;        }    }}
 |