PMProcessRoutine.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Common.Util;
  6. using Aitex.Core.RT.RecipeCenter;
  7. using Venus_RT.Devices;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using Venus_Core;
  10. namespace Venus_RT.Modules.PMs
  11. {
  12. class PMProcessRoutine : PMRoutineBase, IRoutine
  13. {
  14. private enum ProcessStep
  15. {
  16. kPreparePressure,
  17. kPrepareTemperature,
  18. kRunRecipes,
  19. kEnd,
  20. }
  21. public string CurrentRunningRecipe { get; set; }
  22. public string ProcessRecipeName { get; set; }
  23. public string ChuckRecipeName { get; set; }
  24. public string DechuckRecipeNamae { get; set; }
  25. public string CleanRecipeName { get; set; }
  26. public RecipeHead ProcessRecipeHead { get; set; }
  27. public DateTime RecipeStartTime { get; private set; }
  28. private readonly PumpDownRoutine _pumpDownRoutine;
  29. private readonly ProcessHelper _processHelper;
  30. private bool _withWafer = true;
  31. private bool _needPumpDown = false;
  32. private Recipe _currentRecipe = null;
  33. private int _currentStep = 0;
  34. private Queue<Recipe> _qeRecipes = new Queue<Recipe>();
  35. private double _tolerance;
  36. private double _OffsetTemp = 0.0f;
  37. private bool _bLoopMode = false;
  38. private int _loopStartStep = 0;
  39. private int _loopCounter = 0;
  40. private double ChillerTemp
  41. {
  42. get
  43. {
  44. if (ProcessRecipeHead != null)
  45. {
  46. if (!string.IsNullOrEmpty(ProcessRecipeHead.ChillerTemp))
  47. {
  48. double setpoint = Convert.ToDouble(ProcessRecipeHead.ChillerTemp);
  49. if (setpoint > 0 && setpoint < 600)
  50. return setpoint;
  51. }
  52. }
  53. return 0;
  54. }
  55. }
  56. private double BasePressure
  57. {
  58. get
  59. {
  60. if (ProcessRecipeHead != null)
  61. {
  62. if (!string.IsNullOrEmpty(ProcessRecipeHead.BasePressure))
  63. {
  64. double setpoint = Convert.ToDouble(ProcessRecipeHead.BasePressure);
  65. if (setpoint > 0 && setpoint < 750000)
  66. return setpoint;
  67. }
  68. }
  69. return SC.GetValue<int>($"{Module}.Pump.PumpBasePressure");
  70. }
  71. }
  72. public double EstimatedTotalLeftTime
  73. {
  74. get;
  75. private set;
  76. }
  77. public PMProcessRoutine(JetPM chamber, PumpDownRoutine pdRoutine) : base(chamber)
  78. {
  79. Name = "Process";
  80. _pumpDownRoutine = pdRoutine;
  81. _processHelper = new ProcessHelper(chamber);
  82. }
  83. private bool AssignFuns(Recipe recipe)
  84. {
  85. foreach(var step in recipe.Steps)
  86. {
  87. if (ProcessHelper.LoadStepFuns(step) == false)
  88. return false;
  89. foreach(ProcessUnitBase unit in step.LstUnit)
  90. {
  91. if (ProcessHelper.LoadMethods(unit) == false)
  92. {
  93. Stop($"Cannot find the process routine for unit:{unit.GetType()}");
  94. return false;
  95. }
  96. }
  97. }
  98. return true;
  99. }
  100. public RState Start(params object[] objs)
  101. {
  102. if (_withWafer && WaferManager.Instance.CheckNoWafer(Module.ToString(), 0))
  103. {
  104. Stop($"can not run process, no wafer at {Module}");
  105. return RState.Failed;
  106. }
  107. if (!CheckSlitDoor() || !CheckDryPump() || !CheckTurboPump())
  108. {
  109. return RState.Failed;
  110. }
  111. // Load/Validate Recipe
  112. _qeRecipes.Clear();
  113. string recipeName = (string)objs[0];
  114. string recipeContent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipeName, false);
  115. Recipe recipe = Recipe.Load(recipeContent);
  116. if(recipe == null)
  117. {
  118. Stop($"Load Recipe:{recipeName} failed");
  119. return RState.Failed;
  120. }
  121. if (AssignFuns(recipe) == false)
  122. {
  123. Stop($"Associate process alogrithm with recipe:{recipeName} failed");
  124. return RState.Failed;
  125. }
  126. switch(recipe.Header.Type)
  127. {
  128. case RecipeType.Process:
  129. if(recipe.Header.ChuckRecipe != null)
  130. {
  131. var chuckRecipe = Recipe.Load(recipe.Header.ChuckRecipe);
  132. if(chuckRecipe != null)
  133. {
  134. ChuckRecipeName = recipe.Header.ChuckRecipe;
  135. _qeRecipes.Enqueue(chuckRecipe);
  136. }
  137. }
  138. ProcessRecipeHead = recipe.Header;
  139. ProcessRecipeName = recipeName;
  140. _qeRecipes.Enqueue(recipe);
  141. if(recipe.Header.DechuckRecipe != null)
  142. {
  143. var dechuckRecipe = Recipe.Load(recipe.Header.DechuckRecipe);
  144. if(dechuckRecipe != null)
  145. {
  146. DechuckRecipeNamae = recipe.Header.DechuckRecipe;
  147. _qeRecipes.Enqueue(dechuckRecipe);
  148. }
  149. }
  150. break;
  151. case RecipeType.Chuck:
  152. ChuckRecipeName = recipeName;
  153. _qeRecipes.Enqueue(recipe);
  154. break;
  155. case RecipeType.DeChuck:
  156. DechuckRecipeNamae = recipeName;
  157. _qeRecipes.Enqueue(recipe);
  158. break;
  159. case RecipeType.Clean:
  160. CleanRecipeName = recipeName;
  161. _qeRecipes.Enqueue(recipe);
  162. break;
  163. }
  164. _bLoopMode = false;
  165. _loopStartStep = 0;
  166. _loopCounter = 0;
  167. _tolerance = SC.GetValue<double>($"System.MaxTemperatureToleranceToTarget");
  168. _OffsetTemp = SC.GetValue<double>($"{Module}.Chiller.ChillerTemperatureOffset");
  169. return Runner.Start(Module, Name);
  170. }
  171. public RState Monitor()
  172. {
  173. Runner.Run((int)ProcessStep.kPreparePressure, PreparePressure, IsPressureReady)
  174. .Run((int)ProcessStep.kPrepareTemperature, PrepareTemp, IsTempReady)
  175. .Run((int)ProcessStep.kRunRecipes, StartNewRecipe, RunRecipes)
  176. .End((int)ProcessStep.kEnd, ProcessDone, _delay_1s);
  177. return Runner.Status;
  178. }
  179. private bool PreparePressure()
  180. {
  181. if(_chamber.ChamberPressure < BasePressure)
  182. {
  183. _needPumpDown = false;
  184. return true;
  185. }
  186. _needPumpDown = true;
  187. return _pumpDownRoutine.Start(BasePressure) == RState.Running;
  188. }
  189. private bool IsPressureReady()
  190. {
  191. if (_needPumpDown == false)
  192. return true;
  193. var status = _pumpDownRoutine.Monitor();
  194. if(status == RState.End)
  195. {
  196. return true;
  197. }
  198. else if (status == RState.Failed || status == RState.Timeout)
  199. {
  200. Runner.Stop($"Pump down to {BasePressure} failed.");
  201. return true;
  202. }
  203. return false;
  204. }
  205. private bool PrepareTemp()
  206. {
  207. return SetCoolantTemp(ChillerTemp, _OffsetTemp);
  208. }
  209. private bool IsTempReady()
  210. {
  211. return CheckCoolantTemp(ChillerTemp, _tolerance);
  212. }
  213. private RState StartNewStep()
  214. {
  215. var state = _currentRecipe.Steps[_currentStep].Start();
  216. if (state != RState.Running)
  217. return state;
  218. if (_currentRecipe.Steps[_currentStep].CycleStart)
  219. {
  220. if (!_bLoopMode)
  221. {
  222. _bLoopMode = true;
  223. _loopStartStep = _currentStep;
  224. _loopCounter = _currentRecipe.Steps[_currentStep].CycleNumber;
  225. }
  226. }
  227. return RState.Running;
  228. }
  229. private bool StartNewRecipe()
  230. {
  231. if(_qeRecipes.Count > 0)
  232. {
  233. _currentStep = 0;
  234. _currentRecipe = _qeRecipes.Dequeue();
  235. CurrentRunningRecipe = _currentRecipe.Header.Name;
  236. Notify($"Recipe:{CurrentRunningRecipe} start");
  237. return StartNewStep() == RState.Running;
  238. }
  239. return false;
  240. }
  241. private bool RunRecipes()
  242. {
  243. var step = _currentRecipe.Steps[_currentStep];
  244. var result = step.Run();
  245. if(result == RState.Failed)
  246. {
  247. Runner.Stop($"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  248. return true;
  249. }
  250. else if(result == RState.End)
  251. {
  252. _currentRecipe.Steps[_currentStep].End();
  253. if(_currentRecipe.Steps[_currentStep].CycleEnd)
  254. {
  255. if(_loopCounter > 0)
  256. {
  257. _loopCounter--;
  258. _currentStep = _loopStartStep;
  259. return StartNewStep() != RState.Running;
  260. }
  261. else
  262. {
  263. _bLoopMode = false;
  264. _loopStartStep = 0;
  265. }
  266. }
  267. if (_currentStep < _currentRecipe.Steps.Count - 1)
  268. {
  269. _currentStep++;
  270. return StartNewStep() != RState.Running;
  271. }
  272. else
  273. {
  274. Notify($"Recipe:{CurrentRunningRecipe} finished");
  275. return !StartNewRecipe();
  276. }
  277. }
  278. return false;
  279. }
  280. private bool ProcessDone()
  281. {
  282. return true;
  283. }
  284. public void Abort()
  285. {
  286. CloseAllValves();
  287. }
  288. }
  289. }