TransporterGantryPositionRoutine.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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.Beckhoff.Station;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.Layout;
  9. using MECF.Framework.Common.Routine;
  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.AXIS.CANOpen;
  15. using CyberX8_RT.Devices.Facilities;
  16. using CyberX8_RT.Devices.TransPorter;
  17. using CyberX8_RT.Modules.Loader;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. namespace CyberX8_RT.Modules.Transporter
  24. {
  25. public class TransporterGantryPositionRoutine : RoutineBase, IRoutine
  26. {
  27. private enum MoveToStep
  28. {
  29. SafeMoveTo,
  30. CheckMoveToStatus,
  31. GantryPosition,
  32. GantryPositionWait,
  33. End
  34. }
  35. #region 内部变量
  36. private string _cellName;
  37. private JetAxisBase _gantryAxis;
  38. private JetAxisBase _elevatorAxis;
  39. private LoaderEntity _loaderEntity;
  40. private JetAxisBase _loaderRotationAxis;
  41. private SystemFacilities _facilities;
  42. private TransporterConflictRoutine _conflictRoutine;
  43. ProcessLayoutCellItem _cellItem;
  44. #endregion
  45. /// <summary>
  46. /// 构造函数
  47. /// </summary>
  48. /// <param name="module"></param>
  49. public TransporterGantryPositionRoutine(string module) : base(module)
  50. {
  51. }
  52. /// <summary>
  53. /// 中止
  54. /// </summary>
  55. public void Abort()
  56. {
  57. Runner.Stop("Manual Abort");
  58. }
  59. /// <summary>
  60. /// 监控
  61. /// </summary>
  62. /// <returns></returns>
  63. public RState Monitor()
  64. {
  65. Runner.Run(MoveToStep.SafeMoveTo,SafeMoveTo,_delay_1ms)
  66. .WaitWithStopCondition(MoveToStep.CheckMoveToStatus, () => CommonFunction.CheckRoutineEndState(_conflictRoutine), () => CommonFunction.CheckRoutineStopState(_conflictRoutine))
  67. //1.3 Gantry 移动
  68. .Run(MoveToStep.GantryPosition, GantryPositionToCell, NullFun, _delay_1ms)
  69. .WaitWithStopCondition(MoveToStep.GantryPositionWait, CheckGantryPositionStatus, CheckGantryPositionRunStop)
  70. .End(MoveToStep.End,NullFun,100);
  71. return Runner.Status;
  72. }
  73. /// <summary>
  74. /// 安全避障移动
  75. /// </summary>
  76. /// <returns></returns>
  77. private bool SafeMoveTo()
  78. {
  79. string stationName = GetStationName();
  80. if (string.IsNullOrEmpty(stationName))
  81. {
  82. return false;
  83. }
  84. var result = _gantryAxis.GetPositionByStation(stationName);
  85. if (result.success)
  86. {
  87. bool isPositive = false;
  88. if (_gantryAxis.MotionData.MotorPosition < result.position)
  89. {
  90. isPositive = true;
  91. }
  92. return _conflictRoutine.Start(result.position, isPositive) == RState.Running;
  93. }
  94. else
  95. {
  96. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{_cellName} not in station list");
  97. return false;
  98. }
  99. }
  100. /// <summary>
  101. /// 根据cellName获取StationName
  102. /// </summary>
  103. /// <returns></returns>
  104. private string GetStationName()
  105. {
  106. string stationName = _cellName;
  107. if (_cellName != "Park" && _cellName != "Loader")
  108. {
  109. _cellItem = ProcessLayoutManager.Instance.GetProcessLayoutCellItemByName(_cellName);
  110. if (_cellItem != null)
  111. {
  112. stationName = $"Cell{_cellItem.CellId}";
  113. }
  114. else
  115. {
  116. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{_cellName} not in layout");
  117. return "";
  118. }
  119. }
  120. return stationName;
  121. }
  122. /// <summary>
  123. /// Gantry Position To cell
  124. /// </summary>
  125. /// <returns></returns>
  126. private bool GantryPositionToCell()
  127. {
  128. string stationName = GetStationName();
  129. if (string.IsNullOrEmpty(stationName))
  130. {
  131. return false;
  132. }
  133. return _gantryAxis.PositionStation(stationName);
  134. }
  135. /// <summary>
  136. /// 检验Gantry移动状态
  137. /// </summary>
  138. /// <returns></returns>
  139. private bool CheckGantryPositionStatus()
  140. {
  141. return _gantryAxis.Status == RState.End;
  142. }
  143. /// <summary>
  144. /// 检验Gantry是否还在运动
  145. /// </summary>
  146. /// <returns></returns>
  147. private bool CheckGantryPositionRunStop()
  148. {
  149. return _gantryAxis.Status == RState.Failed;
  150. }
  151. /// <summary>
  152. /// 启动
  153. /// </summary>
  154. /// <param name="objs"></param>
  155. /// <returns></returns>
  156. public RState Start(params object[] objs)
  157. {
  158. _cellName = objs[0].ToString();
  159. _elevatorAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Elevator");
  160. _gantryAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Gantry");
  161. _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  162. _loaderRotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Rotation");
  163. _facilities = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  164. _conflictRoutine = new TransporterConflictRoutine(Module);
  165. if(!CheckStartPreConfition())
  166. {
  167. return RState.Failed;
  168. }
  169. return Runner.Start(Module, $"GantryGoToPosition {_cellName}");
  170. }
  171. /// <summary>
  172. /// 启动校验条件
  173. /// </summary>
  174. /// <returns></returns>
  175. private bool CheckStartPreConfition()
  176. {
  177. if (!_loaderEntity.IsHomed)
  178. {
  179. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{ModuleName.Loader1} is not homed");
  180. return false;
  181. }
  182. if (_cellName == "Loader")
  183. {
  184. double loaderRotationPosition = _loaderRotationAxis.MotionData.MotorPosition;
  185. if (!_loaderRotationAxis.CheckPositionIsInStation(loaderRotationPosition, "TRNPA") &&
  186. !_loaderRotationAxis.CheckPositionIsInStation(loaderRotationPosition, "TRNPB"))
  187. {
  188. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{ModuleName.Loader1} rotation axis {loaderRotationPosition} is not int TRNPA or TRNPB station");
  189. return false;
  190. }
  191. }
  192. string otherTransporter = Module == ModuleName.Transporter2.ToString() ? ModuleName.Transporter1.ToString() : ModuleName.Transporter1.ToString();
  193. TransporterEntity otherTransporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(otherTransporter);
  194. if (!otherTransporterEntity.IsHomed)
  195. {
  196. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{otherTransporter} is not homed");
  197. return false;
  198. }
  199. if (otherTransporterEntity.IsBusy)
  200. {
  201. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{otherTransporter} is busy");
  202. return false;
  203. }
  204. double elevatorPosition=_elevatorAxis.MotionData.MotorPosition;
  205. if (WaferHolderManager.Instance.HasWaferHolder(Module)&& !_elevatorAxis.CheckPositionIsInStation(elevatorPosition, "Up"))
  206. {
  207. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{Module} has wafer Shuttle but elevator axis is not in up");
  208. return false;
  209. }
  210. //检验Facilities
  211. var faciltiesResult = _facilities.CheckCDA();
  212. if (!faciltiesResult.result)
  213. {
  214. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, faciltiesResult.reason);
  215. return false;
  216. }
  217. if (!_gantryAxis.IsSwitchOn)
  218. {
  219. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{Module} gantry axis is not switch on ");
  220. return false;
  221. }
  222. if (!_gantryAxis.IsHomed)
  223. {
  224. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{Module} gantry axis is not homed ");
  225. return false;
  226. }
  227. if (!_elevatorAxis.IsSwitchOn)
  228. {
  229. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{Module} elevator axis is not switch on ");
  230. return false;
  231. }
  232. if (!_elevatorAxis.IsHomed)
  233. {
  234. LOG.WriteLog(eEvent.ERR_TRANSPORTER, Module, $"{Module} elevator axis is not homed ");
  235. return false;
  236. }
  237. return true;
  238. }
  239. }
  240. }