FlipperHomeRoutine.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using athosRT.Devices.FLP;
  7. using athosRT.FSM;
  8. using athosRT.tool;
  9. using MECF.Framework.Common.Equipment;
  10. namespace athosRT.Modules.FLP
  11. {
  12. public class FlipperHomeRoutine : ModuleRoutineBase, IRoutine
  13. {
  14. private FlipperBase _flipper;
  15. private ModuleName modulename;
  16. private int _WaitTimeout;
  17. private int _ClampTimeout;
  18. private int _TurnTimeout;
  19. public FlipperHomeRoutine(ModuleName module, FlipperBase flipper) : base(module)
  20. {
  21. modulename = module;
  22. _flipper = flipper;
  23. _WaitTimeout = 60*1000;
  24. _ClampTimeout = 60 * 1000;
  25. _TurnTimeout = 60 * 1000;
  26. }
  27. public RState Start(params object[] objs)
  28. {
  29. if (_flipper == null)
  30. {
  31. LogObject.Error(Module.ToString(),"Flipper is null. Cannot Start");
  32. return RState.Failed;
  33. }
  34. return Runner.Start(modulename, "Flipper Home Start");
  35. }
  36. public RState Monitor()
  37. {
  38. Runner
  39. .Run(FlipperHomeStep.WaitForDevice, fReset, fCheckMotionOver, _WaitTimeout)
  40. .Delay(FlipperHomeStep.DeviceWait1, 1000)
  41. //.Run((int)FlipperHomeStep.ClampOpen, fClampOpen, fIsClampOpen, _ClampTimeout)
  42. .Run(FlipperHomeStep.ClampClose, fClampClose, fIsClampClose, _ClampTimeout)
  43. .Delay(FlipperHomeStep.DeviceWait2, 1000)
  44. .End(FlipperHomeStep.TurnToHome, fTurnToHome, fCheckMotionOver, _TurnTimeout);
  45. return Runner.Status;
  46. }
  47. private bool fIsClampOpen()
  48. {
  49. if (_flipper.IsBusy && _flipper.IsClampOpen)
  50. {
  51. //忙状态
  52. //_flipper.ShowAction();
  53. LogObject.Info(modulename.ToString(), $"busy状态");
  54. return false;
  55. }
  56. else
  57. {
  58. //空闲状态
  59. LogObject.Info(modulename.ToString(), "进入空闲状态");
  60. return true;
  61. }
  62. }
  63. private bool fIsClampClose()
  64. {
  65. if (_flipper.IsBusy && _flipper.IsClampClose)
  66. {
  67. //忙状态
  68. //_flipper.ShowAction();
  69. LogObject.Info(modulename.ToString(), $"busy状态");
  70. return false;
  71. }
  72. else
  73. {
  74. //空闲状态
  75. LogObject.Info(modulename.ToString(), "进入空闲状态");
  76. return true;
  77. }
  78. }
  79. private bool fReset()
  80. {
  81. _flipper.Reset();
  82. return true;
  83. }
  84. private bool fClampOpen()
  85. {
  86. //有错误 驱动层已打出原因log
  87. if (_flipper.Clamp(false))
  88. {
  89. LogObject.Info(modulename.ToString(), "开始 Clamp Open.");
  90. return true;
  91. }
  92. else
  93. {
  94. LogObject.Error(modulename.ToString(), $"HOME Clamp failed.{_flipper.State}");
  95. return false;
  96. }
  97. }
  98. private bool fClampClose()
  99. {
  100. //有错误 驱动层已打出原因log
  101. if (_flipper.Clamp(true))
  102. {
  103. LogObject.Info(modulename.ToString(), "开始HOME Clamp close.");
  104. return true;
  105. }
  106. else
  107. {
  108. LogObject.Error(modulename.ToString(), $"HOME Clamp failed.{_flipper.State}");
  109. return false;
  110. }
  111. }
  112. private bool fTurnToHome()
  113. {
  114. //关闭
  115. //有错误 驱动层已打出log
  116. if (_flipper.Home())
  117. {
  118. LogObject.Info(modulename.ToString(),"开始HOME Turn");
  119. return true;
  120. }
  121. else
  122. {
  123. LogObject.Error(modulename.ToString(), $"HOME Turn failed.{_flipper.State}");
  124. return false;
  125. }
  126. }
  127. private bool fCheckMotionOver()
  128. {
  129. if (_flipper.IsBusy || _flipper.State != FlipperState.Idle)
  130. {
  131. //忙状态
  132. //_flipper.ShowAction();
  133. LogObject.Info(modulename.ToString(), $"busy状态");
  134. return false;
  135. }
  136. else
  137. {
  138. //空闲状态
  139. LogObject.Info(modulename.ToString(),"进入空闲状态");
  140. return true;
  141. }
  142. }
  143. public void Abort()
  144. {
  145. }
  146. enum FlipperHomeStep
  147. {
  148. WaitForDevice,
  149. DeviceWait1,
  150. TurnToHome,
  151. DeviceWait2,
  152. ClampOpen,
  153. ClampClose,
  154. }
  155. }
  156. }