SETMEntity.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  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. SetSpeeding,
  54. QuerySpeeding,
  55. SaveSpeeding
  56. }
  57. public enum MSG
  58. {
  59. Home,
  60. RobotHome,
  61. Online,
  62. Offline,
  63. Pump,
  64. Vent,
  65. Purge,
  66. CyclePurge,
  67. LeakCheck,
  68. Pick,
  69. Place,
  70. Swap,
  71. DoublePick,
  72. DoublePlace,
  73. DoubleSwap,
  74. PMPick,
  75. PMPlace,
  76. PMSwap,
  77. Extend,
  78. Retract,
  79. TMCycle,
  80. ControlPressure,
  81. Error,
  82. Abort,
  83. AbortControlPressure,
  84. Align,
  85. CreateJob,
  86. StartJob,
  87. Goto,
  88. SetSpeed,
  89. QuerySpeed,
  90. SaveSpeed
  91. }
  92. #region 公开变量
  93. public ModuleName Module => _module;
  94. public bool IsIdle
  95. {
  96. get { return fsm.State == (int)STATE.Idle; }
  97. }
  98. public bool IsError
  99. {
  100. get { return fsm.State == (int)STATE.Error; }
  101. }
  102. public bool IsInit
  103. {
  104. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  105. }
  106. public bool IsBusy
  107. {
  108. get { return !IsInit && !IsError && !IsIdle; }
  109. }
  110. public RState RobotStatus
  111. {
  112. get
  113. {
  114. if (_robot.Status != RState.Running)
  115. {
  116. if (_robotWatch.ElapsedMilliseconds < 100)
  117. return RState.Running;
  118. else
  119. return _robot.Status;
  120. }
  121. else
  122. return RState.Running;
  123. }
  124. }
  125. /// <summary>
  126. /// VCE部分的内容从变量转化为查询方法
  127. /// </summary>
  128. public bool VCEIsATM(ModuleName VCEName)
  129. {
  130. switch (RtInstance.ConfigType)
  131. {
  132. case ConfigType.VenusSE:
  133. return _tm.IsVCEATM;
  134. case ConfigType.VenusDE:
  135. return VCEName == ModuleName.VCEA ? _tm.IsVCEAATM : _tm.IsVCEBATM;
  136. default:
  137. return false;
  138. }
  139. }
  140. public bool TMIsATM => _tm.IsTMATM;
  141. public bool TMIsVAC => _tm.IsTMVAC;
  142. public bool VCEIsVAC(ModuleName VCEName)
  143. {
  144. switch (RtInstance.ConfigType)
  145. {
  146. case ConfigType.VenusSE:
  147. return _tm.IsVCEVAC;
  148. case ConfigType.VenusDE:
  149. return VCEName == ModuleName.VCEA ? _tm.IsVCEAVAC : _tm.IsVCEBVAC;
  150. default:
  151. return false;
  152. }
  153. }
  154. public bool IsPMASlitDoorClosed => _tm.PMASlitDoorClosed;
  155. public bool IsPMBSlitDoorClosed => _tm.PMBSlitDoorClosed;
  156. public bool IsPMCSlitDoorClosed => _tm.PMCSlitDoorClosed;
  157. public bool IsPMDSlitDoorClosed => _tm.PMDSlitDoorClosed;
  158. public bool IsVCESlitDoorClosed(ModuleName VCEName)
  159. {
  160. return _tm.VCESlitDoorClosed(VCEName);
  161. }
  162. public bool IsPMASlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMA);
  163. public bool IsPMBSlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMB);
  164. public bool IsPMCSlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMC);
  165. public bool IsPMDSlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.PMD);
  166. //public bool IsVCESlitDoorOpen => _tm.CheckSlitValveOpen(ModuleName.VCE1);
  167. public double VCEPressure(ModuleName VCEName)
  168. {
  169. switch (RtInstance.ConfigType)
  170. {
  171. case ConfigType.VenusSE:
  172. return _tm.VCEPressure;
  173. case ConfigType.VenusDE:
  174. return VCEName == ModuleName.VCEA ? _tm.VCEAPressure : _tm.VCEBPressure;
  175. default:
  176. return 0;
  177. }
  178. }
  179. public bool VCECanMove(ModuleName VCEName)
  180. {
  181. switch (RtInstance.ConfigType)
  182. {
  183. case ConfigType.VenusSE:
  184. if (_tm.VCESlitDoorClosed(VCEName))
  185. return true;
  186. else
  187. return _tm.RobotNotExtendVCE;
  188. case ConfigType.VenusDE:
  189. if (_tm.VCESlitDoorClosed(VCEName))
  190. return true;
  191. else
  192. return VCEName == ModuleName.VCEA ? _tm.RobotNotExtendVCEA : _tm.RobotNotExtendVCEB;
  193. default:
  194. return false;
  195. }
  196. }
  197. public bool CassetteArrive(ModuleName VCEName)
  198. {
  199. switch (RtInstance.ConfigType)
  200. {
  201. case ConfigType.VenusSE:
  202. return true;
  203. case ConfigType.VenusDE:
  204. return VCEName == ModuleName.VCEA ? _tm.VCEACassPresent : _tm.VCEBCassPresent;
  205. default:
  206. return false;
  207. }
  208. }
  209. public bool VCECanMap(ModuleName VCEName)
  210. {
  211. switch (RtInstance.ConfigType)
  212. {
  213. case ConfigType.VenusSE:
  214. if (!VCECanMove(VCEName))
  215. return false;
  216. else
  217. return true;
  218. case ConfigType.VenusDE:
  219. if (!VCECanMove(VCEName))
  220. return false;
  221. else
  222. return VCEName == ModuleName.VCEA ? _tm.VCEACassPresent : _tm.VCEBCassPresent;
  223. default:
  224. return false;
  225. }
  226. }
  227. private bool _IsOnline;
  228. public bool IsOnline => _IsOnline;
  229. //public bool IsTMVac => _tm.IsTMVac;
  230. //public bool IsTMATM => _tm.IsTMATM;
  231. #endregion
  232. #region 私有变量
  233. private readonly TMBase _tm;
  234. private readonly ITransferRobot _robot;
  235. private readonly IPreAlign _vpa;
  236. private readonly SEMFHomeRoutine _homeRoutine;
  237. private readonly SEMFPickRoutine _pickRoutine;
  238. private readonly SEMFPlaceRoutine _placeRoutine;
  239. private readonly SEMFVentRoutine _ventRoutine;
  240. private readonly SEMFPumpRoutine _pumpRoutine;
  241. private readonly SEMFLeakCheckRoutine _leakcheckRoutine;
  242. private readonly SEMFPMPickRoutine _pickpmRoutine;
  243. private readonly SEMFPMPlaceRoutine _placepmRoutine;
  244. private readonly SEMFSwapRoutine _swaproutine;
  245. private readonly SEMFPMSwapRoutine _pmswaproutine;
  246. private readonly SEMFPMRetractRoutine _pmRetractRoutine;
  247. private readonly SEMFPMExtendRoutine _pmExtendRoutine;
  248. //private readonly
  249. //private bool startControlPressureFlag = true;
  250. //private bool stopControlPressureFlag = false;
  251. private Stopwatch _robotWatch = new Stopwatch();
  252. private R_TRIG _robotIdleTrigger = new R_TRIG();
  253. //private int _controlPressureCheckPoint = 100;
  254. //private int _controlPressureSetPoint = 90;
  255. //private int _controlFlowSetPoint = 90;
  256. private ModuleName _module;
  257. #endregion
  258. public SETMEntity(ModuleName module)
  259. {
  260. _module = module;
  261. switch (RtInstance.ConfigType)
  262. {
  263. case ConfigType.VenusSE:
  264. _tm = DEVICE.GetDevice<HongHuTM>(module.ToString());
  265. break;
  266. case ConfigType.VenusDE:
  267. _tm = DEVICE.GetDevice<HongHuDETM>(module.ToString());
  268. break;
  269. }
  270. if (ModuleHelper.IsInstalled(ModuleName.TMRobot))
  271. _robot = new HongHuVR(_module);
  272. _vpa = new HongHuVPA(_module);
  273. _robotWatch = new Stopwatch();
  274. _homeRoutine = new SEMFHomeRoutine(_tm, _robot, _vpa, module);
  275. _pickRoutine = new SEMFPickRoutine(_tm, _robot, _vpa, module);
  276. _placeRoutine = new SEMFPlaceRoutine(_tm, _robot, _vpa, module);
  277. _pumpRoutine = new SEMFPumpRoutine(_tm, module);
  278. _ventRoutine = new SEMFVentRoutine(_tm, module);
  279. _leakcheckRoutine = new SEMFLeakCheckRoutine(_tm, module);
  280. _pickpmRoutine = new SEMFPMPickRoutine(_tm, _robot, module);
  281. _placepmRoutine = new SEMFPMPlaceRoutine(_tm, _robot, module);
  282. _swaproutine = new SEMFSwapRoutine(_tm, _robot, module);
  283. _pmswaproutine = new SEMFPMSwapRoutine(_tm, _robot, module);
  284. _pmExtendRoutine = new SEMFPMExtendRoutine(_tm, _robot, _vpa, module);
  285. _pmRetractRoutine = new SEMFPMRetractRoutine(_tm, _robot, _vpa, module);
  286. InitFsmMap();
  287. }
  288. protected override bool Init()
  289. {
  290. DATA.Subscribe($"{_module}.FsmState", () => ((STATE)fsm.State).ToString());
  291. DATA.Subscribe($"{_module}.RobotMoveAction", () => _robot.TMRobotMoveInfo, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  292. DATA.Subscribe($"{_module}.RobotMoveAction.ArmTarget", () => _robot.TMRobotMoveInfo.ArmTarget.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  293. DATA.Subscribe($"{_module}.RobotMoveAction.BladeTarget", () => _robot.TMRobotMoveInfo.BladeTarget, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  294. DATA.Subscribe($"{_module}.RobotMoveAction.RobotAction", () => _robot.TMRobotMoveInfo.Action.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  295. DATA.Subscribe($"{_module}.IsOnline", () => IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  296. DATA.Subscribe($"{_module}.IsOffline", () => !IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  297. DATA.Subscribe($"{_module}.WithWaferSpeed", () => _robot.WithWaferSpeed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  298. DATA.Subscribe($"{_module}.NoWaferSpeed", () => _robot.NoWaferSpeed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  299. DATA.Subscribe($"{_module}.IsAlarm", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  300. OP.Subscribe($"{_module}.Goto", (cmd, args) => RobotGoto(args));
  301. OP.Subscribe($"{_module}.Home", (cmd, args) => { PostMsg(MSG.Home, args); return true; });
  302. OP.Subscribe($"{_module}.Abort", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  303. OP.Subscribe($"{_module}.Pick", (cmd, args) => { PostMsg(MSG.Pick, args); return true; });
  304. OP.Subscribe($"{_module}.Place", (cmd, args) => { PostMsg(MSG.Place, args); return true; });
  305. OP.Subscribe($"{_module}.Extend", (cmd, args) => { PostMsg(MSG.Extend, args); return true; });
  306. OP.Subscribe($"{_module}.Retract", (cmd, args) => { PostMsg(MSG.Retract, args); return true; });
  307. OP.Subscribe($"{_module}.PMPick", (cmd, args) => { PostMsg(MSG.PMPick, args); return true; });
  308. OP.Subscribe($"{_module}.PMPlace", (cmd, args) => { PostMsg(MSG.PMPlace, args); return true; });
  309. OP.Subscribe($"{_module}.PumpDown", (cmd, args) => { PostMsg(MSG.Pump); return true; });
  310. OP.Subscribe($"{_module}.Vent", (cmd, args) => { PostMsg(MSG.Vent); return true; });
  311. OP.Subscribe($"{_module}.LeakCheck", (cmd, args) => { PostMsg(MSG.LeakCheck); return true; });
  312. OP.Subscribe($"{_module}.Online", (cmd, args) =>
  313. {
  314. if (IsIdle)
  315. _IsOnline = true;
  316. else
  317. LOG.Write(eEvent.WARN_TM, _module, "cannot Set Online as TM is not idle");
  318. return true;
  319. });
  320. OP.Subscribe($"{_module}.Offline", (cmd, args) =>
  321. {
  322. _IsOnline = false;
  323. return true;
  324. });
  325. OP.Subscribe($"{_module}.SetSpeed", (cmd, args) => { PostMsg(MSG.SetSpeed, args); return true; });
  326. OP.Subscribe($"{_module}.QuerySpeed", (cmd, args) => { PostMsg(MSG.QuerySpeed, args); return true; });
  327. OP.Subscribe($"{_module}.SaveSpeed", (cmd, args) => { PostMsg(MSG.SaveSpeed, args); return true; });
  328. return true;
  329. }
  330. private void InitFsmMap()
  331. {
  332. fsm = new StateMachine<SETMEntity>($"{_module}", (int)STATE.Init, 50);
  333. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  334. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  335. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  336. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  337. //Home
  338. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomeTimeout, STATE.Idle);
  339. Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Init);
  340. //Pick
  341. Transition(STATE.Idle, MSG.Pick, fnStartPick, STATE.Picking);
  342. Transition(STATE.Picking, FSM_MSG.TIMER, fnPickTimeout, STATE.Idle);
  343. Transition(STATE.Picking, MSG.Abort, fnAbortPick, STATE.Idle);
  344. //Place
  345. Transition(STATE.Idle, MSG.Place, fnStartPlace, STATE.Placing);
  346. Transition(STATE.Placing, FSM_MSG.TIMER, fnPlaceTimeout, STATE.Idle);
  347. Transition(STATE.Placing, MSG.Abort, fnAbortPlace, STATE.Idle);
  348. //Pump
  349. Transition(STATE.Idle, MSG.Pump, fnStartPump, STATE.Pumping);
  350. Transition(STATE.Pumping, FSM_MSG.TIMER, fnPumpTimeout, STATE.Idle);
  351. Transition(STATE.Pumping, MSG.Abort, fnAbortPump, STATE.Idle);
  352. //Vent
  353. Transition(STATE.Idle, MSG.Vent, fnStartVent, STATE.Venting);
  354. Transition(STATE.Venting, FSM_MSG.TIMER, fnVentTimeout, STATE.Idle);
  355. Transition(STATE.Venting, MSG.Abort, fnAbortVent, STATE.Idle);
  356. //PMPick
  357. Transition(STATE.Idle, MSG.PMPick, fnStartPMPick, STATE.PMPicking);
  358. Transition(STATE.PMPicking, FSM_MSG.TIMER, fnPMPickTimeout, STATE.Idle);
  359. Transition(STATE.PMPicking, MSG.Abort, fnAbortPMPick, STATE.Idle);
  360. //PMPlace
  361. Transition(STATE.Idle, MSG.PMPlace, fnStartPMPlace, STATE.PMPlacing);
  362. Transition(STATE.PMPlacing, FSM_MSG.TIMER, fnPMPlaceTimeout, STATE.Idle);
  363. Transition(STATE.PMPlacing, MSG.Abort, fnAbortPMPlace, STATE.Idle);
  364. //PA align
  365. Transition(STATE.Idle, MSG.Align, fnStartAlign, STATE.Aligning);
  366. Transition(STATE.Aligning, FSM_MSG.TIMER, fnAlignTimeout, STATE.Idle);
  367. Transition(STATE.Aligning, MSG.Abort, fnAbortAlign, STATE.Idle);
  368. //Swap
  369. Transition(STATE.Idle, MSG.Swap, fnStartSwap, STATE.Swapping);
  370. Transition(STATE.Swapping, FSM_MSG.TIMER, fnSwapTimeout, STATE.Idle);
  371. Transition(STATE.Swapping, MSG.Abort, fnAbortSwap, STATE.Idle);
  372. //PM Swap
  373. Transition(STATE.Idle, MSG.PMSwap, fnStartPMSwap, STATE.PMSwaping);
  374. Transition(STATE.PMSwaping, FSM_MSG.TIMER, fnPMSwapTimeout, STATE.Idle);
  375. Transition(STATE.PMSwaping, MSG.Abort, fnAbortPMSwap, STATE.Idle);
  376. //Extend
  377. Transition(STATE.Idle, MSG.Extend, FnStartExtend, STATE.Extending);
  378. Transition(STATE.Extending, FSM_MSG.TIMER, FnExtend, STATE.Idle);
  379. Transition(STATE.Extending, MSG.Abort, FnAbortExtend, STATE.Idle);
  380. //Retract
  381. Transition(STATE.Idle, MSG.Retract, FnStartRetract, STATE.Retracting);
  382. Transition(STATE.Retracting, FSM_MSG.TIMER, FnRetract, STATE.Idle);
  383. Transition(STATE.Retracting, MSG.Abort, FnAbortRetract, STATE.Idle);
  384. //leakcheck
  385. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.Leakchecking);
  386. Transition(STATE.Leakchecking, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  387. Transition(STATE.Leakchecking, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  388. //setspeed
  389. Transition(STATE.Idle, MSG.SetSpeed, fnSetSpeed, STATE.SetSpeeding);
  390. Transition(STATE.SetSpeeding, FSM_MSG.TIMER, fnSetSpeedTimeout, STATE.Idle);
  391. Transition(STATE.SetSpeeding, MSG.Abort, fnAbortSetSpeed, STATE.Idle);
  392. //RQspeed
  393. Transition(STATE.Idle, MSG.QuerySpeed, fnRQSpeed, STATE.QuerySpeeding);
  394. Transition(STATE.QuerySpeeding, FSM_MSG.TIMER, fnRQSpeedTimeout, STATE.Idle);
  395. Transition(STATE.QuerySpeeding, MSG.Abort, fnAbortRQSpeed, STATE.Idle);
  396. //save speed
  397. Transition(STATE.Idle, MSG.SaveSpeed, fnSaveSpeed, STATE.SaveSpeeding);
  398. Transition(STATE.SaveSpeeding, FSM_MSG.TIMER, fnSaveSpeedTimeout, STATE.Idle);
  399. Transition(STATE.SaveSpeeding, MSG.Abort, fnAbortSaveSpeed, STATE.Idle);
  400. //Control Pressure
  401. AnyStateTransition(FSM_MSG.TIMER, ControlPressureTimer_Elapsed, FSM_STATE.SAME);
  402. Running = true;
  403. }
  404. private bool RobotGoto(object[] param)
  405. {
  406. return _robot.Goto((ModuleName)param[0], (int)param[1], (Hand)param[2]);
  407. }
  408. private bool FnStartExtend(object[] param)
  409. {
  410. return _pmExtendRoutine.Start(param) == RState.Running;
  411. }
  412. private bool FnExtend(object[] param)
  413. {
  414. RState ret = _pmExtendRoutine.Monitor();
  415. if (ret == RState.Failed || ret == RState.Timeout)
  416. {
  417. PostMsg(MSG.Error);
  418. return false;
  419. }
  420. return ret == RState.End;
  421. }
  422. private bool FnAbortExtend(object[] param)
  423. {
  424. _pmExtendRoutine.Abort();
  425. return true;
  426. }
  427. private bool FnStartRetract(object[] param)
  428. {
  429. return _pmRetractRoutine.Start(param) == RState.Running;
  430. }
  431. private bool FnRetract(object[] param)
  432. {
  433. RState ret = _pmRetractRoutine.Monitor();
  434. if (ret == RState.Failed || ret == RState.Timeout)
  435. {
  436. PostMsg(MSG.Error);
  437. return false;
  438. }
  439. return ret == RState.End;
  440. }
  441. private bool FnAbortRetract(object[] param)
  442. {
  443. _pmRetractRoutine.Abort();
  444. return true;
  445. }
  446. private bool FnStartLeakCheck(object[] param)
  447. {
  448. return _leakcheckRoutine.Start(param) == RState.Running;
  449. }
  450. private bool FnLeakCheckTimeout(object[] param)
  451. {
  452. RState ret = _leakcheckRoutine.Monitor();
  453. if (ret == RState.Failed || ret == RState.Timeout)
  454. {
  455. PostMsg(MSG.Error);
  456. return false;
  457. }
  458. return ret == RState.End;
  459. }
  460. private bool FnAbortLeakCheck(object[] param)
  461. {
  462. _leakcheckRoutine.Abort();
  463. return true;
  464. }
  465. private bool fnAbortPMSwap(object[] param)
  466. {
  467. _pmswaproutine.Abort();
  468. return true;
  469. }
  470. private bool fnPMSwapTimeout(object[] param)
  471. {
  472. RState ret = _pmswaproutine.Monitor();
  473. if (ret == RState.Failed || ret == RState.Timeout)
  474. {
  475. PostMsg(MSG.Error);
  476. return false;
  477. }
  478. return ret == RState.End;
  479. }
  480. private bool fnStartPMSwap(object[] param)
  481. {
  482. return _pmswaproutine.Start(param) == RState.Running;
  483. }
  484. private bool fnAbortSwap(object[] param)
  485. {
  486. _swaproutine.Abort();
  487. return true;
  488. }
  489. private bool fnSwapTimeout(object[] param)
  490. {
  491. RState ret = _swaproutine.Monitor();
  492. if (ret == RState.Failed || ret == RState.Timeout)
  493. {
  494. PostMsg(MSG.Error);
  495. return false;
  496. }
  497. return ret == RState.End;
  498. }
  499. private bool fnStartSwap(object[] param)
  500. {
  501. return _swaproutine.Start(param) == RState.Running;
  502. }
  503. private bool fnStartAlign(object[] param)
  504. {
  505. if (float.TryParse(param[0].ToString(), out float angle))
  506. {
  507. return _vpa.Align();
  508. }
  509. else
  510. {
  511. LOG.Write(eEvent.ERR_TM, ModuleName.Aligner1, $"wrong angle, value is {param[0]}.");
  512. return false;
  513. }
  514. }
  515. private bool fnAlignTimeout(object[] param)
  516. {
  517. if (_vpa.Status == RState.End)
  518. {
  519. return true;
  520. }
  521. else if (_vpa.Status != RState.Running)
  522. {
  523. LOG.Write(eEvent.ERR_TM, ModuleName.Aligner1, $"PreAligner align failed: {_vpa.Status}");
  524. return true;
  525. }
  526. return false;
  527. }
  528. private bool fnAbortAlign(object[] param)
  529. {
  530. return true;
  531. }
  532. private bool fnAbortPMPlace(object[] param)
  533. {
  534. _placepmRoutine.Abort();
  535. return true;
  536. }
  537. private bool fnPMPlaceTimeout(object[] param)
  538. {
  539. RState ret = _placepmRoutine.Monitor();
  540. if (ret == RState.Failed || ret == RState.Timeout)
  541. {
  542. PostMsg(MSG.Error);
  543. return false;
  544. }
  545. return ret == RState.End;
  546. }
  547. private bool fnStartPMPlace(object[] param)
  548. {
  549. return _placepmRoutine.Start(param) == RState.Running;
  550. }
  551. private bool fnAbortPMPick(object[] param)
  552. {
  553. _pickpmRoutine.Abort();
  554. return true;
  555. }
  556. private bool fnPMPickTimeout(object[] param)
  557. {
  558. RState ret = _pickpmRoutine.Monitor();
  559. if (ret == RState.Failed || ret == RState.Timeout)
  560. {
  561. PostMsg(MSG.Error);
  562. return false;
  563. }
  564. return ret == RState.End;
  565. }
  566. private bool fnStartPMPick(object[] param)
  567. {
  568. return _pickpmRoutine.Start(param) == RState.Running;
  569. }
  570. private bool fnAbortVent(object[] param)
  571. {
  572. _ventRoutine.Abort();
  573. return true;
  574. }
  575. private bool fnVentTimeout(object[] param)
  576. {
  577. RState ret = _ventRoutine.Monitor();
  578. if (ret == RState.Failed || ret == RState.Timeout)
  579. {
  580. _ventRoutine.Abort();
  581. PostMsg(MSG.Error);
  582. return false;
  583. }
  584. return ret == RState.End;
  585. }
  586. private bool fnStartVent(object[] param)
  587. {
  588. return _ventRoutine.Start(param) == RState.Running;
  589. }
  590. private bool fnAbortPump(object[] param)
  591. {
  592. _pumpRoutine.Abort();
  593. return true;
  594. }
  595. private bool fnPumpTimeout(object[] param)
  596. {
  597. RState ret = _pumpRoutine.Monitor();
  598. if (ret == RState.Failed || ret == RState.Timeout)
  599. {
  600. _pumpRoutine.Abort();
  601. PostMsg(MSG.Error);
  602. return false;
  603. }
  604. return ret == RState.End;
  605. }
  606. private bool fnStartPump(object[] param)
  607. {
  608. return _pumpRoutine.Start(param) == RState.Running;
  609. }
  610. private bool fnAbortPlace(object[] param)
  611. {
  612. return true;
  613. }
  614. private bool fnPlaceTimeout(object[] param)
  615. {
  616. RState ret = _placeRoutine.Monitor();
  617. if (ret == RState.Failed || ret == RState.Timeout)
  618. {
  619. PostMsg(MSG.Error);
  620. return false;
  621. }
  622. return ret == RState.End;
  623. }
  624. private bool fnStartPlace(object[] param)
  625. {
  626. return _placeRoutine.Start(param) == RState.Running;
  627. }
  628. private bool fnAbortPick(object[] param)
  629. {
  630. _pickRoutine.Abort();
  631. return true;
  632. }
  633. private bool fnStartPick(object[] param)
  634. {
  635. return _pickRoutine.Start(param) == RState.Running;
  636. }
  637. private bool fnPickTimeout(object[] param)
  638. {
  639. RState ret = _pickRoutine.Monitor();
  640. if (ret == RState.Failed || ret == RState.Timeout)
  641. {
  642. PostMsg(MSG.Error);
  643. return false;
  644. }
  645. return ret == RState.End;
  646. }
  647. private bool fnAbortHome(object[] param)
  648. {
  649. _homeRoutine.Abort();
  650. return true;
  651. }
  652. private bool fnHome(object[] param)
  653. {
  654. if (fsm.State == (int)STATE.Init && param.Length > 0)//带参home
  655. {
  656. return false;
  657. }
  658. else
  659. return _homeRoutine.Start(param) == RState.Running;
  660. }
  661. private bool fnHomeTimeout(object[] param)
  662. {
  663. RState ret = _homeRoutine.Monitor();
  664. if (ret == RState.Failed || ret == RState.Timeout)
  665. {
  666. PostMsg(MSG.Error);
  667. return false;
  668. }
  669. return ret == RState.End;
  670. }
  671. private bool fnSetSpeed(object[] param)
  672. {
  673. return _robot.SetSpeed(param[0].ToString(), float.Parse(param[1].ToString()));
  674. }
  675. private bool fnSaveSpeed(object[] param)
  676. {
  677. return _robot.SaveSpeed(param[0].ToString());
  678. }
  679. private bool fnRQSpeed(object[] param)
  680. {
  681. return _robot.QuerySpeed(param[0].ToString());
  682. }
  683. private bool fnSetSpeedTimeout(object[] param)
  684. {
  685. RState ret = _robot.Status;
  686. if (ret == RState.Failed || ret == RState.Timeout)
  687. {
  688. PostMsg(MSG.Error);
  689. return false;
  690. }
  691. return ret == RState.End;
  692. }
  693. private bool fnSaveSpeedTimeout(object[] param)
  694. {
  695. RState ret = _robot.Status;
  696. if (ret == RState.Failed || ret == RState.Timeout)
  697. {
  698. PostMsg(MSG.Error);
  699. return false;
  700. }
  701. return ret == RState.End;
  702. }
  703. private bool fnAbortSaveSpeed(object[] param)
  704. {
  705. return true;
  706. }
  707. private bool fnRQSpeedTimeout(object[] param)
  708. {
  709. RState ret = _robot.Status;
  710. if (ret == RState.Failed || ret == RState.Timeout)
  711. {
  712. PostMsg(MSG.Error);
  713. return false;
  714. }
  715. return ret == RState.End;
  716. }
  717. private bool fnAbortRQSpeed(object[] param)
  718. {
  719. return true;
  720. }
  721. private bool fnAbortSetSpeed(object[] param)
  722. {
  723. return true;
  724. }
  725. private bool fnOffline(object[] param)
  726. {
  727. //IsOnline = false;
  728. //return true;
  729. throw new NotImplementedException();
  730. }
  731. private bool fnOnline(object[] param)
  732. {
  733. //IsOnline = true;
  734. //return true;
  735. throw new NotImplementedException();
  736. }
  737. private bool fnError(object[] param)
  738. {
  739. return true;
  740. }
  741. /// <summary>
  742. /// 控压处理逻辑
  743. /// 需要按照module去控压
  744. /// 在SE中 因为共用drypump 其前端压力以及使用锁存在抢占可能 需要在pumpstate处于idle下
  745. /// 在DE中 因为分开用drypump 可以在online后始终保持控压的模式
  746. /// </summary>
  747. /// <param name="param"></param>
  748. /// <returns></returns>
  749. private bool ControlPressureTimer_Elapsed(object[] param)
  750. {
  751. // robot idle check
  752. _robotIdleTrigger.CLK = _robot.Status != RState.Running;
  753. if (_robotIdleTrigger.Q)
  754. {
  755. _robotWatch.Restart();
  756. }
  757. if (RouteManager.IsATMMode)
  758. return true;
  759. if (IsOnline)
  760. {
  761. switch (RtInstance.ConfigType)
  762. {
  763. case ConfigType.VenusSE:
  764. //nobody use pump
  765. if (_tm.PumpingState == PumpState.Idle && !_tm.IsPressureControl)
  766. _tm.PressureControl(true);
  767. break;
  768. case ConfigType.VenusDE:
  769. if (!_tm.IsPressureControl)
  770. _tm.PressureControl(true);
  771. break;
  772. default:
  773. return true;
  774. }
  775. }
  776. else
  777. {
  778. switch (Module)
  779. {
  780. case ModuleName.TM:
  781. if (_tm.IsPressureControl)
  782. _tm.PressureControl(false);
  783. break;
  784. default:
  785. return true;
  786. }
  787. }
  788. //废弃代码
  789. //if (IsOnline && _tm.PumpingState == PumpState.Idle)
  790. //{
  791. //
  792. //}
  793. //else
  794. //{
  795. // if (!SC.GetValue<bool>($"{_module}.PressureControl.ControlWriteMode"))
  796. // {
  797. // SC.SetItemValue($"{_module}.PressureControl.ControlWriteMode", true);
  798. // }
  799. //}
  800. return true;
  801. }
  802. public bool Check(int msg, out string reason, params object[] args)
  803. {
  804. reason = "";
  805. return true;
  806. }
  807. public bool CheckAcked(int msg)
  808. {
  809. return fsm.CheckExecuted(msg);
  810. }
  811. public bool CheckToPostMessage(int msg, params object[] args)
  812. {
  813. if (!fsm.FindTransition(fsm.State, msg))
  814. {
  815. LOG.Write(eEvent.WARN_FSM_WARN, _module, $"TM is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  816. return false;
  817. }
  818. Running = true;
  819. fsm.PostMsg(msg, args);
  820. return true;
  821. }
  822. public int Invoke(string function, params object[] args)
  823. {
  824. switch (function)
  825. {
  826. case "Home":
  827. CheckToPostMessage((int)MSG.Home);
  828. return (int)MSG.Home;
  829. }
  830. return (int)FSM_MSG.NONE;
  831. }
  832. }
  833. }