RobotMoveHelper.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.Util;
  3. using CyberX8_Core;
  4. using CyberX8_RT.Modules;
  5. using CyberX8_RT.Modules.Loader;
  6. using CyberX8_RT.Modules.PUF;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.Schedulers;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. namespace CyberX8_RT.Schedulers.EfemRobot
  17. {
  18. public class RobotMoveHelper : Singleton<RobotMoveHelper>
  19. {
  20. private enum RobotOperation
  21. {
  22. None,
  23. Pick,
  24. PickWait,
  25. CheckLoaderPrepare,
  26. Place,
  27. PlaceWait
  28. }
  29. #region 内部变量
  30. private Queue<MoveItem> _queue=new Queue<MoveItem>();
  31. private MoveItem _moveItem;
  32. private RState _state = RState.End;
  33. private RobotOperation _currentOperation=RobotOperation.None;
  34. private EfemEntity _efemEntity;
  35. private LoaderEntity _loaderEntity;
  36. private PUFEntity _puf1Entity;
  37. private PUFEntity _puf2Entity;
  38. private string _module;
  39. #endregion
  40. #region 属性
  41. /// <summary>
  42. /// 是否忙碌
  43. /// </summary>
  44. public bool IsBusy
  45. {
  46. get { return _state == RState.Running; }
  47. }
  48. /// <summary>
  49. /// 是否空闲
  50. /// </summary>
  51. public bool IsIdle
  52. {
  53. get { return _state == RState.End; }
  54. }
  55. /// <summary>
  56. /// 是否错误
  57. /// </summary>
  58. public bool IsError
  59. {
  60. get { return _state == RState.Failed || _state == RState.Timeout; }
  61. }
  62. /// <summary>
  63. /// 当前模块名称
  64. /// </summary>
  65. public string Module { get { return _module; } }
  66. /// <summary>
  67. /// 是否完成
  68. /// </summary>
  69. public bool IsPickCompleted { get { return _currentOperation >= RobotOperation.Place; } }
  70. #endregion
  71. /// <summary>
  72. /// 构造函数
  73. /// </summary>
  74. /// <param name="queue"></param>
  75. public RobotMoveHelper()
  76. {
  77. }
  78. /// <summary>
  79. /// 启动
  80. /// </summary>
  81. /// <param name="queue"></param>
  82. /// <returns></returns>
  83. public bool Start(MoveItem moveItem,string module)
  84. {
  85. _efemEntity = Singleton<RouteManager>.Instance.EFEM;
  86. _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  87. _puf1Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF1.ToString());
  88. _puf2Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF2.ToString());
  89. _moveItem = moveItem;
  90. _queue.Clear();
  91. _queue.Enqueue(moveItem);
  92. _state = RState.Running;
  93. _currentOperation = RobotOperation.Pick;
  94. _module = module;
  95. return true;
  96. }
  97. /// <summary>
  98. /// 监控状态
  99. /// </summary>
  100. /// <returns></returns>
  101. public bool Monitor(string module)
  102. {
  103. if (_module != module)
  104. {
  105. return false;
  106. }
  107. if (_currentOperation == RobotOperation.Pick)
  108. {
  109. if (CheckOtherModuleError())
  110. {
  111. return false;
  112. }
  113. if (_efemEntity.IsIdle)
  114. {
  115. bool result = Pick();
  116. if (result)
  117. {
  118. _currentOperation = RobotOperation.PickWait;
  119. }
  120. }
  121. }
  122. else if (_currentOperation == RobotOperation.PickWait)
  123. {
  124. if (_efemEntity.IsIdle && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0)
  125. && WaferManager.Instance.CheckNoWafer(_moveItem.SourceModule, _moveItem.SourceSlot))
  126. {
  127. if (_moveItem.DestinationType == ModuleType.PUF)
  128. {
  129. _currentOperation = RobotOperation.CheckLoaderPrepare;
  130. }
  131. else
  132. {
  133. _currentOperation = RobotOperation.Place;
  134. }
  135. }
  136. }
  137. else if (_currentOperation == RobotOperation.CheckLoaderPrepare)
  138. {
  139. if(_loaderEntity.State==(int)LOADERSTATE.WaitForUnload)
  140. {
  141. _currentOperation = RobotOperation.Place;
  142. }
  143. }
  144. else if (_currentOperation == RobotOperation.Place)
  145. {
  146. if (CheckOtherModuleError())
  147. {
  148. return false;
  149. }
  150. if (_efemEntity.IsIdle)
  151. {
  152. bool result = Place();
  153. if (result)
  154. {
  155. _currentOperation = RobotOperation.PlaceWait;
  156. }
  157. }
  158. }
  159. else if (_currentOperation == RobotOperation.PlaceWait)
  160. {
  161. if (_efemEntity.IsIdle && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0)
  162. && WaferManager.Instance.CheckHasWafer(_moveItem.DestinationModule, _moveItem.DestinationSlot))
  163. {
  164. _state = RState.End;
  165. _currentOperation = RobotOperation.None;
  166. }
  167. }
  168. return true;
  169. }
  170. //检验其他模块是否故障
  171. private bool CheckOtherModuleError()
  172. {
  173. return _loaderEntity.IsError||_puf1Entity.IsError||_puf2Entity.IsError;
  174. }
  175. /// <summary>
  176. /// 取片
  177. /// </summary>
  178. /// <param name="moveItem"></param>
  179. /// <returns></returns>
  180. private bool Pick()
  181. {
  182. return _efemEntity.CheckToPostMessage<EfemEntity.STATE, EfemEntity.MSG>(eEvent.ERR_EFEM_COMMON_FAILED,
  183. ModuleName.EFEM.ToString(), (int)EfemEntity.MSG.Pick, _queue);
  184. }
  185. /// <summary>
  186. /// 放片
  187. /// </summary>
  188. /// <param name="moveItem"></param>
  189. /// <returns></returns>
  190. private bool Place()
  191. {
  192. return _efemEntity.CheckToPostMessage<EfemEntity.STATE, EfemEntity.MSG>(eEvent.ERR_EFEM_COMMON_FAILED,
  193. ModuleName.EFEM.ToString(), (int)EfemEntity.MSG.Place, _queue);
  194. }
  195. /// <summary>
  196. /// 重置
  197. /// </summary>
  198. public void Reset()
  199. {
  200. _state = RState.End;
  201. _queue.Clear();
  202. }
  203. }
  204. }