ModuleHomeAllRoutine.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. using Aitex.Core.RT.Fsm;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.Equipment;
  5. using MECF.Framework.Common.Routine;
  6. using CyberX8_Core;
  7. using CyberX8_RT.Modules.Loader;
  8. using CyberX8_RT.Modules.PUF;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using CyberX8_RT.Modules.Transporter;
  15. namespace CyberX8_RT.Modules
  16. {
  17. public class ModuleHomeAllRoutine : RoutineBase, IRoutine
  18. {
  19. private enum HomeStep
  20. {
  21. DualPufHome,
  22. DelayPuf,
  23. DualPufHomeWait,
  24. LoaderHome,
  25. LoaderDelay,
  26. LoaderHomeWait,
  27. LoaderTransporterHome,
  28. LoaderTransporterDelay,
  29. LoaderTransporterHomeWait,
  30. ProcessTransporterHome,
  31. ProcessTransporterDelay,
  32. ProcessTransporterHomeWait,
  33. End
  34. }
  35. #region 内部变量
  36. private PUFEntity _puf1Entity;
  37. private PUFEntity _puf2Entity;
  38. private LoaderEntity _loaderEntity;
  39. private TransporterEntity _loaderTransporterEntity;
  40. private TransporterEntity _processTransporterEntity;
  41. #endregion
  42. /// <summary>
  43. /// 构造函数
  44. /// </summary>
  45. /// <param name="module"></param>
  46. public ModuleHomeAllRoutine(string module) : base(module)
  47. {
  48. }
  49. /// <summary>
  50. /// 中止
  51. /// </summary>
  52. public void Abort()
  53. {
  54. Runner.Stop("Manual Stop");
  55. }
  56. /// <summary>
  57. /// 监控
  58. /// </summary>
  59. /// <returns></returns>
  60. public RState Monitor()
  61. {
  62. Runner.Run(HomeStep.DualPufHome, HomeDualPuf, _delay_1ms)
  63. .Delay(HomeStep.DelayPuf, _delay_1s)
  64. .WaitWithStopCondition(HomeStep.DualPufHomeWait, CheckHomeDualPufStatus, CheckHomeDualPufStopStatus)
  65. .Run(HomeStep.LoaderHome, HomeLoaderEntity, _delay_1ms)
  66. .Delay(HomeStep.LoaderDelay, _delay_1s)
  67. .WaitWithStopCondition(HomeStep.LoaderHomeWait, CheckHomeLoaderStatus, CheckHomeLoaderStopStatus)
  68. .Run(HomeStep.LoaderTransporterHome, HomeLoaderTransporterEntity, _delay_1ms)
  69. .Delay(HomeStep.LoaderTransporterDelay, _delay_1s)
  70. .WaitWithStopCondition(HomeStep.LoaderTransporterHomeWait, CheckHomeLoaderTransporterStatus, CheckHomeLoaderTransporterStopStatus)
  71. .Run(HomeStep.ProcessTransporterHome, HomeProcessTransporterEntity, _delay_1ms)
  72. .Delay(HomeStep.ProcessTransporterDelay, _delay_1s)
  73. .WaitWithStopCondition(HomeStep.ProcessTransporterHomeWait, CheckHomeProcessTransporterStatus, CheckHomeProcessTransporterStopStatus)
  74. .End(HomeStep.End, NullFun, _delay_1ms);
  75. return Runner.Status;
  76. }
  77. /// <summary>
  78. /// Home Dual Puf
  79. /// </summary>
  80. /// <returns></returns>
  81. private bool HomeDualPuf()
  82. {
  83. if (ModuleHelper.IsInstalled(ModuleName.PUF1))
  84. {
  85. if (_puf1Entity.Invoke("HomeAll") == (int)FSM_MSG.ALARM)
  86. {
  87. return false;
  88. }
  89. }
  90. return true;
  91. }
  92. /// <summary>
  93. /// 检验dual puf home情况
  94. /// </summary>
  95. /// <returns></returns>
  96. private bool CheckHomeDualPufStatus()
  97. {
  98. bool puf1Result = true;
  99. if (ModuleHelper.IsInstalled(ModuleName.PUF1))
  100. {
  101. puf1Result = _puf1Entity.IsIdle;
  102. }
  103. return puf1Result;
  104. }
  105. /// <summary>
  106. /// 检验dual puf home失败情况
  107. /// </summary>
  108. /// <returns></returns>
  109. private bool CheckHomeDualPufStopStatus()
  110. {
  111. bool puf1Result = false;
  112. if (ModuleHelper.IsInstalled(ModuleName.PUF1))
  113. {
  114. puf1Result = _puf1Entity.State != (int)PUFSTATE.Idle && _puf1Entity.State != (int)PUFSTATE.Homing; ;
  115. }
  116. bool puf2Result = false;
  117. if (ModuleHelper.IsInstalled(ModuleName.PUF2))
  118. {
  119. puf2Result = _puf2Entity.State != (int)PUFSTATE.Idle && _puf2Entity.State != (int)PUFSTATE.Homing;
  120. }
  121. return puf1Result && puf2Result;
  122. }
  123. /// <summary>
  124. /// Home Loader
  125. /// </summary>
  126. /// <returns></returns>
  127. private bool HomeLoaderEntity()
  128. {
  129. if (ModuleHelper.IsInstalled(ModuleName.Loader1))
  130. {
  131. if (_loaderEntity.Invoke("HomeAll") == (int)FSM_MSG.ALARM)
  132. {
  133. return false;
  134. }
  135. }
  136. return true;
  137. }
  138. /// <summary>
  139. /// 检验Loader home情况
  140. /// </summary>
  141. /// <returns></returns>
  142. private bool CheckHomeLoaderStatus()
  143. {
  144. bool result = true;
  145. if (ModuleHelper.IsInstalled(ModuleName.Loader1))
  146. {
  147. result = _loaderEntity.IsIdle;
  148. }
  149. return result;
  150. }
  151. /// <summary>
  152. /// 检验Loader home失败情况
  153. /// </summary>
  154. /// <returns></returns>
  155. private bool CheckHomeLoaderStopStatus()
  156. {
  157. bool result = false;
  158. if (ModuleHelper.IsInstalled(ModuleName.Loader1))
  159. {
  160. result = _loaderEntity.State != (int)LOADERSTATE.Idle && _loaderEntity.State != (int)LOADERSTATE.Homing;
  161. }
  162. return result;
  163. }
  164. /// <summary>
  165. /// Home LoaderTransporter
  166. /// </summary>
  167. /// <returns></returns>
  168. private bool HomeLoaderTransporterEntity()
  169. {
  170. if (ModuleHelper.IsInstalled(ModuleName.Transporter2))
  171. {
  172. if (_loaderTransporterEntity.Invoke("HomeAll") == (int)FSM_MSG.ALARM)
  173. {
  174. return false;
  175. }
  176. }
  177. return true;
  178. }
  179. /// <summary>
  180. /// 检验LoaderTransporter home情况
  181. /// </summary>
  182. /// <returns></returns>
  183. private bool CheckHomeLoaderTransporterStatus()
  184. {
  185. bool result = true;
  186. if (ModuleHelper.IsInstalled(ModuleName.Transporter2))
  187. {
  188. result = _loaderTransporterEntity.IsIdle;
  189. }
  190. return result;
  191. }
  192. /// <summary>
  193. /// 检验Loader home失败情况
  194. /// </summary>
  195. /// <returns></returns>
  196. private bool CheckHomeLoaderTransporterStopStatus()
  197. {
  198. bool result = false;
  199. if (ModuleHelper.IsInstalled(ModuleName.Transporter2))
  200. {
  201. result = _loaderTransporterEntity.State != (int)TransporterState.Idle && _loaderTransporterEntity.State != (int)TransporterState.Homing;
  202. }
  203. return result;
  204. }
  205. /// <summary>
  206. /// Home ProcessTransporter
  207. /// </summary>
  208. /// <returns></returns>
  209. private bool HomeProcessTransporterEntity()
  210. {
  211. if (ModuleHelper.IsInstalled(ModuleName.Transporter1))
  212. {
  213. if (_processTransporterEntity.Invoke("HomeAll") == (int)FSM_MSG.ALARM)
  214. {
  215. return false;
  216. }
  217. }
  218. return true;
  219. }
  220. /// <summary>
  221. /// 检验LoaderTransporter home情况
  222. /// </summary>
  223. /// <returns></returns>
  224. private bool CheckHomeProcessTransporterStatus()
  225. {
  226. bool result = true;
  227. if (ModuleHelper.IsInstalled(ModuleName.Transporter1))
  228. {
  229. result = _processTransporterEntity.IsIdle;
  230. }
  231. return result;
  232. }
  233. /// <summary>
  234. /// 检验Loader home失败情况
  235. /// </summary>
  236. /// <returns></returns>
  237. private bool CheckHomeProcessTransporterStopStatus()
  238. {
  239. bool result = false;
  240. if (ModuleHelper.IsInstalled(ModuleName.Transporter1))
  241. {
  242. result = _processTransporterEntity.State != (int)TransporterState.Idle && _processTransporterEntity.State != (int)TransporterState.Homing;
  243. }
  244. return result;
  245. }
  246. public RState Start(params object[] objs)
  247. {
  248. _puf1Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF1.ToString());
  249. _puf2Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF2.ToString());
  250. _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  251. _loaderTransporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(ModuleName.Transporter2.ToString());
  252. _processTransporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(ModuleName.Transporter1.ToString());
  253. return Runner.Start("System", "System Home All");
  254. }
  255. }
  256. }