WaferRobotMap.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Util;
  6. using Aitex.Sorter.Common;
  7. using MECF.Framework.Common.Device.Bases;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.Schedulers;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using FurnaceRT.Equipments.PMs;
  18. using FurnaceRT.Equipments.FIMSs;
  19. using FurnaceRT.Equipments.Systems;
  20. using static FurnaceRT.Equipments.FIMSs.FIMSModule;
  21. using Aitex.Core.Common;
  22. using System.Text.RegularExpressions;
  23. using Aitex.Core.RT.Device.Unit;
  24. namespace FurnaceRT.Equipments.WaferRobots
  25. {
  26. public class WaferRobotMap : ModuleRoutine, IRoutine
  27. {
  28. enum RoutineStep
  29. {
  30. Map,
  31. CheckBeforeMap,
  32. CheckAfterMap,
  33. CheckMappingFinish,
  34. Delay,
  35. CheckRobotIsReady,
  36. }
  37. private ModuleName _mapFIMS;
  38. private int _slotNumber;
  39. private string _slotMap;
  40. private bool _isCompareWithSlotMap;
  41. private bool _isCreateWafer;
  42. private Hand _blade;
  43. private WaferRobotModule _waferRobotModule;
  44. private int _timeout = 0;
  45. private int _timeout2 = 10;
  46. private RD_TRIG _holdTrig = new RD_TRIG();
  47. private R_TRIG _emergencyStopTrig = new R_TRIG();
  48. private R_TRIG _pauseTrig = new R_TRIG();
  49. private R_TRIG _resumeTrig = new R_TRIG();
  50. private RoutineStep _routineStep;
  51. private double _durationTime = 0;
  52. private bool _isHasAlarm = false;
  53. private bool _needStartCheck = true;
  54. public WaferRobotMap(WaferRobotModule waferRobotModule)
  55. {
  56. _waferRobotModule = waferRobotModule;
  57. Module = waferRobotModule.Module;
  58. Name = "Map";
  59. }
  60. public void Init(ModuleName mapFIMS, int slotNumber, Hand blade, string slotMap, bool isCompareWithSlotMap, bool isCreateWafer, bool isHasAlarm)
  61. {
  62. _mapFIMS = mapFIMS;
  63. _slotNumber = slotNumber;
  64. _blade = blade;
  65. _slotMap = slotMap;
  66. _isCompareWithSlotMap = isCompareWithSlotMap;
  67. _isCreateWafer = isCreateWafer;
  68. var para = new List<object> { _mapFIMS, _slotNumber, _blade, slotMap, isCompareWithSlotMap, isCreateWafer, true };//增加参数true,表示执行过程中有alarm
  69. _waferRobotModule.MapFailAlarm.RetryMessage = (int)WaferRobotModule.MSG.MapRetry;
  70. _waferRobotModule.MapFailAlarm.RetryMessageParas = para.ToArray();
  71. _waferRobotModule.MapTimeoutAlarm.RetryMessage = (int)WaferRobotModule.MSG.MapRetry;
  72. _waferRobotModule.MapTimeoutAlarm.RetryMessageParas = para.ToArray();
  73. _isHasAlarm = isHasAlarm;
  74. if (!_isHasAlarm)
  75. _needStartCheck = true;
  76. }
  77. public Result Start(params object[] objs)
  78. {
  79. // 抛出过alarm就不reset
  80. if (!_isHasAlarm)
  81. {
  82. Reset();
  83. }
  84. else
  85. {
  86. _historySteps.Remove((int)_routineStep);
  87. _isHasAlarm = false;
  88. ResetState();
  89. }
  90. _holdTrig.RST = true;
  91. _emergencyStopTrig.RST = true;
  92. _pauseTrig.RST = true;
  93. _resumeTrig.RST = true;
  94. _timeout = SC.GetValue<int>($"{Module}.PickTimeout");
  95. if (_needStartCheck)
  96. {
  97. if (_mapFIMS == ModuleName.FIMS1 || _mapFIMS == ModuleName.FIMS2)
  98. {
  99. if (!Singleton<EquipmentManager>.Instance.Modules.ContainsKey(_mapFIMS))
  100. {
  101. _waferRobotModule.PickWaferFailAlarm.Set($"{_mapFIMS} is not install");
  102. return Result.FAIL;
  103. }
  104. if (!CarrierManager.Instance.CheckHasCarrier(_mapFIMS, 0))
  105. {
  106. _waferRobotModule.MapFailAlarm.Set($"no carrier at {_mapFIMS}");
  107. return Result.FAIL;
  108. }
  109. var fims = Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as FIMSModule;
  110. if (fims != null && !fims.CheckReadyForTransfer(ModuleHelper.Converter(Module), _blade, 0, EnumTransferType.Map, out string reason))
  111. {
  112. _waferRobotModule.MapFailAlarm.Set(reason);
  113. return Result.FAIL;
  114. }
  115. if (fims != null && fims.IsWaferOnRobot)
  116. {
  117. _waferRobotModule.MapFailAlarm.Set($"The wafer on {Module} has shifted");
  118. }
  119. fims.IsMapping = true;
  120. }
  121. if (ModuleHelper.IsPm(_mapFIMS))
  122. {
  123. var pmModule = Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as PMModule;
  124. if (pmModule != null && !pmModule.CheckReadyForTransfer(ModuleHelper.Converter(_waferRobotModule.Module), _blade, 0, EnumTransferType.Map, out string reason))
  125. {
  126. _waferRobotModule.MapFailAlarm.Set(reason);
  127. return Result.FAIL;
  128. }
  129. }
  130. }
  131. Notify($"Start");
  132. return Result.RUN;
  133. }
  134. public void Abort()
  135. {
  136. if (_mapFIMS == ModuleName.FIMS1 || _mapFIMS == ModuleName.FIMS2)
  137. (Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as FIMSModule).IsMapping = false;
  138. _waferRobotModule.Stop();
  139. }
  140. public override Result Monitor()
  141. {
  142. try
  143. {
  144. CheckBeforeMap((int)RoutineStep.CheckBeforeMap, _mapFIMS, _blade);
  145. Map((int)RoutineStep.Map, _mapFIMS, _blade, _timeout);
  146. CheckMappingFinish((int)RoutineStep.CheckMappingFinish, _mapFIMS, _timeout2);
  147. CheckAfterMap((int)RoutineStep.CheckAfterMap, _mapFIMS, _slotNumber, _slotMap, _isCompareWithSlotMap, _isCreateWafer);
  148. CheckRobotIsReady((int)RoutineStep.CheckRobotIsReady, _timeout);
  149. if (SC.ContainsItem("System.AddRobotDelay") && SC.ContainsItem("System.RobotDelayTime") && SC.GetValue<bool>("System.AddRobotDelay"))
  150. Delay((int)RoutineStep.Delay, float.Parse(SC.GetStringValue("System.RobotDelayTime")));
  151. }
  152. catch (RoutineBreakException)
  153. {
  154. return Result.RUN;
  155. }
  156. catch (RoutineFaildException ex)
  157. {
  158. if (_mapFIMS == ModuleName.FIMS1 || _mapFIMS == ModuleName.FIMS2)
  159. (Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as FIMSModule).IsMapping = false;
  160. return Result.FAIL;
  161. }
  162. if (_mapFIMS == ModuleName.FIMS1 || _mapFIMS == ModuleName.FIMS2)
  163. (Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as FIMSModule).IsMapping = false;
  164. Notify("Finished");
  165. return Result.DONE;
  166. }
  167. private void CheckAfterMap(int id, ModuleName mapModule, int slotNumber, string slotMap, bool isCompareWithSlotMap, bool isCreateWafer)
  168. {
  169. Tuple<bool, Result> ret = Execute(id, () =>
  170. {
  171. Notify("Check after map condition");
  172. string reason = string.Empty;
  173. //_waferRobotModule.WaferRobotDevice.SlotMap = "1111111111111111111111111";
  174. if (SC.GetValue<bool>($"System.IsSimulatorMode"))
  175. _waferRobotModule.WaferRobotDevice.SlotMap = "1111111111111111111111111";
  176. int waferCount = _waferRobotModule.WaferRobotDevice.SlotMap.Length == 0 ? 0 : Regex.Matches(_waferRobotModule.WaferRobotDevice.SlotMap, "1").Count;
  177. //if (waferCount != slotNumber)
  178. //{
  179. // _waferRobotModule.MapFailAlarm.Set($"Mapping result {waferCount} unequal to input number {slotNumber}");
  180. // return false;
  181. //}
  182. if (isCompareWithSlotMap && string.IsNullOrEmpty(_waferRobotModule.WaferRobotDevice.SlotMap))
  183. {
  184. _waferRobotModule.MapFailAlarm.Set($"Mapping result is null");
  185. return false;
  186. }
  187. var carrier = CarrierManager.Instance.GetCarrier(mapModule, 0);
  188. if (carrier != null)
  189. {
  190. carrier.IsMapped = true;
  191. carrier.IsMapOK = true;
  192. }
  193. ModuleName originModule = ModuleName.System;
  194. WaferType waferType = WaferType.None;
  195. if (mapModule != ModuleName.PM1)
  196. {
  197. originModule = carrier.InternalModuleName;
  198. Enum.TryParse(carrier.CarrierType.ToString(), out waferType);
  199. }
  200. waferCount = 0;
  201. //"返回结果,格式:“MAP 1 0 D C 1 1” 1:单片,D:叠片 C:跨槽 0:无片"
  202. for (int i = 0; i < _waferRobotModule.WaferRobotDevice.SlotMap.Length; i++)
  203. {
  204. switch (_waferRobotModule.WaferRobotDevice.SlotMap[i])
  205. {
  206. case '1':
  207. if (isCreateWafer)
  208. {
  209. if (WaferManager.Instance.CheckHasWafer(mapModule, i))
  210. WaferManager.Instance.DeleteWafer(mapModule, i);
  211. WaferManager.Instance.CreateWafer(mapModule, i, originModule, i, WaferStatus.Normal, waferType);
  212. CarrierManager.Instance.UpdateWaferIn(originModule, 0, true);
  213. }
  214. waferCount++;
  215. break;
  216. case '0':
  217. if (isCreateWafer)
  218. {
  219. if (WaferManager.Instance.CheckHasWafer(mapModule, i))
  220. WaferManager.Instance.DeleteWafer(mapModule, i);
  221. }
  222. break;
  223. case 'D':
  224. if (isCreateWafer)
  225. {
  226. if (WaferManager.Instance.CheckHasWafer(mapModule, i))
  227. WaferManager.Instance.DeleteWafer(mapModule, i);
  228. WaferManager.Instance.CreateWafer(mapModule, i, originModule, i, WaferStatus.Double, waferType);
  229. CarrierManager.Instance.UpdateWaferIn(originModule, 0, true);
  230. }
  231. reason += $"slot={i + 1} double wafer\n";
  232. break;
  233. case 'C':
  234. if (isCreateWafer)
  235. {
  236. if (WaferManager.Instance.CheckHasWafer(mapModule, i))
  237. WaferManager.Instance.DeleteWafer(mapModule, i);
  238. WaferManager.Instance.CreateWafer(mapModule, i, originModule, i, WaferStatus.Crossed, waferType);
  239. CarrierManager.Instance.UpdateWaferIn(originModule, 0, true);
  240. }
  241. reason += $"slot={i + 1} crossed wafer\n";
  242. break;
  243. }
  244. }
  245. if (!string.IsNullOrEmpty(reason))
  246. {
  247. if (carrier != null)
  248. carrier.IsMapOK = false;
  249. _waferRobotModule.MapFailAlarm.Set(reason);
  250. return false;
  251. }
  252. //if (waferCount != slotNumber)
  253. //{
  254. // if (carrier != null)
  255. // carrier.IsMapOK = false;
  256. // _waferRobotModule.MapFailAlarm.Set($"mapping result wafer count={waferCount}, set wafer count={slotNumber}, not match");
  257. // return false;
  258. //}
  259. if (carrier != null)
  260. carrier.HasWaferIn = waferCount > 0;
  261. //if (isCompareWithSlotMap && slotMap != _waferRobotModule.WaferRobotDevice.SlotMap)
  262. //{
  263. // if (carrier != null)
  264. // carrier.IsMapOK = false;
  265. // _waferRobotModule.MapFailAlarm.Set($"mapping result slot map={_waferRobotModule.WaferRobotDevice.SlotMap}, set slot map={slotMap}, not match");
  266. // return false;
  267. //}
  268. return true;
  269. });
  270. if (ret.Item1)
  271. {
  272. if (ret.Item2 == Result.FAIL)
  273. {
  274. throw (new RoutineFaildException());
  275. }
  276. }
  277. _needStartCheck = false;
  278. }
  279. private void CheckBeforeMap(int id, ModuleName source, Hand blade)
  280. {
  281. Tuple<bool, Result> ret = Execute(id, () =>
  282. {
  283. Notify("Check map condition");
  284. string reason = string.Empty;
  285. if (_waferRobotModule.WaferRobotDevice.IsError)
  286. {
  287. _waferRobotModule.MapFailAlarm.Set($"pick from {source} failed for robot error, error code={_waferRobotModule.WaferRobotDevice.ErrorCode}");
  288. return false;
  289. }
  290. if (!_waferRobotModule.WaferRobotDevice.IsIdle)
  291. {
  292. _waferRobotModule.MapFailAlarm.Set($"pick from {source} failed for robot isn't Ready");
  293. return false;
  294. }
  295. if (source == ModuleName.FIMS1 || source == ModuleName.FIMS2)
  296. {
  297. var stage = Singleton<EquipmentManager>.Instance.Modules[source] as FIMSModule;
  298. if (stage == null && !stage.CheckReadyForTransfer(ModuleHelper.Converter(Module), _blade, 0, EnumTransferType.Map, out reason))
  299. {
  300. _waferRobotModule.MapFailAlarm.Set(reason);
  301. return false;
  302. }
  303. }
  304. if (ModuleHelper.IsPm(source))
  305. {
  306. var pmModule = Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as PMModule;
  307. if (pmModule != null && !pmModule.CheckReadyForTransfer(ModuleHelper.Converter(_waferRobotModule.Module), _blade, 0, EnumTransferType.Map, out reason))
  308. {
  309. _waferRobotModule.MapFailAlarm.Set(reason);
  310. return false;
  311. }
  312. }
  313. return true;
  314. });
  315. if (ret.Item1)
  316. {
  317. if (ret.Item2 == Result.FAIL)
  318. {
  319. throw (new RoutineFaildException());
  320. }
  321. }
  322. _needStartCheck = false;
  323. }
  324. private void Map(int id, ModuleName source, Hand hand, int timeout)
  325. {
  326. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  327. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  328. {
  329. Notify("Map");
  330. string reason;
  331. if (!_waferRobotModule.RobotMap(source, hand, out reason))
  332. {
  333. _waferRobotModule.MapFailAlarm.Set(reason);
  334. return false;
  335. }
  336. return true;
  337. }, () =>
  338. {
  339. if (_waferRobotModule.WaferRobotDevice.IsReady() && !_waferRobotModule.WaferRobotDevice.IsError)
  340. {
  341. return true;
  342. }
  343. return false;
  344. }, timeout * 1000);
  345. if (ret.Item1)
  346. {
  347. if (ret.Item2 == Result.FAIL)
  348. {
  349. //_waferRobotModule.MapFailAlarm.Description = $"{_waferRobotModule.WaferRobotDevice.ErrorCode}";
  350. _waferRobotModule.MapFailAlarm.Set($"mapping {source} failed for robot error, error code={_waferRobotModule.WaferRobotDevice.ErrorCode}");
  351. throw (new RoutineFaildException());
  352. }
  353. else if (ret.Item2 == Result.TIMEOUT) //timeout
  354. {
  355. //_waferRobotModule.PickWaferTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  356. _waferRobotModule.MapTimeoutAlarm.Set($"timeout over {timeout} seconds");
  357. throw (new RoutineFaildException());
  358. }
  359. else
  360. throw (new RoutineBreakException());
  361. }
  362. }
  363. private void CheckMappingFinish(int id, ModuleName source, int timeout)
  364. {
  365. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  366. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  367. {
  368. Notify("Check EX1/EX2 Home Position");
  369. return true;
  370. }, () =>
  371. {
  372. var sensor1 = DEVICE.GetDevice<IoSensor>($"PM1.SensorWaferRobotEX1AxisHomePosition");
  373. var sensor2 = DEVICE.GetDevice<IoSensor>($"PM1.SensorWaferRobotEX2AxisHomePosition");
  374. if (sensor1 != null && sensor1.Value && sensor2 != null && sensor2.Value)
  375. {
  376. return true;
  377. }
  378. return false;
  379. }, timeout * 1000);
  380. if (ret.Item1)
  381. {
  382. if (ret.Item2 == Result.FAIL)
  383. {
  384. throw (new RoutineFaildException());
  385. }
  386. else if (ret.Item2 == Result.TIMEOUT) //timeout
  387. {
  388. //_waferRobotModule.PickWaferTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  389. _waferRobotModule.MapTimeoutAlarm.Set($"check wafer robot EX1/EX2 home position timeout over {timeout} seconds");
  390. throw (new RoutineFaildException());
  391. }
  392. else
  393. throw (new RoutineBreakException());
  394. }
  395. }
  396. private void CheckRobotIsReady(int id, int timeout)
  397. {
  398. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  399. {
  400. return true;
  401. }, () =>
  402. {
  403. int count = 0;
  404. while (count < 3)
  405. {
  406. if (_waferRobotModule.WaferRobotDevice.IsReady() && !_waferRobotModule.WaferRobotDevice.IsError)
  407. count++;
  408. }
  409. if (count == 3)
  410. return true;
  411. return false;
  412. }, timeout * 1000);
  413. if (ret.Item1)
  414. {
  415. if (ret.Item2 == Result.FAIL)
  416. {
  417. throw (new RoutineFaildException());
  418. }
  419. else if (ret.Item2 == Result.TIMEOUT) //timeout
  420. {
  421. throw (new RoutineFaildException());
  422. }
  423. else
  424. throw (new RoutineBreakException());
  425. }
  426. }
  427. }
  428. }