SchedulerSETMRobot.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. using Aitex.Core.RT.Fsm;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using Aitex.Sorter.Common;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Schedulers;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Interop;
  15. using Venus_Core;
  16. using Venus_RT.Modules.TM.VenusEntity;
  17. using Venus_RT.Scheduler;
  18. namespace Venus_RT.Modules.Schedulers
  19. {
  20. public class SchedulerSETMRobot : SchedulerModule
  21. {
  22. class SchedulerItem
  23. {
  24. public SETMEntity.MSG MoveType { get; set; }
  25. public ModuleName target { get; set; }
  26. public Queue<MoveItem> moveList { get; set; }
  27. }
  28. public override bool IsAvailable
  29. {
  30. get { return _entity.IsIdle && (_entity.IsOnline || !Singleton<RouteManager>.Instance.IsAutoMode) && RunSchedulers(); }
  31. }
  32. public override bool IsOnline
  33. {
  34. get { return _entity.IsOnline; }
  35. }
  36. public override bool IsError
  37. {
  38. get { return _entity.IsError; }
  39. }
  40. public RState RobotStatus
  41. {
  42. get { return _entity.RobotStatus; }
  43. }
  44. private SETMEntity _entity;
  45. public int _entityTaskToken = (int)FSM_MSG.NONE;
  46. private Queue<SchedulerItem> _schedulerList = new Queue<SchedulerItem>();
  47. private SchedulerItem _currentScheduler = null;
  48. private int _singleArmOption = 0;
  49. public SchedulerSETMRobot(ModuleName module) : base(module.ToString())
  50. {
  51. _entity = Singleton<RouteManager>.Instance.seTM;
  52. _singleArmOption = SC.GetValue<int>("SETM.SingleArmOption");
  53. }
  54. public bool PostMoveItems(MoveItem[] items)
  55. {
  56. foreach (var item in items)
  57. {
  58. LOG.Write(eEvent.EV_ROUTER, ModuleName.TMRobot, $"Post Moving Item: {item.SourceModule} Slot {item.SourceSlot + 1} => {item.DestinationModule} Slot {item.DestinationSlot + 1}");
  59. }
  60. //pm swap
  61. void PackPMSwapCmds(MoveItem[] swapItems)
  62. {
  63. // must swap the item order for PM swap
  64. if (!ModuleHelper.IsTMRobot(swapItems[1].SourceModule))
  65. {
  66. SchedulerItem item = new SchedulerItem();
  67. item.MoveType = SETMEntity.MSG.Pick;
  68. item.target = swapItems[1].SourceModule;
  69. item.moveList = new Queue<MoveItem>();
  70. item.moveList.Enqueue(new MoveItem(swapItems[1].SourceModule, swapItems[1].SourceSlot, ModuleName.TMRobot, 0, (Hand)0));
  71. _schedulerList.Enqueue(item);
  72. }
  73. SchedulerItem swap = new SchedulerItem();
  74. swap.MoveType = SETMEntity.MSG.PMSwap;
  75. swap.target = swapItems[0].SourceModule;
  76. swap.moveList = new Queue<MoveItem>();
  77. swap.moveList.Enqueue(new MoveItem(swapItems[0].SourceModule, swapItems[0].SourceSlot, ModuleName.TMRobot, 1, (Hand)1));
  78. swap.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, 0, swapItems[1].DestinationModule, swapItems[1].DestinationSlot, (Hand)0));
  79. _schedulerList.Enqueue(swap);
  80. if (!ModuleHelper.IsTMRobot(swapItems[0].DestinationModule))
  81. {
  82. SchedulerItem last = new SchedulerItem();
  83. last.MoveType = SETMEntity.MSG.Place;
  84. last.target = swapItems[0].DestinationModule;
  85. last.moveList = new Queue<MoveItem>();
  86. last.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, 1, swapItems[0].DestinationModule, swapItems[0].DestinationSlot, (Hand)1));
  87. _schedulerList.Enqueue(last);
  88. }
  89. }
  90. void PackSwapCmds(MoveItem[] swapItems, SETMEntity.MSG swapType, int swapIndex)
  91. {
  92. SchedulerItem swap = new SchedulerItem();
  93. swap.MoveType = swapType;
  94. swap.target = swapItems[0].DestinationModule;
  95. swap.moveList = new Queue<MoveItem>();
  96. for (int i = 0; i < swapIndex; i++)
  97. {
  98. if (!ModuleHelper.IsTMRobot(swapItems[i].SourceModule))
  99. {
  100. SchedulerItem item = new SchedulerItem();
  101. item.MoveType = !ModuleHelper.IsPm(swapItems[i].SourceModule) ? SETMEntity.MSG.Pick : SETMEntity.MSG.PMPick;
  102. item.target = swapItems[i].SourceModule;
  103. item.moveList = new Queue<MoveItem>();
  104. item.moveList.Enqueue(new MoveItem(swapItems[i].SourceModule, swapItems[i].SourceSlot, ModuleName.TMRobot, i, (Hand)i));
  105. _schedulerList.Enqueue(item);
  106. swap.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, i, swapItems[i].DestinationModule, swapItems[i].DestinationSlot, (Hand)i));
  107. }
  108. }
  109. for (int j = swapIndex; j < swapItems.Length; j++)
  110. {
  111. swap.moveList.Enqueue(new MoveItem(swapItems[j].SourceModule, swapItems[j].SourceSlot, ModuleName.TMRobot, j - swapIndex, (Hand)(j - swapIndex)));
  112. }
  113. _schedulerList.Enqueue(swap);
  114. for (int j = swapIndex; j < swapItems.Length; j++)
  115. {
  116. if (!ModuleHelper.IsTMRobot(swapItems[j].DestinationModule))
  117. {
  118. SchedulerItem item = new SchedulerItem();
  119. item.MoveType = !ModuleHelper.IsPm(swapItems[j].DestinationModule) ? SETMEntity.MSG.Place : SETMEntity.MSG.PMPlace;
  120. item.target = swapItems[j].DestinationModule;
  121. item.moveList = new Queue<MoveItem>();
  122. item.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, j - swapIndex, swapItems[j].DestinationModule, swapItems[j].DestinationSlot, (Hand)(j - swapIndex)));
  123. _schedulerList.Enqueue(item);
  124. }
  125. }
  126. }
  127. //双臂模式 检查是否双臂有wafer
  128. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1) && _singleArmOption == 0)
  129. {
  130. //switch (items.Length)
  131. //{
  132. // //3 in && 3 out
  133. // //double pick align swap
  134. // case 6:
  135. //
  136. // break;
  137. // //2 in && 3 out
  138. // case 5:
  139. //
  140. // break;
  141. // //1 in && 3 out
  142. // //2 in && 2 out
  143. // case 4:
  144. // break;
  145. // //1 in && 2 out
  146. // case 3:
  147. // if (
  148. // ModuleHelper.IsVCE(items[0].SourceModule)&&
  149. // ModuleHelper.IsVCE(items[1].SourceModule)&&
  150. // ModuleHelper.IsVCE(items[2].SourceModule)&&
  151. // ModuleHelper.IsPm(items[0].DestinationModule) &&
  152. // ModuleHelper.IsPm(items[1].DestinationModule) &&
  153. // ModuleHelper.IsPm(items[2].DestinationModule))
  154. // {
  155. // SchedulerItem scitem = new SchedulerItem();
  156. // scitem.MoveType = SETMEntity.MSG.Swap;
  157. // scitem.target = items[0].SourceModule;
  158. // scitem.moveList = new Queue<MoveItem>();
  159. // scitem.moveList.Enqueue(new MoveItem(items[0].SourceModule, items[0].SourceSlot, ModuleName.TMRobot, 0, Hand.Blade1));
  160. // scitem.moveList.Enqueue(new MoveItem(items[1].SourceModule, items[1].SourceSlot, ModuleName.TMRobot, 1, Hand.Blade2));
  161. // _schedulerList.Enqueue(scitem);
  162. //
  163. // scitem = new SchedulerItem();
  164. // scitem.MoveType = SETMEntity.MSG.PMPlace;
  165. // scitem.target = items[0].DestinationModule;
  166. // scitem.moveList = new Queue<MoveItem>();
  167. // scitem.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, 0, items[0].DestinationModule, items[0].DestinationSlot, Hand.Blade1));
  168. // _schedulerList.Enqueue(scitem);
  169. //
  170. // scitem = new SchedulerItem();
  171. // scitem.MoveType = SETMEntity.MSG.PMPlace;
  172. // scitem.target = items[0].DestinationModule;
  173. // scitem.moveList = new Queue<MoveItem>();
  174. // scitem.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, 1, items[1].DestinationModule, items[1].DestinationSlot, Hand.Blade2));
  175. // _schedulerList.Enqueue(scitem);
  176. //
  177. // scitem = new SchedulerItem();
  178. // scitem.MoveType = SETMEntity.MSG.Pick;
  179. // scitem.target = items[2].SourceModule;
  180. // scitem.moveList = new Queue<MoveItem>();
  181. // scitem.moveList.Enqueue(new MoveItem(items[2].SourceModule, items[2].SourceSlot, ModuleName.TMRobot, 0, Hand.Blade1));
  182. // _schedulerList.Enqueue(scitem);
  183. //
  184. // scitem = new SchedulerItem();
  185. // scitem.MoveType = SETMEntity.MSG.PMPlace;
  186. // scitem.target = items[2].DestinationModule;
  187. // scitem.moveList = new Queue<MoveItem>();
  188. // scitem.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, 0, items[2].DestinationModule, items[2].DestinationSlot, Hand.Blade1));
  189. // _schedulerList.Enqueue(scitem);
  190. // }
  191. //
  192. // if (ModuleHelper.IsVCE(items[0].DestinationModule) &&
  193. // ModuleHelper.IsVCE(items[1].DestinationModule) &&
  194. // ModuleHelper.IsVCE(items[2].DestinationModule) &&
  195. // ModuleHelper.IsPm(items[0].SourceModule) &&
  196. // ModuleHelper.IsPm(items[1].SourceModule) &&
  197. // ModuleHelper.IsPm(items[2].SourceModule))
  198. // {
  199. // SchedulerItem scitem = new SchedulerItem();
  200. // scitem.MoveType = SETMEntity.MSG.PMPick;
  201. // scitem.target = items[0].SourceModule;
  202. // scitem.moveList = new Queue<MoveItem>();
  203. // scitem.moveList.Enqueue(new MoveItem(items[0].SourceModule, items[0].SourceSlot, ModuleName.TMRobot, 0, Hand.Blade1));
  204. // _schedulerList.Enqueue(scitem);
  205. //
  206. // scitem = new SchedulerItem();
  207. // scitem.MoveType = SETMEntity.MSG.PMPick;
  208. // scitem.target = items[1].SourceModule;
  209. // scitem.moveList = new Queue<MoveItem>();
  210. // scitem.moveList.Enqueue(new MoveItem(items[1].SourceModule, items[1].SourceSlot, ModuleName.TMRobot, 1, Hand.Blade2));
  211. // _schedulerList.Enqueue(scitem);
  212. //
  213. // scitem = new SchedulerItem();
  214. // scitem.MoveType = SETMEntity.MSG.Place;
  215. // scitem.target = items[0].DestinationModule;
  216. // scitem.moveList = new Queue<MoveItem>();
  217. // scitem.moveList.Enqueue(new MoveItem( ModuleName.TMRobot, 0, items[0].DestinationModule, items[0].DestinationSlot, Hand.Blade1));
  218. // _schedulerList.Enqueue(scitem);
  219. //
  220. // scitem = new SchedulerItem();
  221. // scitem.MoveType = SETMEntity.MSG.Place;
  222. // scitem.target = items[1].DestinationModule;
  223. // scitem.moveList = new Queue<MoveItem>();
  224. // scitem.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, 1, items[1].DestinationModule, items[1].DestinationSlot, Hand.Blade2));
  225. // _schedulerList.Enqueue(scitem);
  226. //
  227. // scitem = new SchedulerItem();
  228. // scitem.MoveType = SETMEntity.MSG.PMPick;
  229. // scitem.target = items[2].SourceModule;
  230. // scitem.moveList = new Queue<MoveItem>();
  231. // scitem.moveList.Enqueue(new MoveItem(items[2].SourceModule, items[2].SourceSlot, ModuleName.TMRobot, 0, Hand.Blade1));
  232. // _schedulerList.Enqueue(scitem);
  233. //
  234. // scitem = new SchedulerItem();
  235. // scitem.MoveType = SETMEntity.MSG.Place;
  236. // scitem.target = items[2].DestinationModule;
  237. // scitem.moveList = new Queue<MoveItem>();
  238. // scitem.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, 0, items[2].DestinationModule, items[2].DestinationSlot, Hand.Blade1));
  239. // _schedulerList.Enqueue(scitem);
  240. //
  241. // }
  242. // break;
  243. // //1 in && 1 out
  244. // case 2:
  245. // break;
  246. // default:
  247. // break;
  248. //}
  249. if (items.Length == 4)
  250. {
  251. //是回到vce 且下一个也是 再下两个要出来 可以做swap
  252. if (ModuleHelper.IsVCE(items[0].DestinationModule) &&
  253. items[0].DestinationModule == items[1].DestinationModule &&
  254. items[0].DestinationModule == items[2].SourceModule &&
  255. items[0].DestinationModule == items[3].SourceModule)
  256. {
  257. PackSwapCmds(items, SETMEntity.MSG.Swap, 2);
  258. }
  259. else if (items.Length == 3)
  260. {
  261. if (ModuleHelper.IsVCE(items[0].DestinationModule) &&
  262. items[0].DestinationModule == items[1].DestinationModule &&
  263. items[0].DestinationModule == items[2].SourceModule)
  264. {
  265. PackSwapCmds(items, SETMEntity.MSG.Swap, 2);
  266. }
  267. else if (ModuleHelper.IsVCE(items[0].DestinationModule) &&
  268. items[0].DestinationModule == items[1].SourceModule &&
  269. items[0].DestinationModule == items[2].SourceModule)
  270. {
  271. PackSwapCmds(items, SETMEntity.MSG.Swap, 1);
  272. }
  273. else if (ModuleHelper.IsVCE(items[0].SourceModule) &&
  274. items[0].SourceModule == items[1].SourceModule &&
  275. ModuleHelper.IsPm(items[1].DestinationModule) &&
  276. items[1].DestinationModule == items[2].SourceModule)
  277. {
  278. SchedulerItem llDoublePick = new SchedulerItem();
  279. llDoublePick.MoveType = SETMEntity.MSG.Swap;
  280. llDoublePick.target = items[0].SourceModule;
  281. llDoublePick.moveList = new Queue<MoveItem>();
  282. llDoublePick.moveList.Enqueue(new MoveItem(items[0].SourceModule, items[0].SourceSlot, ModuleName.TMRobot, 0, 0));
  283. llDoublePick.moveList.Enqueue(new MoveItem(items[1].SourceModule, items[1].SourceSlot, ModuleName.TMRobot, 1, (Hand)1));
  284. _schedulerList.Enqueue(llDoublePick);
  285. SchedulerItem pm1_place = new SchedulerItem();
  286. pm1_place.MoveType = SETMEntity.MSG.PMPlace;
  287. pm1_place.target = items[0].DestinationModule;
  288. pm1_place.moveList = new Queue<MoveItem>();
  289. pm1_place.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, 0, items[0].DestinationModule, items[0].DestinationSlot, 0));
  290. _schedulerList.Enqueue(pm1_place);
  291. SchedulerItem pm2_swap = new SchedulerItem();
  292. pm2_swap.MoveType = SETMEntity.MSG.PMSwap;
  293. pm2_swap.target = items[2].SourceModule;
  294. pm2_swap.moveList = new Queue<MoveItem>();
  295. pm2_swap.moveList.Enqueue(new MoveItem(items[2].SourceModule, items[2].SourceSlot, ModuleName.TMRobot, 0, 0));
  296. pm2_swap.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, 1, items[1].DestinationModule, items[1].DestinationSlot, (Hand)1));
  297. _schedulerList.Enqueue(pm2_swap);
  298. if (ModuleHelper.IsVCE(items[2].DestinationModule))
  299. {
  300. SchedulerItem llPlace = new SchedulerItem();
  301. llPlace.MoveType = SETMEntity.MSG.Place;
  302. llPlace.target = items[2].DestinationModule;
  303. llPlace.moveList = new Queue<MoveItem>();
  304. llPlace.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, 0, items[2].DestinationModule, items[2].DestinationSlot, 0));
  305. _schedulerList.Enqueue(llPlace);
  306. }
  307. }
  308. }
  309. }
  310. else if (items.Length == 2)
  311. {
  312. if (ModuleHelper.IsTMRobot(items[0].DestinationModule)
  313. && ModuleHelper.IsTMRobot(items[1].DestinationModule)
  314. &&ModuleHelper.IsVCE(items[0].SourceModule)
  315. &&ModuleHelper.IsVCE(items[1].SourceModule)
  316. &&WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot,0) && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  317. {
  318. SchedulerItem llDoublePick = new SchedulerItem();
  319. llDoublePick.MoveType = SETMEntity.MSG.Swap;
  320. llDoublePick.target = items[0].SourceModule;
  321. llDoublePick.moveList = new Queue<MoveItem>();
  322. llDoublePick.moveList.Enqueue(new MoveItem(items[0].SourceModule, items[0].SourceSlot, ModuleName.TMRobot, 0, 0));
  323. llDoublePick.moveList.Enqueue(new MoveItem(items[1].SourceModule, items[1].SourceSlot, ModuleName.TMRobot, 1, (Hand)1));
  324. _schedulerList.Enqueue(llDoublePick);
  325. }
  326. else if (ModuleHelper.IsVCE(items[0].DestinationModule) &&
  327. items[0].DestinationModule == items[1].DestinationModule)
  328. {
  329. PackSwapCmds(items, SETMEntity.MSG.Swap, 2);
  330. }
  331. else if (ModuleHelper.IsVCE(items[0].SourceModule) &&
  332. items[0].SourceModule == items[1].SourceModule)
  333. {
  334. PackSwapCmds(items, SETMEntity.MSG.Swap, 0);
  335. }
  336. else if (ModuleHelper.IsPm(items[0].SourceModule) &&
  337. items[0].SourceModule == items[1].DestinationModule)
  338. {
  339. PackPMSwapCmds(items);
  340. }
  341. }
  342. }
  343. Hand freeHand = SelectFreeHand();
  344. //如果没有空的手臂 直接报错
  345. if (freeHand == Hand.None && !ModuleHelper.IsTMRobot(items[0].SourceModule))
  346. {
  347. LOG.Write(eEvent.WARN_ROUTER, ModuleName.TMRobot, "No Free Arm to transfer wafer");
  348. return false;
  349. }
  350. if (_schedulerList.Count == 0)
  351. {
  352. if (items.Length >= 2 && items[0].SourceModule == items[1].DestinationModule && ModuleHelper.IsPm(items[0].SourceModule))
  353. {
  354. SchedulerItem item = new SchedulerItem();
  355. item.MoveType = SETMEntity.MSG.PMSwap;
  356. item.target = items[0].SourceModule;
  357. item.moveList = new Queue<MoveItem>();
  358. item.moveList.Enqueue(new MoveItem(items[0].SourceModule, items[0].SourceSlot, items[1].DestinationModule, items[1].DestinationSlot, (Hand)(items[1].SourceSlot == 1 ? 0 : 1)));
  359. _schedulerList.Enqueue(item);
  360. item = new SchedulerItem();
  361. item.MoveType = SETMEntity.MSG.Place;
  362. item.target = items[0].SourceModule;
  363. item.moveList = new Queue<MoveItem>();
  364. item.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, items[1].SourceSlot, items[0].DestinationModule, items[0].DestinationSlot, (Hand)(items[1].SourceSlot == 1 ? 0 : 1)));
  365. _schedulerList.Enqueue(item);
  366. items = items.Skip(2).ToArray();
  367. }
  368. if (items.Length == 3
  369. && ModuleHelper.IsTMRobot(items[1].DestinationModule)
  370. && ModuleHelper.IsTMRobot(items[2].DestinationModule)
  371. && items[1].DestinationSlot == items[2].DestinationSlot
  372. )
  373. {
  374. items[1].DestinationSlot = 0;
  375. items[2].DestinationSlot = 1;
  376. }
  377. foreach (var moveitem in items)
  378. {
  379. //如果不是从tm上来去 就要补上tmrobot中间过程
  380. if (!ModuleHelper.IsTMRobot(moveitem.SourceModule) && !ModuleHelper.IsTMRobot(moveitem.DestinationModule))
  381. {
  382. //如何取
  383. SchedulerItem item = new SchedulerItem();
  384. item.MoveType = !ModuleHelper.IsPm(moveitem.SourceModule) ? SETMEntity.MSG.Pick : SETMEntity.MSG.PMPick;
  385. item.target = moveitem.SourceModule;
  386. item.moveList = new Queue<MoveItem>();
  387. item.moveList.Enqueue(new MoveItem(moveitem.SourceModule, moveitem.SourceSlot, ModuleName.TMRobot, (int)freeHand, freeHand));
  388. _schedulerList.Enqueue(item);
  389. //如何放
  390. item = new SchedulerItem();
  391. item.MoveType = !ModuleHelper.IsPm(moveitem.DestinationModule) ? SETMEntity.MSG.Place : SETMEntity.MSG.PMPlace;
  392. item.target = moveitem.DestinationModule;
  393. item.moveList = new Queue<MoveItem>();
  394. item.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, (int)freeHand, moveitem.DestinationModule, moveitem.DestinationSlot, freeHand));
  395. _schedulerList.Enqueue(item);
  396. }
  397. //如果是place
  398. else if (ModuleHelper.IsTMRobot(moveitem.SourceModule))
  399. {
  400. SchedulerItem item = new SchedulerItem();
  401. item.MoveType = !ModuleHelper.IsPm(moveitem.DestinationModule) ? SETMEntity.MSG.Place : SETMEntity.MSG.PMPlace;
  402. item.target = moveitem.DestinationModule;
  403. item.moveList = new Queue<MoveItem>();
  404. item.moveList.Enqueue(new MoveItem(ModuleName.TMRobot, moveitem.SourceSlot, moveitem.DestinationModule, moveitem.DestinationSlot, (Hand)moveitem.SourceSlot));
  405. _schedulerList.Enqueue(item);
  406. }
  407. //如果是pick
  408. else if (ModuleHelper.IsTMRobot(moveitem.DestinationModule))
  409. {
  410. SchedulerItem item = new SchedulerItem();
  411. item.MoveType = !ModuleHelper.IsPm(moveitem.SourceModule) ? SETMEntity.MSG.Pick : SETMEntity.MSG.PMPick;
  412. item.target = moveitem.SourceModule;
  413. item.moveList = new Queue<MoveItem>();
  414. item.moveList.Enqueue(new MoveItem(moveitem.SourceModule, moveitem.SourceSlot, ModuleName.TMRobot, moveitem.DestinationSlot, (Hand)moveitem.DestinationSlot));
  415. _schedulerList.Enqueue(item);
  416. }
  417. }
  418. }
  419. RunSchedulers();
  420. return true;
  421. }
  422. bool RunSchedulers()
  423. {
  424. //非运行状态
  425. if (_entity.IsIdle && CheckTaskDone())
  426. {
  427. if (_schedulerList.Count == 0)
  428. return true;
  429. _currentScheduler = _schedulerList.Dequeue();
  430. Queue<MoveItem> moveItems = new Queue<MoveItem>();
  431. foreach (var item in _currentScheduler.moveList)
  432. {
  433. moveItems.Enqueue(item);
  434. LOG.Write(eEvent.INFO_TM, ModuleName.TMRobot, $"TM Moving Items: {item.SourceModule} Slot {item.SourceSlot + 1} => {item.DestinationModule} Slot {item.DestinationSlot + 1}");
  435. }
  436. if (_entity.CheckToPostMessage((int)_currentScheduler.MoveType, moveItems))
  437. {
  438. _entityTaskToken = (int)_currentScheduler.MoveType;
  439. }
  440. else
  441. _entityTaskToken = (int)FSM_MSG.NONE;
  442. }
  443. return false;
  444. }
  445. //获得没有wafer的手臂
  446. private Hand SelectFreeHand()
  447. {
  448. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && _singleArmOption != 2)
  449. return Hand.Blade1;
  450. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1) && _singleArmOption != 1)
  451. return Hand.Blade2;
  452. return Hand.None;
  453. }
  454. private bool CheckTaskDone()
  455. {
  456. bool ret = false;
  457. switch (_entityTaskToken)
  458. {
  459. case (int)SETMEntity.MSG.Pick:
  460. case (int)SETMEntity.MSG.PMPick:
  461. ret = WaferManager.Instance.CheckHasWafer(_currentScheduler.moveList.Peek().DestinationModule, _currentScheduler.moveList.Peek().DestinationSlot) &&
  462. WaferManager.Instance.CheckNoWafer(_currentScheduler.moveList.Peek().SourceModule, _currentScheduler.moveList.Peek().SourceSlot);
  463. break;
  464. case (int)SETMEntity.MSG.Place:
  465. case (int)SETMEntity.MSG.PMPlace:
  466. ret = WaferManager.Instance.CheckHasWafer(_currentScheduler.moveList.Peek().DestinationModule, _currentScheduler.moveList.Peek().DestinationSlot) &&
  467. WaferManager.Instance.CheckNoWafer(_currentScheduler.moveList.Peek().SourceModule, _currentScheduler.moveList.Peek().SourceSlot);
  468. break;
  469. case (int)SETMEntity.MSG.Swap:
  470. ret = WaferManager.Instance.CheckHasWafer(_currentScheduler.moveList.Peek().DestinationModule, _currentScheduler.moveList.Peek().DestinationSlot) &&
  471. WaferManager.Instance.CheckHasWafer(_currentScheduler.moveList.Last().DestinationModule, _currentScheduler.moveList.Last().DestinationSlot);
  472. break;
  473. case (int)SETMEntity.MSG.PMSwap:
  474. ret = WaferManager.Instance.CheckHasWafer(_currentScheduler.moveList.Peek().DestinationModule, _currentScheduler.moveList.Peek().DestinationSlot) &&
  475. WaferManager.Instance.CheckHasWafer(_currentScheduler.moveList.Peek().SourceModule, _currentScheduler.moveList.Peek().SourceSlot);
  476. break;
  477. case (int)SETMEntity.MSG.Align:
  478. ret = _entity.CheckAcked(_entityTaskToken) && _entity.IsIdle ;
  479. break;
  480. case (int)FSM_MSG.NONE:
  481. ret = true;
  482. break;
  483. }
  484. if (ret && _entityTaskToken != (int)FSM_MSG.NONE)
  485. {
  486. _entityTaskToken = (int)FSM_MSG.NONE;
  487. LOG.Write(eEvent.EV_ROUTER, Module, $"Scheduler, {_currentScheduler.target} Task done: {_currentScheduler.MoveType}");
  488. }
  489. return ret;
  490. }
  491. public override bool Align(float angle)
  492. {
  493. _task = TaskType.Align;
  494. if (_entity.CheckToPostMessage((int)SETMEntity.MSG.Align, angle))
  495. {
  496. _entityTaskToken = (int)SETMEntity.MSG.Align;
  497. return true;
  498. }
  499. else
  500. {
  501. _entityTaskToken = (int)FSM_MSG.NONE;
  502. return false;
  503. }
  504. }
  505. }
  506. }