PlaceExtendRoutine.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Device.Unit;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using Aitex.Sorter.Common;
  8. using athosRT.Devices;
  9. using athosRT.Devices.PA;
  10. using athosRT.FSM;
  11. using athosRT.Modules.EFEMs.Tasks;
  12. using athosRT.Modules.LPs;
  13. using athosRT.tool;
  14. using MECF.Framework.Common.Equipment;
  15. using MECF.Framework.Common.SubstrateTrackings;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  17. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  18. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  19. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  20. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  21. using System;
  22. using System.Collections.Generic;
  23. using System.Linq;
  24. using System.Numerics;
  25. using System.Text;
  26. using System.Threading.Tasks;
  27. using static MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase.RobotBaseDevice;
  28. namespace athosRT.Modules.EFEMs.Routine
  29. {
  30. public class PlaceExtendRoutine : ModuleRoutineBase, FSM.IRoutine
  31. {
  32. protected bool MultiWaferSize = Singleton<DeviceDefineManager>.Instance.GetValue<bool>(nameof(MultiWaferSize)).GetValueOrDefault();
  33. private SCConfigItem _scPlaceTimeout => SC.GetConfigItem("Robot.TimeLimitForPlaceWafer");
  34. private int _timeout = 0;
  35. private int _axisTimeout = 0;
  36. private int _axisSpeed = 0;
  37. public LoadPort _lpDevice;
  38. protected readonly bool HaveMotionAxis = Singleton<DeviceDefineManager>.Instance.GetValue<bool>("MotionAxisInstalled").GetValueOrDefault();
  39. public ModuleName Station { get; set; }
  40. protected bool NeedRobotGripAndUngrip => SC.GetValue<bool>("System.EnableRobotGripAndUngrip");
  41. private int _existInterval => SC.GetValue<int>("Robot.Robot.ExistInterval");
  42. public int Slot { get; set; }
  43. public Hand Blade { get; set; }
  44. public MpntTaskEnum TaskEnum { get; set; }
  45. protected Aligner aligner = null;
  46. RobotGoto robotgoto;
  47. WaitRobotMotion waitrobotmotion;
  48. UnGripRobotBlade UnGripRobotBlade;
  49. RobotBaseDevice robot;
  50. public PlaceExtendRoutine(
  51. ModuleName module
  52. ) : base(module)
  53. {
  54. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  55. if (HaveMotionAxis)
  56. {
  57. _axisTimeout = SC.GetValue<int>("MotionAxis.MoveTimeout");
  58. _axisSpeed = SC.GetValue<int>("MotionAxis.AutoSpeed");
  59. }
  60. aligner = DEVICE.GetDevice<Aligner>("Aligner");
  61. }
  62. public void Abort()
  63. {
  64. }
  65. public RState Monitor()
  66. {
  67. switch (TaskEnum)
  68. {
  69. case MpntTaskEnum.P1:
  70. Runner
  71. .Run(PlaceExtendStep.CheckBeforePlace, CheckBeforePlace, fWaitRobotMotion, _timeout)
  72. .End(PlaceExtendStep.RobotGoto, fRobotGoto, fWaitRobotMotion, _timeout);
  73. break;
  74. case MpntTaskEnum.PB:
  75. Runner
  76. .Run(PlaceExtendStep.CheckBladeWaferIsExist,CheckBladeWaferIsExist, fWaitRobotMotion, _timeout)
  77. .Run(PlaceExtendStep.CheckBeforePlace,NullFun,CheckBeforePlace,_timeout)
  78. .Run(PlaceExtendStep.RobotGoto,fRobotGoto, fWaitRobotMotion, _timeout)
  79. .End(PlaceExtendStep.UnGripRobotBlade, fUnGripRobotBlade, fWaitRobotMotion, _timeout);
  80. break;
  81. case MpntTaskEnum.P4:
  82. Runner
  83. .Run(PlaceExtendStep.RobotGoto, fRobotGotoPlaceRetract, fWaitRobotMotion, _timeout)
  84. .Run(PlaceExtendStep.CheckBladeWaferIsExist,CheckBladeWaferIsExist, fWaitRobotMotion, _timeout)
  85. .End(PlaceExtendStep.CheckAfterPlace, NullFun, CheckAfterPlace,_timeout);
  86. break;
  87. }
  88. return Runner.Status;
  89. }
  90. private bool fUnGripRobotBlade()
  91. {
  92. if (NeedRobotGripAndUngrip)
  93. {
  94. if (robot.Release((RobotArmEnum)Blade))
  95. {
  96. LogObject.Info("Robot","Release wafer");
  97. return true;
  98. }
  99. else
  100. {
  101. LogObject.Error("Robot", "Cannot release wafer");
  102. return false;
  103. }
  104. }
  105. return true;
  106. }
  107. private bool CheckAfterPlace()
  108. {
  109. switch (Blade)
  110. {
  111. case Hand.Blade1:
  112. if (!CheckSensorNoWafer(ModuleName.Robot, (int)Blade))
  113. {
  114. //EV.PostMessage<EventEnum>(ModuleName.System.ToString(), EventEnum.WaferDetectedAfterSend);
  115. return false;
  116. }
  117. break;
  118. case Hand.Blade2:
  119. for (int index = 0; index < robot.Blade2Slots; ++index)
  120. {
  121. if (!CheckSensorNoWafer(ModuleName.Robot, (int)(Blade + index)))
  122. {
  123. //EV.PostMessage<EventEnum>(ModuleName.System.ToString(), EventEnum.WaferDetectedAfterSend);
  124. return false;
  125. }
  126. }
  127. break;
  128. default:
  129. for (int slot1 = 0; slot1 < robot.Blade2Slots + 1; ++slot1)
  130. {
  131. if (!CheckSensorNoWafer(ModuleName.Robot, slot1))
  132. {
  133. //EV.PostMessage<EventEnum>(ModuleName.System.ToString(), EventEnum.WaferDetectedAfterSend);
  134. return false;
  135. }
  136. }
  137. break;
  138. }
  139. return true;
  140. }
  141. private bool CheckBladeWaferIsExist()
  142. {
  143. //this.robot, this.Blade, this._timeout
  144. if (!robot.ReadParameter(new object[3] { "CheckWaferIsPresence", (Blade == Hand.Blade1 ? 0 : 1), _existInterval }))
  145. {
  146. //手臂上有wafer 无法pick
  147. return false;
  148. }
  149. return true;
  150. }
  151. private bool fWaitRobotMotion()
  152. {
  153. if (robot.IsReady())
  154. {
  155. LogObject.Info("robot","is ready");
  156. return true;
  157. }
  158. else
  159. {
  160. //LogObject.Error("robot", "is not ready");
  161. return false;
  162. }
  163. }
  164. private bool CheckBeforePlace()
  165. {
  166. //this.Station, this.Slot, this.Blade
  167. if (!CheckRobotMotionInterlock(Station, Slot, out _))
  168. {
  169. return false;
  170. }
  171. switch (Blade)
  172. {
  173. case Hand.Blade1 :
  174. if (!Singleton<WaferManager>.Instance.CheckWafer(Station, Slot, WaferStatus.Empty))
  175. {
  176. return false;
  177. }
  178. if (!Singleton<WaferManager>.Instance.CheckWafer(ModuleName.Robot, (int)Blade, WaferStatus.Normal))
  179. {
  180. //EV.PostMessage<EventEnum>(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  181. return false;
  182. }
  183. if (!CheckSeneorHasWafer(ModuleName.Robot, (int)Blade))
  184. {
  185. //EV.PostMessage<EventEnum>(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  186. return false;
  187. }
  188. break;
  189. default:
  190. case Hand.Blade2 :
  191. bool flag1 = true;
  192. for (int index = 0; index < robot.Blade2Slots; ++index)
  193. {
  194. if (!Singleton<WaferManager>.Instance.CheckWafer(Station, Slot + index, WaferStatus.Empty))
  195. {
  196. //EV.PostMessage<EventEnum>(ModuleName.System.ToString(), EventEnum.WaferPresentWithRecord, (object)string.Format("Target {0}{1:D2}", (object)chamber.ToString(), (object)(slot + index + 1)));
  197. return false;
  198. }
  199. flag1 &= Singleton<WaferManager>.Instance.CheckWafer(ModuleName.Robot, (int)(Blade + index), WaferStatus.Normal);
  200. if (!CheckSeneorHasWafer(ModuleName.Robot, (int)(Blade + index)))
  201. {
  202. //EV.PostMessage<EventEnum>(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  203. return false;
  204. }
  205. }
  206. if (!flag1)
  207. {
  208. //EV.PostMessage<EventEnum>(ModuleName.System.ToString(), EventEnum.WaferNotDetectedBeforeSend);
  209. return false;
  210. }
  211. break;
  212. }
  213. if (ModuleHelper.IsCoolingBuffer(Station))
  214. {
  215. if (!DEVICE.GetDevice<IoCoolingBuffer>(Station.ToString()).CheckPinUp())
  216. {
  217. //EV.PostWarningLog(chamber.ToString(), "Can not place wafer to buffer, buffer isn't pick position.");
  218. return false;
  219. }
  220. }
  221. else if (ModuleHelper.IsLoadPort(Station) && this.MultiWaferSize && Singleton<WaferManager>.Instance.GetWaferSize(ModuleName.Robot, 0) != DEVICE.GetDevice<OpenStageWithWaferSizeLoadPort>(Station.ToString()).Size)
  222. {
  223. //EV.PostWarningLog(chamber.ToString(), "Can not place wafer to loadport, size is unmatch.");
  224. return false;
  225. }
  226. return true;
  227. }
  228. private bool fRobotGotoPlaceRetract()
  229. {
  230. bool flag = robot.GoTo(new object[4]
  231. {
  232. (RobotArmEnum)Blade,
  233. Station,
  234. Slot,
  235. RobotPostionEnum.PlaceRetract
  236. });
  237. if (flag)
  238. {
  239. LogObject.Info("Robot", "RobotGotoPlaceRetract成功");
  240. return true;
  241. }
  242. else
  243. {
  244. LogObject.Error("Robot", "RobotGotoPlaceRetract失败");
  245. return false;
  246. }
  247. }
  248. private bool fRobotGoto()
  249. {
  250. bool flag = robot.GoTo(new object[4]
  251. {
  252. (RobotArmEnum) Blade,
  253. Station,
  254. Slot,
  255. RobotPostionEnum.PlaceExtend
  256. });
  257. if (flag)
  258. {
  259. LogObject.Info("Robot", "RobotGoto成功");
  260. return true;
  261. }
  262. else
  263. {
  264. LogObject.Error("Robot", "RobotGoto失败");
  265. return false;
  266. }
  267. }
  268. public RState Start(params object[] objs)
  269. {
  270. Reset();
  271. _timeout = _scPlaceTimeout.IntValue * 1000;
  272. if (!ModuleHelper.IsLoadLock(Station) || TaskEnum == MpntTaskEnum.ParamNg)
  273. {
  274. return RState.Failed;
  275. }
  276. else
  277. {
  278. return Runner.Start(ModuleName.System, "PlaceExtendRoutine");
  279. }
  280. }
  281. protected bool CheckSensorNoWafer(ModuleName chamber, int slot)
  282. {
  283. if (SC.GetValue<bool>("System.IsSimulatorMode") || chamber != ModuleName.Robot)
  284. return Singleton<WaferManager>.Instance.CheckNoWafer(chamber, slot);
  285. return slot == 0 ? !this.robot.IsWaferPresenceOnBlade1 : !this.robot.IsWaferPresenceOnBlade2;
  286. }
  287. protected bool CheckRobotMotionInterlock(ModuleName chamber, int slot, out string reason)
  288. {
  289. reason = string.Empty;
  290. if (robot.RobotState == RobotStateEnum.Error)
  291. {
  292. reason = "robot is error.";
  293. return false;
  294. }
  295. if (!robot.IsReady())
  296. {
  297. reason = string.Format("robot isn't Ready.");
  298. return false;
  299. }
  300. if (chamber == ModuleName.Aligner)
  301. {
  302. if (aligner.Moving)
  303. {
  304. reason = string.Format("aligner is moving.");
  305. return false;
  306. }
  307. if (robot.IsReady())
  308. return true;
  309. reason = string.Format("aligner isn't Ready.");
  310. return false;
  311. }
  312. if (ModuleHelper.IsLoadPort(chamber))
  313. {
  314. LoadPortBaseDevice device = DEVICE.GetDevice<LoadPortBaseDevice>(chamber.ToString());
  315. if (!device.IsEnableTransferWafer(out reason))
  316. {
  317. reason = string.Format($"{chamber} isn't Ready.The reason is {reason}");
  318. return false;
  319. }
  320. if (device.MapError)
  321. {
  322. reason = string.Format("{0} Map has crossed error.", (object)chamber.ToString());
  323. return false;
  324. }
  325. if (chamber.Equals(ModuleName.LP1))
  326. {
  327. if (!DeviceModel.SensorSMIF1PODOPEN.Value)
  328. {
  329. reason = string.Format("{0} SMIF1PODOPEN signal is Off.", (object)chamber.ToString());
  330. return false;
  331. }
  332. if (!DeviceModel.SensorSMIF1PODPRESENT.Value)
  333. {
  334. reason = string.Format("{0} SensorSMIF1PODPRESENT signal is Off,Foup is presence.", (object)chamber.ToString());
  335. return false;
  336. }
  337. if (!DeviceModel.SensorSMIF1READY.Value)
  338. {
  339. reason = string.Format("{0} SensorSMIF1READY signal is Off.", (object)chamber.ToString());
  340. return false;
  341. }
  342. }
  343. else if (chamber.Equals(ModuleName.LP2))
  344. {
  345. if (!DeviceModel.SensorSMIF2PODOPEN.Value)
  346. {
  347. reason = string.Format("{0} SMIF2PODOPEN signal is Off.", (object)chamber.ToString());
  348. return false;
  349. }
  350. if (!DeviceModel.SensorSMIF2PODPRESENT.Value)
  351. {
  352. reason = string.Format("{0} SensorSMIF2PODPRESENT signal is Off,Foup is not presence .", (object)chamber.ToString());
  353. return false;
  354. }
  355. if (!DeviceModel.SensorSMIF2READY.Value)
  356. {
  357. reason = string.Format("{0} SensorSMIF2READY signal is Off.", (object)chamber.ToString());
  358. return false;
  359. }
  360. }
  361. return true;
  362. }
  363. if (ModuleHelper.IsLoadLock(chamber))
  364. return DEVICE.GetDevice<LoadLockDevice>(chamber.ToString()).IsEnableTransferWafer(out reason);
  365. if (ModuleHelper.IsCoolingBuffer(chamber))
  366. {
  367. IoCoolingBuffer device = DEVICE.GetDevice<IoCoolingBuffer>(chamber.ToString());
  368. if (device.Busy)
  369. {
  370. reason = "buffer is not idle";
  371. return false;
  372. }
  373. if (device.CheckPinUp())
  374. return true;
  375. reason = "buffer pin not up position";
  376. return false;
  377. }
  378. if (ModuleHelper.IsAligner(chamber))
  379. {
  380. PreAligner device = DEVICE.GetDevice<PreAligner>(chamber.ToString());
  381. if (device.Busy)
  382. {
  383. reason = "Aligner is not Idle";
  384. return false;
  385. }
  386. return true;
  387. }
  388. reason = "error target";
  389. return false;
  390. }
  391. protected bool CheckSeneorHasWafer(ModuleName chamber, int slot)
  392. {
  393. if (SC.GetValue<bool>("System.IsSimulatorMode") || chamber != ModuleName.Robot)
  394. return Singleton<WaferManager>.Instance.CheckHasWafer(chamber, slot);
  395. return slot == 0 ? this.robot.IsWaferPresenceOnBlade1 : this.robot.IsWaferPresenceOnBlade2;
  396. }
  397. public enum PlaceExtendStep
  398. {
  399. CheckBladeWaferIsExist,
  400. CheckBeforePlace,
  401. RobotGoto,
  402. WaitRobotMotion,
  403. UnGripRobotBlade,
  404. CheckAfterPlace,
  405. WaitRobotReady,
  406. CheckRobotNoBusy
  407. }
  408. }
  409. }