CommonRoutine.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. using Aitex.Core.RT.Device.Unit;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  6. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.OcrReaders;
  7. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  8. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using athosRT.Devices;
  15. using MECF.Framework.Common.Equipment;
  16. using athosRT.FSM;
  17. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  18. using Aitex.Core.Common;
  19. using Aitex.Sorter.Common;
  20. using System.Diagnostics;
  21. using static MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase.RobotBaseDevice;
  22. using athosRT.Devices.PA;
  23. namespace athosRT.tool
  24. {
  25. public class CommonRoutine
  26. {
  27. protected bool bUINotify;
  28. protected RobotBaseDevice robot = null;
  29. protected Aligner aligner = null;
  30. protected OcrReader widreader = null;
  31. protected IoCoolingBuffer buffer1 = null;
  32. protected IoCoolingBuffer buffer2 = null;
  33. protected PreAligner aligner1 = null;
  34. protected PreAligner aligner2 = null;
  35. protected LoadLockDevice ll1 = null;
  36. protected LoadLockDevice ll2 = null;
  37. protected IoCoolingBuffer _ioCoolBuffer;
  38. private List<LoadPortBaseDevice> LPs;
  39. protected readonly bool HaveAligner = Singleton<DeviceDefineManager>.Instance.GetValue<bool>("AlignerInstalled").GetValueOrDefault();
  40. protected readonly bool AlignerNeedMoveUpCommand = Singleton<DeviceDefineManager>.Instance.GetValue<bool>(nameof(AlignerNeedMoveUpCommand)).GetValueOrDefault();
  41. protected readonly int LoadPortQuantity = Singleton<DeviceDefineManager>.Instance.GetValue<int>(nameof(LoadPortQuantity)).GetValueOrDefault();
  42. protected readonly string RobotTypeDefine = Singleton<DeviceDefineManager>.Instance.GetValue("RobotType");
  43. protected readonly bool HaveMotionAxis = Singleton<DeviceDefineManager>.Instance.GetValue<bool>("MotionAxisInstalled").GetValueOrDefault();
  44. protected static readonly bool LoadLockDoorControlByStation = Singleton<DeviceDefineManager>.Instance.GetValue<bool>("LLDoorControlByStation").GetValueOrDefault();
  45. protected readonly string LoadPortTypeDefine = Singleton<DeviceDefineManager>.Instance.GetValue("LoadPortType");
  46. protected int OffsetX;
  47. protected int OffsetY;
  48. protected int OffsetZ;
  49. private DeviceTimer _timerQuery = new DeviceTimer();
  50. private int _queryPeriod = 500;
  51. protected bool NeedSetParameter;
  52. protected bool IsStopped;
  53. private int _existInterval = SC.GetValue<int>("Robot.Robot.ExistInterval");
  54. protected bool NeedRobotGripAndUngrip = SC.GetValue<bool>("System.EnableRobotGripAndUngrip");
  55. private DeviceTimer _timerPerf = new DeviceTimer();
  56. public string Module { get; set; }
  57. public string Name { get; set; }
  58. public string Display { get; set; }
  59. public CommonRoutine()
  60. {
  61. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  62. aligner = DEVICE.GetDevice<Aligner>("Aligner");
  63. widreader = DEVICE.GetDevice<OcrReader>("WIDReader");
  64. buffer1 = DEVICE.GetDevice<IoCoolingBuffer>("CoolingBuffer1");
  65. buffer2 = DEVICE.GetDevice<IoCoolingBuffer>("CoolingBuffer2");
  66. aligner1 = DEVICE.GetDevice<PreAligner>("Aligner1");
  67. aligner2 = DEVICE.GetDevice<PreAligner>("Aligner2");
  68. ll1 = DEVICE.GetDevice<LoadLockDevice>("LL1");
  69. ll2 = DEVICE.GetDevice<LoadLockDevice>("LL2");
  70. List<ModuleName> moduleNameList = new List<ModuleName>(Singleton<DeviceManager>.Instance.LpNames);
  71. LPs = new List<LoadPortBaseDevice>();
  72. moduleNameList.ForEach((lp => LPs.Add(DEVICE.GetDevice<LoadPortBaseDevice>(lp.ToString()))));
  73. }
  74. }
  75. public class RobotReset : ModuleRoutineBase, FSM.IRoutine
  76. {
  77. RobotBaseDevice robot = null;
  78. int timeout = 0;
  79. string header = "RobotReset";
  80. public RobotReset(ModuleName module,RobotBaseDevice _robot,int _timeout) : base(module)
  81. {
  82. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  83. timeout = _timeout;
  84. }
  85. public RState Monitor()
  86. {
  87. Runner.Run((int)RobotResetStep.RobotReset, fRobotReset, timeout).
  88. End((int)RobotResetStep.CheckRobotState,fCheckRobotState,timeout);
  89. return Runner.Status;
  90. }
  91. private bool fCheckRobotState()
  92. {
  93. robot.RobotReset();
  94. LogObject.Info(header, "机械臂开始重置");
  95. return true;
  96. }
  97. private bool fRobotReset()
  98. {
  99. if (!robot.IsBusy && robot.RobotState != RobotStateEnum.Error && robot.RobotState == RobotStateEnum.Idle)
  100. {
  101. LogObject.Info(header,"重置成功 机械臂处于空闲状态");
  102. return true;
  103. }
  104. else
  105. {
  106. LogObject.Error(header, "重置失败 请检查机械臂");
  107. return false;
  108. }
  109. }
  110. public RState Start(params object[] objs)
  111. {
  112. Reset();
  113. return Runner.Start(ModuleName.Robot,header);
  114. }
  115. public void Abort()
  116. {
  117. }
  118. public enum RobotResetStep
  119. {
  120. RobotReset,
  121. CheckRobotState
  122. }
  123. }
  124. public class RobotHome : ModuleRoutineBase, FSM.IRoutine
  125. {
  126. RobotBaseDevice robot = null;
  127. int timeout = 0;
  128. string header = "RobotHome";
  129. public RobotHome(ModuleName module, RobotBaseDevice _robot, int _timeout) : base(module)
  130. {
  131. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  132. timeout = _timeout;
  133. }
  134. public void Abort()
  135. {
  136. }
  137. public RState Monitor()
  138. {
  139. Runner.End((int)RobotHomeStep.RobotHome, fRobotHome, timeout);
  140. return Runner.Status;
  141. }
  142. private bool fRobotHome()
  143. {
  144. LogObject.Info(header, "机械臂执行home操作");
  145. robot.Home(null);
  146. return true;
  147. }
  148. public RState Start(params object[] objs)
  149. {
  150. Reset();
  151. return Runner.Start(ModuleName.Robot,header);
  152. }
  153. public enum RobotHomeStep
  154. {
  155. RobotHome
  156. }
  157. }
  158. public class RobotArmHome : ModuleRoutineBase, FSM.IRoutine
  159. {
  160. RobotBaseDevice robot = null;
  161. int timeout = 0;
  162. string header = "RobotArmHome";
  163. ModuleName module ;
  164. public RobotArmHome(ModuleName _module, RobotBaseDevice _robot, int _timeout) : base(_module)
  165. {
  166. module = _module;
  167. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  168. timeout = _timeout;
  169. }
  170. public void Abort()
  171. {
  172. }
  173. public RState Monitor()
  174. {
  175. Runner.Run((int)RobotArmHomeStep.RobotArmHome, fRobotArmHome, timeout)
  176. .End(1, fFindName,timeout);
  177. return Runner.Status;
  178. }
  179. private bool fFindName()
  180. {
  181. Trace.WriteLine("robot status:"+robot.RobotState);
  182. return true;
  183. }
  184. private bool fRobotArmHome()
  185. {
  186. Trace.WriteLine(header+" and state is "+robot.RobotState);
  187. robot.PostMsg((int)RobotMsg.StartHome);
  188. if (robot.Home(null))
  189. {
  190. Trace.WriteLine("home成功");
  191. LogObject.Info(header,"home成功");
  192. robot.PostMsg((int)RobotMsg.HomeComplete);
  193. return true;
  194. }
  195. else
  196. {
  197. Trace.WriteLine("home失败");
  198. //LogObject.Error(header, "home失败");
  199. robot.PostMsg((int)RobotMsg.ERROR);
  200. return false;
  201. }
  202. }
  203. public RState Start(params object[] objs)
  204. {
  205. Reset();
  206. return Runner.Start(module, header);
  207. }
  208. public enum RobotArmHomeStep {
  209. RobotArmHome
  210. }
  211. }
  212. public class WaitRobotMotion : ModuleRoutineBase, FSM.IRoutine
  213. {
  214. RobotBaseDevice robot = null;
  215. int timeout = 0;
  216. string header = "WaitRobotMotion";
  217. ModuleName module;
  218. public WaitRobotMotion(ModuleName _module, RobotBaseDevice _robot, int _timeout) : base(_module)
  219. {
  220. module = _module;
  221. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  222. timeout = _timeout;
  223. }
  224. public void Abort()
  225. {
  226. }
  227. public RState Monitor()
  228. {
  229. Runner.Run((int)WaitRobotMotionStep.WaitRobotMotion, fWaitRobotMotion , timeout)
  230. .End(100,NullFun,0);
  231. return Runner.Status;
  232. }
  233. private bool fWaitRobotMotion()
  234. {
  235. Trace.WriteLine("WaitRobotMotion");
  236. if (robot.IsReady())
  237. {
  238. LogObject.Info(header, "状态切换为准备态");
  239. return true;
  240. }
  241. else
  242. {
  243. //LogObject.Error(header, "状态未能切换过来");
  244. return false;
  245. }
  246. }
  247. public RState Start(params object[] objs)
  248. {
  249. Reset();
  250. return Runner.Start(module, header);
  251. }
  252. public enum WaitRobotMotionStep
  253. {
  254. WaitRobotMotion
  255. }
  256. }
  257. public class ReserveRobotToBusy : ModuleRoutineBase, FSM.IRoutine
  258. {
  259. RobotBaseDevice robot = null;
  260. int timeout = 0;
  261. string header = "ReserveRobotToBusy";
  262. ModuleName module;
  263. public ReserveRobotToBusy(ModuleName _module, RobotBaseDevice _robot, int _timeout) : base(_module)
  264. {
  265. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  266. timeout = _timeout;
  267. module = _module;
  268. }
  269. public void Abort()
  270. {
  271. }
  272. public RState Monitor()
  273. {
  274. Runner.End((int)ReserveRobotToBusyStep.ReserveRobotToBusy, fReserveRobotToBusy, timeout);
  275. return Runner.Status;
  276. }
  277. private bool fReserveRobotToBusy()
  278. {
  279. LogObject.Info(header,"将设备置为Busy状态");
  280. robot.IsBusy = true;
  281. return true;
  282. }
  283. public RState Start(params object[] objs)
  284. {
  285. Reset();
  286. return Runner.Start(module,header);
  287. }
  288. public enum ReserveRobotToBusyStep {
  289. ReserveRobotToBusy
  290. }
  291. }
  292. public class CoolBufferMoveUP : ModuleRoutineBase, FSM.IRoutine
  293. {
  294. IoCoolingBuffer device;
  295. WaferSize size;
  296. ModuleName module;
  297. string header = "CoolBufferMoveUP";
  298. int timeout = 0;
  299. public CoolBufferMoveUP(ModuleName _module, IoCoolingBuffer _device, WaferSize _size, int _timeout) : base(_module)
  300. {
  301. device = _device;
  302. size = _size;
  303. module = _module;
  304. timeout = _timeout;
  305. }
  306. public void Abort()
  307. {
  308. }
  309. public RState Monitor()
  310. {
  311. Runner.End((int)CoolBufferMoveUPStep.CoolBufferMoveUP, fCoolBufferMoveUP,timeout);
  312. return Runner.Status;
  313. }
  314. private bool fCoolBufferMoveUP()
  315. {
  316. if (device.CheckPinUp() || device.Move(size, true, out _))
  317. {
  318. LogObject.Info(header, "CoolBufferMoveUP成功");
  319. return true;
  320. }
  321. else
  322. {
  323. //LogObject.Error(header, "fCoolBufferMoveUP失败");
  324. return false;
  325. }
  326. }
  327. public RState Start(params object[] objs)
  328. {
  329. Reset();
  330. return Runner.Start(module,header);
  331. }
  332. public enum CoolBufferMoveUPStep {
  333. CoolBufferMoveUP
  334. }
  335. }
  336. public class UnGripRobotBlade : ModuleRoutineBase, FSM.IRoutine
  337. {
  338. RobotBaseDevice robot = null;
  339. int timeout = 0;
  340. string header = "UnGripRobotBlade";
  341. ModuleName module;
  342. Hand blade;
  343. //IRoutine WaitRobotMotioRoutine;
  344. public UnGripRobotBlade(ModuleName _module, Hand _blade,RobotBaseDevice _robot, int _timeout) : base(_module)
  345. {
  346. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  347. timeout = _timeout;
  348. module = _module;
  349. blade = _blade;
  350. //WaitRobotMotioRoutine = new WaitRobotMotion(module,robot,timeout);
  351. }
  352. public void Abort()
  353. {
  354. }
  355. public RState Monitor()
  356. {
  357. Runner.Run((int)UnGripRobotBladeStep.UnGripRobotBlade, fUnGripRobotBlade, fWaitRobot, timeout)
  358. .End(100,NullFun,timeout);
  359. return Runner.Status;
  360. }
  361. private bool fWaitRobot()
  362. {
  363. if (!robot.IsBusy)
  364. {
  365. LogObject.Info(header,"robot非忙");
  366. return true;
  367. }
  368. else
  369. {
  370. //LogObject.Error(header,"robot忙");
  371. return false;
  372. }
  373. }
  374. private bool fUnGripRobotBlade()
  375. {
  376. if (robot.Release((RobotArmEnum)blade))
  377. {
  378. LogObject.Info(header, "释放成功");
  379. return true;
  380. }
  381. else
  382. {
  383. LogObject.Error(header,"释放失败");
  384. return false;
  385. }
  386. }
  387. public RState Start(params object[] objs)
  388. {
  389. Reset();
  390. return Runner.Start(module,header);
  391. }
  392. public enum UnGripRobotBladeStep {
  393. UnGripRobotBlade,
  394. WaitRobot
  395. }
  396. }
  397. public class GripRobotBlade : ModuleRoutineBase, FSM.IRoutine
  398. {
  399. RobotBaseDevice robot = null;
  400. int timeout = 0;
  401. string header = "GripRobotBlade";
  402. ModuleName module;
  403. Hand blade;
  404. public GripRobotBlade(ModuleName _module, Hand _blade, RobotBaseDevice _robot, int _timeout) : base(_module)
  405. {
  406. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  407. module = _module;
  408. timeout = _timeout;
  409. blade = _blade;
  410. }
  411. public void Abort()
  412. {
  413. }
  414. public RState Monitor()
  415. {
  416. Runner.Run((int)GripRobotBladeStep.GripRobotBlade, fGripRobotBlade, timeout)
  417. .Wait((int)GripRobotBladeStep.WaitRobot, fWaitRobot, _delay_1s)
  418. .End(100,NullFun,_delay_1s);
  419. return Runner.Status;
  420. }
  421. private bool fWaitRobot()
  422. {
  423. if (!robot.IsBusy)
  424. {
  425. LogObject.Info(header, "robot非忙");
  426. return true;
  427. }
  428. else
  429. {
  430. //LogObject.Error(header, "robot忙");
  431. return false;
  432. }
  433. }
  434. private bool fGripRobotBlade()
  435. {
  436. if (robot.Grip((RobotArmEnum)blade))
  437. {
  438. LogObject.Info(header, "释放成功");
  439. return true;
  440. }
  441. else
  442. {
  443. //LogObject.Error(header, "释放失败");
  444. return false;
  445. }
  446. }
  447. public RState Start(params object[] objs)
  448. {
  449. Reset();
  450. return Runner.Start(module,header);
  451. }
  452. public enum GripRobotBladeStep
  453. {
  454. GripRobotBlade,
  455. WaitRobot
  456. }
  457. }
  458. public class RobotGoto : ModuleRoutineBase, FSM.IRoutine
  459. {
  460. RobotBaseDevice robot = null;
  461. int timeout = 0;
  462. string header = "RobotGoto";
  463. ModuleName module;
  464. Hand blade;
  465. int slot = 0;
  466. RobotPostionEnum postype;
  467. public RobotGoto(ModuleName _module,RobotBaseDevice _robot,int _timeout, Hand _blade, int _slot, RobotPostionEnum _postype) : base(_module)
  468. {
  469. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  470. module = _module;
  471. timeout = _timeout;
  472. blade = _blade;
  473. slot = _slot;
  474. postype = _postype;
  475. }
  476. public void Abort()
  477. {
  478. }
  479. public RState Monitor()
  480. {
  481. Runner
  482. .End((int)RobotGotoStep.RobotGoto,robotgoto,timeout);
  483. return Runner.Status;
  484. }
  485. private bool robotgoto()
  486. {
  487. bool flag = robot.GoTo(new object[4]
  488. {
  489. (RobotArmEnum) blade,
  490. module.ToString(),
  491. slot,
  492. postype
  493. });
  494. if (flag)
  495. {
  496. LogObject.Info(header,"RobotGoto成功");
  497. return true;
  498. }
  499. else
  500. {
  501. //LogObject.Error(header, "RobotGoto失败");
  502. return false;
  503. }
  504. }
  505. public RState Start(params object[] objs)
  506. {
  507. Reset();
  508. return Runner.Start(module,header);
  509. }
  510. public enum RobotGotoStep {
  511. RobotGoto
  512. }
  513. }
  514. //public class HomeGripAndUngripRobotBlade : ModuleRoutineBase, FSM.IRoutine
  515. //{
  516. // public HomeGripAndUngripRobotBlade(ModuleName module) : base(module)
  517. // {
  518. // }
  519. // public void Abort()
  520. // {
  521. // }
  522. // public RState Monitor()
  523. // {
  524. // return Runner.Status;
  525. // }
  526. // public RState Start(params object[] objs)
  527. // {
  528. // return Runner.Start();
  529. // }
  530. //}
  531. }