RobotMoveHelper.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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, (int)_moveItem.RobotHand)
  113. && WaferManager.Instance.CheckNoWafer(_moveItem.SourceModule, _moveItem.SourceSlot))
  114. {
  115. _currentOperation = RobotOperation.Place;
  116. }
  117. }
  118. else if (_currentOperation == RobotOperation.Place)
  119. {
  120. if (_efemEntity.IsIdle)
  121. {
  122. bool result = Place();
  123. if (result)
  124. {
  125. _currentOperation = RobotOperation.PlaceWait;
  126. }
  127. }
  128. }
  129. else if (_currentOperation == RobotOperation.PlaceWait)
  130. {
  131. if (_efemEntity.IsIdle && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, (int)_moveItem.RobotHand)
  132. && WaferManager.Instance.CheckHasWafer(_moveItem.DestinationModule, _moveItem.DestinationSlot))
  133. {
  134. _state = RState.End;
  135. _currentOperation = RobotOperation.None;
  136. }
  137. }
  138. return true;
  139. }
  140. /// <summary>
  141. /// 取片
  142. /// </summary>
  143. /// <param name="moveItem"></param>
  144. /// <returns></returns>
  145. private bool Pick()
  146. {
  147. return _efemEntity.CheckToPostMessage<EfemEntity.STATE, EfemEntity.MSG>(eEvent.ERR_EFEM_COMMON_FAILED,
  148. ModuleName.EFEM.ToString(), (int)EfemEntity.MSG.Pick, _queue);
  149. }
  150. /// <summary>
  151. /// 放片
  152. /// </summary>
  153. /// <param name="moveItem"></param>
  154. /// <returns></returns>
  155. private bool Place()
  156. {
  157. return _efemEntity.CheckToPostMessage<EfemEntity.STATE, EfemEntity.MSG>(eEvent.ERR_EFEM_COMMON_FAILED,
  158. ModuleName.EFEM.ToString(), (int)EfemEntity.MSG.Place, _queue);
  159. }
  160. /// <summary>
  161. /// 重置
  162. /// </summary>
  163. public void Reset()
  164. {
  165. _state = RState.End;
  166. _queue.Clear();
  167. }
  168. }
  169. }