123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Routine;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.Alarms;
- using MECF.Framework.Common.Device.Bases;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using FurnaceRT.Equipments.Systems;
- using static Aitex.Core.RT.Device.Unit.IoBoat;
- using System.Diagnostics;
- using FurnaceRT.Devices;
- namespace FurnaceRT.Equipments.Boats
- {
- public class BoatMove : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- SetBoatSpeed,
- SetBoatDirection,
- BoatRAxisHome,
- BoatRAxisMove,
- SetBoatZAxisMoveStop,
- SetBoatRAxisMoveStop,
- SetBoatInterval,
- CheckPrepareMove,
- Loop,
- EndLoop,
- Delay1,
- Delay2,
- Delay3,
- ZMoveToStart,
- ZMoveToEnd,
- ZMove,
- AutoShutterOpen,
- AutoShutterClose,
- }
- private BoatModule _boatModule;
- private int _timeout = 0;
- private int _shutterTimeout = 0;
- private string _command;
- private string _position;
- private float _speed;
- public BoatMove(BoatModule boatModule)
- {
- _boatModule = boatModule;
- Module = boatModule.Module;
- Name = "Move";
- }
- public void Init(string command, string position, string speed)
- {
- _command = command;
- _position = position;
- float.TryParse(speed, out _speed);
- var para = new List<object> { _command, _position, _speed };
- _boatModule.BoatZAxisMoveFailedForInterlock.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
- _boatModule.BoatZAxisMoveFailedForInterlock.RetryMessageParas = para.ToArray();
- _boatModule.BoatZAxisMoveFailedForHumanInterlock.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
- _boatModule.BoatZAxisMoveFailedForHumanInterlock.RetryMessageParas = para.ToArray();
- _boatModule.BoatZAxisMoveFailedForWaferRobotArmExtend.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
- _boatModule.BoatZAxisMoveFailedForWaferRobotArmExtend.RetryMessageParas = para.ToArray();
- _boatModule.BoatZAxisMoveTimeOut.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
- _boatModule.BoatZAxisMoveTimeOut.RetryMessageParas = para.ToArray();
- _boatModule.AutoShutterMoveFailedForInterlock.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
- _boatModule.AutoShutterMoveFailedForInterlock.RetryMessageParas = para.ToArray();
- _boatModule.AutoShutterOpenTimeOut.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
- _boatModule.AutoShutterOpenTimeOut.RetryMessageParas = para.ToArray();
- _boatModule.AutoShutterCloseTimeOut.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
- _boatModule.AutoShutterCloseTimeOut.RetryMessageParas = para.ToArray();
- _boatModule.BoatRAxisMoveTimeOut.RetryMessage = (int)BoatModule.MSG.BoatMoveRetry;
- _boatModule.BoatRAxisMoveTimeOut.RetryMessageParas = para.ToArray();
- }
- public Result Start(params object[] objs)
- {
- Reset();
- _timeout = SC.GetValue<int>($"{Module}.MotionTimeout");
- _shutterTimeout = SC.GetValue<int>($"{Module}.AutoShutter.MotionTimeout");
- var isBeforeShutter = new List<string>() { "boatload", "boatcap2", "boatunload", "boatloaderhome", };
- if (!string.IsNullOrEmpty(_command) && isBeforeShutter.Contains(_command))
- {
- string reason = "";
- if (!_boatModule.CheckPrepareMove(out reason, false))
- {
- _boatModule.BoatZAxisMoveFailedForInterlock.Set(reason);
- return Result.FAIL;
- }
- }
- Notify($"Start");
- return Result.RUN;
- }
- public void Abort()
- {
- _boatModule.ZAxisDevice.ServoStop();
- _boatModule.RAxisDevice.ServoStop();
- }
- public override Result Monitor()
- {
- try
- {
- PauseRountine(_boatModule.RAxisDevice.IsPause);
- if (_boatModule.RAxisDevice.IsPause)
- return Result.RUN;
- if (_boatModule.RAxisDevice.IsError || _boatModule.ZAxisDevice.IsError)
- return Result.FAIL;
- switch (_command)
- {
- case "boatload":
- case "boatcap2":
- AutoShutterOpen((int)RoutineStep.AutoShutterOpen, true, _shutterTimeout);
- CheckPrepareMove((int)RoutineStep.CheckPrepareMove, 2);
- var position = (BoatPosition)Enum.Parse(typeof(BoatPosition), _position);
- SetBoatZAxisMove((int)RoutineStep.ZMove, position, _speed, (int)_timeout);
- break;
- case "boatunload":
- case "boatloaderhome":
- AutoShutterOpen((int)RoutineStep.AutoShutterOpen, true, _shutterTimeout);
- CheckPrepareMove((int)RoutineStep.CheckPrepareMove, 2);
- position = (BoatPosition)Enum.Parse(typeof(BoatPosition), _position);
- SetBoatZAxisMove((int)RoutineStep.ZMove, position, _speed, (int)_timeout);
- AutoShutterOpen((int)RoutineStep.AutoShutterClose, false, _shutterTimeout);
- break;
- case "boatrotate":
- var direction = (BoatRotationDirection)Enum.Parse(typeof(BoatRotationDirection), _position);
- SetBoatRAxisMove((int)RoutineStep.BoatRAxisMove, direction, _speed, _timeout);
- break;
- case "boatrotatestop"://r home
- SetBoatRAxisMoveStop((int)RoutineStep.SetBoatRAxisMoveStop);
- Delay((int)RoutineStep.Delay1, 2);
- SetBoatRAxisHome((int)RoutineStep.BoatRAxisHome, _timeout);
- break;
- case "stop(includer-axis)":
- SetBoatZAxisMoveStop((int)RoutineStep.SetBoatZAxisMoveStop);
- SetBoatRAxisMoveStop((int)RoutineStep.SetBoatRAxisMoveStop);
- break;
- }
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException ex)
- {
- _boatModule.RAxisDevice.ServoStop();
- return Result.FAIL;
- }
- Notify("Finished");
- return Result.DONE;
- }
- private void CheckPrepareMove(int id, int timeout)
- {
- var reason = "";
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Check boat move enable");
- return true;
- }, () =>
- {
- return _boatModule.CheckPrepareMove(out reason);
- }, timeout * 2 * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- _boatModule.BoatZAxisMoveFailedForInterlock.Set($"{reason} is not OK, can not complete in {timeout} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- private void AutoShutterOpen(int id, bool isOpen, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"shutter {(isOpen ? "open" : "close")}");
- string reason;
- if (!_boatModule.ShutterDevice.SetOpen(isOpen, out reason))
- {
- _boatModule.ShutterDevice.AutoShutterMoveFailedForInterlock.Set();
- return false;
- }
- return true;
- }, () =>
- {
- return isOpen ? _boatModule.ShutterDevice.OpenCloseStatus == DeviceStatus.Open : _boatModule.ShutterDevice.OpenCloseStatus == DeviceStatus.Close;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- if (isOpen)
- {
- _boatModule.ShutterDevice.AutoShutterOpenTimeOut.Set($"can not complete in {timeout} seconds");
- }
- else
- {
- _boatModule.ShutterDevice.AutoShutterCloseTimeOut.Set($"can not complete in {timeout} seconds");
- }
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- private void SetBoatZAxisMove(int id, BoatPosition position, float speed, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Boat ZAxis movet to {position}");
- string reason;
- if (!_boatModule.ZAxisDevice.SetServoMoveTo(position.ToString(), out reason, speed))
- {
- //_boatModule.BoatDevice.BoatRAxisMoveFailedForInterlock.Description = reason;
- _boatModule.BoatZAxisMoveFailedForInterlock.Set(reason);
- }
- return true;
- }, () =>
- {
- if (_boatModule.ZAxisDevice.IsError)
- return null;
- return _boatModule.ZAxisDevice.CheckServoAtPosition(position.ToString());
- }, timeout * 2 * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- _boatModule.ZAxisDevice.ServoStop();
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- _boatModule.ZAxisDevice.ServoStop();
- _boatModule.BoatZAxisMoveTimeOut.Set($"can not complete in {timeout} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- private void SetBoatZAxisMoveStop(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify($"Set ZAxis boat stop");
- _boatModule.ZAxisDevice.ServoStop();
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- private void SetBoatRAxisMoveStop(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify($"Set RAxis boat stop");
- _boatModule.RAxisDevice.ServoStop();
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- private void SetBoatRAxisHome(int id, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Boat RAxis home");
- if (!_boatModule.RAxisDevice.SetServoHome())
- {
- _boatModule.BoatRAxisHomeFailed.Set();
- }
- return true;
- }, () =>
- {
- if (_boatModule.RAxisDevice.IsError)
- return null;
- return _boatModule.RAxisDevice.IsHomeDone && _boatModule.RAxisDevice.IsReady;
- }, timeout * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- _boatModule.RAxisDevice.ServoStop();
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- _boatModule.RAxisDevice.ServoStop();
- _boatModule.BoatRAxisHomeTimeout.Set($"can not complete in {timeout} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- private void SetBoatRAxisMove(int id, BoatRotationDirection direction, float speed, int timeout)
- {
- Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
- {
- Notify($"Boat RAxis {direction}");
- string reason;
- if (!_boatModule.RAxisDevice.SetServoMoveTo(direction.ToString(), out reason, speed))
- {
- //_boatModule.BoatDevice.BoatRAxisMoveFailedForInterlock.Description = reason;
- _boatModule.BoatRAxisMoveFailedForInterlock.Set(reason);
- }
- return true;
- }, () =>
- {
- if (_boatModule.RAxisDevice.IsError)
- return null;
- return _boatModule.RAxisDevice.IsMoving;
- }, timeout * 2 * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- _boatModule.RAxisDevice.ServoStop();
- throw (new RoutineFaildException());
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- _boatModule.RAxisDevice.ServoStop();
- _boatModule.BoatRAxisMoveTimeOut.Set($"can not complete in {timeout} seconds");
- throw (new RoutineFaildException());
- }
- else
- throw (new RoutineBreakException());
- }
- }
- }
- }
|