SchedulerRobot.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using Aitex.Core.RT.Fsm;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.Util;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.Schedulers;
  7. using CyberX8_Core;
  8. using CyberX8_RT.Modules;
  9. using CyberX8_RT.Modules.PUF;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using MECF.Framework.Common.SubstrateTrackings;
  16. using CyberX8_RT.Modules.Loader;
  17. using CyberX8_RT.Modules.SRD;
  18. namespace CyberX8_RT.Schedulers.EfemRobot
  19. {
  20. public class SchedulerRobot : SchedulerModule
  21. {
  22. private enum SchedulerRobotOperation
  23. {
  24. None,
  25. Pick,
  26. PickWait,
  27. Place,
  28. PlaceWait
  29. }
  30. #region 内部变量
  31. private EfemEntity _efemEntity;
  32. private LoaderEntity _loaderEntity;
  33. private PUFEntity _puf1Entity;
  34. private PUFEntity _puf2Entity;
  35. #endregion
  36. #region 属性
  37. /// <summary>
  38. /// 是否空闲
  39. /// </summary>
  40. public override bool IsIdle
  41. {
  42. get { return _state == RState.End; }
  43. }
  44. /// <summary>
  45. /// 是否错误
  46. /// </summary>
  47. public override bool IsError
  48. {
  49. get { return _state == RState.Failed || _state == RState.Timeout; }
  50. }
  51. #endregion
  52. /// <summary>
  53. /// 构造函数
  54. /// </summary>
  55. /// <param name="module"></param>
  56. public SchedulerRobot(ModuleName module) : base(module.ToString())
  57. {
  58. _efemEntity = Singleton<RouteManager>.Instance.EFEM;
  59. _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  60. _puf1Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF1.ToString());
  61. _puf2Entity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(ModuleName.PUF2.ToString());
  62. }
  63. /// <summary>
  64. /// 执行
  65. /// </summary>
  66. /// <param name="parameter"></param>
  67. /// <returns></returns>
  68. public override bool RunProcess(object recipe, object parameter, List<SchedulerSyncModuleMessage> syncMessages)
  69. {
  70. if (_efemEntity.IsBusy)
  71. {
  72. return false;
  73. }
  74. MoveItem moveItem = (MoveItem)parameter;
  75. if (moveItem.SourceModule != ModuleName.Unknown&&moveItem.DestinationModule!=ModuleName.Unknown)
  76. {
  77. _state = RState.Running;
  78. if (RobotMoveHelper.Instance.IsIdle)
  79. {
  80. RobotMoveHelper.Instance.Start(moveItem, Module.ToString());
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. /// <summary>
  87. /// 监控执行
  88. /// </summary>
  89. /// <returns></returns>
  90. public override bool MonitorProcess(SchedulerSequence schedulerSequence, bool hasMatchWafer)
  91. {
  92. RobotMoveHelper.Instance.Monitor(Module.ToString());
  93. if (RobotMoveHelper.Instance.IsIdle)
  94. {
  95. _state = RState.End;
  96. }
  97. return true;
  98. }
  99. /// <summary>
  100. /// 检验前置条件
  101. /// </summary>
  102. /// <param name="sequenceIndex"></param>
  103. /// <param name="parameter"></param>
  104. /// <returns></returns>
  105. public override bool CheckPrecondition(List<SchedulerSequence> schedulerSequences, int sequenceIndex, object parameter,string materialId, ref string reason)
  106. {
  107. if (parameter == null)
  108. {
  109. reason = "parameter is null";
  110. return true;
  111. }
  112. if (_state == RState.Running)
  113. {
  114. reason = "scheduler module is already running";
  115. return false;
  116. }
  117. if(_efemEntity.IsBusy)
  118. {
  119. reason = "efem is busy";
  120. return false;
  121. }
  122. if(_efemEntity.IsError)
  123. {
  124. reason = "efem is error";
  125. return false;
  126. }
  127. if(_loaderEntity.IsError||_puf1Entity.IsError)
  128. {
  129. reason = "loader or puf is error";
  130. return false;
  131. }
  132. MoveItem moveItem = (MoveItem)parameter;
  133. if(WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot,(int)moveItem.RobotHand))
  134. {
  135. reason = "robot has wafer";
  136. return false;
  137. }
  138. if (moveItem.SourceModule == ModuleName.Unknown)
  139. {
  140. UpdateUnkownSourceModule(schedulerSequences, moveItem, sequenceIndex);
  141. }
  142. if (moveItem.DestinationModule == ModuleName.Unknown)
  143. {
  144. bool result= UpdateUnkownTargetModule(schedulerSequences, moveItem, sequenceIndex);
  145. if (!result)
  146. {
  147. reason = "efem robot confirm target module failed";
  148. return false;
  149. }
  150. }
  151. if (ModuleHelper.IsPUF(moveItem.DestinationModule))
  152. {
  153. PUFEntity pufEntity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(moveItem.DestinationModule.ToString());
  154. if (pufEntity != null)
  155. {
  156. if (pufEntity.State == (int)PUFSTATE.WaitForRobotPlace)
  157. {
  158. return true;
  159. }
  160. else
  161. {
  162. if (pufEntity.IsIdle)
  163. {
  164. pufEntity.CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, Module.ToString(),
  165. (int)PUFMSG.ReadyForRobotPlace);
  166. }
  167. reason = $"{pufEntity.Module} state is not WaitForRobotPlace";
  168. return false;
  169. }
  170. }
  171. else
  172. {
  173. reason = $"{moveItem.DestinationModule} puf is null";
  174. }
  175. }
  176. else if (ModuleHelper.IsPUF(moveItem.SourceModule))
  177. {
  178. PUFEntity pufEntity = Singleton<RouteManager>.Instance.GetModule<PUFEntity>(moveItem.SourceModule.ToString());
  179. if (pufEntity != null)
  180. {
  181. if (pufEntity.State == (int)PUFSTATE.WaitForRobotPick)
  182. {
  183. return true;
  184. }
  185. else
  186. {
  187. if (pufEntity.IsIdle)
  188. {
  189. pufEntity.CheckToPostMessage<PUFSTATE, PUFMSG>(eEvent.ERR_PUF, pufEntity.Module.ToString(),
  190. (int)PUFMSG.ReadyForRobotPick);
  191. }
  192. reason = $"{pufEntity.Module} state is not WaitForRobotPick";
  193. return false;
  194. }
  195. }
  196. else
  197. {
  198. reason = $"{moveItem.SourceModule} puf is null";
  199. return false;
  200. }
  201. }
  202. return true;
  203. }
  204. /// <summary>
  205. /// 更新未知源模块
  206. /// </summary>
  207. private void UpdateUnkownSourceModule(List<SchedulerSequence> schedulerSequences, MoveItem moveItem, int sequenceIndex)
  208. {
  209. if (moveItem.SourceModule == ModuleName.Unknown)
  210. {
  211. if (sequenceIndex >= 1 && sequenceIndex - 1 < schedulerSequences.Count)
  212. {
  213. SchedulerSequence preSchedulerSequence = schedulerSequences[sequenceIndex - 1];
  214. if (preSchedulerSequence != null && preSchedulerSequence.SchedulerModule != null)
  215. {
  216. moveItem.SourceModule = preSchedulerSequence.SchedulerModule.Module;
  217. }
  218. }
  219. }
  220. }
  221. /// <summary>
  222. /// 更新未知目标模块
  223. /// </summary>
  224. private bool UpdateUnkownTargetModule(List<SchedulerSequence> schedulerSequences, MoveItem moveItem, int sequenceIndex)
  225. {
  226. SchedulerSequence currentSchedulerSequence= schedulerSequences[sequenceIndex];
  227. ModuleName moduleName = ModuleName.Unknown;
  228. if (moveItem.DestinationType == ModuleType.SRD)
  229. {
  230. SRDEntity srd1Entity = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(ModuleName.SRD1.ToString());
  231. if (srd1Entity != null&&srd1Entity.IsIdle&&srd1Entity.IsAuto&&WaferManager.Instance.CheckNoWafer(ModuleName.SRD1.ToString(),0))
  232. {
  233. moduleName = ModuleName.SRD1;
  234. }
  235. else
  236. {
  237. SRDEntity srd2Entity= Singleton<RouteManager>.Instance.GetModule<SRDEntity>(ModuleName.SRD2.ToString());
  238. if (srd2Entity != null && srd2Entity.IsIdle&&srd2Entity.IsAuto && WaferManager.Instance.CheckNoWafer(ModuleName.SRD2.ToString(), 0))
  239. {
  240. moduleName=ModuleName.SRD2;
  241. }
  242. }
  243. }
  244. else
  245. {
  246. return false;
  247. }
  248. if (moduleName == ModuleName.Unknown)
  249. {
  250. return false;
  251. }
  252. else
  253. {
  254. if(WaferManager.Instance.CheckHasWafer(moduleName,0))
  255. {
  256. return false;
  257. }
  258. IModuleEntity moduleEntity = Singleton<RouteManager>.Instance.GetModule<IModuleEntity>(moduleName.ToString());
  259. if (moduleEntity==null)
  260. {
  261. return false;
  262. }
  263. if (moduleEntity.IsBusy)
  264. {
  265. return false;
  266. }
  267. moveItem.DestinationModule = moduleName;
  268. if (sequenceIndex + 1 < schedulerSequences.Count)
  269. {
  270. SchedulerSequence sequence = schedulerSequences[sequenceIndex + 1];
  271. if (sequence.SchedulerModule == null)
  272. {
  273. sequence.SchedulerModule = SchedulerManager.Instance.GetScheduler(moduleName);
  274. sequence.ModuleName = moduleName;
  275. }
  276. }
  277. }
  278. return true;
  279. }
  280. public override void ResetTask()
  281. {
  282. base.ResetTask();
  283. RobotMoveHelper.Instance.Reset();
  284. }
  285. }
  286. }