GoWarehouseForOutStoreJob.cs 8.5 KB
using Common;
using DeviceLibrary.bean;
using DeviceLibrary.manager;
using System;

namespace DeviceLibrary
{
    /// <summary>
    /// 去立库接出库的治具
    /// </summary>
    public class GoWarehouseForOutStoreJob : Job
    {
        /// <summary>
        /// 去云仓接满料
        /// </summary>
        public GoWarehouseForOutStoreJob(JobParam jobParam) : base(jobParam)
        {
            JobName = "出库任务";
        }

        bool IsLoadOnAGV = false;
        public override Job Run(Agv_Info agv)
        {

            if (JobRunStep.IsStep(RunStep.NONE))
            {
                JobRunStep.ToNextStep(RunStep.ADJUST_WIDTH);
                runInfo = "准备去" + JobParam.TargetNode + ",先调宽";
                JobRunStep.Msg = runInfo;
                AdjustWidth(agv, JobParam.FixMissionInfo.Type);
            }
            else if (JobRunStep.IsStep(RunStep.ADJUST_WIDTH))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.WAIT_CHECK_RESULT);
                    runInfo = "检查AGV负载情况";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, SettingString.CheckShelf);
                }
            }
            else if (JobRunStep.IsStep(RunStep.WAIT_CHECK_RESULT))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    if (agv.IsExistShelf)
                    {
                        JobRunStep.ToNextStep(RunStep.END);
                        runInfo = "车上有负载,无法运行出库任务";
                        JobRunStep.Msg = runInfo;
                        IsLoadOnAGV = true;
                    }
                    else if (!agv.IsExistShelf)
                    {
                        if (JobParam.SrcNode.Area.Equals(Area.D))
                        {
                            JobRunStep.ToNextStep(RunStep.WAIT_AGV_REACH_A6);
                            runInfo = $"车上无负载,准备去{JobParam.TargetNode.Name}接料";
                            JobRunStep.Msg = runInfo;
                            AllocateTask(agv, JobParam.TargetNode.Name);
                        }
                        else if (JobParam.SrcNode.Area.Equals(Area.Air_C))
                        {
                            JobRunStep.ToNextStep(RunStep.WAIT_AGV_REACH_AIR_DOOR);
                            runInfo = "去接料,先过风淋门";
                            JobRunStep.Msg = runInfo;
                            AllocateTask(agv, SettingString.DoorAirOut);
                        }
                        else if (JobParam.SrcNode.Area.Equals(Area.C))//4C车间
                        {
                            JobRunStep.ToNextStep(RunStep.WAIT_AGV_REACH_DOOR);
                            runInfo = "先过门,再接料";
                            JobRunStep.Msg = runInfo;
                            AllocateTask(agv, SettingString.DoorCToD);
                        }
                        else
                        {
                            JobRunStep.ToNextStep(RunStep.WAIT_AGV_REACH_A6);
                            runInfo = $"车上无负载,准备去{JobParam.TargetNode.Name}接料";
                            JobRunStep.Msg = runInfo;
                            AllocateTask(agv, JobParam.TargetNode.Name);
                        }
                    }

                }

            }
            else if (JobRunStep.IsStep(RunStep.WAIT_AGV_REACH_AIR_DOOR))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.WAIT_AGV_REACH_DOOR);
                    runInfo = $"去{JobParam.TargetNode.Name},先过门";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, SettingString.DoorCToD);
                }

            }
            else if (JobRunStep.IsStep(RunStep.WAIT_AGV_REACH_DOOR))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.WAIT_AGV_REACH_A6);
                    runInfo = $"去{JobParam.TargetNode.Name}接料";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, JobParam.TargetNode.Name);
                }

            }
            else if (JobRunStep.IsStep(RunStep.WAIT_AGV_REACH_A6))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    WarehouseSigManager.TargetWithFix.CurPlace = JobParam.TargetNode.Name;
                    JobRunStep.ToNextStep(RunStep.WAIT_DOUBLE_LINE_RESPONSE);
                    runInfo = "到达 " + JobParam.TargetNode.Name + ",并发送出库请求";
                    JobRunStep.Msg = runInfo;
                    OpManager.ServerToClient.ReadyLeave(JobParam.TargetNode.Name, JobParam.Shelf == null ? "" : JobParam.Shelf.RFID);

                }
            }
            else if (JobRunStep.IsStep(RunStep.WAIT_DOUBLE_LINE_RESPONSE))
            {
                if (WarehouseSigManager.MayLeave)
                {
                    agv.HasError = false;
                    JobRunStep.ToNextStep(RunStep.WAIT__FULL_SHELF_IN_AGV);
                    runInfo = "收到出库请求的响应," + JobParam.TargetNode.Name + "出治具";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, SettingString.Enter);
                    WarehouseSigManager.MayLeave = false;
                }
                else if (OpManager.Info.GetTransfer(out string target))
                {
                    if (target.Equals(SettingString.Cancel))
                    {
                        agv.HasError = false;
                        runInfo = $"收到离开信号,出库任务取消";
                        JobRunStep.Msg = runInfo;
                        JobRunStep.EndJob();
                        return null;
                    }
                }
                else if (JobRunStep.IsTimeOut(15, out TimeSpan timeOutValue))
                {
                    //JobRunStep.ToNextStep(RunStep.WAIT_AGV_REACH_A6);
                    agv.HasError = true;
                    agv.SetErrorMsg($"{JobParam.TargetNode.Name}回复出料请求超时", timeOutValue.TotalMinutes.ToString("f2"));
                }


            }
            else if (JobRunStep.IsStep(RunStep.WAIT__FULL_SHELF_IN_AGV))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    agv.HasError = false;
                    JobRunStep.ToNextStep(RunStep.WAIT_LEAVE_SIG);
                    runInfo = JobParam.TargetNode.Name + "治具进入小车完成";
                    JobRunStep.Msg = runInfo;
                    //JobRunStep.EndJob();
                    // return new SendFixToLineJob(new JobParam(JobParam.TargetNode.ToCopy()),true);
                }
                else if (JobRunStep.IsTimeOut(120, out TimeSpan timeOutValue))
                {
                    //链条停止
                    runInfo = "治具在[" + JobParam.TargetNode.Name + "]进入小车超时";
                    //msg +=runInfo;
                    //GoFullShelfStationStep.Msg = msg;
                    agv.HasError = true;
                    agv.SetErrorMsg("治具在[" + JobParam.TargetNode.Name + "]进入小车超时", timeOutValue.TotalMinutes.ToString("f2"));
                }

            }
            else if (JobRunStep.IsStep(RunStep.WAIT_LEAVE_SIG))
            {
                if (OpManager.Info.GetTransfer(out string target))
                {
                    if (!target.Equals(SettingString.Cancel))
                    {
                        agv.HasError = false;
                        runInfo = $"收到离开信号,开始运送出库治具到" + target;
                        JobRunStep.Msg = runInfo;
                        JobRunStep.EndJob();
                        return new SendFixToLineJob(new JobParam(JobParam.TargetNode, NodeManager.GetNodeByName(target)), true);
                    }
                    else
                    {
                        agv.HasError = true;
                        agv.SetErrorMsg("有出库任务,但返回目的地为Cancel", (DateTime.Now - StartJobTime).TotalMinutes.ToString("f2"));
                    }
                }
            }
            else if (JobRunStep.IsStep(RunStep.END))
            {
                JobRunStep.EndJob();
                return null;
            }
            return this;
        }

    }
}