LoaderHomeAllRoutine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.Routine;
  4. using MECF.Framework.Common.Equipment;
  5. using MECF.Framework.Common.Routine;
  6. using MECF.Framework.Common.Utilities;
  7. using CyberX8_Core;
  8. using CyberX8_RT.Devices.AXIS;
  9. using CyberX8_RT.Devices.Loader;
  10. using CyberX8_RT.Devices.PUF;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using CyberX8_RT.Devices.Safety;
  17. namespace CyberX8_RT.Modules.Loader
  18. {
  19. public class LoaderHomeAllRoutine : RoutineBase, IRoutine
  20. {
  21. private enum HomeAllStep
  22. {
  23. CheckSafety,
  24. SideADoorUnlock,
  25. WaitSideADoorUnlock,
  26. TiltAHome,
  27. WaitTiltAHome,
  28. TiltAGotoVertical,
  29. TiltAGotoVerticalCheck,
  30. SideBDoorUnlock,
  31. WaitSideBDoorUnlock,
  32. TiltBHome,
  33. WaitTiltBHome,
  34. TiltBGotoVertical,
  35. TiltBGotoVerticalCheck,
  36. ShuttleAHome,
  37. WaitShuttleAHome,
  38. ShuttleAGotoClose,
  39. ShuttleAGotoCloseCheck,
  40. ShuttleBHome,
  41. WaitShuttleBHome,
  42. ShuttleBGotoClose,
  43. ShuttleBGotoCloseCheck,
  44. SideADoorLockOn,
  45. SideADoorLockOnCheck,
  46. SideBDoorLockOn,
  47. SideBDoorLockOnCheck,
  48. CheckDupfCondition,
  49. RotationHome,
  50. WaitRotationHome,
  51. RotationGotoTrnpa,
  52. RotationGotoTrnpaCheck,
  53. CRSAHome,
  54. WaitCRSAHome,
  55. CRSAGotoSetUp,
  56. CRSAGotoSetUpCheck,
  57. CRSBHome,
  58. WaitCRSBHome,
  59. CRSBGotoSetUp,
  60. CRSBGotoSetUpCheck,
  61. End
  62. }
  63. #region 内部变量
  64. private JetAxisBase _shuttleAAxis;
  65. private JetAxisBase _shuttleBAxis;
  66. private JetAxisBase _tiltAAxis;
  67. private JetAxisBase _tiltBAxis;
  68. private JetAxisBase _rotationAxis;
  69. private JetAxisBase _crsAAxis;
  70. private JetAxisBase _crsBAxis;
  71. private JetAxisBase _puf1VerticalAxis;
  72. private JetAxisBase _puf2VerticalAxis;
  73. private JetAxisBase _puf2RotationAxis;
  74. private LoaderSideDevice _sideADevice;
  75. private bool _isExecuteSideAUnlock = false;
  76. private LoaderSideDevice _sideBDevice;
  77. private bool _isExecuteSideBUnlock = false;
  78. #endregion
  79. public LoaderHomeAllRoutine(string module) : base(module)
  80. {
  81. _shuttleAAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.ShuttleA");
  82. _shuttleBAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.ShuttleB");
  83. _tiltAAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.TiltA");
  84. _tiltBAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.TiltB");
  85. _crsAAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.LSA");
  86. _crsBAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.LSB");
  87. _rotationAxis = DEVICE.GetDevice<JetAxisBase>($"{module}.Rotation");
  88. }
  89. public void Abort()
  90. {
  91. Runner.Stop("Manual Abort");
  92. }
  93. public RState Monitor()
  94. {
  95. //Home Tilt Goto VERT
  96. Runner.Run(HomeAllStep.CheckSafety,CheckSafety,_delay_1ms)
  97. .Run(HomeAllStep.SideADoorUnlock, () => SideDoorUnlock(_sideADevice, ref _isExecuteSideAUnlock), _delay_1ms)
  98. .WaitWithStopCondition(HomeAllStep.WaitSideADoorUnlock, () => CheckSideDoorUnlockedEndStatus(_sideADevice, _isExecuteSideAUnlock),
  99. () => CheckSideDoorUnlockedStopStatus(_sideADevice, _isExecuteSideAUnlock))
  100. .Run(HomeAllStep.TiltAHome, () => { return _tiltAAxis.Home(); },_delay_1ms)
  101. .WaitWithStopCondition(HomeAllStep.WaitTiltAHome, () => { return _tiltAAxis.Status == RState.End; }, () => {return _tiltAAxis.Status == RState.Failed; })
  102. .Run(HomeAllStep.TiltAGotoVertical, () => { return _tiltAAxis.PositionStation("VERT",true); },100)
  103. .WaitWithStopCondition(HomeAllStep.TiltAGotoVerticalCheck, () => { return _tiltAAxis.Status == RState.End; }, () => { return _tiltAAxis.Status == RState.Failed; })
  104. .Run(HomeAllStep.SideBDoorUnlock, () => SideDoorUnlock(_sideBDevice, ref _isExecuteSideBUnlock), _delay_1ms)
  105. .WaitWithStopCondition(HomeAllStep.WaitSideBDoorUnlock, () => CheckSideDoorUnlockedEndStatus(_sideBDevice, _isExecuteSideBUnlock),
  106. () => CheckSideDoorUnlockedStopStatus(_sideADevice, _isExecuteSideBUnlock))
  107. .Run(HomeAllStep.TiltBHome, () => { return _tiltBAxis.Home(); }, _delay_1ms)
  108. .WaitWithStopCondition(HomeAllStep.WaitTiltBHome, () => { return _tiltBAxis.Status == RState.End; }, () => { return _tiltBAxis.Status == RState.Failed; })
  109. .Run(HomeAllStep.TiltBGotoVertical, () => { return _tiltBAxis.PositionStation("VERT",true); }, 100)
  110. .WaitWithStopCondition(HomeAllStep.TiltBGotoVerticalCheck, () => { return _tiltBAxis.Status == RState.End; }, () => { return _tiltBAxis.Status == RState.Failed; })
  111. //Home Shuttle Goto CLOSED
  112. .Run(HomeAllStep.ShuttleAHome, () => { return _shuttleAAxis.Home(); }, _delay_1ms)
  113. .WaitWithStopCondition(HomeAllStep.WaitShuttleAHome, () => { return _shuttleAAxis.Status == RState.End; }, () => { return _shuttleAAxis.Status == RState.Failed; })
  114. .Run(HomeAllStep.ShuttleAGotoClose, () => { return _shuttleAAxis.PositionStation("CLOSED",true); }, 100)
  115. .WaitWithStopCondition(HomeAllStep.ShuttleAGotoCloseCheck, () => { return _shuttleAAxis.Status == RState.End; }, () => { return _shuttleAAxis.Status == RState.Failed; })
  116. .Run(HomeAllStep.ShuttleBHome, () => { return _shuttleBAxis.Home(); }, _delay_1ms)
  117. .WaitWithStopCondition(HomeAllStep.WaitShuttleBHome, () => { return _shuttleBAxis.Status == RState.End; }, () => { return _shuttleBAxis.Status == RState.Failed; })
  118. .Run(HomeAllStep.ShuttleBGotoClose, () => { return _shuttleBAxis.PositionStation("CLOSED", true); }, 100)
  119. .WaitWithStopCondition(HomeAllStep.ShuttleBGotoCloseCheck, () => { return _shuttleBAxis.Status == RState.End; }, () => { return _shuttleBAxis.Status == RState.Failed; })
  120. //Door Lock On
  121. .Run(HomeAllStep.SideADoorLockOn, () => { return _sideADevice.DoorLockOnAction(); }, 100)
  122. .WaitWithStopCondition(HomeAllStep.SideADoorLockOnCheck, () => { return _sideADevice.Status==RState.End; }, () => { return _sideADevice.Status==RState.Failed; })
  123. .Run(HomeAllStep.SideBDoorLockOn, () => { return _sideBDevice.DoorLockOnAction(); }, 100)
  124. .WaitWithStopCondition(HomeAllStep.SideBDoorLockOnCheck, () => { return _sideBDevice.Status==RState.End; }, () => { return _sideBDevice.Status==RState.Failed; })
  125. //Home Rotation Goto TRNPA
  126. .Run(HomeAllStep.CheckDupfCondition,CheckDupufCondition,_delay_1ms)
  127. .Run(HomeAllStep.RotationHome, () => { return _rotationAxis.Home(); },_delay_1ms)
  128. .WaitWithStopCondition(HomeAllStep.WaitRotationHome, () => { return _rotationAxis.Status == RState.End; }, () => { return _rotationAxis.Status == RState.Failed; })
  129. .Run(HomeAllStep.RotationGotoTrnpa, () => { return _rotationAxis.PositionStation("TRNPA",true); }, 100)
  130. .WaitWithStopCondition(HomeAllStep.RotationGotoTrnpaCheck, () => { return _rotationAxis.Status == RState.End; }, () => { return _rotationAxis.Status == RState.Failed; })
  131. //Home CRS
  132. .Run(HomeAllStep.CRSAHome, () => { return _crsAAxis.Home(); }, _delay_1ms)
  133. .WaitWithStopCondition(HomeAllStep.WaitCRSAHome, () => { return _crsAAxis.Status == RState.End; }, () => { return _crsAAxis.Status == RState.Failed; })
  134. .Run(HomeAllStep.CRSAGotoSetUp, () => { return _crsAAxis.PositionStation("Setup", true); }, _delay_1ms)
  135. .WaitWithStopCondition(HomeAllStep.CRSAGotoSetUpCheck, () => { return _crsAAxis.Status == RState.End; }, () => { return _crsAAxis.Status == RState.Failed; })
  136. .Run(HomeAllStep.CRSBHome, () => { return _crsBAxis.Home(); }, _delay_1ms)
  137. .WaitWithStopCondition(HomeAllStep.WaitCRSBHome, () => { return _crsBAxis.Status == RState.End; }, () => { return _crsBAxis.Status == RState.Failed; })
  138. .Run(HomeAllStep.CRSBGotoSetUp, () => { return _crsBAxis.PositionStation("Setup",true); }, 100)
  139. .WaitWithStopCondition(HomeAllStep.CRSBGotoSetUpCheck, () => { return _crsBAxis.Status == RState.End; }, () => { return _crsBAxis.Status == RState.Failed; })
  140. .End(HomeAllStep.End,NullFun);
  141. return Runner.Status;
  142. }
  143. /// <summary>
  144. /// 检验Safety
  145. /// </summary>
  146. /// <returns></returns>
  147. private bool CheckSafety()
  148. {
  149. SafetyDevice safetyDevice = DEVICE.GetDevice<SafetyDevice>("Safety");
  150. if (safetyDevice == null)
  151. {
  152. LOG.WriteLog(eEvent.ERR_LOADER, Module.ToString(), "Safety device is null");
  153. return false;
  154. }
  155. if (safetyDevice.SafetyData.TwincatState != 8)
  156. {
  157. LOG.WriteLog(eEvent.ERR_LOADER, Module.ToString(), "Twincat Status is not OP status");
  158. return false;
  159. }
  160. if (safetyDevice.SafetyData.LoaderPufCommErr)
  161. {
  162. LOG.WriteLog(eEvent.ERR_LOADER, Module.ToString(), "Twincat Loader Communication status is error");
  163. return false;
  164. }
  165. if (safetyDevice.SafetyData.LoaderPufFunctionBlockErr)
  166. {
  167. LOG.WriteLog(eEvent.ERR_LOADER, Module.ToString(), "Twincat Loader function block status is error");
  168. return false;
  169. }
  170. return true;
  171. }
  172. /// <summary>
  173. /// Side Door Unlock
  174. /// </summary>
  175. /// <returns></returns>
  176. private bool SideDoorUnlock(LoaderSideDevice sideDevice,ref bool execute)
  177. {
  178. if (sideDevice.SideData.DoorLowerLocked || sideDevice.SideData.DoorUpperLocked)
  179. {
  180. execute = true;
  181. return sideDevice.DoorLockOffAction();
  182. }
  183. else
  184. {
  185. return true;
  186. }
  187. }
  188. /// <summary>
  189. /// 校验Side Unlocked
  190. /// </summary>
  191. /// <param name="sideDevice"></param>
  192. /// <param name="execute"></param>
  193. /// <returns></returns>
  194. private bool CheckSideDoorUnlockedEndStatus(LoaderSideDevice sideDevice,bool execute)
  195. {
  196. if(execute)
  197. {
  198. return sideDevice.Status == RState.End;
  199. }
  200. else
  201. {
  202. return true;
  203. }
  204. }
  205. /// <summary>
  206. /// 校验Side Unlocked
  207. /// </summary>
  208. /// <param name="sideDevice"></param>
  209. /// <param name="execute"></param>
  210. /// <returns></returns>
  211. private bool CheckSideDoorUnlockedStopStatus(LoaderSideDevice sideDevice, bool execute)
  212. {
  213. if (execute)
  214. {
  215. return sideDevice.Status == RState.Failed;
  216. }
  217. else
  218. {
  219. return true;
  220. }
  221. }
  222. /// <summary>
  223. /// 检验puf条件
  224. /// </summary>
  225. /// <returns></returns>
  226. private bool CheckDupufCondition()
  227. {
  228. if (ModuleHelper.IsInstalled(ModuleName.PUF1))
  229. {
  230. if (!_puf1VerticalAxis.IsHomed)
  231. {
  232. LOG.WriteLog(eEvent.ERR_LOADER, Module.ToString(), "Puf1 Vertical is not homed");
  233. return false;
  234. }
  235. JetAxisBase puf1VerticalAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF1}.Vertical");
  236. double puf1VerticalPosition = puf1VerticalAxis.MotionData.MotorPosition;
  237. if (!puf1VerticalAxis.CheckPositionIsInStation(puf1VerticalPosition, "Park"))
  238. {
  239. LOG.Write(eEvent.ERR_LOADER, Module, $"PUF1 Vertical {puf1VerticalPosition} is not in Park station,Cannot execute GotoSavedPosition");
  240. return false;
  241. }
  242. }
  243. if (ModuleHelper.IsInstalled(ModuleName.PUF2))
  244. {
  245. if (!_puf2VerticalAxis.IsHomed)
  246. {
  247. LOG.WriteLog(eEvent.ERR_LOADER, Module.ToString(), "Puf2 Vertical is not homed");
  248. return false;
  249. }
  250. JetAxisBase puf2VerticalAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF2}.Vertical");
  251. double puf2VerticalPosition = puf2VerticalAxis.MotionData.MotorPosition;
  252. if (!puf2VerticalAxis.CheckPositionIsInStation(puf2VerticalPosition, "Park") &&
  253. !puf2VerticalAxis.CheckPositionIsInStation(puf2VerticalPosition, "Robot"))
  254. {
  255. LOG.Write(eEvent.ERR_LOADER, Module, $"PUF2 Vertical {puf2VerticalPosition} is not in Park and Robot station,Cannot execute GotoSavedPosition");
  256. return false;
  257. }
  258. if (!_puf2RotationAxis.IsHomed)
  259. {
  260. LOG.WriteLog(eEvent.ERR_LOADER, Module.ToString(), "Puf2 Rotation is not homed");
  261. return false;
  262. }
  263. JetAxisBase puf2RotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF2}.Rotation");
  264. double puf2RotationPosition = puf2RotationAxis.MotionData.MotorPosition;
  265. if (!puf2RotationAxis.CheckPositionIsInStation(puf2RotationPosition, "Park") &&
  266. !puf2RotationAxis.CheckPositionIsInStation(puf2RotationPosition, "Robot"))
  267. {
  268. LOG.Write(eEvent.ERR_LOADER, Module, $"PUF2 Rotation {puf2RotationPosition} is not in Park and Robot station,Cannot execute GotoSavedPosition");
  269. return false;
  270. }
  271. }
  272. return true;
  273. }
  274. public RState Start(params object[] objs)
  275. {
  276. _sideADevice = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.SideA");
  277. _sideBDevice = DEVICE.GetDevice<LoaderSideDevice>($"{Module}.SideB");
  278. _puf1VerticalAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF1}.Vertical");
  279. _puf2VerticalAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF2}.Vertical");
  280. _puf2RotationAxis = DEVICE.GetDevice<JetAxisBase>($"{ModuleName.PUF2}.Rotation");
  281. _isExecuteSideAUnlock = false;
  282. _isExecuteSideBUnlock = false;
  283. if(!CheckPreCondition())
  284. {
  285. return RState.Failed;
  286. }
  287. Runner.Start(Module, "Home All");
  288. return RState.Running;
  289. }
  290. /// <summary>
  291. /// 检验前置条件
  292. /// </summary>
  293. /// <returns></returns>
  294. private bool CheckPreCondition()
  295. {
  296. //if(_sideADevice.SideData.WaferPresent)
  297. //{
  298. // LOG.WriteLog(eEvent.ERR_AXIS, Module.ToString(), "Side A wafer present,cannot home");
  299. // return false;
  300. //}
  301. //if (_sideBDevice.SideData.WaferPresent)
  302. //{
  303. // LOG.WriteLog(eEvent.ERR_AXIS, Module.ToString(), "Side B wafer present,cannot home");
  304. // return false;
  305. //}
  306. return true;
  307. }
  308. }
  309. }