增加AGV任务判断

This commit is contained in:
anerx 2025-03-23 13:55:15 +08:00
parent 714ea9a94e
commit 5108f66352
3 changed files with 52 additions and 13 deletions

View File

@ -46,7 +46,8 @@ public class HikAgv(ILogger<HikAgv> logger)
logger.LogInformation($"task {taskCode} cancel succeed."); logger.LogInformation($"task {taskCode} cancel succeed.");
} }
public async Task CarryToAsync(AgvPosition start, AgvPosition end, string ctnrType, int priority, string taskType) public async Task<string> CarryToAsync(AgvPosition start, AgvPosition end, string ctnrType, int priority,
string taskType)
{ {
var url = Url + SchedulingTaskUri; var url = Url + SchedulingTaskUri;
var input = new var input = new
@ -65,19 +66,50 @@ public class HikAgv(ILogger<HikAgv> logger)
var rs = await PostAsync<string>(url, input); var rs = await PostAsync<string>(url, input);
if (rs is null) if (rs is null)
{ {
logger.LogWarning($"{start.PositionCode} carry to {end.PositionCode} error: result is null"); throw new NullReferenceException($"{start.PositionCode} carry to {end.PositionCode} error: result is null");
return;
} }
if (rs.Code != "0") if (rs.Code != "0")
{ {
logger.LogWarning($"{start.PositionCode} carry to {end.PositionCode} error: code is {rs.Code} message is {rs.Message}"); throw new Exception(
return; $"{start.PositionCode} carry to {end.PositionCode} error: code is {rs.Code} message is {rs.Message}");
} }
logger.LogInformation($"{start.PositionCode} carry to {end.PositionCode} succeed"); return rs.Data;
} }
public async Task WaitingForTaskCompletedAsync(string taskCode)
{
while (true)
{
var input = new
{
reqCode = GetRequestCode(),
taskCodes = new List<string> { taskCode }
};
var rs = await PostAsync<List<TaskStatusModel>>(Url + "queryTaskStatus", input);
if (rs is null)
{
throw new NullReferenceException($"task {taskCode} wait completed error: result is null");
}
if (rs.Code != "0")
{
throw new Exception($"task {taskCode} wait completed error: code is {rs.Code} message is {rs.Message}");
}
// 检查是否有符合条件的任务状态为 9
var task = rs.Data.FirstOrDefault(t => t.taskCode == taskCode);
if (task is { taskStatus: "9" })
{
logger.LogInformation($"task {taskCode} wait completed succeed");
break; // 退出循环
}
// 可以添加适当的延迟,避免频繁请求
await Task.Delay(1000);
}
}
public async Task UnBin(AgvBinEntity bin) public async Task UnBin(AgvBinEntity bin)
{ {

View File

@ -0,0 +1,8 @@
namespace Seyounth.Hyosung.Core.Agv.HikModels;
public class TaskStatusModel
{
public string taskCode { get; set; }
public string taskStatus { get; set; }
}

View File

@ -43,10 +43,9 @@ public class HyosungAgvService(
ctnrType = "14"; ctnrType = "14";
bin.HeightCode = ctnrType; bin.HeightCode = ctnrType;
await _agv.CarryToAsync(start, stop, ctnrType, 120, "1"); var taskCode = await _agv.CarryToAsync(start, stop, ctnrType, 120, "1");
await _agv.WaitingForTaskCompletedAsync(taskCode);
await agvBinService.BindAsync(bin); await agvBinService.BindAsync(bin);
//等待30秒 确保AGV已经把产品叉出
await Task.Delay(30 * 1000);
} }
public async Task UnBin(AgvBinEntity bin) public async Task UnBin(AgvBinEntity bin)