PufDistanceSensor.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.OperationCenter;
  5. using Aitex.Core.RT.SCCore;
  6. using MECF.Framework.Common.Beckhoff.AxisProvider;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.TwinCat;
  9. using MECF.Framework.RT.Core.Equipments;
  10. using CyberX8_RT.Devices.AXIS;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using MECF.Framework.Common.IOCore;
  17. namespace CyberX8_RT.Devices.PUF
  18. {
  19. public class PufDistanceSensor : BaseDevice, IDevice
  20. {
  21. #region 常量
  22. private const string STUCK_WAFER_200_DISTANCE_OFFSET1 = "CheckStuckWafer200_DistanceOffset1";
  23. private const string STUCK_WAFER_200_DISTANCE_OFFSET2 = "CheckStuckWafer200_DistanceOffset2";
  24. private const string STUCK_WAFER_200_TORQUE_LIMIT = "CheckStuckWafer200_TorqueLimit_Percent";
  25. private const string DISTANCE_SENSOR1="DistanceSensor1";
  26. private const string DISTANCE_SENSOR2 = "DistanceSensor2";
  27. private const string DISTANCE_OFFSET1 = "DistanceOffset1";
  28. private const string DISTANCE_OFFSET2 = "DistanceOffset2";
  29. private const double STANDARD = 100;
  30. #endregion
  31. #region 内部变量
  32. //动态变量主要是用于calibrate显示
  33. private double _dynamicOffset1 = 0;
  34. private double _dynamicOffset2 = 0;
  35. //执行过程中主要用于以下两个变量
  36. private double _offset1 = 0;
  37. private double _offset2 = 0;
  38. /// <summary>
  39. /// distance sensor1
  40. /// </summary>
  41. private double _distanceSensor1;
  42. /// <summary>
  43. /// distance sensor2
  44. /// </summary>
  45. private double _distanceSensor2;
  46. /// <summary>
  47. /// Distance sensor阈值
  48. /// </summary>
  49. private double _checkStuckWafer_DistanceSensorThreshold_mm;
  50. #endregion
  51. /// <summary>
  52. /// 构造函数
  53. /// </summary>
  54. /// <param name="moduleName"></param>
  55. public PufDistanceSensor(string moduleName): base(moduleName,"DistanceSensor", "DistanceSensor", "DistanceSensor")
  56. {
  57. LoadConfigParameter();
  58. _dynamicOffset1 = _offset1;
  59. _dynamicOffset2 = _offset2;
  60. }
  61. /// <summary>
  62. /// 初始化
  63. /// </summary>
  64. /// <returns></returns>
  65. public bool Initialize()
  66. {
  67. InitializeData();
  68. SubscribeValueAction();
  69. return true;
  70. }
  71. /// <summary>
  72. /// 订阅变量数值发生变化
  73. /// </summary>
  74. private void SubscribeValueAction()
  75. {
  76. IOModuleManager.Instance.SubscribeModuleVariable($"{Module}", DISTANCE_SENSOR1, UpdateVariableValue);
  77. IOModuleManager.Instance.SubscribeModuleVariable($"{Module}", DISTANCE_SENSOR2, UpdateVariableValue);
  78. }
  79. /// 更新变量数值
  80. /// </summary>
  81. /// <param name="variable"></param>
  82. /// <param name="value"></param>
  83. private void UpdateVariableValue(string variable, object value)
  84. {
  85. if (variable == $"{DISTANCE_SENSOR1}")
  86. {
  87. _distanceSensor1 = (double)value;
  88. }
  89. else if (variable == $"{DISTANCE_SENSOR2}")
  90. {
  91. _distanceSensor2 = (double)value;
  92. }
  93. }
  94. /// <summary>
  95. /// 初始化数据
  96. /// </summary>
  97. private void InitializeData()
  98. {
  99. DATA.Subscribe($"{Module}.{DISTANCE_OFFSET1}", () => _dynamicOffset1, Aitex.Core.Util.SubscriptionAttribute.FLAG.IgnoreSaveDB);
  100. DATA.Subscribe($"{Module}.{DISTANCE_OFFSET2}", () => _dynamicOffset2, Aitex.Core.Util.SubscriptionAttribute.FLAG.IgnoreSaveDB);
  101. DATA.Subscribe($"{Module}.{DISTANCE_SENSOR1}", () => _distanceSensor1, Aitex.Core.Util.SubscriptionAttribute.FLAG.IgnoreSaveDB);
  102. DATA.Subscribe($"{Module}.{DISTANCE_SENSOR2}", () => _distanceSensor2, Aitex.Core.Util.SubscriptionAttribute.FLAG.IgnoreSaveDB);
  103. }
  104. /// <summary>
  105. /// 保存参数
  106. /// </summary>
  107. /// <param name="offset1"></param>
  108. /// <param name="offset2"></param>
  109. public void SaveConfig(double offset1,double offset2)
  110. {
  111. _dynamicOffset1=offset1;
  112. _dynamicOffset2=offset2;
  113. SC.SetItemValue($"{Module}.{STUCK_WAFER_200_DISTANCE_OFFSET1}", offset1);
  114. SC.SetItemValue($"{Module}.{STUCK_WAFER_200_DISTANCE_OFFSET2}", offset2);
  115. }
  116. /// <summary>
  117. /// Stick Distance检验结果
  118. /// </summary>
  119. /// <returns></returns>
  120. public bool CheckStickDistanceStatus()
  121. {
  122. LoadConfigParameter();
  123. double inter1 = STANDARD - _distanceSensor1;
  124. double inter2=STANDARD - _distanceSensor2;
  125. double offsetInter1=Math.Abs(_offset1- inter1);
  126. double offsetInter2=Math.Abs(_offset2- inter2);
  127. if(offsetInter1>_checkStuckWafer_DistanceSensorThreshold_mm)
  128. {
  129. LOG.WriteLog(eEvent.ERR_PUF, Module, $"offset bias {offsetInter1} is over {_checkStuckWafer_DistanceSensorThreshold_mm}");
  130. return false;
  131. }
  132. if (offsetInter2 > _checkStuckWafer_DistanceSensorThreshold_mm)
  133. {
  134. LOG.WriteLog(eEvent.ERR_PUF, Module, $"offset bias {offsetInter2} is over {_checkStuckWafer_DistanceSensorThreshold_mm}");
  135. return false;
  136. }
  137. return true;
  138. }
  139. private void LoadConfigParameter()
  140. {
  141. _offset1 = SC.GetValue<double>($"{Module}.{STUCK_WAFER_200_DISTANCE_OFFSET1}");
  142. _offset2 = SC.GetValue<double>($"{Module}.{STUCK_WAFER_200_DISTANCE_OFFSET2}");
  143. if (SC.ContainsItem($"{Module}.CheckStuckWafer_DistanceSensorThreshold_mm"))
  144. {
  145. _checkStuckWafer_DistanceSensorThreshold_mm = SC.GetValue<double>($"{Module}.CheckStuckWafer_DistanceSensorThreshold_mm");
  146. }
  147. }
  148. public void Monitor()
  149. {
  150. }
  151. public void Reset()
  152. {
  153. }
  154. public void Terminate()
  155. {
  156. }
  157. }
  158. }