StoreToLinesWithBackJob.cs 7.5 KB
using Common;
using DeviceLibrary.manager;

namespace DeviceLibrary.bean.job
{
    /// <summary>
    /// 库房到线体,(空架返回)
    /// </summary>
    public class StoreToLinesWithBackJob : Job
    {
        /// <summary>
        /// 库房分发料任务
        /// </summary>
        public StoreToLinesWithBackJob(JobParam jobParam) : base(jobParam)
        {
        }
        lift.LiftStatus liftStatus;
        public override Job Run(AgvInfo agv)
        {
            if (JobRunStep.IsStep(RunStep.NONE))
            {
                JobRunStep.ToNextStep(RunStep.SD_StoreToLine_01_ToPickUpPosition);
                runInfo = $"任务开始,去{JobParam.SrcNode.AliceName}的取料点";
                JobRunStep.Msg = runInfo;
                //任务状态变更
                MissionManager.SetMissionState(JobParam.GetMissionInfo().missionId, service.model.MissionState.接料, out string msg);
                AllocateTask(agv, $"{JobParam.SrcNode.Name}_{SettingString.PutShelfOn}");
            }
            else if (JobRunStep.IsStep(RunStep.SD_StoreToLine_01_ToPickUpPosition))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.SD_StoreToLine_02_PutShelfOn);
                    runInfo = $"到达{JobParam.SrcNode.AliceName}的取料点,准备拾取料车";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, $"{SettingString.PutShelfOn}");
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_StoreToLine_02_PutShelfOn))
            {
                JobRunStep.ToNextStep(RunStep.SD_StoreToLine_03_ToLine);
                runInfo = $"在{JobParam.SrcNode.AliceName}拾取料车完成,去{JobParam.CurTargetNode.AliceName}的放料点";
                JobRunStep.Msg = runInfo;
                //任务状态变更
                MissionManager.SetMissionState(JobParam.GetMissionInfo().missionId, service.model.MissionState.送料, out string msg);
                AllocateTask(agv,$"{JobParam.CurTargetNode.Name}_{SettingString.TakeShelfOff}");
            }
            else if (JobRunStep.IsStep(RunStep.SD_StoreToLine_03_ToLine))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    //确认按钮生效
                    JobParam.CurTargetNode.ExtendEquip.AllowConfirm();

                    JobRunStep.ToNextStep(RunStep.SD_StoreToLine_04_UpdateLocation);
                    runInfo = $"到达{JobParam.CurTargetNode.AliceName}的放料点,上报位置给ITS";
                    JobRunStep.Msg = runInfo;
                    //上报位置
                    manager.UploadManager.UploadPosition(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                        service.model.TransportStatus.TypeStr.status,agv.Name,agv.Place.Name,service.model.TransportStatus.ModeStr.auto,
                        $"到达{ JobParam.CurTargetNode.Name }"));
                    System.Threading.Thread.Sleep(2000);
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_StoreToLine_04_UpdateLocation))
            {
                JobRunStep.ToNextStep(RunStep.SD_StoreToLine_05_WaitConfirm);
                runInfo = $"等待{JobParam.CurTargetNode.AliceName}的人员确认";
                JobRunStep.Msg = runInfo;
                manager.UploadManager.UploadPosition(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                service.model.TransportStatus.TypeStr.status, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.agvButton,
                 $"等待{ JobParam.CurTargetNode.Name }确认"));
                System.Threading.Thread.Sleep(2000);
            }
            else if (JobRunStep.IsStep(RunStep.SD_StoreToLine_05_WaitConfirm))
            {
                if (OpManager.WaitConfirm.Line(JobParam.CurTargetNode))
                {
                    //关闭按钮确认
                    JobParam.CurTargetNode.ExtendEquip.Reset();
                    JobRunStep.ToNextStep(RunStep.SD_LiftToLine_10_CheckNextLine);
                    runInfo = $"{JobParam.CurTargetNode.AliceName}的人员确认完成";
                    JobRunStep.Msg = runInfo;
                }
                else if (JobRunStep.IsTimeOut(WaitTimeOut, out double timeoutval))
                {
                    //报警,$"等待{JobParam.CurTargetNode.AliceName}的人员确认超时{timeoutval}分"
                    manager.UploadManager.UploadPosition(new service.model.TransportStatus(agv.CurJob.JobParam.GetMissionInfo().missionId,
                   service.model.TransportStatus.TypeStr.error, agv.Name, agv.Place.Name, service.model.TransportStatus.ModeStr.agvButton,
                    $"等待{ JobParam.CurTargetNode.Name }确认超时{timeoutval}分"));
                    System.Threading.Thread.Sleep(2000);
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_StoreToLine_06_CheckNextLine))
            {
                if (JobParam.TargetNodes.Count > 0)
                {
                    JobRunStep.ToNextStep(RunStep.SD_StoreToLine_03_ToLine);
                    JobParam.CurTargetNode = JobParam.TargetNodes[0];
                    JobParam.TargetNodes.RemoveAt(0);
                    System.Threading.Thread.Sleep(1000);
                    runInfo = $"去下一线体{JobParam.CurTargetNode.AliceName}的放料点";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, $"{JobParam.CurTargetNode.Name}_{SettingString.TakeShelfOff}");
                }
                else
                {
                    JobRunStep.ToNextStep(RunStep.SD_StoreToLine_07_BackToPickUpPosition);
                    runInfo = $"{JobParam.CurTargetNode.AliceName}是最后一个线体,分发结束,返回{JobParam.SrcNode.Name}的放料点";
                    JobRunStep.Msg = runInfo;
                    //任务状态变更
                    MissionManager.SetMissionState(JobParam.GetMissionInfo().missionId, service.model.MissionState.返回起始地, out string msg);
                    AllocateTask(agv, $"{JobParam.SrcNode.Name}_{SettingString.TakeShelfOff}");
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_StoreToLine_07_BackToPickUpPosition))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.SD_StoreToLine_08_TakeShelfOff);
                    runInfo = $"到达{JobParam.SrcNode.AliceName}的放料点,准备卸下料车";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, SettingString.TakeShelfOff);
                }
            }
            else if (JobRunStep.IsStep(RunStep.SD_StoreToLine_08_TakeShelfOff))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.END);
                    runInfo = $"料车在{JobParam.SrcNode.AliceName}放下完成,任务结束";
                    //任务状态变更
                    MissionManager.SetMissionState(JobParam.GetMissionInfo().missionId, service.model.MissionState.完成, out string msg);
                    JobRunStep.Msg = runInfo;
                }
            }
            else if (JobRunStep.IsStep(RunStep.END))
            {
                JobRunStep.EndJob();
                return null;
            }
            return this;
        }
    }
}