GoFullShelfStationJob.cs 14.0 KB
using Common;
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;
        }

        /// <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}]:{2}", CurTaskID, CurTaskState, runInfo); }
        }

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

        public HttpManager.BoxDestInfo FullShelfDestInfo = null;

        private JobStep<GO_FULL_SHELF_STATION_STEP> jobStep = 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);
            //bool rtn = false;
            if (jobStep.IsStep(GO_FULL_SHELF_STATION_STEP.NONE))
            {
                jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_CHECK_RESULT);
                runInfo = "检查AGV负载情况";
                msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                jobStep.Msg = msg;
                MissionSys.AssignMission(agv, SettingString.CheckShelf);
                UpdateJobTaskInfo(agv.CurTarName, agv.CurTaskID);
            }
            else if (jobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_CHECK_RESULT))
            {
                CurTaskState = MissionSys.GetTakJobState(CurTaskID);
                if (MissionSys.CheckTaskFinished(agv, SettingString.CheckShelf, CurTaskState))
                {
                    if (agv.IsExistShelf)
                    {
                        jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.END);
                        runInfo = "车上有料架,无法去入料口出料";
                        msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                        jobStep.Msg = msg;
                        IsLoadOnAGV = true;
                    }
                    else if (!agv.IsExistShelf)
                    {
                        if (agvPlace.Equals("") || agvPlace.Equals(SettingString.Standby) || agvPlace.StartsWith(SettingString.AutoCharge))//待机位/充电位接到任务
                        {
                            jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                            runInfo = "无负载,准备运动到入料口" + FullShelfStationPlace;
                            msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                            jobStep.Msg = msg;
                            MissionSys.AssignMission(agv, FullShelfStationPlace);
                            UpdateJobTaskInfo(agv.CurTarName, agv.CurTaskID);
                        }
                        else if (AGVManager.CheckIsInAirDoor(agvPlace))
                        {
                            jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_AIR_DOOR);
                            runInfo = "在风淋门内,先过风淋门";
                            msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                            jobStep.Msg = msg;
                            MissionSys.AssignMission(agv, SettingString.DoorAirOut);
                            UpdateJobTaskInfo(agv.CurTarName, agv.CurTaskID);
                        }
                        else if (agvPlace.StartsWith(SettingString.RoomC_Name_Prefix))//4C车间
                        {
                            jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_DOOR);
                            runInfo = string.Format("在{0}车间,向{1}门运行,再到双层线入料口", SettingString.RoomC_Name, SettingString.RoomD_Name);
                            msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                            jobStep.Msg = msg;
                            MissionSys.AssignMission(agv, SettingString.DoorCToD);
                            UpdateJobTaskInfo(agv.CurTarName, agv.CurTaskID);
                        }
                        else
                        {
                            jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                            runInfo = "无负载,准备运动到入料口" + FullShelfStationPlace;
                            msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                            jobStep.Msg = msg;
                            MissionSys.AssignMission(agv, FullShelfStationPlace);
                            UpdateJobTaskInfo(agv.CurTarName, agv.CurTaskID);
                        }
                    }

                }

            }
            else if (jobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_AIR_DOOR))
            {
                CurTaskState = MissionSys.GetTakJobState(CurTaskID);
                if (MissionSys.CheckTaskFinished(agv, SettingString.DoorAirOut, CurTaskState))
                {
                    jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_DOOR);
                    runInfo = string.Format("过风淋门,向{0}门运行,再到双层线入料口{1}", SettingString.RoomD_Name,FullShelfStationPlace);
                    msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                    jobStep.Msg = msg;
                    MissionSys.AssignMission(agv, SettingString.DoorCToD);
                    UpdateJobTaskInfo(agv.CurTarName, agv.CurTaskID);
                }

            }
            else if (jobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_DOOR))
            {
                CurTaskState = MissionSys.GetTakJobState(CurTaskID);
                if (MissionSys.CheckTaskFinished(agv, SettingString.DoorCToD, CurTaskState))
                {
                    jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                    runInfo = string.Format("到达{0}门,准备运动到双层线入料口{1}", SettingString.RoomD_Name, FullShelfStationPlace);
                    msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                    jobStep.Msg = msg;
                    MissionSys.AssignMission(agv, FullShelfStationPlace);
                    UpdateJobTaskInfo(agv.CurTarName, agv.CurTaskID);
                }

            }
            else if (jobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6))
            {
                CurTaskState = MissionSys.GetTakJobState(CurTaskID);
                if (MissionSys.CheckTaskFinished(agv, FullShelfStationPlace, CurTaskState))
                {
                    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))
                        {
                            jobStep.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}", jobStep.CurStep(), runInfo);
                            jobStep.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}", jobStep.CurStep(), runInfo); ;
                                jobStep.Msg = msg;
                            }
                            else
                            {
                                //[{"msg":"0料车已解绑或未发新料"}]
                                jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_REACH_STANDBY);
                                runInfo = "从产线" + agvPlace + "回到待机位";
                                msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                                jobStep.Msg = msg;
                                MissionSys.AssignMission(agv, SettingString.Standby);
                                UpdateJobTaskInfo(agv.CurTarName, agv.CurTaskID);
                            }
                        }
                    }


                }
            }
            else if (jobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT_REACH_STANDBY))
            {
                CurTaskState = MissionSys.GetTakJobState(CurTaskID);
                if (MissionSys.CheckTaskFinished(agv, SettingString.Standby, CurTaskState))
                {
                    jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.END);
                    runInfo = "到达待机位";
                    msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                    jobStep.Msg = msg;
                }
            }
            else if (jobStep.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}", jobStep.CurStep(), runInfo);
                    jobStep.Msg = msg;
                    return this;
                }
                ClientNode node = AGVManager.nodeInfo[id];
                if (node.StateEquals(eNodeStatus.MayLeave))
                {
                    if (!agv.CurTarName.Equals("Enter"))
                    {
                        jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT__FULL_SHELF_IN_AGV);
                        runInfo = "收到双层线出料架请求[ReadyLeave]的响应 " + FullShelfStationPlace + "出料架,小车链条运行";
                        msg += string.Format("[{0}] {1}", jobStep.CurStep(), runInfo);
                        jobStep.Msg = msg;
                        MissionSys.AssignMission(agv,SettingString.Enter);
                        UpdateJobTaskInfo(agv.CurTarName, agv.CurTaskID);
                    }

                }
                else if (jobStep.IsTimeOut(15000, out double timeOutValue))
                {
                    jobStep.ToNextStep(GO_FULL_SHELF_STATION_STEP.WAIT_AGV_REACH_A6);
                }


            }
            else if (jobStep.IsStep(GO_FULL_SHELF_STATION_STEP.WAIT__FULL_SHELF_IN_AGV))
            {
                CurTaskState = MissionSys.GetTakJobState(CurTaskID);
                if (MissionSys.CheckTaskFinished(agv, SettingString.Enter, CurTaskState))
                {

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

            }

            return this;
        }

    }
    /// <summary>
    /// 出满料步骤
    /// </summary>
    public enum GO_FULL_SHELF_STATION_STEP
    {
        /// <summary>
        /// 负载检查
        /// </summary>
        NONE,
        /// <summary>
        /// 负载检查结果
        /// </summary>
        WAIT_CHECK_RESULT,
        /// <summary>
        /// 等待到达4C风淋门
        /// </summary>
        WAIT_AGV_REACH_AIR_DOOR,
        /// <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
    }
}