DoubleLineNodeFor4D.cs 3.7 KB
using log4net.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGVControl
{
    /// <summary>
    /// 
    /// </summary>
    public class DoubleLineNodeFor4D : ClientNode
    {
        public DoubleLineNodeFor4D(string name, string ip, string aliceName, string lineName, string pos_name, string pos_guid, bool isUse, int emptyCnt) : base(name, ip, aliceName, lineName, pos_name, pos_guid, isUse, emptyCnt)
        {

        }

        /// <summary>
        /// 双层线任务
        /// </summary>
        /// <param name="currentAgv"></param>
        /// <returns></returns>
        public override Job GetNewJob(Agv_Info currentAgv)
        {
            if (SettingString.C4_AGV_IPs.Contains(currentAgv.IP))
                return null;
            if (!Common.CheckCanExecuteMission(currentAgv))
                return null;
            if (!Common.CheckAGVStatusNone(currentAgv))
                return null;
            //执行空料架任务的小车数量
            int emptyJobCnt = 0;
            foreach (Agv_Info agv in Common.agvInfo)
            {
                if (SettingString.C4_AGV_IPs.Contains(agv.IP))
                    continue;
                if (agv.CurJob is GoEmptyShelfLineJob || agv.CurJob is EmptyShelfBackJob)
                {
                    emptyJobCnt++;
                }
            }
            if ((SettingString.AGVCNT / 2 - emptyJobCnt).Equals(1))//保留一辆小车出满料架
            {
                return null;
            }
            //出工单料的目的地是否有空料架
            if (Common.FindEmptyShelfBeforeSendFullShelf(out string nodeName))
            {
                if (nodeName.StartsWith("E") &&  !SettingString.C4_AGV_IPs.Contains(currentAgv.IP))
                {
                    ClientNode clientNode = Common.nodeInfo.Find(s => s.Name.Equals(nodeName));
                    int cnt = 0;
                    foreach (Agv_Info agv in Common.agvInfo)
                    {
                        if (SettingString.C4_AGV_IPs.Contains(agv.IP))
                            continue;
                        if (agv.CurJob is GoEmptyShelfLineJob)
                        {
                            if (((GoEmptyShelfLineJob)agv.CurJob).EmptyShelfPlace.Equals(nodeName))
                                cnt++;
                        }
                    }
                    if (cnt < clientNode.EmptyShelfCnt)
                    {
                        return new GoEmptyShelfLineJob(currentAgv.Place, nodeName);
                    }
                }

            }
            //出满料
            if (Common.FindFullShelfTask(currentAgv))
            {
                if (!SettingString.C4_AGV_IPs.Contains(currentAgv.IP))
                {
                    int i = Common.agvInfo.FindIndex(s=>s.CurJob is GoFullShelfStationJob && !s.IP.Equals(currentAgv.IP));
                    if(i>-1)
                        return null;
                }

                return new GoFullShelfStationJob(currentAgv.Place);
            }

            //回收空料架
            if (Common.FindEmptyShelfNode(currentAgv, out string emptyNodeName))
            {
                foreach (Agv_Info agv in Common.agvInfo)
                {
                    if (SettingString.C4_AGV_IPs.Contains(agv.IP))
                        continue;
                    if (agv.CurJob is GoEmptyShelfLineJob && ((GoEmptyShelfLineJob)agv.CurJob).EmptyShelfPlace.Equals(emptyNodeName))
                    {
                        return null;
                    }
                }
                return new GoEmptyShelfLineJob(currentAgv.Place, emptyNodeName);
            }
            return null;
        }
    }
}