SEMFPickRoutine.cs 12 KB

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