TransporterMoveToRoutine.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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 TransporterMoveToRoutine : RoutineBase, IRoutine
  26. {
  27. private enum MoveToStep
  28. {
  29. CheckStatus,
  30. ElevatorPosition,
  31. ElevatorPositionWait,
  32. SafeMoveTo,
  33. CheckMoveToStatus,
  34. GantryPosition,
  35. GantryPositionWait,
  36. End
  37. }
  38. #region 内部变量
  39. private string _cellName;
  40. private string _otherModule;
  41. private JetAxisBase _gantryAxis;
  42. private JetAxisBase _elevatorAxis;
  43. private JetAxisBase _otherElevatorAxis;
  44. private LoaderEntity _loaderEntity;
  45. private JetAxisBase _loaderRotationAxis;
  46. private TransporterCommon _transporterCommon;
  47. private SystemFacilities _facilities;
  48. private TransporterConflictRoutine _conflictRoutine;
  49. ProcessLayoutCellItem _cellItem;
  50. private bool _waferHolderPresent = false;
  51. #endregion
  52. #region 属性
  53. public string TargetCell { get { return _cellName; } }
  54. #endregion
  55. /// <summary>
  56. /// 构造函数
  57. /// </summary>
  58. /// <param name="module"></param>
  59. public TransporterMoveToRoutine(string module) : base(module)
  60. {
  61. }
  62. /// <summary>
  63. /// 中止
  64. /// </summary>
  65. public void Abort()
  66. {
  67. Runner.Stop("Manual Abort");
  68. }
  69. /// <summary>
  70. /// 监控
  71. /// </summary>
  72. /// <returns></returns>
  73. public RState Monitor()
  74. {
  75. Runner.Run(MoveToStep.CheckStatus, CheckStartPreConfition, NullFun,_delay_1ms)
  76. //1. Elevator
  77. .Run(MoveToStep.ElevatorPosition, ElevatorPosition, _delay_1ms)
  78. .WaitWithStopCondition(MoveToStep.ElevatorPositionWait, CheckElevatorPositionStatus, CheckElevatorPositionRunStop)
  79. //2. other Transporter Safe Move
  80. .Run(MoveToStep.SafeMoveTo, SafeMoveTo, _delay_1ms)
  81. .WaitWithStopCondition(MoveToStep.CheckMoveToStatus, () => CommonFunction.CheckRoutineEndState(_conflictRoutine),
  82. CheckSafeMoveToStopStatus)
  83. //3. this Gantry Move To Target Cell
  84. .Run(MoveToStep.GantryPosition, GantryPositionToCell, _delay_1ms)
  85. .WaitWithStopCondition(MoveToStep.GantryPositionWait, CheckGantryPositionStatus, CheckGantryPositionRunStop)
  86. .End(MoveToStep.End,NullFun,100);
  87. return Runner.Status;
  88. }
  89. /// <summary>
  90. /// Elevator Position
  91. /// </summary>
  92. /// <returns></returns>
  93. private bool ElevatorPosition()
  94. {
  95. bool result= false;
  96. //运动至UP
  97. double elevatorPosition = _elevatorAxis.MotionData.MotorPosition;
  98. if (!_elevatorAxis.CheckPositionIsInStation(elevatorPosition, "UP"))
  99. {
  100. result= _elevatorAxis.PositionStation("UP");
  101. if(!result)
  102. {
  103. NotifyError(eEvent.ERR_TRANSPORTER, "elevator goto up failed", 0);
  104. }
  105. }
  106. else
  107. {
  108. result = true;
  109. }
  110. return result;
  111. }
  112. /// <summary>
  113. /// 安全避障移动
  114. /// </summary>
  115. /// <returns></returns>
  116. private bool SafeMoveTo()
  117. {
  118. _cellItem = ProcessLayoutManager.Instance.GetProcessLayoutCellItemByModuleName(_cellName);
  119. string stationName = _cellName;
  120. if (_cellItem != null)
  121. {
  122. if (_cellName.ToLower() != "loader" && _cellName.ToLower() != "park")
  123. {
  124. stationName = $"Cell{_cellItem.CellId}";
  125. }
  126. }
  127. else
  128. {
  129. NotifyError(eEvent.ERR_TRANSPORTER, $"{_cellName} not in layout",0);
  130. return false;
  131. }
  132. var result = _gantryAxis.GetPositionByStation(stationName);
  133. if (result.success)
  134. {
  135. bool isPositive = false;
  136. if (_gantryAxis.MotionData.MotorPosition < result.position)
  137. {
  138. isPositive = true;
  139. }
  140. return _conflictRoutine.Start(result.position, isPositive) == RState.Running;
  141. }
  142. else
  143. {
  144. NotifyError(eEvent.ERR_TRANSPORTER, $"{_cellName} not in station list",0);
  145. return false;
  146. }
  147. }
  148. /// <summary>
  149. /// 检验安全避让异常结束状态
  150. /// </summary>
  151. /// <returns></returns>
  152. private bool CheckSafeMoveToStopStatus()
  153. {
  154. bool result = CommonFunction.CheckRoutineStopState(_conflictRoutine);
  155. if (result)
  156. {
  157. NotifyError(eEvent.ERR_TRANSPORTER, "Safe Move failed", 0);
  158. }
  159. return result;
  160. }
  161. /// <summary>
  162. /// Gantry Position To cell
  163. /// </summary>
  164. /// <returns></returns>
  165. private bool GantryPositionToCell()
  166. {
  167. _cellItem= ProcessLayoutManager.Instance.GetProcessLayoutCellItemByModuleName(_cellName);
  168. bool result = false;
  169. if (_cellItem != null)
  170. {
  171. if (_cellName.ToLower() != "loader"&&_cellName.ToLower()!="park")
  172. {
  173. result= _gantryAxis.PositionStation($"Cell{_cellItem.CellId}", false);
  174. }
  175. else
  176. {
  177. result= _gantryAxis.PositionStation(_cellName,false);
  178. }
  179. if (!result)
  180. {
  181. NotifyError(eEvent.ERR_TRANSPORTER, "gantry axis motion failed", 0);
  182. }
  183. return result;
  184. }
  185. else
  186. {
  187. NotifyError(eEvent.ERR_TRANSPORTER, $"{_cellName} not in layout",0);
  188. return false;
  189. }
  190. }
  191. /// <summary>
  192. /// 检验Elevator移动状态
  193. /// </summary>
  194. /// <returns></returns>
  195. private bool CheckElevatorPositionStatus()
  196. {
  197. return _elevatorAxis.Status == RState.End;
  198. }
  199. /// <summary>
  200. /// 检验Elevator是否还在运动
  201. /// </summary>
  202. /// <returns></returns>
  203. private bool CheckElevatorPositionRunStop()
  204. {
  205. bool result= _elevatorAxis.Status == RState.Failed||_elevatorAxis.Status==RState.Timeout;
  206. if (result)
  207. {
  208. NotifyError(eEvent.ERR_TRANSPORTER, "elevator motion failed",0);
  209. }
  210. return result;
  211. }
  212. /// <summary>
  213. /// 检验Gantry移动状态
  214. /// </summary>
  215. /// <returns></returns>
  216. private bool CheckGantryPositionStatus()
  217. {
  218. return _gantryAxis.Status == RState.End;
  219. }
  220. /// <summary>
  221. /// 检验Gantry是否还在运动
  222. /// </summary>
  223. /// <returns></returns>
  224. private bool CheckGantryPositionRunStop()
  225. {
  226. bool result= _gantryAxis.Status == RState.Failed||_gantryAxis.Status==RState.Timeout;
  227. if(result)
  228. {
  229. NotifyError(eEvent.ERR_TRANSPORTER, "gantry motion failed", 0);
  230. }
  231. return result;
  232. }
  233. /// <summary>
  234. /// 启动
  235. /// </summary>
  236. /// <param name="objs"></param>
  237. /// <returns></returns>
  238. public RState Start(params object[] objs)
  239. {
  240. _cellName = objs[0].ToString();
  241. InitializeParameters();
  242. return Runner.Start(Module,$"MoveTo {_cellName}");
  243. }
  244. /// <summary>
  245. /// 初始化参数
  246. /// </summary>
  247. private void InitializeParameters()
  248. {
  249. _elevatorAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Elevator");
  250. _otherModule = Module == "Transporter2" ? "Transporter1" : "Transporter2";
  251. _otherElevatorAxis = DEVICE.GetDevice<JetAxisBase>($"{_otherModule}.Elevator");
  252. _gantryAxis = DEVICE.GetDevice<JetAxisBase>($"{Module}.Gantry");
  253. _loaderEntity = Singleton<RouteManager>.Instance.GetModule<LoaderEntity>(ModuleName.Loader1.ToString());
  254. _loaderRotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.Loader1}.Rotation");
  255. _conflictRoutine = new TransporterConflictRoutine(Module);
  256. _transporterCommon = DEVICE.GetDevice<TransporterCommon>($"{Module}.Common");
  257. }
  258. /// <summary>
  259. /// 启动校验条件
  260. /// </summary>
  261. /// <returns></returns>
  262. private bool CheckStartPreConfition()
  263. {
  264. //所有轴上电并Homed
  265. if(!CheckPreCondition())
  266. {
  267. return false;
  268. }
  269. //若目标Cell为Loader, 则Loader应在TRNPA或TRNPB位
  270. if (_cellName == "Loader")
  271. {
  272. double loaderRotationPosition = _loaderRotationAxis.MotionData.MotorPosition;
  273. if (!_loaderRotationAxis.CheckPositionIsInStation(loaderRotationPosition, "TRNPA") &&
  274. !_loaderRotationAxis.CheckPositionIsInStation(loaderRotationPosition, "TRNPB"))
  275. {
  276. NotifyError(eEvent.ERR_TRANSPORTER, $"{ModuleName.Loader1} rotation axis {loaderRotationPosition} is not int TRNPA or TRNPB station",-1);
  277. return false;
  278. }
  279. }
  280. //检验Facilities
  281. //var faciltiesResult = _facilities.CheckCDA();
  282. //if (!faciltiesResult.result)
  283. //{
  284. // NotifyError(eEvent.ERR_TRANSPORTER, faciltiesResult.reason, -1);
  285. // return false;
  286. //}
  287. return true;
  288. }
  289. /// <summary>
  290. /// 检验前置条件
  291. /// </summary>
  292. /// <returns></returns>
  293. private bool CheckPreCondition()
  294. {
  295. if (!_gantryAxis.IsSwitchOn)
  296. {
  297. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} gantry axis is not switch on ",-1);
  298. return false;
  299. }
  300. if (!_gantryAxis.IsHomed)
  301. {
  302. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} gantry axis is not homed ",-1);
  303. return false;
  304. }
  305. if (!_elevatorAxis.IsSwitchOn)
  306. {
  307. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} elevator axis is not switch on ",-1);
  308. return false;
  309. }
  310. if (!_elevatorAxis.IsHomed)
  311. {
  312. NotifyError(eEvent.ERR_TRANSPORTER, $"{Module} elevator axis is not homed ",-1);
  313. return false;
  314. }
  315. return true;
  316. }
  317. /// <summary>
  318. /// 重试
  319. /// </summary>
  320. /// <param name="step"></param>
  321. public RState Retry(int step)
  322. {
  323. InitializeParameters();
  324. List<Enum> preStepIds = new List<Enum>();
  325. return Runner.Retry(MoveToStep.CheckStatus, preStepIds, Module, "Moveto Retry");
  326. }
  327. /// <summary>
  328. /// 检验前面Unload完成状态
  329. /// </summary>
  330. /// <returns></returns>
  331. public bool CheckCompleteCondition(int index)
  332. {
  333. TransporterEntity transporterEntity = Singleton<RouteManager>.Instance.GetModule<TransporterEntity>(Module);
  334. if (!_gantryAxis.CheckPositionIsInStation(_gantryAxis.MotionData.MotorPosition,_cellName))
  335. {
  336. NotifyError(eEvent.ERR_TRANSPORTER, $"gantry is not in {_cellName}", index);
  337. return false;
  338. }
  339. return true;
  340. }
  341. }
  342. }