From 750eb80fa8b1f00dad961a0da0b8c87060332e79 Mon Sep 17 00:00:00 2001 From: CaesarBao <445720029@qq.com> Date: Fri, 27 Sep 2024 09:03:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=BB=E5=8A=A1=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=EF=BC=8C=E6=96=B0=E5=A2=9EAGV=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=BC=96=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/BaseTaskInfoBusiness.cs | 151 +++++++++++++----- SlnMesnac.Business/base/UpLoadBusiness.cs | 42 +++++ SlnMesnac.Model/domain/AirportTask.cs | 16 ++ .../service/Impl/AirportTaskServiceImpl.cs | 2 +- 4 files changed, 168 insertions(+), 43 deletions(-) create mode 100644 SlnMesnac.Business/base/UpLoadBusiness.cs diff --git a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs index c0b2a7d..b07056b 100644 --- a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs +++ b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; + +using Microsoft.Extensions.Logging; using SlnMesnac.Repository.service; using System; using System.Collections.Generic; @@ -14,6 +15,7 @@ using SlnMesnac.Model.Enum; using HslCommunication.Enthernet; using System.Threading; using SlnMesnac.TouchSocket.Entity; +using static SlnMesnac.TouchSocket.TcpServer; namespace SlnMesnac.Business.@base { @@ -30,8 +32,8 @@ namespace SlnMesnac.Business.@base { _logger = logger; _tcpServer = tcpServer; - _tcpServer.VisionSysStateEvent += TcpServerOnVisionSysStateEvent; - _tcpServer.StackWorkDoneEvent += _tcpServer_StackWorkDoneEvent; + _tcpServer.ReceiveVisionSysStateEvent += TcpServerOnVisionSysStateEvent; + _tcpServer.ReceiveStackWorkDoneEvent += _tcpServer_StackWorkDoneEvent; _Taskservice = Taskservice; _AGVStateService = agvService; InitClearTimer(); @@ -41,7 +43,7 @@ namespace SlnMesnac.Business.@base /// 一次码垛完成,发送码垛结果 /// /// - private void _tcpServer_StackWorkDoneEvent(TcpVisionEntity entity) + private void _tcpServer_StackWorkDoneEvent(TcpVisionEntity entity, string id) { try { @@ -76,7 +78,7 @@ namespace SlnMesnac.Business.@base /// 视觉系统回复给上位机调度系统开始工作状态 /// /// - private void TcpServerOnVisionSysStateEvent(TcpVisionEntity entity) + private void TcpServerOnVisionSysStateEvent(TcpVisionEntity entity, string id) { try { @@ -111,27 +113,6 @@ namespace SlnMesnac.Business.@base return instance; } - private void doWhileGetAGVTaskInfo() - { - try - { - Task.Run((() => - { - while (true) - { - GetAGVTaskInfo(null,null); - Task.Delay(1000); - } - - - })); - - } - catch (Exception ex) - { - - } - } private void InitClearTimer() { System.Timers.Timer timer = new System.Timers.Timer @@ -263,24 +244,59 @@ namespace SlnMesnac.Business.@base //根据规则筛选最优AGV if (AgvItem.agvworkstate == "任务空闲") { - _logger.LogInformation($"获取空闲AGV列表"); - _RefreshLogMessageAction?.Invoke("执行站台[" + AirportTask.conveyorno + "],下发" + "[" + AirportTask.taskno + "]任务"); - //调用派发任务接口,向任务状态为任务空闲的AGV派发任务 - bool iTaskflag = true; - if (iTaskflag) + //搬运机器人是否已到位 + if (string.IsNullOrEmpty(AirportTask.agvtaskno)) { - _RefreshLogMessageAction?.Invoke("[" + AgvItem.agvno + "]AGV,执行任务[" + AirportTask.taskno + "]"); - AgvItem.taskno = AirportTask.taskno; - AgvItem.agvworkstate = "任务执行中"; - AgvItem.refreshtime = DateTime.Now; - _AGVStateService.UpdateAsync(AgvItem); + _logger.LogInformation($"获取空闲AGV列表"); + _RefreshLogMessageAction?.Invoke("执行站台[" + AirportTask.conveyorno + "],下发" + "[" + AirportTask.taskno + "]任务"); - //更新任务信息表状态为执行中 - AirportTask.agvno = AgvItem.agvno; - AirportTask.taskstate = "执行中"; - _Taskservice.UpdateTaskAsync(AirportTask); - break; + //调用派发任务接口,向任务状态为任务空闲的复合AGV、搬运AGV派发任务 + bool iTaskflag = true; + if (iTaskflag) + { + _RefreshLogMessageAction?.Invoke("[" + AgvItem.agvno + "]AGV,执行任务[" + AirportTask.taskno + "]"); + AgvItem.taskno = AirportTask.taskno; + AgvItem.agvworkstate = "任务执行中"; + AgvItem.refreshtime = DateTime.Now; + _AGVStateService.UpdateAsync(AgvItem); + + //更新任务信息表状态为执行中 + AirportTask.agvno = AgvItem.agvno; + AirportTask.taskstate = "执行中"; + //等待agv返回任务编号 + AirportTask.agvtaskno = Guid.NewGuid().ToString("N"); + + + _Taskservice.UpdateTaskAsync(AirportTask); + break; + } + } + //复合机器人是否已到位 + if (string.IsNullOrEmpty(AirportTask.amrtaskno)) + { + _logger.LogInformation($"获取空闲AGV列表"); + _RefreshLogMessageAction?.Invoke("执行站台[" + AirportTask.conveyorno + "],下发" + "[" + AirportTask.taskno + "]任务"); + + //调用派发任务接口,向任务状态为任务空闲的复合AGV、搬运AGV派发任务 + bool iTaskflag = true; + if (iTaskflag) + { + _RefreshLogMessageAction?.Invoke("[" + AgvItem.agvno + "]AGV,执行任务[" + AirportTask.taskno + "]"); + AgvItem.taskno = AirportTask.taskno; + AgvItem.agvworkstate = "任务执行中"; + AgvItem.refreshtime = DateTime.Now; + _AGVStateService.UpdateAsync(AgvItem); + + //更新任务信息表状态为执行中 + AirportTask.agvno = AgvItem.agvno; + AirportTask.taskstate = "执行中"; + //等待agv返回任务编号 + AirportTask.amrtaskno = Guid.NewGuid().ToString("N"); + _Taskservice.UpdateTaskAsync(AirportTask); + break; + } } + } } return iflag; @@ -321,10 +337,61 @@ namespace SlnMesnac.Business.@base // 设置计时器 Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); - //通过任务编号查询agv任务 + foreach (AirportTask airportTask in Task) + { + //1.根据搬运AGV任务编号查询agv是否到达 + if (!string.IsNullOrEmpty(airportTask.agvtaskno)) + { + //2.调用3.查询任务状态接口 + //根据搬运AGV任务编号查询agv是否到达 + bool iflag = true; + if (iflag) + { + //3:已完成 + // if (state == 3) + // { + // + // } + //更新任务表中AGV编号 + airportTask.agvno = ""; + //更新agv返回任务编号 + airportTask.agvtaskno = Guid.NewGuid().ToString("N"); + _Taskservice.UpdateTaskAsync(airportTask); + } + } + //根据复合AGV任务编号查询agv是否到达 + if (!string.IsNullOrEmpty(airportTask.amrtaskno)) + { + //根据复合AGV任务编号查询agv是否到达 + bool iflag = true; + if (iflag) + { + //已到达更新任务表中AGV编号 + + } + } + //复合、搬运已到上料点 + if (!string.IsNullOrEmpty(airportTask.agvtaskno) && !string.IsNullOrEmpty(airportTask.agvtaskno)) + { + //1.获取任务抓取数量 + //判断是否为第一车,搬运机器人码垛无需定位 + if (airportTask.loadcount == 0) + { + //下发视觉抓取任务 + + } + if (airportTask.loadcount == 0) + { + //下发视觉抓取任务 + + } + } + } + + // 检查是否超过两秒 if (stopwatch.ElapsedMilliseconds > 2000) { diff --git a/SlnMesnac.Business/base/UpLoadBusiness.cs b/SlnMesnac.Business/base/UpLoadBusiness.cs new file mode 100644 index 0000000..7354b96 --- /dev/null +++ b/SlnMesnac.Business/base/UpLoadBusiness.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.Logging; +using SlnMesnac.Repository; +using SlnMesnac.Repository.service; +using SlnMesnac.TouchSocket; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SlnMesnac.Business.@base +{ + public class UpLoadBusiness + { + #region 单例模式 + //private static readonly Lazy lazy = new Lazy(() => new UpLoadBusiness(_logger,_tcpServer,)); + + //public static UpLoadBusiness Instance + //{ + // get + // { + // return lazy.Value; + // } + //} + + public UpLoadBusiness(ILogger logger, IAirportTaskService Taskservice, IAGVStateService agvService, TcpServer tcpServer) + { + _logger = logger; + _tcpServer = tcpServer; + _Taskservice = Taskservice; + _AGVStateService = agvService; + + } + #endregion + private TcpServer _tcpServer = null; + public Action _Taskaction; + public Action _RefreshLogMessageAction; + private static UpLoadBusiness instance; + private ILogger _logger; + private IAirportTaskService _Taskservice; + private IAGVStateService _AGVStateService; + + } +} diff --git a/SlnMesnac.Model/domain/AirportTask.cs b/SlnMesnac.Model/domain/AirportTask.cs index 1574354..35d2fdf 100644 --- a/SlnMesnac.Model/domain/AirportTask.cs +++ b/SlnMesnac.Model/domain/AirportTask.cs @@ -119,5 +119,21 @@ namespace SlnMesnac.Repository [SugarColumn(ColumnName="FinishTime")] public DateTime? finishtime {get;set;} + /// + /// Desc: + /// Default: + /// Nullable:False + /// + [SugarColumn(ColumnName = "AGVTaskNo")] + public string agvtaskno { get; set; } + + /// + /// Desc: + /// Default: + /// Nullable:False + /// + [SugarColumn(ColumnName = "AMRTaskNo")] + public string amrtaskno { get; set; } + } } diff --git a/SlnMesnac.Repository/service/Impl/AirportTaskServiceImpl.cs b/SlnMesnac.Repository/service/Impl/AirportTaskServiceImpl.cs index 2009ff8..30e6102 100644 --- a/SlnMesnac.Repository/service/Impl/AirportTaskServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/AirportTaskServiceImpl.cs @@ -70,7 +70,7 @@ namespace SlnMesnac.Repository.service.Impl List taskInfos = null; try { - String sql = "select *from ( SELECT id, ConveyorNo,TaskNo,FlightNo,AGVNo,ManipulatorNo,MAX(StartTime) as StartTime,TaskState, TotalCount ,LoadCount FROM AirportTask group by ConveyorNo )"; + String sql = "select *from ( SELECT id, ConveyorNo,TaskNo,FlightNo,AGVNo,ManipulatorNo,MAX(StartTime) as StartTime,TaskState, TotalCount ,LoadCount,AGVTaskNo,AMRTaskNo FROM AirportTask group by ConveyorNo )"; taskInfos = base._rep.AsTenant().GetConnection("AGV").Ado.SqlQuery(sql); } catch (Exception ex)