CommonRoutine.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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(RobotResetStep.RobotReset, fRobotReset, timeout).
  88. End(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(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(RobotArmHomeStep.RobotArmHome, fRobotArmHome, timeout)
  176. .End(RobotArmHomeStep.End, 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. End
  211. }
  212. }
  213. public class WaitRobotMotion : ModuleRoutineBase, FSM.IRoutine
  214. {
  215. RobotBaseDevice robot = null;
  216. int timeout = 0;
  217. string header = "WaitRobotMotion";
  218. ModuleName module;
  219. public WaitRobotMotion(ModuleName _module, RobotBaseDevice _robot, int _timeout) : base(_module)
  220. {
  221. module = _module;
  222. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  223. timeout = _timeout;
  224. }
  225. public void Abort()
  226. {
  227. }
  228. public RState Monitor()
  229. {
  230. Runner.Run(WaitRobotMotionStep.WaitRobotMotion, fWaitRobotMotion , timeout)
  231. .End(WaitRobotMotionStep.End, NullFun,0);
  232. return Runner.Status;
  233. }
  234. private bool fWaitRobotMotion()
  235. {
  236. Trace.WriteLine("WaitRobotMotion");
  237. if (robot.IsReady())
  238. {
  239. LogObject.Info(header, "状态切换为准备态");
  240. return true;
  241. }
  242. else
  243. {
  244. //LogObject.Error(header, "状态未能切换过来");
  245. return false;
  246. }
  247. }
  248. public RState Start(params object[] objs)
  249. {
  250. Reset();
  251. return Runner.Start(module, header);
  252. }
  253. public enum WaitRobotMotionStep
  254. {
  255. WaitRobotMotion,
  256. End
  257. }
  258. }
  259. public class ReserveRobotToBusy : ModuleRoutineBase, FSM.IRoutine
  260. {
  261. RobotBaseDevice robot = null;
  262. int timeout = 0;
  263. string header = "ReserveRobotToBusy";
  264. ModuleName module;
  265. public ReserveRobotToBusy(ModuleName _module, RobotBaseDevice _robot, int _timeout) : base(_module)
  266. {
  267. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  268. timeout = _timeout;
  269. module = _module;
  270. }
  271. public void Abort()
  272. {
  273. }
  274. public RState Monitor()
  275. {
  276. Runner.End(ReserveRobotToBusyStep.ReserveRobotToBusy, fReserveRobotToBusy, timeout);
  277. return Runner.Status;
  278. }
  279. private bool fReserveRobotToBusy()
  280. {
  281. LogObject.Info(header,"将设备置为Busy状态");
  282. robot.IsBusy = true;
  283. return true;
  284. }
  285. public RState Start(params object[] objs)
  286. {
  287. Reset();
  288. return Runner.Start(module,header);
  289. }
  290. public enum ReserveRobotToBusyStep {
  291. ReserveRobotToBusy
  292. }
  293. }
  294. public class CoolBufferMoveUP : ModuleRoutineBase, FSM.IRoutine
  295. {
  296. IoCoolingBuffer device;
  297. WaferSize size;
  298. ModuleName module;
  299. string header = "CoolBufferMoveUP";
  300. int timeout = 0;
  301. public CoolBufferMoveUP(ModuleName _module, IoCoolingBuffer _device, WaferSize _size, int _timeout) : base(_module)
  302. {
  303. device = _device;
  304. size = _size;
  305. module = _module;
  306. timeout = _timeout;
  307. }
  308. public void Abort()
  309. {
  310. }
  311. public RState Monitor()
  312. {
  313. Runner.End(CoolBufferMoveUPStep.CoolBufferMoveUP, fCoolBufferMoveUP,timeout);
  314. return Runner.Status;
  315. }
  316. private bool fCoolBufferMoveUP()
  317. {
  318. if (device.CheckPinUp() || device.Move(size, true, out _))
  319. {
  320. LogObject.Info(header, "CoolBufferMoveUP成功");
  321. return true;
  322. }
  323. else
  324. {
  325. //LogObject.Error(header, "fCoolBufferMoveUP失败");
  326. return false;
  327. }
  328. }
  329. public RState Start(params object[] objs)
  330. {
  331. Reset();
  332. return Runner.Start(module,header);
  333. }
  334. public enum CoolBufferMoveUPStep {
  335. CoolBufferMoveUP
  336. }
  337. }
  338. public class UnGripRobotBlade : ModuleRoutineBase, FSM.IRoutine
  339. {
  340. RobotBaseDevice robot = null;
  341. int timeout = 0;
  342. string header = "UnGripRobotBlade";
  343. ModuleName module;
  344. Hand blade;
  345. //IRoutine WaitRobotMotioRoutine;
  346. public UnGripRobotBlade(ModuleName _module, Hand _blade,RobotBaseDevice _robot, int _timeout) : base(_module)
  347. {
  348. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  349. timeout = _timeout;
  350. module = _module;
  351. blade = _blade;
  352. //WaitRobotMotioRoutine = new WaitRobotMotion(module,robot,timeout);
  353. }
  354. public void Abort()
  355. {
  356. }
  357. public RState Monitor()
  358. {
  359. Runner.Run(UnGripRobotBladeStep.UnGripRobotBlade, fUnGripRobotBlade, fWaitRobot, timeout)
  360. .End(UnGripRobotBladeStep.WaitRobot, NullFun,timeout);
  361. return Runner.Status;
  362. }
  363. private bool fWaitRobot()
  364. {
  365. if (!robot.IsBusy)
  366. {
  367. LogObject.Info(header,"robot非忙");
  368. return true;
  369. }
  370. else
  371. {
  372. //LogObject.Error(header,"robot忙");
  373. return false;
  374. }
  375. }
  376. private bool fUnGripRobotBlade()
  377. {
  378. if (robot.Release((RobotArmEnum)blade))
  379. {
  380. LogObject.Info(header, "释放成功");
  381. return true;
  382. }
  383. else
  384. {
  385. LogObject.Error(header,"释放失败");
  386. return false;
  387. }
  388. }
  389. public RState Start(params object[] objs)
  390. {
  391. Reset();
  392. return Runner.Start(module,header);
  393. }
  394. public enum UnGripRobotBladeStep {
  395. UnGripRobotBlade,
  396. WaitRobot
  397. }
  398. }
  399. public class GripRobotBlade : ModuleRoutineBase, FSM.IRoutine
  400. {
  401. RobotBaseDevice robot = null;
  402. int timeout = 0;
  403. string header = "GripRobotBlade";
  404. ModuleName module;
  405. Hand blade;
  406. public GripRobotBlade(ModuleName _module, Hand _blade, RobotBaseDevice _robot, int _timeout) : base(_module)
  407. {
  408. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  409. module = _module;
  410. timeout = _timeout;
  411. blade = _blade;
  412. }
  413. public void Abort()
  414. {
  415. }
  416. public RState Monitor()
  417. {
  418. Runner.Run(GripRobotBladeStep.GripRobotBlade, fGripRobotBlade, timeout)
  419. .Wait(GripRobotBladeStep.WaitRobot, fWaitRobot, _delay_1s)
  420. .End(GripRobotBladeStep.End, NullFun,_delay_1s);
  421. return Runner.Status;
  422. }
  423. private bool fWaitRobot()
  424. {
  425. if (!robot.IsBusy)
  426. {
  427. LogObject.Info(header, "robot非忙");
  428. return true;
  429. }
  430. else
  431. {
  432. //LogObject.Error(header, "robot忙");
  433. return false;
  434. }
  435. }
  436. private bool fGripRobotBlade()
  437. {
  438. if (robot.Grip((RobotArmEnum)blade))
  439. {
  440. LogObject.Info(header, "释放成功");
  441. return true;
  442. }
  443. else
  444. {
  445. //LogObject.Error(header, "释放失败");
  446. return false;
  447. }
  448. }
  449. public RState Start(params object[] objs)
  450. {
  451. Reset();
  452. return Runner.Start(module,header);
  453. }
  454. public enum GripRobotBladeStep
  455. {
  456. GripRobotBlade,
  457. WaitRobot,
  458. End
  459. }
  460. }
  461. public class RobotGoto : ModuleRoutineBase, FSM.IRoutine
  462. {
  463. RobotBaseDevice robot = null;
  464. int timeout = 0;
  465. string header = "RobotGoto";
  466. ModuleName module;
  467. Hand blade;
  468. int slot = 0;
  469. RobotPostionEnum postype;
  470. public RobotGoto(ModuleName _module,RobotBaseDevice _robot,int _timeout, Hand _blade, int _slot, RobotPostionEnum _postype) : base(_module)
  471. {
  472. robot = DEVICE.GetDevice<RobotBaseDevice>("Robot");
  473. module = _module;
  474. timeout = _timeout;
  475. blade = _blade;
  476. slot = _slot;
  477. postype = _postype;
  478. }
  479. public void Abort()
  480. {
  481. }
  482. public RState Monitor()
  483. {
  484. Runner
  485. .End(RobotGotoStep.RobotGoto,robotgoto,timeout);
  486. return Runner.Status;
  487. }
  488. private bool robotgoto()
  489. {
  490. bool flag = robot.GoTo(new object[4]
  491. {
  492. (RobotArmEnum) blade,
  493. module.ToString(),
  494. slot,
  495. postype
  496. });
  497. if (flag)
  498. {
  499. LogObject.Info(header,"RobotGoto成功");
  500. return true;
  501. }
  502. else
  503. {
  504. //LogObject.Error(header, "RobotGoto失败");
  505. return false;
  506. }
  507. }
  508. public RState Start(params object[] objs)
  509. {
  510. Reset();
  511. return Runner.Start(module,header);
  512. }
  513. public enum RobotGotoStep {
  514. RobotGoto
  515. }
  516. }
  517. //public class HomeGripAndUngripRobotBlade : ModuleRoutineBase, FSM.IRoutine
  518. //{
  519. // public HomeGripAndUngripRobotBlade(ModuleName module) : base(module)
  520. // {
  521. // }
  522. // public void Abort()
  523. // {
  524. // }
  525. // public RState Monitor()
  526. // {
  527. // return Runner.Status;
  528. // }
  529. // public RState Start(params object[] objs)
  530. // {
  531. // return Runner.Start();
  532. // }
  533. //}
  534. }