DualArmMoveManager.cs 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.Eventing.Reader;
  4. using Aitex.Core.Common;
  5. using Aitex.Core.RT.Device;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.Routine;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.Util;
  11. using Aitex.Sorter.Common;
  12. using Aitex.Sorter.RT.Module;
  13. using Aitex.Sorter.RT.SorterCommonFrame.Routines;
  14. using MECF.Framework.Common.Equipment;
  15. using MECF.Framework.Common.SubstrateTrackings;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  17. //using SorterRT.Routines;
  18. namespace Aitex.Sorter.RT.SorterCommonFrame.Modules
  19. {
  20. public class DualMoveManager : IMoveManager
  21. {
  22. public event Action<MoveErrorArgument> OnMoveError;
  23. public int TaskCount { get { return tasks.Count; } }
  24. public bool IsPaused { get { return !_pause; } }
  25. public int WaferCompleted
  26. {
  27. get
  28. {
  29. int count = tasks.Count;
  30. int completed = lastTaskCount - count;
  31. lastTaskCount = count;
  32. return completed;
  33. }
  34. }
  35. private PickRoutine pickRoutine = null;
  36. private PlaceRoutine placeRoutine = null;
  37. private AlignRoutine alignRoutine = null;
  38. private SwapRoutine swapRoutine = null;
  39. private List<MoveTask> tasks = new List<MoveTask>();
  40. private IRoutine _robotRoutine = null;
  41. private AlignRoutine _alignerRoutine = null;
  42. private MoveTask task1 = null;
  43. private MoveTask task2 = null;
  44. private MoveTask task3 = null;
  45. private bool _verifyFail = false;
  46. private int lastTaskCount = 0;
  47. private bool _pause;
  48. public DualMoveManager()
  49. {
  50. pickRoutine = new PickRoutine("System", "PickRoutine");
  51. pickRoutine.Initalize();
  52. swapRoutine = new SwapRoutine("System", "SwapRoutine");
  53. swapRoutine.Initalize();
  54. placeRoutine = new PlaceRoutine("System", "PlaceRoutine");
  55. placeRoutine.Initalize();
  56. alignRoutine = new AlignRoutine("System", "AlignRoutine");
  57. alignRoutine.Initalize();
  58. }
  59. public bool Initialize()
  60. {
  61. return true;
  62. }
  63. public bool Pause()
  64. {
  65. _pause = true;
  66. return true;
  67. }
  68. public bool Resume()
  69. {
  70. _pause = false;
  71. return true;
  72. }
  73. public bool Stop()
  74. {
  75. tasks.Clear();
  76. if (task1 != null)
  77. tasks.Add(task1);
  78. if (task2 != null)
  79. tasks.Add(task2);
  80. _pause = false;
  81. return true;
  82. }
  83. public bool Start(List<MoveTask> tasks)
  84. {
  85. _robotRoutine = null;
  86. _alignerRoutine = null;
  87. _pause = false;
  88. this.tasks = tasks;
  89. foreach (MoveTask task in tasks)
  90. {
  91. WaferManager.Instance.UpdateWaferProcessStatus(task.WaferID, ProcessStatus.Wait);
  92. task.WaferID = WaferManager.Instance.GetWaferID(task.SourceStaion, task.SourceSlot);
  93. }
  94. newTask();
  95. if (task1 == null)
  96. {
  97. return true;
  98. }
  99. _robotRoutine = null;
  100. _alignerRoutine = null;
  101. lastTaskCount = tasks.Count;
  102. return true;
  103. }
  104. private void newTask()
  105. {
  106. if (tasks.Count > 0)
  107. task1 = tasks[0];
  108. if (task1 != null)
  109. {
  110. WaferManager.Instance.UpdateWaferProcessStatus(task1.WaferID, ProcessStatus.Busy);
  111. task1.swap = IsSwap(task1);
  112. LOG.Info(string.Format(" next task1, Wafer Moved from {0}{1:D2} to {2}{3:D2}.option is {4}, swasp is {5}",
  113. task1.SourceStaion.ToString(), task1.SourceSlot, task1.DestStaion.ToString(), task1.DestSlot, task1.option, task1.swap));
  114. task2 = FindSecondTask(task1.DestStaion, task1.DestSlot, task1.option, task1.swap);
  115. if (task2 != null)
  116. {
  117. WaferManager.Instance.UpdateWaferProcessStatus(task2.WaferID, ProcessStatus.Busy);
  118. task3 = FindThirdTask(task2.DestStaion, task2.DestSlot, task2.option, task2.swap);
  119. if (task3 != null)
  120. {
  121. WaferManager.Instance.UpdateWaferProcessStatus(task3.WaferID, ProcessStatus.Busy);
  122. }
  123. }
  124. }
  125. }
  126. private bool IsSwap(MoveTask task)
  127. {
  128. if ((task.DestStaion == task.SourceStaion) && (task.DestSlot == task.SourceSlot))
  129. return false;
  130. return WaferManager.Instance.CheckHasWafer(task.DestStaion, task.DestSlot);
  131. }
  132. /// <summary>
  133. ///
  134. /// </summary>
  135. /// <param name="objs"></param>
  136. /// <returns>如果任务全部完成,或者任务失败,返回true</returns>
  137. public bool Monitor(object[] objs)
  138. {
  139. Result ret = Result.RUN;
  140. if (tasks.Count == 0 && task1 == null && task2 == null)
  141. {
  142. return true; //completed
  143. }
  144. if (ret == Result.DONE || task1 ==null)
  145. {
  146. if (_pause)
  147. {
  148. return false; //pause
  149. }
  150. }
  151. if (task1 == null)
  152. {
  153. if (!_pause)
  154. newTask();
  155. }
  156. if (_alignerRoutine != null)
  157. {
  158. ret = _alignerRoutine.Monitor();
  159. if (ret == Result.DONE)
  160. {
  161. _alignerRoutine = null;
  162. AlignCompleted();
  163. return false;
  164. }
  165. else if (ret == Result.FAIL)
  166. {
  167. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
  168. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
  169. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
  170. NotifyError("Aligner", "Aligner Error");
  171. return true; //failed
  172. }
  173. }
  174. if (_robotRoutine != null)
  175. {
  176. ret = _robotRoutine.Monitor();
  177. if (ret == Result.DONE)
  178. {
  179. _robotRoutine = null;
  180. return false;
  181. }
  182. else if (ret == Result.FAIL)
  183. {
  184. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
  185. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
  186. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
  187. NotifyError("Robot", "Robot Error");
  188. return true; //failed
  189. }
  190. }
  191. else
  192. {
  193. if (!_pause)
  194. {
  195. IRoutine rountine = NextRoutine();
  196. if (rountine != null)
  197. {
  198. rountine.Start();
  199. _robotRoutine = rountine;
  200. }
  201. }
  202. }
  203. return false;
  204. }
  205. public Result Monitor()
  206. {
  207. Result ret = Result.RUN;
  208. if (tasks.Count == 0 && task1 == null && task2 == null)
  209. {
  210. return Result.DONE; //completed
  211. }
  212. if (ret == Result.DONE || task1 ==null)
  213. {
  214. if (_pause)
  215. {
  216. return Result.RUN; //pause
  217. }
  218. }
  219. if (task1 == null)
  220. {
  221. if (!_pause)
  222. newTask();
  223. }
  224. if (_alignerRoutine != null)
  225. {
  226. ret = _alignerRoutine.Monitor();
  227. if (ret == Result.DONE)
  228. {
  229. _alignerRoutine = null;
  230. AlignCompleted();
  231. return Result.RUN;
  232. }
  233. else if (ret == Result.FAIL)
  234. {
  235. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
  236. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
  237. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
  238. NotifyError("Aligner", "Aligner Error");
  239. return Result.FAIL; //failed
  240. }
  241. if (ret == Result.VERIFYFAIL)
  242. {
  243. //_alignerRoutine = null;
  244. if (SC.ContainsItem(SorterCommon.ScPathName.Process_LMMismatchHandle))
  245. switch (SC.GetValue<int>(SorterCommon.ScPathName.Process_LMMismatchHandle))
  246. {
  247. case 2:
  248. task1.DestStaion = task1.SourceStaion;
  249. task1.DestSlot = task1.SourceSlot;
  250. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
  251. _verifyFail = true;
  252. break;
  253. case 3:
  254. ModuleName handleLp;
  255. if (SC.ContainsItem(SorterCommon.ScPathName.Process_MismatchCollectPort))
  256. {
  257. handleLp = ModuleHelper.Converter(SC.GetStringValue(SorterCommon.ScPathName.Process_MismatchCollectPort));
  258. if (!ModuleHelper.IsLoadPort(handleLp)) break;
  259. //handleLp = ModuleName.LP1;
  260. }
  261. else break;
  262. task1.DestStaion = handleLp;
  263. int startSlot = SC.ContainsItem("LoadPort." + handleLp.ToString() + "StartSlot")
  264. ? SC.GetValue<int>("LoadPort." + handleLp.ToString() + "StartSlot") : 1;
  265. if (startSlot > 25 || startSlot < 1) startSlot = 1;
  266. int endSlot = SC.ContainsItem("LoadPort." + handleLp.ToString() + "EndSlot")
  267. ? SC.GetValue<int>("LoadPort." + handleLp.ToString() + "EndSlot") : 25;
  268. if (endSlot > 25 || endSlot < 1) endSlot = 25;
  269. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
  270. _verifyFail = true;
  271. var emptySlot = DEVICE.GetDevice<LoadPort>(handleLp.ToString()).GetEmptySlot();
  272. foreach (int slot in emptySlot)
  273. {
  274. if (slot < startSlot || slot > endSlot) emptySlot.Remove(slot);
  275. }
  276. if (emptySlot.Count != 0)
  277. {
  278. if (SC.ContainsItem("Process.PlaceFromTopOnHostLPMode") && SC.GetValue<bool>("Process.PlaceFromTopOnHostLPMode"))
  279. {
  280. task1.DestSlot = emptySlot[emptySlot.Count - 1];
  281. }
  282. else
  283. {
  284. task1.DestSlot = emptySlot[0];
  285. }
  286. break;
  287. }
  288. else
  289. {
  290. Singleton<RouteManagerSorter>.Instance.PostMsg(RouteManagerSorter.MSG.PauseRecipe);
  291. EV.PostWarningLog(handleLp.ToString(), $"{handleLp} is full.");
  292. break;
  293. }
  294. default:
  295. break;
  296. }
  297. _alignerRoutine.PostAlignValue = SC.ContainsItem("Aligner." + task1.DestStaion + "PostAlignAngle") ?
  298. SC.GetValue<double>("Aligner." + task1.DestStaion + "PostAlignAngle") : 0;
  299. //AlignCompleted();
  300. return Result.RUN;
  301. }
  302. }
  303. if (_robotRoutine != null)
  304. {
  305. ret = _robotRoutine.Monitor();
  306. if (ret == Result.DONE)
  307. {
  308. _robotRoutine = null;
  309. return Result.RUN;
  310. }
  311. else if (ret == Result.FAIL)
  312. {
  313. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 0, ProcessStatus.Failed);
  314. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Robot, 1, ProcessStatus.Failed);
  315. WaferManager.Instance.UpdateWaferProcessStatus(ModuleName.Aligner, 0, ProcessStatus.Failed);
  316. NotifyError("Robot", "Robot Error");
  317. return Result.FAIL; //failed
  318. }
  319. }
  320. else
  321. {
  322. if (!_pause)
  323. {
  324. IRoutine rountine = NextRoutine();
  325. if (rountine != null)
  326. {
  327. rountine.Start();
  328. _robotRoutine = rountine;
  329. }
  330. }
  331. }
  332. return Result.RUN;
  333. }
  334. private void AlignCompleted()
  335. {
  336. if (task1 != null)
  337. {
  338. if (task1.Step == MoveStep.WaitAligner)
  339. {
  340. task1.Step = MoveStep.PickFromAligner;
  341. }
  342. }
  343. if (task2 != null)
  344. {
  345. if (task2.Step == MoveStep.WaitAligner)
  346. {
  347. task2.Step = MoveStep.PickFromAligner;
  348. }
  349. }
  350. if (task3 != null)
  351. {
  352. if (task3.Step == MoveStep.WaitAligner)
  353. {
  354. task3.Step = MoveStep.PickFromAligner;
  355. }
  356. }
  357. }
  358. private IRoutine NextRoutine()
  359. {
  360. IRoutine routine = null;
  361. if (task2 != null && task2.Step == MoveStep.Aligning)
  362. {
  363. alignRoutine.Option = task2.option;
  364. alignRoutine.Notch = task2.Notch;
  365. alignRoutine.IsVerifyAny = task2.VerifyAny;
  366. alignRoutine.IsVerifyLM1 = task2.VerifyLaserMaker;
  367. alignRoutine.StrLaserMark1 = task2.LaserMaker;
  368. alignRoutine.IsReadLM2 = task2.VerifyT7Code;
  369. alignRoutine.StrLaserMark2 = task2.T7Code;
  370. alignRoutine.PostAlignValue = SC.ContainsItem("Aligner." + task2.DestStaion.ToString() + "PostAlignAngle") ?
  371. SC.GetValue<double>("Aligner." + task2.DestStaion.ToString() + "PostAlignAngle") : 0;
  372. _alignerRoutine = alignRoutine;
  373. _alignerRoutine.Start();
  374. task2.Step = MoveStep.WaitAligner;
  375. }
  376. if (task3 != null && task3.Step == MoveStep.Aligning)
  377. {
  378. alignRoutine.Option = task3.option;
  379. alignRoutine.Notch = task3.Notch;
  380. alignRoutine.IsVerifyAny = task3.VerifyAny;
  381. alignRoutine.IsVerifyLM1 = task3.VerifyLaserMaker;
  382. alignRoutine.StrLaserMark1 = task3.LaserMaker;
  383. alignRoutine.IsReadLM2 = task3.VerifyT7Code;
  384. alignRoutine.StrLaserMark2 = task3.T7Code;
  385. alignRoutine.PostAlignValue = SC.ContainsItem("Aligner." + task3.DestStaion + "PostAlignAngle") ?
  386. SC.GetValue<double>("Aligner." + task3.DestStaion + "PostAlignAngle") : 0;
  387. _alignerRoutine = alignRoutine;
  388. _alignerRoutine.Start();
  389. task3.Step = MoveStep.WaitAligner;
  390. }
  391. //pass aligner and turnover station
  392. if (task1 != null && PassTurnOver(task1.option) && PassAligner(task1.option))
  393. {
  394. switch (task1.Step)
  395. {
  396. case MoveStep.PickFromSource:
  397. {
  398. pickRoutine.Source = task1.SourceStaion;
  399. pickRoutine.Slot = task1.SourceSlot;
  400. pickRoutine.Blade = GetEmptyHand();
  401. task1.Blade = pickRoutine.Blade;
  402. routine = pickRoutine;
  403. task1.Step = MoveStep.PlaceToAligner;
  404. break;
  405. }
  406. case MoveStep.PlaceToAligner:
  407. {
  408. placeRoutine.Station = ModuleName.Aligner;
  409. placeRoutine.Slot = 0;
  410. placeRoutine.Blade = task1.Blade;
  411. task1.Step = MoveStep.Aligning;
  412. routine = placeRoutine;
  413. break;
  414. }
  415. case MoveStep.PlaceToTurnOver:
  416. {
  417. placeRoutine.Station = ModuleName.TurnOverStation;
  418. placeRoutine.Slot = 0;
  419. placeRoutine.Blade = task1.Blade;
  420. task1.Step = MoveStep.PickFromTurnOver;
  421. routine = placeRoutine;
  422. break;
  423. }
  424. case MoveStep.Aligning:
  425. {
  426. alignRoutine.Option = task1.option;
  427. alignRoutine.Notch = task1.Notch;
  428. alignRoutine.IsVerifyAny = task1.VerifyAny;
  429. alignRoutine.IsVerifyLM1 = task1.VerifyLaserMaker;
  430. alignRoutine.StrLaserMark1 = task1.LaserMaker;
  431. alignRoutine.IsVerifyLM2 = task1.VerifyT7Code;
  432. alignRoutine.StrLaserMark1 = task1.T7Code;
  433. alignRoutine.PostAlignValue = SC.ContainsItem("Aligner." + task1.DestStaion + "PostAlignAngle") ?
  434. SC.GetValue<double>("Aligner." + task1.DestStaion + "PostAlignAngle") : 0;
  435. _alignerRoutine = alignRoutine;
  436. _alignerRoutine.Start();
  437. task1.Step = MoveStep.WaitAligner;
  438. if (task2 != null)
  439. {
  440. if (task2.Step == MoveStep.PickFromSource)
  441. {
  442. pickRoutine.Source = task2.SourceStaion;
  443. pickRoutine.Slot = task2.SourceSlot;
  444. pickRoutine.Blade = GetEmptyHand();
  445. task2.Blade = pickRoutine.Blade;
  446. routine = pickRoutine;
  447. task2.Step = MoveStep.PlaceToAligner;
  448. }
  449. }
  450. break;
  451. }
  452. case MoveStep.PickFromTurnOver:
  453. {
  454. if (task2 != null)
  455. {
  456. switch (task2.Step)
  457. {
  458. case MoveStep.PlaceToTurnOver:
  459. swapRoutine.Source = ModuleName.TurnOverStation;
  460. swapRoutine.Slot = 0;
  461. swapRoutine.PlaceBlade = task2.Blade;
  462. task1.Blade = SwapHand(swapRoutine.PlaceBlade);
  463. task1.Step = MoveStep.PlaceToDest;
  464. task2.Step = MoveStep.PickFromTurnOver;
  465. routine = swapRoutine;
  466. break;
  467. case MoveStep.PlaceToAligner:
  468. placeRoutine.Station = ModuleName.Aligner;
  469. placeRoutine.Slot = 0;
  470. placeRoutine.Blade = task2.Blade;
  471. task2.Step = MoveStep.Aligning;
  472. routine = placeRoutine;
  473. break;
  474. case MoveStep.PickFromAligner:
  475. if (task3!=null)
  476. {
  477. switch (task3.Step)
  478. {
  479. case MoveStep.PickFromSource:
  480. pickRoutine.Source = task3.SourceStaion;
  481. pickRoutine.Slot = task3.SourceSlot;
  482. pickRoutine.Blade = GetEmptyHand();
  483. task3.Blade = pickRoutine.Blade;
  484. routine = pickRoutine;
  485. task3.Step = MoveStep.PlaceToAligner;
  486. break;
  487. case MoveStep.PlaceToAligner:
  488. swapRoutine.Source = ModuleName.Aligner;
  489. swapRoutine.Slot = 0;
  490. swapRoutine.PlaceBlade = task3.Blade;
  491. task2.Blade = SwapHand(swapRoutine.PlaceBlade);
  492. task2.Step = MoveStep.PlaceToTurnOver;
  493. task3.Step = MoveStep.Aligning;
  494. routine = swapRoutine;
  495. break;
  496. }
  497. }
  498. else
  499. {
  500. pickRoutine.Source = ModuleName.Aligner;
  501. pickRoutine.Slot = 0;
  502. pickRoutine.Blade = task2.Blade;
  503. task2.Step = MoveStep.PlaceToTurnOver;
  504. routine = pickRoutine;
  505. }
  506. break;
  507. }
  508. }
  509. else
  510. {
  511. pickRoutine.Source = ModuleName.TurnOverStation;
  512. pickRoutine.Slot = 0;
  513. pickRoutine.Blade = task1.Blade;
  514. task1.Step = MoveStep.PlaceToDest;
  515. routine = pickRoutine;
  516. }
  517. break;
  518. }
  519. case MoveStep.PickFromAligner:
  520. {
  521. if (_alignerRoutine == null) //aligning completed
  522. {
  523. if (task2 != null && task3 != null && task2.Step != MoveStep.PlaceToAligner)
  524. {
  525. switch (task3.Step)
  526. {
  527. case MoveStep.PickFromSource:
  528. pickRoutine.Source = task3.SourceStaion;
  529. pickRoutine.Slot = task3.SourceSlot;
  530. pickRoutine.Blade = GetEmptyHand();
  531. task3.Blade = pickRoutine.Blade;
  532. routine = pickRoutine;
  533. task3.Step = MoveStep.PlaceToAligner;
  534. break;
  535. case MoveStep.PlaceToAligner:
  536. swapRoutine.Source = ModuleName.Aligner;
  537. swapRoutine.Slot = 0;
  538. swapRoutine.PlaceBlade = task3.Blade;
  539. task2.Blade = SwapHand(swapRoutine.PlaceBlade);
  540. task2.Step = MoveStep.PlaceToTurnOver;
  541. task3.Step = MoveStep.Aligning;
  542. routine = swapRoutine;
  543. break;
  544. }
  545. }
  546. else if (task2 != null)
  547. {
  548. switch (task2.Step)
  549. {
  550. case MoveStep.PickFromTurnOver:
  551. pickRoutine.Source = ModuleName.TurnOverStation;
  552. pickRoutine.Slot = 0;
  553. pickRoutine.Blade = task2.Blade;
  554. task2.Step = MoveStep.PlaceToAligner;
  555. routine = pickRoutine;
  556. break;
  557. case MoveStep.PlaceToTurnOver:
  558. placeRoutine.Station = ModuleName.TurnOverStation;
  559. placeRoutine.Slot = 0;
  560. placeRoutine.Blade = task2.Blade;
  561. task2.Step = MoveStep.PickFromTurnOver;
  562. routine = placeRoutine;
  563. break;
  564. case MoveStep.PlaceToAligner:
  565. swapRoutine.Source = ModuleName.Aligner;
  566. swapRoutine.Slot = 0;
  567. swapRoutine.PlaceBlade = task2.Blade;
  568. task1.Blade = SwapHand(swapRoutine.PlaceBlade);
  569. task1.Step = MoveStep.PlaceToTurnOver;
  570. task2.Step = MoveStep.Aligning;
  571. routine = swapRoutine;
  572. break;
  573. }
  574. }
  575. else
  576. {
  577. //从aligner移动至Turnover station
  578. pickRoutine.Source = ModuleName.Aligner;
  579. pickRoutine.Slot = 0;
  580. pickRoutine.Blade = task1.Blade;
  581. task1.Step = MoveStep.PlaceToTurnOver;
  582. routine = pickRoutine;
  583. }
  584. }
  585. break;
  586. }
  587. case MoveStep.PlaceToDest:
  588. {
  589. if (task2 != null)
  590. {
  591. if (WaferManager.Instance.CheckNoWafer(task1.DestStaion, task1.DestSlot))
  592. {
  593. if (task2.Step == MoveStep.PickFromSource && !task2.swap)
  594. {
  595. pickRoutine.Source = task2.SourceStaion;
  596. pickRoutine.Slot = task2.SourceSlot;
  597. pickRoutine.Blade = GetEmptyHand();
  598. task2.Blade = pickRoutine.Blade;
  599. task2.Step = MoveStep.PlaceToDest;
  600. routine = pickRoutine;
  601. }
  602. else
  603. {
  604. placeRoutine.Station = task1.DestStaion;
  605. placeRoutine.Slot = task1.DestSlot;
  606. placeRoutine.Blade = task1.Blade;
  607. task1.swap = false;
  608. task1.Step = MoveStep.Completed;
  609. routine = placeRoutine;
  610. }
  611. }
  612. else
  613. {
  614. task1.Step = MoveStep.Completed;
  615. _robotRoutine = placeRoutine;
  616. swapRoutine.Source = task1.DestStaion;
  617. swapRoutine.Slot = task1.DestSlot;
  618. swapRoutine.PlaceBlade = task1.Blade;
  619. task1.Blade = SwapHand(swapRoutine.PlaceBlade);
  620. task1.swap = true;
  621. task1.Step = MoveStep.Completed;
  622. routine = swapRoutine;
  623. }
  624. }
  625. else
  626. {
  627. if (WaferManager.Instance.CheckNoWafer(task1.DestStaion, task1.DestSlot))
  628. {
  629. placeRoutine.Station = task1.DestStaion;
  630. placeRoutine.Slot = task1.DestSlot;
  631. placeRoutine.Blade = task1.Blade;
  632. task1.swap = false;
  633. task1.Step = MoveStep.Completed;
  634. routine = placeRoutine;
  635. }
  636. else
  637. {
  638. task1.Step = MoveStep.Completed;
  639. _robotRoutine = placeRoutine;
  640. swapRoutine.Source = task1.DestStaion;
  641. swapRoutine.Slot = task1.DestSlot;
  642. swapRoutine.PlaceBlade = task1.Blade;
  643. task1.Blade = SwapHand(swapRoutine.PlaceBlade);
  644. task1.swap = true;
  645. task1.Step = MoveStep.Completed;
  646. routine = swapRoutine;
  647. }
  648. }
  649. break;
  650. }
  651. case MoveStep.Completed:
  652. {
  653. if (_verifyFail)
  654. {
  655. WaferManager.Instance.UpdateWaferProcessStatus(task1.DestStaion, task1.DestSlot, ProcessStatus.Failed);
  656. _verifyFail = false;
  657. }
  658. else
  659. WaferManager.Instance.UpdateWaferProcessStatus(task1.DestStaion, task1.DestSlot, ProcessStatus.Completed);
  660. tasks.Remove(task1);
  661. if (task3 != null && task2 != null)
  662. {
  663. if (task2.Step == MoveStep.PlaceToDest)
  664. {
  665. task1 = task2;
  666. task2 = null;
  667. }
  668. else
  669. {
  670. if (task1.swap)
  671. {
  672. MoveTask task = GetNextTask();
  673. task1 = task2;
  674. task2 = task;
  675. }
  676. else
  677. {
  678. task1 = task2;
  679. task2 = task3;
  680. task3 = FindThirdTask(task2.DestStaion, task2.DestSlot, task2.option, task2.swap);
  681. }
  682. }
  683. }
  684. else if (task2 != null)
  685. {
  686. if (task2.Step == MoveStep.PlaceToDest)
  687. {
  688. task1 = task2;
  689. task2 = null;
  690. }
  691. else
  692. {
  693. if (task1.swap)
  694. {
  695. MoveTask task = GetNextTask();
  696. task1 = task2;
  697. task2 = task;
  698. }
  699. else
  700. {
  701. task1 = task2;
  702. task2 = FindSecondTask(task1.DestStaion, task1.DestSlot, task1.option, task1.swap);
  703. }
  704. }
  705. }
  706. else
  707. {
  708. if (task1.swap)
  709. task1 = GetNextTask();
  710. else
  711. task1 = null;
  712. }
  713. break;
  714. }
  715. }
  716. if (task2 != null)
  717. {
  718. if (routine == null)
  719. {
  720. if (task2.Step == MoveStep.PickFromSource)
  721. {
  722. pickRoutine.Source = task2.SourceStaion;
  723. pickRoutine.Slot = task2.SourceSlot;
  724. pickRoutine.Blade = GetEmptyHand();
  725. task2.Blade = pickRoutine.Blade;
  726. routine = pickRoutine;
  727. task2.Step = MoveStep.PlaceToAligner;
  728. }
  729. else if (task2.Step == MoveStep.PlaceToDest)
  730. {
  731. if (WaferManager.Instance.CheckNoWafer(task2.DestStaion, task2.DestSlot))
  732. {
  733. placeRoutine.Station = task2.DestStaion;
  734. placeRoutine.Slot = task2.DestSlot;
  735. placeRoutine.Blade = task2.Blade;
  736. task2.swap = false;
  737. task2.Step = MoveStep.Completed;
  738. routine = placeRoutine;
  739. }
  740. else
  741. {
  742. task2.Step = MoveStep.Completed;
  743. _robotRoutine = placeRoutine;
  744. swapRoutine.Source = task2.DestStaion;
  745. swapRoutine.Slot = task2.DestSlot;
  746. swapRoutine.PlaceBlade = task2.Blade;
  747. task2.Blade = SwapHand(swapRoutine.PlaceBlade);
  748. task2.swap = true;
  749. task2.Step = MoveStep.Completed;
  750. routine = swapRoutine;
  751. }
  752. }
  753. else if (task2.Step == MoveStep.Completed)
  754. {
  755. WaferManager.Instance.UpdateWaferProcessStatus(task2.DestStaion, task2.DestSlot,
  756. Aitex.Core.Common.ProcessStatus.Completed);
  757. tasks.Remove(task2);
  758. return routine;
  759. }
  760. }
  761. }
  762. }
  763. else
  764. {
  765. if (task1.Step == MoveStep.PickFromSource)
  766. {
  767. if (IsDoublePick())
  768. {
  769. pickRoutine.Source = task1.SourceStaion;
  770. if (task1.SourceSlot < task2.SourceSlot)
  771. pickRoutine.Slot = task1.SourceSlot;
  772. else
  773. pickRoutine.Slot = task2.SourceSlot;
  774. pickRoutine.Blade = Hand.Both;
  775. task1.Blade = Hand.Both;
  776. routine = pickRoutine;
  777. task1.Step = MoveStep.PlaceToDest;
  778. task2.Step = MoveStep.PlaceToDest;
  779. }
  780. else
  781. {
  782. pickRoutine.Source = task1.SourceStaion;
  783. pickRoutine.Slot = task1.SourceSlot;
  784. pickRoutine.Blade = GetEmptyHand();
  785. task1.Blade = pickRoutine.Blade;
  786. routine = pickRoutine;
  787. if (PassAligner(task1.option) && PassTurnOver(task1.option))
  788. {
  789. task1.Step = MoveStep.PlaceToAligner;
  790. }
  791. else if (PassAligner(task1.option))
  792. {
  793. task1.Step = MoveStep.PlaceToAligner;
  794. }
  795. else if (PassTurnOver(task1.option))
  796. {
  797. task1.Step = MoveStep.PlaceToTurnOver;
  798. }
  799. else
  800. {
  801. task1.Step = MoveStep.PlaceToDest;
  802. }
  803. }
  804. }
  805. else if (task1.Step == MoveStep.PlaceToAligner)
  806. {
  807. placeRoutine.Station = ModuleName.Aligner;
  808. placeRoutine.Slot = 0;
  809. placeRoutine.Blade = task1.Blade;
  810. task1.Step = MoveStep.Aligning;
  811. routine = placeRoutine;
  812. }
  813. else if (task1.Step == MoveStep.PlaceToTurnOver)
  814. {
  815. placeRoutine.Station = ModuleName.TurnOverStation;
  816. placeRoutine.Slot = 0;
  817. placeRoutine.Blade = task1.Blade;
  818. task1.Step = MoveStep.Turning;
  819. routine = placeRoutine;
  820. }
  821. else if (task1.Step == MoveStep.Turning)
  822. {
  823. if (task2 != null)
  824. {
  825. if (PassTurnOver(task2.option))
  826. {
  827. if (task2.Step == MoveStep.PickFromSource)
  828. {
  829. pickRoutine.Source = task2.SourceStaion;
  830. pickRoutine.Slot = task2.SourceSlot;
  831. pickRoutine.Blade = GetEmptyHand();
  832. task2.Blade = pickRoutine.Blade;
  833. routine = pickRoutine;
  834. if(PassAligner(task2.option))
  835. task2.Step = MoveStep.PlaceToAligner;
  836. else
  837. task2.Step = MoveStep.PlaceToTurnOver;
  838. }
  839. else if (task2.Step == MoveStep.PickFromAligner)
  840. {
  841. pickRoutine.Source = ModuleName.Aligner;
  842. pickRoutine.Slot = 0;
  843. pickRoutine.Blade = GetEmptyHand();
  844. task2.Blade = pickRoutine.Blade;
  845. routine = pickRoutine;
  846. task2.Step = MoveStep.PlaceToTurnOver;
  847. }
  848. }
  849. task1.Step = MoveStep.PickFromTurnOver;
  850. }
  851. else
  852. {
  853. pickRoutine.Source = ModuleName.TurnOverStation;
  854. pickRoutine.Slot = 0;
  855. pickRoutine.Blade = task1.Blade;
  856. task1.Step = MoveStep.PickFromTurnOver;
  857. routine = pickRoutine;
  858. }
  859. }
  860. else if (task1.Step == MoveStep.Aligning)
  861. {
  862. alignRoutine.Option = task1.option;
  863. alignRoutine.Notch = task1.Notch;
  864. alignRoutine.IsVerifyAny = task1.VerifyAny;
  865. alignRoutine.IsVerifyLM1 = task1.VerifyLaserMaker;
  866. alignRoutine.StrLaserMark1 = task1.LaserMaker;
  867. alignRoutine.IsVerifyLM2 = task1.VerifyT7Code;
  868. alignRoutine.StrLaserMark2 = task1.T7Code;
  869. alignRoutine.PostAlignValue = SC.ContainsItem("Aligner." + task1.DestStaion.ToString() + "PostAlignAngle") ?
  870. SC.GetValue<double>("Aligner." + task1.DestStaion.ToString() + "PostAlignAngle") : 0;
  871. _alignerRoutine = alignRoutine;
  872. _alignerRoutine.Start();
  873. task1.Step = MoveStep.WaitAligner;
  874. if (task2 != null)
  875. {
  876. if (PassAligner(task2.option))
  877. {
  878. if (task2.Step == MoveStep.PickFromSource)
  879. {
  880. pickRoutine.Source = task2.SourceStaion;
  881. pickRoutine.Slot = task2.SourceSlot;
  882. pickRoutine.Blade = GetEmptyHand();
  883. task2.Blade = pickRoutine.Blade;
  884. routine = pickRoutine;
  885. task2.Step = MoveStep.PlaceToAligner;
  886. }
  887. }
  888. }
  889. }
  890. else if (task1.Step == MoveStep.PickFromTurnOver)
  891. {
  892. if (task2 != null)
  893. {
  894. if (task2.Step == MoveStep.PlaceToTurnOver)
  895. {
  896. swapRoutine.Source = ModuleName.TurnOverStation;
  897. swapRoutine.Slot = 0;
  898. swapRoutine.PlaceBlade = task2.Blade;
  899. task1.Blade = SwapHand(swapRoutine.PlaceBlade);
  900. task1.Step = MoveStep.PlaceToDest;
  901. task2.Step = MoveStep.PickFromTurnOver;
  902. routine = swapRoutine;
  903. }
  904. else if (task2.Step == MoveStep.PlaceToAligner)
  905. {
  906. placeRoutine.Station = ModuleName.Aligner;
  907. placeRoutine.Slot = 0;
  908. placeRoutine.Blade = task2.Blade;
  909. task2.Step = MoveStep.Aligning;
  910. routine = placeRoutine;
  911. }
  912. else if (task2.Step == MoveStep.PickFromAligner)
  913. {
  914. pickRoutine.Source = ModuleName.Aligner;
  915. pickRoutine.Slot = 0;
  916. pickRoutine.Blade = task2.Blade;
  917. task2.Step = MoveStep.PlaceToTurnOver;
  918. routine = pickRoutine;
  919. }
  920. }
  921. else
  922. {
  923. pickRoutine.Source = ModuleName.TurnOverStation;
  924. pickRoutine.Slot = 0;
  925. pickRoutine.Blade = task1.Blade;
  926. task1.Step = MoveStep.PlaceToDest;
  927. routine = pickRoutine;
  928. }
  929. }
  930. else if (task1.Step == MoveStep.PickFromAligner)
  931. {
  932. if (_alignerRoutine == null) //aligning completed
  933. {
  934. if (task2 != null)
  935. {
  936. if (task2.Step == MoveStep.PickFromTurnOver)
  937. {
  938. pickRoutine.Source = ModuleName.TurnOverStation;
  939. pickRoutine.Slot = 0;
  940. pickRoutine.Blade = task2.Blade;
  941. task2.Step = MoveStep.PlaceToAligner;
  942. routine = pickRoutine;
  943. }
  944. else if (task2.Step == MoveStep.PlaceToTurnOver)
  945. {
  946. placeRoutine.Station = ModuleName.TurnOverStation;
  947. placeRoutine.Slot = 0;
  948. placeRoutine.Blade = task2.Blade;
  949. task2.Step = MoveStep.PickFromTurnOver;
  950. routine = placeRoutine;
  951. }
  952. else if (task2.Step == MoveStep.PlaceToAligner)
  953. {
  954. if (PassTurnOver(task1.option))
  955. {
  956. swapRoutine.Source = ModuleName.Aligner;
  957. swapRoutine.Slot = 0;
  958. swapRoutine.PlaceBlade = task2.Blade;
  959. task1.Blade = SwapHand(swapRoutine.PlaceBlade);
  960. task1.Step = MoveStep.PlaceToTurnOver;
  961. task2.Step = MoveStep.Aligning;
  962. routine = swapRoutine;
  963. }
  964. else
  965. {
  966. swapRoutine.Source = ModuleName.Aligner;
  967. swapRoutine.Slot = 0;
  968. swapRoutine.PlaceBlade = task2.Blade;
  969. task1.Blade = SwapHand(swapRoutine.PlaceBlade);
  970. task1.Step = MoveStep.PlaceToDest;
  971. task2.Step = MoveStep.Aligning;
  972. routine = swapRoutine;
  973. }
  974. }
  975. }
  976. else
  977. {
  978. if (PassTurnOver(task1.option))
  979. {
  980. pickRoutine.Source = ModuleName.Aligner;
  981. pickRoutine.Slot = 0;
  982. pickRoutine.Blade = task1.Blade;
  983. task1.Step = MoveStep.PlaceToTurnOver;
  984. routine = pickRoutine;
  985. }
  986. else
  987. {
  988. pickRoutine.Source = ModuleName.Aligner;
  989. pickRoutine.Slot = 0;
  990. pickRoutine.Blade = task1.Blade;
  991. task1.Step = MoveStep.PlaceToDest;
  992. routine = pickRoutine;
  993. }
  994. }
  995. }
  996. else
  997. {
  998. //waiting
  999. }
  1000. }
  1001. else if (task1.Step == MoveStep.PlaceToDest)
  1002. {
  1003. if (task2 != null && task2.Step == MoveStep.PlaceToDest && IsDoublePlace())
  1004. {
  1005. placeRoutine.Station = task1.DestStaion;
  1006. //placeRoutine.Slot = task1.DestSlot;
  1007. if (task1.DestSlot < task2.DestSlot)
  1008. placeRoutine.Slot = task1.DestSlot;
  1009. else
  1010. placeRoutine.Slot = task2.DestSlot;
  1011. placeRoutine.Blade = Hand.Both;
  1012. task1.Step = MoveStep.Completed;
  1013. task2.Step = MoveStep.Completed;
  1014. routine = placeRoutine;
  1015. }
  1016. else
  1017. {
  1018. if (task2 != null)
  1019. {
  1020. if (WaferManager.Instance.CheckNoWafer(task1.DestStaion, task1.DestSlot))
  1021. {
  1022. if (task2.Step == MoveStep.PickFromSource && !PassAligner(task2.option) &&
  1023. !PassTurnOver(task2.option) && !task2.swap)
  1024. {
  1025. pickRoutine.Source = task2.SourceStaion;
  1026. pickRoutine.Slot = task2.SourceSlot;
  1027. pickRoutine.Blade = GetEmptyHand();
  1028. task2.Blade = pickRoutine.Blade;
  1029. task2.Step = MoveStep.PlaceToDest;
  1030. routine = pickRoutine;
  1031. }
  1032. else
  1033. {
  1034. placeRoutine.Station = task1.DestStaion;
  1035. placeRoutine.Slot = task1.DestSlot;
  1036. placeRoutine.Blade = task1.Blade;
  1037. task1.swap = false;
  1038. task1.Step = MoveStep.Completed;
  1039. routine = placeRoutine;
  1040. }
  1041. }
  1042. else
  1043. {
  1044. task1.Step = MoveStep.Completed;
  1045. _robotRoutine = placeRoutine;
  1046. swapRoutine.Source = task1.DestStaion;
  1047. swapRoutine.Slot = task1.DestSlot;
  1048. swapRoutine.PlaceBlade = task1.Blade;
  1049. task1.Blade = SwapHand(swapRoutine.PlaceBlade);
  1050. task1.swap = true;
  1051. task1.Step = MoveStep.Completed;
  1052. routine = swapRoutine;
  1053. }
  1054. }
  1055. else
  1056. {
  1057. if (WaferManager.Instance.CheckNoWafer(task1.DestStaion, task1.DestSlot))
  1058. {
  1059. placeRoutine.Station = task1.DestStaion;
  1060. placeRoutine.Slot = task1.DestSlot;
  1061. placeRoutine.Blade = task1.Blade;
  1062. task1.swap = false;
  1063. task1.Step = MoveStep.Completed;
  1064. routine = placeRoutine;
  1065. }
  1066. else
  1067. {
  1068. task1.Step = MoveStep.Completed;
  1069. _robotRoutine = placeRoutine;
  1070. swapRoutine.Source = task1.DestStaion;
  1071. swapRoutine.Slot = task1.DestSlot;
  1072. swapRoutine.PlaceBlade = task1.Blade;
  1073. task1.Blade = SwapHand(swapRoutine.PlaceBlade);
  1074. task1.swap = true;
  1075. task1.Step = MoveStep.Completed;
  1076. routine = swapRoutine;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. else if (task1.Step == MoveStep.Completed)
  1082. {
  1083. if (_verifyFail)
  1084. {
  1085. WaferManager.Instance.UpdateWaferProcessStatus(task1.DestStaion, task1.DestSlot,
  1086. Aitex.Core.Common.ProcessStatus.Failed);
  1087. _verifyFail = false;
  1088. }
  1089. else
  1090. WaferManager.Instance.UpdateWaferProcessStatus(task1.DestStaion, task1.DestSlot,
  1091. Aitex.Core.Common.ProcessStatus.Completed);
  1092. tasks.Remove(task1);
  1093. if (task2 != null && task2.Step == MoveStep.Completed)
  1094. {
  1095. WaferManager.Instance.UpdateWaferProcessStatus(task2.DestStaion, task2.DestSlot,
  1096. Aitex.Core.Common.ProcessStatus.Completed);
  1097. tasks.Remove(task2);
  1098. task2 = null;
  1099. }
  1100. if (task2 != null)
  1101. {
  1102. if (task2.Step == MoveStep.PlaceToDest)
  1103. {
  1104. task1 = task2;
  1105. task2 = null;
  1106. }
  1107. else
  1108. {
  1109. if (task1.swap)
  1110. {
  1111. MoveTask task = GetNextTask();
  1112. task1 = task2;
  1113. task2 = task;
  1114. }
  1115. else
  1116. {
  1117. task1 = task2;
  1118. task2 = FindSecondTask(task1.DestStaion, task1.DestSlot, task1.option, task1.swap);
  1119. }
  1120. }
  1121. }
  1122. else
  1123. {
  1124. if (task1.swap)
  1125. task1 = GetNextTask();
  1126. else
  1127. task1 = null;
  1128. }
  1129. }
  1130. if (task2 != null)
  1131. {
  1132. if (routine == null)
  1133. {
  1134. if (task2.Step == MoveStep.PickFromSource)
  1135. {
  1136. pickRoutine.Source = task2.SourceStaion;
  1137. pickRoutine.Slot = task2.SourceSlot;
  1138. pickRoutine.Blade = GetEmptyHand();
  1139. task2.Blade = pickRoutine.Blade;
  1140. routine = pickRoutine;
  1141. if (PassAligner(task2.option) && PassTurnOver(task2.option))
  1142. {
  1143. task2.Step = MoveStep.PlaceToAligner;
  1144. }
  1145. else if (PassTurnOver(task2.option))
  1146. {
  1147. task2.Step = MoveStep.PlaceToTurnOver;
  1148. }
  1149. else if (PassAligner(task2.option))
  1150. {
  1151. task2.Step = MoveStep.PlaceToAligner;
  1152. }
  1153. else
  1154. {
  1155. task2.Step = MoveStep.PlaceToDest;
  1156. }
  1157. }
  1158. else if (task2.Step == MoveStep.PlaceToDest)
  1159. {
  1160. if (WaferManager.Instance.CheckNoWafer(task2.DestStaion, task2.DestSlot))
  1161. {
  1162. placeRoutine.Station = task2.DestStaion;
  1163. placeRoutine.Slot = task2.DestSlot;
  1164. placeRoutine.Blade = task2.Blade;
  1165. task2.swap = false;
  1166. task2.Step = MoveStep.Completed;
  1167. routine = placeRoutine;
  1168. }
  1169. else
  1170. {
  1171. task2.Step = MoveStep.Completed;
  1172. _robotRoutine = placeRoutine;
  1173. swapRoutine.Source = task2.DestStaion;
  1174. swapRoutine.Slot = task2.DestSlot;
  1175. swapRoutine.PlaceBlade = task2.Blade;
  1176. task2.Blade = SwapHand(swapRoutine.PlaceBlade);
  1177. task2.swap = true;
  1178. task2.Step = MoveStep.Completed;
  1179. routine = swapRoutine;
  1180. }
  1181. }
  1182. else if (task2.Step == MoveStep.Completed)
  1183. {
  1184. WaferManager.Instance.UpdateWaferProcessStatus(task2.DestStaion, task2.DestSlot,
  1185. Aitex.Core.Common.ProcessStatus.Completed);
  1186. tasks.Remove(task2);
  1187. return routine;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. return routine;
  1193. }
  1194. private bool IsDoublePick()
  1195. {
  1196. if (!SC.GetValue<bool>(SorterCommon.ScPathName.Robot_DualBlade1TransferEnable))
  1197. return false;
  1198. if (task2 == null)
  1199. return false;
  1200. if (task1.option != task2.option)
  1201. return false;
  1202. if (PassAligner(task1.option))
  1203. return false;
  1204. if (PassTurnOver(task1.option))
  1205. return false;
  1206. if (task1.swap || task2.swap)
  1207. return false;
  1208. if (task1.SourceStaion != task2.SourceStaion)
  1209. return false;
  1210. if (Math.Abs(task1.DestSlot - task2.DestSlot) != 1)
  1211. return false;
  1212. if (Math.Abs(task1.SourceSlot - task2.SourceSlot) != 1)
  1213. return false;
  1214. return true;
  1215. }
  1216. private bool IsDoublePlace()
  1217. {
  1218. if(!SC.GetValue<bool>(SorterCommon.ScPathName.Robot_DualBlade1TransferEnable))
  1219. return false;
  1220. if (task2 == null)
  1221. return false;
  1222. if (task1.option != task2.option)
  1223. return false;
  1224. if (PassAligner(task1.option))
  1225. return false;
  1226. if (task1.swap || task2.swap)
  1227. return false;
  1228. if (task1.DestStaion != task2.DestStaion)
  1229. return false;
  1230. if (Math.Abs(task1.DestSlot - task2.DestSlot) != 1)
  1231. return false;
  1232. return true;
  1233. }
  1234. private bool PassAligner(MoveOption option)
  1235. {
  1236. //return false;
  1237. return (((option & MoveOption.Align) == MoveOption.Align) ||
  1238. ((option & MoveOption.ReadID) == MoveOption.ReadID) ||
  1239. ((option & MoveOption.ReadID2) == MoveOption.ReadID2)
  1240. );
  1241. }
  1242. private bool PassTurnOver(MoveOption option)
  1243. {
  1244. //return false;
  1245. return (((option & MoveOption.Turnover) == MoveOption.Turnover));
  1246. }
  1247. private Hand GetEmptyHand()
  1248. {
  1249. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, 0, WaferStatus.Normal))
  1250. {
  1251. return Hand.Blade1;
  1252. }
  1253. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, 1, WaferStatus.Normal))
  1254. {
  1255. return Hand.Blade2;
  1256. }
  1257. return Hand.Blade1;
  1258. }
  1259. private bool RobotHaveWafer()
  1260. {
  1261. if (WaferManager.Instance.CheckHasWafer(ModuleName.Robot, 0))
  1262. {
  1263. return true;
  1264. }
  1265. if (WaferManager.Instance.CheckHasWafer(ModuleName.Robot, 1))
  1266. {
  1267. return true;
  1268. }
  1269. return false;
  1270. }
  1271. private Hand SwapHand(Hand blade)
  1272. {
  1273. if (blade == Hand.Blade1)
  1274. {
  1275. return Hand.Blade2;
  1276. }
  1277. return Hand.Blade1;
  1278. }
  1279. private MoveTask GetNextTask()
  1280. {
  1281. MoveTask newTask = null;
  1282. if (task1.swap)
  1283. {
  1284. newTask = FindSwapNextTask(task1.DestStaion, task1.DestSlot);
  1285. if (newTask == null)
  1286. {
  1287. LOG.Error("有未定义目标位置的传片任务");
  1288. return newTask;
  1289. }
  1290. if (PassAligner(newTask.option))
  1291. newTask.Step = MoveStep.PlaceToAligner;
  1292. else
  1293. newTask.Step = MoveStep.PlaceToDest;
  1294. newTask.Blade = task1.Blade;
  1295. }
  1296. if (newTask != null)
  1297. {
  1298. if (!newTask.swap)
  1299. WaferManager.Instance.UpdateWaferProcessStatus(newTask.WaferID, ProcessStatus.Busy);
  1300. }
  1301. return newTask;
  1302. }
  1303. private MoveTask FindSwapNextTask(ModuleName chamber, int slot)
  1304. {
  1305. foreach (MoveTask task in tasks)
  1306. {
  1307. if (task.SourceStaion == chamber && task.SourceSlot == slot)
  1308. {
  1309. task.swap = IsSwap(task);
  1310. LOG.Info(string.Format("Get Swap next task, Wafer Moved from {0}{1:D2} to {2}{3:D2}.option is {4}, swasp is {5}",
  1311. task.SourceStaion.ToString(), task.SourceSlot, task.DestStaion.ToString(), task.DestSlot,task.option,task.swap));
  1312. return task;
  1313. }
  1314. }
  1315. return null;
  1316. }
  1317. private MoveTask FindSecondTask(ModuleName chamber, int slot, MoveOption option, bool swap)
  1318. {
  1319. bool bPassAligner = PassAligner(option);
  1320. if (!bPassAligner && swap) //task1 swap and no pass aligner, onr task excute
  1321. {
  1322. LOG.Info(string.Format("Get second task, no task"));
  1323. return null;
  1324. }
  1325. // foreach (MoveTask task in tasks)
  1326. if (tasks.Count >1)
  1327. {
  1328. MoveTask task = tasks[1];
  1329. task.swap = IsSwap(task);
  1330. if (task == task1)
  1331. {
  1332. LOG.Info(string.Format("Get second task, no task"));
  1333. return null;
  1334. }
  1335. if (task.SourceStaion == chamber && task.SourceSlot == slot) //task source is task1 target, can't run together
  1336. {
  1337. LOG.Info(string.Format("Get second task, no task"));
  1338. return null;
  1339. }
  1340. bool bTaskPassAligner = PassAligner(task.option); //path should be same
  1341. if (bTaskPassAligner != bPassAligner)
  1342. {
  1343. LOG.Info(string.Format("Get second task, no task"));
  1344. return null;
  1345. }
  1346. if (task.swap != swap)
  1347. {
  1348. LOG.Info(string.Format("Get second task, no task"));
  1349. return null;
  1350. }
  1351. if (swap)
  1352. {
  1353. if (task.DestStaion == chamber && task.DestSlot == slot)
  1354. {
  1355. LOG.Info(string.Format("Get second task, no task"));
  1356. return null; ;
  1357. }
  1358. }
  1359. LOG.Info(string.Format("Get second task, Wafer Moved from {0}{1:D2} to {2}{3:D2}.option is {4}, swap is {5}",
  1360. task.SourceStaion.ToString(), task.SourceSlot, task.DestStaion.ToString(), task.DestSlot, task.option, task.swap));
  1361. if (task != null)
  1362. {
  1363. if (!task.swap)
  1364. WaferManager.Instance.UpdateWaferProcessStatus(task.WaferID, ProcessStatus.Busy);
  1365. }
  1366. return task;
  1367. }
  1368. LOG.Info(string.Format("Get second task, no task"));
  1369. return null;
  1370. }
  1371. private MoveTask FindThirdTask(ModuleName chamber, int slot, MoveOption option, bool swap)
  1372. {
  1373. bool bPassAligner = PassAligner(option);
  1374. if (!bPassAligner && swap) //task1 swap and no pass aligner, onr task execute
  1375. {
  1376. LOG.Info("Get third task, no task");
  1377. return null;
  1378. }
  1379. if (tasks.Count >2)
  1380. {
  1381. MoveTask task = tasks[2];
  1382. task.swap = IsSwap(task);
  1383. if (task == task2)
  1384. {
  1385. LOG.Info(string.Format("Get third task, no task"));
  1386. return null;
  1387. }
  1388. if (task.SourceStaion == chamber && task.SourceSlot == slot) //task source is task1 target, can't run together
  1389. {
  1390. LOG.Info(string.Format("Get third task, no task"));
  1391. return null;
  1392. }
  1393. bool bTaskPassAligner = PassAligner(task.option); //path should be same
  1394. if (bTaskPassAligner != bPassAligner)
  1395. {
  1396. LOG.Info(string.Format("Get third task, no task"));
  1397. return null;
  1398. }
  1399. if (task.swap != swap)
  1400. {
  1401. LOG.Info(string.Format("Get third task, no task"));
  1402. return null;
  1403. }
  1404. if (swap)
  1405. {
  1406. if (task.DestStaion == chamber && task.DestSlot == slot)
  1407. {
  1408. LOG.Info(string.Format("Get third task, no task"));
  1409. return null; ;
  1410. }
  1411. }
  1412. LOG.Info(string.Format("Get third task, Wafer Moved from {0}{1:D2} to {2}{3:D2}.option is {4}, swap is {5}",
  1413. task.SourceStaion.ToString(), task.SourceSlot, task.DestStaion.ToString(), task.DestSlot, task.option, task.swap));
  1414. if (task != null)
  1415. {
  1416. if (!task.swap)
  1417. WaferManager.Instance.UpdateWaferProcessStatus(task.WaferID, ProcessStatus.Busy);
  1418. }
  1419. return task;
  1420. }
  1421. LOG.Info(string.Format("Get third task, no task"));
  1422. return null;
  1423. }
  1424. //private void PostMsg(RouteManager.MSG msg, params object[] objs)
  1425. //{
  1426. // Singleton<RouteManager>.Instance.PostMsg(msg, objs);
  1427. //}
  1428. private void NotifyError(string module, string message)
  1429. {
  1430. if (OnMoveError != null)
  1431. {
  1432. OnMoveError(new MoveErrorArgument(module, message));
  1433. }
  1434. }
  1435. }
  1436. }