GoFullShelfStationJob.cs 10.2 KB

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

namespace AGVControl
{
    /// <summary>
    /// 检查AGV是否有负载,去A6入料口并装车
    /// </summary>
    public class GoFullShelfStationJob : Job
    {
        /// <summary>
        /// 去A6入料口任务并检查AGV是否有负载
        /// </summary>
        /// <param name="agvCurPlace">接到任务时,AGV的位置(空表示待机位)</param>
        /// <param name="palce"></param>
        public GoFullShelfStationJob(string agvCurPlace = "", string palce = "A6")
        {
            FullShelfStationPlace = palce;
            agvPlace = agvCurPlace;
        }

        /// <summary>
        /// 出满料位置点
        /// </summary>
        public string FullShelfStationPlace { get; set; }

        /// <summary>
        /// 运行信息
        /// </summary>
        public string RunInfo { get; set; }
        /// <summary>
        /// 接到任务时,AGV的位置
        /// </summary>
        public string agvPlace { get; set; }
        public override bool IsEnd { get { return GoFullShelfStationStep.IsStep(GO_FULL_SHELF_STATION_STEP.END); } }
        /// <summary>
        /// AGV上是否有负载
        /// </summary>
        public bool IsLoadOnAGV { get; private set; } = false;

        public AGVManager.BoxDestInfo FullShelfDestInfo = null;

        private JobStep<GO_FULL_SHELF_STATION_STEP> GoFullShelfStationStep = new JobStep<GO_FULL_SHELF_STATION_STEP>(GO_FULL_SHELF_STATION_STEP.NONE);

        public override Job Execute(Agv_Info agv)
        {
            string msg = "";
            bool rtn = false;
            if (GoFullShelfStationStep.IsStep(GO_FULL_SHELF_STATION_STEP.NONE))
            {
                GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_CHECK_RESULT);
                msg = agv.Name + " 检查AGV负载情况";
                GoFullShelfStationStep.Msg = msg;
                Common.CheckLoad(agv);
            }
            else if (GoFullShelfStationStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_CHECK_RESULT))
            {
                if (GoFullShelfStationStep.IsTimeOut(15000, out double timeOutValue))
                {
                    Common.mir.Get_IO_Status(agv, out bool[] input, out bool[] output);
                    if (!input.Equals(null) && input[3])
                    {
                        GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.END);
                        msg = agv.Name + " 车上有料架,无法去入料口出料";
                        GoFullShelfStationStep.Msg = msg;
                        agv.IsExistShelf = true;
                        IsLoadOnAGV = true;
                    }
                    else if (!input.Equals(null) && !input[3])
                    {
                        if (agvPlace.Equals(""))//待机位接到任务
                        {
                            GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                            msg = agv.Name + " 无负载,准备运动到入料口";
                            GoFullShelfStationStep.Msg = msg;
                            Common.MoveToNode(agv, FullShelfStationPlace);
                        }
                        else if (agvPlace.StartsWith("G"))//4C车间
                        {
                            GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_DOOR);
                            msg = agv.Name + " 在4C车间,向4D门运行,再到双层线入料口";
                            GoFullShelfStationStep.Msg = msg;
                            Common.DoorMission(agv, SettingString.MoveDoorCToD);
                        }
                    }
                }

            }
            else if (GoFullShelfStationStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_DOOR))
            {
                if (agv.Place.Equals(SettingString.D4_DOOR_Name) && agv.PlaceState.Equals(ePlaceState.MoveFinish))
                {
                    GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                    msg = agv.Name + " 到达4D门,准备运动到双层线入料口";
                    GoFullShelfStationStep.Msg = msg;
                    Common.MoveToNode(agv, FullShelfStationPlace);
                }

            }
            else if (GoFullShelfStationStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6))
            {
                if (agv.Place.Equals(FullShelfStationPlace) && agv.PlaceState.Equals(ePlaceState.MoveFinish))
                {
                    ClientNode node = Common.nodeInfo.Find(s => s.Name.Equals(SettingString.A6)
                    && (s.StateEquals(eNodeStatus.NeedEnterLeave) || s.StateEquals(eNodeStatus.NeedEnterLeave)) && !s.RFID.Equals("00"));
                    if (node.Name.Equals(SettingString.A6))
                    {
                        if (AGVManager.FindFullShelfTarget(node.RFID, out FullShelfDestInfo))
                        {
                            GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_DOUBLE_LINE_RESPONSE);
                            msg = "AGV到达 " + FullShelfStationPlace + ",并发送出料架请求[ReadyLeave]";
                            GoFullShelfStationStep.Msg = msg;
                            Common.server.ReadyLeave(FullShelfStationPlace);
                        }
                        else
                        {
                            if (!FullShelfDestInfo.Equals(null))
                            {
                                msg = "AGV到达 " + FullShelfStationPlace + ",查询满料架目的地:" + FullShelfDestInfo.ShowInfo();
                                GoFullShelfStationStep.Msg = msg;
                            }
                            else
                            {
                                //[{"msg":"0料车已解绑或未发新料"}]
                                GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_REACH_STANDBY);
                                msg = "从产线" + agvPlace + "回到待机位";
                                GoFullShelfStationStep.Msg = msg;
                                Common.MoveToNode(agv, SettingString.MoveStandby);
                            }
                        }
                    }


                }
            }
            else if (GoFullShelfStationStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_REACH_STANDBY))
            {
                if (agv.Place.StartsWith(SettingString.Standby_Name_Prefix) && agv.PlaceState.Equals(ePlaceState.MoveFinish))
                {
                    GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.END);
                    msg = "到达待机位";
                    GoFullShelfStationStep.Msg = msg;
                }
            }
            else if (GoFullShelfStationStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_DOUBLE_LINE_RESPONSE))
            {
                int id = Common.FindNode(FullShelfStationPlace);
                ClientNode node = Common.nodeInfo[id];
                if (node.StateEquals(eNodeStatus.MayLeave))
                {
                    GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT__FULL_SHELF_IN_AGV);
                    msg = "收到双层线出料架请求[ReadyLeave]的响应 " + FullShelfStationPlace + "出料架,小车链条运行";
                    GoFullShelfStationStep.Msg = msg;
                    rtn = Common.mir.Add_Mission_Fleet(agv, Common.agvMission["Enter"]);
                    agv.TaskSend = rtn ? "Enter" : "";
                }
                else if (GoFullShelfStationStep.IsTimeOut(15000, out double timeOutValue))
                {
                    GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                    msg = "AGV到达 " + FullShelfStationPlace + ",15秒后重新向双层线发送出料架请求[ReadyLeave]";
                    GoFullShelfStationStep.Msg = msg;
                }


            }
            else if (GoFullShelfStationStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT__FULL_SHELF_IN_AGV))
            {
                if (agv.Place.Equals(FullShelfStationPlace) && agv.PlaceState.Equals(ePlaceState.EnterFinish))
                {

                    //GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.END);
                    msg = FullShelfStationPlace + "满料架进入小车完成";
                    GoFullShelfStationStep.Msg = msg;
                    if (FullShelfDestInfo.location.StartsWith("G"))
                    {
                        return new SendFullShelfToLineJob(FullShelfDestInfo, true);
                    }
                    else
                        return new SendFullShelfToLineJob(FullShelfDestInfo);
                }
                else if (GoFullShelfStationStep.IsTimeOut(60000, out double timeOutValue))
                {
                    //链条停止
                    msg = "满料架在[" + FullShelfStationPlace + "]进入小车超时[" + timeOutValue.ToString("f1") + "秒],请检查料架进入小车的情况";
                    GoFullShelfStationStep.Msg = msg;
                }

            }
            RunInfo = GoFullShelfStationStep.Msg;
            return this;
        }

    }
    /// <summary>
    /// 出满料步骤
    /// </summary>
    public enum GO_FULL_SHELF_STATION_STEP
    {
        /// <summary>
        /// 负载检查
        /// </summary>
        NONE,
        /// <summary>
        /// 负载检查结果
        /// </summary>
        WAIT_CHECK_RESULT,
        /// <summary>
        /// 等待AGV到达门
        /// </summary>
        WAIT_AGV_REACH_DOOR,
        /// <summary>
        /// 等待到达A6
        /// </summary>
        WAIT_AGV_REACH_A6,
        /// <summary>
        /// 等待双层线回应
        /// </summary>
        WAIT_DOUBLE_LINE_RESPONSE,
        /// <summary>
        /// 等待料架进入小车
        /// </summary>
        WAIT__FULL_SHELF_IN_AGV,
        /// <summary>
        /// 等待AGV到达待机位
        /// </summary>
        WAIT_REACH_STANDBY,
        /// <summary>
        /// 送上双层线
        /// </summary>
        END
    }
}