PlatingCellVerticalPositionRoutine.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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(firstWafer.WaferType==WaferType.Assit || secondWafer.WaferType==WaferType.Assit)
  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. return true;
  127. }
  128. /// <summary>
  129. /// vertical 运动到位置
  130. /// </summary>
  131. /// <returns></returns>
  132. private bool VerticalGotoPosition()
  133. {
  134. if(_verticalAxis != null )
  135. {
  136. if (!_verticalAxis.IsSwitchOn)
  137. {
  138. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical is not Power On");
  139. return false;
  140. }
  141. else if (!_verticalAxis.IsHomed)
  142. {
  143. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "Vertical is not Home,Home vertical first");
  144. return false;
  145. }
  146. return _verticalAxis.PositionStation(_station,_offset,false,_speed,_accelerate);
  147. }
  148. else
  149. {
  150. LOG.WriteLog(eEvent.ERR_PLATINGCELL, Module, "vertical axis is null");
  151. return false;
  152. }
  153. }
  154. /// <summary>
  155. /// 检验Vertical移动状态
  156. /// </summary>
  157. /// <returns></returns>
  158. private bool CheckVerticalPositionStatus()
  159. {
  160. return _verticalAxis.Status == RState.End;
  161. }
  162. /// <summary>
  163. /// 检验Vertical是否还在运动
  164. /// </summary>
  165. /// <returns></returns>
  166. private bool CheckVerticalPositionRunStop()
  167. {
  168. return _verticalAxis.Status == RState.Failed;
  169. }
  170. /// <summary>
  171. /// 启动
  172. /// </summary>
  173. /// <param name="objs"></param>
  174. /// <returns></returns>
  175. public RState Start(params object[] objs)
  176. {
  177. _station=objs[0].ToString();
  178. _offset = (double)objs[1];
  179. if(objs.Length > 2)
  180. {
  181. _speed = (int)objs[2];
  182. }
  183. if (objs.Length > 3)
  184. {
  185. _accelerate = (int)objs[3];
  186. }
  187. _matcher = ModuleMatcherManager.Instance.GetMatcherListByVertical(Module); //获取电机所在的platingcell 列表
  188. _cellEntities.Clear();
  189. foreach (string str in _matcher)
  190. {
  191. if(!Enum.TryParse(str, out ModuleName moduleName))
  192. {
  193. continue;
  194. }
  195. if (!ModuleHelper.IsInstalled(moduleName))
  196. {
  197. continue;
  198. }
  199. PlatingCellEntity cellEntity = Singleton<RouteManager>.Instance.GetModule<PlatingCellEntity>(str);
  200. if (cellEntity.IsDisable)
  201. {
  202. continue;
  203. }
  204. if (cellEntity.IsError)
  205. {
  206. continue;
  207. }
  208. _cellEntities.Add(cellEntity);
  209. }
  210. _verticalAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Vertical");
  211. return Runner.Start(Module, "Start PlatingCell Vertical Position");
  212. }
  213. }
  214. }