349 lines
14 KiB
C#
349 lines
14 KiB
C#
using RobotApp.Common.Shares;
|
|
using RobotApp.VDA5050;
|
|
using RobotApp.VDA5050.Factsheet;
|
|
using RobotApp.VDA5050.InstantAction;
|
|
using RobotApp.VDA5050.Type;
|
|
using System.Text.Json;
|
|
|
|
namespace RobotApp.Services.Robot;
|
|
|
|
|
|
public class RobotFactsheet(RobotConnection RobotConnection, RobotConfiguration RobotConfiguration) : BackgroundService
|
|
{
|
|
private readonly Dictionary<ActionType, AgvAction> AgvActions = new()
|
|
{
|
|
{ ActionType.startPause, StartPause},
|
|
{ ActionType.stopPause, StopPause},
|
|
{ ActionType.startCharging, StartCharging},
|
|
{ ActionType.stopCharging, StopCharging},
|
|
{ ActionType.initPosition, InitPosition},
|
|
{ ActionType.stateRequest, StateRequest},
|
|
{ ActionType.factsheetRequest, FactsheetRequest},
|
|
{ ActionType.cancelOrder, CancelOrder},
|
|
{ ActionType.liftUp, LiftUp},
|
|
{ ActionType.liftDown, LiftDown},
|
|
{ ActionType.liftRotate, LiftRotate},
|
|
{ ActionType.rotate, Rotate},
|
|
{ ActionType.rotateKeepLift, RotateKeepLift},
|
|
{ ActionType.mutedBaseOn, MutedBaseOn},
|
|
{ ActionType.mutedBaseOff, MutedBaseOff},
|
|
{ ActionType.mutedLoadOn, MutedLoadOn},
|
|
{ ActionType.mutedLoadOff, MutedLoadOff},
|
|
{ ActionType.dockTo, DockTo},
|
|
{ ActionType.moveStraightToCoor, MoveStraightToCoor},
|
|
{ ActionType.moveStraightWithDistance, MoveStraightWithDistance},
|
|
};
|
|
|
|
public AgvAction? GetAction(ActionType actionType) => AgvActions.TryGetValue(actionType, out AgvAction? value) && value is not null ? value : null;
|
|
|
|
public async Task PubFactsheet()
|
|
{
|
|
if (!RobotConnection.IsConnected) return;
|
|
FactSheetMsg factSheet = new()
|
|
{
|
|
SerialNumber = RobotConfiguration.SerialNumber,
|
|
ProtocolFeatures = new()
|
|
{
|
|
AgvActions = [..AgvActions.Values],
|
|
}
|
|
};
|
|
string factSheetJson = JsonSerializer.Serialize(factSheet, JsonOptionExtends.Write);
|
|
await RobotConnection.Publish(VDA5050Topic.FACTSHEET.ToTopicString(), factSheetJson);
|
|
}
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
await Task.Yield();
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
if (RobotConnection.IsConnected) break;
|
|
await Task.Delay(1000);
|
|
}
|
|
await PubFactsheet();
|
|
}
|
|
|
|
public readonly static AgvAction StartPause = new()
|
|
{
|
|
ActionType = ActionType.startPause.ToString(),
|
|
ActionDescription = "Tam dừng robot.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã tạm dừng.",
|
|
BlockingTypes = [BlockingType.NONE.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction StopPause = new()
|
|
{
|
|
ActionType = ActionType.stopPause.ToString(),
|
|
ActionDescription = "Tiếp tục hoạt động robot sau khi tạm dừng.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã tiếp tục hoạt động.",
|
|
BlockingTypes = [BlockingType.NONE.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction StartCharging = new()
|
|
{
|
|
ActionType = ActionType.startCharging.ToString(),
|
|
ActionDescription = "Bắt đầu quá trình sạc pin.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã bắt đầu sạc pin.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction StopCharging = new()
|
|
{
|
|
ActionType = ActionType.stopCharging.ToString(),
|
|
ActionDescription = "Kết thúc quá trình sạc pin.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã kết thúc sạc pin.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction InitPosition = new()
|
|
{
|
|
ActionType = ActionType.initPosition.ToString(),
|
|
ActionDescription = "Khởi tạo vị trí robot.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString()],
|
|
ActionParameters = [
|
|
new()
|
|
{
|
|
Key = "x",
|
|
Description = "Tọa độ X của vị trí khởi tạo.",
|
|
ValueDataType = ValueDataType.FLOAT.ToString(),
|
|
IsOptional = false,
|
|
},
|
|
new()
|
|
{
|
|
Key = "y",
|
|
Description = "Tọa độ Y của vị trí khởi tạo.",
|
|
ValueDataType = ValueDataType.FLOAT.ToString(),
|
|
IsOptional = false,
|
|
},
|
|
new()
|
|
{
|
|
Key = "theta",
|
|
Description = "Góc quay (theta) của vị trí khởi tạo. (rad)",
|
|
ValueDataType = ValueDataType.FLOAT.ToString(),
|
|
IsOptional = false,
|
|
}],
|
|
ResultDescription = "Robot đã khởi tạo vị trí.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction StateRequest = new()
|
|
{
|
|
ActionType = ActionType.stateRequest.ToString(),
|
|
ActionDescription = "Yêu cầu gửi trạng thái robot ngay lập tức.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã gửi trạng thái ngay lập tức.",
|
|
BlockingTypes = [BlockingType.NONE.ToString(), BlockingType.SOFT.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction FactsheetRequest = new()
|
|
{
|
|
ActionType = ActionType.factsheetRequest.ToString(),
|
|
ActionDescription = "Yêu cầu gửi Factsheet robot ngay lập tức.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã gửi Factsheet ngay lập tức.",
|
|
BlockingTypes = [BlockingType.NONE.ToString(), BlockingType.SOFT.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction CancelOrder = new()
|
|
{
|
|
ActionType = ActionType.cancelOrder.ToString(),
|
|
ActionDescription = "Hủy bỏ Order hiện tại của robot.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã hủy bỏ Order hiện tại.",
|
|
BlockingTypes = [BlockingType.NONE.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction LiftUp = new()
|
|
{
|
|
ActionType = ActionType.liftUp.ToString(),
|
|
ActionDescription = "Nâng cao bàn nâng của robot.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã nâng cao bàn nâng.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction LiftDown = new()
|
|
{
|
|
ActionType = ActionType.liftDown.ToString(),
|
|
ActionDescription = "Hạ thấp bàn nâng của robot.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã hạ thấp bàn nâng.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction LiftRotate = new()
|
|
{
|
|
ActionType = ActionType.liftRotate.ToString(),
|
|
ActionDescription = "Xoay bàn nâng của robot.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [
|
|
new()
|
|
{
|
|
Key = "angle",
|
|
Description = "Góc xoay của bàn nâng. (rad)",
|
|
ValueDataType = ValueDataType.FLOAT.ToString(),
|
|
IsOptional = false,
|
|
}],
|
|
ResultDescription = "Robot đã xoay bàn nâng.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction Rotate = new()
|
|
{
|
|
ActionType = ActionType.rotate.ToString(),
|
|
ActionDescription = "Xoay robot tại chỗ.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [
|
|
new()
|
|
{
|
|
Key = "angle",
|
|
Description = "Góc xoay của robot. (rad)",
|
|
ValueDataType = ValueDataType.FLOAT.ToString(),
|
|
IsOptional = false,
|
|
}],
|
|
ResultDescription = "Robot đã xoay tại chỗ.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction RotateKeepLift = new()
|
|
{
|
|
ActionType = ActionType.rotateKeepLift.ToString(),
|
|
ActionDescription = "Xoay robot tại chỗ giữ nguyên trạng thái bàn nâng.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [
|
|
new()
|
|
{
|
|
Key = "angle",
|
|
Description = "Góc xoay của robot. (rad)",
|
|
ValueDataType = ValueDataType.FLOAT.ToString(),
|
|
IsOptional = false,
|
|
}],
|
|
ResultDescription = "Robot đã xoay tại chỗ giữ nguyên trạng thái bàn nâng.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction MutedBaseOn = new()
|
|
{
|
|
ActionType = ActionType.mutedBaseOn.ToString(),
|
|
ActionDescription = "Bật chế độ muted base robot.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã bật chế độ muted base.",
|
|
BlockingTypes = [BlockingType.NONE.ToString(), BlockingType.SOFT.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction MutedBaseOff = new()
|
|
{
|
|
ActionType = ActionType.mutedBaseOff.ToString(),
|
|
ActionDescription = "Tắt chế độ muted base robot.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã tắt chế độ muted base.",
|
|
BlockingTypes = [BlockingType.NONE.ToString(), BlockingType.SOFT.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction MutedLoadOn = new()
|
|
{
|
|
ActionType = ActionType.mutedLoadOn.ToString(),
|
|
ActionDescription = "Bật chế độ muted load robot.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã bật chế độ muted load.",
|
|
BlockingTypes = [BlockingType.NONE.ToString(), BlockingType.SOFT.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction MutedLoadOff = new()
|
|
{
|
|
ActionType = ActionType.mutedLoadOff.ToString(),
|
|
ActionDescription = "Tắt chế độ muted load robot.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [],
|
|
ResultDescription = "Robot đã tắt chế độ muted load.",
|
|
BlockingTypes = [BlockingType.NONE.ToString(), BlockingType.SOFT.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction DockTo = new()
|
|
{
|
|
ActionType = ActionType.dockTo.ToString(),
|
|
ActionDescription = "Robot di chuyển vào vị trí đặc biết",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [
|
|
new()
|
|
{
|
|
Key = "dockId",
|
|
Description = "ID của vị trí dock.",
|
|
ValueDataType = ValueDataType.STRING.ToString(),
|
|
IsOptional = false,
|
|
}],
|
|
ResultDescription = "Robot đã dock đến vị trí sạc hoặc bến đỗ.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction MoveStraightToCoor = new()
|
|
{
|
|
ActionType = ActionType.moveStraightToCoor.ToString(),
|
|
ActionDescription = "Di chuyển thẳng đến tọa độ xác định.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [
|
|
new()
|
|
{
|
|
Key = "x",
|
|
Description = "Tọa độ X đích đến.",
|
|
ValueDataType = ValueDataType.FLOAT.ToString(),
|
|
IsOptional = false,
|
|
},
|
|
new()
|
|
{
|
|
Key = "y",
|
|
Description = "Tọa độ Y đích đến.",
|
|
ValueDataType = ValueDataType.FLOAT.ToString(),
|
|
IsOptional = false,
|
|
}],
|
|
ResultDescription = "Robot đã di chuyển thẳng đến tọa độ xác định.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
|
|
public readonly static AgvAction MoveStraightWithDistance = new()
|
|
{
|
|
ActionType = ActionType.moveStraightWithDistance.ToString(),
|
|
ActionDescription = "Di chuyển thẳng với khoảng cách xác định.",
|
|
ActionScopes = [ActionScopes.INSTANT.ToString(), ActionScopes.NODE.ToString()],
|
|
ActionParameters = [
|
|
new()
|
|
{
|
|
Key = "distance",
|
|
Description = "Khoảng cách di chuyển. (m)",
|
|
ValueDataType = ValueDataType.FLOAT.ToString(),
|
|
IsOptional = false,
|
|
},
|
|
new()
|
|
{
|
|
Key = "direction",
|
|
Description = "Hướng di chuyển: 1 - tiến, -1 - lùi.",
|
|
ValueDataType = ValueDataType.INTEGER.ToString(),
|
|
IsOptional = false,
|
|
},
|
|
new()
|
|
{
|
|
Key = "angle",
|
|
Description = "Góc di chuyển so với hướng hiện tại của robot. (rad)",
|
|
ValueDataType = ValueDataType.FLOAT.ToString(),
|
|
IsOptional = true,
|
|
}],
|
|
ResultDescription = "Robot đã di chuyển thẳng với khoảng cách xác định.",
|
|
BlockingTypes = [BlockingType.HARD.ToString()],
|
|
};
|
|
}
|