SRDProcessRecipeRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.Routine;
  3. using MECF.Framework.Common.RecipeCenter;
  4. using MECF.Framework.Common.Routine;
  5. using CyberX8_Core;
  6. using CyberX8_RT.Devices.AXIS;
  7. using CyberX8_RT.Devices.SRD;
  8. using System;
  9. using System.Collections.Generic;
  10. using MECF.Framework.Common.Utilities;
  11. using MECF.Framework.Common.CommonData;
  12. using MECF.Framework.Common.CommonData.SRD;
  13. using Aitex.Core.RT.SCCore;
  14. using Aitex.Core.RT.Device;
  15. using CyberX8_RT.Devices.Facilities;
  16. using Aitex.Core.Util;
  17. using CyberX8_RT.Modules.Transporter;
  18. using MECF.Framework.Common.WaferHolder;
  19. using MECF.Framework.Common.Persistent.SRD;
  20. namespace CyberX8_RT.Modules.SRD
  21. {
  22. public class SRDProcessRecipeRoutine : RoutineBase, IRoutine
  23. {
  24. #region 常量
  25. private const int LOTTRACK_TIME = 1000;
  26. #endregion
  27. private enum SRDProcessState
  28. {
  29. Ready,
  30. StartLoader,
  31. Loading,
  32. StartRunRecipe,
  33. RunReciping,
  34. StartUnloader,
  35. Unloading,
  36. CycleEnd,
  37. End
  38. }
  39. #region 内部变量
  40. /// <summary>
  41. /// 次数
  42. /// </summary>
  43. private int _cycleCount = 0;
  44. /// <summary>
  45. /// Rotation Axis
  46. /// </summary>
  47. private JetAxisBase _rotationAxis;
  48. /// <summary>
  49. /// Arm Axis
  50. /// </summary>
  51. private JetAxisBase _armAxis;
  52. /// <summary>
  53. /// SRD Recipe
  54. /// </summary>
  55. private SrdRecipe _srdRecipe;
  56. /// <summary>
  57. /// 设备对象
  58. /// </summary>
  59. private SrdCommonDevice _srdCommonDevice;
  60. /// <summary>
  61. /// Run Recipe Routine
  62. /// </summary>
  63. private SRDRunRecipeRoutine _runRecipeRoutine;
  64. /// <summary>
  65. /// Unloader Routine
  66. /// </summary>
  67. private SRDUnloaderRoutine _unloaderRoutine;
  68. /// <summary>
  69. /// Loader Routine
  70. /// </summary>
  71. private SRDLoaderRoutine _loaderRoutine;
  72. /// <summary>
  73. /// lock track time
  74. /// </summary>
  75. private DateTime _lotTackTime = DateTime.Now;
  76. /// <summary>
  77. /// LotTrack数据
  78. /// </summary>
  79. private List<SRDLotTrackData> _datas = new List<SRDLotTrackData>();
  80. /// <summary>
  81. /// LotTrack文件头数据
  82. /// </summary>
  83. private LotTrackFileHeaderCommonData _header = new LotTrackFileHeaderCommonData();
  84. /// <summary>
  85. /// Facilities
  86. /// </summary>
  87. private SystemFacilities _facilities;
  88. /// <summary>
  89. /// Manual模式
  90. /// </summary>
  91. private bool _isManual = false;
  92. #endregion
  93. #region 属性
  94. /// <summary>
  95. /// 当前子状态机
  96. /// </summary>
  97. public string CurrentStateMachine
  98. {
  99. get { return GetCurrentStateMachine(); }
  100. }
  101. /// <summary>
  102. /// 当前cycle次数
  103. /// </summary>
  104. public int AchievedCycle { get { return Runner.LoopCounter; } }
  105. /// <summary>
  106. /// 是否正在用水
  107. /// </summary>
  108. public bool IsUsingWater { get { return _runRecipeRoutine.IsUsingWater; } }
  109. /// <summary>
  110. /// LotTrack数据
  111. /// </summary>
  112. public List<SRDLotTrackData> SRDLotTrackDatas { get { return _datas; } }
  113. /// <summary>
  114. /// LotTrack文件头数据
  115. /// </summary>
  116. public LotTrackFileHeaderCommonData SRDLotTrackHeaderDatas { get { return _header; } }
  117. #endregion
  118. /// <summary>
  119. /// 构造函数
  120. /// </summary>
  121. /// <param name="module"></param>
  122. public SRDProcessRecipeRoutine(string module, JetAxisBase rotationAxis, JetAxisBase armAxis, SrdCommonDevice srdCommon) : base(module)
  123. {
  124. _rotationAxis = rotationAxis;
  125. _armAxis = armAxis;
  126. _srdCommonDevice = srdCommon;
  127. _runRecipeRoutine = new SRDRunRecipeRoutine(module);
  128. _unloaderRoutine= new SRDUnloaderRoutine(module);
  129. _loaderRoutine = new SRDLoaderRoutine(module);
  130. }
  131. /// <summary>
  132. /// 取消
  133. /// </summary>
  134. public void Abort()
  135. {
  136. if(_unloaderRoutine.Monitor() == RState.Running)
  137. {
  138. _unloaderRoutine.Abort();
  139. }
  140. if (_runRecipeRoutine.Monitor() == RState.Running)
  141. {
  142. _runRecipeRoutine.Abort();
  143. }
  144. if (_loaderRoutine.Monitor() == RState.Running)
  145. {
  146. _loaderRoutine.Abort();
  147. }
  148. Runner.Stop("Manual Abort");
  149. if (_srdCommonDevice != null)
  150. {
  151. _srdCommonDevice.EnterErrorOperation();
  152. }
  153. }
  154. /// <summary>
  155. /// 监控
  156. /// </summary>
  157. /// <returns></returns>
  158. /// <exception cref="NotImplementedException"></exception>
  159. public RState Monitor()
  160. {
  161. LottrackRecord();
  162. Runner.LoopStart(SRDProcessState.Ready, "Process Recipe Start", _cycleCount, NullFun, _delay_1ms)
  163. .LoopRunIf(SRDProcessState.StartLoader, !_isManual,() => { return StartLoader(); }, _delay_1ms)
  164. .LoopRunIfWithStopStatus(SRDProcessState.Loading, !_isManual, CheckLoaderEndStatus, CheckLoaderErrorStatus)
  165. .LoopRun(SRDProcessState.StartRunRecipe, () => { return StartRunRecipe(); }, _delay_1ms)
  166. .LoopRunWithStopStatus(SRDProcessState.RunReciping, CheckRunRecipeEndStatus, CheckRunRecipeErrorStatus)
  167. .LoopRunIf(SRDProcessState.StartUnloader, !_isManual, () => { return StartUnloader(); }, _delay_1ms)
  168. .LoopRunIfWithStopStatus(SRDProcessState.Unloading, !_isManual, CheckUnloaderEndStatus, CheckUnloaderErrorStatus)
  169. .LoopEnd(SRDProcessState.CycleEnd, NullFun, _delay_1ms)
  170. .End(SRDProcessState.End, NullFun, _delay_1ms);
  171. return Runner.Status;
  172. }
  173. /// <summary>
  174. /// 启动
  175. /// </summary>
  176. /// <param name="objects"></param>
  177. /// <returns></returns>
  178. /// <exception cref="NotImplementedException"></exception>
  179. public RState Start(params object[] objects)
  180. {
  181. _srdRecipe = objects[0] as SrdRecipe;
  182. if (_srdRecipe == null)
  183. {
  184. LOG.WriteLog(eEvent.ERR_SRD, Module.ToString(), " recipe is null");
  185. return RState.Failed;
  186. }
  187. _cycleCount = (int)objects[1];
  188. if (_cycleCount == 0)
  189. {
  190. return RState.End;
  191. }
  192. _isManual = false;
  193. SRDPersistentValue srdPersistentValue = SRDPersistentManager.Instance.GetModulePersistentValue(Module);
  194. if(srdPersistentValue.OperatingMode.Equals("Manual")) _isManual = true;
  195. _header.SoftWareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  196. _header.Recipe = $"{_srdRecipe.Ppid}.srd.rcp";
  197. if (SC.ContainsItem("System.ToolID")) _header.ToolID = SC.GetStringValue("System.ToolID");
  198. _facilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  199. if (_facilities == null)
  200. {
  201. LOG.WriteLog(eEvent.ERR_SRD, Module, "Facility is null");
  202. return RState.Failed;
  203. }
  204. _datas.Clear();
  205. _lotTackTime = DateTime.Now;
  206. SRDEntity srdEntity = Singleton<RouteManager>.Instance.GetModule<SRDEntity>(Module);
  207. if (srdEntity.IsManual && !srdEntity.IsLoaded)
  208. {
  209. NotifyError(eEvent.ERR_SRD, $"{Module} is not Loaded, can't run recipe", 0);
  210. return RState.Failed;
  211. }
  212. return Runner.Start(Module, "Process Recipe");
  213. }
  214. #region Loader
  215. /// <summary>
  216. /// 启动LoaderRoutine
  217. /// </summary>
  218. /// <param name="recipe"></param>
  219. /// <returns></returns>
  220. private bool StartLoader()
  221. {
  222. bool result = _loaderRoutine.Start() == RState.Running;
  223. if (!result)
  224. {
  225. NotifyError(eEvent.ERR_SRD, _loaderRoutine.ErrorMsg, 0);
  226. }
  227. return result;
  228. }
  229. /// <summary>
  230. /// 检验LoaderRoutine完成情况
  231. /// </summary>
  232. /// <returns></returns>
  233. private bool CheckLoaderEndStatus()
  234. {
  235. return CommonFunction.CheckRoutineEndState(_loaderRoutine);
  236. }
  237. /// <summary>
  238. /// 检验LoaderRoutine错误情况
  239. /// </summary>
  240. /// <returns></returns>
  241. private bool CheckLoaderErrorStatus()
  242. {
  243. bool result = CommonFunction.CheckRoutineStopState(_loaderRoutine);
  244. if (result)
  245. {
  246. AddLotTrackData();
  247. if (_srdCommonDevice != null)
  248. {
  249. _srdCommonDevice.EnterErrorOperation();
  250. }
  251. NotifyError(eEvent.ERR_SRD, _loaderRoutine.ErrorMsg, 0);
  252. }
  253. return result;
  254. }
  255. #endregion
  256. #region RunRecipe
  257. /// <summary>
  258. /// 启动状态机
  259. /// </summary>
  260. /// <param name="recipe"></param>
  261. /// <returns></returns>
  262. private bool StartRunRecipe()
  263. {
  264. bool result = _runRecipeRoutine.Start(_srdRecipe)==RState.Running;
  265. if (result)
  266. {
  267. LOG.WriteLog(eEvent.INFO_SRD, Module.ToString(), $"Start Run Recipe, recipe[{_srdRecipe.Ppid}] times[{_cycleCount + 1}]");
  268. }
  269. else
  270. {
  271. NotifyError(eEvent.ERR_SRD, _runRecipeRoutine.ErrorMsg, 0);
  272. }
  273. return result;
  274. }
  275. /// <summary>
  276. /// 检验RunRecipeRoutine完成情况
  277. /// </summary>
  278. /// <returns></returns>
  279. private bool CheckRunRecipeEndStatus()
  280. {
  281. return CommonFunction.CheckRoutineEndState(_runRecipeRoutine);
  282. }
  283. /// <summary>
  284. /// 检验RunRecipeRoutine错误情况
  285. /// </summary>
  286. /// <returns></returns>
  287. private bool CheckRunRecipeErrorStatus()
  288. {
  289. bool result = CommonFunction.CheckRoutineStopState(_runRecipeRoutine);
  290. if (result)
  291. {
  292. AddLotTrackData();
  293. if (_srdCommonDevice != null)
  294. {
  295. _srdCommonDevice.EnterErrorOperation();
  296. }
  297. NotifyError(eEvent.ERR_SRD, _runRecipeRoutine.ErrorMsg, 0);
  298. }
  299. return result;
  300. }
  301. #endregion
  302. #region Unloader
  303. /// <summary>
  304. /// 启动UnloaderRoutine
  305. /// </summary>
  306. /// <param name="recipe"></param>
  307. /// <returns></returns>
  308. private bool StartUnloader()
  309. {
  310. bool result= _unloaderRoutine.Start(false) == RState.Running;
  311. if (!result)
  312. {
  313. NotifyError(eEvent.ERR_SRD,_unloaderRoutine.ErrorMsg, 0);
  314. }
  315. return result;
  316. }
  317. /// <summary>
  318. /// 检验UnloaderRoutine完成情况
  319. /// </summary>
  320. /// <returns></returns>
  321. private bool CheckUnloaderEndStatus()
  322. {
  323. return CommonFunction.CheckRoutineEndState(_unloaderRoutine);
  324. }
  325. /// <summary>
  326. /// 检验UnloaderRoutine错误情况
  327. /// </summary>
  328. /// <returns></returns>
  329. private bool CheckUnloaderErrorStatus()
  330. {
  331. bool result= CommonFunction.CheckRoutineStopState(_unloaderRoutine);
  332. if (result)
  333. {
  334. AddLotTrackData();
  335. NotifyError(eEvent.ERR_SRD, _unloaderRoutine.ErrorMsg, 0);
  336. }
  337. return result;
  338. }
  339. #endregion
  340. /// <summary>
  341. /// 获取当前子状态机
  342. /// </summary>
  343. private string GetCurrentStateMachine()
  344. {
  345. string result;
  346. if(Runner.CurrentStep.ToString() == "Ready")
  347. {
  348. result = "Ready";
  349. }
  350. else if(Runner.CurrentStep.ToString().Contains("RunReciping"))
  351. {
  352. result = _runRecipeRoutine.CurrentStep;
  353. }
  354. else if(Runner.CurrentStep.ToString().Contains("Unloading"))
  355. {
  356. result = _unloaderRoutine.CurrentStep;
  357. }
  358. else
  359. {
  360. result = "End";
  361. }
  362. return result;
  363. }
  364. /// <summary>
  365. /// 记录Lottrack
  366. /// </summary>
  367. private void LottrackRecord()
  368. {
  369. //记录Lottrack
  370. if (DateTime.Now.Subtract(_lotTackTime).TotalMilliseconds >= LOTTRACK_TIME)
  371. {
  372. AddLotTrackData();
  373. _lotTackTime = DateTime.Now;
  374. }
  375. }
  376. /// <summary>
  377. /// 获取Lot Track数据
  378. /// </summary>
  379. /// <returns></returns>
  380. private void AddLotTrackData()
  381. {
  382. SRDLotTrackData data = new SRDLotTrackData();
  383. data.TimeStamp = DateTime.Now;
  384. data.StateMachine = GetCurrentStateMachine();
  385. data.WaterPressure = _srdCommonDevice.CommonData.WaterPressure;
  386. data.ChuckVacuumOn = _srdCommonDevice.CommonData.ChuckVacuum;
  387. data.ChuckVacuumPressure = _srdCommonDevice.CommonData.VacuumValue;
  388. //data.SpinTorque = _rotationAxis.MotionData.ActualTorque;
  389. data.RotationSpeed = _rotationAxis.MotionData.ActualVelocity;
  390. data.WaterOn = _srdCommonDevice.CommonData.WaterOn;
  391. data.WaterFlow = _srdCommonDevice.CommonData.WaterFlow;
  392. data.LoaderDIEnable = _facilities.LoaderDiEnable;
  393. _datas.Add(data);
  394. }
  395. /// <summary>
  396. /// 重试
  397. /// </summary>
  398. /// <param name="step"></param>
  399. public RState Retry(int step)
  400. {
  401. List<Enum> preStepIds = new List<Enum>();
  402. return Runner.Retry(SRDProcessState.Ready, preStepIds, Module, "RunRecipe Retry");
  403. }
  404. /// <summary>
  405. /// 检验前面完成状态
  406. /// </summary>
  407. /// <returns></returns>
  408. public bool CheckCompleteCondition(int index)
  409. {
  410. if (_armAxis.IsRun)
  411. {
  412. NotifyError(eEvent.ERR_SRD, "Arm axis is run", 0);
  413. return false;
  414. }
  415. if (!_armAxis.IsHomed)
  416. {
  417. NotifyError(eEvent.ERR_SRD, "Arm axis is not homed", 0);
  418. return false;
  419. }
  420. if (_rotationAxis.IsRun)
  421. {
  422. NotifyError(eEvent.ERR_SRD, "Rotation axis is run", 0);
  423. return false;
  424. }
  425. if (!_rotationAxis.IsHomed)
  426. {
  427. NotifyError(eEvent.ERR_SRD, "Rotation axis is not homed", 0);
  428. return false;
  429. }
  430. if (!_srdCommonDevice.CommonData.ChuckVacuum)
  431. {
  432. NotifyError(eEvent.ERR_SRD, "Vacuum is not released", 0);
  433. return false;
  434. }
  435. if (!_srdCommonDevice.CommonData.DoorOpened)
  436. {
  437. NotifyError(eEvent.ERR_SRD, "Door is not opened", 0);
  438. return false;
  439. }
  440. return true;
  441. }
  442. }
  443. }