VpwSimpleHomeRoutine.cs 5.8 KB

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