RobotBase.cs 78 KB

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