修改任务实体,新增AGV任务编号

master
CaesarBao 4 months ago
parent 1171d1cd87
commit 750eb80fa8

@ -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
/// 一次码垛完成,发送码垛结果
/// </summary>
/// <param name="entity"></param>
private void _tcpServer_StackWorkDoneEvent(TcpVisionEntity entity)
private void _tcpServer_StackWorkDoneEvent(TcpVisionEntity entity, string id)
{
try
{
@ -76,7 +78,7 @@ namespace SlnMesnac.Business.@base
/// 视觉系统回复给上位机调度系统开始工作状态
/// </summary>
/// <param name="entity"></param>
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)
{

@ -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<UpLoadBusiness> lazy = new Lazy<UpLoadBusiness>(() => new UpLoadBusiness(_logger,_tcpServer,));
//public static UpLoadBusiness Instance
//{
// get
// {
// return lazy.Value;
// }
//}
public UpLoadBusiness(ILogger<UpLoadBusiness> logger, IAirportTaskService Taskservice, IAGVStateService agvService, TcpServer tcpServer)
{
_logger = logger;
_tcpServer = tcpServer;
_Taskservice = Taskservice;
_AGVStateService = agvService;
}
#endregion
private TcpServer _tcpServer = null;
public Action<AirportTask> _Taskaction;
public Action<string> _RefreshLogMessageAction;
private static UpLoadBusiness instance;
private ILogger<UpLoadBusiness> _logger;
private IAirportTaskService _Taskservice;
private IAGVStateService _AGVStateService;
}
}

@ -119,5 +119,21 @@ namespace SlnMesnac.Repository
[SugarColumn(ColumnName="FinishTime")]
public DateTime? finishtime {get;set;}
/// <summary>
/// Desc:
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(ColumnName = "AGVTaskNo")]
public string agvtaskno { get; set; }
/// <summary>
/// Desc:
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(ColumnName = "AMRTaskNo")]
public string amrtaskno { get; set; }
}
}

@ -70,7 +70,7 @@ namespace SlnMesnac.Repository.service.Impl
List<AirportTask> 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<AirportTask>(sql);
}
catch (Exception ex)

Loading…
Cancel
Save