增加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.");
|
||||
}
|
||||
|
||||
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 input = new
|
||||
@ -65,19 +66,50 @@ public class HikAgv(ILogger<HikAgv> logger)
|
||||
var rs = await PostAsync<string>(url, input);
|
||||
if (rs is null)
|
||||
{
|
||||
logger.LogWarning($"{start.PositionCode} carry to {end.PositionCode} error: result is null");
|
||||
return;
|
||||
throw new NullReferenceException($"{start.PositionCode} carry to {end.PositionCode} error: result is null");
|
||||
}
|
||||
|
||||
if (rs.Code != "0")
|
||||
{
|
||||
logger.LogWarning($"{start.PositionCode} carry to {end.PositionCode} error: code is {rs.Code} message is {rs.Message}");
|
||||
return;
|
||||
throw new Exception(
|
||||
$"{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)
|
||||
{
|
||||
|
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; }
|
||||
}
|
@ -24,7 +24,7 @@ public class HyosungAgvService(
|
||||
} while (status is null);
|
||||
|
||||
var tray = await trayService.GetByCode(trayCode);
|
||||
var height = (int)Math.Ceiling((double)((tray.StackHeight??0) / 10.0)!);
|
||||
var height = (int)Math.Ceiling((double)((tray.StackHeight ?? 0) / 10.0)!);
|
||||
var bin = await agvBinService.GetAvailableBin(height);
|
||||
AgvPosition start = new AgvPosition()
|
||||
{
|
||||
@ -36,17 +36,16 @@ public class HyosungAgvService(
|
||||
PositionCode = bin.CtnrCode,
|
||||
Type = "05"
|
||||
};
|
||||
if(!string.IsNullOrEmpty(bin.HeightCode))
|
||||
if (!string.IsNullOrEmpty(bin.HeightCode))
|
||||
await UnBin(bin);
|
||||
var ctnrType = await dictService.GetKeyAsync("AgvRackType", bin.Height.ToString());
|
||||
if (string.IsNullOrEmpty(ctnrType))
|
||||
ctnrType = "14";
|
||||
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);
|
||||
//等待30秒 确保AGV已经把产品叉出
|
||||
await Task.Delay(30 * 1000);
|
||||
}
|
||||
|
||||
public async Task UnBin(AgvBinEntity bin)
|
||||
|
Loading…
x
Reference in New Issue
Block a user