TransporterPickUpMoveToRoutine.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Layout;
  8. using MECF.Framework.Common.Routine;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using MECF.Framework.Common.Utilities;
  11. using MECF.Framework.Common.WaferHolder;
  12. using CyberX8_Core;
  13. using CyberX8_RT.Devices.AXIS;
  14. using CyberX8_RT.Devices.Facilities;
  15. using CyberX8_RT.Devices.TransPorter;
  16. using CyberX8_RT.Modules.Loader;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. namespace CyberX8_RT.Modules.Transporter
  23. {
  24. public class TransporterPickUpMoveToRoutine : RoutineBase, IRoutine
  25. {
  26. private enum TransferStep
  27. {
  28. CheckStatus,
  29. PickUpFrom,
  30. PickUpFromWait,
  31. MoveTo,
  32. MoveToWait,
  33. End
  34. }
  35. #region 内部变量
  36. private string _fromCellName;
  37. private string _toCellName;
  38. private JetAxisBase _gantryAxis;
  39. private JetAxisBase _elevatorAxis;
  40. private LoaderEntity _loaderEntity;
  41. private JetAxisBase _loaderRotationAxis;
  42. private SystemFacilities _facilities;
  43. private TransporterPickUpFromRoutine _pickUpRoutine;
  44. private TransporterMoveToRoutine _moveToRoutine;
  45. #endregion
  46. #region 属性
  47. public string SourceCell { get { return _fromCellName; } }
  48. public string TargetCell { get { return _toCellName; } }
  49. #endregion
  50. /// <summary>
  51. /// 构造函数
  52. /// </summary>
  53. /// <param name="module"></param>
  54. public TransporterPickUpMoveToRoutine(string module) : base(module)
  55. {
  56. _pickUpRoutine=new TransporterPickUpFromRoutine(module);
  57. _moveToRoutine = new TransporterMoveToRoutine(module);
  58. }
  59. /// <summary>
  60. /// 中止
  61. /// </summary>
  62. public void Abort()
  63. {
  64. Runner.Stop("Manual Abort");
  65. }
  66. /// <summary>
  67. /// 监控
  68. /// </summary>
  69. /// <returns></returns>
  70. public RState Monitor()
  71. {
  72. Runner.Run(TransferStep.CheckStatus, CheckStartPreConfition,_delay_1ms)
  73. //1.1 PickupFrom
  74. .Run(TransferStep.PickUpFrom, () => { return _pickUpRoutine.Start(_fromCellName) == RState.Running; }, _delay_1ms)
  75. .WaitWithStopCondition(TransferStep.PickUpFromWait, ()=>CommonFunction.CheckRoutineEndState(_pickUpRoutine), CheckPickupStopStatus)
  76. //1.2 Move to
  77. .Run(TransferStep.MoveTo, () => { return _moveToRoutine.Start(_toCellName) == RState.Running; }, _delay_1ms)
  78. .WaitWithStopCondition(TransferStep.MoveToWait, ()=>CommonFunction.CheckRoutineEndState(_moveToRoutine), CheckMoveToStopStatus)
  79. .End(TransferStep.End,LastChangeWafer,100);
  80. return Runner.Status;
  81. }
  82. /// <summary>
  83. /// 检验pickup异常状态
  84. /// </summary>
  85. /// <returns></returns>
  86. private bool CheckPickupStopStatus()
  87. {
  88. bool result = CommonFunction.CheckRoutineStopState(_pickUpRoutine);
  89. if (result)
  90. {
  91. NotifyError(eEvent.ERR_TRANSPORTER, $"PickUp MoveTo Routine\r\nPickUp Routine\r\n{_pickUpRoutine.ErrorMsg}", 0);
  92. }
  93. return result;
  94. }
  95. /// <summary>
  96. /// 检验MoveTo异常状态
  97. /// </summary>
  98. /// <returns></returns>
  99. private bool CheckMoveToStopStatus()
  100. {
  101. bool result = CommonFunction.CheckRoutineStopState(_moveToRoutine);
  102. if (result)
  103. {
  104. NotifyError(eEvent.ERR_TRANSPORTER, $"PickUpMoveTo Routine\r\nMoveTo Routine\r\n_moveToRoutine.ErrorMsg", 1);
  105. }
  106. return result;
  107. }
  108. /// <summary>
  109. /// 检验前置条件
  110. /// </summary>
  111. /// <returns></returns>
  112. private bool CheckPreCondition()
  113. {
  114. if(!_gantryAxis.IsSwitchOn)
  115. {
  116. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} gantry axis is not switch on ",-1);
  117. return false;
  118. }
  119. if (!_gantryAxis.IsHomed)
  120. {
  121. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} gantry axis is not homed ", -1);
  122. return false;
  123. }
  124. if (!_elevatorAxis.IsSwitchOn)
  125. {
  126. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} elevator axis is not switch on ",-1);
  127. return false;
  128. }
  129. if (!_elevatorAxis.IsHomed)
  130. {
  131. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} elevator axis is not homed ", -1);
  132. return false;
  133. }
  134. return true;
  135. }
  136. /// <summary>
  137. /// 最后交换Wafer
  138. /// </summary>
  139. /// <returns></returns>
  140. private bool LastChangeWafer()
  141. {
  142. ModuleName sourceModule;
  143. if (_fromCellName.ToLower() == "loader")
  144. {
  145. sourceModule = ModuleName.Loader1;
  146. }
  147. else
  148. {
  149. sourceModule = (ModuleName)Enum.Parse(typeof(ModuleName), _fromCellName);
  150. }
  151. ModuleName destModule;
  152. if (_toCellName.ToLower() == "loader")
  153. {
  154. destModule = ModuleName.Loader1;
  155. }
  156. else
  157. {
  158. destModule = (ModuleName)Enum.Parse(typeof(ModuleName), _toCellName);
  159. }
  160. if (WaferManager.Instance.CheckHasWafer(sourceModule, 0))
  161. {
  162. WaferManager.Instance.WaferMoved(sourceModule, 0, destModule, 0);
  163. }
  164. if (WaferManager.Instance.CheckHasWafer(sourceModule, 1))
  165. {
  166. WaferManager.Instance.WaferMoved(sourceModule, 1, destModule, 1);
  167. }
  168. return true;
  169. }
  170. /// <summary>
  171. /// 启动
  172. /// </summary>
  173. /// <param name="objs"></param>
  174. /// <returns></returns>
  175. public RState Start(params object[] objs)
  176. {
  177. _fromCellName = objs[0].ToString();
  178. _toCellName = objs[1].ToString();
  179. InitializeParameters();
  180. return Runner.Start(Module, $"Pickup {_fromCellName} Moveto {_toCellName}");
  181. }
  182. /// <summary>
  183. /// 初始化Parameters
  184. /// </summary>
  185. private void InitializeParameters()
  186. {
  187. _elevatorAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Elevator");
  188. _gantryAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Gantry");
  189. _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  190. _loaderRotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Rotation");
  191. _facilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  192. }
  193. /// <summary>
  194. /// 启动校验条件
  195. /// </summary>
  196. /// <returns></returns>
  197. private bool CheckStartPreConfition()
  198. {
  199. if (!CheckPreCondition())
  200. {
  201. return false;
  202. }
  203. double elevatorPosition = _elevatorAxis.MotionData.MotorPosition;
  204. if (!_elevatorAxis.CheckPositionIsInStation(elevatorPosition, "Up"))
  205. {
  206. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} elevator axis {elevatorPosition} is no int Up station",-1);
  207. return false;
  208. }
  209. if (!_loaderEntity.IsHomed)
  210. {
  211. NotifyError(eEvent.ERR_TRANSPORTER, $"{ModuleName.Loader1} is not homed",-1);
  212. return false;
  213. }
  214. if (_toCellName == "Loader" || _fromCellName == "Loader")
  215. {
  216. double loaderRotationPosition = _loaderRotationAxis.MotionData.MotorPosition;
  217. if (!_loaderRotationAxis.CheckPositionIsInStation(loaderRotationPosition, "TRNPA") &&
  218. !_loaderRotationAxis.CheckPositionIsInStation(loaderRotationPosition, "TRNPB"))
  219. {
  220. NotifyError(eEvent.ERR_TRANSPORTER, $"{ModuleName.Loader1} rotation axis {loaderRotationPosition} is not int TRNPA or TRNPB station", -1);
  221. return false;
  222. }
  223. }
  224. if (WaferHolderManager.Instance.HasWaferHolder(Module))
  225. {
  226. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} has wafer Shuttle", -1);
  227. return false;
  228. }
  229. if (!WaferHolderManager.Instance.HasWaferHolder(_fromCellName))
  230. {
  231. NotifyError(eEvent.ERR_TRANSPORTER, $"{_fromCellName} does not has wafer Shuttle", -1);
  232. return false;
  233. }
  234. if (WaferHolderManager.Instance.HasWaferHolder(_toCellName))
  235. {
  236. NotifyError(eEvent.ERR_TRANSPORTER, $"{_toCellName} already has wafer Shuttle",-1);
  237. return false;
  238. }
  239. //检验Facilities
  240. //var faciltiesResult = _facilities.CheckCDA();
  241. //if (!faciltiesResult.result)
  242. //{
  243. // NotifyError(eEvent.ERR_TRANSPORTER, faciltiesResult.reason, -1);
  244. // return false;
  245. //}
  246. return true;
  247. }
  248. /// <summary>
  249. /// 重试
  250. /// </summary>
  251. /// <param name="step"></param>
  252. public RState Retry(int step)
  253. {
  254. if (string.IsNullOrEmpty(_fromCellName))
  255. {
  256. NotifyError(eEvent.ERR_TRANSPORTER, "source cell is empty", step);
  257. return RState.Failed;
  258. }
  259. if (string.IsNullOrEmpty(_toCellName))
  260. {
  261. NotifyError(eEvent.ERR_TRANSPORTER, "target cell is empty", step);
  262. return RState.Failed;
  263. }
  264. InitializeParameters();
  265. List<Enum> preStepIds = new List<Enum>();
  266. if (step == 0 || step == -1)
  267. {
  268. return Runner.Retry(TransferStep.CheckStatus, preStepIds, Module, "PickUp Moveto Retry");
  269. }
  270. else
  271. {
  272. AddPreSteps(TransferStep.MoveTo, preStepIds);
  273. return Runner.Retry(TransferStep.MoveTo, preStepIds, Module, $"PickUp Moveto step {TransferStep.MoveTo} Retry");
  274. }
  275. }
  276. /// <summary>
  277. /// 忽略前
  278. /// </summary>
  279. /// <param name="step"></param>
  280. /// <param name="preStepIds"></param>
  281. private void AddPreSteps(TransferStep step, List<Enum> preStepIds)
  282. {
  283. for (int i = 0; i < (int)step; i++)
  284. {
  285. preStepIds.Add((TransferStep)i);
  286. }
  287. }
  288. /// <summary>
  289. /// 检验前面Unload完成状态
  290. /// </summary>
  291. /// <returns></returns>
  292. public bool CheckCompleteCondition(int index)
  293. {
  294. TransporterEntity transporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(Module);
  295. if (transporterEntity.WaferHolderInfo==null)
  296. {
  297. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} does not have waferholder", index);
  298. return false;
  299. }
  300. double gantryPosition = _gantryAxis.MotionData.MotorPosition;
  301. if(!_gantryAxis.CheckPositionIsInStation(gantryPosition,_toCellName))
  302. {
  303. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} gantry not in {_toCellName}", index);
  304. return false;
  305. }
  306. return true;
  307. }
  308. }
  309. }