DoubleLineNodeFor4C.cs 3.5 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGVControl
{
    /// <summary>
    /// 双层线有料料架出口
    /// </summary>
    public class DoubleLineNodeFor4C : ClientNode
    {
        public DoubleLineNodeFor4C(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 - emptyJobCnt).Equals(2))//保留2辆小车出满料架
            {
                return null;
            }
            //出工单料的目的地是否有空料架
            if (Common.FindEmptyShelfBeforeSendFullShelf(out string nodeName))
            {
                if (nodeName.StartsWith(SettingString.C4_Name_Prefix) && 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 (agv.CurJob is GoEmptyShelfLineJob)
                        {
                            if (((GoEmptyShelfLineJob)agv.CurJob).EmptyShelfPlace.Equals(nodeName))
                                cnt++;
                        }
                    }
                    if (cnt < clientNode.EmptyShelfCnt)
                    {
                        return new GoEmptyShelfLineJob(currentAgv.Place, nodeName);
                    }
                }

            }

            //回收空料架
            if (Common.FindEmptyShelfNode(currentAgv, out string emptyNodeName))
            {
                if (SettingString.C4_AGV_IPs.Contains(currentAgv.IP))
                {
                    int i = Common.agvInfo.FindIndex(s => s.CurJob is GoEmptyShelfLineJob && ((GoEmptyShelfLineJob)s.CurJob).EmptyShelfPlace.Equals(emptyNodeName));
                    if (i == -1)
                        return new GoEmptyShelfLineJob(currentAgv.Place, emptyNodeName);
                }
            }

            //出满料
            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 new GoFullShelfStationJob(currentAgv.Place);
                }
            }

            return null;
        }
    }
}