| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 | 
							- 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;
 
- namespace FurnaceRT.Equipments.Boats
 
- {
 
-     public class BoatRAxisMoveCycleTest : ModuleRoutine, IRoutine
 
-     {
 
-         enum RoutineStep
 
-         {
 
-             SetBoatSpeed,
 
-             SetBoatDirection,
 
-             BoatRAxisHome,
 
-             BoatRAxisMove,
 
-             SetBoatRAxisMoveStop,
 
-             SetBoatInterval,
 
-             Loop,
 
-             EndLoop,
 
-             Delay1,
 
-             Delay2,
 
-             Delay3,
 
-         }
 
-         private BoatRotationMode _targetMode;
 
-         private float _speed;
 
-         private float _interval;
 
-         private float _rotateTime;
 
-         private BoatModule _boatModule;
 
-         private int _timeout = 0;
 
-         private bool _isRotate;
 
-         private BoatRotationDirection _direction;
 
-         private Stopwatch _timer = new Stopwatch();
 
-         private int _count;
 
-         public BoatRAxisMoveCycleTest(BoatModule boatModule)
 
-         {
 
-             _boatModule = boatModule;
 
-             Module = boatModule.Module;
 
-             Name = "RAxisMoveTest";
 
-         }
 
-         public void Init(string direction = "CW")
 
-         {
 
-             _direction = (BoatRotationDirection)Enum.Parse(typeof(BoatRotationDirection), direction);
 
-         }
 
-         public Result Start(params object[] objs)
 
-         {
 
-             Reset();
 
-             _isRotate = _targetMode != BoatRotationMode.Stop;
 
-             _timeout = SC.GetValue<int>($"{Module}.MotionTimeout");
 
-             _count = SC.GetValue<int>($"Boat.BoatRotationServo.CycleCount");
 
-             _speed = (float)SC.GetValue<double>($"Boat.BoatRotationServo.MoveSpeed");
 
-             _interval = (float)SC.GetValue<double>($"Boat.BoatRotationServo.IntervalTime");
 
-             _rotateTime = (float)SC.GetValue<double>($"Boat.BoatRotationServo.RotateTime");
 
-             Notify($"Start");
 
-             return Result.RUN;
 
-         }
 
-         public void Abort()
 
-         {
 
-             _boatModule.RAxisDevice.ServoStop();
 
-         }
 
-         public override Result Monitor()
 
-         {
 
-             try
 
-             {
 
-                 PauseRountine(_boatModule.RAxisDevice.IsPause);
 
-                 if (_boatModule.RAxisDevice.IsPause)
 
-                     return Result.RUN;
 
-                 if (_boatModule.RAxisDevice.IsError)
 
-                     return Result.FAIL;
 
-                 Loop((int)RoutineStep.Loop, _count);
 
-                 SetBoatRAxisMove((int)RoutineStep.BoatRAxisMove, _direction, (int)_rotateTime);
 
-                 
 
-                 SetBoatRAxisMoveStop((int)RoutineStep.SetBoatRAxisMoveStop);
 
-                 Delay((int)RoutineStep.Delay1, 2);
 
-                
 
-                 Delay((int)RoutineStep.Delay2, _interval);
 
-                 SetBoatRAxisHome((int)RoutineStep.BoatRAxisHome, _timeout);
 
-                 Delay((int)RoutineStep.Delay3, _interval);
 
-                 EndLoop((int)RoutineStep.EndLoop);
 
-             }
 
-             catch (RoutineBreakException)
 
-             {
 
-                 return Result.RUN;
 
-             }
 
-             catch (RoutineFaildException ex)
 
-             {
 
-                 return Result.FAIL;
 
-             }
 
-             Notify("Finished");
 
-             return Result.DONE;
 
-         }
 
-         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, int timeout)
 
-         {
 
-             Tuple<bool, Result> ret = ExecuteAndWait(id, () =>
 
-             {
 
-                 Notify($"Boat RAxis {direction}");
 
-                 _timer.Restart();
 
-                 string reason;
 
-                 if (!_boatModule.RAxisDevice.SetServoMoveTo(direction.ToString(), out reason))
 
-                 {
 
-                     //_boatModule.BoatDevice.BoatRAxisMoveFailedForInterlock.Description = reason;
 
-                     _boatModule.BoatRAxisMoveFailedForInterlock.Set(reason);
 
-                 }
 
-                 return true;
 
-             }, () =>
 
-             {
 
-                 if (_boatModule.RAxisDevice.IsError)
 
-                     return null;
 
-                 return _boatModule.RAxisDevice.IsMoving && _timer.ElapsedMilliseconds > timeout * 1000;
 
-             }, 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());
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |