123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using athosRT.Devices.FLP;
- using athosRT.FSM;
- using athosRT.tool;
- using MECF.Framework.Common.Equipment;
- namespace athosRT.Modules.FLP
- {
- public class FlipperHomeRoutine : ModuleRoutineBase, IRoutine
- {
- private FlipperBase _flipper;
- private ModuleName modulename;
- private int _WaitTimeout;
- private int _ClampTimeout;
- private int _TurnTimeout;
- public FlipperHomeRoutine(ModuleName module, FlipperBase flipper) : base(module)
- {
- modulename = module;
- _flipper = flipper;
- _WaitTimeout = 60*1000;
- _ClampTimeout = 60 * 1000;
- _TurnTimeout = 60 * 1000;
- }
- public RState Start(params object[] objs)
- {
- if (_flipper == null)
- {
- LogObject.Error(Module.ToString(),"Flipper is null. Cannot Start");
- return RState.Failed;
- }
- return Runner.Start(modulename, "Flipper Home Start");
- }
- public RState Monitor()
- {
- Runner
- .Run(FlipperHomeStep.WaitForDevice, fReset, fCheckMotionOver, _WaitTimeout)
- .Delay(FlipperHomeStep.DeviceWait1, 1000)
- //.Run((int)FlipperHomeStep.ClampOpen, fClampOpen, fIsClampOpen, _ClampTimeout)
- .Run(FlipperHomeStep.ClampClose, fClampClose, fIsClampClose, _ClampTimeout)
- .Delay(FlipperHomeStep.DeviceWait2, 1000)
- .End(FlipperHomeStep.TurnToHome, fTurnToHome, fCheckMotionOver, _TurnTimeout);
- return Runner.Status;
- }
- private bool fIsClampOpen()
- {
- if (_flipper.IsBusy && _flipper.IsClampOpen)
- {
- //忙状态
- //_flipper.ShowAction();
- LogObject.Info(modulename.ToString(), $"busy状态");
- return false;
- }
- else
- {
- //空闲状态
- LogObject.Info(modulename.ToString(), "进入空闲状态");
- return true;
- }
-
- }
- private bool fIsClampClose()
- {
- if (_flipper.IsBusy && _flipper.IsClampClose)
- {
- //忙状态
- //_flipper.ShowAction();
- LogObject.Info(modulename.ToString(), $"busy状态");
- return false;
- }
- else
- {
- //空闲状态
- LogObject.Info(modulename.ToString(), "进入空闲状态");
- return true;
- }
- }
- private bool fReset()
- {
- _flipper.Reset();
- return true;
- }
- private bool fClampOpen()
- {
- //有错误 驱动层已打出原因log
- if (_flipper.Clamp(false))
- {
- LogObject.Info(modulename.ToString(), "开始 Clamp Open.");
- return true;
- }
- else
- {
- LogObject.Error(modulename.ToString(), $"HOME Clamp failed.{_flipper.State}");
- return false;
- }
- }
- private bool fClampClose()
- {
- //有错误 驱动层已打出原因log
- if (_flipper.Clamp(true))
- {
- LogObject.Info(modulename.ToString(), "开始HOME Clamp close.");
- return true;
- }
- else
- {
- LogObject.Error(modulename.ToString(), $"HOME Clamp failed.{_flipper.State}");
- return false;
- }
- }
- private bool fTurnToHome()
- {
- //关闭
- //有错误 驱动层已打出log
- if (_flipper.Home())
- {
- LogObject.Info(modulename.ToString(),"开始HOME Turn");
- return true;
- }
- else
- {
- LogObject.Error(modulename.ToString(), $"HOME Turn failed.{_flipper.State}");
- return false;
- }
- }
- private bool fCheckMotionOver()
- {
- if (_flipper.IsBusy || _flipper.State != FlipperState.Idle)
- {
- //忙状态
- //_flipper.ShowAction();
- LogObject.Info(modulename.ToString(), $"busy状态");
- return false;
- }
- else
- {
- //空闲状态
- LogObject.Info(modulename.ToString(),"进入空闲状态");
- return true;
- }
- }
- public void Abort()
- {
- }
- enum FlipperHomeStep
- {
- WaitForDevice,
- DeviceWait1,
- TurnToHome,
- DeviceWait2,
- ClampOpen,
- ClampClose,
- }
- }
- }
|