GoFullShelfStationJob.cs 14.3 KB
using Common;
using System;

namespace DeviceLibrary
{
    /// <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 = SettingString.Standby, string palce = SettingString.A6)
        {
            FullShelfStationPlace = palce;
            agvPlace = agvCurPlace;
            JobName = "接满料任务";
        }

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

        /// <summary>
        /// 接到任务时,AGV的位置
        /// </summary>
        public string agvPlace { get; set; }
        private string runInfo = "";
        /// <summary>
        /// 运行信息
        /// </summary>
        public override string RunInfo
        {
            get { return string.Format("接满料任务[{0}]:{1}", CurTaskID, runInfo); }
        }

        /// <summary>
        /// AGV上是否有负载
        /// </summary>
        public bool IsLoadOnAGV { get; private set; } = false;

        public HttpManager.BoxDestInfo FullShelfDestInfo = null;

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

        public override Job Execute(Agv_Info agv)
        {
            string msg = string.Format("{0} 接满料任务: ", agv.Name);
            StartJobTime = curJobStep.startTime;
            //bool rtn = false;
            if (curJobStep.IsStep(GO_FULL_SHELF_STATION_STEP.NONE))
            {
                curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_CHECK_RESULT);
                runInfo = "检查AGV负载情况";
                msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                curJobStep.Msg = msg;
                MissionSys.AssignMission(agv, SettingString.CheckShelf);
                 UpdateJobTaskInfo(agv);
            }
            else if (curJobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_CHECK_RESULT))
            {
                CurTaskState = MissionSys.GetTakJobState(agv);
                if (MissionSys.CheckTaskFinished(agv, SettingString.CheckShelf, CurTaskState))
                {
                    RecordRunLog(agv, curJobStep.CurStep(), runInfo, agv.Place);
                    if (agv.IsExistShelf)
                    {
                        curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.END);
                        runInfo = "车上有料架,无法去入料口出料";
                        msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                        curJobStep.Msg = msg;
                        IsLoadOnAGV = true;
                    }
                    else if (!agv.IsExistShelf)
                    {
                        if (agvPlace.Equals("") || agvPlace.Equals(SettingString.Standby) || agvPlace.StartsWith(SettingString.AutoCharge))//待机位/充电位接到任务
                        {
                            curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                            runInfo = "无负载,准备运动到入料口" + FullShelfStationPlace;
                            msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                            curJobStep.Msg = msg;
                            MissionSys.AssignMission(agv, FullShelfStationPlace);
                             UpdateJobTaskInfo(agv);
                        }
                        else if (AGVManager.CheckIsInAirDoor(agvPlace))
                        {
                            curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.OUT_AIR_DOOR_1);
                            runInfo = "去风淋门停留点";
                            msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                            curJobStep.Msg = msg;
                            MissionSys.AssignMission(agv, $"{SettingString.DoorAirOut}-1");
                            UpdateJobTaskInfo(agv);
                        }
                        else
                        {
                            curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                            runInfo = "无负载,准备运动到入料口" + FullShelfStationPlace;
                            msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                            curJobStep.Msg = msg;
                            MissionSys.AssignMission(agv, FullShelfStationPlace);
                             UpdateJobTaskInfo(agv);
                        }
                    }

                }

            }
            else if (curJobStep.IsStep(GO_FULL_SHELF_STATION_STEP.OUT_AIR_DOOR_2))
            {
                CurTaskState = MissionSys.GetTakJobState(agv);
                if (MissionSys.CheckTaskFinished(agv, $"{SettingString.DoorAirOut}-2", CurTaskState))
                {
                    RecordRunLog(agv, curJobStep.CurStep(), runInfo, agv.Place);
                    curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.OUT_AIR_DOOR_3);
                    runInfo = string.Format("{0}进入风淋门,准备出{1}风淋门", agv.Place, SettingString.RoomD_Name);
                    msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                    curJobStep.Msg = msg;
                    MissionSys.AssignMission(agv, $"{SettingString.DoorAirOut}-3");
                    UpdateJobTaskInfo(agv);
                }
            }
            else if (curJobStep.IsStep(GO_FULL_SHELF_STATION_STEP.OUT_AIR_DOOR_3))
            {
                CurTaskState = MissionSys.GetTakJobState(agv);
                if (MissionSys.CheckTaskFinished(agv, $"{SettingString.DoorAirOut}-3", CurTaskState))
                {
                    RecordRunLog(agv, curJobStep.CurStep(), runInfo, agv.Place);
                    curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                    runInfo = string.Format("到达{0}门,准备运动到双层线入料口{1}", SettingString.RoomD_Name, FullShelfStationPlace);
                    msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                    curJobStep.Msg = msg;
                    MissionSys.AssignMission(agv, FullShelfStationPlace);
                    UpdateJobTaskInfo(agv);
                }
            }
            else if (curJobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6))
            {
                CurTaskState = MissionSys.GetTakJobState(agv);
                if (MissionSys.CheckTaskFinished(agv, FullShelfStationPlace, CurTaskState))
                {
                    RecordRunLog(agv, curJobStep.CurStep(), runInfo, agv.Place);
                    ClientNode node = AGVManager.nodeInfo.Find(s => s.Name.Equals(SettingString.A6)
                    && (s.StateEquals(eNodeStatus.NeedLeave) || s.StateEquals(eNodeStatus.NeedEnterLeave)) && !s.RFID.StartsWith("0"));
                    if (node != null && node.Name.Equals(SettingString.A6))
                    {
                        if (HttpManager.FindFullShelfTarget(node.RFID, out FullShelfDestInfo))
                        {
                            curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_DOUBLE_LINE_RESPONSE);
                            if (FullShelfDestInfo != null)
                            {
                                AGVManager.GetLineNameByNodeName(FullShelfDestInfo.location, out string line);
                                agv.BoxDestInfo = FullShelfDestInfo.ShowInfo(line);
                            }
                            runInfo = "AGV到达 " + FullShelfStationPlace + ",并发送出料架请求[ReadyLeave]";
                            msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                            curJobStep.Msg = msg;
                            AGVManager.server.ReadyLeave(FullShelfStationPlace);
                        }
                        else
                        {
                            if (FullShelfDestInfo != null)
                            {
                                AGVManager.GetLineNameByNodeName(FullShelfDestInfo.location, out string line);
                                runInfo = "AGV到达 " + FullShelfStationPlace + ",查询满料架目的地:" + FullShelfDestInfo.ShowInfo(line);
                                msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo); ;
                                curJobStep.Msg = msg;
                            }
                            else
                            {
                                //[{"msg":"0料车已解绑或未发新料"}]
                                curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_REACH_STANDBY);
                                runInfo = "从产线" + agvPlace + "回到待机位";
                                msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                                curJobStep.Msg = msg;
                                MissionSys.AssignMission(agv, SettingString.Standby);
                                 UpdateJobTaskInfo(agv);
                            }
                        }
                    }


                }
            }
            else if (curJobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_REACH_STANDBY))
            {
                CurTaskState = MissionSys.GetTakJobState(agv);
                if (MissionSys.CheckTaskFinished(agv, SettingString.Standby, CurTaskState))
                {
                    RecordRunLog(agv, curJobStep.CurStep(), runInfo, agv.Place);
                    curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.END);
                    runInfo = "到达待机位";
                    msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                    curJobStep.Msg = msg;
                }
            }
            else if (curJobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_DOUBLE_LINE_RESPONSE))
            {
                int id = AGVManager.FindNode(FullShelfStationPlace);
                if (id == -1)
                {
                    runInfo = "未找到节点:" + FullShelfStationPlace;
                    msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                    curJobStep.Msg = msg;
                    return this;
                }
                ClientNode node = AGVManager.nodeInfo[id];
                if (node.StateEquals(eNodeStatus.MayLeave))
                {
                    agv.HasError = false;
                    if (!agv.CurTarName.Equals("Enter"))
                    {
                        RecordRunLog(agv, curJobStep.CurStep(), runInfo, agv.Place);
                        curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT__FULL_SHELF_IN_AGV);
                        runInfo = "收到双层线出料架请求[ReadyLeave]的响应 " + FullShelfStationPlace + "出料架,小车链条运行";
                        msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                        curJobStep.Msg = msg;
                        MissionSys.AssignMission(agv,SettingString.Enter);
                         UpdateJobTaskInfo(agv);
                    }

                }
                else if (curJobStep.IsTimeOut(15000, out TimeSpan timeOutValue))
                {
                    curJobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                    agv.HasError = true;
                    agv.SetErrorMsg($"{FullShelfStationPlace}回复出料请求超时", timeOutValue.TotalMinutes.ToString("f2"));
                }


            }
            else if (curJobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT__FULL_SHELF_IN_AGV))
            {
                CurTaskState = MissionSys.GetTakJobState(agv);
                if (MissionSys.CheckTaskFinished(agv, SettingString.Enter, CurTaskState))
                {
                    RecordRunLog(agv, curJobStep.CurStep(), runInfo, agv.Place);
                    agv.HasError = false;
                    //GoFullShelfStationStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.END);
                    runInfo = FullShelfStationPlace + "满料架进入小车完成";
                    msg += string.Format("[{0}] {1}", curJobStep.CurStep(), runInfo);
                    curJobStep.Msg = msg;
                    RecordRunLog(agv, curJobStep.CurStep(), runInfo, agv.Place);
                    return new SendFullShelfToLineJob(FullShelfDestInfo);
                }
                else if (curJobStep.IsTimeOut(60000, out TimeSpan timeOutValue))
                {
                    //链条停止
                    runInfo = "满料架在[" + FullShelfStationPlace + "]进入小车超时,请检查料架进入小车的情况";
                    //msg +=runInfo;
                    //GoFullShelfStationStep.Msg = msg;
                    agv.HasError = true;
                    agv.SetErrorMsg("满料架在[" + FullShelfStationPlace + "]进入小车超时", timeOutValue.TotalMinutes.ToString("f2"));
                }

            }
            return this;
        }

    }
    /// <summary>
    /// 出满料步骤
    /// </summary>
    public enum GO_FULL_SHELF_STATION_STEP
    {
        /// <summary>
        /// 负载检查
        /// </summary>
        NONE,
        /// <summary>
        /// 负载检查结果
        /// </summary>
        WAIT_CHECK_RESULT,
        /// <summary>
        /// 去出3D风淋门等待位
        /// </summary>
        OUT_AIR_DOOR_1,
        /// <summary>
        /// 进风淋门
        /// </summary>
        OUT_AIR_DOOR_2,
        /// <summary>
        /// 出风淋门
        /// </summary>
        OUT_AIR_DOOR_3,
        /// <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
    }
}