SunWayRobot.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.SCCore;
  3. using Aitex.Sorter.Common;
  4. using MECF.Framework.Common.CommonData;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.SubstrateTrackings;
  7. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  8. using System;
  9. using System.Collections.Concurrent;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Text.RegularExpressions;
  14. using System.Threading.Tasks;
  15. using Venus_Core;
  16. using Venus_RT.Devices.VCE;
  17. namespace Venus_RT.Devices.TM
  18. {
  19. public class SunWayRobot : ITransferRobot
  20. {
  21. private readonly AsyncSocket _socket;
  22. private const string EOF = "\r";
  23. private RState _status;
  24. private bool _IsHomed;
  25. private VRStep _currentStep = VRStep.Idle;
  26. private Dictionary<string, int> _StationNumbers = new Dictionary<string, int>();
  27. public RState Status { get { return _status; } }
  28. public bool IsHomed { get { return _IsHomed; } }
  29. private string Hand2Arm(Hand hand) => hand == Hand.Blade2 ? "B" : "A";
  30. //private readonly Regex _rex_check_load = new Regex(@"LOAD\s+(A|B)\s+(\w+)\s*");
  31. private readonly Regex _rex_check_load = new Regex(@"CHECK LOAD\s*");
  32. private readonly Regex _rex_rq_load_A = new Regex(@"LOAD\sA\s.*");
  33. private readonly Regex _rex_rq_load_B = new Regex(@"LOAD\sB\s.*");
  34. private readonly Regex _rex_error_code = new Regex(@"_ERR\s+(\d+)\s*");
  35. private readonly Regex _rex_rq_speed = new Regex(@"MOTIONPARA.*");
  36. private RobotMoveInfo _robotMoveInfo = new RobotMoveInfo();
  37. private string _WithWaferSpeed = "";
  38. private string _NoWaferSpeed = "";
  39. public string WithWaferSpeed => _WithWaferSpeed;
  40. public string NoWaferSpeed => _NoWaferSpeed;
  41. public RobotMoveInfo TMRobotMoveInfo { get { return _robotMoveInfo; } }
  42. public double Offset_X => 0;
  43. public double Offset_Y => 0;
  44. public double Offset_D => 0;
  45. public Dictionary<string, string> _error2msg = new Dictionary<string, string>()
  46. {
  47. {"105" , "数据解析错误" },
  48. {"221" , "手臂选择无效,检查指令中的对应参数" },
  49. //{"222" , "无效的 Pan 参数"},
  50. {"233" , "伸缩信号未使能,检查传输腔传感器信号是否正常" },
  51. {"304" , "未识别的错误码" },
  52. {"305" , "无法识别的命令,检查指令" },
  53. {"309" , "不支持的指令,检查指令" },
  54. //{"350" , "解析器错误,堆栈溢出,检查指令" },
  55. {"401" , "ZWAFER参数错误 ,检查ZWAFER参数" },
  56. {"402" , "非法的slot参数,检查slot设置参数" },
  57. {"403" , "运动指令RX参数错误,检查RX参数字段" },
  58. {"404" , "晶圆夹取失败,检测传感器是否正常" },
  59. {"405" , "晶圆释放失败,检测传感器是否正常" },
  60. {"406" , "气缸压力表检测错误,检查气缸传感器" },
  61. {"407" , "Mapping传感器伸出失败,检查气缸传感器" },
  62. {"408" , "Mapping传感器缩回失败,检查气缸传感器" },
  63. {"409" , "Mapping传感器位置数据不正确,检查mapping工位或传感器设置" },
  64. {"410" , "Mapping参数值不合理,检查Mapping设置参数" },
  65. //{"416" , "无法执行 CheckLoad 操作,检查指令中的对应参数" },
  66. //{"417" , "Offset 参数参数超限,检查指令中指定的 offset 值是否在允许范围内" },
  67. //{"418" , "AWC 功能检测到误差过大,检查晶圆是否过偏或检查AWC传感器标定参数" },
  68. //{"420" , "副臂没有在HOME位置,请检查副臂的位置,可以使用HOME ALL使得所有关节姿态回到HOME位置" },
  69. {"451" , "放片时,AWC偏差超过设定最大偏差值(PAN L) ,检测到晶圆偏心过大,或者 AWC 校验失败" },
  70. {"452" , "PICK时,AWC偏差超过设定最大偏差值(PAN L) ,检测到晶圆偏心过大,或者 AWC 校验失败" },
  71. {"453" , "AWC采集数据个数异常,检查AWC传感器配置" },
  72. {"455" , "放片时,AWC偏差超过设定最大偏差值(PAN R) ,检测到晶圆偏心过大,或者 AWC 校验失败" },
  73. {"456" , "PICK时,AWC偏差超过设定最大偏差值(PAN R) ,检测到晶圆偏心过大,或者 AWC 校验失败" },
  74. {"457" , "AWC检查到破片报警(PAN L),检查破片设置值,晶圆位置,或者 AWC 校验失败" },
  75. {"458" , "AWC检查到破片报警(PAN R),检查破片设置值,晶圆位置,或者 AWC 校验失败" },
  76. {"459" , "AWC未标定,检查AWC标定信息,工位示教后进行AWC标定" },
  77. {"460" , "AWC标定失败,检查晶圆SIZE设置是否正确 ,检查AWC传感器是否正常触发 " },
  78. {"550" , "Station参数超出范围,检查站点配置参数" },
  79. //{"551" , "ARM 不在站点,检查当前手臂实际位置与逻辑位置" },
  80. //{"560" , "机械臂处于 HALT 状态,拒绝接受新的指令" },
  81. //{"561" , "当前机械臂状态机与指令不匹配,当前状态机不满足执行该指令的条件" },
  82. {"599" , "用户急停开启 ,检查用户急停 " },
  83. {"600" , "系统未上电,发送上电指令" },
  84. {"602" , "指令正在执行中,等待机械手运动完成" },
  85. //{"603" , "收到急停指令" },
  86. {"604" , "示教器控制中,通过操作示教盒退出示教盒模式 " },
  87. {"605" , "机械手运动中停止,确认是否发送了HALT指令" },
  88. //{"608" , "机械臂急停中" },
  89. {"609" , "系统存在错误,检查错误码或查看Robot内部log文件" },
  90. {"610" , "示教盒急停启动,解除示教盒急停按钮" },
  91. {"611" , "驱动器报警,检查驱动器状态或对应IO状态" },
  92. {"629" , "驱动器存在报警,检查驱动器报警码" },
  93. //{"692" , "检测左 PAN 上有片,与逻辑状态不匹配" },
  94. //{"693" , "检测右 PAN 上有片,与逻辑状态不匹配" },
  95. //{"694" , "检测左 PAN 上无片,与逻辑状态不匹配" },
  96. //{"695" , "检测右 PAN 上有片,与逻辑状态不匹配" },
  97. //{"700" , "当前手臂有晶圆 ,检查指令动作要求的晶圆状态,与手臂内部存储的晶圆状态是否匹配" },
  98. //{"701" , "当前手臂无晶圆,检查指令动作要求的晶圆状态,与手臂内部存储的晶圆状态是否匹配"},
  99. {"705" , "LOAD状态未知,RQ LOAD查询状态 "},
  100. //{"711" , "站点互锁错误,检查站点的“允许机械臂进入信号”是否就绪"},
  101. {"712" , "真空吸附动作失败,检查真空吸附传感器是否正常"},
  102. {"720" , "PAN L PICK RE状态不正确,检查PAN L上是否有晶圆"},
  103. {"721" , "PAN R PICK RE状态不正确,检查PAN R是否有晶圆 "},
  104. {"722" , "PAN R PLACE前状态不正确,查询PAN R状态"},
  105. {"723" , "PAN L PLACE前状态不正确,查询PAN L状态"},
  106. {"724" , "PAN R PLACE EX状态不正确 ,检查PAN R上是否有晶圆"},
  107. {"725" , "PAN L PLACE EX状态不正确 ,检查PAN L上是否有晶圆"},
  108. {"726" , "PAN R PLACE RE状态不正确 ,检查PAN R上是否有晶圆"},
  109. {"727" , "PAN L PLACE RE状态不正确 ,检查PAN L是否有晶圆"},
  110. {"730" , "PLACE前LOAD状态错误,RQ LOAD查询状态"},
  111. {"731" , "PLACE后检测到晶圆,检查手指上晶圆状态"},
  112. {"734" , "PLACE执行Extend过程中未检测到晶圆,检查Sensor状态和wafer check配置"},
  113. {"736" , "PLACE执行Retract过程中检测到晶圆,检查Sensor状态和wafer check配置"},
  114. {"740" , "PICK前LOAD状态错误 ,RQ LOAD查询状态"},
  115. {"741" , "PICK后未检测到晶圆 ,检查手指是否有晶圆和Sensor状态"},
  116. {"744" , "PICK执行Extend过程中检测到晶圆,检查Sensor状态和wafer check配置"},
  117. {"745" , "PICK执行Retract过程中未检测到晶圆,检查Sensor状态和wafer check配置"},
  118. {"751" , "PAN L晶圆不存在,查询LOAD状态"},
  119. {"752" , "PAN R晶圆不存在,查询LOAD状态"},
  120. {"757" , "PAN R晶圆不存在,查询LOAD状态"},
  121. {"758" , "PAN R PICK EX检测到晶圆,检查Sensor状态和PAN R当前是否晶圆"},
  122. {"759" , "PAN L PICK RE未检测到晶圆,检查Sensor状态和PAN L当前是否晶圆"},
  123. {"760" , "PAN R PICK RE未检测到晶圆,检查Sensor状态和PAN R当前是否晶圆"},
  124. {"761" , "PAN L PLACE EX未检测到晶圆,检查Sensor状态和PAN L当前是否有晶圆"},
  125. {"762" , "PAN R PLACE EX未检测到晶圆,检查Sensor状态和PAN R当前是否有晶圆"},
  126. {"763" , "PAN L PLACE RE检测到晶圆,检查Sensor状态和PAN L当前是否有晶圆"},
  127. {"764" , "PAN R PLACE RE检测到晶圆,检查Sensor状态和PAN R当前是否有晶圆"},
  128. //{"771" , "取片时 AWC 传感器检测失败,检查 AWC 传感器状态,或者 AWC 配置相关是否正确"},
  129. //{"791" , "查询 AWC 数据失败,未曾执行过 AWC 相关功能的操作"},
  130. //{"792" , "AWC 传感器检测失败,检查AWC传感器状态,或者AWC配置相关是否正确"},
  131. //{"799" , "放片失败,检查手臂晶圆状态,或者晶圆检测传感器状态"},
  132. {"800" , "PICK执行Retract过程中未检测到晶圆,检查Sensor状态和wafer check配置"},
  133. {"801" , "改变运动状态发生错误,检查当前运动状态"},
  134. {"802" , "无法获取下一个状态,检查机械手当前运动状态"},
  135. {"803" , "没有正在运行的指令 ,指令是否运行完成"},
  136. {"804" , "没有暂停的动作,检查机械手是否在运动"},
  137. {"805" , "没有可跳过的动作,检查运动状态"},
  138. {"806" , "带拐点工位不支持该指令,拐点开关是否打开"},
  139. {"1006" , "非法的IO端口号,确认配置的IO号"},
  140. {"1314" , "PITCH轴超界,检查PITCH关节值"},
  141. {"1315" , "关节位置超界 ,查询当前关节值和软限位"},
  142. {"1316" , "关节位置超硬限 ,查询当前关节值和硬限位传感器"},
  143. {"1320" , "机械手跟踪差超限错误 ,查询当前跟踪差配置值"},
  144. {"1321" , "机械手发生碰撞,检测当前碰撞参数配置值"},
  145. {"1322" , "机械手发生碰撞,检测当前碰撞参数配置值"},
  146. {"1323" , "机械手发生碰撞,检测当前碰撞参数配置值"},
  147. {"2000" , "ALGN偏差超过最大值,检查设置的晶圆最大偏差值 检查晶圆位置 "},
  148. {"2001" , "AGLN CCD数据异常,确认晶圆位置是否正确 确认CCD传感器位置是否正确 确认内部线路正负正确 "},
  149. {"2002" , "返回值格式错误,确认返回值格式"},
  150. {"2003" , "通信已经断开,检查通讯线路是否正常"},
  151. {"2008" , "FLAT片数据异常,确认晶圆位置是否正确 确认CCD传感器位置是否正确 "},
  152. {"13007" , "通信断开,检查通讯线路是否正常"},
  153. {"13033" , "伺服驱动器初始化失败,检查驱动器通信连线或检查通信配置"},
  154. };
  155. private BlockingCollection<RobotAnimationData> blockingCollection = new BlockingCollection<RobotAnimationData>();
  156. private ModuleName _module;
  157. public SunWayRobot(ModuleName module)
  158. {
  159. _module = module;
  160. _socket = new AsyncSocket("", EOF);
  161. _socket.Connect(SC.GetStringValue($"{_module}.IPAddress"));
  162. _socket.OnDataChanged += OnReceiveMessage;
  163. _socket.OnErrorHappened += OnErrorHappen;
  164. _status = RState.Init;
  165. _IsHomed = false;
  166. _StationNumbers[ModuleName.VCE1.ToString()] = SC.GetValue<int>($"{_module}.VCE1StationNumber");
  167. _StationNumbers[ModuleName.VCEA.ToString()] = SC.GetValue<int>($"{_module}.VCEAStationNumber");
  168. _StationNumbers[ModuleName.VCEB.ToString()] = SC.GetValue<int>($"{_module}.VCEBStationNumber");
  169. _StationNumbers[ModuleName.Aligner1.ToString()] = SC.GetValue<int>($"{_module}.Aligner1StationNumber");
  170. _StationNumbers[ModuleName.PMA.ToString()] = SC.GetValue<int>($"{_module}.PMAStationNumber");
  171. _StationNumbers[ModuleName.PMB.ToString()] = SC.GetValue<int>($"{_module}.PMBStationNumber");
  172. _StationNumbers[ModuleName.PMC.ToString()] = SC.GetValue<int>($"{_module}.PMCStationNumber");
  173. _StationNumbers[ModuleName.PMD.ToString()] = SC.GetValue<int>($"{_module}.PMDStationNumber");
  174. _StationNumbers["CheckLoad"] = SC.GetValue<int>($"{_module}.CheckStationNumber");
  175. WaferManager.Instance.SubscribeLocation(ModuleName.TMRobot, 2);
  176. Task.Run(() =>
  177. {
  178. foreach (var data in blockingCollection.GetConsumingEnumerable())
  179. {
  180. _robotMoveInfo.Action = data.Action;
  181. _robotMoveInfo.ArmTarget = data.Hand == Hand.Blade1 ? RobotArm.ArmA : (data.Hand == Hand.Both ? RobotArm.Both : RobotArm.ArmB);
  182. _robotMoveInfo.BladeTarget = $"{_robotMoveInfo.ArmTarget}.{data.Target}";
  183. System.Threading.Thread.Sleep(600);
  184. }
  185. });
  186. }
  187. //初始化某个轴
  188. //1.清错
  189. //2.设备上电
  190. //3.各轴按顺序运动
  191. public bool Home()
  192. {
  193. _status = RState.Running;
  194. _currentStep = VRStep.Home;
  195. return _SendCommand("HOME ALL");
  196. }
  197. public bool Halt()
  198. {
  199. _status = RState.Running;
  200. _currentStep = VRStep.Halt;
  201. return _SendCommand("HALT");
  202. }
  203. public bool Release()
  204. {
  205. _status = RState.Running;
  206. _currentStep = VRStep.Release;
  207. return _SendCommand("RELEASE");
  208. }
  209. //public bool MOVE()
  210. //{
  211. //}
  212. public bool Pick(ModuleName station, int slot, Hand hand)
  213. {
  214. if (!CheckRobotStatus())
  215. return false;
  216. _currentStep = VRStep.Pick;
  217. _status = RState.Running;
  218. SetRobotMovingInfo(RobotAction.Picking, hand, station);
  219. return _SendCommand($"PICK {_StationNumbers[station.ToString()]} ARM {Hand2Arm(hand)}");
  220. }
  221. public bool PickExtend(ModuleName station, int slot, Hand hand)
  222. {
  223. if (!CheckRobotStatus())
  224. return false;
  225. _currentStep = VRStep.PickExtend;
  226. _status = RState.Running;
  227. SetRobotMovingInfo(RobotAction.Extending, hand, station);
  228. return _SendCommand($"PICK {_StationNumbers[station.ToString()]} ARM {Hand2Arm(hand)} ENRT NR");
  229. }
  230. public bool PickRetract(ModuleName station, int slot, Hand hand)
  231. {
  232. if (!CheckRobotStatus())
  233. return false;
  234. _currentStep = VRStep.PickRetract;
  235. _status = RState.Running;
  236. SetRobotMovingInfo(RobotAction.Retracting, hand, station);
  237. return _SendCommand($"PICK {_StationNumbers[station.ToString()]} ARM {Hand2Arm(hand)} STRT NR");
  238. }
  239. public bool Place(ModuleName station, int slot, Hand hand)
  240. {
  241. if (!CheckRobotStatus())
  242. return false;
  243. _currentStep = VRStep.Place;
  244. _status = RState.Running;
  245. SetRobotMovingInfo(RobotAction.Placing, hand, station);
  246. return _SendCommand($"PLACE {_StationNumbers[station.ToString()]} ARM {Hand2Arm(hand)}");
  247. }
  248. public bool PlaceExtend(ModuleName station, int slot, Hand hand)
  249. {
  250. if (!CheckRobotStatus())
  251. return false;
  252. _currentStep = VRStep.Place;
  253. _status = RState.Running;
  254. SetRobotMovingInfo(RobotAction.Extending, hand, station);
  255. return _SendCommand($"PLACE {_StationNumbers[station.ToString()]} ARM {Hand2Arm(hand)} ENRT NR");
  256. }
  257. public bool PlaceRetract(ModuleName station, int slot, Hand hand)
  258. {
  259. if (!CheckRobotStatus())
  260. return false;
  261. _currentStep = VRStep.Place;
  262. _status = RState.Running;
  263. SetRobotMovingInfo(RobotAction.Retracting, hand, station);
  264. return _SendCommand($"PLACE {_StationNumbers[station.ToString()]} ARM {Hand2Arm(hand)} STRT NR");
  265. }
  266. public bool Transfer(ModuleName fromstation, ModuleName tostation, Hand hand)
  267. {
  268. if (!CheckRobotStatus())
  269. return false;
  270. _currentStep = VRStep.Xfer;
  271. _status = RState.Running;
  272. return _SendCommand($"XFER ARM {Hand2Arm(hand)} {_StationNumbers[fromstation.ToString()]} {_StationNumbers[tostation.ToString()]}");
  273. }
  274. public bool CheckLoad(Hand hand = Hand.Blade1)
  275. {
  276. if (_currentStep != VRStep.Home && _currentStep != VRStep.CheckLoad_ArmA && !CheckRobotStatus())
  277. return false;
  278. _currentStep = hand == Hand.Blade2 ? VRStep.CheckLoad_ArmB : VRStep.CheckLoad_ArmA;
  279. _status = RState.Running;
  280. string arm = hand == Hand.Blade2 ? "B" : "A";
  281. return _SendCommand($"CHECK LOAD {_StationNumbers["CheckLoad"]} {arm}");
  282. }
  283. public bool QueryAwc()
  284. {
  285. return true;
  286. }
  287. public bool Goto(ModuleName station, int slot, Hand hand)
  288. {
  289. if (!CheckRobotStatus())
  290. return false;
  291. _currentStep = VRStep.Goto;
  292. _status = RState.Running;
  293. SetRobotMovingInfo(RobotAction.Rotating, hand, station);
  294. return _SendCommand($"Goto {_StationNumbers[station.ToString()]} ARM {Hand2Arm(hand)}");
  295. }
  296. public bool MoveTo(ModuleName stnFrom, ModuleName stnTo, Hand hand)
  297. {
  298. _currentStep = VRStep.Move;
  299. _status = RState.Running;
  300. return _SendCommand($"MOVE R ABS 100 ARM {Hand2Arm(hand)}"); ;
  301. }
  302. public bool PickWithOffset(ModuleName station, int slot, Hand hand, int Roffset, int Toffset)
  303. {
  304. _currentStep = VRStep.Pick;
  305. _status = RState.Running;
  306. SetRobotMovingInfo(RobotAction.Picking, hand, station);
  307. return _SendCommand($"PICK {_StationNumbers[station.ToString()]} ARM {Hand2Arm(hand)} RO {Roffset} TO {Toffset}"); ;
  308. }
  309. public bool ReQueryLoadA()
  310. {
  311. _currentStep = VRStep.ReQueryLoadA;
  312. _status = RState.Running;
  313. return _SendCommand($"RQ LOAD ARM A");
  314. }
  315. public bool ReQueryLoadB()
  316. {
  317. _currentStep = VRStep.ReQueryLoadB;
  318. _status = RState.Running;
  319. return _SendCommand($"RQ LOAD ARM B");
  320. }
  321. public bool SetSpeed(string withwafer, float speed)
  322. {
  323. if (!CheckRobotStatus())
  324. return false;
  325. _currentStep = VRStep.SetSpeed;
  326. _status = RState.Running;
  327. int setspeed = (int)Math.Floor(speed * 10);
  328. return _SendCommand($"SET MOTIONPARA {withwafer} SPDPCT ALL {setspeed.ToString().PadLeft(4, '0')}");
  329. }
  330. public bool SaveSpeed(string withwafer)
  331. {
  332. if (!CheckRobotStatus())
  333. return false;
  334. _currentStep = VRStep.SaveSpeed;
  335. _status = RState.Running;
  336. return _SendCommand($"STORE MOTIONPARA {withwafer} SPDPCT ALL");
  337. }
  338. public bool QuerySpeed(string withwafer)
  339. {
  340. if (!CheckRobotStatus())
  341. return false;
  342. _currentStep = VRStep.RQSpeed;
  343. _status = RState.Running;
  344. //MOTIONPARA {} SPDPCT all x t z
  345. return _SendCommand($"RQ MOTIONPARA {withwafer} SPDPCT ALL");
  346. }
  347. public bool ServeOn(bool IsOn)
  348. {
  349. _currentStep = VRStep.ServeOn;
  350. _status = RState.Running;
  351. if (IsOn)
  352. return _SendCommand($"SET SERVOS ON");
  353. else
  354. return _SendCommand($"SET SERVOS OFF");
  355. }
  356. private bool _SendCommand(string cmd)
  357. {
  358. LOG.WriteSingeLine(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"Send Command to TMRobot: {cmd},Connect:{_socket.IsConnected}");
  359. return _socket.Write(cmd + EOF);
  360. }
  361. private bool CheckRobotStatus()
  362. {
  363. if (Status == RState.Init)
  364. {
  365. LOG.Write(eEvent.ERR_DEVICE_INFO, ModuleName.TMRobot, "TMRobot is not homed, please home first.");
  366. return false;
  367. }
  368. else if (Status == RState.Running)
  369. {
  370. LOG.Write(eEvent.ERR_DEVICE_INFO, ModuleName.TMRobot, "TMRobot is busy, please wait a minute");
  371. return false;
  372. }
  373. else if (Status == RState.Failed || Status == RState.Timeout)
  374. {
  375. LOG.Write(eEvent.ERR_DEVICE_INFO, ModuleName.TMRobot, "TMRobot has a error, please check and fix the hardware issue and home it");
  376. return false;
  377. }
  378. return true;
  379. }
  380. private void OnReceiveMessage(string revMsg)
  381. {
  382. string[] ResMsgs = revMsg.Split('\r');
  383. foreach (string revRawMsg in ResMsgs)
  384. {
  385. if (string.IsNullOrWhiteSpace(revRawMsg)) continue;
  386. string RevMsg = revRawMsg.Trim();
  387. LOG.WriteSingeLine(eEvent.INFO_TM_ROBOT, ModuleName.TMRobot, $"Receive message from TMRobot: {RevMsg}, while {_currentStep}");
  388. if (_rex_error_code.IsMatch(RevMsg))
  389. {
  390. _IsHomed = false;
  391. _status = RState.Failed;
  392. var results = _rex_error_code.Match(RevMsg);
  393. ErrorMessageHandler(results.Groups[1].Value);
  394. return;
  395. }
  396. switch (_currentStep)
  397. {
  398. case VRStep.Goto:
  399. case VRStep.Halt:
  400. case VRStep.Move:
  401. case VRStep.Xfer:
  402. case VRStep.SetSpeed:
  403. case VRStep.SaveSpeed:
  404. case VRStep.Pick:
  405. case VRStep.PickExtend:
  406. case VRStep.PickRetract:
  407. case VRStep.Place:
  408. case VRStep.PlaceExtend:
  409. case VRStep.PlaceRetract:
  410. {
  411. if (RevMsg.Trim() == "_RDY" || (RevMsg.Contains("_RDY") && !RevMsg.Contains("_ERR")))
  412. {
  413. _currentStep = VRStep.Idle;
  414. _status = RState.End;
  415. }
  416. else
  417. {
  418. ReportWrongMsg(RevMsg);
  419. }
  420. if (_currentStep != VRStep.PickExtend && _currentStep != VRStep.PlaceExtend)
  421. SetRobotMovingInfo(RobotAction.None, Hand.Both, ModuleName.TMRobot);
  422. }
  423. break;
  424. case VRStep.Home:
  425. {
  426. if (RevMsg.Trim() == "_RDY")
  427. {
  428. //CheckLoad(Hand.Blade1);
  429. _currentStep = VRStep.Idle;
  430. _status = RState.End;
  431. _IsHomed = true;
  432. SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.TMRobot);
  433. }
  434. else
  435. ReportWrongMsg(RevMsg);
  436. }
  437. break;
  438. case VRStep.CheckLoad_ArmA:
  439. {
  440. if (_rex_check_load.IsMatch(RevMsg))
  441. {
  442. GetCheckLoadResult(RevMsg);
  443. //CheckLoad(Hand.Blade2);
  444. }
  445. if (RevMsg.Trim() == "_RDY" || (RevMsg.Contains("_RDY") && !RevMsg.Contains("_ERR")))
  446. {
  447. _currentStep = VRStep.Idle;
  448. _status = RState.End;
  449. }
  450. }
  451. break;
  452. case VRStep.CheckLoad_ArmB:
  453. {
  454. if (_rex_check_load.IsMatch(RevMsg))
  455. {
  456. GetCheckLoadResult(RevMsg);
  457. //_currentStep = VRStep.Idle;
  458. //_status = RState.End;
  459. //_IsHomed = true;
  460. }
  461. if (RevMsg.Trim() == "_RDY" || (RevMsg.Contains("_RDY") && !RevMsg.Contains("_ERR")))
  462. {
  463. _currentStep = VRStep.Idle;
  464. _status = RState.End;
  465. }
  466. }
  467. break;
  468. case VRStep.ReQueryLoadA:
  469. if (_rex_rq_load_A.IsMatch(RevMsg))
  470. {
  471. string WaferStatus = RevMsg.Split(' ')[2];
  472. //LOG.Write(eEvent.WARN_DEFAULT_WARN, ModuleName.TMRobot, WaferStatus);
  473. if (WaferStatus.Contains("ON") && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0))
  474. {
  475. WaferManager.Instance.CreateWafer(ModuleName.TMRobot, 0, Aitex.Core.Common.WaferStatus.Normal);
  476. }
  477. if (WaferStatus.Contains("OFF"))
  478. {
  479. //LOG.Write(eEvent.WARN_DEFAULT_WARN, ModuleName.TMRobot, "contains off");
  480. WaferManager.Instance.DeleteWafer(ModuleName.TMRobot, 0);
  481. }
  482. }
  483. else
  484. {
  485. if (RevMsg.Trim() == "_RDY" || (RevMsg.Contains("_RDY") && !RevMsg.Contains("_ERR")))
  486. {
  487. _currentStep = VRStep.Idle;
  488. _status = RState.End;
  489. }
  490. else
  491. {
  492. ReportWrongMsg(RevMsg);
  493. }
  494. }
  495. break;
  496. case VRStep.ReQueryLoadB:
  497. if (_rex_rq_load_B.IsMatch(RevMsg))
  498. {
  499. string WaferStatus = RevMsg.Split(' ')[2];
  500. //LOG.Write(eEvent.WARN_DEFAULT_WARN, ModuleName.TMRobot, WaferStatus);
  501. if (WaferStatus.Contains("ON") && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  502. {
  503. WaferManager.Instance.CreateWafer(ModuleName.TMRobot, 1, Aitex.Core.Common.WaferStatus.Normal);
  504. }
  505. if (WaferStatus.Contains("OFF"))
  506. {
  507. WaferManager.Instance.DeleteWafer(ModuleName.TMRobot, 1);
  508. }
  509. }
  510. else
  511. {
  512. if (RevMsg.Trim() == "_RDY" || (RevMsg.Contains("_RDY") && !RevMsg.Contains("_ERR")))
  513. {
  514. _currentStep = VRStep.Idle;
  515. _status = RState.End;
  516. }
  517. else
  518. {
  519. ReportWrongMsg(RevMsg);
  520. }
  521. }
  522. break;
  523. case VRStep.RQSpeed:
  524. //MOTIONPARA {} SPDPCT all r t z
  525. if (_rex_rq_speed.IsMatch(RevMsg))
  526. {
  527. string[] _msgs = RevMsg.Split(' ');
  528. if (_msgs[1] == "WITHWAFER")
  529. {
  530. _WithWaferSpeed = _msgs[4];
  531. }
  532. if (_msgs[1] == "NOWAFER")
  533. {
  534. _NoWaferSpeed = _msgs[4];
  535. }
  536. if (_msgs[1] == "MIDDLE")
  537. {
  538. _WithWaferSpeed = _msgs[4];
  539. }
  540. }
  541. else
  542. {
  543. if (RevMsg.Trim() == "_RDY" || (RevMsg.Contains("_RDY") && !RevMsg.Contains("_ERR")))
  544. {
  545. _currentStep = VRStep.Idle;
  546. _status = RState.End;
  547. }
  548. else
  549. {
  550. ReportWrongMsg(RevMsg);
  551. }
  552. }
  553. break;
  554. default:
  555. if (!RevMsg.Contains("_EVENT"))
  556. ReportWrongMsg(RevMsg);
  557. break;
  558. }
  559. }
  560. }
  561. private void GetCheckLoadResult(string revMsg)
  562. {
  563. Match result = _rex_check_load.Match(revMsg);
  564. string Arm = result.Groups[1].Value;
  565. string WaferStatus = result.Groups[2].Value;
  566. if (WaferStatus == "ON")
  567. {
  568. WaferManager.Instance.CreateWafer(ModuleName.TMRobot, Arm == "A" ? 0 : 1, Aitex.Core.Common.WaferStatus.Unknown);
  569. }
  570. }
  571. private void ErrorMessageHandler(string errorcode)
  572. {
  573. _status = RState.Failed;
  574. string ErrorInfo;
  575. if (_error2msg.ContainsKey(errorcode))
  576. {
  577. ErrorInfo = _error2msg[errorcode];
  578. LOG.Write(eEvent.ERR_DEVICE_INFO, ModuleName.TMRobot, ErrorInfo);
  579. }
  580. else
  581. {
  582. LOG.Write(eEvent.ERR_DEVICE_INFO, ModuleName.TMRobot, $"Dictionary Not Contains error code:{errorcode}");
  583. }
  584. _IsHomed = false;
  585. }
  586. private void OnErrorHappen(ErrorEventArgs args)
  587. {
  588. //Singleton<RouteManager>.Instance.SETM.PostMsg(SETMEntity.MSG.Error);
  589. LOG.Write(eEvent.ERR_DEVICE_INFO, ModuleName.TMRobot, $"HongHu TMRobot Error: {args.Reason} while {_currentStep}");
  590. }
  591. private void ReportWrongMsg(string revMsg)
  592. {
  593. LOG.Write(eEvent.WARN_DEVICE_INFO, ModuleName.TMRobot, $"Receive wrong message:{revMsg} while {_currentStep}");
  594. }
  595. public void SetRobotMovingInfo(RobotAction action, Hand hand, ModuleName target)
  596. {
  597. //_robotMoveInfo.Action = action;
  598. //_robotMoveInfo.ArmTarget = hand == Hand.Blade1 ? RobotArm.ArmA : (hand == Hand.Both ? RobotArm.Both : RobotArm.ArmB);
  599. //_robotMoveInfo.BladeTarget = $"{_robotMoveInfo.ArmTarget}.{target}";
  600. blockingCollection.Add(new RobotAnimationData(action, hand, target));
  601. }
  602. }
  603. }