WaferRobotMap.cs 19 KB

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