SETMEntity.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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 (RtInstance.ConfigType)
  126. {
  127. case ConfigType.VenusSE:
  128. return _tm.IsVCEATM;
  129. case ConfigType.VenusDE:
  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 (RtInstance.ConfigType)
  140. {
  141. case ConfigType.VenusSE:
  142. return _tm.IsVCEVAC;
  143. case ConfigType.VenusDE:
  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 (RtInstance.ConfigType)
  165. {
  166. case ConfigType.VenusSE:
  167. return _tm.VCEPressure;
  168. case ConfigType.VenusDE:
  169. return VCEName == ModuleName.VCEA ? _tm.VCEAPressure: _tm.VCEBPressure;
  170. default:
  171. return 0;
  172. }
  173. }
  174. public bool VCECanMove(ModuleName VCEName)
  175. {
  176. switch (RtInstance.ConfigType)
  177. {
  178. case ConfigType.VenusSE:
  179. if(_tm.VCESlitDoorClosed(VCEName))
  180. return true;
  181. else
  182. return _tm.RobotNotExtendVCE;
  183. case ConfigType.VenusDE:
  184. if (_tm.VCESlitDoorClosed(VCEName))
  185. return true;
  186. else
  187. return VCEName == ModuleName.VCEA ? _tm.RobotNotExtendVCEA : _tm.RobotNotExtendVCEB;
  188. default:
  189. return false;
  190. }
  191. }
  192. private bool _IsOnline;
  193. public bool IsOnline => _IsOnline;
  194. //public bool IsTMVac => _tm.IsTMVac;
  195. //public bool IsTMATM => _tm.IsTMATM;
  196. #endregion
  197. #region 私有变量
  198. private readonly TMBase _tm;
  199. private readonly ITransferRobot _robot;
  200. private readonly IPreAlign _vpa;
  201. private readonly SEMFHomeRoutine _homeRoutine;
  202. private readonly SEMFPickRoutine _pickRoutine;
  203. private readonly SEMFPlaceRoutine _placeRoutine;
  204. private readonly SEMFVentRoutine _ventRoutine;
  205. private readonly SEMFPumpRoutine _pumpRoutine;
  206. private readonly SEMFLeakCheckRoutine _leakcheckRoutine;
  207. private readonly SEMFPMPickRoutine _pickpmRoutine;
  208. private readonly SEMFPMPlaceRoutine _placepmRoutine;
  209. private readonly SEMFSwapRoutine _swaproutine;
  210. private readonly SEMFPMSwapRoutine _pmswaproutine;
  211. private readonly SEMFPMRetractRoutine _pmRetractRoutine;
  212. private readonly SEMFPMExtendRoutine _pmExtendRoutine;
  213. //private readonly
  214. //private bool startControlPressureFlag = true;
  215. //private bool stopControlPressureFlag = false;
  216. private Stopwatch _robotWatch = new Stopwatch();
  217. private R_TRIG _robotIdleTrigger = new R_TRIG();
  218. //private int _controlPressureCheckPoint = 100;
  219. //private int _controlPressureSetPoint = 90;
  220. //private int _controlFlowSetPoint = 90;
  221. private ModuleName _module;
  222. #endregion
  223. public SETMEntity(ModuleName module)
  224. {
  225. _module = module;
  226. switch (RtInstance.ConfigType)
  227. {
  228. case ConfigType.VenusSE:
  229. _tm = DEVICE.GetDevice<HongHuTM>(module.ToString());
  230. break;
  231. case ConfigType.VenusDE:
  232. _tm = DEVICE.GetDevice<HongHuDETM>(module.ToString());
  233. break;
  234. }
  235. if (ModuleHelper.IsInstalled(ModuleName.TMRobot))
  236. _robot = new HongHuVR(_module);
  237. _vpa = new HongHuVPA(_module);
  238. _robotWatch = new Stopwatch();
  239. _homeRoutine = new SEMFHomeRoutine(_tm,_robot, _vpa, module);
  240. _pickRoutine = new SEMFPickRoutine(_tm,_robot, _vpa, module);
  241. _placeRoutine = new SEMFPlaceRoutine(_tm, _robot, _vpa, module);
  242. _pumpRoutine = new SEMFPumpRoutine(_tm, module);
  243. _ventRoutine = new SEMFVentRoutine(_tm, module);
  244. _leakcheckRoutine = new SEMFLeakCheckRoutine(_tm, module);
  245. _pickpmRoutine = new SEMFPMPickRoutine(_tm, _robot, module);
  246. _placepmRoutine = new SEMFPMPlaceRoutine(_tm, _robot, module);
  247. _swaproutine = new SEMFSwapRoutine(_tm, _robot, module);
  248. _pmswaproutine = new SEMFPMSwapRoutine(_tm, _robot, module);
  249. _pmExtendRoutine = new SEMFPMExtendRoutine(_tm, _robot, _vpa, module);
  250. _pmRetractRoutine = new SEMFPMRetractRoutine(_tm, _robot, _vpa, module);
  251. InitFsmMap();
  252. }
  253. protected override bool Init()
  254. {
  255. DATA.Subscribe($"{_module}.FsmState", () => ((STATE)fsm.State).ToString());
  256. DATA.Subscribe($"{_module}.RobotMoveAction", () => _robot.TMRobotMoveInfo, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  257. DATA.Subscribe($"{_module}.RobotMoveAction.ArmTarget", () => _robot.TMRobotMoveInfo.ArmTarget.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  258. DATA.Subscribe($"{_module}.RobotMoveAction.BladeTarget", () => _robot.TMRobotMoveInfo.BladeTarget, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  259. DATA.Subscribe($"{_module}.RobotMoveAction.RobotAction", () => _robot.TMRobotMoveInfo.Action.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  260. DATA.Subscribe($"{_module}.IsOnline", () => IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  261. DATA.Subscribe($"{_module}.IsOffline", () => !IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  262. OP.Subscribe($"{_module}.Goto", (cmd, args) => RobotGoto(args));
  263. OP.Subscribe($"{_module}.Home", (cmd, args) => { PostMsg(MSG.Home, args); return true; });
  264. OP.Subscribe($"{_module}.Abort", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  265. OP.Subscribe($"{_module}.Pick", (cmd, args) => { PostMsg(MSG.Pick, args); return true; });
  266. OP.Subscribe($"{_module}.Place", (cmd, args) => { PostMsg(MSG.Place, args); return true; });
  267. OP.Subscribe($"{_module}.Extend", (cmd, args) => { PostMsg(MSG.Extend, args); return true; });
  268. OP.Subscribe($"{_module}.Retract", (cmd, args) => { PostMsg(MSG.Retract, args); return true; });
  269. OP.Subscribe($"{_module}.PMPick", (cmd, args) => { PostMsg(MSG.PMPick, args); return true; });
  270. OP.Subscribe($"{_module}.PMPlace", (cmd, args) => { PostMsg(MSG.PMPlace, args); return true; });
  271. OP.Subscribe($"{_module}.PumpDown", (cmd, args) => { PostMsg(MSG.Pump); return true; });
  272. OP.Subscribe($"{_module}.Vent", (cmd, args) => { PostMsg(MSG.Vent); return true; });
  273. OP.Subscribe($"{_module}.LeakCheck", (cmd, args) => { PostMsg(MSG.LeakCheck); return true; });
  274. OP.Subscribe($"{_module}.Online", (cmd, args) =>
  275. {
  276. if (IsIdle)
  277. _IsOnline = true;
  278. else
  279. LOG.Write(eEvent.WARN_TM,_module,"cannot Set Online as TM is not idle");
  280. return true;
  281. });
  282. OP.Subscribe($"{_module}.Offline", (cmd, args) =>
  283. {
  284. _IsOnline = false;
  285. return true;
  286. });
  287. return true;
  288. }
  289. private void InitFsmMap()
  290. {
  291. fsm = new StateMachine<SETMEntity>($"{_module}", (int)STATE.Init, 50);
  292. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  293. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  294. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  295. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  296. //Home
  297. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomeTimeout, STATE.Idle);
  298. Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Init);
  299. //Pick
  300. Transition(STATE.Idle, MSG.Pick, fnStartPick, STATE.Picking);
  301. Transition(STATE.Picking, FSM_MSG.TIMER, fnPickTimeout, STATE.Idle);
  302. Transition(STATE.Picking, MSG.Abort, fnAbortPick, STATE.Idle);
  303. //Place
  304. Transition(STATE.Idle, MSG.Place, fnStartPlace, STATE.Placing);
  305. Transition(STATE.Placing, FSM_MSG.TIMER, fnPlaceTimeout, STATE.Idle);
  306. Transition(STATE.Placing, MSG.Abort, fnAbortPlace, STATE.Idle);
  307. //Pump
  308. Transition(STATE.Idle, MSG.Pump, fnStartPump, STATE.Pumping);
  309. Transition(STATE.Pumping, FSM_MSG.TIMER, fnPumpTimeout, STATE.Idle);
  310. Transition(STATE.Pumping, MSG.Abort, fnAbortPump, STATE.Idle);
  311. //Vent
  312. Transition(STATE.Idle, MSG.Vent, fnStartVent, STATE.Venting);
  313. Transition(STATE.Venting, FSM_MSG.TIMER, fnVentTimeout, STATE.Idle);
  314. Transition(STATE.Venting, MSG.Abort, fnAbortVent, STATE.Idle);
  315. //PMPick
  316. Transition(STATE.Idle, MSG.PMPick, fnStartPMPick, STATE.PMPicking);
  317. Transition(STATE.PMPicking, FSM_MSG.TIMER, fnPMPickTimeout, STATE.Idle);
  318. Transition(STATE.PMPicking, MSG.Abort, fnAbortPMPick, STATE.Idle);
  319. //PMPlace
  320. Transition(STATE.Idle, MSG.PMPlace, fnStartPMPlace, STATE.PMPlacing);
  321. Transition(STATE.PMPlacing, FSM_MSG.TIMER, fnPMPlaceTimeout, STATE.Idle);
  322. Transition(STATE.PMPlacing, MSG.Abort, fnAbortPMPlace, STATE.Idle);
  323. //PA align
  324. Transition(STATE.Idle, MSG.Align, fnStartAlign, STATE.Aligning);
  325. Transition(STATE.Aligning, FSM_MSG.TIMER, fnAlignTimeout, STATE.Idle);
  326. Transition(STATE.Aligning, MSG.Abort, fnAbortAlign, STATE.Idle);
  327. //Swap
  328. Transition(STATE.Idle, MSG.Swap, fnStartSwap, STATE.Swapping);
  329. Transition(STATE.Swapping, FSM_MSG.TIMER, fnSwapTimeout, STATE.Idle);
  330. Transition(STATE.Swapping, MSG.Abort, fnAbortSwap, STATE.Idle);
  331. //PM Swap
  332. Transition(STATE.Idle, MSG.PMSwap, fnStartPMSwap, STATE.PMSwaping);
  333. Transition(STATE.PMSwaping, FSM_MSG.TIMER, fnPMSwapTimeout, STATE.Idle);
  334. Transition(STATE.PMSwaping, MSG.Abort, fnAbortPMSwap, STATE.Idle);
  335. //Extend
  336. Transition(STATE.Idle, MSG.Extend, FnStartExtend, STATE.Extending);
  337. Transition(STATE.Extending, FSM_MSG.TIMER, FnExtend, STATE.Idle);
  338. Transition(STATE.Extending, MSG.Abort, FnAbortExtend, STATE.Idle);
  339. //Retract
  340. Transition(STATE.Idle, MSG.Retract, FnStartRetract, STATE.Retracting);
  341. Transition(STATE.Retracting, FSM_MSG.TIMER, FnRetract, STATE.Idle);
  342. Transition(STATE.Retracting, MSG.Abort, FnAbortRetract, STATE.Idle);
  343. //leakcheck
  344. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.Leakchecking);
  345. Transition(STATE.Leakchecking, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  346. Transition(STATE.Leakchecking, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  347. //Control Pressure
  348. AnyStateTransition(FSM_MSG.TIMER, ControlPressureTimer_Elapsed, FSM_STATE.SAME);
  349. Running = true;
  350. }
  351. private bool RobotGoto(object[] param)
  352. {
  353. return _robot.Goto((ModuleName)param[0], (int)param[1], (Hand)param[2]);
  354. }
  355. private bool FnStartExtend(object[] param)
  356. {
  357. return _pmExtendRoutine.Start(param) == RState.Running;
  358. }
  359. private bool FnExtend(object[] param)
  360. {
  361. RState ret = _pmExtendRoutine.Monitor();
  362. if (ret == RState.Failed || ret == RState.Timeout)
  363. {
  364. PostMsg(MSG.Error);
  365. return false;
  366. }
  367. return ret == RState.End;
  368. }
  369. private bool FnAbortExtend(object[] param)
  370. {
  371. _pmExtendRoutine.Abort();
  372. return true;
  373. }
  374. private bool FnStartRetract(object[] param)
  375. {
  376. return _pmRetractRoutine.Start(param) == RState.Running;
  377. }
  378. private bool FnRetract(object[] param)
  379. {
  380. RState ret = _pmRetractRoutine.Monitor();
  381. if (ret == RState.Failed || ret == RState.Timeout)
  382. {
  383. PostMsg(MSG.Error);
  384. return false;
  385. }
  386. return ret == RState.End;
  387. }
  388. private bool FnAbortRetract(object[] param)
  389. {
  390. _pmRetractRoutine.Abort();
  391. return true;
  392. }
  393. private bool FnStartLeakCheck(object[] param)
  394. {
  395. return _leakcheckRoutine.Start(param) == RState.Running;
  396. }
  397. private bool FnLeakCheckTimeout(object[] param)
  398. {
  399. RState ret = _leakcheckRoutine.Monitor();
  400. if (ret == RState.Failed || ret == RState.Timeout)
  401. {
  402. PostMsg(MSG.Error);
  403. return false;
  404. }
  405. return ret == RState.End;
  406. }
  407. private bool FnAbortLeakCheck(object[] param)
  408. {
  409. _leakcheckRoutine.Abort();
  410. return true;
  411. }
  412. private bool fnAbortPMSwap(object[] param)
  413. {
  414. _pmswaproutine.Abort();
  415. return true;
  416. }
  417. private bool fnPMSwapTimeout(object[] param)
  418. {
  419. RState ret = _pmswaproutine.Monitor();
  420. if (ret == RState.Failed || ret == RState.Timeout)
  421. {
  422. PostMsg(MSG.Error);
  423. return false;
  424. }
  425. return ret == RState.End;
  426. }
  427. private bool fnStartPMSwap(object[] param)
  428. {
  429. return _pmswaproutine.Start(param) == RState.Running;
  430. }
  431. private bool fnAbortSwap(object[] param)
  432. {
  433. _swaproutine.Abort();
  434. return true;
  435. }
  436. private bool fnSwapTimeout(object[] param)
  437. {
  438. RState ret = _swaproutine.Monitor();
  439. if (ret == RState.Failed || ret == RState.Timeout)
  440. {
  441. PostMsg(MSG.Error);
  442. return false;
  443. }
  444. return ret == RState.End;
  445. }
  446. private bool fnStartSwap(object[] param)
  447. {
  448. return _swaproutine.Start(param) == RState.Running;
  449. }
  450. private bool fnStartAlign(object[] param)
  451. {
  452. if (float.TryParse(param[0].ToString(), out float angle))
  453. {
  454. return _vpa.Align();
  455. }
  456. else
  457. {
  458. LOG.Write(eEvent.ERR_TM,ModuleName.Aligner1,$"wrong angle, value is {param[0]}.");
  459. return false;
  460. }
  461. }
  462. private bool fnAlignTimeout(object[] param)
  463. {
  464. if (_vpa.Status == RState.End)
  465. {
  466. return true;
  467. }
  468. else if (_vpa.Status != RState.Running)
  469. {
  470. LOG.Write(eEvent.ERR_TM, ModuleName.Aligner1, $"PreAligner align failed: {_vpa.Status}");
  471. return true;
  472. }
  473. return false;
  474. }
  475. private bool fnAbortAlign(object[] param)
  476. {
  477. return true;
  478. }
  479. private bool fnAbortPMPlace(object[] param)
  480. {
  481. _placepmRoutine.Abort();
  482. return true;
  483. }
  484. private bool fnPMPlaceTimeout(object[] param)
  485. {
  486. RState ret = _placepmRoutine.Monitor();
  487. if (ret == RState.Failed || ret == RState.Timeout)
  488. {
  489. PostMsg(MSG.Error);
  490. return false;
  491. }
  492. return ret == RState.End;
  493. }
  494. private bool fnStartPMPlace(object[] param)
  495. {
  496. return _placepmRoutine.Start(param) == RState.Running;
  497. }
  498. private bool fnAbortPMPick(object[] param)
  499. {
  500. _pickpmRoutine.Abort();
  501. return true;
  502. }
  503. private bool fnPMPickTimeout(object[] param)
  504. {
  505. RState ret = _pickpmRoutine.Monitor();
  506. if (ret == RState.Failed || ret == RState.Timeout)
  507. {
  508. PostMsg(MSG.Error);
  509. return false;
  510. }
  511. return ret == RState.End;
  512. }
  513. private bool fnStartPMPick(object[] param)
  514. {
  515. return _pickpmRoutine.Start(param) == RState.Running;
  516. }
  517. private bool fnAbortVent(object[] param)
  518. {
  519. _ventRoutine.Abort();
  520. return true;
  521. }
  522. private bool fnVentTimeout(object[] param)
  523. {
  524. RState ret = _ventRoutine.Monitor();
  525. if (ret == RState.Failed || ret == RState.Timeout)
  526. {
  527. _ventRoutine.Abort();
  528. PostMsg(MSG.Error);
  529. return false;
  530. }
  531. return ret == RState.End;
  532. }
  533. private bool fnStartVent(object[] param)
  534. {
  535. return _ventRoutine.Start(param) == RState.Running;
  536. }
  537. private bool fnAbortPump(object[] param)
  538. {
  539. _pumpRoutine.Abort();
  540. return true;
  541. }
  542. private bool fnPumpTimeout(object[] param)
  543. {
  544. RState ret = _pumpRoutine.Monitor();
  545. if (ret == RState.Failed || ret == RState.Timeout)
  546. {
  547. _pumpRoutine.Abort();
  548. PostMsg(MSG.Error);
  549. return false;
  550. }
  551. return ret == RState.End;
  552. }
  553. private bool fnStartPump(object[] param)
  554. {
  555. return _pumpRoutine.Start(param) == RState.Running;
  556. }
  557. private bool fnAbortPlace(object[] param)
  558. {
  559. return true;
  560. }
  561. private bool fnPlaceTimeout(object[] param)
  562. {
  563. RState ret = _placeRoutine.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 fnStartPlace(object[] param)
  572. {
  573. return _placeRoutine.Start(param) == RState.Running;
  574. }
  575. private bool fnAbortPick(object[] param)
  576. {
  577. _pickRoutine.Abort();
  578. return true;
  579. }
  580. private bool fnStartPick(object[] param)
  581. {
  582. return _pickRoutine.Start(param) == RState.Running;
  583. }
  584. private bool fnPickTimeout(object[] param)
  585. {
  586. RState ret = _pickRoutine.Monitor();
  587. if (ret == RState.Failed || ret == RState.Timeout)
  588. {
  589. PostMsg(MSG.Error);
  590. return false;
  591. }
  592. return ret == RState.End;
  593. }
  594. private bool fnAbortHome(object[] param)
  595. {
  596. _homeRoutine.Abort();
  597. return true;
  598. }
  599. private bool fnHome(object[] param)
  600. {
  601. if (fsm.State == (int)STATE.Init && param.Length > 0)//带参home
  602. {
  603. return false;
  604. }
  605. else
  606. return _homeRoutine.Start(param) == RState.Running;
  607. }
  608. private bool fnHomeTimeout(object[] param)
  609. {
  610. RState ret = _homeRoutine.Monitor();
  611. if (ret == RState.Failed || ret == RState.Timeout)
  612. {
  613. PostMsg(MSG.Error);
  614. return false;
  615. }
  616. return ret == RState.End;
  617. }
  618. private bool fnOffline(object[] param)
  619. {
  620. //IsOnline = false;
  621. //return true;
  622. throw new NotImplementedException();
  623. }
  624. private bool fnOnline(object[] param)
  625. {
  626. //IsOnline = true;
  627. //return true;
  628. throw new NotImplementedException();
  629. }
  630. private bool fnError(object[] param)
  631. {
  632. return true;
  633. }
  634. /// <summary>
  635. /// 控压处理逻辑
  636. /// 需要按照module去控压
  637. /// 在SE中 因为共用drypump 其前端压力以及使用锁存在抢占可能 需要在pumpstate处于idle下
  638. /// 在DE中 因为分开用drypump 可以在online后始终保持控压的模式
  639. /// </summary>
  640. /// <param name="param"></param>
  641. /// <returns></returns>
  642. private bool ControlPressureTimer_Elapsed(object[] param)
  643. {
  644. // robot idle check
  645. _robotIdleTrigger.CLK = _robot.Status != RState.Running;
  646. if (_robotIdleTrigger.Q)
  647. {
  648. _robotWatch.Restart();
  649. }
  650. if (RouteManager.IsATMMode)
  651. return true;
  652. if (IsOnline)
  653. {
  654. switch (RtInstance.ConfigType)
  655. {
  656. case ConfigType.VenusSE:
  657. //nobody use pump
  658. if (_tm.PumpingState == PumpState.Idle && !_tm.IsPressureControl)
  659. _tm.PressureControl(true);
  660. break;
  661. case ConfigType.VenusDE:
  662. if(!_tm.IsPressureControl)
  663. _tm.PressureControl(true);
  664. break;
  665. default:
  666. return true;
  667. }
  668. }
  669. else
  670. {
  671. switch (Module)
  672. {
  673. case ModuleName.TM:
  674. if(_tm.IsPressureControl)
  675. _tm.PressureControl(false);
  676. break;
  677. default:
  678. return true;
  679. }
  680. }
  681. //废弃代码
  682. //if (IsOnline && _tm.PumpingState == PumpState.Idle)
  683. //{
  684. //
  685. //}
  686. //else
  687. //{
  688. // if (!SC.GetValue<bool>($"{_module}.PressureControl.ControlWriteMode"))
  689. // {
  690. // SC.SetItemValue($"{_module}.PressureControl.ControlWriteMode", true);
  691. // }
  692. //}
  693. return true;
  694. }
  695. public bool Check(int msg, out string reason, params object[] args)
  696. {
  697. reason = "";
  698. return true;
  699. }
  700. public bool CheckAcked(int msg)
  701. {
  702. return fsm.CheckExecuted(msg);
  703. }
  704. public bool CheckToPostMessage(int msg, params object[] args)
  705. {
  706. if (!fsm.FindTransition(fsm.State, msg))
  707. {
  708. LOG.Write(eEvent.WARN_FSM_WARN, _module, $"TM is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  709. return false;
  710. }
  711. Running = true;
  712. fsm.PostMsg(msg, args);
  713. return true;
  714. }
  715. public int Invoke(string function, params object[] args)
  716. {
  717. switch (function)
  718. {
  719. case "Home":
  720. CheckToPostMessage((int)MSG.Home);
  721. return (int)MSG.Home;
  722. }
  723. return (int)FSM_MSG.NONE;
  724. }
  725. }
  726. }