SETMEntity.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Diagnostics;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using Venus_Core;
  19. using Venus_RT.Devices;
  20. using Venus_RT.Devices.PreAligner;
  21. using Venus_RT.Devices.TM;
  22. using Venus_RT.Devices.VCE;
  23. using Venus_RT.Modules.PMs;
  24. using static Mono.Security.X509.X520;
  25. namespace Venus_RT.Modules.TM.VenusEntity
  26. {
  27. public class SETMEntity : Entity, IModuleEntity
  28. {
  29. public enum STATE
  30. {
  31. Unknown,
  32. Init,
  33. Initializing,
  34. InitializingRB,
  35. Idle,
  36. Error,
  37. Pumping,
  38. Venting,
  39. Purging,
  40. Leakchecking,
  41. Picking,
  42. Placing,
  43. Swaping,
  44. PMPicking,
  45. PMPlacing,
  46. PMSwaping,
  47. Aligning,
  48. Mapping,
  49. Extending,
  50. Retracting,
  51. Swapping,
  52. Gotoing,
  53. ControllingPressure,
  54. }
  55. public enum MSG
  56. {
  57. Home,
  58. RobotHome,
  59. Online,
  60. Offline,
  61. Pump,
  62. Vent,
  63. Purge,
  64. CyclePurge,
  65. LeakCheck,
  66. Pick,
  67. Place,
  68. Swap,
  69. DoublePick,
  70. DoublePlace,
  71. DoubleSwap,
  72. PMPick,
  73. PMPlace,
  74. PMSwap,
  75. Extend,
  76. Retract,
  77. TMCycle,
  78. ControlPressure,
  79. Error,
  80. Abort,
  81. AbortControlPressure,
  82. Align,
  83. CreateJob,
  84. StartJob,
  85. Goto,
  86. }
  87. #region 公开变量
  88. public ModuleName Module => _module;
  89. public bool IsIdle
  90. {
  91. get { return fsm.State == (int)STATE.Idle; }
  92. }
  93. public bool IsError
  94. {
  95. get { return fsm.State == (int)STATE.Error; }
  96. }
  97. public bool IsInit
  98. {
  99. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  100. }
  101. public bool IsBusy
  102. {
  103. get { return !IsInit && !IsError && !IsIdle; }
  104. }
  105. public RState RobotStatus
  106. {
  107. get
  108. {
  109. if (_robot.Status != RState.Running)
  110. {
  111. if (_robotWatch.ElapsedMilliseconds < 100)
  112. return RState.Running;
  113. else
  114. return _robot.Status;
  115. }
  116. else
  117. return RState.Running;
  118. }
  119. }
  120. /// <summary>
  121. /// VCE部分的内容从变量转化为查询方法
  122. /// </summary>
  123. public bool VCEIsATM(ModuleName VCEName)
  124. {
  125. switch (_module)
  126. {
  127. case ModuleName.SETM:
  128. return _tm.IsVCEATM;
  129. case ModuleName.DETM:
  130. return VCEName == ModuleName.VCEA ? _tm.IsVCEAATM: _tm.IsVCEBATM;
  131. default:
  132. return false;
  133. }
  134. }
  135. public bool TMIsATM => _tm.IsTMATM;
  136. public bool TMIsVAC => _tm.IsTMVAC;
  137. public bool VCEIsVAC(ModuleName VCEName)
  138. {
  139. switch (_module)
  140. {
  141. case ModuleName.SETM:
  142. return _tm.IsVCEVAC;
  143. case ModuleName.DETM:
  144. return VCEName == ModuleName.VCEA ? _tm.IsVCEAVAC : _tm.IsVCEBVAC;
  145. default:
  146. return false;
  147. }
  148. }
  149. public bool IsPMASlitDoorClosed => _tm.PMASlitDoorClosed;
  150. public bool IsPMBSlitDoorClosed => _tm.PMBSlitDoorClosed;
  151. public bool IsPMCSlitDoorClosed => _tm.PMCSlitDoorClosed;
  152. public bool IsPMDSlitDoorClosed => _tm.PMDSlitDoorClosed;
  153. public bool IsVCESlitDoorClosed(ModuleName VCEName)
  154. {
  155. return _tm.VCESlitDoorClosed(VCEName);
  156. }
  157. public bool IsPMASlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMA);
  158. public bool IsPMBSlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMB);
  159. public bool IsPMCSlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMC);
  160. public bool IsPMDSlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMD);
  161. //public bool IsVCESlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.VCE1);
  162. public double VCEPressure(ModuleName VCEName)
  163. {
  164. switch (_module)
  165. {
  166. case ModuleName.SETM:
  167. return _tm.VCEPressure;
  168. case ModuleName.DETM:
  169. return VCEName == ModuleName.SETM ? _tm.VCEAPressure: _tm.VCEBPressure;
  170. default:
  171. return 0;
  172. }
  173. }
  174. private bool _IsOnline;
  175. public bool IsOnline => _IsOnline;
  176. //public bool IsTMVac => _tm.IsTMVac;
  177. //public bool IsTMATM => _tm.IsTMATM;
  178. #endregion
  179. #region 私有变量
  180. private readonly TMBase _tm;
  181. private readonly ITransferRobot _robot;
  182. private readonly IPreAlign _vpa;
  183. private readonly SEMFHomeRoutine _homeRoutine;
  184. private readonly SEMFPickRoutine _pickRoutine;
  185. private readonly SEMFPlaceRoutine _placeRoutine;
  186. private readonly SEMFVentRoutine _ventRoutine;
  187. private readonly SEMFPumpRoutine _pumpRoutine;
  188. private readonly SEMFLeakCheckRoutine _leakcheckRoutine;
  189. private readonly SEMFPMPickRoutine _pickpmRoutine;
  190. private readonly SEMFPMPlaceRoutine _placepmRoutine;
  191. private readonly SEMFSwapRoutine _swaproutine;
  192. private readonly SEMFPMSwapRoutine _pmswaproutine;
  193. private readonly SEMFPMRetractRoutine _pmRetractRoutine;
  194. private readonly SEMFPMExtendRoutine _pmExtendRoutine;
  195. //private readonly
  196. //private bool startControlPressureFlag = true;
  197. //private bool stopControlPressureFlag = false;
  198. private Stopwatch _robotWatch = new Stopwatch();
  199. private R_TRIG _robotIdleTrigger = new R_TRIG();
  200. //private int _controlPressureCheckPoint = 100;
  201. //private int _controlPressureSetPoint = 90;
  202. //private int _controlFlowSetPoint = 90;
  203. private ModuleName _module;
  204. #endregion
  205. public SETMEntity(ModuleName module)
  206. {
  207. _module = module;
  208. if (module == ModuleName.SETM)
  209. _tm = DEVICE.GetDevice<HongHuTM>(module.ToString());
  210. if (module == ModuleName.DETM)
  211. _tm = DEVICE.GetDevice<HongHuDETM>(module.ToString());
  212. if (ModuleHelper.IsInstalled(ModuleName.TMRobot))
  213. _robot = new HongHuVR(_module);
  214. _vpa = new HongHuVPA(_module);
  215. _robotWatch = new Stopwatch();
  216. _homeRoutine = new SEMFHomeRoutine(_tm,_robot, _vpa, module);
  217. _pickRoutine = new SEMFPickRoutine(_tm,_robot, _vpa, module);
  218. _placeRoutine = new SEMFPlaceRoutine(_tm, _robot, _vpa, module);
  219. _pumpRoutine = new SEMFPumpRoutine(_tm, module);
  220. _ventRoutine = new SEMFVentRoutine(_tm, module);
  221. _leakcheckRoutine = new SEMFLeakCheckRoutine(_tm, module);
  222. _pickpmRoutine = new SEMFPMPickRoutine(_tm, _robot, module);
  223. _placepmRoutine = new SEMFPMPlaceRoutine(_tm, _robot, module);
  224. _swaproutine = new SEMFSwapRoutine(_tm, _robot, module);
  225. _pmswaproutine = new SEMFPMSwapRoutine(_tm, _robot, module);
  226. _pmExtendRoutine = new SEMFPMExtendRoutine(_tm, _robot, _vpa, module);
  227. _pmRetractRoutine = new SEMFPMRetractRoutine(_tm, _robot, _vpa, module);
  228. InitFsmMap();
  229. }
  230. protected override bool Init()
  231. {
  232. DATA.Subscribe($"{_module}.FsmState", () => ((STATE)fsm.State).ToString());
  233. DATA.Subscribe($"{_module}.RobotMoveAction", () => _robot.TMRobotMoveInfo, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  234. DATA.Subscribe($"{_module}.RobotMoveAction.ArmTarget", () => _robot.TMRobotMoveInfo.ArmTarget.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  235. DATA.Subscribe($"{_module}.RobotMoveAction.BladeTarget", () => _robot.TMRobotMoveInfo.BladeTarget, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  236. DATA.Subscribe($"{_module}.RobotMoveAction.RobotAction", () => _robot.TMRobotMoveInfo.Action.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  237. DATA.Subscribe($"{_module}.IsOnline", () => IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  238. DATA.Subscribe($"{_module}.IsOffline", () => !IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  239. OP.Subscribe($"{_module}.Goto", (cmd, args) => RobotGoto(args));
  240. OP.Subscribe($"{_module}.Home", (cmd, args) => { PostMsg(MSG.Home, args); return true; });
  241. OP.Subscribe($"{_module}.Abort", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  242. OP.Subscribe($"{_module}.Pick", (cmd, args) => { PostMsg(MSG.Pick, args); return true; });
  243. OP.Subscribe($"{_module}.Place", (cmd, args) => { PostMsg(MSG.Place, args); return true; });
  244. OP.Subscribe($"{_module}.Extend", (cmd, args) => { PostMsg(MSG.Extend, args); return true; });
  245. OP.Subscribe($"{_module}.Retract", (cmd, args) => { PostMsg(MSG.Retract, args); return true; });
  246. OP.Subscribe($"{_module}.PMPick", (cmd, args) => { PostMsg(MSG.PMPick, args); return true; });
  247. OP.Subscribe($"{_module}.PMPlace", (cmd, args) => { PostMsg(MSG.PMPlace, args); return true; });
  248. OP.Subscribe($"{_module}.PumpDown", (cmd, args) => { PostMsg(MSG.Pump); return true; });
  249. OP.Subscribe($"{_module}.Vent", (cmd, args) => { PostMsg(MSG.Vent); return true; });
  250. OP.Subscribe($"{_module}.LeakCheck", (cmd, args) => { PostMsg(MSG.LeakCheck); return true; });
  251. OP.Subscribe($"{_module}.Online", (cmd, args) =>
  252. {
  253. if (IsIdle)
  254. _IsOnline = true;
  255. else
  256. LOG.Write(eEvent.WARN_TM,_module,"cannot Set Online as TM is not idle");
  257. return true;
  258. });
  259. OP.Subscribe($"{_module}.Offline", (cmd, args) =>
  260. {
  261. _IsOnline = false;
  262. return true;
  263. });
  264. return true;
  265. }
  266. private void InitFsmMap()
  267. {
  268. fsm = new StateMachine<SETMEntity>($"{_module}", (int)STATE.Init, 50);
  269. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  270. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  271. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  272. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  273. //Home
  274. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomeTimeout, STATE.Idle);
  275. Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Init);
  276. //Pick
  277. Transition(STATE.Idle, MSG.Pick, fnStartPick, STATE.Picking);
  278. Transition(STATE.Picking, FSM_MSG.TIMER, fnPickTimeout, STATE.Idle);
  279. Transition(STATE.Picking, MSG.Abort, fnAbortPick, STATE.Idle);
  280. //Place
  281. Transition(STATE.Idle, MSG.Place, fnStartPlace, STATE.Placing);
  282. Transition(STATE.Placing, FSM_MSG.TIMER, fnPlaceTimeout, STATE.Idle);
  283. Transition(STATE.Placing, MSG.Abort, fnAbortPlace, STATE.Idle);
  284. //Pump
  285. Transition(STATE.Idle, MSG.Pump, fnStartPump, STATE.Pumping);
  286. Transition(STATE.Pumping, FSM_MSG.TIMER, fnPumpTimeout, STATE.Idle);
  287. Transition(STATE.Pumping, MSG.Abort, fnAbortPump, STATE.Idle);
  288. //Vent
  289. Transition(STATE.Idle, MSG.Vent, fnStartVent, STATE.Venting);
  290. Transition(STATE.Venting, FSM_MSG.TIMER, fnVentTimeout, STATE.Idle);
  291. Transition(STATE.Venting, MSG.Abort, fnAbortVent, STATE.Idle);
  292. //PMPick
  293. Transition(STATE.Idle, MSG.PMPick, fnStartPMPick, STATE.PMPicking);
  294. Transition(STATE.PMPicking, FSM_MSG.TIMER, fnPMPickTimeout, STATE.Idle);
  295. Transition(STATE.PMPicking, MSG.Abort, fnAbortPMPick, STATE.Idle);
  296. //PMPlace
  297. Transition(STATE.Idle, MSG.PMPlace, fnStartPMPlace, STATE.PMPlacing);
  298. Transition(STATE.PMPlacing, FSM_MSG.TIMER, fnPMPlaceTimeout, STATE.Idle);
  299. Transition(STATE.PMPlacing, MSG.Abort, fnAbortPMPlace, STATE.Idle);
  300. //PA align
  301. Transition(STATE.Idle, MSG.Align, fnStartAlign, STATE.Aligning);
  302. Transition(STATE.Aligning, FSM_MSG.TIMER, fnAlignTimeout, STATE.Idle);
  303. Transition(STATE.Aligning, MSG.Abort, fnAbortAlign, STATE.Idle);
  304. //Swap
  305. Transition(STATE.Idle, MSG.Swap, fnStartSwap, STATE.Swapping);
  306. Transition(STATE.Swapping, FSM_MSG.TIMER, fnSwapTimeout, STATE.Idle);
  307. Transition(STATE.Swapping, MSG.Abort, fnAbortSwap, STATE.Idle);
  308. //PM Swap
  309. Transition(STATE.Idle, MSG.PMSwap, fnStartPMSwap, STATE.PMSwaping);
  310. Transition(STATE.PMSwaping, FSM_MSG.TIMER, fnPMSwapTimeout, STATE.Idle);
  311. Transition(STATE.PMSwaping, MSG.Abort, fnAbortPMSwap, STATE.Idle);
  312. //Extend
  313. Transition(STATE.Idle, MSG.Extend, FnStartExtend, STATE.Extending);
  314. Transition(STATE.Extending, FSM_MSG.TIMER, FnExtend, STATE.Idle);
  315. Transition(STATE.Extending, MSG.Abort, FnAbortExtend, STATE.Idle);
  316. //Retract
  317. Transition(STATE.Idle, MSG.Retract, FnStartRetract, STATE.Retracting);
  318. Transition(STATE.Retracting, FSM_MSG.TIMER, FnRetract, STATE.Idle);
  319. Transition(STATE.Retracting, MSG.Abort, FnAbortRetract, STATE.Idle);
  320. //leakcheck
  321. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.Leakchecking);
  322. Transition(STATE.Leakchecking, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  323. Transition(STATE.Leakchecking, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  324. //Control Pressure
  325. AnyStateTransition(FSM_MSG.TIMER, ControlPressureTimer_Elapsed, FSM_STATE.SAME);
  326. Running = true;
  327. }
  328. private bool RobotGoto(object[] param)
  329. {
  330. return _robot.Goto((ModuleName)param[0], (int)param[1], (Hand)param[2]);
  331. }
  332. private bool FnStartExtend(object[] param)
  333. {
  334. return _pmExtendRoutine.Start(param) == RState.Running;
  335. }
  336. private bool FnExtend(object[] param)
  337. {
  338. RState ret = _pmExtendRoutine.Monitor();
  339. if (ret == RState.Failed || ret == RState.Timeout)
  340. {
  341. PostMsg(MSG.Error);
  342. return false;
  343. }
  344. return ret == RState.End;
  345. }
  346. private bool FnAbortExtend(object[] param)
  347. {
  348. _pmExtendRoutine.Abort();
  349. return true;
  350. }
  351. private bool FnStartRetract(object[] param)
  352. {
  353. return _pmRetractRoutine.Start(param) == RState.Running;
  354. }
  355. private bool FnRetract(object[] param)
  356. {
  357. RState ret = _pmRetractRoutine.Monitor();
  358. if (ret == RState.Failed || ret == RState.Timeout)
  359. {
  360. PostMsg(MSG.Error);
  361. return false;
  362. }
  363. return ret == RState.End;
  364. }
  365. private bool FnAbortRetract(object[] param)
  366. {
  367. _pmRetractRoutine.Abort();
  368. return true;
  369. }
  370. private bool FnStartLeakCheck(object[] param)
  371. {
  372. return _leakcheckRoutine.Start(param) == RState.Running;
  373. }
  374. private bool FnLeakCheckTimeout(object[] param)
  375. {
  376. RState ret = _leakcheckRoutine.Monitor();
  377. if (ret == RState.Failed || ret == RState.Timeout)
  378. {
  379. PostMsg(MSG.Error);
  380. return false;
  381. }
  382. return ret == RState.End;
  383. }
  384. private bool FnAbortLeakCheck(object[] param)
  385. {
  386. _leakcheckRoutine.Abort();
  387. return true;
  388. }
  389. private bool fnAbortPMSwap(object[] param)
  390. {
  391. _pmswaproutine.Abort();
  392. return true;
  393. }
  394. private bool fnPMSwapTimeout(object[] param)
  395. {
  396. RState ret = _pmswaproutine.Monitor();
  397. if (ret == RState.Failed || ret == RState.Timeout)
  398. {
  399. PostMsg(MSG.Error);
  400. return false;
  401. }
  402. return ret == RState.End;
  403. }
  404. private bool fnStartPMSwap(object[] param)
  405. {
  406. return _pmswaproutine.Start(param) == RState.Running;
  407. }
  408. private bool fnAbortSwap(object[] param)
  409. {
  410. _swaproutine.Abort();
  411. return true;
  412. }
  413. private bool fnSwapTimeout(object[] param)
  414. {
  415. RState ret = _swaproutine.Monitor();
  416. if (ret == RState.Failed || ret == RState.Timeout)
  417. {
  418. PostMsg(MSG.Error);
  419. return false;
  420. }
  421. return ret == RState.End;
  422. }
  423. private bool fnStartSwap(object[] param)
  424. {
  425. return _swaproutine.Start(param) == RState.Running;
  426. }
  427. private bool fnStartAlign(object[] param)
  428. {
  429. if (float.TryParse(param[0].ToString(), out float angle))
  430. {
  431. return _vpa.Align();
  432. }
  433. else
  434. {
  435. LOG.Write(eEvent.ERR_TM,ModuleName.Aligner1,$"wrong angle, value is {param[0]}.");
  436. return false;
  437. }
  438. }
  439. private bool fnAlignTimeout(object[] param)
  440. {
  441. if (_vpa.Status == RState.End)
  442. {
  443. return true;
  444. }
  445. else if (_vpa.Status != RState.Running)
  446. {
  447. LOG.Write(eEvent.ERR_TM, ModuleName.Aligner1, $"PreAligner align failed: {_vpa.Status}");
  448. return true;
  449. }
  450. return false;
  451. }
  452. private bool fnAbortAlign(object[] param)
  453. {
  454. return true;
  455. }
  456. private bool fnAbortPMPlace(object[] param)
  457. {
  458. _placepmRoutine.Abort();
  459. return true;
  460. }
  461. private bool fnPMPlaceTimeout(object[] param)
  462. {
  463. RState ret = _placepmRoutine.Monitor();
  464. if (ret == RState.Failed || ret == RState.Timeout)
  465. {
  466. PostMsg(MSG.Error);
  467. return false;
  468. }
  469. return ret == RState.End;
  470. }
  471. private bool fnStartPMPlace(object[] param)
  472. {
  473. return _placepmRoutine.Start(param) == RState.Running;
  474. }
  475. private bool fnAbortPMPick(object[] param)
  476. {
  477. _pickpmRoutine.Abort();
  478. return true;
  479. }
  480. private bool fnPMPickTimeout(object[] param)
  481. {
  482. RState ret = _pickpmRoutine.Monitor();
  483. if (ret == RState.Failed || ret == RState.Timeout)
  484. {
  485. PostMsg(MSG.Error);
  486. return false;
  487. }
  488. return ret == RState.End;
  489. }
  490. private bool fnStartPMPick(object[] param)
  491. {
  492. return _pickpmRoutine.Start(param) == RState.Running;
  493. }
  494. private bool fnAbortVent(object[] param)
  495. {
  496. _ventRoutine.Abort();
  497. return true;
  498. }
  499. private bool fnVentTimeout(object[] param)
  500. {
  501. RState ret = _ventRoutine.Monitor();
  502. if (ret == RState.Failed || ret == RState.Timeout)
  503. {
  504. _ventRoutine.Abort();
  505. PostMsg(MSG.Error);
  506. return false;
  507. }
  508. return ret == RState.End;
  509. }
  510. private bool fnStartVent(object[] param)
  511. {
  512. return _ventRoutine.Start(param) == RState.Running;
  513. }
  514. private bool fnAbortPump(object[] param)
  515. {
  516. _pumpRoutine.Abort();
  517. return true;
  518. }
  519. private bool fnPumpTimeout(object[] param)
  520. {
  521. RState ret = _pumpRoutine.Monitor();
  522. if (ret == RState.Failed || ret == RState.Timeout)
  523. {
  524. _pumpRoutine.Abort();
  525. PostMsg(MSG.Error);
  526. return false;
  527. }
  528. return ret == RState.End;
  529. }
  530. private bool fnStartPump(object[] param)
  531. {
  532. return _pumpRoutine.Start(param) == RState.Running;
  533. }
  534. private bool fnAbortPlace(object[] param)
  535. {
  536. return true;
  537. }
  538. private bool fnPlaceTimeout(object[] param)
  539. {
  540. RState ret = _placeRoutine.Monitor();
  541. if (ret == RState.Failed || ret == RState.Timeout)
  542. {
  543. PostMsg(MSG.Error);
  544. return false;
  545. }
  546. return ret == RState.End;
  547. }
  548. private bool fnStartPlace(object[] param)
  549. {
  550. return _placeRoutine.Start(param) == RState.Running;
  551. }
  552. private bool fnAbortPick(object[] param)
  553. {
  554. _pickRoutine.Abort();
  555. return true;
  556. }
  557. private bool fnStartPick(object[] param)
  558. {
  559. return _pickRoutine.Start(param) == RState.Running;
  560. }
  561. private bool fnPickTimeout(object[] param)
  562. {
  563. RState ret = _pickRoutine.Monitor();
  564. if (ret == RState.Failed || ret == RState.Timeout)
  565. {
  566. PostMsg(MSG.Error);
  567. return false;
  568. }
  569. return ret == RState.End;
  570. }
  571. private bool fnAbortHome(object[] param)
  572. {
  573. _homeRoutine.Abort();
  574. return true;
  575. }
  576. private bool fnHome(object[] param)
  577. {
  578. if (fsm.State == (int)STATE.Init && param.Length > 0)//带参home
  579. {
  580. return false;
  581. }
  582. else
  583. return _homeRoutine.Start(param) == RState.Running;
  584. }
  585. private bool fnHomeTimeout(object[] param)
  586. {
  587. RState ret = _homeRoutine.Monitor();
  588. if (ret == RState.Failed || ret == RState.Timeout)
  589. {
  590. PostMsg(MSG.Error);
  591. return false;
  592. }
  593. return ret == RState.End;
  594. }
  595. private bool fnOffline(object[] param)
  596. {
  597. //IsOnline = false;
  598. //return true;
  599. throw new NotImplementedException();
  600. }
  601. private bool fnOnline(object[] param)
  602. {
  603. //IsOnline = true;
  604. //return true;
  605. throw new NotImplementedException();
  606. }
  607. private bool fnError(object[] param)
  608. {
  609. return true;
  610. }
  611. /// <summary>
  612. /// 控压处理逻辑
  613. /// 需要按照module去控压
  614. /// 在SE中 因为共用drypump 其前端压力以及使用锁存在抢占可能 需要在pumpstate处于idle下
  615. /// 在DE中 因为分开用drypump 可以在online后始终保持控压的模式
  616. /// </summary>
  617. /// <param name="param"></param>
  618. /// <returns></returns>
  619. private bool ControlPressureTimer_Elapsed(object[] param)
  620. {
  621. // robot idle check
  622. _robotIdleTrigger.CLK = _robot.Status != RState.Running;
  623. if (_robotIdleTrigger.Q)
  624. {
  625. _robotWatch.Restart();
  626. }
  627. if (RouteManager.IsATMMode)
  628. return true;
  629. if (IsOnline)
  630. {
  631. switch (Module)
  632. {
  633. case ModuleName.SETM:
  634. //nobody use pump
  635. if (_tm.PumpingState == PumpState.Idle && !_tm.IsPressureControl)
  636. _tm.PressureControl(true);
  637. break;
  638. case ModuleName.DETM:
  639. if(!_tm.IsPressureControl)
  640. _tm.PressureControl(true);
  641. break;
  642. default:
  643. return true;
  644. }
  645. }
  646. else
  647. {
  648. switch (Module)
  649. {
  650. case ModuleName.SETM:
  651. case ModuleName.DETM:
  652. if(_tm.IsPressureControl)
  653. _tm.PressureControl(false);
  654. break;
  655. default:
  656. return true;
  657. }
  658. }
  659. //废弃代码
  660. //if (IsOnline && _tm.PumpingState == PumpState.Idle)
  661. //{
  662. //
  663. //}
  664. //else
  665. //{
  666. // if (!SC.GetValue<bool>($"{_module}.PressureControl.ControlWriteMode"))
  667. // {
  668. // SC.SetItemValue($"{_module}.PressureControl.ControlWriteMode", true);
  669. // }
  670. //}
  671. return true;
  672. }
  673. public bool Check(int msg, out string reason, params object[] args)
  674. {
  675. reason = "";
  676. return true;
  677. }
  678. public bool CheckAcked(int msg)
  679. {
  680. return fsm.CheckExecuted(msg);
  681. }
  682. public bool CheckToPostMessage(int msg, params object[] args)
  683. {
  684. if (!fsm.FindTransition(fsm.State, msg))
  685. {
  686. LOG.Write(eEvent.WARN_FSM_WARN, _module, $"TM is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  687. return false;
  688. }
  689. Running = true;
  690. fsm.PostMsg(msg, args);
  691. return true;
  692. }
  693. public int Invoke(string function, params object[] args)
  694. {
  695. switch (function)
  696. {
  697. case "Home":
  698. CheckToPostMessage((int)MSG.Home);
  699. return (int)MSG.Home;
  700. }
  701. return (int)FSM_MSG.NONE;
  702. }
  703. }
  704. }