SEMFPickRoutine.cs 12 KB

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