WaferMappingRoutine.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using athosRT.FSM;
  7. using athosRT.tool;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Diagnostics;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace athosRT.Modules.EFEMs.Routine
  19. {
  20. public class WaferMappingRoutine : ModuleRoutineBase, FSM.IRoutine
  21. {
  22. private bool MultiWaferSize = Singleton<DeviceDefineManager>.Instance.GetValue<bool>(nameof(MultiWaferSize)).GetValueOrDefault();
  23. private SCConfigItem _scPickTimeout = (SCConfigItem)null;
  24. private int _timeout = 0;
  25. private LoadPortBaseDevice _lp;
  26. private WaferSize _waferSize;
  27. protected bool NeedSetParameter;
  28. private string _reason = string.Empty;
  29. public bool IsDeviceNull => _lp == null;
  30. public ModuleName Source { get; set; }
  31. public RobotBaseDevice robot;
  32. public WaferMappingRoutine(ModuleName Chamber) : base(Chamber)
  33. {
  34. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  35. Name = "Wafer Mapping";
  36. _scPickTimeout = SC.GetConfigItem("Robot.TimeLimitForPickWafer");
  37. }
  38. /// <summary>
  39. /// 千万注意 这里的objs 要传入LP的名字 原来获取LoadPort的
  40. /// </summary>
  41. /// <param name="objs"></param>
  42. /// <returns></returns>
  43. public RState Start(params object[] objs)
  44. {
  45. Reset();
  46. Trace.WriteLine(objs);
  47. _timeout = SC.GetValue<int>("Robot.TimeLimitForPickWafer")*1000;
  48. Name = "Wafer Mapping";
  49. Reset();
  50. NeedSetParameter = true;
  51. string str = (string)objs[0];
  52. ModuleName result;
  53. if (string.IsNullOrEmpty(str) || !Enum.TryParse<ModuleName>(str, out result))
  54. {
  55. LogObject.Info("Wafer Mapping", "Start map wafer argument is not valid");
  56. return RState.Failed;
  57. }
  58. Source = result;
  59. _lp = DEVICE.GetDevice<LoadPortBaseDevice>(Source.ToString());
  60. _waferSize = _lp.GetCurrentWaferSize();
  61. return Runner.Start(result, "Wafer Mapping");
  62. }
  63. public void Abort()
  64. {
  65. }
  66. /// <summary>
  67. /// WaferMap有两种逻辑
  68. /// 一种是LP 一种是Robot
  69. /// 两种的GetWaferMap 是对robot和LP的状态做判断 同名不同参的函数
  70. /// </summary>
  71. /// <returns></returns>
  72. public RState Monitor()
  73. {
  74. bool? nullable = Singleton<DeviceDefineManager>.Instance.GetValue<bool>("WAFSHEnable");
  75. //两种扫片方式
  76. if (nullable.GetValueOrDefault() == false & nullable.HasValue)
  77. {
  78. Runner
  79. .Wait(WaferMappingStep.CheckLoadPortReady, CheckLoadPortReady, _timeout)
  80. .Wait(WaferMappingStep.CheckRobotReady,CheckRobotReady, _timeout)
  81. .Run(WaferMappingStep.MapWafer,MapWafer, WaitRobotMotion, _timeout)
  82. .End(WaferMappingStep.GetWaferMap, GetRobotWaferMap, CheckRobotIdle, _timeout)
  83. ;
  84. }
  85. else
  86. {
  87. Runner
  88. .Wait(WaferMappingStep.CheckLoadPortReady, CheckLoadPortReady, _timeout)
  89. .End(WaferMappingStep.GetWaferMap, GetLPWaferMap, CheckLPIdle, _timeout)
  90. ;
  91. }
  92. return Runner.Status;
  93. }
  94. private bool CheckLPIdle()
  95. {
  96. if (!_lp.IsBusy)
  97. {
  98. LogObject.Info(Name, "LP 不忙");
  99. return true;
  100. }
  101. else
  102. {
  103. //LogObject.Error(Name, "LP 忙");
  104. return false;
  105. }
  106. }
  107. private bool GetLPWaferMap()
  108. {
  109. if (_lp.QueryWaferMap(out _reason))
  110. {
  111. LogObject.Info(Name, "LP GetWaferMap");
  112. return true;
  113. }
  114. else
  115. {
  116. //LogObject.Error(Name, "LP GetWaferMapping");
  117. return false;
  118. }
  119. }
  120. private bool CheckRobotIdle()
  121. {
  122. if (robot.RobotState == RobotStateEnum.Idle)
  123. {
  124. LogObject.Info(Name, "Robot Idle");
  125. return true;
  126. }
  127. else
  128. {
  129. //LogObject.Error(Name, "Robot not Idle");
  130. return false;
  131. }
  132. }
  133. private bool GetRobotWaferMap()
  134. {
  135. if (robot.QueryWaferMap(Source, out _reason))
  136. {
  137. LogObject.Info(Name, "Robot GetWaferMap");
  138. return true;
  139. }
  140. else
  141. {
  142. //LogObject.Error(Name, "Robot GetWaferMapping");
  143. return false;
  144. }
  145. }
  146. private bool WaitRobotMotion()
  147. {
  148. if (robot.IsReady())
  149. {
  150. LogObject.Info(Name, "robot WaferMap");
  151. return true;
  152. }
  153. else
  154. {
  155. //LogObject.Error(Name, "robot WaferMap");
  156. return false;
  157. }
  158. }
  159. private bool MapWafer()
  160. {
  161. if (robot.WaferMapping(Source, out _reason))
  162. {
  163. LogObject.Info(Name, "robot WaferMap");
  164. return true;
  165. }
  166. else
  167. {
  168. //LogObject.Error(Name, "robot WaferMapping");
  169. return false;
  170. }
  171. }
  172. private bool CheckRobotReady()
  173. {
  174. if (robot.RobotState == RobotStateEnum.Idle)
  175. {
  176. LogObject.Info(Name, "CheckRobotReady");
  177. return true;
  178. }
  179. else
  180. {
  181. //LogObject.Error(Name, "Check Robot Not Ready");
  182. return false;
  183. }
  184. }
  185. private bool CheckLoadPortReady()
  186. {
  187. //Trace.WriteLine($"DoorState:{_lp.DoorState}|Ready:{_lp.IsReady()}|");
  188. if (_lp.IsEnableMapWafer(out _reason))
  189. {
  190. LogObject.Info(Name, "LP ready to map wafer");
  191. return true;
  192. }
  193. else
  194. {
  195. //LogObject.Error(Name, $"LP not ready to map wafer | ....{_reason}");
  196. return false;
  197. }
  198. }
  199. private enum WaferMappingStep{
  200. CheckLoadPortReady,
  201. CheckRobotReady,
  202. MapWafer,
  203. WaitRobotMotion,
  204. GetWaferMap,
  205. WaitMapStepOver
  206. }
  207. }
  208. }