PlatingCellVerticalPositionRoutine.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.Routine;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.Routine;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using PunkHPX8_Core;
  11. using PunkHPX8_RT.Devices.AXIS;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Diagnostics.Eventing.Reader;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows.Media.Imaging;
  19. namespace PunkHPX8_RT.Modules.PlatingCell
  20. {
  21. public class PlatingCellVerticalPositionRoutine : RoutineBase, IRoutine
  22. {
  23. private enum PositionStep
  24. {
  25. WaitMatcher,
  26. GotoPosition,
  27. GoToPositionCheck,
  28. End
  29. }
  30. #region 内部变量
  31. /// <summary>
  32. /// vertical axis
  33. /// </summary>
  34. private JetAxisBase _verticalAxis;
  35. /// <summary>
  36. /// matcher集合
  37. /// </summary>
  38. private List<string> _matcher = new List<string>();
  39. /// <summary>
  40. /// cell集合
  41. /// </summary>
  42. private List<PlatingCellEntity> _cellEntities=new List<PlatingCellEntity>();
  43. /// <summary>
  44. /// 位置
  45. /// </summary>
  46. private string _station;
  47. /// <summary>
  48. /// 偏移量
  49. /// </summary>
  50. private double _offset;
  51. /// <summary>
  52. /// 移动速度
  53. /// </summary>
  54. private int _speed;
  55. /// <summary>
  56. /// 加速度
  57. /// </summary>
  58. private int _accelerate;
  59. #endregion
  60. /// <summary>
  61. /// 构造函数
  62. /// </summary>
  63. /// <param name="module"></param>
  64. public PlatingCellVerticalPositionRoutine(string module) : base(module)
  65. {
  66. }
  67. /// <summary>
  68. /// 中止
  69. /// </summary>
  70. public void Abort()
  71. {
  72. Runner.Stop("Manual Abort");
  73. }
  74. /// <summary>
  75. /// 监控
  76. /// </summary>
  77. /// <returns></returns>
  78. public RState Monitor()
  79. {
  80. Runner.Wait(PositionStep.WaitMatcher,CheckMatcher,_delay_60s)
  81. .Run(PositionStep.GotoPosition, VerticalGotoPosition, 100)
  82. .WaitWithStopCondition(PositionStep.GoToPositionCheck, CheckVerticalPositionStatus, CheckVerticalPositionRunStop)
  83. .End(PositionStep.End, NullFun, _delay_1ms);
  84. return Runner.Status;
  85. }
  86. /// <summary>
  87. /// 检验匹配
  88. /// </summary>
  89. /// <returns></returns>
  90. private bool CheckMatcher()
  91. {
  92. if (_cellEntities.Count<=1)
  93. {
  94. return true;
  95. }
  96. int count = 0;
  97. foreach (PlatingCellEntity item in _cellEntities)
  98. {
  99. if (WaferManager.Instance.CheckHasWafer(item.Module, 0))
  100. {
  101. count++;
  102. }
  103. }
  104. if (count == 1)
  105. {
  106. return true;
  107. }
  108. WaferInfo firstWafer = WaferManager.Instance.GetWafer(_cellEntities[0].Module, 0);
  109. WaferInfo secondWafer = WaferManager.Instance.GetWafer(_cellEntities[1].Module, 0);
  110. if (firstWafer == null || secondWafer == null || firstWafer.IsEmpty || secondWafer.IsEmpty)
  111. {
  112. return false;
  113. }
  114. string firstCurrentStep = _cellEntities[0].CurrentStepState;
  115. string secondCurrentStep = _cellEntities[1].CurrentStepState;
  116. if(_cellEntities[0].IsCurrentRunDummyRecipe || _cellEntities[1].IsCurrentRunDummyRecipe)
  117. {
  118. //其中一个是dummy recipe,直接返回true
  119. return true;
  120. }
  121. bool hasDoubleProductionWafer = firstWafer.WaferType == secondWafer.WaferType;
  122. if (hasDoubleProductionWafer)
  123. {
  124. return firstCurrentStep == secondCurrentStep;
  125. }
  126. else
  127. {
  128. //dummy reclaim/rinse/dry与生产片一致
  129. if (secondCurrentStep.StartsWith("Reclaim") || secondCurrentStep.StartsWith("Rinse") || secondCurrentStep.StartsWith("Dry"))
  130. {
  131. return firstCurrentStep==secondCurrentStep;
  132. }
  133. else
  134. {
  135. return true;
  136. }
  137. }
  138. }
  139. /// <summary>
  140. /// vertical 运动到位置
  141. /// </summary>
  142. /// <returns></returns>
  143. private bool VerticalGotoPosition()
  144. {
  145. if(_verticalAxis != null )
  146. {
  147. if (!_verticalAxis.IsSwitchOn)
  148. {
  149. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical is not Power On");
  150. return false;
  151. }
  152. else if (!_verticalAxis.IsHomed)
  153. {
  154. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical is not Home,Home vertical first");
  155. return false;
  156. }
  157. return _verticalAxis.PositionStation(_station,_offset,false,_speed,_accelerate);
  158. }
  159. else
  160. {
  161. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "vertical axis is null");
  162. return false;
  163. }
  164. }
  165. /// <summary>
  166. /// 检验Vertical移动状态
  167. /// </summary>
  168. /// <returns></returns>
  169. private bool CheckVerticalPositionStatus()
  170. {
  171. return _verticalAxis.Status == RState.End;
  172. }
  173. /// <summary>
  174. /// 检验Vertical是否还在运动
  175. /// </summary>
  176. /// <returns></returns>
  177. private bool CheckVerticalPositionRunStop()
  178. {
  179. return _verticalAxis.Status == RState.Failed;
  180. }
  181. /// <summary>
  182. /// 启动
  183. /// </summary>
  184. /// <param name="objs"></param>
  185. /// <returns></returns>
  186. public RState Start(params object[] objs)
  187. {
  188. _station=objs[0].ToString();
  189. _offset = (double)objs[1];
  190. if(objs.Length > 2)
  191. {
  192. _speed = (int)objs[2];
  193. }
  194. if (objs.Length > 3)
  195. {
  196. _accelerate = (int)objs[3];
  197. }
  198. _matcher = ModuleMatcherManager.Instance.GetMatcherListByVertical(Module); //获取电机所在的platingcell 列表
  199. _cellEntities.Clear();
  200. foreach (string str in _matcher)
  201. {
  202. if(!Enum.TryParse(str, out ModuleName moduleName))
  203. {
  204. continue;
  205. }
  206. if (!ModuleHelper.IsInstalled(moduleName))
  207. {
  208. continue;
  209. }
  210. PlatingCellEntity cellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(str);
  211. if (cellEntity.IsDisable)
  212. {
  213. continue;
  214. }
  215. if (cellEntity.IsError)
  216. {
  217. continue;
  218. }
  219. _cellEntities.Add(cellEntity);
  220. }
  221. _verticalAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Vertical");
  222. return Runner.Start(Module, "Start PlatingCell Vertical Position");
  223. }
  224. }
  225. }