SETMEntity.cs 31 KB

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