SIASUNRobot.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. using System;
  2. using System.Collections.Generic;
  3. using Venus_RT.Modules;
  4. using Venus_Core;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  11. using Aitex.Core.RT.Log;
  12. using System.Text.RegularExpressions;
  13. namespace Venus_RT.Devices
  14. {
  15. class SIASUNRobot : ITransferRobot
  16. {
  17. enum OPStep
  18. {
  19. Idle,
  20. Home,
  21. Goto,
  22. MoveTo,
  23. CheckLoad_ArmA,
  24. CheckLoad_ArmB,
  25. Pick,
  26. Place,
  27. PickExtend,
  28. PickRetract,
  29. PlaceExtent,
  30. PlaceRetract,
  31. }
  32. private RState _status;
  33. private bool _IsHomed;
  34. public RState Status { get { return _status; } }
  35. public bool IsHomed { get { return _IsHomed; } }
  36. private readonly AsyncSocket _socket;
  37. private OPStep _currentOP = OPStep.Idle;
  38. private Dictionary<ModuleName, int> _StationNumbers = new Dictionary<ModuleName, int>();
  39. private readonly int _checkLoadStation = 1;
  40. private string Hand2Arm(Hand hand) => hand == Hand.Blade1 ? "A" : "B";
  41. private readonly Regex _rex_check_load = new Regex(@"LOAD\s+(A|B)\s+(\w+)\s*");
  42. private readonly Regex _rex_error_code = new Regex(@"_ERR\s+(\d+)\s*");
  43. public SIASUNRobot()
  44. {
  45. _socket = new AsyncSocket("");
  46. _socket.Connect(SC.GetStringValue($"TM.IPAddress"));
  47. _socket.OnDataChanged += OnReceiveMessage;
  48. _socket.OnErrorHappened += OnErrorHappen;
  49. _status = RState.Init;
  50. _IsHomed = false;
  51. _StationNumbers[ModuleName.LLA] = SC.GetValue<int>("TM.LLAStationNumber");
  52. _StationNumbers[ModuleName.LLB] = SC.GetValue<int>("TM.LLBStationNumber");
  53. _StationNumbers[ModuleName.PMA] = SC.GetValue<int>("TM.PMAStationNumber");
  54. _StationNumbers[ModuleName.PMB] = SC.GetValue<int>("TM.PMBStationNumber");
  55. _StationNumbers[ModuleName.PMC] = SC.GetValue<int>("TM.PMCStationNumber");
  56. _StationNumbers[ModuleName.PMD] = SC.GetValue<int>("TM.PMDStationNumber");
  57. _StationNumbers[ModuleName.PME] = SC.GetValue<int>("TM.PMEStationNumber");
  58. _StationNumbers[ModuleName.PMF] = SC.GetValue<int>("TM.PMFStationNumber");
  59. _checkLoadStation = SC.GetValue<int>("TM.CheckLoadStation");
  60. }
  61. public bool Home()
  62. {
  63. _status = RState.Running;
  64. _currentOP = OPStep.Home;
  65. return _SendCommand("HOME ALL\r");
  66. }
  67. public bool Halt()
  68. {
  69. return _SendCommand("HALT\r");
  70. }
  71. public bool CheckLoad(Hand hand = Hand.Blade1)
  72. {
  73. if (_currentOP != OPStep.Home && _currentOP != OPStep.CheckLoad_ArmA && CheckRobotStatus() == false)
  74. return false;
  75. _currentOP = hand == Hand.Blade2 ? OPStep.CheckLoad_ArmB : OPStep.CheckLoad_ArmA;
  76. _status = RState.Running;
  77. return _SendCommand($"CHECK LOAD {_checkLoadStation} ARM {Hand2Arm(hand)}\r");
  78. }
  79. public bool Goto(ModuleName station, int slot, Hand hand)
  80. {
  81. if (CheckRobotStatus() == false)
  82. return false;
  83. _currentOP = OPStep.Goto;
  84. _status = RState.Running;
  85. return _SendCommand($"GOTO N {_StationNumbers[station]} SLOT {slot} ARM {Hand2Arm(hand)}\r");
  86. }
  87. public bool MoveTo(ModuleName stnFrom, ModuleName stnTo, Hand hand)
  88. {
  89. if (CheckRobotStatus() == false)
  90. return false;
  91. _currentOP = OPStep.MoveTo;
  92. _status = RState.Running;
  93. return _SendCommand($"XFER ARM {Hand2Arm(hand)} {_StationNumbers[stnFrom]} {_StationNumbers[stnTo]}\r");
  94. }
  95. public bool PickExtend(ModuleName chamber, int slot, Hand hand)
  96. {
  97. if (CheckRobotStatus() == false)
  98. return false;
  99. _currentOP = OPStep.PickExtend;
  100. _status = RState.Running;
  101. return _SendCommand($"PICK {_StationNumbers[chamber]} SLOT {slot} ARM {Hand2Arm(hand)} ENRT\r");
  102. }
  103. public bool PickRetract(ModuleName chamber, int slot, Hand hand)
  104. {
  105. if (CheckRobotStatus() == false)
  106. return false;
  107. _currentOP = OPStep.PickRetract;
  108. _status = RState.Running;
  109. return _SendCommand($"PICK {_StationNumbers[chamber]} SLOT {slot} ARM {Hand2Arm(hand)} STRT\r");
  110. }
  111. public bool PlaceExtend(ModuleName chamber, int slot, Hand hand)
  112. {
  113. if (CheckRobotStatus() == false)
  114. return false;
  115. _currentOP = OPStep.PlaceExtent;
  116. _status = RState.Running;
  117. return _SendCommand($"PLACE {_StationNumbers[chamber]} SLOT {slot} ARM {Hand2Arm(hand)} ENRT\r");
  118. }
  119. public bool PlaceRetract(ModuleName chamber, int slot, Hand hand)
  120. {
  121. if (CheckRobotStatus() == false)
  122. return false;
  123. _currentOP = OPStep.PlaceExtent;
  124. _status = RState.Running;
  125. return _SendCommand($"PLACE {_StationNumbers[chamber]} SLOT {slot} ARM {Hand2Arm(hand)} STRT\r");
  126. }
  127. public bool Pick(ModuleName station, int slot, Hand hand)
  128. {
  129. if (CheckRobotStatus() == false)
  130. return false;
  131. _currentOP = OPStep.Pick;
  132. _status = RState.Running;
  133. return _SendCommand($"PICK {_StationNumbers[station]} SLOT {slot} ARM {Hand2Arm(hand)}\r");
  134. }
  135. public bool Place(ModuleName station, int slot, Hand hand)
  136. {
  137. if (CheckRobotStatus() == false)
  138. return false;
  139. _currentOP = OPStep.Place;
  140. _status = RState.Running;
  141. return _SendCommand($"PLACE {_StationNumbers[station]} SLOT {slot} ARM {Hand2Arm(hand)}\r");
  142. }
  143. private bool _SendCommand(string cmd)
  144. {
  145. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TM, $"Send Command to SIASUN TM Robot: {cmd}");
  146. return _socket.Write(cmd);
  147. }
  148. private bool CheckRobotStatus()
  149. {
  150. if(Status == RState.Init)
  151. {
  152. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TM, "TM Robot is not homed, please home first.");
  153. return false;
  154. }
  155. else if(Status == RState.Running)
  156. {
  157. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TM, "TM Robot is busy, please wait a minute");
  158. return false;
  159. }
  160. else if(Status == RState.Failed || Status == RState.Timeout)
  161. {
  162. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TM, "TM Robot has a error, please check and fix the hardware issue and home it");
  163. return false;
  164. }
  165. return true;
  166. }
  167. private void OnReceiveMessage(string RevMsg)
  168. {
  169. if(_rex_error_code.IsMatch(RevMsg))
  170. {
  171. _IsHomed = false;
  172. _status = RState.Failed;
  173. var results = _rex_error_code.Match(RevMsg);
  174. ErrorMessageHandler(results.Groups[1].Value);
  175. return;
  176. }
  177. LOG.Write(eEvent.INFO_TM_ROBOT, ModuleName.TM, $"Receive message from SIASUN TM Robot: {RevMsg}, while{_currentOP}");
  178. switch (_currentOP)
  179. {
  180. case OPStep.Goto:
  181. case OPStep.MoveTo:
  182. case OPStep.Pick:
  183. case OPStep.PickExtend:
  184. case OPStep.PickRetract:
  185. case OPStep.Place:
  186. case OPStep.PlaceExtent:
  187. case OPStep.PlaceRetract:
  188. {
  189. if (RevMsg.Trim() == "_RDY")
  190. {
  191. _currentOP = OPStep.Idle;
  192. _status = RState.End;
  193. }
  194. else
  195. ReportWrongMsg(RevMsg);
  196. }
  197. break;
  198. case OPStep.Home:
  199. {
  200. if(RevMsg.Trim() == "_RDY")
  201. {
  202. CheckLoad(Hand.Blade1);
  203. }
  204. else
  205. ReportWrongMsg(RevMsg);
  206. }
  207. break;
  208. case OPStep.CheckLoad_ArmA:
  209. {
  210. if(_rex_check_load.IsMatch(RevMsg))
  211. {
  212. GetCheckLoadResult(RevMsg);
  213. CheckLoad(Hand.Blade2);
  214. }
  215. else
  216. ReportWrongMsg(RevMsg);
  217. }
  218. break;
  219. case OPStep.CheckLoad_ArmB:
  220. {
  221. if (_rex_check_load.IsMatch(RevMsg))
  222. {
  223. GetCheckLoadResult(RevMsg);
  224. _currentOP = OPStep.Idle;
  225. _status = RState.End;
  226. _IsHomed = true;
  227. }
  228. }
  229. break;
  230. default:
  231. ReportWrongMsg(RevMsg);
  232. break;
  233. }
  234. }
  235. private void GetCheckLoadResult(string strRev)
  236. {
  237. Match result = _rex_check_load.Match(strRev);
  238. string Arm = result.Groups[1].Value;
  239. string WaferStatus = result.Groups[2].Value;
  240. if(WaferStatus == "ON")
  241. {
  242. WaferManager.Instance.CreateWafer(ModuleName.TM, Arm == "A" ? 0 : 1, Aitex.Core.Common.WaferStatus.Unknown);
  243. }
  244. }
  245. private void OnErrorHappen(ErrorEventArgs args)
  246. {
  247. Singleton<RouteManager>.Instance.TM.PostMsg(TMEntity.MSG.Error);
  248. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TM, $"SIASUN TM Robot Error: {args.Reason} while {_currentOP}");
  249. }
  250. private void ReportWrongMsg(string revMsg)
  251. {
  252. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TM, $"Receive wrong message:{revMsg} while {_currentOP}");
  253. }
  254. private void ErrorMessageHandler(string errCode)
  255. {
  256. int ErrCode;
  257. string ErrorInfo;
  258. if(int.TryParse(errCode, out ErrCode))
  259. {
  260. switch (ErrCode)
  261. {
  262. // 系统及硬件错误信息
  263. case 901:
  264. ErrorInfo = $"_Err {errCode}: 主电柜急停启动";
  265. break;
  266. case 902:
  267. ErrorInfo = $"_Err {errCode}: 示教盒急停启动";
  268. break;
  269. case 862:
  270. ErrorInfo = $"_Err {errCode}: 驱动器 RDY 信号断开";
  271. break;
  272. // 执行错误信息
  273. case 3001:
  274. ErrorInfo = $"_Err {errCode}: 系统发生碰撞,按取消恢复";
  275. break;
  276. case 7300:
  277. ErrorInfo = $"_Err {errCode}: 旋转信号不允许";
  278. break;
  279. case 7301:
  280. ErrorInfo = $"_Err {errCode}: 伸缩信号不允许";
  281. break;
  282. case 2200:
  283. ErrorInfo = $"_Err {errCode}: 输出端口 NO.不存在";
  284. break;
  285. case 3100:
  286. ErrorInfo = $"_Err {errCode}: 关节 N 位置超界";
  287. break;
  288. case 3120:
  289. ErrorInfo = $"_Err {errCode}: 关节 N 速度超界";
  290. break;
  291. case 100:
  292. ErrorInfo = $"_Err {errCode}: 手臂电源上电失败(手臂电源未打开)";
  293. break;
  294. // 通信错误信息
  295. case 7307:
  296. ErrorInfo = $"_Err {errCode}: GOTO 工位号超范围";
  297. break;
  298. case 7308:
  299. ErrorInfo = $"_Err {errCode}: 不支持的传感器类型";
  300. break;
  301. case 7312:
  302. ErrorInfo = $"_Err {errCode}: PICK工位号超范围";
  303. break;
  304. case 7313:
  305. ErrorInfo = $"_Err {errCode}: PLACE工位号超范围";
  306. break;
  307. case 7314:
  308. ErrorInfo = $"_Err {errCode}: XFER工位号超范围";
  309. break;
  310. case 7315:
  311. ErrorInfo = $"_Err {errCode}: REMOVE不支持的IO类型";
  312. break;
  313. case 7316:
  314. ErrorInfo = $"_Err {errCode}: RQ INTLCK不识别的参数";
  315. break;
  316. case 7317:
  317. ErrorInfo = $"_Err {errCode}: RQ IO不识别的参数";
  318. break;
  319. case 7319:
  320. ErrorInfo = $"_Err {errCode}: RQ STN工位号超范围";
  321. break;
  322. case 7320:
  323. ErrorInfo = $"_Err {errCode}: wafre(WAF_SEN)参数未设置";
  324. break;
  325. case 7321:
  326. ErrorInfo = $"_Err {errCode}: wafex(RETRACT_PIN)参数未设置";
  327. break;
  328. case 7322:
  329. ErrorInfo = $"_Err {errCode}: svlv(SBIT_SVLV_SEN)参数未设置";
  330. break;
  331. case 7323:
  332. ErrorInfo = $"_Err {errCode}: ens(EX_ENABLE)参数未设置";
  333. break;
  334. case 7324:
  335. ErrorInfo = $"_Err {errCode}: RQ命令不支持的参数";
  336. break;
  337. case 7325:
  338. ErrorInfo = $"_Err {errCode}: SET INTLOCK WAF_SEN参数错";
  339. break;
  340. case 7326:
  341. ErrorInfo = $"_Err {errCode}: SET INTLOCK RZ参数错";
  342. break;
  343. case 7327:
  344. ErrorInfo = $"_Err {errCode}: SET INTLOCK参数错";
  345. break;
  346. case 7328:
  347. ErrorInfo = $"_Err {errCode}: SET IO ECHO参数错";
  348. break;
  349. case 7329:
  350. ErrorInfo = $"_Err {errCode}: SET IO STATE不支持";
  351. break;
  352. case 7330:
  353. ErrorInfo = $"_Err {errCode}: SET IO不支持的参数";
  354. break;
  355. case 7331:
  356. ErrorInfo = $"_Err {errCode}: SET STN工位号超范围";
  357. break;
  358. case 7332:
  359. ErrorInfo = $"_Err {errCode}: 手臂参数读取错误";
  360. break;
  361. case 7333:
  362. ErrorInfo = $"_Err {errCode}: WAF_SEN不识别的参数";
  363. break;
  364. case 7334:
  365. ErrorInfo = $"_Err {errCode}: SET不支持的传感器类型";
  366. break;
  367. case 7335:
  368. ErrorInfo = $"_Err {errCode}: SET 指令输入不完整";
  369. break;
  370. case 7336:
  371. ErrorInfo = $"_Err {errCode}: STORE IO命令不支持该参数";
  372. break;
  373. case 7337:
  374. ErrorInfo = $"_Err {errCode}: STORE LOAD命令不支持该参数";
  375. break;
  376. case 7338:
  377. ErrorInfo = $"_Err {errCode}: STORE STN指令工位号大于20";
  378. break;
  379. case 7339:
  380. ErrorInfo = $"_Err {errCode}: STORE STN命令手臂参数错误";
  381. break;
  382. case 7340:
  383. ErrorInfo = $"_Err {errCode}: STORE不支持的传感器类型";
  384. break;
  385. case 7341:
  386. ErrorInfo = $"_Err {errCode}: STORE指令输入不完整";
  387. break;
  388. case 7342:
  389. ErrorInfo = $"_Err {errCode}: 无法识别的命令";
  390. break;
  391. case 7343:
  392. ErrorInfo = $"_Err {errCode}: HOME参数未指定";
  393. break;
  394. case 7344:
  395. ErrorInfo = $"_Err {errCode}: GOTO指令R轴参数未指定";
  396. break;
  397. case 7345:
  398. ErrorInfo = $"_Err {errCode}: GOTO指令Z轴参数未指定";
  399. break;
  400. case 7346:
  401. ErrorInfo = $"_Err {errCode}: ARM参数错误";
  402. break;
  403. case 7347:
  404. ErrorInfo = $"_Err {errCode}: GOTO指令未指定参数";
  405. break;
  406. case 7349:
  407. ErrorInfo = $"_Err {errCode}: MOVE指令未指定模式或轴";
  408. break;
  409. case 7350:
  410. ErrorInfo = $"_Err {errCode}: MOVE 指令中字段名字错";
  411. break;
  412. case 7351:
  413. ErrorInfo = $"_Err {errCode}: PICK未指定参数";
  414. break;
  415. case 7352:
  416. ErrorInfo = $"_Err {errCode}: PLACE未指定参数";
  417. break;
  418. case 7353:
  419. ErrorInfo = $"_Err {errCode}: REMOVE未指定参数";
  420. break;
  421. case 7354:
  422. ErrorInfo = $"_Err {errCode}: 指令执行未结束";
  423. break;
  424. case 7355:
  425. ErrorInfo = $"_Err {errCode}: GOTO指令未指定工位号";
  426. break;
  427. case 7356:
  428. ErrorInfo = $"_Err {errCode}: PICK指令未指定工位号";
  429. break;
  430. case 7357:
  431. ErrorInfo = $"_Err {errCode}: PLACE指令未指定工位号";
  432. break;
  433. case 7358:
  434. ErrorInfo = $"_Err {errCode}: ABS未指定数值";
  435. break;
  436. case 7359:
  437. ErrorInfo = $"_Err {errCode}: REL未指定数值";
  438. break;
  439. case 7360:
  440. ErrorInfo = $"_Err {errCode}: 没有指定主程序";
  441. break;
  442. case 7361:
  443. ErrorInfo = $"_Err {errCode}: 当前没有打开作业";
  444. break;
  445. case 7362:
  446. ErrorInfo = $"_Err {errCode}: 当前作业不是主作业";
  447. break;
  448. case 7363:
  449. ErrorInfo = $"_Err {errCode}: ex_ena(EX_ENABLE_SEN)参数未设置";
  450. break;
  451. case 7364:
  452. ErrorInfo = $"_Err {errCode}: stable(STABLE_ SIGNAL)参数未设置";
  453. break;
  454. case 7365:
  455. ErrorInfo = $"_Err {errCode}: VIA参数设置有误";
  456. break;
  457. case 7366:
  458. ErrorInfo = $"_Err {errCode}: 系统处于非启动状态";
  459. break;
  460. case 7367:
  461. ErrorInfo = $"_Err {errCode}: extend(EX_SIGNAL)参数未设置";
  462. break;
  463. case 7368:
  464. ErrorInfo = $"_Err {errCode}: retract(RE_ SIGNAL)参数未设置";
  465. break;
  466. case 7371:
  467. ErrorInfo = $"_Err {errCode}: place动作前:未检测到晶圆";
  468. break;
  469. case 7372:
  470. ErrorInfo = $"_Err {errCode}: pick动作前:检测到晶圆";
  471. break;
  472. case 7373:
  473. ErrorInfo = $"_Err {errCode}: place动作后:检测到晶圆";
  474. break;
  475. case 7374:
  476. ErrorInfo = $"_Err {errCode}: pick动作后:未检测到晶圆";
  477. break;
  478. case 7375:
  479. ErrorInfo = $"_Err {errCode}: 系统未上电或当前不是执行模式";
  480. break;
  481. case 7376:
  482. ErrorInfo = $"_Err {errCode}: 参数中存在非数字";
  483. break;
  484. case 7385:
  485. ErrorInfo = $"_Err {errCode}: 驱动器异常停止";
  486. break;
  487. case 7387:
  488. ErrorInfo = $"_Err {errCode}: 驱动器ID1报警";
  489. break;
  490. case 7388:
  491. ErrorInfo = $"_Err {errCode}: 驱动器ID2报警";
  492. break;
  493. case 7389:
  494. ErrorInfo = $"_Err {errCode}: 驱动器ID3报警";
  495. break;
  496. case 7391:
  497. ErrorInfo = $"_Err {errCode}: AWC工位号超范围";
  498. break;
  499. case 7392:
  500. ErrorInfo = $"_Err {errCode}: 偏差过大AWC报警";
  501. break;
  502. case 7393:
  503. ErrorInfo = $"_Err {errCode}: 标定失败,请重新标定";
  504. break;
  505. case 7398:
  506. ErrorInfo = $"_Err {errCode}: 触发点计算半径有误";
  507. break;
  508. case 7399:
  509. ErrorInfo = $"_Err {errCode}: 驱动器锁存AWC数据个数有误";
  510. break;
  511. case 7401:
  512. ErrorInfo = $"_Err {errCode}: 手指上可能有晶圆";
  513. break;
  514. case 7402:
  515. ErrorInfo = $"_Err {errCode}: 手指上可能无晶圆";
  516. break;
  517. case 7403:
  518. ErrorInfo = $"_Err {errCode}: load当前状态为ON,不正确";
  519. break;
  520. case 7404:
  521. ErrorInfo = $"_Err {errCode}: load当前状态为OFF,不正确";
  522. break;
  523. case 7405:
  524. ErrorInfo = $"_Err {errCode}: 当前slot不存在!";
  525. break;
  526. case 7495:
  527. ErrorInfo = $"_Err {errCode}: ID1码盘反馈错误";
  528. break;
  529. case 7496:
  530. ErrorInfo = $"_Err {errCode}: ID2码盘反馈错误";
  531. break;
  532. case 7497:
  533. ErrorInfo = $"_Err {errCode}: ID3码盘反馈错误";
  534. break;
  535. default:
  536. ErrorInfo = $"_Err {errCode}: 不能识别的错误码";
  537. break;
  538. }
  539. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TM, ErrorInfo);
  540. }
  541. else
  542. {
  543. LOG.Write(eEvent.ERR_TM_ROBOT, ModuleName.TM, $"Try Parse the receive error code faild:{errCode}");
  544. }
  545. }
  546. }
  547. }