WaferRobotMap.cs 18 KB

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