SendFullShelfToLineJob.cs 9.4 KB

using AGVControl;
using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;

namespace AGVControl
{
    /// <summary>
    /// 从A6向产线运行任务(出满料)
    /// </summary>
    public class SendFullShelfToLineJob : Job
    {
        /// <summary>
        /// 从A6向产线运行任务(出满料)
        /// </summary>
        /// <param name="palce">产线名</param>
        /// <param name="rfid">料架RFID</param>
        /// <param name="isIgNoreBigShelf">是否忽略大料架</param>
        public SendFullShelfToLineJob(AGVManager.BoxDestInfo boxDestInfo,bool isIgNoreBigShelf=false)
        {
            FullShelfPlace = boxDestInfo.location;
            RFID = boxDestInfo.id;
            BoxDestInfo = boxDestInfo;
            IsIgnoreBigShelf = isIgNoreBigShelf;        
        }

        /// <summary>
        /// 满料架目标位置点
        /// </summary>
        public string FullShelfPlace { get; set; }

        public string RFID { get; set; }

        public AGVManager.BoxDestInfo BoxDestInfo { get; private set; }
        /// <summary>
        /// 是否忽略大料架移库解绑
        /// </summary>
        public bool IsIgnoreBigShelf { get; private set; }


        private string runInfo = "";
        /// <summary>
        /// 运行信息
        /// </summary>
        public override string RunInfo
        {
            get { return runInfo; }
        }


        private JobStep<SEND_FULL_SHELF_STEP> SendFullShelfStep = new JobStep<SEND_FULL_SHELF_STEP>(SEND_FULL_SHELF_STEP.NONE);

        public override Job Execute(Agv_Info agv)
        {
            string msg = agv.Name+" ";
            bool rtn = false;
            agv.RFID = RFID;
            agv.Msg = runInfo;
            if (SendFullShelfStep.IsStep(SEND_FULL_SHELF_STEP.NONE))
            {

                if(FullShelfPlace.StartsWith("G"))
                {
                    SendFullShelfStep.ToNextStep(SEND_FULL_SHELF_STEP.WAIT_AGV_REACH_DOOR);
                    runInfo = "满料架前往4C门,从双层线A6送往[" + FullShelfPlace + "][" + RFID + "]";
                    msg += runInfo;
                    SendFullShelfStep.Msg = msg;
                    Common.DoorMission(agv, SettingString.DoorDToC);
                }
                else
                {
                    SendFullShelfStep.ToNextStep(SEND_FULL_SHELF_STEP.WAIT_AGV_REACH_LINE);
                    runInfo= "满料架从双层线A6送往[" + FullShelfPlace + "][" + RFID + "]";
                    msg += runInfo;
                    SendFullShelfStep.Msg = msg;
                    Common.MoveToNode(agv, FullShelfPlace);
                }

            }

            else if (SendFullShelfStep.IsStep(SEND_FULL_SHELF_STEP.WAIT_AGV_REACH_DOOR))
            {
                if (Common.CheckTaskFinished(agv,SettingString.DoorDToC,agv.CurTaskGUID))
                {
                    SendFullShelfStep.ToNextStep(SEND_FULL_SHELF_STEP.WAIT_AGV_REACH_LINE);
                    runInfo= "满料架从双层线A6送往[" + FullShelfPlace + "][" + RFID + "]";
                    msg += runInfo;
                    SendFullShelfStep.Msg = msg;
                    Common.MoveToNode(agv, FullShelfPlace);
                }
            }
            else if (SendFullShelfStep.IsStep(SEND_FULL_SHELF_STEP.WAIT_AGV_REACH_LINE))
            {
                if (Common.CheckTaskFinished(agv,FullShelfPlace,agv.CurTaskGUID))
                {
                    if(FullShelfPlace.Equals("G21"))
                    {
                        runInfo= "AGV到达 " + FullShelfPlace + "完成";
                        msg += runInfo;
                        SendFullShelfStep.Msg = msg;
                        return new EnterLeaveShelfJob(FullShelfPlace, eEnterLeaveType.Leave);
                    }
                    if (IsIgnoreBigShelf)
                    {
                        SendFullShelfStep.ToNextStep(SEND_FULL_SHELF_STEP.WAIT_LINE_RESPONSE);
                        runInfo = "AGV到达 " + FullShelfPlace + ",并发送入料架请求[ReadyEnter]";
                        msg += runInfo;
                        SendFullShelfStep.Msg = msg;
                        Common.server.ReadyEnter(FullShelfPlace);
                    }
                    else
                    {
                        if (RFID.StartsWith("C") && !agv.Place.Equals("E21"))
                        {
                            SendFullShelfStep.ToNextStep(SEND_FULL_SHELF_STEP.WAIT_BIG_SHELF_UNLOCK);
                            runInfo= "AGV到达 " + FullShelfPlace + ",并等待大料架[" + RFID + "]解绑";
                            msg += runInfo;
                            SendFullShelfStep.Msg = msg;
                        }
                        else
                        {
                            SendFullShelfStep.ToNextStep(SEND_FULL_SHELF_STEP.WAIT_LINE_RESPONSE);
                            runInfo= "AGV到达 " + FullShelfPlace + ",并发送入料架请求[ReadyEnter]";
                            msg += runInfo;
                            SendFullShelfStep.Msg = msg;
                            Common.server.ReadyEnter(FullShelfPlace);
                        }
                    }

                }
            }
            else if (SendFullShelfStep.IsStep(SEND_FULL_SHELF_STEP.WAIT_BIG_SHELF_UNLOCK))
            {
                Common.mir.Get_IO_Status(agv, out bool[] input, out bool[] output);
                System.Threading.Thread.Sleep(50);
                if (AGVManager.GetRackBy(RFID, out string lineName) || (input!=null && input[0]))
                {
                    runInfo= "大料架在" + FullShelfPlace + "解绑完成 [" + RFID + "]";
                    msg += runInfo;
                    SendFullShelfStep.Msg = msg;
                    return new EmptyShelfBackJob(FullShelfPlace,eShelfType.BigShelf);
                }
            }
            else if (SendFullShelfStep.IsStep(SEND_FULL_SHELF_STEP.WAIT_LINE_RESPONSE))
            {
                int id = Common.FindNode(FullShelfPlace);
                ClientNode node = Common.nodeInfo[id];
                if (node.StateEquals(eNodeStatus.MayEnter))
                {
                    if(!agv.CurTaskName.Equals("Leave"))
                    {
                        SendFullShelfStep.ToNextStep(SEND_FULL_SHELF_STEP.WAIT__SHELF_IN_LINE);
                        runInfo= "收到产线入料架请求[ReadyEnter]的响应 " + FullShelfPlace + "入料架,小车链条运行";
                        msg += runInfo;
                        SendFullShelfStep.Msg = msg;
                        rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission["Leave"]);
                        agv.TaskSend = rtn ? "Leave" : "";
                    }

                }
                else if (SendFullShelfStep.IsTimeOut(15000, out double timeOutValue))
                {
                    SendFullShelfStep.ToNextStep(SEND_FULL_SHELF_STEP.WAIT_AGV_REACH_LINE);
                    runInfo= "AGV到达 " + FullShelfPlace + ",15秒后重新向产线发送入料架请求[ReadyEnter]";
                    msg += runInfo;
                    SendFullShelfStep.Msg = msg;
                }
            }
            else if (SendFullShelfStep.IsStep(SEND_FULL_SHELF_STEP.WAIT__SHELF_IN_LINE))
            {
                if (Common.CheckEnterOrLeaveFinished(agv, "Leave", agv.CurTaskGUID))
                {
                    runInfo= "满料架进入" + FullShelfPlace + "完成 [" + RFID + "]";
                    msg += runInfo;
                    SendFullShelfStep.Msg = msg;
                    agv.RFID = "";
                    AGVManager.UpdateStatus(RFID, FullShelfPlace);
                    return new EmptyAGVBackJob(FullShelfPlace);
                }
                else if (SendFullShelfStep.IsTimeOut(60000, out double timeOutValue))
                {
                    //链条停止
                    runInfo= "满料架在[" + FullShelfPlace + "]离开小车超时[" + timeOutValue.ToString("f1") + "秒],请检查料架离开小车的情况";
                    msg += runInfo;
                    SendFullShelfStep.Msg = msg;
                }

            }
            //else if (SendFullShelfStep.IsStep(SEND_FULL_SHELF_STEP.END))
            //{

            //}

            return this;
        }

    }
    /// <summary>
    /// AGV送满料架到产线
    /// </summary>
    public enum SEND_FULL_SHELF_STEP
    {
        /// <summary>
        /// 料架已进入小车,去目的地
        /// </summary>
        NONE,
        /// <summary>
        /// 等待AGV到达门
        /// </summary>
        WAIT_AGV_REACH_DOOR,
        /// <summary>
        /// 等待小车到达目的地
        /// </summary>
        WAIT_AGV_REACH_LINE,
        /// <summary>
        /// 等待大料架解绑
        /// </summary>
        WAIT_BIG_SHELF_UNLOCK,
        /// <summary>
        /// 等待AGV载大料架返回双层线
        /// </summary>
        WAIT_BIG_SHELF_BACK_DOUBLE_LINE,
        /// <summary>
        /// 等待AGV到达停车位
        /// </summary>
        WAIT_BIG_SHELF_BACK_STANDYBY,
        /// <summary>
        /// 等待产线回应
        /// </summary>
        WAIT_LINE_RESPONSE,
        /// <summary>
        /// 等待料架进入产线
        /// </summary>
        WAIT__SHELF_IN_LINE,

        /// <summary>
        /// 进入产线完成
        /// </summary>
        END
    }
}