using Aitex.Core.RT.Routine;
using Aitex.Core.RT.SCCore;

namespace SicModules.UnLoads.Routines
{
    public class UnLoadSeparateRoutine : UnLoadBaseRoutine
    {
        /*
         *  1、Unload伺服到传盘压力
            2、夹爪打开
            3、顶升晶圆
            4、夹爪闭合
            5、顶升缩回
            6、打开闸板阀
            7、Robot开始取托盘到TM
            8、关闭闸板阀
         * 
         */
        enum RoutineStep
        {
            ClawOpen,
            LiftUp,
            Clawing,
            LiftDown,
            TimeDelay1,
        }

        private int _clawMoveTimeOut = 30;
        private int _liftMoveTimeOut = 30;

        public UnLoadSeparateRoutine()
        {
            Name = "Separate";
        }

        public override Result Start(params object[] objs)
        {
            Reset();
            _liftMoveTimeOut = SC.GetValue<int>("UnLoad.LiftMoveTimeOut");
            _clawMoveTimeOut = SC.GetValue<int>("UnLoad.ClawMoveTimeOut");

            Notify("Start");
            return Result.RUN;
        }


        public override Result Monitor()
        {
            try
            {
                ClawMove((int)RoutineStep.ClawOpen, WaferClaw, false, _clawMoveTimeOut);
                LiftMove((int)RoutineStep.LiftUp, true, _liftMoveTimeOut);
                ClawMove((int)RoutineStep.Clawing, WaferClaw, true, _clawMoveTimeOut);
                LiftMove((int)RoutineStep.LiftDown, false, _liftMoveTimeOut);
            }
            catch (RoutineBreakException)
            {
                return Result.RUN;
            }
            catch (RoutineFaildException)
            {
                return Result.FAIL;
            }

            Notify("Finished");

            return Result.DONE;
        }

        public override void Abort()
        {

        }

    }
}
