SingleArmMoveManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.Common;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Routine;
  6. using EFEM.RT.Routines;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using Aitex.Sorter.RT.Module;
  11. namespace EFEM.RT.Modules
  12. {
  13. public class SingleArmMoveManager : IMoveManager
  14. {
  15. private IRoutine _alignerRoutine;
  16. private bool _pause = true;
  17. private IRoutine _robotRoutine;
  18. private readonly AlignRoutine alignRoutine;
  19. private int lastTaskCount;
  20. private readonly PickRoutine pickRoutine;
  21. private readonly PlaceRoutine placeRoutine;
  22. private MoveTask task1;
  23. private List<MoveTask> tasks = new List<MoveTask>();
  24. public SingleArmMoveManager()
  25. {
  26. pickRoutine = new PickRoutine("System", "PickWafer");
  27. pickRoutine.Initalize();
  28. placeRoutine = new PlaceRoutine("System", "PlaceWafer");
  29. placeRoutine.Initalize();
  30. alignRoutine = new AlignRoutine("System", "Alignment");
  31. alignRoutine.Initalize();
  32. }
  33. public Hand Blade { get; set; }
  34. public event Action<MoveErrorArgument> OnMoveError;
  35. public int TaskCount => tasks.Count;
  36. public bool IsPaused => !_pause;
  37. public int WaferCompleted
  38. {
  39. get
  40. {
  41. var count = tasks.Count;
  42. var completed = lastTaskCount - count;
  43. lastTaskCount = count;
  44. return completed;
  45. }
  46. }
  47. public bool Pause()
  48. {
  49. _pause = true;
  50. return true;
  51. }
  52. public bool Resume()
  53. {
  54. _pause = false;
  55. return true;
  56. }
  57. public bool Stop()
  58. {
  59. tasks.Clear();
  60. if (task1 != null)
  61. tasks.Add(task1);
  62. _pause = false;
  63. return true;
  64. }
  65. public bool Start(List<MoveTask> tasks)
  66. {
  67. _robotRoutine = null;
  68. _alignerRoutine = null;
  69. this.tasks = tasks;
  70. _pause = false;
  71. var bCheck = true;
  72. var isSameStation = false || tasks[0].SourceStaion == tasks[tasks.Count - 1].DestStaion;
  73. for (var i = 0; i < tasks.Count; i++)
  74. if (!(tasks[i].DestStaion == tasks[tasks.Count - 1].DestStaion && isSameStation))
  75. if (IsSwap(tasks[i]))
  76. {
  77. var reason = string.Format("single arm can't support swap operation. {0}:{1} ---> {2}:{3}.",
  78. tasks[i].SourceStaion.ToString(),
  79. tasks[i].SourceSlot,
  80. tasks[i].DestStaion.ToString(),
  81. tasks[i].DestSlot);
  82. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, reason);
  83. bCheck = false;
  84. }
  85. if (!bCheck)
  86. return false;
  87. foreach (var task in tasks)
  88. {
  89. WaferManager.Instance.UpdateWaferProcessStatus(task.SourceStaion, task.SourceSlot, EnumWaferProcessStatus.Wait);//(task.WaferID, ProcessStatus.Wait);
  90. task.WaferID = WaferManager.Instance.GetWaferID(task.SourceStaion, task.SourceSlot);
  91. }
  92. newTask();
  93. if (task1 == null) return true;
  94. _robotRoutine = null;
  95. _alignerRoutine = null;
  96. lastTaskCount = tasks.Count;
  97. return true;
  98. }
  99. public bool Monitor(object[] objs)
  100. {
  101. var ret = Result.RUN;
  102. if (tasks.Count == 0 && task1 == null) return true; //completed
  103. if (task1 == null)
  104. if (!_pause)
  105. newTask();
  106. if (_alignerRoutine != null)
  107. {
  108. ret = _alignerRoutine.Monitor();
  109. if (ret == Result.DONE)
  110. {
  111. _alignerRoutine = null;
  112. AlignCompleted();
  113. return false;
  114. }
  115. if (ret == Result.FAIL)
  116. {
  117. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
  118. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
  119. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
  120. NotifyError("Aligner", "Aligner Error");
  121. return true; //failed
  122. }
  123. }
  124. if (_robotRoutine != null)
  125. {
  126. ret = _robotRoutine.Monitor();
  127. if (ret == Result.DONE)
  128. {
  129. _robotRoutine = null;
  130. return false;
  131. }
  132. if (ret == Result.FAIL)
  133. {
  134. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
  135. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
  136. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
  137. NotifyError("Robot", "Robot Error");
  138. return true; //failed
  139. }
  140. }
  141. else
  142. {
  143. if (!_pause)
  144. {
  145. var rountine = NextRoutine();
  146. if (rountine != null)
  147. {
  148. ret = rountine.Start();
  149. if (ret == Result.FAIL)
  150. {
  151. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
  152. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
  153. NotifyError("Robot", "Robot Error");
  154. return true;
  155. }
  156. _robotRoutine = rountine;
  157. }
  158. }
  159. }
  160. return false;
  161. }
  162. public Result Monitor()
  163. {
  164. var ret = Result.RUN;
  165. if (tasks.Count == 0 && task1 == null) return Result.DONE; //completed
  166. if (task1 == null)
  167. if (!_pause)
  168. newTask();
  169. if (_alignerRoutine != null)
  170. {
  171. ret = _alignerRoutine.Monitor();
  172. if (ret == Result.DONE)
  173. {
  174. _alignerRoutine = null;
  175. AlignCompleted();
  176. return Result.RUN;
  177. }
  178. if (ret == Result.FAIL)
  179. {
  180. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, EnumWaferProcessStatus.Failed);
  181. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, EnumWaferProcessStatus.Failed);
  182. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, EnumWaferProcessStatus.Failed);
  183. NotifyError("Aligner", "Aligner Error");
  184. return Result.FAIL; //failed
  185. }
  186. }
  187. if (_robotRoutine != null)
  188. {
  189. ret = _robotRoutine.Monitor();
  190. if (ret == Result.DONE)
  191. {
  192. _robotRoutine = null;
  193. IRoutine rountine = NextRoutine();
  194. if (rountine != null)
  195. {
  196. if (rountine.Start() == Result.FAIL)
  197. {
  198. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, EnumWaferProcessStatus.Failed);
  199. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, EnumWaferProcessStatus.Failed);
  200. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, EnumWaferProcessStatus.Failed);
  201. NotifyError("Robot", "Robot Error");
  202. return Result.FAIL;
  203. }
  204. else
  205. {
  206. _robotRoutine = rountine;
  207. return _robotRoutine.Monitor();
  208. }
  209. }
  210. return Result.RUN;
  211. }
  212. if (ret == Result.FAIL)
  213. {
  214. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, EnumWaferProcessStatus.Failed);
  215. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, EnumWaferProcessStatus.Failed);
  216. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, EnumWaferProcessStatus.Failed);
  217. NotifyError("Robot", "Robot Error");
  218. return Result.FAIL; //failed
  219. }
  220. }
  221. else
  222. {
  223. if (!_pause)
  224. {
  225. IRoutine rountine = NextRoutine();
  226. if (rountine != null)
  227. {
  228. if (rountine.Start() == Result.FAIL)
  229. {
  230. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, EnumWaferProcessStatus.Failed);
  231. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, EnumWaferProcessStatus.Failed);
  232. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, EnumWaferProcessStatus.Failed);
  233. NotifyError("Robot", "Robot Error");
  234. return Result.FAIL;
  235. }
  236. else
  237. {
  238. _robotRoutine = rountine;
  239. return _robotRoutine.Monitor();
  240. }
  241. }
  242. return Result.RUN;
  243. }
  244. }
  245. return Result.RUN;
  246. }
  247. public bool Initialize()
  248. {
  249. return true;
  250. }
  251. private void newTask()
  252. {
  253. if (tasks.Count > 0)
  254. task1 = tasks[0];
  255. if (task1 != null) WaferManager.Instance.UpdateWaferProcessStatus(task1.SourceStaion, task1.SourceSlot, EnumWaferProcessStatus.Wait); //(task1.WaferID, ProcessStatus.Busy);
  256. }
  257. private bool IsSwap(MoveTask task)
  258. {
  259. if (task.DestStaion == task.SourceStaion && task.DestSlot == task.SourceSlot)
  260. return false;
  261. return WaferManager.Instance.CheckHasWafer(task.DestStaion, task.DestSlot);
  262. }
  263. private void AlignCompleted()
  264. {
  265. if (task1 != null)
  266. if (task1.Step == MoveStep.WaitAligner)
  267. task1.Step = MoveStep.PickFromAligner;
  268. }
  269. private IRoutine NextRoutine()
  270. {
  271. IRoutine routine = null;
  272. if (task1.Step == MoveStep.PickFromSource)
  273. {
  274. pickRoutine.Source = task1.SourceStaion;
  275. pickRoutine.Slot = task1.SourceSlot;
  276. pickRoutine.Blade = GetEmptyHand();
  277. pickRoutine.WaitForPickTime = task1.DelayTimeBeforePick;
  278. task1.Blade = pickRoutine.Blade;
  279. routine = pickRoutine;
  280. if (PassAligner(task1.option))
  281. task1.Step = MoveStep.PlaceToAligner;
  282. else
  283. task1.Step = MoveStep.PlaceToDest;
  284. }
  285. else if (task1.Step == MoveStep.PlaceToAligner)
  286. {
  287. placeRoutine.Station = ModuleName.Aligner;
  288. placeRoutine.Slot = 0;
  289. placeRoutine.Blade = task1.Blade;
  290. task1.Step = MoveStep.Aligning;
  291. routine = placeRoutine;
  292. }
  293. else if (task1.Step == MoveStep.Aligning)
  294. {
  295. alignRoutine.Option = task1.option;
  296. alignRoutine.Notch = task1.Notch;
  297. alignRoutine.VerifyAny = task1.VerifyAny;
  298. alignRoutine.VerifyLaserMaker = task1.VerifyLaserMaker;
  299. alignRoutine.LaserMaker = task1.LaserMaker;
  300. alignRoutine.VerifyT7Code = task1.VerifyT7Code;
  301. alignRoutine.T7Code = task1.T7Code;
  302. _alignerRoutine = alignRoutine;
  303. _alignerRoutine.Start();
  304. task1.Step = MoveStep.WaitAligner;
  305. }
  306. else if (task1.Step == MoveStep.PickFromAligner)
  307. {
  308. if (_alignerRoutine == null) //aligning completed
  309. {
  310. pickRoutine.Source = ModuleName.Aligner;
  311. pickRoutine.Slot = 0;
  312. pickRoutine.Blade = task1.Blade;
  313. task1.Step = MoveStep.PlaceToDest;
  314. routine = pickRoutine;
  315. }
  316. }
  317. else if (task1.Step == MoveStep.PlaceToDest)
  318. {
  319. placeRoutine.Station = task1.DestStaion;
  320. placeRoutine.Slot = task1.DestSlot;
  321. placeRoutine.Blade = task1.Blade;
  322. task1.Step = MoveStep.Completed;
  323. routine = placeRoutine;
  324. }
  325. else if (task1.Step == MoveStep.Completed)
  326. {
  327. WaferManager.Instance.UpdateWaferProcessStatus(task1.DestStaion, task1.DestSlot,
  328. ProcessStatus.Completed);
  329. tasks.Remove(task1);
  330. task1 = GetNextTask();
  331. }
  332. return routine;
  333. }
  334. private bool PassAligner(MoveOption option)
  335. {
  336. return (option & MoveOption.Align) == MoveOption.Align || (option & MoveOption.ReadID) == MoveOption.ReadID
  337. || (option & MoveOption.ReadID2) ==
  338. MoveOption.ReadID2;
  339. }
  340. private Hand GetEmptyHand()
  341. {
  342. return Blade;
  343. /*
  344. if (!WaferManager.Instance.CheckWafer(UnitName.Robot, 0, WaferStatus.Normal))
  345. {
  346. return Hand.Blade1;
  347. }
  348. if (!WaferManager.Instance.CheckWafer(UnitName.Robot, 1, WaferStatus.Normal))
  349. {
  350. return Hand.Blade2;
  351. }
  352. */
  353. //return Hand.Blade1;
  354. }
  355. private MoveTask GetNextTask()
  356. {
  357. MoveTask newTask = null;
  358. if (tasks.Count > 0)
  359. newTask = tasks[0];
  360. if (newTask != null) WaferManager.Instance.UpdateWaferProcessStatus(newTask.SourceStaion, newTask.SourceSlot, EnumWaferProcessStatus.Wait);//(newTask.WaferID, ProcessStatus.Busy);
  361. return newTask;
  362. }
  363. //private void PostMsg(RouteManager.MSG msg, params object[] objs)
  364. //{
  365. // Singleton<RouteManager>.Instance.PostMsg(msg, objs);
  366. //}
  367. private void NotifyError(string module, string message)
  368. {
  369. if (OnMoveError != null) OnMoveError(new MoveErrorArgument(module, message));
  370. }
  371. }
  372. }