From adb4016b5eb5b119a899480c321be996d9bf10bd Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 08 四月 2026 00:55:22 +0800
Subject: [PATCH] feat(robot): 完善机械手任务处理逻辑与状态管理
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs | 36 +++++++++++++++++++-----------------
1 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
index 8a55144..c35e485 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
@@ -1,7 +1,7 @@
using Microsoft.Extensions.Logging;
using Quartz;
-using System.Net;
using WIDESEA_Core;
+using WIDESEAWCS_Common;
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.LogHelper;
@@ -29,15 +29,6 @@
[DisallowConcurrentExecution]
public class RobotJob : IJob
{
- /// <summary>
- /// 浠诲姟鎬绘暟涓婇檺
- /// </summary>
- /// <remarks>
- /// 褰撴満鍣ㄤ汉澶勭悊鐨勮揣鐗╂暟閲忚揪鍒版涓婇檺鏃讹紝涓嶅啀涓嬪彂鏂颁换鍔°��
- /// 闃叉鏈哄櫒浜鸿繃搴﹀姵绱垨绯荤粺杩囪浇銆�
- /// </remarks>
- private const int MaxTaskTotalNum = 48;
-
/// <summary>
/// 娑堟伅浜嬩欢璁㈤槄鏍囧織
/// </summary>
@@ -116,7 +107,7 @@
ILogger<RobotJob> logger)
{
// 鍒濆鍖栫姸鎬佺鐞嗗櫒锛屼紶鍏ョ紦瀛樻湇鍔�
- _stateManager = new RobotStateManager(cache);
+ _stateManager = new RobotStateManager(cache, _logger);
_logger = logger;
// 鍒涘缓 Socket 缃戝叧锛屽皝瑁� TcpSocketServer 鐨勮闂�
@@ -124,14 +115,14 @@
ISocketClientGateway socketGateway = new SocketClientGateway(tcpSocket);
// 鍒濆鍖栦换鍔″鐞嗗櫒
- _taskProcessor = new RobotTaskProcessor(socketGateway, _stateManager, robotTaskService, taskService, httpClientHelper);
+ _taskProcessor = new RobotTaskProcessor(socketGateway, _stateManager, robotTaskService, taskService, httpClientHelper, _logger);
// 鍒濆鍖栧鎴风绠$悊鍣�
- _clientManager = new RobotClientManager(tcpSocket, _stateManager);
+ _clientManager = new RobotClientManager(tcpSocket, _stateManager, _logger);
// 鍒濆鍖栧懡浠ゅ鐞嗗櫒
// 绠�鍗曞懡浠ゅ鐞嗗櫒锛氬鐞嗙姸鎬佹洿鏂扮瓑绠�鍗曞懡浠�
- var simpleCommandHandler = new RobotSimpleCommandHandler(_taskProcessor);
+ var simpleCommandHandler = new RobotSimpleCommandHandler(_taskProcessor, socketGateway);
// 鍓嶇紑鍛戒护澶勭悊鍣細澶勭悊 pickfinished銆乸utfinished 绛夊甫鍙傛暟鐨勫懡浠�
var prefixCommandHandler = new RobotPrefixCommandHandler(robotTaskService, _taskProcessor, _stateManager, socketGateway);
@@ -139,7 +130,7 @@
_messageRouter = new RobotMessageHandler(socketGateway, _stateManager, cache, simpleCommandHandler, prefixCommandHandler, logger);
// 鍒濆鍖栧伐浣滄祦缂栨帓鍣�
- _workflowOrchestrator = new RobotWorkflowOrchestrator(_stateManager, _clientManager, _taskProcessor, robotTaskService);
+ _workflowOrchestrator = new RobotWorkflowOrchestrator(_stateManager, _clientManager, _taskProcessor, robotTaskService, _logger);
// 璁㈤槄瀹㈡埛绔柇寮�杩炴帴浜嬩欢
_clientManager.OnClientDisconnected += OnClientDisconnected;
@@ -214,8 +205,19 @@
return;
}
+ if (state.CurrentAction == "Picking" || state.CurrentAction == "Puting")
+ {
+ return;
+ }
+
// 杞鑾峰彇璇ヨ澶囩殑寰呭鐞嗕换鍔�
var task = _taskProcessor.GetTask(robotCrane);
+
+ // 濡傛灉娌℃湁鑾峰彇鍒板緟澶勭悊浠诲姟锛屼笖RobotArmObject涓�1锛堟湁鐗╂枡锛夛紝鍒欒幏鍙栬璁惧鎵ц涓殑浠诲姟
+ if (task == null && state.RobotArmObject == 1)
+ {
+ task = _taskProcessor.GetExecutingTask(robotCrane);
+ }
// 濡傛灉鏈夊緟澶勭悊浠诲姟
if (task != null)
@@ -229,7 +231,7 @@
}
// 妫�鏌ヤ换鍔℃�绘暟鏄惁鏈揪鍒颁笂闄�
- if (latestState.RobotTaskTotalNum < MaxTaskTotalNum)
+ if (latestState.RobotTaskTotalNum < RobotConst.MaxTaskTotalNum)
{
// 璋冪敤宸ヤ綔娴佺紪鎺掑櫒鎵ц浠诲姟
// 缂栨帓鍣ㄤ細鏍规嵁褰撳墠鐘舵�佸喅瀹氫笅涓�姝ュ姩浣�
@@ -246,4 +248,4 @@
}
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3