SEMFPickRoutine.cs 11 KB

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