VpwSimpleHomeRoutine.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.Routine;
  7. using MECF.Framework.Common.ToolLayout;
  8. using PunkHPX8_Core;
  9. using PunkHPX8_RT.Devices.AXIS;
  10. using PunkHPX8_RT.Devices.Facilities;
  11. using PunkHPX8_RT.Devices.VpwCell;
  12. using PunkHPX8_RT.Devices.VpwMain;
  13. using PunkHPX8_RT.Modules.VpwMain;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. namespace PunkHPX8_RT.Modules.VpwCelMain
  20. {
  21. public class VpwSimpleHomeRoutine : RoutineBase, IRoutine
  22. {
  23. private enum VpwSimpleHomeStep
  24. {
  25. CheckPreCondition,
  26. ChamberUp,
  27. HomeAllRotation,
  28. CheckAllRotationHome,
  29. ChamberDown,
  30. End
  31. }
  32. #region 常量
  33. #endregion
  34. #region 内部变量
  35. /// <summary>
  36. /// Cell device集合
  37. /// </summary>
  38. private List<VpwCellDevice> _vpwCellDevices = new List<VpwCellDevice>();
  39. /// <summary>
  40. /// Main Device
  41. /// </summary>
  42. private VpwMainDevice _mainDevice;
  43. /// <summary>
  44. /// 用于处理没有被dissable的vpwcell
  45. /// </summary>
  46. private List<VpwCellDevice> _cellLst = new List<VpwCellDevice>();
  47. /// <summary>
  48. /// vpw cell rotation列表
  49. /// </summary>
  50. private List<JetAxisBase> _rotationAxis = new List<JetAxisBase>();
  51. /// <summary>
  52. /// 检验chamber是否上升/下降到位
  53. /// </summary>
  54. private int _checkChamberUpDownTimes = 3;
  55. #endregion
  56. /// <summary>
  57. /// 构造函数
  58. /// </summary>
  59. /// <param name="module"></param>
  60. public VpwSimpleHomeRoutine(string module) : base(module)
  61. {
  62. }
  63. /// <summary>
  64. /// 中止
  65. /// </summary>
  66. public void Abort()
  67. {
  68. Runner.Stop("Vpw Simple Home abort");
  69. }
  70. /// <summary>
  71. /// 监控
  72. /// </summary>
  73. /// <returns></returns>
  74. public RState Monitor()
  75. {
  76. Runner.Run(VpwSimpleHomeStep.CheckPreCondition, CheckPreCondition, _delay_1ms)
  77. .Run(VpwSimpleHomeStep.ChamberUp, _mainDevice.ChamberUp, CheckChamberClosed, _checkChamberUpDownTimes*1000)
  78. .Run(VpwSimpleHomeStep.HomeAllRotation, HomeAllRotation,_delay_1s)
  79. .WaitWithStopCondition(VpwSimpleHomeStep.CheckAllRotationHome, CheckAllRotationHomed, CheckRotationHomeFailed)
  80. .Run(VpwSimpleHomeStep.ChamberDown, _mainDevice.ChamberDown, CheckChamberOpened, _checkChamberUpDownTimes*1000)
  81. .End(VpwSimpleHomeStep.End, NullFun, _delay_1ms);
  82. return Runner.Status;
  83. }
  84. private bool CheckPreCondition()
  85. {
  86. //SystemFacilities systemFacility = DEVICE.GetDevice<SystemFacilities>("System.Facilities");
  87. //if (systemFacility == null)
  88. //{
  89. // LOG.WriteLog(eEvent.ERR_VPW, Module, "Facility is null");
  90. // return false;
  91. //}
  92. return true;
  93. }
  94. private bool HomeAllRotation()
  95. {
  96. bool result = true;
  97. foreach (var axis in _rotationAxis)
  98. {
  99. result &= axis.Home();
  100. if (result == false)
  101. {
  102. return result;
  103. }
  104. }
  105. return result;
  106. }
  107. private bool CheckAllRotationHomed()
  108. {
  109. bool result = true;
  110. foreach (var axis in _rotationAxis)
  111. {
  112. bool condition = axis.IsHomed && axis.Status == RState.End;
  113. result &= condition;
  114. }
  115. return result;
  116. }
  117. private bool CheckRotationHomeFailed()
  118. {
  119. bool result = false;
  120. foreach (var axis in _rotationAxis)
  121. {
  122. bool condition = axis.Status == RState.Failed;
  123. result |= condition;
  124. }
  125. return result;
  126. }
  127. /// <summary>
  128. /// 检验Chamber关闭
  129. /// </summary>
  130. /// <returns></returns>
  131. private bool CheckChamberClosed()
  132. {
  133. return _mainDevice.CommonData.ChamberClosed && !_mainDevice.CommonData.ChamberOpened;
  134. }
  135. /// <summary>
  136. /// 检验Chamber打开
  137. /// </summary>
  138. /// <returns></returns>
  139. private bool CheckChamberOpened()
  140. {
  141. return !_mainDevice.CommonData.ChamberClosed && _mainDevice.CommonData.ChamberOpened;
  142. }
  143. /// <summary>
  144. /// 启动
  145. /// </summary>
  146. /// <param name="objs"></param>
  147. /// <returns></returns>
  148. public RState Start(params object[] objs)
  149. {
  150. _rotationAxis.Clear();
  151. _vpwCellDevices.Clear();
  152. _cellLst.Clear();
  153. VpwMainItem vpwMainItem = VpwMainItemManager.Instance.GetItem(Module.ToString());
  154. if (vpwMainItem == null || vpwMainItem.VpwCells == null)
  155. {
  156. return RState.Failed;
  157. }
  158. foreach (var item in vpwMainItem.VpwCells)
  159. {
  160. VpwCellDevice cellDevice = DEVICE.GetDevice<VpwCellDevice>(item.ModuleName);
  161. _vpwCellDevices.Add(cellDevice);
  162. }
  163. foreach (var device in _vpwCellDevices)
  164. {
  165. VpwCellEntity vpwCellEntity = Singleton<RouteManager>.Instance.GetModule<VpwCellEntity>(device.Module);
  166. if (vpwCellEntity.IsAuto || vpwCellEntity.IsManual)
  167. {
  168. _cellLst.Add(device);
  169. JetAxisBase axis = DEVICE.GetDevice<JetAxisBase>($"{device.Module}.Rotation");
  170. _rotationAxis.Add(axis);
  171. }
  172. }
  173. _mainDevice = DEVICE.GetDevice<VpwMainDevice>(Module.ToString());
  174. _checkChamberUpDownTimes = SC.GetValue<int>("VPWMain.ChamberUpDownCheckTime");
  175. return Runner.Start(Module, "VPW Simple Home");
  176. }
  177. }
  178. }