AlignRoutine.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. using System;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using EFEM.RT.Modules;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. namespace EFEM.RT.Routines
  11. {
  12. internal class AlignRoutine : CommonRoutine, IRoutine
  13. {
  14. enum Align
  15. {
  16. AlignForReader,
  17. WaitAlignForReader,
  18. AlignerRelease,
  19. WaitAlignerRelease,
  20. AlignerMoveUp,
  21. WaitAlignerMoveUp,
  22. ReaderWaferID,
  23. ReaderWaferID2,
  24. Align,
  25. WaitAlign,
  26. AlignerRelease2,
  27. WaitAlignerRelease2,
  28. AlignerMoveUp2,
  29. WaitAlignerMoveUp2,
  30. }
  31. private SCConfigItem _scAlignTimeout = null;
  32. private SCConfigItem _scReaderTimeout = null;
  33. private SCConfigItem _scReadLaserNotch = null;
  34. private int _timeoutAlign = 0;
  35. private int _timeoutReadID = 0;
  36. private double _fReadLaserNotch = 0;
  37. public AlignRoutine(string module, string name)
  38. {
  39. }
  40. public bool Initalize()
  41. {
  42. _scAlignTimeout = SC.GetConfigItem(SorterCommon.ScPathName.Aligner_TimeLimitForAlignWafer);
  43. _scReaderTimeout = SC.GetConfigItem(SorterCommon.ScPathName.OcrReader_TimeLimitForWID);
  44. _scReadLaserNotch = SC.GetConfigItem(SorterCommon.ScPathName.Aligner_AlignerReadAngle);
  45. return true;
  46. }
  47. public double Notch { get; set; }
  48. public MoveOption Option { get; set; }
  49. public bool VerifyAny { get; set; }
  50. public bool VerifyLaserMaker { get; set; }
  51. public string LaserMaker { get; set; }
  52. public bool VerifyT7Code { get; set; }
  53. public string T7Code { get; set; }
  54. public Result Start(params object[] objs)
  55. {
  56. _timeoutAlign = _scAlignTimeout.IntValue;
  57. _timeoutReadID = _scReaderTimeout.IntValue;
  58. _fReadLaserNotch = _scReadLaserNotch.DoubleValue;
  59. Reset();
  60. EV.PostMessage(ModuleName.Robot.ToString(), EventEnum.AlignBegins, string.Format("{0:F2}",Notch));
  61. return Result.RUN;
  62. }
  63. public Result Monitor()
  64. {
  65. try
  66. {
  67. bool bAlignerForRead = false;
  68. if ((Option & MoveOption.ReadID) == MoveOption.ReadID || (Option & MoveOption.ReadID2) == MoveOption.ReadID2)
  69. {
  70. bAlignerForRead = true;
  71. AlignWafer((int)Align.AlignForReader, "Aligning to read wafer ID", _fReadLaserNotch, Notify, Stop);
  72. WaitAlignerMotion((int)Align.WaitAlignForReader, aligner, "Wait to finish reading wafer ID", _timeoutAlign, Notify, Stop);
  73. ReleaseAligner((int)Align.AlignerRelease, "Aligner ungrip", Notify, Stop);
  74. WaitAlignerMotion((int)Align.WaitAlignerRelease, aligner, "Wait aligner ungrip", _timeoutAlign, Notify, Stop);
  75. AlignerMoveUp((int)Align.AlignerMoveUp, "Aligner move up", Notify, Stop);
  76. WaitAlignerMotion((int)Align.WaitAlignerMoveUp, aligner, "Wait aligner moved up", _timeoutAlign, Notify, Stop);
  77. }
  78. if ((Option & MoveOption.ReadID) == MoveOption.ReadID)
  79. {
  80. ReadWaferID((int)Align.ReaderWaferID, "Read wafer ID", _timeoutReadID, true, Notify, Stop);
  81. }
  82. if ((Option & MoveOption.ReadID2) == MoveOption.ReadID2)
  83. {
  84. ReadWaferID((int)Align.ReaderWaferID2, "Read wafer ID2", _timeoutReadID, false, Notify, Stop);
  85. }
  86. if (!bAlignerForRead || (Math.Abs(Notch - _fReadLaserNotch) > 0.01))
  87. {
  88. AlignWafer((int)Align.Align, "Align wafer", Notch, Notify, Stop);
  89. WaitAlignerMotion((int)Align.WaitAlign, aligner, "Wait to finish aligning", _timeoutAlign, Notify, Stop);
  90. ReleaseAligner((int)Align.AlignerRelease2, "Aligner ungrip", Notify, Stop);
  91. WaitAlignerMotion((int)Align.WaitAlignerRelease2, aligner, "Wait aligner ungrip", _timeoutAlign, Notify, Stop);
  92. AlignerMoveUp((int)Align.AlignerMoveUp2, "Aligner move up", Notify, Stop);
  93. WaitAlignerMotion((int)Align.WaitAlignerMoveUp2, aligner, "Wait aligner moved up", _timeoutAlign, Notify, Stop);
  94. }
  95. }
  96. catch (RoutineBreakException)
  97. {
  98. return Result.RUN;
  99. }
  100. catch (RoutineFaildException)
  101. {
  102. return Result.FAIL;
  103. }
  104. WaferManager.Instance.UpdateWaferNotch(ModuleName.Aligner, 0, aligner.Notch);
  105. bool bVerifyLMOK = true;
  106. if ((Option & MoveOption.ReadID) == MoveOption.ReadID)
  107. {
  108. WaferManager.Instance.UpdateWaferLaser(ModuleName.Aligner, 0, widreader.LaserMaker);
  109. if (VerifyLaserMaker)
  110. {
  111. if(LaserMaker != widreader.LaserMaker)
  112. {
  113. bVerifyLMOK = false;
  114. string reason = string.Format("LaserMaker1 unmatch. Host:{0};Reader:{1}.", LaserMaker, widreader.LaserMaker);
  115. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, reason);
  116. }
  117. }
  118. }
  119. bool bVerifyT7OK = true;
  120. if ((Option & MoveOption.ReadID2) == MoveOption.ReadID2)
  121. {
  122. WaferManager.Instance.UpdateWaferT7Code(ModuleName.Aligner, 0, widreader.T7Code);
  123. if (VerifyT7Code)
  124. {
  125. if (T7Code != widreader.T7Code)
  126. {
  127. bVerifyT7OK = false;
  128. string reason = string.Format("LaserMaker2 unmatch. Host:{0};Reader:{1}.", T7Code, widreader.T7Code);
  129. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, reason);
  130. }
  131. }
  132. }
  133. bool bVerifyOK = bVerifyLMOK & bVerifyT7OK;
  134. if (VerifyAny)
  135. bVerifyOK = bVerifyLMOK | bVerifyT7OK;
  136. if(bVerifyOK)
  137. {
  138. if (SC.GetValue<bool>(SorterCommon.ScPathName.OcrReader_EnablePauseOnWaferIdVerifyFailed))
  139. {
  140. Singleton<RouteManager>.Instance.PostMsg(RouteManager.MSG.Pause);
  141. }
  142. }
  143. EV.PostMessage(ModuleName.Robot.ToString(), EventEnum.AlignEnds);
  144. return Result.DONE;
  145. }
  146. public new void Abort()
  147. {
  148. base.Abort();
  149. }
  150. public void AlignWafer(int id, string name, double notch,Action<string> notify, Action<string> error)
  151. {
  152. Tuple<bool, Result> ret = Execute(id, () =>
  153. {
  154. notify(String.Format(name));
  155. string reason = string.Empty;
  156. return aligner.Align(notch, out reason);
  157. });
  158. if (ret.Item1)
  159. {
  160. if (ret.Item2 == Result.FAIL)
  161. {
  162. throw (new RoutineFaildException());
  163. }
  164. }
  165. }
  166. public void AlignerMoveUp(int id, string name, Action<string> notify, Action<string> error)
  167. {
  168. Tuple<bool, Result> ret = Execute(id, () =>
  169. {
  170. notify(String.Format("{0} Lift up", aligner.Name));
  171. string reason = string.Empty;
  172. return aligner.LiftUp(out reason);
  173. });
  174. if (ret.Item1)
  175. {
  176. if (ret.Item2 == Result.FAIL)
  177. {
  178. throw (new RoutineFaildException());
  179. }
  180. }
  181. }
  182. public void ReleaseAligner(int id, string name, Action<string> notify, Action<string> error)
  183. {
  184. Tuple<bool, Result> ret = Execute(id, () =>
  185. {
  186. notify(String.Format("{0} Ungrip", aligner.Name));
  187. string reason = string.Empty;
  188. return aligner.Release(Hand.Both, out reason);
  189. });
  190. if (ret.Item1)
  191. {
  192. if (ret.Item2 == Result.FAIL)
  193. {
  194. throw (new RoutineFaildException());
  195. }
  196. }
  197. }
  198. protected void ReadWaferID(int id, string name, int time, bool bLaserMarker, Action<string> notify, Action<string> error)
  199. {
  200. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  201. {
  202. notify(name);
  203. string reason = string.Empty;
  204. if (!widreader.Read(bLaserMarker, out reason))
  205. {
  206. error(String.Format("Read Wafer ID failed,{0}", reason));
  207. }
  208. return true;
  209. }, () =>
  210. {
  211. if (!widreader.Busy)
  212. {
  213. return true;
  214. }
  215. return false;
  216. }, time * 1000);
  217. if (ret.Item1)
  218. {
  219. if (ret.Item2 == Result.FAIL)
  220. {
  221. throw (new RoutineFaildException());
  222. }
  223. else if (ret.Item2 == Result.TIMEOUT) //timeout
  224. {
  225. error(String.Format(" read WaferID timeout after {0} seconds", time));
  226. throw (new RoutineFaildException());
  227. }
  228. else
  229. throw (new RoutineBreakException());
  230. }
  231. }
  232. }
  233. }