123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- using Aitex.Core.RT.Routine;
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using DocumentFormat.OpenXml.Wordprocessing;
- using FurnaceRT.Equipments.Systems;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Schedulers;
- using MECF.Framework.RT.EquipmentLibrary.LogicUnits;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace FurnaceRT.Equipments.CarrierRobots
- {
-
- public class CarrierRobotCycleSwap : ModuleRoutine, IRoutine
- {
- enum RoutineStep
- {
- Loop,
- GetModule,
- Pick1,
- Pick2,
- PickInit1,
- PickInit2,
- Place1,
- Place2,
- PlaceInit1,
- PlaceInit2,
- EndLoop,
- }
- private CarrierRobotModule _CarrierRobotModule;
- private ModuleName _source;
- private ModuleName _dest;
- private Hand _hand;
- private CarrierRobotPick _pick;
- private CarrierRobotPlace _place;
- private int _slot;
- private int _cycleNumber;
- public bool IsAbortCycle = false;
- private int _currentIndex;
- public int _overAllLoopCount=0;
- private List<ModuleName> _lsModuleName;
- public CarrierRobotCycleSwap(CarrierRobotModule cassetteModule)
- {
- _pick = new CarrierRobotPick(cassetteModule);
- _place = new CarrierRobotPlace(cassetteModule);
- _CarrierRobotModule = cassetteModule;
- Module = cassetteModule.Name;
- Name = "CycleSwap";
- }
- public Result Start(params object[] objs)
- {
- Reset();
- _currentIndex = 0;
- _overAllLoopCount = 0;
- Notify("Start");
- return Result.RUN;
- }
- public void Init(ModuleName source, ModuleName dest, int slot, Hand hand, int cyclenum)
- {
- _source = source;
- _dest = dest;
- _slot = slot;
- _hand = hand;
- IsAbortCycle = false;
- int startIndex = int.Parse(source.ToString().Replace("Stocker", ""));
- int endIndex = int.Parse(dest.ToString().Replace("Stocker", ""));
- _lsModuleName = new List<ModuleName>();
- for (int i = 0; i < cyclenum; i++)
- {
- if (startIndex > endIndex)
- {
- for (int j = startIndex; j >= endIndex; j--)
- {
- _lsModuleName.Add((ModuleName)Enum.Parse(typeof(ModuleName), "Stocker" + j));
- }
- }
- else
- {
- for (int j = startIndex; j <= endIndex; j++)
- {
- _lsModuleName.Add((ModuleName)Enum.Parse(typeof(ModuleName), "Stocker" + j));
- }
- }
- }
- _cycleNumber = _lsModuleName.Count;
- }
- public void Abort()
- {
- IsAbortCycle = true;
- (Singleton<EquipmentManager>.Instance.Modules[_dest] as ITransferTarget)?.NoteTransferStop(ModuleHelper.Converter(_CarrierRobotModule.Module), new Hand(), 0, EnumTransferType.Pick);
- }
- public override Result Monitor()
- {
- try
- {
- if (IsAbortCycle) return Result.DONE;
- PauseRountine(_CarrierRobotModule.CarrierRobotDevice.IsPause);
- if (_CarrierRobotModule.CarrierRobotDevice.IsPause)
- return Result.RUN;
- Loop((int)RoutineStep.Loop, _cycleNumber);
- GetModule((int)RoutineStep.GetModule);
- PickInit((int)RoutineStep.PickInit1, _source, _slot, _hand);
- ExecuteRoutine((int)RoutineStep.Pick1, _pick);
- PlaceInit((int)RoutineStep.PlaceInit1, _dest, _slot, _hand);
- ExecuteRoutine((int)RoutineStep.Place1, _place);
- EndLoop((int)RoutineStep.EndLoop);
- }
- catch (RoutineBreakException)
- {
- return Result.RUN;
- }
- catch (RoutineFaildException)
- {
- return Result.FAIL;
- }
- Notify("Finished");
- return Result.DONE;
- }
- private void GetModule(int id)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify($"Get Module currentIndex = {_currentIndex}");
- _source = _lsModuleName[_currentIndex];
- if (_currentIndex == _lsModuleName.Count - 1)
- {
- _currentIndex = 0;
- }
- else
- {
- _currentIndex++;
- }
- _dest = _lsModuleName[_currentIndex];
- if ( _source.Equals(_lsModuleName.FirstOrDefault()))
- {
- _overAllLoopCount++;
- Notify($"_overAllLoopCount = {_overAllLoopCount}");
- }
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- private void PickInit(int id, ModuleName source, int slot, Hand blade)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify($"Pick from {source} {slot} init");
- string reason = string.Empty;
- _pick.Init(source, slot, blade, false);
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- private void PlaceInit(int id, ModuleName dest, int slot, Hand blade)
- {
- Tuple<bool, Result> ret = Execute(id, () =>
- {
- Notify($"Place to {dest} {slot} init");
- string reason = string.Empty;
- _place.Init(dest, slot, blade, false);
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw (new RoutineFaildException());
- }
- }
- }
- }
- }
|