SEMFPickRoutine.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using Aitex.Sorter.Common;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Schedulers;
  8. using MECF.Framework.Common.SubstrateTrackings;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using Venus_Core;
  15. using Venus_RT.Devices;
  16. using Venus_RT.Devices.PreAligner;
  17. using Venus_RT.Modules.VCE;
  18. namespace Venus_RT.Modules.TM.VenusEntity
  19. {
  20. public class SEMFPickRoutine : ModuleRoutineBase, IRoutine
  21. {
  22. private enum PickStep
  23. {
  24. seWaitModuleReady,
  25. sePrepareModule,
  26. sePAQuery,
  27. sePicking,
  28. seNotifyDone,
  29. }
  30. private HongHuTM _tm;
  31. private IPreAlign _vpa;
  32. private ITransferRobot _robot;
  33. private VceEntity _vceModule;
  34. private ModuleName _targetModule;
  35. private int _targetSlot;
  36. private int _pickingTimeout;
  37. public int currentStepNo;
  38. Hand _hand;
  39. /// <summary>
  40. /// 完整pick动作仅可vce vpa取片
  41. /// </summary>
  42. /// <param name="tm"></param>
  43. /// <param name="robot"></param>
  44. /// <param name="vpa"></param>
  45. public SEMFPickRoutine(HongHuTM tm, ITransferRobot robot, IPreAlign vpa) : base(ModuleName.SETM)
  46. {
  47. _tm = tm;
  48. _robot = robot;
  49. _vpa = vpa;
  50. }
  51. public RState Start(params object[] objs)
  52. {
  53. if (!_robot.IsHomed)
  54. {
  55. LOG.Write(eEvent.ERR_TM, Module, $"TM Robot is not homed, please home it first");
  56. return RState.Failed;
  57. }
  58. //MoveItem pickItem = new MoveItem() { SourceModule = , };
  59. var pickItem = (Queue<MoveItem>)objs[0];
  60. _targetModule = pickItem.Peek().SourceModule;
  61. _targetSlot = pickItem.Peek().SourceSlot;
  62. _hand = pickItem.Peek().RobotHand;
  63. //如果目标是Vce 否则是vpa
  64. if (ModuleHelper.IsVCE(_targetModule) && ModuleHelper.IsInstalled(_targetModule))
  65. {
  66. _vceModule = Singleton<RouteManager>.Instance.GetVCE(_targetModule);
  67. //如果vce有错误 报错
  68. if (_vceModule.IsError)
  69. {
  70. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} is Error! Please solve Error first!");
  71. return RState.Failed;
  72. }
  73. if (_targetSlot < 0)
  74. {
  75. LOG.Write(eEvent.ERR_TM, Module, $"VCE target slot cannot be {_targetSlot}. Please check it first.");
  76. return RState.Failed;
  77. }
  78. if (_tm.VCESlitDoorClosed)
  79. {
  80. LOG.Write(eEvent.ERR_TM, Module, $"cannot pick cause vce slitdoor not open.");
  81. return RState.Failed;
  82. }
  83. //如果VCE门是关闭的 说明还未进行pump 无法取片等
  84. //if (_tm.VCESlitDoorClosed)
  85. //{
  86. // LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} slitdoor not open! Please pump down vce and open it first!");
  87. // return RState.Failed;
  88. //}
  89. }
  90. //如果目标又不是VPA 报错
  91. else if (!ModuleHelper.IsVPA(_targetModule))
  92. {
  93. LOG.Write(eEvent.ERR_TM, Module, $"Invalid target module : {_targetModule} for pick action");
  94. return RState.Failed;
  95. }
  96. //检查目标手臂上没有wafer
  97. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, (int)_hand))
  98. {
  99. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as TM Robot Arm: {_hand} already has a wafer");
  100. return RState.Failed;
  101. }
  102. //检查目标槽位上有wafer
  103. if (WaferManager.Instance.CheckNoWafer(_targetModule, _targetSlot))
  104. {
  105. LOG.Write(eEvent.ERR_TM, Module, $"Cannot pick as {_targetModule} Slot {_targetSlot + 1} has no wafer");
  106. return RState.Failed;
  107. }
  108. //2023/10/13 朱永吉 atm mode的判断不允许自动pump vent 信号不满足手动pump vent
  109. //if (RouteManager.IsATMMode && _targetModule == ModuleName.VCE1)
  110. //{
  111. // if (!_tm.IsVCEATM)
  112. // {
  113. // LOG.Write(eEvent.ERR_TM, Module, $"System in ATM Mode but VCE is not ATM!");
  114. // return RState.Failed;
  115. // }
  116. //
  117. // if (!_tm.IsTMATM)
  118. // {
  119. // LOG.Write(eEvent.ERR_TM, Module, $"System in ATM Mode but TM is not ATM!");
  120. // return RState.Failed;
  121. // }
  122. //}
  123. //else
  124. //{
  125. // if (_tm.IsVCEATM)
  126. // {
  127. // LOG.Write(eEvent.ERR_TM, Module, $"System not in ATM Mode but VCE is ATM!");
  128. // return RState.Failed;
  129. // }
  130. //
  131. // if (_tm.IsTMATM)
  132. // {
  133. // LOG.Write(eEvent.ERR_TM, Module, $"System not in ATM Mode but TM is ATM!");
  134. // return RState.Failed;
  135. // }
  136. //}
  137. Reset();
  138. _pickingTimeout = SC.GetValue<int>("SETM.PickTimeout") * 1000;
  139. return Runner.Start(Module, $"Pick from {_targetModule}");
  140. }
  141. public RState Monitor()
  142. {
  143. Runner.Wait(PickStep.seWaitModuleReady, CheckModuleReady, _delay_60s)
  144. .Run(PickStep.sePrepareModule, PrepareModule, CheckModuleReady)
  145. .RunIf(PickStep.sePAQuery, _targetModule == ModuleName.VPA, QueryOffset, VPAIsIdle, _pickingTimeout)
  146. .Run (PickStep.sePicking, Picking, WaitPickDone, _pickingTimeout)
  147. .End (PickStep.seNotifyDone, NullFun, 500);
  148. return Runner.Status;
  149. }
  150. private bool PrepareModule()
  151. {
  152. switch (_targetModule)
  153. {
  154. case ModuleName.VCE1:
  155. return _vceModule.CheckToPostMessage((int)VceMSG.Goto, _targetSlot);//移动到目标槽位
  156. case ModuleName.VPA:
  157. return true;//10/17暂时为true 后可能要求旋转到0
  158. default:
  159. return false;
  160. }
  161. }
  162. private bool WaitPickDone()
  163. {
  164. if (_robot.Status == RState.Running)
  165. {
  166. return false;
  167. }
  168. else if (_robot.Status == RState.End)
  169. {
  170. WaferManager.Instance.WaferMoved(_targetModule, _targetSlot, ModuleName.TMRobot, (int)_hand);
  171. return true;
  172. }
  173. else
  174. {
  175. Runner.Stop($"TM Robot Picking failed, {_robot.Status}");
  176. return true;
  177. }
  178. }
  179. private bool CheckIsPA() => _targetModule == ModuleName.VPA;
  180. private bool QueryOffset()
  181. {
  182. return _vpa.QueryOffset();
  183. }
  184. private bool VPAIsIdle()
  185. {
  186. if (_vpa.Status == RState.Running)
  187. {
  188. return false;
  189. }
  190. else if (_vpa.Status == RState.End)
  191. {
  192. return true;
  193. }
  194. else
  195. {
  196. Runner.Stop($"VPA Query Offset failed, {_vpa.Status}");
  197. return true;
  198. }
  199. }
  200. private bool WaitRobotIsIdle()
  201. {
  202. if (_robot.Status == RState.Running)
  203. {
  204. return false;
  205. }
  206. else if (_robot.Status == RState.End)
  207. {
  208. return true;
  209. }
  210. else
  211. {
  212. Runner.Stop($"TM Robot QueryOffset failed, {_robot.Status}");
  213. return true;
  214. }
  215. }
  216. private bool Picking()
  217. {
  218. //到达目标点位 pick固定槽位点的wafer
  219. if (_targetModule == ModuleName.VPA && (_vpa.ROffset!=0 || _vpa.TOffset!=0))
  220. {
  221. int[] RT = calculateRT(_vpa.ROffset, _vpa.TOffset);
  222. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"will pick from PA with R:{RT[1]} D:{RT[0]}");
  223. return _robot.PickWithOffset(_targetModule, 0, _hand, RT[1], RT[0]);
  224. }
  225. else
  226. return _robot.Pick(_targetModule, 0, _hand);
  227. }
  228. private int[] calculateRT(int OriginR,int OriginS)
  229. {
  230. int[] RT = new int[2];
  231. try
  232. {
  233. bool desflag = false;
  234. double angle = 0;
  235. if (OriginR / 10 < 90)
  236. angle = OriginR / 10;
  237. if (OriginR / 10 < 270 && OriginR / 10 > 90)
  238. {
  239. desflag = true;
  240. angle = OriginR / 10 - 90;
  241. }
  242. if (OriginR / 10 > 270)
  243. angle = 450 - OriginR / 10;
  244. double angleInRadians = angle * Math.PI / 180;
  245. //OriginS * 25.4 inch 转化为 mm
  246. double Robot2PA = OriginS * 25.4 / 10000;
  247. double Robot2Wafer = Math.Sqrt(Robot2PA * Robot2PA + 402.5 * 402.5 - 2 * Robot2PA * 402.5 * Math.Cos(angleInRadians));
  248. //距离(mm)
  249. double distance = Robot2Wafer - 402.5;
  250. //角度(度)
  251. double angleA = Math.Asin(Robot2PA * Math.Sin(angleInRadians) / Robot2Wafer) * 180 / Math.PI;
  252. if (desflag)
  253. angleA = -angleA;
  254. RT[0] = (int)(angleA * 1000);
  255. RT[1] = (int)(distance * 1000);
  256. }
  257. catch
  258. {
  259. LOG.Write(eEvent.ERR_TM_ROBOT,ModuleName.TMRobot,"错误纠偏计算");
  260. RT[0] = 0;
  261. RT[1] = 0;
  262. }
  263. return RT;
  264. }
  265. private bool CheckModuleReady()
  266. {
  267. switch (_targetModule)
  268. {
  269. case ModuleName.VCE1:
  270. return _vceModule.IsIdle;
  271. case ModuleName.VPA:
  272. return _vpa.Status == RState.End;
  273. default:
  274. return false;
  275. }
  276. }
  277. public void Abort()
  278. {
  279. _robot.Halt();
  280. }
  281. }
  282. }