RobotBase.cs 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Fsm;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading.Tasks;
  16. using MECF.Framework.Common.CommonData;
  17. using MECF.Framework.Common.Event;
  18. using Aitex.Core.RT.Log;
  19. using Aitex.Core.Common;
  20. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase
  21. {
  22. public abstract class RobotBaseDevice : Entity, IDevice, IRobot, IEntity
  23. {
  24. public event Action<ModuleName, string> OnSlotMapRead;
  25. public virtual string SlotMap { get; set; }
  26. public event Action<bool> ActionDone;
  27. public event Action<string, AlarmEventItem> OnDeviceAlarmStateChanged;
  28. public bool HasAlarm { get; }
  29. private bool _isBusy;
  30. public bool IsBusy
  31. {
  32. get { return _isBusy; }
  33. set
  34. {
  35. if (_isBusy != value)
  36. LOG.Write($"Set {RobotModuleName} IsBusy flag to {value}");
  37. _isBusy = value;
  38. }
  39. }
  40. public AlarmEventItem RobotHasError { get; set; }
  41. public bool IsCarrierMove { get; set; }
  42. public bool IsWaferRobot { get; set; }
  43. public string ErrorCode { get; set; } = "";
  44. public virtual bool IsReady()
  45. {
  46. return RobotState == RobotStateEnum.Idle && !IsBusy;
  47. }
  48. public virtual bool IsReady(out string reason)
  49. {
  50. reason = "";
  51. return RobotState == RobotStateEnum.Idle && !IsBusy;
  52. }
  53. public object[] CurrentParamter { get; private set; }
  54. public bool IsPause { get; set; }
  55. public bool IsOnline { get; set; }
  56. public ModuleName BladeTarget { get; set; }
  57. public ModuleName Blade1Target { get; set; }
  58. public ModuleName Blade2Target { get; set; }
  59. public virtual Dictionary<string, string> ModuleAssociateStationDic { get; set; }
  60. public BladePostureEnum Blade1Posture { get; set; } = BladePostureEnum.Degree0;
  61. public BladePostureEnum Blade1ActionPosture { get; set; }
  62. public virtual bool IsWaferPresenceOnBlade1 { get; set; }
  63. public virtual bool IsWaferPresenceOnBlade2 { get; set; }
  64. public virtual bool IsWaferPresenceOnBlade3 { get; set; }
  65. public virtual bool IsWaferPresenceOnBlade4 { get; set; }
  66. public virtual bool IsWaferPresenceOnBlade5 { get; set; }
  67. public bool IsIdle
  68. {
  69. get
  70. {
  71. return fsm.State == (int)RobotStateEnum.Idle && fsm.CheckExecuted() && !IsBusy;
  72. }
  73. }
  74. public bool IsError
  75. {
  76. get
  77. {
  78. return fsm.State == (int)RobotStateEnum.Error || fsm.State == (int)RobotStateEnum.Stopped;
  79. }
  80. }
  81. public bool IsInit
  82. {
  83. get
  84. {
  85. return fsm.State == (int)RobotStateEnum.Init;
  86. }
  87. }
  88. public virtual bool Blade1Enable
  89. {
  90. get
  91. {
  92. if (SC.ContainsItem($"{ScRoot}.{Name}.Blade1Enable"))
  93. {
  94. return SC.GetValue<bool>($"{ScRoot}.{Name}.Blade1Enable");
  95. }
  96. return SC.GetValue<bool>($"Robot.Blade1Enable");
  97. }
  98. set
  99. {
  100. if (SC.ContainsItem($"{ScRoot}.{Name}.Blade1Enable"))
  101. {
  102. SC.SetItemValue($"{ScRoot}.{Name}.Blade1Enable", value);
  103. }
  104. else if (SC.ContainsItem($"Robot.Blade1Enable"))
  105. {
  106. SC.SetItemValue($"Robot.Blade1Enable", value);
  107. }
  108. }
  109. }
  110. public virtual bool Blade2Enable
  111. {
  112. get
  113. {
  114. if (SC.ContainsItem($"{ScRoot}.{Name}.Blade2Enable"))
  115. {
  116. return SC.GetValue<bool>($"{ScRoot}.{Name}.Blade2Enable");
  117. }
  118. return SC.GetValue<bool>($"Robot.Blade2Enable");
  119. }
  120. set
  121. {
  122. if (SC.ContainsItem($"{ScRoot}.{Name}.Blade2Enable"))
  123. {
  124. SC.SetItemValue($"{ScRoot}.{Name}.Blade2Enable", value);
  125. }
  126. else if (SC.ContainsItem($"Robot.Blade2Enable"))
  127. {
  128. SC.SetItemValue($"Robot.Blade2Enable", value);
  129. }
  130. }
  131. }
  132. public int Blade2Slots
  133. {
  134. get
  135. {
  136. if (SC.ContainsItem($"{ScRoot}.{Name}.Blade2Slots"))
  137. {
  138. return Math.Max(SC.GetValue<int>($"{ScRoot}.{Name}.Blade2Slots"), 1);
  139. }
  140. if (SC.ContainsItem($"Robot.Blade2Slots"))
  141. {
  142. return Math.Max(SC.GetValue<int>($"Robot.Blade2Slots"), 1);
  143. }
  144. return 1;
  145. }
  146. }
  147. public WaferSize Size
  148. {
  149. get; set;
  150. } = WaferSize.WS12;
  151. public virtual WaferSize GetCurrentWaferSize()
  152. {
  153. return Size;
  154. }
  155. public virtual LinkedList<string> CommandMessages
  156. {
  157. get; set;
  158. } = new LinkedList<string>();
  159. private List<string> _commandMsgs
  160. {
  161. get
  162. {
  163. List<string> ret = new List<string>();
  164. foreach (var msg in CommandMessages)
  165. {
  166. ret.Add(msg);
  167. }
  168. return ret;
  169. }
  170. }
  171. public RobotMoveInfo MoveInfo { get; set; }
  172. public RobotArmEnum CmdRobotArm { get; set; }
  173. public ModuleName CmdTarget { get; set; }
  174. public int CmdTargetSlot { get; set; }
  175. public int SpeedAxis1 { set; get; }
  176. public int SpeedAxis2 { set; get; }
  177. public int SpeedAxis3 { set; get; }
  178. public int SpeedAxis4 { set; get; }
  179. public int SpeedAxis5 { set; get; }
  180. public int SpeedAxis6 { set; get; }
  181. public int Speed { set; get; }
  182. public float PositionAxis1 { get; set; }
  183. public float PositionAxis2 { get; set; }
  184. public float PositionAxis3 { get; set; }
  185. public float PositionAxis4 { get; set; }
  186. public float PositionAxis5 { get; set; }
  187. public float PositionAxis6 { get; set; }
  188. public string[] ReadMappingUpData { get; protected set; }
  189. public string[] ReadMappingDownData { get; protected set; }
  190. public virtual int RobotCommandTimeout
  191. {
  192. get
  193. {
  194. if (SC.ContainsItem($"Robot.{RobotModuleName}.TimeLimitRobotCommand"))
  195. return SC.GetValue<int>($"Robot.{RobotModuleName}.TimeLimitRobotCommand");
  196. return 90;
  197. }
  198. }
  199. public enum RobotMsg
  200. {
  201. Reset,
  202. Clear,
  203. ResetToReady,
  204. Stop,
  205. StartInit,
  206. InitComplete,
  207. ERROR,
  208. ActionDone = 7,
  209. Abort,
  210. StartHome,
  211. HomeComplete,
  212. StartMaintenance,
  213. CompleteMaintenance,
  214. ReadData,
  215. ReadDataComplete,
  216. SetParameters,
  217. SetParametersComplete,
  218. Move,
  219. MoveComplete,
  220. PickWafer,
  221. PickComplete,
  222. PlaceWafer,
  223. PlaceComplete,
  224. SwapWafer,
  225. SwapComplete,
  226. MapWafer,
  227. MapComplete,
  228. GoToPosition,
  229. ArrivedPosition,
  230. Grip,
  231. GripComplete,
  232. UnGrip,
  233. UnGripComplete,
  234. ExtendForPlace,
  235. ExtendForPick,
  236. ExtendComplete,
  237. RetractFromPlace,
  238. RetractFromPick,
  239. RetractComplete,
  240. TransferWafer,
  241. TransferComplete,
  242. PickCassette,
  243. PickCassetteComplete,
  244. PlaceCassette,
  245. PlaceCassetteComplete,
  246. ExecuteCommand,
  247. }
  248. protected RobotBaseDevice(string module, string name, string scRoot = "Robot")
  249. : base()
  250. {
  251. Module = module;
  252. Name = name;
  253. ScRoot = scRoot;
  254. RobotModuleName = (ModuleName)Enum.Parse(typeof(ModuleName), Name);
  255. InitializeRobot();
  256. }
  257. protected override bool Init()
  258. {
  259. return base.Init();
  260. }
  261. public virtual void InitializeRobot()
  262. {
  263. BuildTransitionTable();
  264. SubscribeDataVariable();
  265. SubscribeOperation();
  266. SubscribeDeviceOperation();
  267. MoveInfo = new RobotMoveInfo()
  268. {
  269. Action = RobotAction.Moving,
  270. ArmTarget = RobotArm.Both,
  271. BladeTarget = "ArmA.System",
  272. };
  273. SubscribeWaferLocation();
  274. Running = true;
  275. }
  276. protected virtual void SubscribeWaferLocation()
  277. {
  278. WaferManager.Instance.SubscribeLocation(Name, 2);
  279. }
  280. protected virtual void SubscribeOperation()
  281. {
  282. OP.Subscribe(String.Format("{0}.{1}", Name, "MapWafer"), (out string reason, int time, object[] param) =>
  283. {
  284. ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), param[0].ToString(), true);
  285. bool ret = WaferMapping(chamber);
  286. if (ret)
  287. {
  288. reason = string.Format("{0} {1}", Name, "Map wafer succesfully");
  289. return true;
  290. }
  291. reason = $"{Name} map wafer failed";
  292. return false;
  293. });
  294. OP.Subscribe(String.Format("{0}.{1}", Name, "ExecuteCommand"), (out string reason, int time, object[] param) =>
  295. {
  296. bool ret = ExecuteCommand(param);
  297. if (ret)
  298. {
  299. reason = string.Format("{0} {1}", Name, "Execute command succesfully");
  300. return true;
  301. }
  302. reason = $"{Name} execute failed";
  303. return false;
  304. });
  305. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotFlippe"), (out string reason, int time, object[] param) =>
  306. {
  307. bool isto0 = Convert.ToBoolean(param[0]);
  308. bool ret = RobotFlippe(isto0);
  309. if (ret)
  310. {
  311. reason = string.Format("{0} {1}", Name, $"Flippe to {(isto0 ? "0 degree" : "180 Degree")} command succesfully");
  312. return true;
  313. }
  314. reason = $"{Name} Flippe failed";
  315. return false;
  316. });
  317. OP.Subscribe(String.Format("{0}.{1}", Name, "SetWaferSize"), (out string reason, int time, object[] param) =>
  318. {
  319. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), param[0].ToString());
  320. WaferSize size = (WaferSize)Enum.Parse(typeof(WaferSize), param[1].ToString());
  321. bool ret = SetWaferSize(arm, size);
  322. if (ret)
  323. {
  324. reason = string.Format("{0} {1}", Name, "Set Wafer size");
  325. return true;
  326. }
  327. reason = $"{Name} not ready";
  328. return false;
  329. });
  330. OP.Subscribe(String.Format("{0}.{1}", Name, "PickCassette"), (out string reason, int time, object[] param) =>
  331. {
  332. bool ret = PickCassette(RobotArmEnum.Blade1, param[0].ToString(), 0);
  333. if (ret)
  334. {
  335. reason = string.Format("{0} {1}", Name, "Pick cassette");
  336. return true;
  337. }
  338. reason = $"{Name} not ready";
  339. return false;
  340. });
  341. OP.Subscribe(String.Format("{0}.{1}", Name, "PlaceCassette"), (out string reason, int time, object[] param) =>
  342. {
  343. bool ret = PlaceCassette(RobotArmEnum.Blade1, param[0].ToString(), 0);
  344. if (ret)
  345. {
  346. reason = string.Format("{0} {1}", Name, "Pick cassette");
  347. return true;
  348. }
  349. reason = $"{Name} not ready";
  350. return false;
  351. });
  352. OP.Subscribe(String.Format("{0}.{1}", Name, "Init"), (out string reason, int time, object[] param) =>
  353. {
  354. bool ret = Home(param);
  355. if (ret)
  356. {
  357. reason = string.Format("{0} {1}", Name, "Initializing");
  358. return true;
  359. }
  360. reason = "";
  361. return false;
  362. });
  363. OP.Subscribe(String.Format("{0}.{1}", Name, "Abort"), (out string reason, int time, object[] param) =>
  364. {
  365. bool ret = Abort();
  366. if (ret)
  367. {
  368. reason = string.Format("{0} {1}", Name, "Abort");
  369. return true;
  370. }
  371. reason = "";
  372. return false;
  373. });
  374. OP.Subscribe(String.Format("{0}.{1}", Name, "Home"), (out string reason, int time, object[] param) =>
  375. {
  376. bool ret = Home(param);
  377. if (ret)
  378. {
  379. reason = string.Format("{0} {1}", Name, "Homing");
  380. return true;
  381. }
  382. reason = "";
  383. return false;
  384. });
  385. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotHome"), (out string reason, int time, object[] param) =>
  386. {
  387. bool ret = Home(param);
  388. if (ret)
  389. {
  390. reason = string.Format("{0} {1}", Name, "Homing");
  391. return true;
  392. }
  393. reason = "";
  394. return false;
  395. });
  396. OP.Subscribe(String.Format("{0}.{1}", Name, "HomeModule"), (out string reason, int time, object[] param) =>
  397. {
  398. bool ret = HomeModule(param);
  399. if (ret)
  400. {
  401. reason = string.Format("{0} {1}", Name, "ModuleHoming");
  402. return true;
  403. }
  404. reason = "";
  405. return false;
  406. });
  407. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotHomeModule"), (out string reason, int time, object[] param) =>
  408. {
  409. bool ret = HomeModule(param);
  410. if (ret)
  411. {
  412. reason = string.Format("{0} {1}", Name, "ModuleHomingHoming");
  413. return true;
  414. }
  415. reason = "";
  416. return false;
  417. });
  418. OP.Subscribe(String.Format("{0}.{1}", Name, "Reset"), (out string reason, int time, object[] param) =>
  419. {
  420. RobotReset();
  421. reason = "";
  422. return true;
  423. });
  424. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotReset"), (out string reason, int time, object[] param) =>
  425. {
  426. RobotReset();
  427. reason = "";
  428. return true;
  429. });
  430. OP.Subscribe(String.Format("{0}.{1}", Name, "Grip"), (out string reason, int time, object[] param) =>
  431. {
  432. Hand hand = (Hand)Enum.Parse(typeof(Hand), param[0].ToString(), true);
  433. RobotArmEnum arm = (RobotArmEnum)((int)hand);
  434. bool ret = Grip(arm);
  435. if (ret)
  436. {
  437. reason = string.Format("{0} {1}", Name, "Grip");
  438. return true;
  439. }
  440. reason = $"{Name} busy";
  441. return false;
  442. });
  443. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotGrip"), (out string reason, int time, object[] param) =>
  444. {
  445. //Hand hand = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), (string)param[0], );
  446. string strarm = Regex.Replace(param[0].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  447. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), strarm);
  448. bool ret = Grip(arm);
  449. if (ret)
  450. {
  451. reason = string.Format("{0} {1}", Name, "Grip");
  452. return true;
  453. }
  454. reason = $"{Name} busy";
  455. return false;
  456. });
  457. OP.Subscribe(String.Format("{0}.{1}", Name, "Release"), (out string reason, int time, object[] param) =>
  458. {
  459. Hand hand = (Hand)Enum.Parse(typeof(Hand), param[0].ToString(), true);
  460. RobotArmEnum arm = (RobotArmEnum)((int)hand);
  461. bool ret = Release(arm);
  462. if (ret)
  463. {
  464. reason = string.Format("{0} {1}", Name, "Release");
  465. return true;
  466. }
  467. reason = $"{Name} busy";
  468. return false;
  469. });
  470. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotRelease"), (out string reason, int time, object[] param) =>
  471. {
  472. //Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[0], true);
  473. string strarm = Regex.Replace(param[0].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  474. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), strarm);
  475. bool ret = Release(arm);
  476. if (ret)
  477. {
  478. reason = string.Format("{0} {1}", Name, "Release");
  479. return true;
  480. }
  481. reason = $"{Name} busy";
  482. return false;
  483. });
  484. OP.Subscribe(String.Format("{0}.{1}", Name, "Stop"), (out string reason, int time, object[] param) =>
  485. {
  486. bool ret = Stop();
  487. if (ret)
  488. {
  489. reason = string.Format("{0} {1}", Name, "Stopping");
  490. return true;
  491. }
  492. reason = $"{Name} busy";
  493. return false;
  494. });
  495. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotStop"), (out string reason, int time, object[] param) =>
  496. {
  497. bool ret = Stop();
  498. if (ret)
  499. {
  500. reason = string.Format("{0} {1}", Name, "Stopping");
  501. return true;
  502. }
  503. reason = $"{Name} busy";
  504. return false;
  505. });
  506. OP.Subscribe(String.Format("{0}.{1}", Name, "Pick"), (out string reason, int time, object[] param) =>
  507. {
  508. //ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), (string)param[0], true);
  509. string station = (string)param[0];
  510. int slot = int.Parse(param[1].ToString());
  511. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  512. RobotArmEnum arm = (RobotArmEnum)((int)hand);
  513. bool ret = Pick(arm, station, slot);
  514. if (ret)
  515. {
  516. reason = string.Format("{0} {1}", Name, "Pick wafer");
  517. return true;
  518. }
  519. reason = $"{Name} busy";
  520. return false;
  521. });
  522. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotPick"), (out string reason, int time, object[] param) =>
  523. {
  524. string station = (string)param[0];
  525. int slot = int.Parse((string)param[1]);
  526. string strarm = Regex.Replace(param[2].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  527. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), strarm);
  528. bool ret = Pick(arm, station, slot);
  529. if (ret)
  530. {
  531. reason = string.Format("{0} {1}", Name, "Pick wafer");
  532. return true;
  533. }
  534. reason = $"{Name} busy";
  535. return false;
  536. });
  537. OP.Subscribe(String.Format("{0}.{1}", Name, "Place"), (out string reason, int time, object[] param) =>
  538. {
  539. string station = (string)param[0];
  540. int slot = int.Parse(param[1].ToString());
  541. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  542. RobotArmEnum arm = (RobotArmEnum)((int)hand);
  543. bool ret = Place(arm, station, slot);
  544. if (ret)
  545. {
  546. reason = string.Format("{0} {1}", Name, "Place wafer");
  547. return true;
  548. }
  549. reason = $"{Name} busy";
  550. return false;
  551. });
  552. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotPlace"), (out string reason, int time, object[] param) =>
  553. {
  554. string station = (string)param[0];
  555. int slot = int.Parse((string)param[1]);
  556. string strarm = Regex.Replace(param[2].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  557. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), strarm);
  558. bool ret = Place(arm, station, slot);
  559. if (ret)
  560. {
  561. reason = string.Format("{0} {1}", Name, "Place wafer");
  562. return true;
  563. }
  564. reason = $"{Name} busy";
  565. return false;
  566. });
  567. OP.Subscribe(String.Format("{0}.{1}", Name, "Exchange"), (out string reason, int time, object[] param) =>
  568. {
  569. string station = (string)param[0];
  570. int slot = int.Parse((string)param[1]);
  571. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  572. RobotArmEnum arm = (RobotArmEnum)((int)hand);
  573. bool ret = Swap(arm, station, slot);//, slot, hand, out reason);
  574. if (ret)
  575. {
  576. reason = string.Format("{0} {1}", Name, "Swap wafer");
  577. return true;
  578. }
  579. reason = $"{Name} busy";
  580. return false;
  581. });
  582. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotExchange"), (out string reason, int time, object[] param) =>
  583. {
  584. string station = (string)param[0];
  585. int slot = int.Parse((string)param[1]);
  586. string strarm = Regex.Replace(param[2].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  587. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), strarm);
  588. bool ret = Swap(arm, station, slot);//, slot, hand, out reason);
  589. if (ret)
  590. {
  591. reason = string.Format("{0} {1}", Name, "Swap wafer");
  592. return true;
  593. }
  594. reason = $"{Name} busy";
  595. return false;
  596. });
  597. OP.Subscribe(String.Format("{0}.{1}", Name, "Goto"), (out string reason, int time, object[] param) =>
  598. {
  599. bool ret = GoTo(param);
  600. if (ret)
  601. {
  602. reason = string.Format("{0}{1}", Name, "Goto");
  603. return true;
  604. }
  605. reason = $"{Name} busy";
  606. return false;
  607. });
  608. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotGoto"), (out string reason, int time, object[] param) =>
  609. {
  610. bool ret = GoTo(param);
  611. if (ret)
  612. {
  613. reason = string.Format("{0}{1}", Name, "Goto");
  614. return true;
  615. }
  616. reason = $"{Name} busy";
  617. return false;
  618. });
  619. OP.Subscribe(String.Format("{0}.{1}", Name, "SetSpeed"), (out string reason, int time, object[] param) =>
  620. {
  621. bool ret = SetSpeed(param);
  622. if (ret)
  623. {
  624. reason = string.Format("{0}{1}", Name, "SetSpeed");
  625. return true;
  626. }
  627. reason = $"{Name} busy";
  628. return false;
  629. });
  630. OP.Subscribe(String.Format("{0}.{1}", Name, "SetParameter"), (out string reason, int time, object[] param) =>
  631. {
  632. bool ret = SetParameter(param);
  633. if (ret)
  634. {
  635. reason = string.Format("{0}{1}", Name, "SetParameter");
  636. return true;
  637. }
  638. reason = $"{Name} busy";
  639. return false;
  640. });
  641. OP.Subscribe(String.Format("{0}.{1}", Name, "ReadParameter"), (out string reason, int time, object[] param) =>
  642. {
  643. bool ret = ReadParameter(param);
  644. if (ret)
  645. {
  646. reason = string.Format("{0}{1}", Name, "ReadData");
  647. return true;
  648. }
  649. reason = $"{Name} busy";
  650. return false;
  651. });
  652. OP.Subscribe(String.Format("{0}.{1}", Name, "RobotMove"), (out string reason, int time, object[] param) =>
  653. {
  654. bool ret = Move(param);
  655. if (ret)
  656. {
  657. reason = string.Format("{0}{1}", Name, "MovePostion");
  658. return true;
  659. }
  660. reason = $"{Name} busy";
  661. return false;
  662. });
  663. OP.Subscribe(String.Format("{0}.{1}", Name, "SetRobotParameters"), (out string reason, int time, object[] param) =>
  664. {
  665. bool ret = SetRobotParameters(param);
  666. if (ret)
  667. {
  668. reason = string.Format("{0}{1}", Name, param[0]);
  669. return true;
  670. }
  671. reason = $"{Name} busy";
  672. return false;
  673. });
  674. OP.Subscribe(String.Format("{0}.{1}", Name, "ReadRobotParameters"), (out string reason, int time, object[] param) =>
  675. {
  676. bool ret = ReadParameter(param);
  677. if (ret)
  678. {
  679. reason = string.Format("{0}{1}", Name, "ReadRobotParameters");
  680. return true;
  681. }
  682. reason = $"{Name} busy";
  683. return false;
  684. });
  685. }
  686. protected virtual void SubscribeDeviceOperation()
  687. {
  688. DEVICE.Register(String.Format("{0}.{1}", Name, "Init"), (out string reason, int time, object[] param) =>
  689. {
  690. bool ret = Home(param);
  691. if (ret)
  692. {
  693. reason = string.Format("{0} {1}", Name, "Initializing");
  694. return true;
  695. }
  696. reason = "";
  697. return false;
  698. });
  699. DEVICE.Register(String.Format("{0}.{1}", Name, "Home"), (out string reason, int time, object[] param) =>
  700. {
  701. bool ret = Home(param);
  702. if (ret)
  703. {
  704. reason = string.Format("{0} {1}", Name, "Homing");
  705. return true;
  706. }
  707. reason = "";
  708. return false;
  709. });
  710. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotHome"), (out string reason, int time, object[] param) =>
  711. {
  712. bool ret = Home(param);
  713. if (ret)
  714. {
  715. reason = string.Format("{0} {1}", Name, "Homing");
  716. return true;
  717. }
  718. reason = "";
  719. return false;
  720. });
  721. DEVICE.Register(String.Format("{0}.{1}", Name, "HomeModule"), (out string reason, int time, object[] param) =>
  722. {
  723. bool ret = HomeModule(param);
  724. if (ret)
  725. {
  726. reason = string.Format("{0} {1}", Name, "Homing");
  727. return true;
  728. }
  729. reason = "";
  730. return false;
  731. });
  732. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotHomeModule"), (out string reason, int time, object[] param) =>
  733. {
  734. bool ret = HomeModule(param);
  735. if (ret)
  736. {
  737. reason = string.Format("{0} {1}", Name, "Homing");
  738. return true;
  739. }
  740. reason = "";
  741. return false;
  742. });
  743. DEVICE.Register(String.Format("{0}.{1}", Name, "Reset"), (out string reason, int time, object[] param) =>
  744. {
  745. RobotReset();
  746. reason = "";
  747. return true;
  748. });
  749. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotReset"), (out string reason, int time, object[] param) =>
  750. {
  751. RobotReset();
  752. reason = "";
  753. return true;
  754. });
  755. DEVICE.Register(String.Format("{0}.{1}", Name, "Grip"), (out string reason, int time, object[] param) =>
  756. {
  757. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[0], true);
  758. RobotArmEnum arm = (RobotArmEnum)((int)hand);
  759. bool ret = Grip(arm);
  760. if (ret)
  761. {
  762. reason = string.Format("{0} {1}", Name, "Grip");
  763. return true;
  764. }
  765. reason = "";
  766. return false;
  767. });
  768. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotGrip"), (out string reason, int time, object[] param) =>
  769. {
  770. //Hand hand = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), (string)param[0], );
  771. string strarm = Regex.Replace(param[0].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  772. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), strarm);
  773. bool ret = Grip(arm);
  774. if (ret)
  775. {
  776. reason = string.Format("{0} {1}", Name, "Grip");
  777. return true;
  778. }
  779. reason = "";
  780. return false;
  781. });
  782. DEVICE.Register(String.Format("{0}.{1}", Name, "Release"), (out string reason, int time, object[] param) =>
  783. {
  784. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[0], true);
  785. RobotArmEnum arm = (RobotArmEnum)((int)hand);
  786. bool ret = Release(arm);
  787. if (ret)
  788. {
  789. reason = string.Format("{0} {1}", Name, "Release");
  790. return true;
  791. }
  792. reason = "";
  793. return false;
  794. });
  795. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotRelease"), (out string reason, int time, object[] param) =>
  796. {
  797. //Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[0], true);
  798. string strarm = Regex.Replace(param[0].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  799. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), strarm);
  800. bool ret = Release(arm);
  801. //bool ret = QueryWaferMap(ModuleName.LP1, out reason);
  802. if (ret)
  803. {
  804. reason = string.Format("{0} {1}", Name, "Release");
  805. return true;
  806. }
  807. reason = "";
  808. return false;
  809. });
  810. DEVICE.Register(String.Format("{0}.{1}", Name, "Stop"), (out string reason, int time, object[] param) =>
  811. {
  812. bool ret = Stop();
  813. if (ret)
  814. {
  815. reason = string.Format("{0} {1}", Name, "Stopping");
  816. return true;
  817. }
  818. reason = "";
  819. return false;
  820. });
  821. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotStop"), (out string reason, int time, object[] param) =>
  822. {
  823. bool ret = Stop();
  824. if (ret)
  825. {
  826. reason = string.Format("{0} {1}", Name, "Stopping");
  827. return true;
  828. }
  829. reason = "";
  830. return false;
  831. });
  832. DEVICE.Register(String.Format("{0}.{1}", Name, "Pick"), (out string reason, int time, object[] param) =>
  833. {
  834. //ModuleName chamber = (ModuleName)Enum.Parse(typeof(ModuleName), (string)param[0], true);
  835. string station = (string)param[0];
  836. int slot = int.Parse((string)param[1]);
  837. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  838. RobotArmEnum arm = (RobotArmEnum)((int)hand);
  839. bool ret = Pick(arm, station, slot);
  840. if (ret)
  841. {
  842. reason = string.Format("{0} {1}", Name, "Pick wafer");
  843. return true;
  844. }
  845. reason = "";
  846. return false;
  847. });
  848. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotPick"), (out string reason, int time, object[] param) =>
  849. {
  850. string station = (string)param[0];
  851. int slot = int.Parse((string)param[1]);
  852. string strarm = Regex.Replace(param[2].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  853. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), strarm);
  854. bool ret = Pick(arm, station, slot);
  855. if (ret)
  856. {
  857. reason = string.Format("{0} {1}", Name, "Pick wafer");
  858. return true;
  859. }
  860. reason = "";
  861. return false;
  862. });
  863. DEVICE.Register(String.Format("{0}.{1}", Name, "Place"), (out string reason, int time, object[] param) =>
  864. {
  865. string station = (string)param[0];
  866. int slot = int.Parse((string)param[1]);
  867. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  868. RobotArmEnum arm = (RobotArmEnum)((int)hand);
  869. bool ret = Place(arm, station, slot);
  870. if (ret)
  871. {
  872. reason = string.Format("{0} {1}", Name, "Place wafer");
  873. return true;
  874. }
  875. reason = $"{Name} busy";
  876. return false;
  877. });
  878. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotPlace"), (out string reason, int time, object[] param) =>
  879. {
  880. string station = (string)param[0];
  881. int slot = int.Parse((string)param[1]);
  882. string strarm = Regex.Replace(param[2].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  883. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), strarm);
  884. bool ret = Place(arm, station, slot);
  885. if (ret)
  886. {
  887. reason = string.Format("{0} {1}", Name, "Place wafer");
  888. return true;
  889. }
  890. reason = $"{Name} busy";
  891. return false;
  892. });
  893. DEVICE.Register(String.Format("{0}.{1}", Name, "Exchange"), (out string reason, int time, object[] param) =>
  894. {
  895. string station = (string)param[0];
  896. int slot = int.Parse((string)param[1]);
  897. Hand hand = (Hand)Enum.Parse(typeof(Hand), (string)param[2], true);
  898. RobotArmEnum arm = (RobotArmEnum)((int)hand);
  899. bool ret = Swap(arm, station, slot);//, slot, hand, out reason);
  900. if (ret)
  901. {
  902. reason = string.Format("{0} {1}", Name, "Swap wafer");
  903. return true;
  904. }
  905. reason = "";
  906. return false;
  907. });
  908. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotExchange"), (out string reason, int time, object[] param) =>
  909. {
  910. string station = (string)param[0];
  911. int slot = int.Parse((string)param[1]);
  912. string strarm = Regex.Replace(param[2].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  913. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), strarm);
  914. bool ret = Swap(arm, station, slot);//, slot, hand, out reason);
  915. if (ret)
  916. {
  917. reason = string.Format("{0} {1}", Name, "Swap wafer");
  918. return true;
  919. }
  920. reason = "";
  921. return false;
  922. });
  923. DEVICE.Register(String.Format("{0}.{1}", Name, "Goto"), (out string reason, int time, object[] param) =>
  924. {
  925. bool ret = GoTo(param);
  926. if (ret)
  927. {
  928. reason = string.Format("{0}{1}", Name, "Goto");
  929. return true;
  930. }
  931. reason = "";
  932. return false;
  933. });
  934. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotGoto"), (out string reason, int time, object[] param) =>
  935. {
  936. bool ret = GoTo(param);
  937. if (ret)
  938. {
  939. reason = string.Format("{0}{1}", Name, "Goto");
  940. return true;
  941. }
  942. reason = "";
  943. return false;
  944. });
  945. DEVICE.Register(String.Format("{0}.{1}", Name, "HirataRobotGoto"), (out string reason, int time, object[] param) =>
  946. {
  947. RobotArmEnum arm = (RobotArmEnum)Enum.Parse(typeof(RobotArmEnum), param[0].ToString());
  948. string station = param[1].ToString();
  949. int slot = Convert.ToInt32(param[2]);
  950. RobotPostionEnum pos = (RobotPostionEnum)Enum.Parse(typeof(RobotPostionEnum), param[3].ToString());
  951. bool ret = GoTo(arm, station, slot, pos);
  952. if (ret)
  953. {
  954. reason = string.Format("{0}{1}", Name, "HirataRobotGoto");
  955. return true;
  956. }
  957. reason = "";
  958. return false;
  959. });
  960. DEVICE.Register(String.Format("{0}.{1}", Name, "SetSpeed"), (out string reason, int time, object[] param) =>
  961. {
  962. bool ret = SetSpeed(param);
  963. if (ret)
  964. {
  965. reason = string.Format("{0}{1}", Name, "SetSpeed");
  966. return true;
  967. }
  968. reason = "";
  969. return false;
  970. });
  971. DEVICE.Register(String.Format("{0}.{1}", Name, "SetParameter"), (out string reason, int time, object[] param) =>
  972. {
  973. bool ret = SetParameter(param);
  974. if (ret)
  975. {
  976. reason = string.Format("{0}{1}", Name, "SetParameter");
  977. return true;
  978. }
  979. reason = "";
  980. return false;
  981. });
  982. DEVICE.Register(String.Format("{0}.{1}", Name, "ReadParameter"), (out string reason, int time, object[] param) =>
  983. {
  984. bool ret = ReadParameter(param);
  985. if (ret)
  986. {
  987. reason = string.Format("{0}{1}", Name, "ReadData");
  988. return true;
  989. }
  990. reason = "";
  991. return false;
  992. });
  993. DEVICE.Register(String.Format("{0}.{1}", Name, "RobotMove"), (out string reason, int time, object[] param) =>
  994. {
  995. bool ret = Move(param);
  996. if (ret)
  997. {
  998. reason = string.Format("{0}{1}", Name, "MovePostion");
  999. return true;
  1000. }
  1001. reason = "";
  1002. return false;
  1003. });
  1004. }
  1005. public virtual bool Move(object[] param)
  1006. {
  1007. return CheckToPostMessage((int)RobotMsg.Move, param); ;
  1008. }
  1009. public virtual bool ReadParameter(object[] param)
  1010. {
  1011. return CheckToPostMessage((int)RobotMsg.ReadData, param);
  1012. }
  1013. public virtual bool SetParameter(object[] arg2)
  1014. {
  1015. return CheckToPostMessage((int)RobotMsg.SetParameters, arg2);
  1016. }
  1017. public virtual bool SetWaferSize(RobotArmEnum arm, WaferSize size)
  1018. {
  1019. return CheckToPostMessage((int)RobotMsg.SetParameters, new object[] { "WaferSize", arm, size });
  1020. }
  1021. public bool InvokeSetSpeed(string arg1, object[] arg2)
  1022. {
  1023. var speed = 3;
  1024. //string reason;
  1025. if (int.TryParse((string)arg2[0], out speed))
  1026. {
  1027. if (!(speed <= 3 || speed >= 1))
  1028. EV.PostWarningLog(ModuleName.Robot.ToString(), "Error Parameter,speed should be range in 1, 3");
  1029. return SetSpeed(new object[] { speed });
  1030. }
  1031. EV.PostWarningLog(ModuleName.Robot.ToString(), $"invalid parameters. {arg2[0]}");
  1032. return false;
  1033. }
  1034. public virtual bool SetSpeed(object[] arg2)
  1035. {
  1036. if (IsBusy) return false;
  1037. List<object> paras = new List<object>() { "TransferSpeedLevel" };
  1038. foreach (var value in arg2) paras.Add(value);
  1039. return CheckToPostMessage((int)RobotMsg.SetParameters, paras.ToArray());
  1040. }
  1041. public virtual bool SetRobotParameters(object[] arg2)
  1042. {
  1043. if (IsBusy) return false;
  1044. return CheckToPostMessage((int)RobotMsg.SetParameters, arg2.ToArray());
  1045. }
  1046. public virtual bool SetSpeed(string speedtype, int value)
  1047. {
  1048. return CheckToPostMessage((int)RobotMsg.SetParameters, new object[] { speedtype, value });
  1049. }
  1050. public virtual bool InvokeRobotGoTo(string arg1, object[] arg2)
  1051. {
  1052. return CheckToPostMessage((int)RobotMsg.GoToPosition, arg2);
  1053. }
  1054. private void SubscribeDataVariable()
  1055. {
  1056. DATA.Subscribe($"{Name}.State", () => RobotState.ToString());
  1057. DATA.Subscribe($"{Name}.RobotState", () => RobotState.ToString());
  1058. DATA.Subscribe($"{Name}.Axis1Postion", () => PositionAxis1.ToString());
  1059. DATA.Subscribe($"{Name}.Axis2Postion", () => PositionAxis2.ToString());
  1060. DATA.Subscribe($"{Name}.Axis3Postion", () => PositionAxis3.ToString());
  1061. DATA.Subscribe($"{Name}.Axis4Postion", () => PositionAxis4.ToString());
  1062. DATA.Subscribe($"{Name}.Axis5Postion", () => PositionAxis5.ToString());
  1063. DATA.Subscribe($"{Name}.RobotErrorCode", () => ErrorCode ?? ErrorCode.ToString());
  1064. DATA.Subscribe($"{Name}.IsPause", () => IsPause);
  1065. DATA.Subscribe($"{Name}.RobotMoveInfo", () => MoveInfo);
  1066. DATA.Subscribe($"{Name}.RobotBladeTraget", () => BladeTarget);
  1067. DATA.Subscribe($"{Name}.RobotBlade1Traget", () => Blade1Target);
  1068. DATA.Subscribe($"{Name}.RobotBlade2Traget", () => Blade2Target);
  1069. DATA.Subscribe($"{Name}.WaferSize", () => GetCurrentWaferSize().ToString());
  1070. DATA.Subscribe($"{Name}.Blade1WaferSize", () => GetBladeWaferSize(0).ToString());
  1071. DATA.Subscribe($"{Name}.Blade2WaferSize", () => GetBladeWaferSize(1).ToString());
  1072. DATA.Subscribe($"{Name}.CommandMessages", () => _commandMsgs);
  1073. }
  1074. private WaferSize GetBladeWaferSize(int slotIndex)
  1075. {
  1076. if (WaferManager.Instance.CheckHasWafer(RobotModuleName, slotIndex))
  1077. return WaferManager.Instance.GetWaferSize(RobotModuleName, slotIndex);
  1078. return Size;
  1079. }
  1080. private int _SmInterval
  1081. {
  1082. get
  1083. {
  1084. if (SC.ContainsItem($"Robot.{RobotModuleName}.SMInterval"))
  1085. return SC.GetValue<int>($"Robot.{RobotModuleName}.SMInterval");
  1086. return 50;
  1087. }
  1088. }
  1089. private void BuildTransitionTable()
  1090. {
  1091. fsm = new StateMachine<RobotBaseDevice>(Name + ".StateMachine", (int)RobotStateEnum.Idle, _SmInterval);
  1092. //Init sequence
  1093. AnyStateTransition(RobotMsg.ERROR, fError, RobotStateEnum.Error);
  1094. AnyStateTransition(RobotMsg.Reset, fReset, RobotStateEnum.Resetting);
  1095. AnyStateTransition(RobotMsg.Stop, fStop, RobotStateEnum.Stopped);
  1096. AnyStateTransition(RobotMsg.Abort, fAbort, RobotStateEnum.Init);
  1097. AnyStateTransition(RobotMsg.StartMaintenance, fStartMaitenance, RobotStateEnum.Maintenance);
  1098. Transition(RobotStateEnum.Maintenance, RobotMsg.CompleteMaintenance, fCompleteMaintenance, RobotStateEnum.Init);
  1099. Transition(RobotStateEnum.Maintenance, FSM_MSG.TIMER, fMonitorMaintenance, RobotStateEnum.Init);
  1100. Transition(RobotStateEnum.Resetting, RobotMsg.ActionDone, fResetComplete, RobotStateEnum.Idle);
  1101. Transition(RobotStateEnum.Resetting, FSM_MSG.TIMER, fMonitorReset, RobotStateEnum.Idle);
  1102. Transition(RobotStateEnum.Stopped, FSM_MSG.TIMER, fMonitorStop, RobotStateEnum.Idle);
  1103. Transition(RobotStateEnum.Init, RobotMsg.StartInit, fStartInit, RobotStateEnum.Initializing);
  1104. Transition(RobotStateEnum.Idle, RobotMsg.StartInit, fStartInit, RobotStateEnum.Initializing);
  1105. Transition(RobotStateEnum.Error, RobotMsg.StartInit, fStartInit, RobotStateEnum.Initializing);
  1106. Transition(RobotStateEnum.Error, RobotMsg.InitComplete, fInitComplete, RobotStateEnum.Idle);
  1107. Transition(RobotStateEnum.Init, RobotMsg.InitComplete, fInitComplete, RobotStateEnum.Idle);
  1108. Transition(RobotStateEnum.Initializing, RobotMsg.InitComplete, fInitComplete, RobotStateEnum.Idle);
  1109. Transition(RobotStateEnum.Initializing, RobotMsg.ActionDone, fInitComplete, RobotStateEnum.Idle);
  1110. Transition(RobotStateEnum.Initializing, FSM_MSG.TIMER, fMonitorInit, RobotStateEnum.Idle);
  1111. Transition(RobotStateEnum.Init, RobotMsg.StartHome, fStartHome, RobotStateEnum.Homing);
  1112. Transition(RobotStateEnum.Idle, RobotMsg.StartHome, fStartHome, RobotStateEnum.Homing);
  1113. Transition(RobotStateEnum.Error, RobotMsg.StartHome, fStartHome, RobotStateEnum.Homing);
  1114. Transition(RobotStateEnum.Init, RobotMsg.HomeComplete, fHomeComplete, RobotStateEnum.Idle);
  1115. Transition(RobotStateEnum.Error, RobotMsg.HomeComplete, fHomeComplete, RobotStateEnum.Idle);
  1116. Transition(RobotStateEnum.Homing, RobotMsg.HomeComplete, fHomeComplete, RobotStateEnum.Idle);
  1117. Transition(RobotStateEnum.Homing, RobotMsg.ActionDone, fHomeComplete, RobotStateEnum.Idle);
  1118. Transition(RobotStateEnum.Homing, FSM_MSG.TIMER, fMonitorHome, RobotStateEnum.Idle);
  1119. Transition(RobotStateEnum.Error, RobotMsg.Clear, fClear, RobotStateEnum.Init);
  1120. Transition(RobotStateEnum.Error, RobotMsg.ResetToReady, fResetToReady, RobotStateEnum.Idle);
  1121. Transition(RobotStateEnum.Idle, RobotMsg.SetParameters, fStartSetParameters, RobotStateEnum.SettingServos);
  1122. Transition(RobotStateEnum.SettingServos, RobotMsg.SetParameters, fStartSetParameters, RobotStateEnum.SettingServos);
  1123. Transition(RobotStateEnum.SettingServos, RobotMsg.SetParametersComplete, fSetComplete, RobotStateEnum.Idle);
  1124. Transition(RobotStateEnum.SettingServos, RobotMsg.ActionDone, fSetComplete, RobotStateEnum.Idle);
  1125. Transition(RobotStateEnum.SettingServos, FSM_MSG.TIMER, fMonitorSetParamter, RobotStateEnum.Idle);
  1126. Transition(RobotStateEnum.Idle, RobotMsg.ReadData, fStartReadData, RobotStateEnum.ReadingData);
  1127. Transition(RobotStateEnum.ReadingData, RobotMsg.ActionDone, null, RobotStateEnum.Idle);
  1128. Transition(RobotStateEnum.ReadingData, RobotMsg.ReadDataComplete, null, RobotStateEnum.Idle);
  1129. Transition(RobotStateEnum.ReadingData, FSM_MSG.TIMER, fMonitorReadData, RobotStateEnum.Idle);
  1130. Transition(RobotStateEnum.Idle, RobotMsg.PickWafer, fStartPickWafer, RobotStateEnum.Picking);
  1131. Transition(RobotStateEnum.Picking, RobotMsg.PickComplete, fPickComplete, RobotStateEnum.Idle);
  1132. Transition(RobotStateEnum.Picking, RobotMsg.ActionDone, fPickComplete, RobotStateEnum.Idle);
  1133. Transition(RobotStateEnum.Picking, FSM_MSG.TIMER, fMonitorPick, RobotStateEnum.Idle);
  1134. Transition(RobotStateEnum.Idle, RobotMsg.PlaceWafer, fStartPlaceWafer, RobotStateEnum.Placing);
  1135. Transition(RobotStateEnum.Placing, RobotMsg.PlaceComplete, fPlaceComplete, RobotStateEnum.Idle);
  1136. Transition(RobotStateEnum.Placing, RobotMsg.ActionDone, fPlaceComplete, RobotStateEnum.Idle);
  1137. Transition(RobotStateEnum.Placing, FSM_MSG.TIMER, fMonitorPlace, RobotStateEnum.Idle);
  1138. Transition(RobotStateEnum.Idle, RobotMsg.SwapWafer, fStartSwapWafer, RobotStateEnum.Swapping);
  1139. Transition(RobotStateEnum.Swapping, RobotMsg.SwapComplete, fSwapComplete, RobotStateEnum.Idle);
  1140. Transition(RobotStateEnum.Swapping, RobotMsg.ActionDone, fSwapComplete, RobotStateEnum.Idle);
  1141. Transition(RobotStateEnum.Swapping, FSM_MSG.TIMER, fMonitorSwap, RobotStateEnum.Idle);
  1142. Transition(RobotStateEnum.Idle, RobotMsg.MapWafer, fStartMapWafer, RobotStateEnum.Mapping);
  1143. Transition(RobotStateEnum.Mapping, RobotMsg.MapComplete, fMapComplete, RobotStateEnum.Idle);
  1144. Transition(RobotStateEnum.Mapping, RobotMsg.ActionDone, fMapComplete, RobotStateEnum.Idle);
  1145. Transition(RobotStateEnum.Mapping, FSM_MSG.TIMER, fMonitorMap, RobotStateEnum.Idle);
  1146. Transition(RobotStateEnum.Mapping, RobotMsg.ReadData, fStartReadData, RobotStateEnum.ReadingData);
  1147. Transition(RobotStateEnum.Idle, RobotMsg.GoToPosition, fStartGoTo, RobotStateEnum.GoingToPosition);
  1148. Transition(RobotStateEnum.Idle, RobotMsg.Move, fStartMove, RobotStateEnum.Moving);
  1149. Transition(RobotStateEnum.Moving, RobotMsg.MoveComplete, fMoveComplete, RobotStateEnum.Idle);
  1150. Transition(RobotStateEnum.Moving, RobotMsg.ActionDone, fMoveComplete, RobotStateEnum.Idle);
  1151. Transition(RobotStateEnum.Moving, FSM_MSG.TIMER, fMonitorMoving, RobotStateEnum.Idle);
  1152. Transition(RobotStateEnum.GoingToPosition, RobotMsg.ArrivedPosition, fGoToComplete, RobotStateEnum.Idle);
  1153. Transition(RobotStateEnum.GoingToPosition, RobotMsg.MoveComplete, fMoveComplete, RobotStateEnum.Idle);
  1154. Transition(RobotStateEnum.GoingToPosition, RobotMsg.ActionDone, fGoToComplete, RobotStateEnum.Idle);
  1155. Transition(RobotStateEnum.GoingToPosition, FSM_MSG.TIMER, fMonitorGoTo, RobotStateEnum.Idle);
  1156. Transition(RobotStateEnum.Idle, RobotMsg.Grip, fStartGrip, RobotStateEnum.Gripping);
  1157. Transition(RobotStateEnum.Gripping, RobotMsg.GripComplete, fGripComplete, RobotStateEnum.Idle);
  1158. Transition(RobotStateEnum.Gripping, RobotMsg.ActionDone, fGripComplete, RobotStateEnum.Idle);
  1159. Transition(RobotStateEnum.Gripping, FSM_MSG.TIMER, fMonitorGrip, RobotStateEnum.Idle);
  1160. Transition(RobotStateEnum.Idle, RobotMsg.UnGrip, fStartUnGrip, RobotStateEnum.UnGripping);
  1161. Transition(RobotStateEnum.UnGripping, RobotMsg.UnGripComplete, fUnGripComplete, RobotStateEnum.Idle);
  1162. Transition(RobotStateEnum.UnGripping, RobotMsg.ActionDone, fUnGripComplete, RobotStateEnum.Idle);
  1163. Transition(RobotStateEnum.UnGripping, FSM_MSG.TIMER, fMonitorUnGrip, RobotStateEnum.Idle);
  1164. Transition(RobotStateEnum.Idle, RobotMsg.ExtendForPick, fStartExtendForPick, RobotStateEnum.ExtendingForPick);
  1165. Transition(RobotStateEnum.ExtendingForPick, RobotMsg.ExtendComplete, fExtendForPickComplete, RobotStateEnum.Idle);
  1166. Transition(RobotStateEnum.ExtendingForPick, RobotMsg.ActionDone, fExtendForPickComplete, RobotStateEnum.Idle);
  1167. Transition(RobotStateEnum.ExtendingForPick, FSM_MSG.TIMER, fMonitorExtendForPickComplete, RobotStateEnum.Idle);
  1168. Transition(RobotStateEnum.Idle, RobotMsg.ExtendForPlace, fStartExtendForPlace, RobotStateEnum.ExtendingForPlace);
  1169. Transition(RobotStateEnum.ExtendingForPlace, RobotMsg.ExtendComplete, fExtendForPlaceComplete, RobotStateEnum.Idle);
  1170. Transition(RobotStateEnum.ExtendingForPlace, RobotMsg.ActionDone, fExtendForPlaceComplete, RobotStateEnum.Idle);
  1171. Transition(RobotStateEnum.ExtendingForPlace, FSM_MSG.TIMER, fMonitorExtendForPlaceComplete, RobotStateEnum.Idle);
  1172. Transition(RobotStateEnum.Idle, RobotMsg.RetractFromPick, fStartRetractFromPick, RobotStateEnum.RetractingFromPick);
  1173. Transition(RobotStateEnum.RetractingFromPick, RobotMsg.RetractComplete, fRetractFromPickComplete, RobotStateEnum.Idle);
  1174. Transition(RobotStateEnum.RetractingFromPick, RobotMsg.ActionDone, fRetractFromPickComplete, RobotStateEnum.Idle);
  1175. Transition(RobotStateEnum.RetractingFromPick, FSM_MSG.TIMER, fMonitorRetractFromPickComplete, RobotStateEnum.Idle);
  1176. Transition(RobotStateEnum.Idle, RobotMsg.RetractFromPlace, fStartRetractFromPlace, RobotStateEnum.RetractingFromPlace);
  1177. Transition(RobotStateEnum.RetractingFromPlace, RobotMsg.RetractComplete, fRetractFromPlaceComplete, RobotStateEnum.Idle);
  1178. Transition(RobotStateEnum.RetractingFromPlace, RobotMsg.ActionDone, fRetractFromPlaceComplete, RobotStateEnum.Idle);
  1179. Transition(RobotStateEnum.RetractingFromPlace, FSM_MSG.TIMER, fMonitorRetractFromPlaceComplete, RobotStateEnum.Idle);
  1180. Transition(RobotStateEnum.Idle, RobotMsg.TransferWafer, fStartTransferWafer, RobotStateEnum.Transferring);
  1181. Transition(RobotStateEnum.Transferring, RobotMsg.TransferComplete, fTransferPlaceComplete, RobotStateEnum.Idle);
  1182. Transition(RobotStateEnum.Transferring, RobotMsg.ActionDone, fTransferPlaceComplete, RobotStateEnum.Idle);
  1183. Transition(RobotStateEnum.Idle, RobotMsg.PickCassette, fStartPickCassette, RobotStateEnum.PickingCassette);
  1184. Transition(RobotStateEnum.PickingCassette, RobotMsg.PickCassetteComplete, fPickCassetteComplete, RobotStateEnum.Idle);
  1185. Transition(RobotStateEnum.PickingCassette, RobotMsg.ActionDone, fPickCassetteComplete, RobotStateEnum.Idle);
  1186. Transition(RobotStateEnum.PickingCassette, FSM_MSG.TIMER, fMonitorPickingCassette, RobotStateEnum.Idle);
  1187. Transition(RobotStateEnum.Idle, RobotMsg.PlaceCassette, fStartPlaceCassette, RobotStateEnum.PlacingCassette);
  1188. Transition(RobotStateEnum.PlacingCassette, RobotMsg.PlaceCassetteComplete, fPlaceCassetteComplete, RobotStateEnum.Idle);
  1189. Transition(RobotStateEnum.PlacingCassette, RobotMsg.ActionDone, fPlaceCassetteComplete, RobotStateEnum.Idle);
  1190. Transition(RobotStateEnum.PlacingCassette, FSM_MSG.TIMER, fMonitorPlacingCassette, RobotStateEnum.Idle);
  1191. Transition(RobotStateEnum.Idle, RobotMsg.ExecuteCommand, fStartExecuteCommand, RobotStateEnum.Executing);
  1192. Transition(RobotStateEnum.Executing, FSM_MSG.TIMER, fMonitorExecuting, RobotStateEnum.Idle);
  1193. Transition(RobotStateEnum.Executing, RobotMsg.ActionDone, null, RobotStateEnum.Idle);
  1194. }
  1195. protected virtual bool fMonitorExecuting(object[] param)
  1196. {
  1197. IsBusy = false;
  1198. return false;
  1199. }
  1200. protected virtual bool fStartExecuteCommand(object[] param)
  1201. {
  1202. return true;
  1203. }
  1204. protected virtual bool fMonitorHome(object[] param)
  1205. {
  1206. return false;
  1207. }
  1208. protected virtual bool fHomeComplete(object[] param)
  1209. {
  1210. return true;
  1211. }
  1212. protected virtual bool fStartHome(object[] param)
  1213. {
  1214. return true;
  1215. }
  1216. protected virtual bool fMonitorPlacingCassette(object[] param)
  1217. {
  1218. return false;
  1219. }
  1220. protected virtual bool fMonitorPickingCassette(object[] param)
  1221. {
  1222. return false;
  1223. }
  1224. protected virtual bool fMonitorExtendForPickComplete(object[] param)
  1225. {
  1226. return false;
  1227. }
  1228. protected virtual bool fMonitorExtendForPlaceComplete(object[] param)
  1229. {
  1230. return false;
  1231. }
  1232. protected virtual bool fMonitorRetractFromPickComplete(object[] param)
  1233. {
  1234. return false;
  1235. }
  1236. protected virtual bool fMonitorRetractFromPlaceComplete(object[] param)
  1237. {
  1238. return false;
  1239. }
  1240. protected virtual bool fPlaceCassetteComplete(object[] param)
  1241. {
  1242. return true;
  1243. }
  1244. protected virtual bool fStartPlaceCassette(object[] param)
  1245. {
  1246. return true;
  1247. }
  1248. protected virtual bool fPickCassetteComplete(object[] param)
  1249. {
  1250. return true;
  1251. }
  1252. protected virtual bool fStartPickCassette(object[] param)
  1253. {
  1254. return true;
  1255. }
  1256. protected virtual bool fMonitorMoving(object[] param)
  1257. {
  1258. return false;
  1259. }
  1260. protected virtual bool fMonitorMaintenance(object[] param)
  1261. {
  1262. return false;
  1263. }
  1264. protected virtual bool fCompleteMaintenance(object[] param)
  1265. {
  1266. return true;
  1267. }
  1268. protected virtual bool fStartMaitenance(object[] param)
  1269. {
  1270. return true;
  1271. }
  1272. protected virtual bool fMonitorUnGrip(object[] param)
  1273. {
  1274. return true;
  1275. }
  1276. protected virtual bool fMonitorGrip(object[] param)
  1277. {
  1278. return true;
  1279. }
  1280. protected virtual bool fMoveComplete(object[] param)
  1281. {
  1282. IsBusy = false;
  1283. return true;
  1284. }
  1285. protected virtual bool fStartMove(object[] param)
  1286. {
  1287. return true;
  1288. }
  1289. protected virtual bool fMonitorSetParamter(object[] param)
  1290. {
  1291. return false;
  1292. }
  1293. protected virtual bool fMonitorReadData(object[] param)
  1294. {
  1295. return false;
  1296. }
  1297. protected virtual bool fMonitorReset(object[] param)
  1298. {
  1299. return false;
  1300. }
  1301. protected virtual bool fMonitorStop(object[] param)
  1302. {
  1303. return false;
  1304. }
  1305. protected virtual bool fMonitorGoTo(object[] param)
  1306. {
  1307. return false;
  1308. }
  1309. protected virtual bool fMonitorMap(object[] param)
  1310. {
  1311. return false;
  1312. }
  1313. protected virtual bool fMonitorPlace(object[] param)
  1314. {
  1315. return false;
  1316. }
  1317. protected virtual bool fMonitorSwap(object[] param)
  1318. {
  1319. return false;
  1320. }
  1321. protected virtual bool fMonitorPick(object[] param)
  1322. {
  1323. return false;
  1324. }
  1325. protected virtual bool fMonitorInit(object[] param)
  1326. {
  1327. return false;
  1328. }
  1329. protected virtual bool fStop(object[] param)
  1330. {
  1331. return true;
  1332. }
  1333. protected virtual bool fAbort(object[] param)
  1334. {
  1335. return true;
  1336. }
  1337. protected bool fResetComplete(object[] param)
  1338. {
  1339. IsBusy = false;
  1340. return true;
  1341. }
  1342. protected abstract bool fClear(object[] param);
  1343. protected virtual bool fSetComplete(object[] param)
  1344. {
  1345. IsBusy = false;
  1346. return true;
  1347. }
  1348. protected abstract bool fStartReadData(object[] param);
  1349. protected abstract bool fStartSetParameters(object[] param);
  1350. protected abstract bool fStartTransferWafer(object[] param);
  1351. protected abstract bool fStartUnGrip(object[] param);
  1352. protected abstract bool fStartGrip(object[] param);
  1353. protected abstract bool fStartGoTo(object[] param);
  1354. protected abstract bool fStartMapWafer(object[] param);
  1355. protected abstract bool fStartSwapWafer(object[] param);
  1356. protected abstract bool fStartPlaceWafer(object[] param);
  1357. protected abstract bool fStartPickWafer(object[] param);
  1358. protected abstract bool fResetToReady(object[] param);
  1359. protected abstract bool fReset(object[] param);
  1360. protected abstract bool fStartInit(object[] param);
  1361. protected abstract bool fError(object[] param);
  1362. protected abstract bool fStartExtendForPick(object[] param);
  1363. protected abstract bool fStartExtendForPlace(object[] param);
  1364. protected abstract bool fStartRetractFromPick(object[] param);
  1365. protected abstract bool fStartRetractFromPlace(object[] param);
  1366. protected virtual bool fTransferPlaceComplete(object[] param)
  1367. {
  1368. IsBusy = false;
  1369. return true;
  1370. }
  1371. protected virtual bool fGoToComplete(object[] param)
  1372. {
  1373. IsBusy = false;
  1374. return true;
  1375. }
  1376. protected virtual bool fExtendForPickComplete(object[] param)
  1377. {
  1378. return true;
  1379. }
  1380. protected virtual bool fExtendForPlaceComplete(object[] param)
  1381. {
  1382. return true;
  1383. }
  1384. protected virtual bool fRetractFromPickComplete(object[] param)
  1385. {
  1386. return true;
  1387. }
  1388. protected virtual bool fRetractFromPlaceComplete(object[] param)
  1389. {
  1390. IsBusy = false;
  1391. return true;
  1392. }
  1393. protected virtual bool fUnGripComplete(object[] param)
  1394. {
  1395. IsBusy = false;
  1396. return true;
  1397. }
  1398. protected virtual bool fGripComplete(object[] param)
  1399. {
  1400. IsBusy = false;
  1401. return true;
  1402. }
  1403. protected virtual bool fMapComplete(object[] param)
  1404. {
  1405. IsBusy = false;
  1406. return true;
  1407. }
  1408. protected virtual bool fSwapComplete(object[] param)
  1409. {
  1410. IsBusy = false;
  1411. return true;
  1412. }
  1413. protected virtual bool fPlaceComplete(object[] param)
  1414. {
  1415. IsBusy = false;
  1416. return true;
  1417. }
  1418. protected virtual bool fPickComplete(object[] param)
  1419. {
  1420. IsBusy = false;
  1421. return true;
  1422. }
  1423. protected virtual bool fInitFail(object[] param)
  1424. {
  1425. IsBusy = false;
  1426. return true;
  1427. }
  1428. protected virtual bool fInitComplete(object[] param)
  1429. {
  1430. IsBusy = false;
  1431. return true;
  1432. }
  1433. public RobotStateEnum RobotState { get => (RobotStateEnum)fsm.State; }
  1434. public string Module { get; set; }
  1435. public string Name { get; set; }
  1436. public string ScRoot { get; set; }
  1437. public ModuleName RobotModuleName { get; private set; }
  1438. public ModuleName CurrentInteractModule { get; private set; }
  1439. public virtual bool ApproachForPick(RobotArmEnum arm, string station, int slot)
  1440. {
  1441. return true;
  1442. }
  1443. public virtual bool ApproachForPlace(RobotArmEnum arm, string station, int slot)
  1444. {
  1445. return true;
  1446. }
  1447. public virtual bool DualPick(string station, int lowerSlot)
  1448. {
  1449. return true;
  1450. }
  1451. public virtual bool DualPlace(string station, int lowerSlot)
  1452. {
  1453. return true;
  1454. }
  1455. public virtual bool DualSwap(string station, int lowerSlotPlaceTo, int lowerSlotPickFrom)
  1456. {
  1457. return true;
  1458. }
  1459. public virtual bool DualTransfer(string sourceStation, int sourceLowerSlot, string destStation, int destLowerSlot)
  1460. {
  1461. return true;
  1462. }
  1463. public virtual string[] GetStationsInUse()
  1464. {
  1465. return null;
  1466. }
  1467. public abstract RobotArmWaferStateEnum GetWaferState(RobotArmEnum arm);
  1468. #region Action
  1469. public virtual bool Home(object[] param)
  1470. {
  1471. return CheckToPostMessage((int)RobotMsg.StartInit, param);
  1472. }
  1473. public virtual bool Init(object[] param)
  1474. {
  1475. return CheckToPostMessage((int)RobotMsg.StartInit, param);
  1476. }
  1477. public virtual bool HomeModule(object[] param)
  1478. {
  1479. return CheckToPostMessage((int)RobotMsg.StartHome, param);
  1480. }
  1481. public virtual bool Abort()
  1482. {
  1483. return CheckToPostMessage((int)RobotMsg.Abort);
  1484. }
  1485. public virtual bool Grip(RobotArmEnum arm)
  1486. {
  1487. return CheckToPostMessage((int)RobotMsg.Grip, new object[] { (int)arm });
  1488. }
  1489. public virtual bool Release(RobotArmEnum arm)
  1490. {
  1491. return CheckToPostMessage((int)RobotMsg.UnGrip, new object[] { (int)arm });
  1492. }
  1493. public virtual bool Stop()
  1494. {
  1495. return CheckToPostMessage((int)RobotMsg.Stop, null);
  1496. }
  1497. public virtual bool GoTo(object[] param)
  1498. {
  1499. if (!IsReady())
  1500. return false;
  1501. if (PostMessageWithoutCheck((int)RobotMsg.GoToPosition, param))
  1502. {
  1503. string log = "";
  1504. foreach (var obj in param)
  1505. {
  1506. log += obj.ToString() + ",";
  1507. }
  1508. LOG.Write($"{RobotModuleName} start go to {log}");
  1509. return true;
  1510. }
  1511. return false;
  1512. }
  1513. public virtual bool GoTo(RobotArmEnum arm, string station, int slot, RobotPostionEnum pos, float xoffset = 0, float yoffset = 0,
  1514. float zoffset = 0, float woffset = 0, bool isFromOriginal = true, bool isJumpToNextMotion = false)
  1515. {
  1516. return GoTo(new object[] { arm, station, slot, pos, xoffset, yoffset, zoffset, woffset, isFromOriginal, isJumpToNextMotion });
  1517. }
  1518. public virtual bool RobotFlippe(bool to0degree)
  1519. {
  1520. return false;
  1521. }
  1522. #endregion
  1523. public virtual void Monitor()
  1524. {
  1525. return;
  1526. }
  1527. public virtual bool PickEx(RobotArmEnum arm, string station, int slot, double rSpeed, double tSpeed,double zSpeed,double sSpeed, double zAxisOffsetSpeed, bool isBypassInterlock)
  1528. {
  1529. if (!IsReady())
  1530. {
  1531. return false;
  1532. }
  1533. IsBusy = true;
  1534. LOG.Write($"{RobotModuleName} {arm} start post message to pick wafer from station:{station},slot:{slot + 1}.");
  1535. if (PostMessageWithoutCheck((int)RobotMsg.PickWafer, new object[] { arm, station, slot, rSpeed, tSpeed, zSpeed, sSpeed, zAxisOffsetSpeed, isBypassInterlock }))
  1536. {
  1537. LOG.Write($"{RobotModuleName} {arm} start pick wafer from station:{station},slot:{slot + 1}.");
  1538. return true;
  1539. }
  1540. return false;
  1541. }
  1542. public virtual bool Pick(RobotArmEnum arm, string station, int slot)
  1543. {
  1544. if (!IsReady())
  1545. {
  1546. return false;
  1547. }
  1548. IsBusy = true;
  1549. LOG.Write($"{RobotModuleName} {arm} start post message to pick wafer from station:{station},slot:{slot + 1}.");
  1550. if (PostMessageWithoutCheck((int)RobotMsg.PickWafer, new object[] { arm, station, slot }))
  1551. {
  1552. LOG.Write($"{RobotModuleName} {arm} start pick wafer from station:{station},slot:{slot + 1}.");
  1553. return true;
  1554. }
  1555. return false;
  1556. }
  1557. public virtual bool PickEx(RobotArmEnum arm, string station, int slot,int speed)
  1558. {
  1559. if (!IsReady())
  1560. return false;
  1561. IsBusy = true;
  1562. if (PostMessageWithoutCheck((int)RobotMsg.PickWafer, new object[] { arm, station, slot, speed}))
  1563. {
  1564. IsBusy = true;
  1565. return true;
  1566. }
  1567. return false;
  1568. }
  1569. public virtual bool PickCassette(RobotArmEnum arm, string station, int slot)
  1570. {
  1571. if (!IsReady())
  1572. return false;
  1573. IsBusy = true;
  1574. LOG.Write($"{RobotModuleName} {arm} start post message to pick cassette from {station}:{slot}");
  1575. if (PostMessageWithoutCheck((int)RobotMsg.PickCassette, new object[] { station, arm, slot }))
  1576. {
  1577. LOG.Write($"{RobotModuleName} {arm} start pick cassette from {station}:{slot}");
  1578. return true;
  1579. }
  1580. return false;
  1581. }
  1582. public virtual bool PickEx(RobotArmEnum arm, string station, int slot, float xoffset = 0, float yoffset = 0, float zoffset = 0, float woffset = 0)
  1583. {
  1584. if (!IsReady())
  1585. return false;
  1586. IsBusy = true;
  1587. if (PostMessageWithoutCheck((int)RobotMsg.PickWafer, new object[] { arm, station, slot, xoffset, yoffset, zoffset, woffset }))
  1588. {
  1589. IsBusy = true;
  1590. return true;
  1591. }
  1592. return false;
  1593. }
  1594. public virtual bool PickEx(RobotArmEnum arm, string station, int slot, float radialOffset = 0, float thetaOffset = 0)
  1595. {
  1596. if (!IsReady())
  1597. return false;
  1598. IsBusy = true;
  1599. if (PostMessageWithoutCheck((int)RobotMsg.PickWafer, new object[] { arm, station, slot, radialOffset, thetaOffset }))
  1600. {
  1601. IsBusy = true;
  1602. return true;
  1603. }
  1604. return false;
  1605. }
  1606. public virtual bool Place(RobotArmEnum arm, string station, int slot)
  1607. {
  1608. if (!IsReady())
  1609. return false;
  1610. IsBusy = true;
  1611. LOG.Write($"{RobotModuleName} {arm} start post message to place wafer to station:{station},slot:{slot + 1}.");
  1612. if (PostMessageWithoutCheck((int)RobotMsg.PlaceWafer, new object[] { arm, station, slot }))
  1613. {
  1614. LOG.Write($"{RobotModuleName} {arm} start place wafer to station:{station},slot:{slot + 1}.");
  1615. IsBusy = true;
  1616. return true;
  1617. }
  1618. return false;
  1619. }
  1620. public virtual bool PlaceEx(RobotArmEnum arm, string station, int slot, double rSpeed, double tSpeed, double zSpeed, double sSpeed, double zAxisOffsetSpeed)
  1621. {
  1622. if (!IsReady())
  1623. return false;
  1624. IsBusy = true;
  1625. LOG.Write($"{RobotModuleName} {arm} start post message to place wafer to station:{station},slot:{slot + 1}.");
  1626. if (PostMessageWithoutCheck((int)RobotMsg.PlaceWafer, new object[] { arm, station, slot, rSpeed, tSpeed, zSpeed, sSpeed, zAxisOffsetSpeed }))
  1627. {
  1628. LOG.Write($"{RobotModuleName} {arm} start place wafer to station:{station},slot:{slot + 1}.");
  1629. IsBusy = true;
  1630. return true;
  1631. }
  1632. return false;
  1633. }
  1634. public virtual bool PlaceCassette(RobotArmEnum arm, string station, int slot)
  1635. {
  1636. if (!IsReady())
  1637. return false;
  1638. IsBusy = true;
  1639. if (PostMessageWithoutCheck((int)RobotMsg.PlaceCassette, new object[] { station, arm, slot }))
  1640. {
  1641. LOG.Write($"{RobotModuleName} {arm} start place cassette to {station}:{slot}");
  1642. IsBusy = true;
  1643. return true;
  1644. }
  1645. return false;
  1646. }
  1647. public virtual bool PlaceEx(RobotArmEnum arm, string station, int slot, float xoffset = 0, float yoffset = 0, float zoffset = 0, float thetaoffset = 0)
  1648. {
  1649. if (!IsReady())
  1650. return false;
  1651. IsBusy = true;
  1652. if (PostMessageWithoutCheck((int)RobotMsg.PlaceWafer, new object[] { arm, station, slot, xoffset, yoffset, zoffset, thetaoffset }))
  1653. {
  1654. IsBusy = true;
  1655. return true;
  1656. }
  1657. return false;
  1658. }
  1659. public virtual bool PlaceEx(RobotArmEnum arm, string station, int slot, float radialOffset = 0, float thetaOffset = 0)
  1660. {
  1661. if (!IsReady())
  1662. return false;
  1663. IsBusy = true;
  1664. if (PostMessageWithoutCheck((int)RobotMsg.PlaceWafer, new object[] { arm, station, slot, radialOffset, thetaOffset }))
  1665. {
  1666. IsBusy = true;
  1667. return true;
  1668. }
  1669. return false;
  1670. }
  1671. public virtual bool Swap(RobotArmEnum pickArm, string station, int slot)
  1672. {
  1673. if (!IsReady())
  1674. return false;
  1675. IsBusy = true;
  1676. if (PostMessageWithoutCheck((int)RobotMsg.SwapWafer, new object[] { pickArm, station, slot }))
  1677. {
  1678. LOG.Write($"{RobotModuleName} {pickArm} start swap wafer from station:{station},slot:{slot + 1}.");
  1679. IsBusy = true;
  1680. return true;
  1681. }
  1682. return false;
  1683. }
  1684. public virtual bool SwapEx(RobotArmEnum pickArm, string station, int slot, float xoffset = 0, float yoffset = 0, float zoffset = 0, float thetaoffset = 0)
  1685. {
  1686. if (!IsReady())
  1687. return false;
  1688. IsBusy = true;
  1689. if (PostMessageWithoutCheck((int)RobotMsg.SwapWafer, new object[] { pickArm, station, slot, xoffset, yoffset, zoffset, thetaoffset }))
  1690. {
  1691. IsBusy = true;
  1692. return true;
  1693. }
  1694. return false;
  1695. }
  1696. public virtual bool Transfer(RobotArmEnum arm, string sourceStation, int sourceSlot, string destStation, int destSlot)
  1697. {
  1698. if (CheckToPostMessage((int)RobotMsg.TransferWafer, new object[] { arm, sourceStation, sourceSlot, destStation, destSlot }))
  1699. {
  1700. IsBusy = true;
  1701. return true;
  1702. }
  1703. return false;
  1704. }
  1705. public virtual void RobotReset()
  1706. {
  1707. if (CheckToPostMessage((int)RobotMsg.Reset, new object[] { "Reset" }))
  1708. {
  1709. IsBusy = true;
  1710. }
  1711. }
  1712. public virtual void Reset()
  1713. {
  1714. if (CheckToPostMessage((int)RobotMsg.Reset, new object[] { "Reset" }))
  1715. {
  1716. IsBusy = true;
  1717. }
  1718. }
  1719. public virtual void OnError(string errortext)
  1720. {
  1721. EV.PostAlarmLog(Name, $"{Name} occurred error: {errortext}");
  1722. IsBusy = false;
  1723. CheckToPostMessage((int)RobotMsg.ERROR, new object[] { errortext });
  1724. }
  1725. public virtual bool SetParameters(object[] param)
  1726. {
  1727. return CheckToPostMessage((int)RobotMsg.SetParameters, param);
  1728. }
  1729. public virtual void SetServo(bool isOn) { }
  1730. public void NotifySlotMapResult(ModuleName ModuleName, string slotMap)
  1731. {
  1732. if (OnSlotMapRead != null)
  1733. {
  1734. OnSlotMapRead(ModuleName, slotMap);
  1735. }
  1736. }
  1737. public virtual bool HomeAllAxes(out string reason)
  1738. {
  1739. reason = string.Empty;
  1740. return true;
  1741. }
  1742. public virtual bool WaferMapping(ModuleName module, out string reason)
  1743. {
  1744. reason = "";
  1745. if (CheckToPostMessage((int)RobotMsg.MapWafer, new object[] { module }))
  1746. {
  1747. CurrentInteractModule = module;
  1748. IsBusy = true;
  1749. return true;
  1750. }
  1751. return false;
  1752. }
  1753. public virtual bool WaferMapping(ModuleName module, int thicknessIndex = 0, WaferSize size = WaferSize.WS12)
  1754. {
  1755. if (CheckToPostMessage((int)RobotMsg.MapWafer, new object[] { module, thicknessIndex, size }))
  1756. {
  1757. CurrentInteractModule = module;
  1758. IsBusy = true;
  1759. return true;
  1760. }
  1761. return false;
  1762. }
  1763. public virtual bool QueryWaferMap(ModuleName module, out string reason)
  1764. {
  1765. reason = "";
  1766. return true;
  1767. }
  1768. public virtual bool SetMaintenanceMode(bool value)
  1769. {
  1770. if (value)
  1771. return CheckToPostMessage((int)RobotMsg.StartMaintenance, null);
  1772. return CheckToPostMessage((int)RobotMsg.CompleteMaintenance, null);
  1773. }
  1774. public virtual bool OnActionDone(object[] param)
  1775. {
  1776. IsBusy = false;
  1777. if (CheckToPostMessage((int)RobotMsg.ActionDone, new object[] { "ActionDone" }))
  1778. {
  1779. LOG.Write($"{RobotModuleName} action done");
  1780. }
  1781. return true;
  1782. }
  1783. public virtual bool ExecuteCommand(object[] paras)
  1784. {
  1785. IsBusy = true;
  1786. if (CheckToPostMessage((int)RobotMsg.ExecuteCommand, paras))
  1787. {
  1788. LOG.Write($"{RobotModuleName} excute command:{paras[0].ToString()}");
  1789. }
  1790. return true;
  1791. }
  1792. public bool CheckToPostMessage(int msg, params object[] args)
  1793. {
  1794. if (!fsm.FindTransition(fsm.State, msg))
  1795. {
  1796. if (msg != 7)
  1797. EV.PostWarningLog(Name, $"{Name} is in { (RobotStateEnum)fsm.State} state,can not do {(RobotMsg)msg}");
  1798. return false;
  1799. }
  1800. if ((RobotMsg)msg == RobotMsg.GoToPosition || (RobotMsg)msg == RobotMsg.ExtendForPick
  1801. || (RobotMsg)msg == RobotMsg.ExtendForPlace || (RobotMsg)msg == RobotMsg.Grip
  1802. || (RobotMsg)msg == RobotMsg.MapWafer || (RobotMsg)msg == RobotMsg.Move
  1803. || (RobotMsg)msg == RobotMsg.PickWafer || (RobotMsg)msg == RobotMsg.PlaceWafer
  1804. || (RobotMsg)msg == RobotMsg.RetractFromPick || (RobotMsg)msg == RobotMsg.StartInit
  1805. || (RobotMsg)msg == RobotMsg.SwapWafer || (RobotMsg)msg == RobotMsg.TransferWafer
  1806. || (RobotMsg)msg == RobotMsg.UnGrip || (RobotMsg)msg == RobotMsg.SetParameters
  1807. || (RobotMsg)msg == RobotMsg.StartHome)
  1808. IsBusy = true;
  1809. if ((RobotMsg)msg != RobotMsg.ActionDone && !((RobotMsg)msg).ToString().Contains("Complete"))
  1810. CurrentParamter = args;
  1811. fsm.PostMsg(msg, args);
  1812. return true;
  1813. }
  1814. public bool PostMessageWithoutCheck(int msg, params object[] args)
  1815. {
  1816. if ((RobotMsg)msg == RobotMsg.GoToPosition || (RobotMsg)msg == RobotMsg.ExtendForPick
  1817. || (RobotMsg)msg == RobotMsg.ExtendForPlace || (RobotMsg)msg == RobotMsg.Grip
  1818. || (RobotMsg)msg == RobotMsg.MapWafer || (RobotMsg)msg == RobotMsg.Move
  1819. || (RobotMsg)msg == RobotMsg.PickWafer || (RobotMsg)msg == RobotMsg.PlaceWafer
  1820. || (RobotMsg)msg == RobotMsg.RetractFromPick || (RobotMsg)msg == RobotMsg.StartInit
  1821. || (RobotMsg)msg == RobotMsg.SwapWafer || (RobotMsg)msg == RobotMsg.TransferWafer
  1822. || (RobotMsg)msg == RobotMsg.UnGrip || (RobotMsg)msg == RobotMsg.SetParameters
  1823. || (RobotMsg)msg == RobotMsg.StartHome)
  1824. IsBusy = true;
  1825. if ((RobotMsg)msg != RobotMsg.ActionDone && !((RobotMsg)msg).ToString().Contains("Complete"))
  1826. CurrentParamter = args;
  1827. fsm.PostMsgWithoutLock(msg, args);
  1828. return true;
  1829. }
  1830. public bool CheckToPostMessage(RobotMsg msg, params object[] args)
  1831. {
  1832. if (!fsm.FindTransition(fsm.State, (int)msg))
  1833. {
  1834. if ((int)msg != 7)
  1835. EV.PostWarningLog(Name, $"{Name} is in { (RobotStateEnum)fsm.State} state,can not do {(RobotMsg)msg}");
  1836. return false;
  1837. }
  1838. if (msg == RobotMsg.GoToPosition || msg == RobotMsg.ExtendForPick
  1839. || msg == RobotMsg.ExtendForPlace || msg == RobotMsg.Grip
  1840. || msg == RobotMsg.MapWafer || msg == RobotMsg.Move
  1841. || msg == RobotMsg.PickWafer || msg == RobotMsg.PlaceWafer
  1842. || msg == RobotMsg.RetractFromPick || msg == RobotMsg.RetractFromPlace
  1843. || msg == RobotMsg.StartInit
  1844. || msg == RobotMsg.SwapWafer || msg == RobotMsg.TransferWafer
  1845. || msg == RobotMsg.UnGrip || (RobotMsg)msg == RobotMsg.SetParameters
  1846. || msg == RobotMsg.ExecuteCommand)
  1847. IsBusy = true;
  1848. if (msg != RobotMsg.ActionDone && !(msg).ToString().Contains("Complete"))
  1849. CurrentParamter = args;
  1850. fsm.PostMsgWithoutLock((int)msg, args);
  1851. return true;
  1852. }
  1853. public bool Check(int msg, out string reason, params object[] args)
  1854. {
  1855. if (!fsm.FindTransition(fsm.State, msg))
  1856. {
  1857. reason = String.Format("{0} is in {1} state,can not do {2}", Name, (RobotStateEnum)fsm.State, (RobotMsg)msg);
  1858. return false;
  1859. }
  1860. //CurrentParamter = args;
  1861. reason = "";
  1862. return true;
  1863. }
  1864. public virtual void SetPauseResume(bool isPause) { }
  1865. public virtual void NoteError(string errortext)
  1866. {
  1867. }
  1868. }
  1869. public enum RobotMoveDirectionEnum
  1870. {
  1871. Fwd,
  1872. Rev
  1873. }
  1874. }