From 6544e3fd869ff106f693666618b9eda71fc5d1d7 Mon Sep 17 00:00:00 2001 From: SoulStar Date: Fri, 1 Nov 2024 17:20:54 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E8=87=AA=E5=8A=A8=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/BaseTaskInfoBusiness.cs | 8 +- SlnMesnac.Business/base/VisionBusiness.cs | 411 +++++++++++------- SlnMesnac.Model/domain/AirportTask.cs | 14 +- SlnMesnac.TouchSocket/TcpServer.cs | 39 +- SlnMesnac.WPF/MainWindow.xaml | 16 +- SlnMesnac.WPF/MainWindow.xaml.cs | 49 --- .../Page/ControlPage/TaskControl.xaml | 13 + .../Page/ControlPage/TaskControl.xaml.cs | 30 ++ .../Page/ControlPage/UserTaskControl.xaml | 54 +++ .../Page/ControlPage/UserTaskControl.xaml.cs | 136 ++++++ .../Page/IndexPage/AddTaskContent.xaml.cs | 11 +- .../IndexPage/IndexContentViewModel.cs | 12 + .../ViewModel/MainWindowViewModel.cs | 72 ++- 13 files changed, 602 insertions(+), 263 deletions(-) create mode 100644 SlnMesnac.WPF/Page/ControlPage/TaskControl.xaml create mode 100644 SlnMesnac.WPF/Page/ControlPage/TaskControl.xaml.cs create mode 100644 SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml create mode 100644 SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml.cs diff --git a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs index 567f79b..55b03ae 100644 --- a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs +++ b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs @@ -126,7 +126,7 @@ namespace SlnMesnac.Business.@base /// AGV状态查询控制 /// /// - public void AGVStateUpdateTimerOperation(TimerControl state) + public void TaskStateUpdateTimerOperation(TimerControl state) { try { @@ -226,8 +226,9 @@ namespace SlnMesnac.Business.@base //只有amr的情况 if (taskItem.amragvisarrive == "已到达" && string.IsNullOrEmpty(taskItem.deliveragvno)) { + int amrStackNo =_AGVStateService.GetSingleAGVState(taskItem.amragvno).stackcount; //调用机械臂向AMR小车抓取 - _visionBusiness.RequestVisionStartWork(StackState.AMRNeedPositioning, _tcpServer.VID); + _visionBusiness.RequestVisionStartWork(StackState.NXAMRNeedPositioning, amrStackNo, _tcpServer.VID); taskItem.taskstate = "抓取中"; _Taskservice.UpdateTaskAsync(taskItem); _logger.LogInformation($"[ {taskItem.conveyorno} ]号传送带开始工作"); @@ -236,8 +237,9 @@ namespace SlnMesnac.Business.@base //amr和deliver都用的情况 if (taskItem.amragvisarrive == "已到达" && taskItem.deliveragvisarrive == "已到达") { + int agvStackNo = _AGVStateService.GetSingleAGVState(taskItem.deliveragvno).stackcount; //调用机械臂向Deliver小车抓取 - _visionBusiness.RequestVisionStartWork(StackState.AGVNeedPositioning, _tcpServer.VID); + _visionBusiness.RequestVisionStartWork(StackState.NXAGVNeedPositioning, agvStackNo, _tcpServer.VID); taskItem.taskstate = "抓取中"; _Taskservice.UpdateTaskAsync(taskItem); _logger.LogInformation($"[ {taskItem.conveyorno} ]号传送带开始工作"); diff --git a/SlnMesnac.Business/base/VisionBusiness.cs b/SlnMesnac.Business/base/VisionBusiness.cs index 1c85e6e..9ea5244 100644 --- a/SlnMesnac.Business/base/VisionBusiness.cs +++ b/SlnMesnac.Business/base/VisionBusiness.cs @@ -43,7 +43,7 @@ namespace SlnMesnac.Business.@base //视觉系统回复开始码垛 _tcpServer.ReceiveVisionStartWorkEvent += GetVisionWorkState; //视觉系统通知一次码垛完成结果 - _tcpServer.ReceiveStackWorkDoneEvent += StackResultSend; + _tcpServer.ReceiveStackWorkDoneEvent += AutoStackResultSend; //_tcpServer.ReceiveStackWorkDoneEvent += AutoStackResultSend; //视觉系统通知人工异常处理完成 _tcpServer.ReceiveManualExceptionDealDoneEvent += GetManualExceptionDealDone; @@ -64,17 +64,17 @@ namespace SlnMesnac.Business.@base /// /// AMR就绪,请求视觉开始工作 /// - public void RequestVisionStartWork(StackState state, string id) + public void RequestVisionStartWork(StackState state, int count, string id) { - _tcpServer.SendAMRRequestVisionStartWork(new byte[1] { (byte)state }, id); + _tcpServer.SendAMRRequestVisionStartWork(new byte[2] { (byte)state, (byte)count }, id); } /// /// 码垛结束,请求视觉系统复位 /// - public void RequestVisionReplace(string port) + public void RequestVisionReplace(string ip) { - _tcpServer.SendStackOverRequestVisionSysReplace(port); + _tcpServer.SendStackOverRequestVisionSysReplace(ip); VDCount = 1; VACount = 0; TotalJudge = false; @@ -100,24 +100,68 @@ namespace SlnMesnac.Business.@base /// private void GetVisionWorkState(TcpVisionEntity entity, string id) { - if (entity.DataLength == 1) + try { - if (entity.DataBytes[0] == 0x00) - { - _logger.LogInformation($"视觉系统收到开始工作状态:正常开始工作"); - } - else if (entity.DataBytes[0] == 0x01) + + if (entity.DataLength == 3) { - _logger.LogError($"视觉系统收到开始工作状态:异常不能开始工作"); + //正常开始工作 + if (entity.DataBytes[0] == 0x00) + { + _logger.LogInformation($"视觉系统收到开始工作状态:正常开始工作"); + VisionSetting record = _visionSettingService.GetList(x => x.VisionID == id).ToList().First(); + //大端字节序 + Array.Reverse(entity.SN); + AirportTask airportTask = _airportTaskService.GetTaskInfos(x => x.amragvno == record.AMRGUID && + x.visiontaskno == (BitConverter.ToUInt16(entity.SN, 0) - 1).ToString() && x.taskstate == "抓取中").First(); + //判断视觉计数和上位机技术是否一致,如果不一致,向视觉计数统一 + //如果这次码垛是AMR + if (entity.DataBytes[2] == 00) + { + AGVState AMR = _aGVStateService.GetSingleAGVState(airportTask.amragvno); + //如果不一样 + if (entity.DataBytes[1] != AMR.stackcount) + { + AMR.stackcount = entity.DataBytes[1]; + _aGVStateService.UpdateAsync(AMR); + } + } + //如果这次码垛是Deliver + else if (entity.DataBytes[2] == 01) + { + AGVState Deliver = _aGVStateService.GetSingleAGVState(airportTask.deliveragvno); + //如果不一样 + if (entity.DataBytes[1] != Deliver.stackcount) + { + Deliver.stackcount = entity.DataBytes[1]; + _aGVStateService.UpdateAsync(Deliver); + } + } + //内容 + else + { + _logger.LogError($"视觉系统收到开始工作状态:返回未知代码"); + } + } + else if (entity.DataBytes[0] == 0x01) + { + _logger.LogError($"视觉系统收到开始工作状态:异常不能开始工作"); + } + else + { + _logger.LogError($"视觉系统收到开始工作状态:返回未知代码"); + } } else { - _logger.LogError($"视觉系统收到开始工作状态:返回未知代码"); + _logger.LogError($"视觉系统收到开始工作状态:数据返回格式错误"); } } - else + catch (Exception ex) { - _logger.LogError($"视觉系统收到开始工作状态:数据返回格式错误"); + RequestVisionReplace(id); + _logger.LogError($"接受开始工作状态发生错误 {ex.Message}"); + } } @@ -129,113 +173,54 @@ namespace SlnMesnac.Business.@base /// public void AutoStackResultSend(TcpVisionEntity entity, string id) { - if (entity.DataLength == 1) + try { - if (entity.DataBytes[0] == 0x00) + if (entity.DataLength == 2) { - _logger.LogInformation($"视觉系统一次码垛结束,码垛完成 Deliver:{VDCount} AMR:{VACount}"); - //上位机回复收到码垛结果 - _tcpServer.SendReplayStackResult(id); - VisionSetting record = _visionSettingService.GetList(x => x.VisionID == id).ToList().First(); - AirportTask airportTask = _airportTaskService.GetTaskInfos(x => x.amragvno == record.AMRGUID && - x.visiontaskno == (BitConverter.ToInt16(entity.SN, 0) - 1).ToString() && x.taskstate == "抓取中").First(); - //成功码垛先码垛计数 - StackCount(airportTask, entity.DataBytes[1]); - //////////////下面是下一次码垛的综合判断条件////////////// - //先判断总数是否需要继续工作 - if (airportTask.totalcount > airportTask.loadcount) + if (entity.DataBytes[0] == 0x00) { - //如上一次是AMR 如有Deliver 判断是否到达 到达向deliver发送开始工作,没就判断amr是否装满 继续向amr - //上一次是AMR - if (entity.DataBytes[1] == 0x01) + _logger.LogInformation($"视觉系统一次码垛结束,码垛完成 Deliver:{VDCount} AMR:{VACount}"); + //上位机回复收到码垛结果 + _tcpServer.SendReplayStackResult(id); + VisionSetting record = _visionSettingService.GetList(x => x.VisionID == id).ToList().First(); + //大端字节序 + Array.Reverse(entity.SN); + AirportTask airportTask = _airportTaskService.GetTaskInfos(x => x.amragvno == record.AMRGUID && + x.visiontaskno == (BitConverter.ToUInt16(entity.SN, 0) - 1).ToString() && x.taskstate == "抓取中").First(); + //成功码垛先码垛计数 + StackCount(airportTask, entity.DataBytes[1]); + //取出两辆小车的计数 + int AMRCount = _aGVStateService.GetSingleAGVState(airportTask.amragvno).stackcount; + int DeliverCount = 0; + if (!string.IsNullOrEmpty(airportTask.deliveragvno)) { - //妹有Deliver的任务(小车号和是否已到达都没有)amr肯定能抓完 继续amr抓取 - if (string.IsNullOrEmpty(airportTask.deliveragvno) && string.IsNullOrEmpty(airportTask.deliveragvisarrive)) - { - //一直向amr抓,直到抓满 - RequestVisionStartWork(StackState.AMRNoPositioning, id); - } - //有Delievr任务(有任务号且状态为未到达)继续amr抓取 - else if (!string.IsNullOrEmpty(airportTask.deliveragvno) && airportTask.deliveragvisarrive == "未到达") - { - //判断AMR小车是否装满,没满就开装,满了就结束,开始循环判断deliver是否到达 - //amr没满 继续装amr - if (_aGVStateService.GetSingleAGVState(airportTask.amragvno).stackcount < BaseTaskInfoBusiness.AMRStackNumber) - { - RequestVisionStartWork(StackState.AMRNoPositioning, id); - } - //AMR满了 - else - { - AirportTask task; - //结束抓取、循环判断deliver是否到达,到了就向新的Deliver开始抓取 - Task.Run(() => - { - //请求复位 - RequestVisionReplace(id); - while (true) - { - //循环判断该任务的deliver是否到达 - Task.Delay(1000); - task = _airportTaskService.GetTaskInfos(x => x.amragvno == record.AMRGUID && x.taskstate == "抓取中").First(); - if (task.deliveragvisarrive == "已到达") - { - RequestVisionStartWork(StackState.AGVNeedPositioning, id); - break; - } - } - }); - } - } - //有Deliver任务(有任务号且已到达)向Deliver发送开始抓取 - else if (!string.IsNullOrEmpty(airportTask.deliveragvno) && airportTask.deliveragvisarrive == "已到达") - { - RequestVisionStartWork(StackState.AGVNeedPositioning, id); - } - //异常情况 - else - { - throw new Exception($"任务 {airportTask.taskno} 状态异常!请清除任务并重新下发任务!"); - } + DeliverCount = _aGVStateService.GetSingleAGVState(airportTask.deliveragvno).stackcount; } - //如上一次是deliver-->则判断deliver是否装满-->装满则deliver入库-->判断剩下的数量用不用调新的deliver-->用就调新的deliver然后发向amr抓取(还得判断AMR是否抓满)-->不用就直接向amr抓取 - //上一次是Deliver - else if (entity.DataBytes[1] == 0x00) + //////////////下面是下一次码垛的综合判断条件////////////// + //先判断总数是否需要继续工作 + if (airportTask.totalcount > airportTask.loadcount) { - //判断Deliver是否装满,装满就直接入库,未装满继续装 - //deliver没满,继续装 - if (_aGVStateService.GetSingleAGVState(airportTask.deliveragvno).stackcount < BaseTaskInfoBusiness.DeliverStackNumber) - { - RequestVisionStartWork(StackState.AGVNoPositioning, id); - } - //deliver满了,入库然后判断 - else + //如上一次是AMR 如有Deliver 判断是否到达 到达向deliver发送开始工作,没就判断amr是否装满 继续向amr + //上一次是AMR + if (entity.DataBytes[1] == 0x00) { - //入库代码 - _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(airportTask.deliveragvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入库", airportTask.conveyorno).JobName); - airportTask.deliveragvno = null; - airportTask.deliveragvisarrive = null; - _airportTaskService.UpdateTaskAsync(airportTask); - //判断剩下的数量用不用调用新的deliver - //剩下的数量不用 直接向amr抓取 - int amrleft = BaseTaskInfoBusiness.AMRStackNumber - _aGVStateService.GetSingleAGVState(airportTask.amragvno).stackcount; - if (airportTask.totalcount - airportTask.loadcount < amrleft) + //妹有Deliver的任务(小车号和是否已到达都没有)amr肯定能抓完 继续amr抓取 + if (string.IsNullOrEmpty(airportTask.deliveragvno) && string.IsNullOrEmpty(airportTask.deliveragvisarrive)) { - RequestVisionStartWork(StackState.AMRNeedPositioning, id); + //一直向amr抓,直到抓满 + RequestVisionStartWork(StackState.NXAMRNoPositioning, AMRCount, id); } - //剩下的数量需要调用,并判断向AMR抓取 - else + //有Delievr任务(有任务号且状态为未到达)继续amr抓取 + else if (!string.IsNullOrEmpty(airportTask.deliveragvno) && airportTask.deliveragvisarrive == "未到达") { - //调新的deliver - AGVState newagv = _baseAGVBusiness.GetBestAGV(AgvType.Deliver); - _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(newagv.agvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入位", airportTask.conveyorno).JobName); - airportTask.deliveragvno = newagv.agvno; - airportTask.deliveragvisarrive = "未到达"; - _airportTaskService.UpdateTaskAsync(airportTask); - //amr无容量,结束抓取,等待Deliver到达 - if (amrleft == 0) + //判断AMR小车是否装满,没满就开装,满了就结束,开始循环判断deliver是否到达 + //amr没满 继续装amr + if (_aGVStateService.GetSingleAGVState(airportTask.amragvno).stackcount < BaseTaskInfoBusiness.AMRStackNumber) + { + RequestVisionStartWork(StackState.NXAMRNoPositioning, AMRCount, id); + } + //AMR满了 + else { AirportTask task; //结束抓取、循环判断deliver是否到达,到了就向新的Deliver开始抓取 @@ -250,95 +235,183 @@ namespace SlnMesnac.Business.@base task = _airportTaskService.GetTaskInfos(x => x.amragvno == record.AMRGUID && x.taskstate == "抓取中").First(); if (task.deliveragvisarrive == "已到达") { - RequestVisionStartWork(StackState.AGVNeedPositioning, id); + RequestVisionStartWork(StackState.NXAGVNeedPositioning, DeliverCount, id); break; } } }); } - //amr有容量,抓 + } + //有Deliver任务(有任务号且已到达)向Deliver发送开始抓取 + else if (!string.IsNullOrEmpty(airportTask.deliveragvno) && airportTask.deliveragvisarrive == "已到达") + { + RequestVisionStartWork(StackState.NXAGVNeedPositioning, DeliverCount, id); + } + //异常情况 + else + { + throw new Exception($"任务 {airportTask.taskno} 状态异常!请清除任务并重新下发任务!"); + } + } + //如上一次是deliver-->则判断deliver是否装满-->装满则deliver入库-->判断剩下的数量用不用调新的deliver-->用就调新的deliver然后发向amr抓取(还得判断AMR是否抓满)-->不用就直接向amr抓取 + //上一次是Deliver + else if (entity.DataBytes[1] == 0x01) + { + //判断Deliver是否装满,装满就直接入库,未装满继续装 + //deliver没满,继续装 + if (_aGVStateService.GetSingleAGVState(airportTask.deliveragvno).stackcount < BaseTaskInfoBusiness.DeliverStackNumber) + { + RequestVisionStartWork(StackState.NXAGVNoPositioning, DeliverCount, id); + } + //deliver满了,入库然后判断 + else + { + //入库代码 + _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(airportTask.deliveragvno, + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入库", airportTask.conveyorno).JobName); + airportTask.deliveragvno = null; + airportTask.deliveragvisarrive = null; + _airportTaskService.UpdateTaskAsync(airportTask); + //判断剩下的数量用不用调用新的deliver + //剩下的数量不用 直接向amr抓取 + int amrleft = BaseTaskInfoBusiness.AMRStackNumber - _aGVStateService.GetSingleAGVState(airportTask.amragvno).stackcount; + if (airportTask.totalcount - airportTask.loadcount < amrleft) + { + RequestVisionStartWork(StackState.NXAMRNeedPositioning, AMRCount, id); + } + //剩下的数量需要调用,并判断向AMR抓取 else { - RequestVisionStartWork(StackState.AMRNeedPositioning, id); + //调新的deliver + AGVState newagv = _baseAGVBusiness.GetBestAGV(AgvType.Deliver); + _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(newagv.agvno, + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入位", airportTask.conveyorno).JobName); + airportTask.deliveragvno = newagv.agvno; + airportTask.deliveragvisarrive = "未到达"; + _airportTaskService.UpdateTaskAsync(airportTask); + //amr无容量,结束抓取,等待Deliver到达 + if (amrleft == 0) + { + AirportTask task; + //结束抓取、循环判断deliver是否到达,到了就向新的Deliver开始抓取 + Task.Run(() => + { + //请求复位 + RequestVisionReplace(id); + while (true) + { + //循环判断该任务的deliver是否到达 + Task.Delay(1000); + task = _airportTaskService.GetTaskInfos(x => x.amragvno == record.AMRGUID && x.taskstate == "抓取中").First(); + if (task.deliveragvisarrive == "已到达") + { + RequestVisionStartWork(StackState.NXAGVNeedPositioning, DeliverCount, id); + break; + } + } + }); + } + //amr有容量,抓 + else + { + RequestVisionStartWork(StackState.NXAMRNeedPositioning, AMRCount, id); + } } } } + //未知代码 + else + { + throw new Exception($"任务 {airportTask.taskno} 未知上次码垛代码!请检查视觉系统状态!"); + } } - //未知代码 + //总数达标,结束任务,复位机械臂,调回小车,任务状态调整 else { - throw new Exception($"任务 {airportTask.taskno} 未知上次码垛代码!请检查视觉系统状态!"); + _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(airportTask.amragvno, + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("1000入库", airportTask.conveyorno).JobName); + airportTask.amragvno = null; + airportTask.amragvisarrive = null; + airportTask.visiontaskno = null; + if (!string.IsNullOrEmpty(airportTask.deliveragvno)) + { + _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(airportTask.deliveragvno, + _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入库", airportTask.conveyorno).JobName); + airportTask.deliveragvno = null; + airportTask.deliveragvisarrive = null; + } + airportTask.finishtime = DateTime.Now; + airportTask.taskstate = "已完成"; + _airportTaskService.UpdateTaskAsync(airportTask); } } - //总数达标,结束任务,复位机械臂,调回小车,任务状态调整 - else + //码垛过程失败 + else if (entity.DataBytes[0] == 0x01) { - _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(airportTask.amragvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("1000入库", airportTask.conveyorno).JobName); - airportTask.amragvno = null; - airportTask.amragvisarrive = null; - airportTask.visiontaskno = null; + VisionSetting record = _visionSettingService.GetList(x => x.VisionID == id).ToList().First(); + //大端字节序 + Array.Reverse(entity.SN); + AirportTask airportTask = _airportTaskService.GetTaskInfos(x => x.amragvno == record.AMRGUID && + x.visiontaskno == (BitConverter.ToUInt16(entity.SN, 0) - 1).ToString() && x.taskstate == "抓取中").First(); + //取出两辆小车的计数 + int AMRCount = _aGVStateService.GetSingleAGVState(airportTask.amragvno).stackcount; + int DeliverCount = 0; if (!string.IsNullOrEmpty(airportTask.deliveragvno)) { - _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(airportTask.deliveragvno, - _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入库", airportTask.conveyorno).JobName); - airportTask.deliveragvno = null; - airportTask.deliveragvisarrive = null; + DeliverCount = _aGVStateService.GetSingleAGVState(airportTask.deliveragvno).stackcount; + } + _logger.LogError($"视觉系统一次码垛结束,码垛过程失败,重新发送码垛信号"); + if (entity.DataBytes[1] == 0x00) + { + //发送向复合机器人(AMR)码垛的信号 + RequestVisionStartWork(StackState.NXAMRNoPositioning, AMRCount, id); + _logger.LogInformation("下一次码垛开始,方向:复合机器人"); + } + else if (entity.DataBytes[1] == 0x01) + { + //发送向搬运机器人(AGVDeliver)码垛的信号 + RequestVisionStartWork(StackState.NXAGVNoPositioning, DeliverCount, id); + _logger.LogInformation("下一次码垛开始,方向:搬运机器人"); + } + else + { + _logger.LogError($"码垛失败返回未知码垛结果代码,请手动重新发送码垛信号"); } - airportTask.finishtime = DateTime.Now; - airportTask.taskstate = "已完成"; - _airportTaskService.UpdateTaskAsync(airportTask); - } - } - //码垛过程失败 - else if (entity.DataBytes[0] == 0x01) - { - _logger.LogError($"视觉系统一次码垛结束,码垛过程失败,重新发送码垛信号"); - if (entity.DataBytes[1] == 0x01) - { - //发送向复合机器人(AMR)码垛的信号 - RequestVisionStartWork(StackState.AMRNoPositioning, id); - _logger.LogInformation("下一次码垛开始,方向:复合机器人"); } - else if (entity.DataBytes[1] == 0x00) + //码垛检查失败 + else if (entity.DataBytes[0] == 0x02) { - //发送向搬运机器人(AGVDeliver)码垛的信号 - RequestVisionStartWork(StackState.AGVNoPositioning, id); - _logger.LogInformation("下一次码垛开始,方向:搬运机器人"); + _logger.LogError($"视觉系统一次码垛结束,码垛检查失败,请手动矫正并手动开始下一次码垛"); + //仍然要码垛计数,只是筐码的不准 + VisionSetting record = _visionSettingService.GetList(x => x.VisionID == id).ToList().First(); + AirportTask airportTask = _airportTaskService.GetTaskInfos(x => x.amragvno == record.AMRGUID && + x.visiontaskno == (BitConverter.ToInt16(entity.SN, 0) - 1).ToString() && x.taskstate == "抓取中").First(); + StackCount(airportTask, entity.DataBytes[1]); } + //未知代码 else { - _logger.LogError($"码垛失败返回未知码垛结果代码,请手动重新发送码垛信号"); + _logger.LogError($"视觉系统一次码垛结束,未知返回代码!请检查视觉系统状态!"); + throw new Exception($"视觉系统 {id}一次码垛结束,未知返回代码!请检查视觉系统状态!"); } } - //码垛检查失败 - else if (entity.DataBytes[0] == 0x02) - { - _logger.LogError($"视觉系统一次码垛结束,码垛检查失败,请手动矫正并手动开始下一次码垛"); - //仍然要码垛计数,只是筐码的不准 - VisionSetting record = _visionSettingService.GetList(x => x.VisionID == id).ToList().First(); - AirportTask airportTask = _airportTaskService.GetTaskInfos(x => x.amragvno == record.AMRGUID && - x.visiontaskno == (BitConverter.ToInt16(entity.SN, 0) - 1).ToString() && x.taskstate == "抓取中").First(); - StackCount(airportTask, entity.DataBytes[1]); - } - //未知代码 + //数据格式错误 else { - _logger.LogError($"视觉系统一次码垛结束,未知返回代码!请检查视觉系统状态!"); - throw new Exception($"视觉系统 {id }一次码垛结束,未知返回代码!请检查视觉系统状态!"); + _logger.LogError($"视觉系统一次码垛结束,返回数据格式错误,请检查视觉系统状态!"); } } - //数据格式错误 - else + catch(Exception ex) { - _logger.LogError($"视觉系统一次码垛结束,返回数据格式错误,请检查视觉系统状态!"); + RequestVisionReplace(id); + _logger.LogError($"接受工作结束再分配状态发生错误 {ex.Message}"); } } public void StackCount(AirportTask airportTask, byte lastCount) { //AMR码垛计数 - if (lastCount == 0x01) + if (lastCount == 0x00) { airportTask.loadcount++; AGVState aGVState = _aGVStateService.GetSingleAGVState(airportTask.amragvno); @@ -355,7 +428,7 @@ namespace SlnMesnac.Business.@base } } //Deliver码垛计数 - else if (lastCount == 0x00) + else if (lastCount == 0x01) { airportTask.loadcount++; AGVState aGVState = _aGVStateService.GetSingleAGVState(airportTask.deliveragvno); @@ -404,7 +477,7 @@ namespace SlnMesnac.Business.@base if (Vjudge) //这里写向哪个机器人码垛的判断条件 { //发送向搬运机器人(AGVDeliver)码垛的信号 - RequestVisionStartWork(StackState.AGVNoPositioning, id); + RequestVisionStartWork(StackState.NXAGVNoPositioning, VDCount, id); _logger.LogInformation("下一次码垛开始,方向:搬运机器人"); VDCount++; VNow = true; @@ -416,7 +489,7 @@ namespace SlnMesnac.Business.@base else { //发送向复合机器人(AMR)码垛的信号 - RequestVisionStartWork(StackState.AMRNoPositioning, id); + RequestVisionStartWork(StackState.NXAMRNoPositioning, VACount, id); _logger.LogInformation("下一次码垛开始,方向:复合机器人"); VACount++; VNow = false; @@ -440,13 +513,13 @@ namespace SlnMesnac.Business.@base if (VNow) //这里写向哪个机器人码垛的判断条件 { //发送向搬运机器人(AGVDeliver)码垛的信号 - RequestVisionStartWork(StackState.AGVNoPositioning, id); + RequestVisionStartWork(StackState.NXAGVNoPositioning, VDCount, id); _logger.LogInformation("下一次码垛开始,方向:搬运机器人"); } else { //发送向复合机器人(AMR)码垛的信号 - RequestVisionStartWork(StackState.AMRNoPositioning, id); + RequestVisionStartWork(StackState.NXAMRNoPositioning, VACount, id); _logger.LogInformation("下一次码垛开始,方向:复合机器人"); } } diff --git a/SlnMesnac.Model/domain/AirportTask.cs b/SlnMesnac.Model/domain/AirportTask.cs index a48925c..94ddd13 100644 --- a/SlnMesnac.Model/domain/AirportTask.cs +++ b/SlnMesnac.Model/domain/AirportTask.cs @@ -44,37 +44,37 @@ namespace SlnMesnac.Repository /// AMRAGV编号 /// [SugarColumn(ColumnName = "AMRAGVNo")] - public string amragvno { get; set; } + public string? amragvno { get; set; } /// /// AMRAGV是否到达 /// [SugarColumn(ColumnName = "AMRAGVIsArrive")] - public string amragvisarrive { get; set; } + public string? amragvisarrive { get; set; } /// /// 搬运AGV编号 /// [SugarColumn(ColumnName = "DeliverAGVNo")] - public string deliveragvno { get; set; } + public string? deliveragvno { get; set; } /// /// 搬运AGV是否到达 /// [SugarColumn(ColumnName = "DeliverAGVIsArrive")] - public string deliveragvisarrive { get; set; } + public string? deliveragvisarrive { get; set; } /// /// 总数量 /// [SugarColumn(ColumnName = "TotalCount")] - public int? totalcount { get; set; } + public int totalcount { get; set; } /// /// 已装载数量 /// [SugarColumn(ColumnName = "LoadCount")] - public int? loadcount { get; set; } + public int loadcount { get; set; } /// /// 任务状态 @@ -86,7 +86,7 @@ namespace SlnMesnac.Repository /// 开始时间 /// [SugarColumn(ColumnName = "StartTime")] - public DateTime? starttime { get; set; } + public DateTime starttime { get; set; } /// /// 结束时间 diff --git a/SlnMesnac.TouchSocket/TcpServer.cs b/SlnMesnac.TouchSocket/TcpServer.cs index 7ae8e1c..99b26f9 100644 --- a/SlnMesnac.TouchSocket/TcpServer.cs +++ b/SlnMesnac.TouchSocket/TcpServer.cs @@ -388,27 +388,50 @@ namespace SlnMesnac.TouchSocket } } + /// + /// 请求视觉开始工作码垛信号 + /// public enum StackState { /// - /// 复合机器人码垛无需定位 + /// 复合机器人码垛无需定位位置在X负侧 /// - AMRNoPositioning = 0x00, + NXAMRNoPositioning = 0x00, /// - /// 复合机器人码垛需要定位 + /// 复合机器人码垛需要定位位置在X负侧 /// - AMRNeedPositioning = 0x01, + NXAMRNeedPositioning = 0x01, /// - /// 搬运机器人码垛无需定位 + /// 搬运机器人码垛无需定位位置在X负侧 /// - AGVNoPositioning = 0x10, + NXAGVNoPositioning = 0x02, /// - /// 搬运机器人码垛需要定位 + /// 搬运机器人码垛需要定位位置在X负侧 /// - AGVNeedPositioning = 0x11, + NXAGVNeedPositioning = 0x03, + + /// + /// 复合机器人码垛无需定位位置在X正侧 + /// + PXAMRNoPositioning = 0x04, + + /// + /// 复合机器人码垛需要定位位置在X正侧 + /// + PXAMRNeedPositioning = 0x05, + + /// + /// 搬运机器人码垛无需定位位置在X正侧 + /// + PXAGVNoPositioning = 0x06, + + /// + /// 搬运机器人码垛需要定位位置在X正侧 + /// + PXAGVNeedPositioning = 0x07, } } diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml index 35212ab..7a0ad7f 100644 --- a/SlnMesnac.WPF/MainWindow.xaml +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -58,13 +58,17 @@ - - + + + + +