SchedulerSETMRobot.cs 29 KB

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