From 30b171ac56aa5676c31811363d4472b4edc820e7 Mon Sep 17 00:00:00 2001 From: SoulStar Date: Wed, 8 Jan 2025 21:08:05 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E5=BD=92=E7=B1=BB=20=E7=B1=BB?= =?UTF-8?q?=E5=92=8C=E6=96=B9=E6=B3=95=20-=20=E6=B7=BB=E5=8A=A0=20enum=20?= =?UTF-8?q?=E6=8A=8A=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81=E5=92=8Cagv?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E9=83=BD=E6=94=B9=E4=B8=BA=20enum=20-=20?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E9=83=A8=E5=88=86AppConfg=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Business/base/BaseAGVBusiness.cs | 117 ++++++++++++----- SlnMesnac.Business/base/BaseBusiness.cs | 106 --------------- .../base/BaseStateRefreshBusiness.cs | 17 +-- .../base/BaseTaskInfoBusiness.cs | 92 +++++++------ SlnMesnac.Business/base/InOutControl.cs | 31 +++++ SlnMesnac.Business/base/VisionBusiness.cs | 44 ++++--- SlnMesnac.Business/util/Enums.cs | 121 ++++++++++++++++++ .../service/IAGVJobService.cs | 5 +- .../service/IAGVSettingService.cs | 8 +- .../service/Impl/AGVJobServiceImpl.cs | 21 ++- .../service/Impl/AGVSettingServiceImpl.cs | 31 ++++- .../service/Impl/VisionSettingServiceImpl.cs | 37 ++++-- SlnMesnac.TouchSocket/TcpServer.cs | 47 ------- .../Page/ControlPage/UserTaskControl.xaml | 15 +-- .../IndexPage/IndexContentViewModel.cs | 5 +- .../ViewModel/MainWindowViewModel.cs | 90 ++----------- 16 files changed, 420 insertions(+), 367 deletions(-) delete mode 100644 SlnMesnac.Business/base/BaseBusiness.cs create mode 100644 SlnMesnac.Business/base/InOutControl.cs create mode 100644 SlnMesnac.Business/util/Enums.cs diff --git a/SlnMesnac.Business/base/BaseAGVBusiness.cs b/SlnMesnac.Business/base/BaseAGVBusiness.cs index d1a74fc..acfce19 100644 --- a/SlnMesnac.Business/base/BaseAGVBusiness.cs +++ b/SlnMesnac.Business/base/BaseAGVBusiness.cs @@ -26,30 +26,38 @@ namespace SlnMesnac.Business.@base private AirPorthttpClient _airPorthttpClient; private IAGVStateService _AGVStateService; private IAGVMapPointService _AGVMapPointService; + private IAGVJobService _AGVJobService; + private IAGVSettingService _AGVSettingService; - - public BaseAGVBusiness(ILogger logger, - AirPorthttpClient airPorthttpClient, - IAGVStateService AGVStateService, - IAGVMapPointService aGVMapPointService, - AppConfig appConfig) + public BaseAGVBusiness(ILogger logger, + AirPorthttpClient airPorthttpClient, + IAGVStateService AGVStateService, + IAGVMapPointService aGVMapPointService, + AppConfig appConfig, + IAGVJobService aGVJobService, + IAGVSettingService aGVSettingService) { _logger = logger; _airPorthttpClient = airPorthttpClient; _AGVStateService = AGVStateService; _AGVMapPointService = aGVMapPointService; _appConfig = appConfig; + _AGVJobService = aGVJobService; + _AGVSettingService = aGVSettingService; } - public static BaseAGVBusiness GetInstance(ILogger logger, - AirPorthttpClient airPorthttpClient, - IAGVStateService AGVStateService, - IAGVMapPointService aGVMapPointService, - AppConfig appConfig) + public static BaseAGVBusiness GetInstance(ILogger logger, + AirPorthttpClient airPorthttpClient, + IAGVStateService AGVStateService, + IAGVMapPointService aGVMapPointService, + AppConfig appConfig, + IAGVJobService aGVJobService, + IAGVSettingService aGVSettingService + ) { if (instance == null) { - instance = new BaseAGVBusiness(logger, airPorthttpClient, AGVStateService, aGVMapPointService, appConfig); + instance = new BaseAGVBusiness(logger, airPorthttpClient, AGVStateService, aGVMapPointService, appConfig, aGVJobService, aGVSettingService); } return instance; } @@ -78,22 +86,22 @@ namespace SlnMesnac.Business.@base verifyStatus = 0, enableSplitCar = 0, load = new List() + { + new LoadsEntity() + { + jobid = JobGUID, + location = PointGUID, + param = new List() + { + new ParamEntity() { - new LoadsEntity() - { - jobid = JobGUID, - location = PointGUID, - param = new List() - { - new ParamEntity() - { - paramname = ParamName, - paramvalue = PointGUID, - } - }, - robotPort = "" - } - }, + paramname = ParamName, + paramvalue = PointGUID, + } + }, + robotPort = "" + } + }, }; return aGVRequestAddTaskEntity; } @@ -238,16 +246,16 @@ namespace SlnMesnac.Business.@base /// /// /// 新任务GUID - public string EndTaskAndClearErrorAndDownloadTask(string agvguid, string jobName) + public string EndTaskAndClearErrorAndDownloadTask(string agvguid, string jobGuid) { bool result = false; try { //终止小车当前任务 - result = EndTaskAndClearError(agvguid); - var param = _appConfig.JobConfig.Where(x => x.JobName == jobName).First(); + result = EndTaskAndClearError(agvguid);//////////////////////////////////////////////////////////////////还没改完/////////////////////////////////////////////////////////////// + var param = _appConfig.JobConfig.Where(x => x.JobGUID == jobGuid).First(); //调用小车到抓取位置 - return DownloadTask(agvguid, param.JobGUID, param.PointGUID, param.PointParamName); + return DownloadTask(agvguid, jobGuid, param.PointGUID, param.PointParamName); } catch (Exception ex) { @@ -289,7 +297,7 @@ namespace SlnMesnac.Business.@base { Task.Run(() => { - var response = _airPorthttpClient.AGVErrorClear(_appConfig.AGVConfig.Where(x => x.AGVGUID == agvguid).First().AGVIp); + var response = _airPorthttpClient.AGVErrorClear(_AGVSettingService.GetAgvSettingByAgvGuid(agvguid).AGVNo); Task.Delay(500); if (response == null) { @@ -297,7 +305,7 @@ namespace SlnMesnac.Business.@base result = false; return false; } - if(response.code == 0) + if (response.code == 0) { _logger.LogError("清除报警成功"); result = true; @@ -340,6 +348,7 @@ namespace SlnMesnac.Business.@base { if (min >= BaseTaskInfoBusiness.AMRStackNumber) { + _logger.LogInformation("无可用车辆!"); return null; } } @@ -347,6 +356,7 @@ namespace SlnMesnac.Business.@base { if (min >= BaseTaskInfoBusiness.DeliverStackNumber) { + _logger.LogInformation("无可用车辆!"); return null; } } @@ -354,12 +364,51 @@ namespace SlnMesnac.Business.@base //var list = _AGVStateService return agv; } - catch(Exception ex) + catch (Exception ex) { _logger.LogError($"AGV筛选发生错误:{ex.Message}"); return null; } } + + /// + /// 入库所有满载AGV + /// + public void ClearFullAGV() + { + try + { + var list = _AGVStateService.GetAgvState(AgvType.Deliver); + foreach (var record in list) + { + if (record.stackcount >= BaseTaskInfoBusiness.DeliverStackNumber && record.agvworkstate == "待机") + { + //入库代码 + EndTaskAndClearErrorAndDownloadTask(record.agvno, + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入库", "0").JobGuid); + _AGVStateService.ResetAGVStackCount(record.agvno); + _logger.LogInformation($"Deliver [{record.agvno}] 入库"); + } + } + list = _AGVStateService.GetAgvState(AgvType.AMR); + foreach (var record in list) + { + if (record.stackcount >= BaseTaskInfoBusiness.AMRStackNumber && record.agvworkstate == "待机") + { + //入库代码 + EndTaskAndClearErrorAndDownloadTask(record.agvno, + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("1000入库", "0").JobGuid); + _AGVStateService.ResetAGVStackCount(record.agvno); + _logger.LogInformation($"AMR [{record.agvno}] 入库"); + } + } + } + catch (Exception ex) + { + _logger.LogError($"清理满载AGV时发生错误!Error: [{ex.Message}]"); + } + } + } } diff --git a/SlnMesnac.Business/base/BaseBusiness.cs b/SlnMesnac.Business/base/BaseBusiness.cs deleted file mode 100644 index 644ff4d..0000000 --- a/SlnMesnac.Business/base/BaseBusiness.cs +++ /dev/null @@ -1,106 +0,0 @@ -using SlnMesnac.Plc; -using SlnMesnac.Rfid; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -#region << 版 本 注 释 >> -/*-------------------------------------------------------------------- -* 版权所有 (c) 2024 WenJY 保留所有权利。 -* CLR版本:4.0.30319.42000 -* 机器名称:LAPTOP-E0N2L34V -* 命名空间:SlnMesnac.Business.base -* 唯一标识:b00d95c1-a164-43a3-9f34-2a5d2efb3f34 -* -* 创建者:WenJY -* 电子邮箱:wenjy@mesnac.com -* 创建时间:2024-04-12 17:36:19 -* 版本:V1.0.0 -* 描述: -* -*-------------------------------------------------------------------- -* 修改人: -* 时间: -* 修改说明: -* -* 版本:V1.0.0 -*--------------------------------------------------------------------*/ -#endregion << 版 本 注 释 >> -namespace SlnMesnac.Business.@base -{ - internal class BaseBusiness - { - private readonly List _plcFactories; - - private readonly List _rfidFactories; - - public BaseBusiness(List plcFactories, List rfidFactories) - { - _plcFactories = plcFactories; - _rfidFactories = rfidFactories; - } - - /// - /// 根据Key获取PLC连接信息 - /// - /// - /// - /// - /// - public PlcAbsractFactory GetPlcByKey(string key) - { - if(_plcFactories == null) - { - throw new ArgumentNullException($"根据Key获取PLC连接信息异常:PLC 连接信息为空"); - } - - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("根据Key获取PLC连接信息异常:设备Key参数为空"); - } - - try - { - var info = _plcFactories.Where(x => x.ConfigKey == key).FirstOrDefault(); - - return info; - }catch(Exception ex) - { - throw new InvalidOperationException($"根据Key获取PLC连接信息异常:{ex.Message}"); - } - } - - - /// - /// 根据Key获取Rfid连接信息 - /// - /// - /// - /// - /// - public RfidAbsractFactory GetRfidByKey(string key) - { - if (_rfidFactories == null) - { - throw new ArgumentNullException($"根据Key获取RFID连接信息异常:PLC 连接信息为空"); - } - - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentNullException("根据Key获取RFID连接信息异常:设备Key参数为空"); - } - - try - { - var info = _rfidFactories.Where(x => x.ConfigKey == key).FirstOrDefault(); - - return info; - } - catch (Exception ex) - { - throw new InvalidOperationException($"根据Key获取RFID连接信息异常:{ex.Message}"); - } - } - } -} diff --git a/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs b/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs index 7c5c4b1..7654abb 100644 --- a/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs +++ b/SlnMesnac.Business/base/BaseStateRefreshBusiness.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using SlnMesnac.Business.util; using SlnMesnac.Model.AirportApiEntity; using SlnMesnac.Repository; using SlnMesnac.Repository.service; @@ -70,9 +71,12 @@ namespace SlnMesnac.Business.@base { _logger.LogError("AGV状态操作失败!" + ex.Message); } - } + /// + /// Timer刷新方法 + /// + /// public async Task TimerUpadteAGVState() { if (!await UpdateALLAGVStateByResposne()) @@ -121,7 +125,7 @@ namespace SlnMesnac.Business.@base { agvno = entity.Guid, agvalarmstate = entity.AgvMoveStatus != 6 ? "正常" : "异常", - agvtype = _aGVSettingService.GetAgvSettingByID(entity.Guid), + agvtype = _aGVSettingService.GetAgvTypeByAGVGuid(entity.Guid), agvworkstate = AGVStatusSelect(entity.AgvMoveStatus), refreshtime = DateTime.Now, taskno = entity.TaskID, @@ -184,13 +188,4 @@ namespace SlnMesnac.Business.@base } } } - - - - public enum TimerControl - { - Start = 1, - Stop = 2, - Dispose = 3 - } } diff --git a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs index c434925..95d0c74 100644 --- a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs +++ b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs @@ -16,6 +16,7 @@ using System.Threading; using SlnMesnac.TouchSocket.Entity; using SlnMesnac.Model.AirportApiEntity; using System.Linq; +using SlnMesnac.Business.util; namespace SlnMesnac.Business.@base { @@ -24,8 +25,16 @@ namespace SlnMesnac.Business.@base /// public class BaseTaskInfoBusiness { + /// + /// AMR最大运载量 + /// public const int AMRStackNumber = 10; + + /// + /// Deliver最大运载量 + /// public const int DeliverStackNumber = 15; + private TcpServer _tcpServer = null; public Action _Taskaction; public Action _RefreshLogMessageAction; @@ -35,7 +44,8 @@ namespace SlnMesnac.Business.@base private IAGVMapPointService _AGVMapPointService; private IAGVStateService _AGVStateService; private IAGVJobService _AGVJobService; - private AirPorthttpClient _airpttpClient; + private IVisionSettingService _AGVVisionSettingService; + private AirPorthttpClient _airPorthttpClient; private BaseAGVBusiness _baseAGVBusiness; private VisionBusiness _visionBusiness; System.Timers.Timer RefreshTimer; @@ -45,6 +55,7 @@ namespace SlnMesnac.Business.@base IAGVStateService agvService, IAGVMapPointService aGVMapPointService, IAGVJobService agvJobService, + IVisionSettingService aVisionSettingService, TcpServer tcpServer, AirPorthttpClient airPorthttpClient, BaseAGVBusiness baseAGVBusiness, @@ -54,19 +65,19 @@ namespace SlnMesnac.Business.@base _tcpServer = tcpServer; _Taskservice = Taskservice; _AGVStateService = agvService; - _airpttpClient = airPorthttpClient; + _airPorthttpClient = airPorthttpClient; //doWhileGetAGVTaskInfo(); _baseAGVBusiness = baseAGVBusiness; _AGVMapPointService = aGVMapPointService; _AGVJobService = agvJobService; - + _AGVVisionSettingService = aVisionSettingService; //新建Timer RefreshTimer = new System.Timers.Timer(1000); RefreshTimer.Elapsed += (sender, e) => { - //清理满载AGV 刷新状态 - ClearFullAGV(); + //不清理满载AGV 刷新状态 + //ClearFullAGV(); RefreshTaskState(); }; @@ -79,6 +90,7 @@ namespace SlnMesnac.Business.@base IAGVStateService agvService, IAGVMapPointService aGVMapPointService, IAGVJobService aAGVJobService, + IVisionSettingService aVisionSettingService, TcpServer tcpServer, AirPorthttpClient airPorthttpClient, BaseAGVBusiness baseAGVBusiness, @@ -87,14 +99,14 @@ namespace SlnMesnac.Business.@base if (instance == null) { instance = new BaseTaskInfoBusiness(logger, - Taskservice, agvService, aGVMapPointService, aAGVJobService, + Taskservice, agvService, aGVMapPointService, aAGVJobService, aVisionSettingService, tcpServer, airPorthttpClient, baseAGVBusiness, visionBusiness); } return instance; } /// - /// 从航班接口获取到新任务插入数据库 + /// 获取新任务插入数据库 /// /// public async Task NewTaskInfo(string taskNo, string conveyNo, string flightNo, int totalCount) @@ -127,7 +139,7 @@ namespace SlnMesnac.Business.@base } /// - /// AGV状态查询控制 + /// 任务刷新Timer控制 /// /// public void TaskStateUpdateTimerOperation(TimerControl state) @@ -157,7 +169,10 @@ namespace SlnMesnac.Business.@base } + #region 任务初次派车调度 + /// + /// AGV调度 /// Timer刷新任务状态, 有新任务初次下发AGV, Timer执行 /// public void RefreshTaskState() @@ -185,7 +200,7 @@ namespace SlnMesnac.Business.@base { string amrTaskId = _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask( firstAMR.agvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("1000入位", taskItem.conveyorno).JobName); + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("1000入位", taskItem.conveyorno).JobGuid); _logger.LogInformation($"为AMR[ {firstAMR.agvno}]分配任务,目标:[ {taskItem.conveyorno} ]号传送带"); taskItem.amragvno = firstAMR.agvno; taskItem.amragvisarrive = "未到达"; @@ -208,7 +223,7 @@ namespace SlnMesnac.Business.@base { string deliverTaskID = _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask( firstDeliver.agvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入位", taskItem.conveyorno).JobName); + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入位", taskItem.conveyorno).JobGuid); _logger.LogInformation($"为Deliver[ {firstDeliver.agvno} ]分配任务,目标:[ {taskItem.conveyorno} ]号传送带"); taskItem.deliveragvno = firstDeliver.agvno; taskItem.deliveragvisarrive = "未到达"; @@ -245,7 +260,7 @@ namespace SlnMesnac.Business.@base { string deliverTaskID = _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask( firstDeliver.agvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入位", taskItem.conveyorno).JobName); + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入位", taskItem.conveyorno).JobGuid); _logger.LogInformation($"为Deliver[ {firstDeliver.agvno} ]分配任务,目标:[ {taskItem.conveyorno} ]号传送带"); taskItem.deliveragvno = firstDeliver.agvno; taskItem.deliveragvisarrive = "未到达"; @@ -330,42 +345,39 @@ namespace SlnMesnac.Business.@base } } + #endregion + /// - /// 入库满载AGV + /// 停止所有任务 /// - public void ClearFullAGV() + public void StopAllTask() { - try + List taskList = _Taskservice.GetTaskInfos(x => x.taskstate == "抓取中" || x.taskstate == "派车中").ToList(); + //任务状态设置为已终止并且机械臂复位 + foreach (var taskInfo in taskList) { - var list = _AGVStateService.GetAgvState(AgvType.Deliver); - foreach (var record in list) - { - if (record.stackcount >= BaseTaskInfoBusiness.DeliverStackNumber && record.agvworkstate == "待机") - { - //入库代码 - _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(record.agvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入库", "0").JobName); - _AGVStateService.ResetAGVStackCount(record.agvno); - _logger.LogInformation($"Deliver [{record.agvno}] 入库"); - } - } - list = _AGVStateService.GetAgvState(AgvType.AMR); - foreach (var record in list) - { - if (record.stackcount >= BaseTaskInfoBusiness.AMRStackNumber && record.agvworkstate == "待机") - { - //入库代码 - _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(record.agvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("1000入库", "0").JobName); - _AGVStateService.ResetAGVStackCount(record.agvno); - _logger.LogInformation($"AMR [{record.agvno}] 入库"); - } - } + _visionBusiness.RequestVisionReplace(_AGVVisionSettingService.GetVisionSettingByAMRGUID(taskInfo.amragvno).VisionID); + taskInfo.finishtime = DateTime.Now; + taskInfo.taskstate = "已终止"; + _Taskservice.UpdateTaskAsync(taskInfo); + _logger.LogInformation($"任务 [{taskInfo.taskno}] 已终止"); } - catch (Exception ex) + //agv全部停止 + var responseList = _airPorthttpClient.AGVAllStateRequest(); + if (responseList == null || responseList.count == 0) + { + _logger.LogInformation($"连接失败或无小车连接"); + return; + } + foreach (var response in responseList.Data) { - _logger.LogError($"清理满载AGV时发生错误!Error: [{ex.Message}]"); + if (!string.IsNullOrEmpty(response.TaskID) && response.AgvMoveStatus != 1 && response.AgvMoveStatus != 3) + { + _baseAGVBusiness.EndTaskAndClearError(response.Guid); + _logger.LogInformation($"小车 [{response.Name}] 任务已终止"); + } } + _logger.LogInformation($"全部复位完毕"); } } } \ No newline at end of file diff --git a/SlnMesnac.Business/base/InOutControl.cs b/SlnMesnac.Business/base/InOutControl.cs new file mode 100644 index 0000000..475ce81 --- /dev/null +++ b/SlnMesnac.Business/base/InOutControl.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Logging; +using SlnMesnac.Config; +using SlnMesnac.Repository.service; +using SlnMesnac.TouchSocket; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Business.@base +{ + public class InOutControl + { + private ILogger _logger; + + private static InOutControl instance; + + public InOutControl(ILogger logger) + { + _logger = logger; + } + + public static InOutControl GetInstance(ILogger logger) + { + if (instance == null) + { + instance = new InOutControl(logger); + } + return instance; + } + } +} diff --git a/SlnMesnac.Business/base/VisionBusiness.cs b/SlnMesnac.Business/base/VisionBusiness.cs index 132854f..909d949 100644 --- a/SlnMesnac.Business/base/VisionBusiness.cs +++ b/SlnMesnac.Business/base/VisionBusiness.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using SlnMesnac.Business.util; using SlnMesnac.Model.domain; using SlnMesnac.Model.Enum; using SlnMesnac.Repository; @@ -208,18 +209,18 @@ namespace SlnMesnac.Business.@base //////////////////////////////////////////////////////上一次是AMR//////////////////////////////////////////////////// if (entity.DataBytes[1] == 0x00) { - //妹有Deliver的任务(小车号和是否已到达都没有)amr肯定能抓完 继续amr抓取 + //----妹有Deliver的任务(小车号和是否已到达都没有)amr肯定能抓完 继续amr抓取 if (string.IsNullOrEmpty(airportTask.deliveragvno) && string.IsNullOrEmpty(airportTask.deliveragvisarrive)) { //一直向amr抓,直到抓满 RequestVisionStartWork(StackState.NXAMRNoPositioning, AMRCount, id); _logger.LogInformation($"任务 [{airportTask.taskno}] 继续向AMR [{airportTask.amragvno}] 抓取"); } - //有Delievr任务(有任务号且状态为未到达)继续amr抓取 + //----有Delievr任务(有任务号且状态为未到达)继续amr抓取 else if (!string.IsNullOrEmpty(airportTask.deliveragvno) && airportTask.deliveragvisarrive == "未到达") { //判断AMR小车是否装满,没满就开装,满了就结束,开始循环判断deliver是否到达 - //amr没满 继续装amr + //----amr没满 继续装amr if (_aGVStateService.GetSingleAGVState(airportTask.amragvno).stackcount < BaseTaskInfoBusiness.AMRStackNumber) { RequestVisionStartWork(StackState.NXAMRNoPositioning, AMRCount, id); @@ -229,7 +230,7 @@ namespace SlnMesnac.Business.@base else { AirportTask task; - //结束抓取、循环判断deliver是否到达,到了就向新的Deliver开始抓取 + //---结束抓取、循环判断deliver是否到达,到了就向新的Deliver开始抓取 Task.Run(() => { //请求复位 @@ -250,13 +251,13 @@ namespace SlnMesnac.Business.@base }); } } - //有Deliver任务(有任务号且已到达)向Deliver发送开始抓取 + //----有Deliver任务(有任务号且已到达)向Deliver发送开始抓取 else if (!string.IsNullOrEmpty(airportTask.deliveragvno) && airportTask.deliveragvisarrive == "已到达") { RequestVisionStartWork(StackState.NXAGVNeedPositioning, DeliverCount, id); _logger.LogInformation($"任务 [{airportTask.taskno}] 向Deliver [{airportTask.deliveragvno}] 抓取"); } - //异常情况 + //----异常情况 else { throw new Exception($"任务 {airportTask.taskno} 状态异常!请清除任务并重新下发任务!"); @@ -267,38 +268,51 @@ namespace SlnMesnac.Business.@base else if (entity.DataBytes[1] == 0x01) { //判断Deliver是否装满,装满就直接入库,未装满继续装 - //deliver没满,继续装 + //----deliver没满,继续装 if (_aGVStateService.GetSingleAGVState(airportTask.deliveragvno).stackcount < BaseTaskInfoBusiness.DeliverStackNumber) { RequestVisionStartWork(StackState.NXAGVNoPositioning, DeliverCount, id); _logger.LogInformation($"任务 [{airportTask.taskno}] 继续向Deliver [{airportTask.deliveragvno}] 抓取"); } - //deliver满了,入库然后判断 + //----deliver满了,入库然后判断 else { //入库代码 _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(airportTask.deliveragvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入库", airportTask.conveyorno).JobName); + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入库", airportTask.conveyorno).JobGuid); _logger.LogInformation($"任务 [{airportTask.taskno}] Deliver [{airportTask.deliveragvno}] 入库"); _aGVStateService.ResetAGVStackCount(airportTask.deliveragvno); airportTask.deliveragvno = null; airportTask.deliveragvisarrive = null; _airportTaskService.UpdateTaskAsync(airportTask); //判断剩下的数量用不用调用新的deliver - //剩下的数量不用 直接向amr抓取 + //----剩下的数量不用 直接向amr抓取 int amrleft = BaseTaskInfoBusiness.AMRStackNumber - _aGVStateService.GetSingleAGVState(airportTask.amragvno).stackcount; if (airportTask.totalcount - airportTask.loadcount < amrleft) { RequestVisionStartWork(StackState.NXAMRNeedPositioning, AMRCount, id); _logger.LogInformation($"任务 [{airportTask.taskno}] 向AMR [{airportTask.amragvno}] 抓取"); } - //剩下的数量需要调用,并判断向AMR抓取 + //----剩下的数量需要调用,并判断向AMR抓取 else { + AGVState newagv = null; //调新的deliver - AGVState newagv = _baseAGVBusiness.GetBestAGV(AgvType.Deliver); + Task.Run(() => + { + do + { + newagv = _baseAGVBusiness.GetBestAGV(AgvType.Deliver); + if (newagv != null && !string.IsNullOrEmpty(newagv.agvno)) + { + break; + } + Task.Delay(1000); + } + while (true); + }); _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(newagv.agvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入位", airportTask.conveyorno).JobName); + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入位", airportTask.conveyorno).JobGuid); airportTask.deliveragvno = newagv.agvno; airportTask.deliveragvisarrive = "未到达"; _logger.LogInformation($"任务 [{airportTask.taskno}] 调用Deliver [{airportTask.deliveragvno}] 入位"); @@ -307,7 +321,7 @@ namespace SlnMesnac.Business.@base if (amrleft <= 0) { AirportTask task; - //结束抓取、循环判断deliver是否到达,到了就向新的Deliver开始抓取 + //----结束抓取、循环判断deliver是否到达,到了就向新的Deliver开始抓取 Task.Run(() => { //请求复位 @@ -327,7 +341,7 @@ namespace SlnMesnac.Business.@base } }); } - //amr有容量,抓 + //----amr有容量,抓 else { RequestVisionStartWork(StackState.NXAMRNeedPositioning, AMRCount, id); diff --git a/SlnMesnac.Business/util/Enums.cs b/SlnMesnac.Business/util/Enums.cs new file mode 100644 index 0000000..1dcd9b1 --- /dev/null +++ b/SlnMesnac.Business/util/Enums.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; + +namespace SlnMesnac.Business.util +{ + public enum AgvTaskState + { + /// + /// 等待中 + /// + [Description("等待中")] + Waiting = 0, + + /// + /// 派车中 + /// + [Description("派车中")] + Dispatching = 1, + + /// + /// 抓取中 + /// + [Description("抓取中")] + grabbing = 2, + + /// + /// 终止 + /// + [Description("终止")] + Stop = 9, + + /// + /// 结束 + /// + [Description("结束")] + End = 10, + + /// + /// 异常 + /// + [Description("异常")] + Error = 20, + } + + public enum TimerControl + { + /// + /// Timer启动 + /// + [Description("Timer启动")] + Start = 1, + + /// + /// Timer关闭 + /// + [Description("Timer关闭")] + Stop = 2, + + /// + /// Timer释放 + /// + [Description("Timer释放")] + Dispose = 3 + } + + /// + /// 请求视觉开始工作码垛信号 + /// + public enum StackState + { + /// + /// 复合机器人码垛无需定位位置在X负侧 + /// + [Description("复合机器人码垛无需定位位置在X负侧")] + NXAMRNoPositioning = 0x00, + + /// + /// 复合机器人码垛需要定位位置在X负侧 + /// + [Description("复合机器人码垛需要定位位置在X负侧")] + NXAMRNeedPositioning = 0x01, + + /// + /// 搬运机器人码垛无需定位位置在X负侧 + /// + [Description("搬运机器人码垛无需定位位置在X负侧")] + NXAGVNoPositioning = 0x02, + + /// + /// 搬运机器人码垛需要定位位置在X负侧 + /// + [Description("搬运机器人码垛需要定位位置在X负侧")] + NXAGVNeedPositioning = 0x03, + + /// + /// 复合机器人码垛无需定位位置在X正侧 + /// + [Description("复合机器人码垛无需定位位置在X正侧")] + PXAMRNoPositioning = 0x04, + + /// + /// 复合机器人码垛需要定位位置在X正侧 + /// + [Description("复合机器人码垛需要定位位置在X正侧")] + PXAMRNeedPositioning = 0x05, + + /// + /// 搬运机器人码垛无需定位位置在X正侧 + /// + [Description("搬运机器人码垛无需定位位置在X正侧")] + PXAGVNoPositioning = 0x06, + + /// + /// 搬运机器人码垛需要定位位置在X正侧 + /// + [Description("搬运机器人码垛需要定位位置在X正侧")] + PXAGVNeedPositioning = 0x07, + } +} diff --git a/SlnMesnac.Repository/service/IAGVJobService.cs b/SlnMesnac.Repository/service/IAGVJobService.cs index ea7b682..3c10ab7 100644 --- a/SlnMesnac.Repository/service/IAGVJobService.cs +++ b/SlnMesnac.Repository/service/IAGVJobService.cs @@ -14,6 +14,7 @@ namespace SlnMesnac.Repository.service /// List GetAGVJobList(); + /// /// 根据模板类型获取对应的AGV模板列表 /// @@ -24,8 +25,8 @@ namespace SlnMesnac.Repository.service /// /// 根据模板类型和传送带编号获取对应的AGV模板 /// - /// - /// + /// 任务类型 + /// 0就是通用模板 其他编号为对应传送带的调用模板 /// AGVJob GetAGVJobListByTypeAndConveyorNo(string jobType, string conveyorno); } diff --git a/SlnMesnac.Repository/service/IAGVSettingService.cs b/SlnMesnac.Repository/service/IAGVSettingService.cs index 22cd5fe..15d029b 100644 --- a/SlnMesnac.Repository/service/IAGVSettingService.cs +++ b/SlnMesnac.Repository/service/IAGVSettingService.cs @@ -16,12 +16,18 @@ namespace SlnMesnac.Repository.service /// List GetAllAgvSetting(); + /// + /// 根据AgvGuid获取单条AGV设置 + /// + /// + AGVSetting GetAgvSettingByAgvGuid(string guid); + /// /// 根据AGVID获取AGV类型 /// /// /// - string GetAgvSettingByID(string id); + string GetAgvTypeByAGVGuid(string guid); /// /// 插入AGV设置 diff --git a/SlnMesnac.Repository/service/Impl/AGVJobServiceImpl.cs b/SlnMesnac.Repository/service/Impl/AGVJobServiceImpl.cs index f7c4ec8..fd97676 100644 --- a/SlnMesnac.Repository/service/Impl/AGVJobServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/AGVJobServiceImpl.cs @@ -8,6 +8,9 @@ using System.Text; namespace SlnMesnac.Repository.service.Impl { + /// + /// AGV模板服务类 + /// public class AGVJobServiceImpl : BaseServiceImpl, IAGVJobService { private ILogger _logger; @@ -21,12 +24,16 @@ namespace SlnMesnac.Repository.service.Impl try { var list = _rep.GetList(); + if (list == null) + { + return new List(); + } return list; } catch (Exception ex) { _logger.LogError($"获取列表发生错误: {ex.Message}"); - return null; + return new List(); } } @@ -35,12 +42,16 @@ namespace SlnMesnac.Repository.service.Impl try { var list = _rep.GetList(x => x.JobType == jobType).ToList(); + if (list == null) + { + return new List(); + } return list; } catch (Exception ex) { _logger.LogError($"获取列表发生错误: {ex.Message}"); - return null; + return new List(); } } @@ -49,12 +60,16 @@ namespace SlnMesnac.Repository.service.Impl try { AGVJob record = _rep.GetList(x => x.ConveyorNo == conveyorno && x.JobType == jobType).First(); + if(record == null) + { + return new AGVJob(); + } return record; } catch (Exception ex) { _logger.LogError($"获取列表发生错误: {ex.Message}"); - return null; + return new AGVJob(); } } } diff --git a/SlnMesnac.Repository/service/Impl/AGVSettingServiceImpl.cs b/SlnMesnac.Repository/service/Impl/AGVSettingServiceImpl.cs index 4a48386..866de0e 100644 --- a/SlnMesnac.Repository/service/Impl/AGVSettingServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/AGVSettingServiceImpl.cs @@ -35,23 +35,46 @@ namespace SlnMesnac.Repository.service.Impl return agvSettingList; } + /// + /// 根据AgvGuid获取单条AGV设置 + /// + /// + public AGVSetting GetAgvSettingByAgvGuid(string guid) + { + try + { + var res = _rep.GetList(x => x.AGVNo == guid).FirstOrDefault(); + if(res == null) + { + return new AGVSetting(); + } + return res; + } + catch (Exception ex) + { + _logger.LogError("根据AGVID获取AGV类型异常" + ex.Message); + return new AGVSetting(); + } + } + + /// /// 根据AGVID获取AGV类型 /// /// /// - public string GetAgvSettingByID(string id) + public string GetAgvTypeByAGVGuid(string guid) { try { - List list = _rep.GetList(); - return list.Where(x => x.AGVNo == id).FirstOrDefault().AGVType; + var res = _rep.GetList(x => x.AGVNo == guid).FirstOrDefault().AGVType; + return res; } catch(Exception ex) { _logger.LogError("根据AGVID获取AGV类型异常" + ex.Message); return ""; - } + } } /// diff --git a/SlnMesnac.Repository/service/Impl/VisionSettingServiceImpl.cs b/SlnMesnac.Repository/service/Impl/VisionSettingServiceImpl.cs index ec1f407..36a5e7f 100644 --- a/SlnMesnac.Repository/service/Impl/VisionSettingServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/VisionSettingServiceImpl.cs @@ -4,6 +4,7 @@ using SlnMesnac.Repository.service.@base; using System; using System.Collections.Generic; using System.Linq.Expressions; +using System.Security.Cryptography; using System.Text; namespace SlnMesnac.Repository.service.Impl @@ -20,12 +21,17 @@ namespace SlnMesnac.Repository.service.Impl { try { - return _rep.GetList(); + var res = _rep.GetList(); + if (res == null) + { + return new List(); + } + return res; } catch (Exception ex) { _logger.LogError($"获取视觉配置列表错误"); - return null; + return new List(); } } @@ -33,12 +39,17 @@ namespace SlnMesnac.Repository.service.Impl { try { - return _rep.GetList(expression); + var res = _rep.GetList(expression); + if (res == null) + { + return new List(); + } + return res; } catch (Exception ex) { _logger.LogError($"获取视觉配置列表错误"); - return null; + return new List(); } } @@ -46,12 +57,17 @@ namespace SlnMesnac.Repository.service.Impl { try { - return _rep.GetSingle(x => x.AMRGUID == guid); + var res = _rep.GetSingle(x => x.AMRGUID == guid); + if (res == null) + { + return new VisionSetting(); + } + return res; } catch(Exception ex) { _logger.LogError($"根据AMRGUID获取视觉配置错误"); - return null; + return new VisionSetting(); } } @@ -59,12 +75,17 @@ namespace SlnMesnac.Repository.service.Impl { try { - return _rep.GetSingle(x => x.VisionID == id); + var res = _rep.GetSingle(x => x.VisionID == id); + if (res == null) + { + return new VisionSetting(); + } + return res; } catch (Exception ex) { _logger.LogError($"根据VisionID获取视觉配置错误"); - return null; + return new VisionSetting(); } } } diff --git a/SlnMesnac.TouchSocket/TcpServer.cs b/SlnMesnac.TouchSocket/TcpServer.cs index 99b26f9..6ee4ed4 100644 --- a/SlnMesnac.TouchSocket/TcpServer.cs +++ b/SlnMesnac.TouchSocket/TcpServer.cs @@ -387,51 +387,4 @@ namespace SlnMesnac.TouchSocket }; } } - - /// - /// 请求视觉开始工作码垛信号 - /// - public enum StackState - { - /// - /// 复合机器人码垛无需定位位置在X负侧 - /// - NXAMRNoPositioning = 0x00, - - /// - /// 复合机器人码垛需要定位位置在X负侧 - /// - NXAMRNeedPositioning = 0x01, - - /// - /// 搬运机器人码垛无需定位位置在X负侧 - /// - NXAGVNoPositioning = 0x02, - - /// - /// 搬运机器人码垛需要定位位置在X负侧 - /// - NXAGVNeedPositioning = 0x03, - - /// - /// 复合机器人码垛无需定位位置在X正侧 - /// - PXAMRNoPositioning = 0x04, - - /// - /// 复合机器人码垛需要定位位置在X正侧 - /// - PXAMRNeedPositioning = 0x05, - - /// - /// 搬运机器人码垛无需定位位置在X正侧 - /// - PXAGVNoPositioning = 0x06, - - /// - /// 搬运机器人码垛需要定位位置在X正侧 - /// - PXAGVNeedPositioning = 0x07, - } - } diff --git a/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml b/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml index de46bd5..41787de 100644 --- a/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml +++ b/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml @@ -6,20 +6,7 @@ xmlns:local="clr-namespace:SlnMesnac.WPF.Page.ControlPage" mc:Ignorable="d" d:DesignWidth="800" Background="Transparent" Height="590"> -