增加AGV任务判断
This commit is contained in:
parent
714ea9a94e
commit
5108f66352
@ -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)
|
||||||
{
|
{
|
||||||
|
8
Seyounth.Hyosung.Core/Agv/HikModels/TaskStatusModel.cs
Normal file
8
Seyounth.Hyosung.Core/Agv/HikModels/TaskStatusModel.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace Seyounth.Hyosung.Core.Agv.HikModels;
|
||||||
|
|
||||||
|
public class TaskStatusModel
|
||||||
|
{
|
||||||
|
public string taskCode { get; set; }
|
||||||
|
|
||||||
|
public string taskStatus { get; set; }
|
||||||
|
}
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user