From 8abc9481eafeb715b39a4f4f8d6f628a642e6b53 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期三, 19 三月 2025 17:38:18 +0800 Subject: [PATCH] 优化AGV和输送线、产线对接逻辑 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs | 190 ++++++++++++++++++++++++++++++---------------- 1 files changed, 123 insertions(+), 67 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" index 1d8ea5d..20a859b 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" @@ -15,7 +15,6 @@ using System.Threading.Tasks; using WIDESEAWCS_Common.StackerCraneEnum; using WIDESEAWCS_Common.TaskEnum; -using WIDESEAWCS_Common.WMSInfo; using WIDESEAWCS_Core; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_IShuttleCar; @@ -31,12 +30,11 @@ using WIDESEAWCS_TaskInfoService; using WIDESEAWCS_Tasks.ConveyorLineJob; using WIDESEAWCS_Tasks.StackerCraneJob; -using static WIDESEAWCS_Common.WMSInfo.RequestWMS; namespace WIDESEAWCS_Tasks { [DisallowConcurrentExecution] - public partial class CommonStackerCraneJob : IJob + public partial class CommonStackerCraneJob : JobBase, IJob { private readonly ITaskService _taskService; private readonly ITaskExecuteDetailService _taskExecuteDetailService; @@ -60,45 +58,84 @@ SpeStackerCrane commonStackerCrane = (SpeStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); if (commonStackerCrane != null) { + commonStackerCrane.Communicator.IsReadAfterWrite = false; #region 淇″彿浜や簰澶勭悊 - Heartbeat(commonStackerCrane); + //Heartbeat(commonStackerCrane); ShuttleCarSignal(commonStackerCrane); #endregion - #region 浠诲姟閫昏緫澶勭悊 - if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.Onlinestate) == (short)Onlinestate.online - && commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WriteStatus) == (short)WriteStatus.Permit) + #region 浠诲姟瀹屾垚 + DeviceProtocolDetailDTO? deviceProtocolDetail = commonStackerCrane.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.CompleteStatus).ToString() && x.DeviceProParamName == nameof(StackerCraneTaskCommandR.CompleteStatus)); + if (deviceProtocolDetail != null) { - #region 浠诲姟瀹屾垚 - DeviceProtocolDetailDTO? deviceProtocolDetail = commonStackerCrane.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.CompleteStatus).ToString() && x.DeviceProParamName == nameof(StackerCraneTaskCommandR.CompleteStatus)); - if (deviceProtocolDetail != null) - { - MethodInfo? method = GetType().GetMethod(deviceProtocolDetail.ProtocolDetailType); - if (method != null) method.Invoke(this, new object[] { commonStackerCrane }); - } - #endregion - + MethodInfo? method = GetType().GetMethod(deviceProtocolDetail.ProtocolDetailType); + if (method != null) method.Invoke(this, new object[] { commonStackerCrane }); + } + #endregion + #region 浠诲姟閫昏緫澶勭悊 + var onlinestate = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.Onlinestate); + var writeStatus = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WriteStatus); + if (onlinestate == (short)Onlinestate.online /*&& writeStatus == (short)WriteStatus.Permit*/) + { #region 鏌ヨ浠诲姟,閫昏緫澶勭悊 if (Enum.Parse<RunStatus>(commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.RunStatus).ToString()) == RunStatus.Standby) { var Task = _taskService.GetTaskState(TaskType: (int)TaskOtherTypeEnum.RelocationCar);//鑾峰彇绉昏溅浠诲姟 + var Task1 = _taskService.GetTaskState((int)CarChargingTaskEnum.ShuttleCar_Finish, (int)TaskOtherTypeEnum.RelocationCarCharging);//鑾峰彇绉昏溅鍏呯數浠诲姟 if (Task != null) { if (Task.TaskState == (int)TaskCarStatusEnum.ShuttleCar_Finish) SendTask(commonStackerCrane, Task); } + else if (Task1 != null) + { + SendTask(commonStackerCrane, Task1); + } else { - Dt_Task? task = GetTask(commonStackerCrane);//鑾峰彇鍫嗗灈鏈哄嚭鍏ュ簱浠诲姟 + Dt_Task? task = GetTask(commonStackerCrane);//鑾峰彇鍫嗗灈鏈轰换鍔� if (task != null) { - if (task.TaskType == (int)TaskInboundTypeEnum.Inbound) + if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation)//绉诲簱浠诲姟鍒ゆ柇缁堢偣鏄惁鏈夌┛姊溅 { - var ShuttleCar = GetShuttleCarInfo(task.TargetAddress);//鍏ュ簱浠诲姟鍒ゆ柇鏄惁瀛樺湪绌挎杞� - if (task.IsPickPlace && ShuttleCar != null)//绉昏蛋 + if (task.SourceIsPickPlace && task.TaskState == (int)TaskRelocationStatusEnum.RelocationNew) + SendTask(commonStackerCrane, task);//涓嬪彂鍫嗗灈鏈轰换鍔� + else if (!task.SourceIsPickPlace && task.TaskState == (int)TaskRelocationStatusEnum.RelocationNew) + { + var ShuttleCar = GetShuttleCarInfo(task.SourceAddress);//绉诲簱浠诲姟鍒ゆ柇璧风偣鏄惁鏈夌┛姊溅 + if (ShuttleCar != null) + { + task.ShuttleCarCode = ShuttleCar.ShuttleCarCode; + _taskService.UpdateData(task); + } + else _taskService.AddRelocationCarTask("", task.SourceAddress); + } + else if (!task.TargetIsPickPlace && task.TaskState == (int)TaskRelocationStatusEnum.CarSource_Finish) + { + var ShuttleCar = GetShuttleCarInfo(task.TargetAddress);//绉诲簱浠诲姟鍒ゆ柇缁堢偣鏄惁鏈夌┛姊溅 + if (task.TargetIsPickPlace && ShuttleCar != null)//绉昏蛋 + { + _taskService.AddRelocationCarTask(task.TargetAddress, "", ShuttleCar.ShuttleCarCode); + } + else if (!task.TargetIsPickPlace && ShuttleCar == null) + { + _taskService.AddRelocationCarTask("", task.TargetAddress); + } + else + { + task.ShuttleCarCode = ShuttleCar?.ShuttleCarCode; + _taskService.UpdateData(task); + SendTask(commonStackerCrane, task);//涓嬪彂鍫嗗灈鏈轰换鍔� + } + } + } + else if (_taskService.TaskInboundTypes.Contains(task.TaskType)) + { + var ShuttleCar = GetShuttleCarInfo(task.TargetAddress);//鍏ュ簱浠诲姟鍒ゆ柇缁堢偣鏄惁鏈夌┛姊溅 + if (task.TargetIsPickPlace && ShuttleCar != null)//绉昏蛋 { _taskService.AddRelocationCarTask(task.TargetAddress, "", ShuttleCar.ShuttleCarCode); } - else if (!task.IsPickPlace && ShuttleCar == null) + else if (!task.TargetIsPickPlace && ShuttleCar == null) { _taskService.AddRelocationCarTask("", task.TargetAddress); } @@ -109,6 +146,8 @@ SendTask(commonStackerCrane, task);//涓嬪彂鍫嗗灈鏈轰换鍔� } } + else + SendTask(commonStackerCrane, task);//涓嬪彂鍫嗗灈鏈轰换鍔� } } @@ -120,7 +159,7 @@ } catch (Exception ex) { - Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString()); + //Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString()); } return Task.CompletedTask; } @@ -132,7 +171,7 @@ if (stackerCraneTaskCommand != null) { bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand); - bool worktype = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, task.TaskType == (int)TaskOtherTypeEnum.RelocationCar ? (short)WorkType.Car : (short)WorkType.Cargo); + bool worktype = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, task.TaskType >= (int)TaskOtherTypeEnum.RelocationCar ? (short)WorkType.Car : (short)WorkType.Cargo); if (sendFlag && worktype) { if (commonStackerCrane.SetValue(StackerCraneDBName.CommandSend, sendFlag)) @@ -171,9 +210,8 @@ { if (commonStackerCrane != null) { - Console.Out.WriteLine($"鍫嗗灈鏈轰换鍔″畬鎴愶細[{commonStackerCrane.CurrentTaskNum}]锛泏DateTime.Now}"); - var Status = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum).Status;///闇�淇敼锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒 - commonStackerCrane.SetValue(StackerCraneDBName.ConfirmComplete, Status); + _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum); + commonStackerCrane.SetValue(StackerCraneDBName.ConfirmComplete, true); } } /// <summary> @@ -183,52 +221,61 @@ /// <returns></returns> private Dt_Task? GetTask(SpeStackerCrane commonStackerCrane) { - Dt_Task task; - if (commonStackerCrane.LastTaskType == null) - { - task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode); - } + Dt_Task task = _taskService.QueryStackerCraneRelocationTask(commonStackerCrane.DeviceCode);//鑾峰彇绉诲簱浠诲姟 + #region 瀛樺湪绉诲簱浠诲姟蹇呴』鍏堟墽琛岀Щ搴撲换鍔� + if (task != null) return task; + #endregion + + #region 鍑哄叆搴撲换鍔� else { - if (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) + if (commonStackerCrane.LastTaskType == null) { - task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); - if (task == null) - { - task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode); - } + task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode); } else { - task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode); - if (task == null) + if (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) { + task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode) ?? _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode); + if (task == null) + { + task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode); + } + } + else + { + task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode); + if (task == null) + { + task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); + } + } + } + + if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) + { + if (OutTaskStationIsOccupied(task) != null) + { + return task; + } + else + { + List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress).Select(x => x.ChildPosi).ToList(); + List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes); + foreach (var item in tasks) + { + if (OutTaskStationIsOccupied(item) != null) + { + return item; + } + } task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); } } + if (task != null && !string.IsNullOrEmpty(task.TargetAddress)) return task;//鍏ュ簱浠诲姟鍒ゆ柇鏄惁宸插垎閰嶈揣浣嶏紝WMS鍒ゆ柇璐т綅鐘舵�佹槸鍚﹀厑璁告斁璐� } - - if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) - { - if (OutTaskStationIsOccupied(task) != null) - { - return task; - } - else - { - List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress).Select(x => x.ChildPosi).ToList(); - List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes); - foreach (var item in tasks) - { - if (OutTaskStationIsOccupied(item) != null) - { - return item; - } - } - task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); - } - } - if (task != null && !string.IsNullOrEmpty(task.TargetAddress)) return task;//鍏ュ簱浠诲姟鍒ゆ柇鏄惁宸插垎閰嶈揣浣嶏紝WMS鍒ゆ柇璐т綅鐘舵�佹槸鍚﹀厑璁告斁璐� + #endregion return task; } @@ -246,10 +293,15 @@ if (device != null) { CommonConveyorLine conveyorLine = (CommonConveyorLine)device; - if (conveyorLine.IsOccupied(router.ChildPosi))//鍑哄簱绔欏彴鏈鍗犵敤 + ConveyorLineTaskCommandR command = conveyorLine.ReadCustomer<ConveyorLineTaskCommandR>(router.ChildPosi); + if (command.Status == 4) { return task; } + //if (conveyorLine.IsOccupied(router.ChildPosi))//鍑哄簱绔欏彴鏈鍗犵敤 + //{ + // return task; + //} } else { @@ -286,7 +338,8 @@ string[] targetCodes = task.NextAddress.Split("-"); if (targetCodes.Length == 3) { - stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]); + var EndRow = Convert.ToInt16(targetCodes[0]); + stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow > 1 ? EndRow - 1 : EndRow); stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); } @@ -315,7 +368,8 @@ string[] sourceCodes = task.CurrentAddress.Split("-"); if (sourceCodes.Length == 3) { - stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]); + var StartRow = Convert.ToInt16(sourceCodes[0]); + stackerCraneTaskCommand.StartRow = Convert.ToInt16(StartRow > 1 ? StartRow - 1 : StartRow); stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]); stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]); } @@ -332,12 +386,13 @@ return null; } } - else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) + else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup || task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OtherGroup) { string[] targetCodes = task.NextAddress.Split("-"); if (targetCodes.Length == 3) { - stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]); + var EndRow = Convert.ToInt16(targetCodes[0]); + stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow > 1 ? EndRow - 1 : EndRow); stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); } @@ -350,7 +405,8 @@ string[] sourceCodes = task.CurrentAddress.Split("-"); if (sourceCodes.Length == 3) { - stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]); + var SourceRow = Convert.ToInt16(sourceCodes[0]); + stackerCraneTaskCommand.StartRow = Convert.ToInt16(SourceRow > 1 ? SourceRow - 1 : SourceRow); stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]); stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]); } -- Gitblit v1.9.3