RobotMoveHelper.cs 5.7 KB

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