WaferRobotMap.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. if (fims != null && fims.IsWaferOnRobot)
  114. {
  115. _waferRobotModule.MapFailAlarm.Set($"The wafer on {Module} has shifted");
  116. }
  117. fims.IsMapping = true;
  118. }
  119. if (ModuleHelper.IsPm(_mapFIMS))
  120. {
  121. var pmModule = Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as PMModule;
  122. if (pmModule != null && !pmModule.CheckReadyForTransfer(ModuleHelper.Converter(_waferRobotModule.Module), _blade, 0, EnumTransferType.Map, out string reason))
  123. {
  124. _waferRobotModule.MapFailAlarm.Set(reason);
  125. return Result.FAIL;
  126. }
  127. }
  128. }
  129. Notify($"Start");
  130. return Result.RUN;
  131. }
  132. public void Abort()
  133. {
  134. if (_mapFIMS == ModuleName.FIMS1 || _mapFIMS == ModuleName.FIMS2)
  135. (Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as FIMSModule).IsMapping = false;
  136. _waferRobotModule.Stop();
  137. }
  138. public override Result Monitor()
  139. {
  140. try
  141. {
  142. CheckBeforeMap((int)RoutineStep.CheckBeforeMap, _mapFIMS, _blade);
  143. Map((int)RoutineStep.Map, _mapFIMS, _blade, _timeout);
  144. CheckMappingFinish((int)RoutineStep.CheckMappingFinish, _mapFIMS, _timeout2);
  145. CheckAfterMap((int)RoutineStep.CheckAfterMap, _mapFIMS, _slotNumber, _slotMap, _isCompareWithSlotMap, _isCreateWafer);
  146. }
  147. catch (RoutineBreakException)
  148. {
  149. return Result.RUN;
  150. }
  151. catch (RoutineFaildException ex)
  152. {
  153. if (_mapFIMS == ModuleName.FIMS1 || _mapFIMS == ModuleName.FIMS2)
  154. (Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as FIMSModule).IsMapping = false;
  155. return Result.FAIL;
  156. }
  157. if (_mapFIMS == ModuleName.FIMS1 || _mapFIMS == ModuleName.FIMS2)
  158. (Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as FIMSModule).IsMapping = false;
  159. Notify("Finished");
  160. return Result.DONE;
  161. }
  162. private void CheckAfterMap(int id, ModuleName mapModule, int slotNumber, string slotMap, bool isCompareWithSlotMap, bool isCreateWafer)
  163. {
  164. Tuple<bool, Result> ret = Execute(id, () =>
  165. {
  166. Notify("Check after map condition");
  167. string reason = string.Empty;
  168. //_waferRobotModule.WaferRobotDevice.SlotMap = "1111111111111111111111111";
  169. if (SC.GetValue<bool>($"System.IsSimulatorMode"))
  170. _waferRobotModule.WaferRobotDevice.SlotMap = "1111111111111111111111111";
  171. int waferCount = _waferRobotModule.WaferRobotDevice.SlotMap.Length == 0 ? 0 : Regex.Matches(_waferRobotModule.WaferRobotDevice.SlotMap, "1").Count;
  172. //if (waferCount != slotNumber)
  173. //{
  174. // _waferRobotModule.MapFailAlarm.Set($"Mapping result {waferCount} unequal to input number {slotNumber}");
  175. // return false;
  176. //}
  177. if (isCompareWithSlotMap && string.IsNullOrEmpty(_waferRobotModule.WaferRobotDevice.SlotMap))
  178. {
  179. _waferRobotModule.MapFailAlarm.Set($"Mapping result is null");
  180. return false;
  181. }
  182. var carrier = CarrierManager.Instance.GetCarrier(mapModule, 0);
  183. if (carrier != null)
  184. {
  185. carrier.IsMapped = true;
  186. carrier.IsMapOK = true;
  187. }
  188. ModuleName originModule = ModuleName.System;
  189. WaferType waferType = WaferType.None;
  190. if (mapModule != ModuleName.PM1)
  191. {
  192. originModule = carrier.InternalModuleName;
  193. Enum.TryParse(carrier.CarrierType.ToString(), out waferType);
  194. }
  195. waferCount = 0;
  196. //"返回结果,格式:“MAP 1 0 D C 1 1” 1:单片,D:叠片 C:跨槽 0:无片"
  197. for (int i = 0; i < _waferRobotModule.WaferRobotDevice.SlotMap.Length; i++)
  198. {
  199. switch (_waferRobotModule.WaferRobotDevice.SlotMap[i])
  200. {
  201. case '1':
  202. if (isCreateWafer)
  203. {
  204. if (WaferManager.Instance.CheckHasWafer(mapModule, i))
  205. WaferManager.Instance.DeleteWafer(mapModule, i);
  206. WaferManager.Instance.CreateWafer(mapModule, i, originModule, i, WaferStatus.Normal, waferType);
  207. CarrierManager.Instance.UpdateWaferIn(originModule, 0, true);
  208. }
  209. waferCount++;
  210. break;
  211. case '0':
  212. if (isCreateWafer)
  213. {
  214. if (WaferManager.Instance.CheckHasWafer(mapModule, i))
  215. WaferManager.Instance.DeleteWafer(mapModule, i);
  216. }
  217. break;
  218. case 'D':
  219. if (isCreateWafer)
  220. {
  221. if (WaferManager.Instance.CheckHasWafer(mapModule, i))
  222. WaferManager.Instance.DeleteWafer(mapModule, i);
  223. WaferManager.Instance.CreateWafer(mapModule, i, originModule, i, WaferStatus.Double, waferType);
  224. CarrierManager.Instance.UpdateWaferIn(originModule, 0, true);
  225. }
  226. reason += $"slot={i + 1} double wafer\n";
  227. break;
  228. case 'C':
  229. if (isCreateWafer)
  230. {
  231. if (WaferManager.Instance.CheckHasWafer(mapModule, i))
  232. WaferManager.Instance.DeleteWafer(mapModule, i);
  233. WaferManager.Instance.CreateWafer(mapModule, i, originModule, i, WaferStatus.Crossed, waferType);
  234. CarrierManager.Instance.UpdateWaferIn(originModule, 0, true);
  235. }
  236. reason += $"slot={i + 1} crossed wafer\n";
  237. break;
  238. }
  239. }
  240. if (!string.IsNullOrEmpty(reason))
  241. {
  242. if (carrier != null)
  243. carrier.IsMapOK = false;
  244. _waferRobotModule.MapFailAlarm.Set(reason);
  245. return false;
  246. }
  247. //if (waferCount != slotNumber)
  248. //{
  249. // if (carrier != null)
  250. // carrier.IsMapOK = false;
  251. // _waferRobotModule.MapFailAlarm.Set($"mapping result wafer count={waferCount}, set wafer count={slotNumber}, not match");
  252. // return false;
  253. //}
  254. if (carrier != null)
  255. carrier.HasWaferIn = waferCount > 0;
  256. //if (isCompareWithSlotMap && slotMap != _waferRobotModule.WaferRobotDevice.SlotMap)
  257. //{
  258. // if (carrier != null)
  259. // carrier.IsMapOK = false;
  260. // _waferRobotModule.MapFailAlarm.Set($"mapping result slot map={_waferRobotModule.WaferRobotDevice.SlotMap}, set slot map={slotMap}, not match");
  261. // return false;
  262. //}
  263. return true;
  264. });
  265. if (ret.Item1)
  266. {
  267. if (ret.Item2 == Result.FAIL)
  268. {
  269. throw (new RoutineFaildException());
  270. }
  271. }
  272. _needStartCheck = false;
  273. }
  274. private void CheckBeforeMap(int id, ModuleName source, Hand blade)
  275. {
  276. Tuple<bool, Result> ret = Execute(id, () =>
  277. {
  278. Notify("Check map condition");
  279. string reason = string.Empty;
  280. if (_waferRobotModule.WaferRobotDevice.IsError)
  281. {
  282. _waferRobotModule.MapFailAlarm.Set($"pick from {source} failed for robot error, error code={_waferRobotModule.WaferRobotDevice.ErrorCode}");
  283. return false;
  284. }
  285. if (!_waferRobotModule.WaferRobotDevice.IsIdle)
  286. {
  287. _waferRobotModule.MapFailAlarm.Set($"pick from {source} failed for robot isn't Ready");
  288. return false;
  289. }
  290. if (source == ModuleName.FIMS1 || source == ModuleName.FIMS2)
  291. {
  292. var stage = Singleton<EquipmentManager>.Instance.Modules[source] as FIMSModule;
  293. if (stage == null && !stage.CheckReadyForTransfer(ModuleHelper.Converter(Module), _blade, 0, EnumTransferType.Map, out reason))
  294. {
  295. _waferRobotModule.MapFailAlarm.Set(reason);
  296. return false;
  297. }
  298. }
  299. if (ModuleHelper.IsPm(source))
  300. {
  301. var pmModule = Singleton<EquipmentManager>.Instance.Modules[_mapFIMS] as PMModule;
  302. if (pmModule != null && !pmModule.CheckReadyForTransfer(ModuleHelper.Converter(_waferRobotModule.Module), _blade, 0, EnumTransferType.Map, out reason))
  303. {
  304. _waferRobotModule.MapFailAlarm.Set(reason);
  305. return false;
  306. }
  307. }
  308. return true;
  309. });
  310. if (ret.Item1)
  311. {
  312. if (ret.Item2 == Result.FAIL)
  313. {
  314. throw (new RoutineFaildException());
  315. }
  316. }
  317. _needStartCheck = false;
  318. }
  319. private void Map(int id, ModuleName source, Hand hand, int timeout)
  320. {
  321. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  322. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  323. {
  324. Notify("Map");
  325. string reason;
  326. if (!_waferRobotModule.RobotMap(source, hand, out reason))
  327. {
  328. _waferRobotModule.MapFailAlarm.Set(reason);
  329. return false;
  330. }
  331. return true;
  332. }, () =>
  333. {
  334. if (_waferRobotModule.WaferRobotDevice.IsReady() && !_waferRobotModule.WaferRobotDevice.IsError)
  335. {
  336. return true;
  337. }
  338. return false;
  339. }, timeout * 1000);
  340. if (ret.Item1)
  341. {
  342. if (ret.Item2 == Result.FAIL)
  343. {
  344. //_waferRobotModule.MapFailAlarm.Description = $"{_waferRobotModule.WaferRobotDevice.ErrorCode}";
  345. _waferRobotModule.MapFailAlarm.Set($"mapping {source} failed for robot error, error code={_waferRobotModule.WaferRobotDevice.ErrorCode}");
  346. throw (new RoutineFaildException());
  347. }
  348. else if (ret.Item2 == Result.TIMEOUT) //timeout
  349. {
  350. //_waferRobotModule.PickWaferTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  351. _waferRobotModule.MapTimeoutAlarm.Set($"timeout over {timeout} seconds");
  352. throw (new RoutineFaildException());
  353. }
  354. else
  355. throw (new RoutineBreakException());
  356. }
  357. }
  358. private void CheckMappingFinish(int id, ModuleName source, int timeout)
  359. {
  360. _routineStep = (RoutineStep)Enum.Parse(typeof(RoutineStep), id.ToString());
  361. Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
  362. {
  363. Notify("Check EX1/EX2 Home Position");
  364. return true;
  365. }, () =>
  366. {
  367. var sensor1 = DEVICE.GetDevice<IoSensor>($"PM1.SensorWaferRobotEX1AxisHomePosition");
  368. var sensor2 = DEVICE.GetDevice<IoSensor>($"PM1.SensorWaferRobotEX2AxisHomePosition");
  369. if (sensor1 != null && sensor1.Value && sensor2 != null && sensor2.Value)
  370. {
  371. return true;
  372. }
  373. return false;
  374. }, timeout * 1000);
  375. if (ret.Item1)
  376. {
  377. if (ret.Item2 == Result.FAIL)
  378. {
  379. throw (new RoutineFaildException());
  380. }
  381. else if (ret.Item2 == Result.TIMEOUT) //timeout
  382. {
  383. //_waferRobotModule.PickWaferTimeoutAlarm.Description = $"timeout over {timeout} seconds";
  384. _waferRobotModule.MapTimeoutAlarm.Set($"check wafer robot EX1/EX2 home position timeout over {timeout} seconds");
  385. throw (new RoutineFaildException());
  386. }
  387. else
  388. throw (new RoutineBreakException());
  389. }
  390. }
  391. }
  392. }