|
|
|
@ -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
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BaseTaskInfoBusiness
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// AMR最大运载量
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const int AMRStackNumber = 10;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deliver最大运载量
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const int DeliverStackNumber = 15;
|
|
|
|
|
|
|
|
|
|
private TcpServer _tcpServer = null;
|
|
|
|
|
public Action<AirportTask> _Taskaction;
|
|
|
|
|
public Action<string> _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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 从航班接口获取到新任务插入数据库
|
|
|
|
|
/// 获取新任务插入数据库
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<bool> NewTaskInfo(string taskNo, string conveyNo, string flightNo, int totalCount)
|
|
|
|
@ -127,7 +139,7 @@ namespace SlnMesnac.Business.@base
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// AGV状态查询控制
|
|
|
|
|
/// 任务刷新Timer控制
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state"></param>
|
|
|
|
|
public void TaskStateUpdateTimerOperation(TimerControl state)
|
|
|
|
@ -157,7 +169,10 @@ namespace SlnMesnac.Business.@base
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 任务初次派车调度
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// AGV调度
|
|
|
|
|
/// Timer刷新任务状态, 有新任务初次下发AGV, Timer执行
|
|
|
|
|
/// </summary>
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 入库满载AGV
|
|
|
|
|
/// 停止所有任务
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ClearFullAGV()
|
|
|
|
|
public void StopAllTask()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
List<AirportTask> 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($"全部复位完毕");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|