SETMEntity.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  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. private int _TMType = 0;
  258. #endregion
  259. public SETMEntity(ModuleName module)
  260. {
  261. _module = module;
  262. switch (RtInstance.ConfigType)
  263. {
  264. case ConfigType.VenusSE:
  265. _tm = DEVICE.GetDevice<HongHuTM>(module.ToString());
  266. break;
  267. case ConfigType.VenusDE:
  268. _tm = DEVICE.GetDevice<HongHuDETM>(module.ToString());
  269. break;
  270. }
  271. _TMType = SC.GetValue<int>($"TM.TMType");
  272. if (ModuleHelper.IsInstalled(ModuleName.TMRobot))
  273. {
  274. switch (_TMType)
  275. {
  276. case 1:
  277. _robot = new SunWayRobot(_module);
  278. break;
  279. case 0:
  280. default:
  281. _robot = new HongHuVR(_module);
  282. break;
  283. }
  284. }
  285. _vpa = new HongHuVPA(_module);
  286. _robotWatch = new Stopwatch();
  287. _homeRoutine = new SEMFHomeRoutine(_tm, _robot, _vpa, module);
  288. _pickRoutine = new SEMFPickRoutine(_tm, _robot, _vpa, module);
  289. _placeRoutine = new SEMFPlaceRoutine(_tm, _robot, _vpa, module);
  290. _pumpRoutine = new SEMFPumpRoutine(_tm, module);
  291. _ventRoutine = new SEMFVentRoutine(_tm, module);
  292. _leakcheckRoutine = new SEMFLeakCheckRoutine(_tm, module);
  293. _pickpmRoutine = new SEMFPMPickRoutine(_tm, _robot, module);
  294. _placepmRoutine = new SEMFPMPlaceRoutine(_tm, _robot, module);
  295. _swaproutine = new SEMFSwapRoutine(_tm, _robot, module);
  296. _pmswaproutine = new SEMFPMSwapRoutine(_tm, _robot, module);
  297. _pmExtendRoutine = new SEMFPMExtendRoutine(_tm, _robot, _vpa, module);
  298. _pmRetractRoutine = new SEMFPMRetractRoutine(_tm, _robot, _vpa, module);
  299. InitFsmMap();
  300. }
  301. protected override bool Init()
  302. {
  303. DATA.Subscribe($"{_module}.FsmState", () => ((STATE)fsm.State).ToString());
  304. DATA.Subscribe($"{_module}.RobotMoveAction", () => _robot.TMRobotMoveInfo, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  305. DATA.Subscribe($"{_module}.RobotMoveAction.ArmTarget", () => _robot.TMRobotMoveInfo.ArmTarget.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  306. DATA.Subscribe($"{_module}.RobotMoveAction.BladeTarget", () => _robot.TMRobotMoveInfo.BladeTarget, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  307. DATA.Subscribe($"{_module}.RobotMoveAction.RobotAction", () => _robot.TMRobotMoveInfo.Action.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  308. DATA.Subscribe($"{_module}.IsOnline", () => IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  309. DATA.Subscribe($"{_module}.IsOffline", () => !IsOnline, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  310. DATA.Subscribe($"{_module}.WithWaferSpeed", () => _robot.WithWaferSpeed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  311. DATA.Subscribe($"{_module}.NoWaferSpeed", () => _robot.NoWaferSpeed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  312. DATA.Subscribe($"{_module}.IsAlarm", () => IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  313. OP.Subscribe($"{_module}.Goto", (cmd, args) => RobotGoto(args));
  314. OP.Subscribe($"{_module}.Home", (cmd, args) => { PostMsg(MSG.Home, args); return true; });
  315. OP.Subscribe($"{_module}.Abort", (cmd, args) => { PostMsg(MSG.Abort); return true; });
  316. OP.Subscribe($"{_module}.Pick", (cmd, args) => { PostMsg(MSG.Pick, args); return true; });
  317. OP.Subscribe($"{_module}.Place", (cmd, args) => { PostMsg(MSG.Place, args); return true; });
  318. OP.Subscribe($"{_module}.Extend", (cmd, args) => { PostMsg(MSG.Extend, args); return true; });
  319. OP.Subscribe($"{_module}.Retract", (cmd, args) => { PostMsg(MSG.Retract, args); return true; });
  320. OP.Subscribe($"{_module}.PMPick", (cmd, args) => { PostMsg(MSG.PMPick, args); return true; });
  321. OP.Subscribe($"{_module}.PMPlace", (cmd, args) => { PostMsg(MSG.PMPlace, args); return true; });
  322. OP.Subscribe($"{_module}.PumpDown", (cmd, args) => { PostMsg(MSG.Pump); return true; });
  323. OP.Subscribe($"{_module}.Vent", (cmd, args) => { PostMsg(MSG.Vent); return true; });
  324. OP.Subscribe($"{_module}.LeakCheck", (cmd, args) => { PostMsg(MSG.LeakCheck); return true; });
  325. OP.Subscribe($"{_module}.Online", (cmd, args) =>
  326. {
  327. if (IsIdle)
  328. _IsOnline = true;
  329. else
  330. LOG.Write(eEvent.WARN_TM, _module, "cannot Set Online as TM is not idle");
  331. return true;
  332. });
  333. OP.Subscribe($"{_module}.Offline", (cmd, args) =>
  334. {
  335. _IsOnline = false;
  336. return true;
  337. });
  338. OP.Subscribe($"{_module}.SetSpeed", (cmd, args) => { PostMsg(MSG.SetSpeed, args); return true; });
  339. OP.Subscribe($"{_module}.QuerySpeed", (cmd, args) => { PostMsg(MSG.QuerySpeed, args); return true; });
  340. OP.Subscribe($"{_module}.SaveSpeed", (cmd, args) => { PostMsg(MSG.SaveSpeed, args); return true; });
  341. return true;
  342. }
  343. private void InitFsmMap()
  344. {
  345. fsm = new StateMachine<SETMEntity>($"{_module}", (int)STATE.Init, 50);
  346. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  347. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  348. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  349. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  350. //Home
  351. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHomeTimeout, STATE.Idle);
  352. Transition(STATE.Initializing, MSG.Abort, fnAbortHome, STATE.Init);
  353. //Pick
  354. Transition(STATE.Idle, MSG.Pick, fnStartPick, STATE.Picking);
  355. Transition(STATE.Picking, FSM_MSG.TIMER, fnPickTimeout, STATE.Idle);
  356. Transition(STATE.Picking, MSG.Abort, fnAbortPick, STATE.Idle);
  357. //Place
  358. Transition(STATE.Idle, MSG.Place, fnStartPlace, STATE.Placing);
  359. Transition(STATE.Placing, FSM_MSG.TIMER, fnPlaceTimeout, STATE.Idle);
  360. Transition(STATE.Placing, MSG.Abort, fnAbortPlace, STATE.Idle);
  361. //Pump
  362. Transition(STATE.Idle, MSG.Pump, fnStartPump, STATE.Pumping);
  363. Transition(STATE.Pumping, FSM_MSG.TIMER, fnPumpTimeout, STATE.Idle);
  364. Transition(STATE.Pumping, MSG.Abort, fnAbortPump, STATE.Idle);
  365. //Vent
  366. Transition(STATE.Idle, MSG.Vent, fnStartVent, STATE.Venting);
  367. Transition(STATE.Venting, FSM_MSG.TIMER, fnVentTimeout, STATE.Idle);
  368. Transition(STATE.Venting, MSG.Abort, fnAbortVent, STATE.Idle);
  369. //PMPick
  370. Transition(STATE.Idle, MSG.PMPick, fnStartPMPick, STATE.PMPicking);
  371. Transition(STATE.PMPicking, FSM_MSG.TIMER, fnPMPickTimeout, STATE.Idle);
  372. Transition(STATE.PMPicking, MSG.Abort, fnAbortPMPick, STATE.Idle);
  373. //PMPlace
  374. Transition(STATE.Idle, MSG.PMPlace, fnStartPMPlace, STATE.PMPlacing);
  375. Transition(STATE.PMPlacing, FSM_MSG.TIMER, fnPMPlaceTimeout, STATE.Idle);
  376. Transition(STATE.PMPlacing, MSG.Abort, fnAbortPMPlace, STATE.Idle);
  377. //PA align
  378. Transition(STATE.Idle, MSG.Align, fnStartAlign, STATE.Aligning);
  379. Transition(STATE.Aligning, FSM_MSG.TIMER, fnAlignTimeout, STATE.Idle);
  380. Transition(STATE.Aligning, MSG.Abort, fnAbortAlign, STATE.Idle);
  381. //Swap
  382. Transition(STATE.Idle, MSG.Swap, fnStartSwap, STATE.Swapping);
  383. Transition(STATE.Swapping, FSM_MSG.TIMER, fnSwapTimeout, STATE.Idle);
  384. Transition(STATE.Swapping, MSG.Abort, fnAbortSwap, STATE.Idle);
  385. //PM Swap
  386. Transition(STATE.Idle, MSG.PMSwap, fnStartPMSwap, STATE.PMSwaping);
  387. Transition(STATE.PMSwaping, FSM_MSG.TIMER, fnPMSwapTimeout, STATE.Idle);
  388. Transition(STATE.PMSwaping, MSG.Abort, fnAbortPMSwap, STATE.Idle);
  389. //Extend
  390. Transition(STATE.Idle, MSG.Extend, FnStartExtend, STATE.Extending);
  391. Transition(STATE.Extending, FSM_MSG.TIMER, FnExtend, STATE.Idle);
  392. Transition(STATE.Extending, MSG.Abort, FnAbortExtend, STATE.Idle);
  393. //Retract
  394. Transition(STATE.Idle, MSG.Retract, FnStartRetract, STATE.Retracting);
  395. Transition(STATE.Retracting, FSM_MSG.TIMER, FnRetract, STATE.Idle);
  396. Transition(STATE.Retracting, MSG.Abort, FnAbortRetract, STATE.Idle);
  397. //leakcheck
  398. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.Leakchecking);
  399. Transition(STATE.Leakchecking, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  400. Transition(STATE.Leakchecking, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  401. //setspeed
  402. Transition(STATE.Idle, MSG.SetSpeed, fnSetSpeed, STATE.SetSpeeding);
  403. Transition(STATE.SetSpeeding, FSM_MSG.TIMER, fnSetSpeedTimeout, STATE.Idle);
  404. Transition(STATE.SetSpeeding, MSG.Abort, fnAbortSetSpeed, STATE.Idle);
  405. //RQspeed
  406. Transition(STATE.Idle, MSG.QuerySpeed, fnRQSpeed, STATE.QuerySpeeding);
  407. Transition(STATE.QuerySpeeding, FSM_MSG.TIMER, fnRQSpeedTimeout, STATE.Idle);
  408. Transition(STATE.QuerySpeeding, MSG.Abort, fnAbortRQSpeed, STATE.Idle);
  409. //save speed
  410. Transition(STATE.Idle, MSG.SaveSpeed, fnSaveSpeed, STATE.SaveSpeeding);
  411. Transition(STATE.SaveSpeeding, FSM_MSG.TIMER, fnSaveSpeedTimeout, STATE.Idle);
  412. Transition(STATE.SaveSpeeding, MSG.Abort, fnAbortSaveSpeed, STATE.Idle);
  413. //Control Pressure
  414. AnyStateTransition(FSM_MSG.TIMER, ControlPressureTimer_Elapsed, FSM_STATE.SAME);
  415. Running = true;
  416. }
  417. private bool RobotGoto(object[] param)
  418. {
  419. return _robot.Goto((ModuleName)param[0], (int)param[1], (Hand)param[2]);
  420. }
  421. private bool FnStartExtend(object[] param)
  422. {
  423. return _pmExtendRoutine.Start(param) == RState.Running;
  424. }
  425. private bool FnExtend(object[] param)
  426. {
  427. RState ret = _pmExtendRoutine.Monitor();
  428. if (ret == RState.Failed || ret == RState.Timeout)
  429. {
  430. PostMsg(MSG.Error);
  431. return false;
  432. }
  433. return ret == RState.End;
  434. }
  435. private bool FnAbortExtend(object[] param)
  436. {
  437. _pmExtendRoutine.Abort();
  438. return true;
  439. }
  440. private bool FnStartRetract(object[] param)
  441. {
  442. return _pmRetractRoutine.Start(param) == RState.Running;
  443. }
  444. private bool FnRetract(object[] param)
  445. {
  446. RState ret = _pmRetractRoutine.Monitor();
  447. if (ret == RState.Failed || ret == RState.Timeout)
  448. {
  449. PostMsg(MSG.Error);
  450. return false;
  451. }
  452. return ret == RState.End;
  453. }
  454. private bool FnAbortRetract(object[] param)
  455. {
  456. _pmRetractRoutine.Abort();
  457. return true;
  458. }
  459. private bool FnStartLeakCheck(object[] param)
  460. {
  461. return _leakcheckRoutine.Start(param) == RState.Running;
  462. }
  463. private bool FnLeakCheckTimeout(object[] param)
  464. {
  465. RState ret = _leakcheckRoutine.Monitor();
  466. if (ret == RState.Failed || ret == RState.Timeout)
  467. {
  468. PostMsg(MSG.Error);
  469. return false;
  470. }
  471. return ret == RState.End;
  472. }
  473. private bool FnAbortLeakCheck(object[] param)
  474. {
  475. _leakcheckRoutine.Abort();
  476. return true;
  477. }
  478. private bool fnAbortPMSwap(object[] param)
  479. {
  480. _pmswaproutine.Abort();
  481. return true;
  482. }
  483. private bool fnPMSwapTimeout(object[] param)
  484. {
  485. RState ret = _pmswaproutine.Monitor();
  486. if (ret == RState.Failed || ret == RState.Timeout)
  487. {
  488. PostMsg(MSG.Error);
  489. return false;
  490. }
  491. return ret == RState.End;
  492. }
  493. private bool fnStartPMSwap(object[] param)
  494. {
  495. return _pmswaproutine.Start(param) == RState.Running;
  496. }
  497. private bool fnAbortSwap(object[] param)
  498. {
  499. _swaproutine.Abort();
  500. return true;
  501. }
  502. private bool fnSwapTimeout(object[] param)
  503. {
  504. RState ret = _swaproutine.Monitor();
  505. if (ret == RState.Failed || ret == RState.Timeout)
  506. {
  507. PostMsg(MSG.Error);
  508. return false;
  509. }
  510. return ret == RState.End;
  511. }
  512. private bool fnStartSwap(object[] param)
  513. {
  514. return _swaproutine.Start(param) == RState.Running;
  515. }
  516. private bool fnStartAlign(object[] param)
  517. {
  518. if (float.TryParse(param[0].ToString(), out float angle))
  519. {
  520. return _vpa.Align();
  521. }
  522. else
  523. {
  524. LOG.Write(eEvent.ERR_TM, ModuleName.Aligner1, $"wrong angle, value is {param[0]}.");
  525. return false;
  526. }
  527. }
  528. private bool fnAlignTimeout(object[] param)
  529. {
  530. if (_vpa.Status == RState.End)
  531. {
  532. return true;
  533. }
  534. else if (_vpa.Status != RState.Running)
  535. {
  536. LOG.Write(eEvent.ERR_TM, ModuleName.Aligner1, $"PreAligner align failed: {_vpa.Status}");
  537. return true;
  538. }
  539. return false;
  540. }
  541. private bool fnAbortAlign(object[] param)
  542. {
  543. return true;
  544. }
  545. private bool fnAbortPMPlace(object[] param)
  546. {
  547. _placepmRoutine.Abort();
  548. return true;
  549. }
  550. private bool fnPMPlaceTimeout(object[] param)
  551. {
  552. RState ret = _placepmRoutine.Monitor();
  553. if (ret == RState.Failed || ret == RState.Timeout)
  554. {
  555. PostMsg(MSG.Error);
  556. return false;
  557. }
  558. return ret == RState.End;
  559. }
  560. private bool fnStartPMPlace(object[] param)
  561. {
  562. return _placepmRoutine.Start(param) == RState.Running;
  563. }
  564. private bool fnAbortPMPick(object[] param)
  565. {
  566. _pickpmRoutine.Abort();
  567. return true;
  568. }
  569. private bool fnPMPickTimeout(object[] param)
  570. {
  571. RState ret = _pickpmRoutine.Monitor();
  572. if (ret == RState.Failed || ret == RState.Timeout)
  573. {
  574. PostMsg(MSG.Error);
  575. return false;
  576. }
  577. return ret == RState.End;
  578. }
  579. private bool fnStartPMPick(object[] param)
  580. {
  581. return _pickpmRoutine.Start(param) == RState.Running;
  582. }
  583. private bool fnAbortVent(object[] param)
  584. {
  585. _ventRoutine.Abort();
  586. return true;
  587. }
  588. private bool fnVentTimeout(object[] param)
  589. {
  590. RState ret = _ventRoutine.Monitor();
  591. if (ret == RState.Failed || ret == RState.Timeout)
  592. {
  593. _ventRoutine.Abort();
  594. PostMsg(MSG.Error);
  595. return false;
  596. }
  597. return ret == RState.End;
  598. }
  599. private bool fnStartVent(object[] param)
  600. {
  601. return _ventRoutine.Start(param) == RState.Running;
  602. }
  603. private bool fnAbortPump(object[] param)
  604. {
  605. _pumpRoutine.Abort();
  606. return true;
  607. }
  608. private bool fnPumpTimeout(object[] param)
  609. {
  610. RState ret = _pumpRoutine.Monitor();
  611. if (ret == RState.Failed || ret == RState.Timeout)
  612. {
  613. _pumpRoutine.Abort();
  614. PostMsg(MSG.Error);
  615. return false;
  616. }
  617. return ret == RState.End;
  618. }
  619. private bool fnStartPump(object[] param)
  620. {
  621. return _pumpRoutine.Start(param) == RState.Running;
  622. }
  623. private bool fnAbortPlace(object[] param)
  624. {
  625. return true;
  626. }
  627. private bool fnPlaceTimeout(object[] param)
  628. {
  629. RState ret = _placeRoutine.Monitor();
  630. if (ret == RState.Failed || ret == RState.Timeout)
  631. {
  632. PostMsg(MSG.Error);
  633. return false;
  634. }
  635. return ret == RState.End;
  636. }
  637. private bool fnStartPlace(object[] param)
  638. {
  639. return _placeRoutine.Start(param) == RState.Running;
  640. }
  641. private bool fnAbortPick(object[] param)
  642. {
  643. _pickRoutine.Abort();
  644. return true;
  645. }
  646. private bool fnStartPick(object[] param)
  647. {
  648. return _pickRoutine.Start(param) == RState.Running;
  649. }
  650. private bool fnPickTimeout(object[] param)
  651. {
  652. RState ret = _pickRoutine.Monitor();
  653. if (ret == RState.Failed || ret == RState.Timeout)
  654. {
  655. PostMsg(MSG.Error);
  656. return false;
  657. }
  658. return ret == RState.End;
  659. }
  660. private bool fnAbortHome(object[] param)
  661. {
  662. _homeRoutine.Abort();
  663. return true;
  664. }
  665. private bool fnHome(object[] param)
  666. {
  667. if (fsm.State == (int)STATE.Init && param.Length > 0)//带参home
  668. {
  669. return false;
  670. }
  671. else
  672. return _homeRoutine.Start(param) == RState.Running;
  673. }
  674. private bool fnHomeTimeout(object[] param)
  675. {
  676. RState ret = _homeRoutine.Monitor();
  677. if (ret == RState.Failed || ret == RState.Timeout)
  678. {
  679. PostMsg(MSG.Error);
  680. return false;
  681. }
  682. return ret == RState.End;
  683. }
  684. private bool fnSetSpeed(object[] param)
  685. {
  686. return _robot.SetSpeed(param[0].ToString(), float.Parse(param[1].ToString()));
  687. }
  688. private bool fnSaveSpeed(object[] param)
  689. {
  690. return _robot.SaveSpeed(param[0].ToString());
  691. }
  692. private bool fnRQSpeed(object[] param)
  693. {
  694. return _robot.QuerySpeed(param[0].ToString());
  695. }
  696. private bool fnSetSpeedTimeout(object[] param)
  697. {
  698. RState ret = _robot.Status;
  699. if (ret == RState.Failed || ret == RState.Timeout)
  700. {
  701. PostMsg(MSG.Error);
  702. return false;
  703. }
  704. return ret == RState.End;
  705. }
  706. private bool fnSaveSpeedTimeout(object[] param)
  707. {
  708. RState ret = _robot.Status;
  709. if (ret == RState.Failed || ret == RState.Timeout)
  710. {
  711. PostMsg(MSG.Error);
  712. return false;
  713. }
  714. return ret == RState.End;
  715. }
  716. private bool fnAbortSaveSpeed(object[] param)
  717. {
  718. return true;
  719. }
  720. private bool fnRQSpeedTimeout(object[] param)
  721. {
  722. RState ret = _robot.Status;
  723. if (ret == RState.Failed || ret == RState.Timeout)
  724. {
  725. PostMsg(MSG.Error);
  726. return false;
  727. }
  728. return ret == RState.End;
  729. }
  730. private bool fnAbortRQSpeed(object[] param)
  731. {
  732. return true;
  733. }
  734. private bool fnAbortSetSpeed(object[] param)
  735. {
  736. return true;
  737. }
  738. private bool fnOffline(object[] param)
  739. {
  740. //IsOnline = false;
  741. //return true;
  742. throw new NotImplementedException();
  743. }
  744. private bool fnOnline(object[] param)
  745. {
  746. //IsOnline = true;
  747. //return true;
  748. throw new NotImplementedException();
  749. }
  750. private bool fnError(object[] param)
  751. {
  752. return true;
  753. }
  754. /// <summary>
  755. /// 控压处理逻辑
  756. /// 需要按照module去控压
  757. /// 在SE中 因为共用drypump 其前端压力以及使用锁存在抢占可能 需要在pumpstate处于idle下
  758. /// 在DE中 因为分开用drypump 可以在online后始终保持控压的模式
  759. /// </summary>
  760. /// <param name="param"></param>
  761. /// <returns></returns>
  762. private bool ControlPressureTimer_Elapsed(object[] param)
  763. {
  764. // robot idle check
  765. _robotIdleTrigger.CLK = _robot.Status != RState.Running;
  766. if (_robotIdleTrigger.Q)
  767. {
  768. _robotWatch.Restart();
  769. }
  770. if (RouteManager.IsATMMode)
  771. return true;
  772. if (IsOnline)
  773. {
  774. switch (RtInstance.ConfigType)
  775. {
  776. case ConfigType.VenusSE:
  777. //nobody use pump
  778. if (_tm.PumpingState == PumpState.Idle && !_tm.IsPressureControl)
  779. _tm.PressureControl(true);
  780. break;
  781. case ConfigType.VenusDE:
  782. if (!_tm.IsPressureControl)
  783. _tm.PressureControl(true);
  784. break;
  785. default:
  786. return true;
  787. }
  788. }
  789. else
  790. {
  791. switch (Module)
  792. {
  793. case ModuleName.TM:
  794. if (_tm.IsPressureControl)
  795. _tm.PressureControl(false);
  796. break;
  797. default:
  798. return true;
  799. }
  800. }
  801. //废弃代码
  802. //if (IsOnline && _tm.PumpingState == PumpState.Idle)
  803. //{
  804. //
  805. //}
  806. //else
  807. //{
  808. // if (!SC.GetValue<bool>($"{_module}.PressureControl.ControlWriteMode"))
  809. // {
  810. // SC.SetItemValue($"{_module}.PressureControl.ControlWriteMode", true);
  811. // }
  812. //}
  813. return true;
  814. }
  815. public bool Check(int msg, out string reason, params object[] args)
  816. {
  817. reason = "";
  818. return true;
  819. }
  820. public bool CheckAcked(int msg)
  821. {
  822. return fsm.CheckExecuted(msg);
  823. }
  824. public bool CheckToPostMessage(int msg, params object[] args)
  825. {
  826. if (!fsm.FindTransition(fsm.State, msg))
  827. {
  828. LOG.Write(eEvent.WARN_FSM_WARN, _module, $"TM is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  829. return false;
  830. }
  831. Running = true;
  832. fsm.PostMsg(msg, args);
  833. return true;
  834. }
  835. public int Invoke(string function, params object[] args)
  836. {
  837. switch (function)
  838. {
  839. case "Home":
  840. CheckToPostMessage((int)MSG.Home);
  841. return (int)MSG.Home;
  842. }
  843. return (int)FSM_MSG.NONE;
  844. }
  845. }
  846. }