434 lines
13 KiB
C#
434 lines
13 KiB
C#
using Aitex.Core.RT.DataCenter;
|
|
using Aitex.Core.RT.Device;
|
|
using Aitex.Core.RT.Event;
|
|
using Aitex.Core.RT.Fsm;
|
|
using Aitex.Core.RT.OperationCenter;
|
|
using Aitex.Core.RT.Routine;
|
|
using Aitex.Core.Util;
|
|
using Aitex.Core.Utilities;
|
|
using Aitex.Sorter.Common;
|
|
using MECF.Framework.Common.Equipment;
|
|
using MECF.Framework.Common.Fsm;
|
|
using MECF.Framework.Common.Schedulers;
|
|
using System;
|
|
|
|
namespace Mainframe.EFEMs
|
|
{
|
|
public class TrayRobotModule : ModuleFsmDevice, IModuleDevice
|
|
{
|
|
public enum STATE
|
|
{
|
|
NotInstall,
|
|
Init,
|
|
Idle,
|
|
Homing,
|
|
Error,
|
|
|
|
RobotHoming,
|
|
TrayRobotPick,
|
|
TrayRobotPlace,
|
|
TrayRobotMap,
|
|
}
|
|
|
|
public enum MSG
|
|
{
|
|
Home,
|
|
Reset,
|
|
Abort,
|
|
Error,
|
|
ToInit,
|
|
|
|
SetOnline,
|
|
SetOffline,
|
|
|
|
RobotHome,
|
|
TrayRobotPick,
|
|
TrayRobotPlace,
|
|
TrayRobotMap,
|
|
};
|
|
|
|
public SicTrayRobot TrayRobotDevice { get; set; }
|
|
|
|
public bool IsReady
|
|
{
|
|
get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed(); }
|
|
}
|
|
|
|
public bool IsError
|
|
{
|
|
get { return FsmState == (int)STATE.Error; }
|
|
}
|
|
|
|
public bool IsInit
|
|
{
|
|
get { return FsmState == (int)STATE.Init; }
|
|
}
|
|
|
|
public bool IsBusy
|
|
{
|
|
get { return !IsInit && !IsError && !IsReady; }
|
|
}
|
|
|
|
public bool IsIdle
|
|
{
|
|
get { return FsmState == (int)STATE.Idle && CheckAllMessageProcessed(); }
|
|
}
|
|
|
|
public bool IsAlarm
|
|
{
|
|
get
|
|
{
|
|
return FsmState == (int)STATE.Error;
|
|
}
|
|
}
|
|
|
|
public event Action<string> OnEnterError;
|
|
|
|
private TrayRobotPickRoutine _trayRobotPickRoutine;
|
|
private TrayRobotPlaceRoutine _trayRobotPlaceRoutine;
|
|
private TrayRobotHomeRoutine _trayRobotHomeRoutine;
|
|
private TrayRobotMapRoutine _trayRobotMapRoutine;
|
|
|
|
private bool _isInit;
|
|
|
|
public TrayRobotModule(ModuleName module)
|
|
{
|
|
Module = module.ToString();
|
|
Name = module.ToString();
|
|
IsOnline = false;
|
|
|
|
EnumLoop<STATE>.ForEach((item) =>
|
|
{
|
|
MapState((int)item, item.ToString());
|
|
});
|
|
|
|
EnumLoop<MSG>.ForEach((item) =>
|
|
{
|
|
MapMessage((int)item, item.ToString());
|
|
});
|
|
|
|
EnableFsm(50, IsInstalled ? STATE.Init : STATE.NotInstall);
|
|
}
|
|
|
|
public override bool Initialize()
|
|
{
|
|
InitRoutine();
|
|
|
|
InitDevice();
|
|
|
|
InitFsm();
|
|
|
|
InitOp();
|
|
|
|
InitData();
|
|
|
|
return base.Initialize();
|
|
}
|
|
|
|
private void InitRoutine()
|
|
{
|
|
ModuleName module = ModuleHelper.Converter(Module);
|
|
|
|
_trayRobotHomeRoutine = new TrayRobotHomeRoutine();
|
|
_trayRobotPickRoutine = new TrayRobotPickRoutine();
|
|
_trayRobotPlaceRoutine = new TrayRobotPlaceRoutine();
|
|
_trayRobotMapRoutine = new TrayRobotMapRoutine();
|
|
}
|
|
|
|
private void InitDevice()
|
|
{
|
|
TrayRobotDevice = DEVICE.GetDevice<SicTrayRobot>($"{ModuleName.TrayRobot}.{ModuleName.TrayRobot}");
|
|
}
|
|
|
|
private void InitFsm()
|
|
{
|
|
//Error
|
|
AnyStateTransition(MSG.Error, FsmOnError, STATE.Error);
|
|
AnyStateTransition(FSM_MSG.ALARM, FsmOnError, STATE.Error);
|
|
Transition(STATE.Error, MSG.Reset, FsmReset, STATE.Idle);
|
|
EnterExitTransition<STATE, FSM_MSG>(STATE.Error, FsmEnterError, FSM_MSG.NONE, FsmExitError);
|
|
|
|
//Home
|
|
Transition(STATE.Init, MSG.Home, FsmStartHome, STATE.Homing);
|
|
Transition(STATE.Error, MSG.Home, FsmStartHome, STATE.Homing);
|
|
Transition(STATE.Idle, MSG.Home, FsmStartHome, STATE.Homing);
|
|
Transition(STATE.Homing, FSM_MSG.TIMER, FsmMonitorHomeTask, STATE.Idle);
|
|
Transition(STATE.Homing, MSG.Error, null, STATE.Init);
|
|
Transition(STATE.Homing, MSG.Abort, FsmAbortTask, STATE.Init);
|
|
EnterExitTransition((int)STATE.Homing, FsmEnterIdle, (int)FSM_MSG.NONE, FsmExitIdle);
|
|
AnyStateTransition(MSG.ToInit, FsmToInit, STATE.Init);
|
|
|
|
//Online
|
|
Transition(STATE.Idle, MSG.SetOnline, FsmStartSetOnline, STATE.Idle);
|
|
Transition(STATE.Idle, MSG.SetOffline, FsmStartSetOffline, STATE.Idle);
|
|
|
|
Transition(STATE.Idle, MSG.RobotHome, FsmStartRobotHome, STATE.RobotHoming);
|
|
Transition(STATE.RobotHoming, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
|
|
Transition(STATE.RobotHoming, MSG.Abort, FsmAbortTask, STATE.Idle);
|
|
|
|
Transition(STATE.Idle, MSG.TrayRobotMap, FsmStartTrayRobotMap, STATE.TrayRobotMap);
|
|
Transition(STATE.TrayRobotMap, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
|
|
Transition(STATE.TrayRobotMap, MSG.Abort, FsmAbortTask, STATE.Idle);
|
|
|
|
Transition(STATE.Idle, MSG.TrayRobotPick, FsmStartTrayRobotPick, STATE.TrayRobotPick);
|
|
Transition(STATE.TrayRobotPick, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
|
|
Transition(STATE.TrayRobotPick, MSG.Abort, FsmAbortTask, STATE.Idle);
|
|
|
|
Transition(STATE.Idle, MSG.TrayRobotPlace, FsmStartTrayRobotPlace, STATE.TrayRobotPlace);
|
|
Transition(STATE.TrayRobotPlace, FSM_MSG.TIMER, FsmMonitorTask, STATE.Idle);
|
|
Transition(STATE.TrayRobotPlace, MSG.Abort, FsmAbortTask, STATE.Idle);
|
|
}
|
|
|
|
private void InitOp()
|
|
{
|
|
OP.Subscribe($"{Name}.Home", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Home));
|
|
OP.Subscribe($"{Name}.Reset", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Reset));
|
|
OP.Subscribe($"{Name}.Abort", (string cmd, object[] args) => CheckToPostMessage((int)MSG.Abort));
|
|
OP.Subscribe($"{Module}.SetOnline", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SetOnline));
|
|
OP.Subscribe($"{Module}.SetOffline", (string cmd, object[] args) => CheckToPostMessage((int)MSG.SetOffline));
|
|
|
|
OP.Subscribe($"{Module}.RobotHome", (string cmd, object[] args) => CheckToPostMessage((int)MSG.RobotHome));
|
|
OP.Subscribe($"{Module}.PickTray", (string cmd, object[] args) => CheckToPostMessage((int)MSG.TrayRobotPick, args[0], args[1]));
|
|
OP.Subscribe($"{Module}.PlaceTray", (string cmd, object[] args) => CheckToPostMessage((int)MSG.TrayRobotPlace, args[0], args[1]));
|
|
OP.Subscribe($"{Module}.MapTray", (string cmd, object[] args) => CheckToPostMessage((int)MSG.TrayRobotMap, args[0]));
|
|
}
|
|
|
|
private void InitData()
|
|
{
|
|
DATA.Subscribe($"{Module}.Status", () => StringFsmStatus);
|
|
DATA.Subscribe($"{Module}.IsOnline", () => IsOnline);
|
|
DATA.Subscribe($"{Module}.IsBusy", () => IsBusy);
|
|
DATA.Subscribe($"{Module}.IsAlarm", () => IsAlarm);
|
|
}
|
|
|
|
private bool FsmOnError(object[] param)
|
|
{
|
|
IsOnline = false;
|
|
|
|
if (FsmState == (int)STATE.Error)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (FsmState == (int)STATE.Init)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
private bool FsmReset(object[] param)
|
|
{
|
|
if (!_isInit)
|
|
{
|
|
PostMsg(MSG.ToInit);
|
|
return false;
|
|
}
|
|
|
|
TrayRobotDevice.RobotReset();
|
|
return true;
|
|
}
|
|
|
|
private bool FsmExitError(object[] param)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
private bool FsmEnterError(object[] param)
|
|
{
|
|
if (OnEnterError != null)
|
|
OnEnterError(Module);
|
|
return true;
|
|
}
|
|
|
|
private bool FsmStartHome(object[] param)
|
|
{
|
|
Result ret = StartRoutine(_trayRobotHomeRoutine);
|
|
if (ret == Result.FAIL || ret == Result.DONE)
|
|
return false;
|
|
return ret == Result.RUN;
|
|
}
|
|
|
|
private bool FsmMonitorHomeTask(object[] param)
|
|
{
|
|
Result ret = MonitorRoutine();
|
|
if (ret == Result.FAIL)
|
|
{
|
|
PostMsg(MSG.Error);
|
|
return false;
|
|
}
|
|
|
|
if (ret == Result.DONE)
|
|
{
|
|
_isInit = true;
|
|
OP.DoOperation($"{Module}.ResetTask");
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private bool FsmAbortTask(object[] param)
|
|
{
|
|
AbortRoutine();
|
|
|
|
TrayRobotDevice.Abort();
|
|
return true;
|
|
}
|
|
|
|
private bool FsmExitIdle(object[] param)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
private bool FsmEnterIdle(object[] param)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
private bool FsmToInit(object[] param)
|
|
{
|
|
TrayRobotDevice.RobotReset();
|
|
return true;
|
|
}
|
|
|
|
private bool FsmStartSetOffline(object[] param)
|
|
{
|
|
IsOnline = false;
|
|
return true;
|
|
}
|
|
|
|
private bool FsmStartSetOnline(object[] param)
|
|
{
|
|
IsOnline = true;
|
|
return true;
|
|
}
|
|
|
|
private bool FsmMonitorTask(object[] param)
|
|
{
|
|
Result ret = MonitorRoutine();
|
|
if (ret == Result.FAIL)
|
|
{
|
|
PostMsg(MSG.Error);
|
|
return false;
|
|
}
|
|
|
|
return ret == Result.DONE;
|
|
}
|
|
|
|
public bool Abort()
|
|
{
|
|
CheckToPostMessage((int)MSG.Abort);
|
|
return true;
|
|
}
|
|
|
|
public bool Home(out string reason)
|
|
{
|
|
CheckToPostMessage((int)MSG.Home);
|
|
reason = string.Empty;
|
|
return true;
|
|
}
|
|
|
|
public bool CheckAcked(int entityTaskToken)
|
|
{
|
|
return FsmState == (int)STATE.Idle && CheckAllMessageProcessed();
|
|
//return true;
|
|
}
|
|
|
|
public void InvokeOffline()
|
|
{
|
|
PostMsg((int)MSG.SetOffline);
|
|
}
|
|
|
|
public void InvokeOnline()
|
|
{
|
|
PostMsg((int)MSG.SetOnline);
|
|
}
|
|
|
|
public bool MapTray(object[] objs)
|
|
{
|
|
if (CheckToPostMessage((int)MSG.TrayRobotMap, objs))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public bool MapTray(ModuleName target)
|
|
{
|
|
if (CheckToPostMessage((int)MSG.TrayRobotMap, target.ToString()))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public bool PickTray(object[] objs)
|
|
{
|
|
if (CheckToPostMessage((int)MSG.TrayRobotPick, objs))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public bool PickTray(ModuleName target, Hand blade, int targetSlot)
|
|
{
|
|
if (CheckToPostMessage((int)MSG.TrayRobotPick, target.ToString(), targetSlot, blade))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public bool PlaceTray(object[] objs)
|
|
{
|
|
if (CheckToPostMessage((int)MSG.TrayRobotPlace, objs))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public bool PlaceTray(ModuleName target, Hand blade, int targetSlot)
|
|
{
|
|
if (CheckToPostMessage((int)MSG.TrayRobotPlace, target.ToString(), targetSlot, blade))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
|
|
private bool FsmStartRobotHome(object[] param)
|
|
{
|
|
Result ret = StartRoutine(_trayRobotHomeRoutine);
|
|
if (ret == Result.FAIL || ret == Result.DONE)
|
|
return false;
|
|
return ret == Result.RUN;
|
|
}
|
|
private bool FsmStartTrayRobotMap(object[] param)
|
|
{
|
|
_trayRobotMapRoutine.Init(ModuleHelper.Converter((string)param[0]));
|
|
Result ret = StartRoutine(_trayRobotMapRoutine);
|
|
if (ret == Result.FAIL || ret == Result.DONE)
|
|
return false;
|
|
return ret == Result.RUN;
|
|
}
|
|
|
|
|
|
private bool FsmStartTrayRobotPick(object[] param)
|
|
{
|
|
_trayRobotPickRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1]);
|
|
Result ret = StartRoutine(_trayRobotPickRoutine);
|
|
if (ret == Result.FAIL || ret == Result.DONE)
|
|
return false;
|
|
return ret == Result.RUN;
|
|
}
|
|
|
|
private bool FsmStartTrayRobotPlace(object[] param)
|
|
{
|
|
_trayRobotPlaceRoutine.Init(ModuleHelper.Converter((string)param[0]), (int)param[1]);
|
|
Result ret = StartRoutine(_trayRobotPlaceRoutine);
|
|
if (ret == Result.FAIL || ret == Result.DONE)
|
|
return false;
|
|
return ret == Result.RUN;
|
|
}
|
|
|
|
public int InvokeError()
|
|
{
|
|
if (CheckToPostMessage((int)MSG.Error))
|
|
return (int)MSG.Error;
|
|
|
|
return (int)FSM_MSG.NONE;
|
|
}
|
|
}
|
|
}
|