SETMEntity.cs 32 KB

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