Initial commit
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
using RobotNet.VDA5050.State;
|
||||
using RobotNet.VDA5050.Type;
|
||||
using RobotNet10.RobotApp.Interfaces;
|
||||
|
||||
namespace RobotNet10.RobotApp.Services.Robot;
|
||||
|
||||
public class RobotError : Error
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class RobotErrors() : IError
|
||||
{
|
||||
public Error[] ErrorsState { get { lock (Errors) { return [.. Errors]; } } }
|
||||
public bool HasFatalError { get { lock (Errors) { return Errors.Any(e => e.ErrorLevel == ErrorLevel.FATAL); } } }
|
||||
public event System.Action? OnNewFatalError;
|
||||
|
||||
private readonly List<RobotError> Errors = [];
|
||||
|
||||
public void AddError(RobotError error, TimeSpan? clearAfter = null)
|
||||
{
|
||||
bool isFatal = false;
|
||||
lock (Errors)
|
||||
{
|
||||
if (Errors.Any(e => e.Id == error.Id)) return;
|
||||
Errors.Add(error);
|
||||
isFatal = error.ErrorLevel == ErrorLevel.FATAL;
|
||||
}
|
||||
if (isFatal) OnNewFatalError?.Invoke();
|
||||
if (clearAfter is not null && clearAfter.HasValue)
|
||||
{
|
||||
if (clearAfter.Value < TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(clearAfter), "TimeSpan cannot be negative.");
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(clearAfter.Value);
|
||||
lock (Errors)
|
||||
{
|
||||
Errors.RemoveAll(e => e.Id == error.Id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteErrorType(string errorType)
|
||||
{
|
||||
lock (Errors)
|
||||
{
|
||||
Errors.RemoveAll(e => e.ErrorType == errorType);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteErrorId(int id)
|
||||
{
|
||||
lock (Errors)
|
||||
{
|
||||
Errors.RemoveAll(e => e.Id == id);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearAllErrors()
|
||||
{
|
||||
lock (Errors)
|
||||
{
|
||||
Errors.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearFatalErrors()
|
||||
{
|
||||
lock (Errors) { Errors.RemoveAll(e => e.ErrorLevel == ErrorLevel.FATAL); }
|
||||
}
|
||||
|
||||
private static RobotError CreateError(int id, ErrorType type, string hint, ErrorLevel level, string description)
|
||||
{
|
||||
return new RobotError()
|
||||
{
|
||||
Id = id,
|
||||
ErrorType = type.ToString(),
|
||||
ErrorLevel = level,
|
||||
ErrorDescription = description,
|
||||
ErrorHint = hint,
|
||||
ErrorReferences = []
|
||||
};
|
||||
}
|
||||
|
||||
public static RobotError Error1001(string oldOrderId, string newOrderId)
|
||||
=> CreateError(1001, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại OrderId", ErrorLevel.WARNING, $"Có order đang được thực hiện. OrderId: {oldOrderId}, OrderId mới: {newOrderId}");
|
||||
public static RobotError Error1002(int nodesLength)
|
||||
=> CreateError(1002, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại kích thước Nodes", ErrorLevel.WARNING, $"Order Nodes không hợp lệ. Kích thước: {nodesLength}");
|
||||
public static RobotError Error1003(int oldOrderUpdateId, int newOrderUpdateId)
|
||||
=> CreateError(1003, ErrorType.ORDER_UPDATE_ERROR, "Vui lòng kiểm tra lại OrderUpdateId", ErrorLevel.WARNING, $"OrderUpdateId {newOrderUpdateId} nhận được nhỏ hơn OrderUpdateId hiện tại là {oldOrderUpdateId}");
|
||||
public static RobotError Error1004(int nodesLength, int edgesLength)
|
||||
=> CreateError(1004, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại kích thước giữa Nodes và Edges", ErrorLevel.WARNING, $"Order không hợp lệ do kích thước giữa Nodes và Edges không phù hợp. Kích thước Edges: {edgesLength}, kích thước nodes: {nodesLength}");
|
||||
public static RobotError Error1005()
|
||||
=> CreateError(1005, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại OrderId", ErrorLevel.WARNING, $"Không có order đang được thực hiện.");
|
||||
public static RobotError Error1006(string rootState)
|
||||
=> CreateError(1006, ErrorType.INITIALIZE_ORDER, "Vui lòng chờ robot sẵn sàng", ErrorLevel.WARNING, $"Robot chưa sẵn sàng để nhận Order. Trạng thái hiện tại {rootState}");
|
||||
public static RobotError Error1007()
|
||||
=> CreateError(1007, ErrorType.VALIDATION_ERROR, "Vui lòng chờ hoàn thành các action hiện tại.", ErrorLevel.WARNING, $"Không thể khởi tạo order mới khi có action đang thực hiện.");
|
||||
public static RobotError Error1008(string edgeId, string nodeId)
|
||||
=> CreateError(1008, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại order", ErrorLevel.WARNING, $"Order có edge {edgeId} tồn tại startNode {nodeId} không nằm trong danh sách nodes");
|
||||
public static RobotError Error1009(string edgeId, string nodeId)
|
||||
=> CreateError(1009, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại order", ErrorLevel.WARNING, $"Order có edge {edgeId} tồn tại endNode {nodeId} không nằm trong danh sách nodes");
|
||||
public static RobotError Error1010(string lastNodeId, string newStartNodeId)
|
||||
=> CreateError(1010, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại order", ErrorLevel.WARNING, $"Order mới nhận được không phải là nối tiếp của order khi lastNodeId: {lastNodeId} mà node đầu tiên của order mới là: {newStartNodeId}");
|
||||
public static RobotError Error1011(int lastNodeSequenceId, int newStartNodeSequenceId)
|
||||
=> CreateError(1011, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại order", ErrorLevel.WARNING, $"Order mới nhận được không phải là nối tiếp của order khi LastNodeSequenceId: {lastNodeSequenceId} mà node đầu tiên của order mới có sequence: {newStartNodeSequenceId}");
|
||||
public static RobotError Error1012(string nodeId, int sequenceId, int correctIndex)
|
||||
=> CreateError(1012, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại order node sequence", ErrorLevel.WARNING, $"Order Nodes không đúng thứ tự. NodeId: {nodeId}, SequenceId: {sequenceId}, Vị trí đúng: {correctIndex}");
|
||||
public static RobotError Error1013(string edgeId, int sequenceId, int correctIndex)
|
||||
=> CreateError(1013, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại order edge sequence", ErrorLevel.WARNING, $"Order Edges không đúng thứ tự. EdgeId: {edgeId}, SequenceId: {sequenceId}, Vị trí đúng: {correctIndex}");
|
||||
public static RobotError Error1014()
|
||||
=> CreateError(1014, ErrorType.ORDER_ERROR, "", ErrorLevel.WARNING, "Order kết thúc không thành công do module Navigation có lỗi xảy ra");
|
||||
public static RobotError Error1015(string nodeId)
|
||||
=> CreateError(1015, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại order", ErrorLevel.WARNING, $"Order node {nodeId} yêu cầu phải có NodePosition");
|
||||
public static RobotError Error1016(string nodeId, double distance, double allowedDeviation)
|
||||
=> CreateError(1016, ErrorType.ORDER_ERROR, "Robot quá xa node bắt đầu", ErrorLevel.WARNING, $"Robot cách node bắt đầu {nodeId} quá xa. Khoảng cách: {distance:F2}m, cho phép: {allowedDeviation:F2}m");
|
||||
public static RobotError Error1017(string nodeId, double distance, double allowedDeviation)
|
||||
=> CreateError(1017, ErrorType.ORDER_ERROR, "Robot đã ở node đích", ErrorLevel.WARNING, $"Robot đã ở tại hoặc quá gần node đích {nodeId}. Khoảng cách: {distance:F2}m, tối thiểu: {allowedDeviation:F2}m");
|
||||
public static RobotError Error1018(string edgeId)
|
||||
=> CreateError(1018, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại trajectory", ErrorLevel.WARNING, $"Edge {edgeId} có trajectory không hợp lệ: knotVector size phải bằng controlPoints + degree + 1");
|
||||
public static RobotError Error1019(string edgeId)
|
||||
=> CreateError(1019, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại trajectory", ErrorLevel.WARNING, $"Edge {edgeId} có trajectory không hợp lệ: knotVector phải là dãy tăng dần từ 0 đến 1");
|
||||
public static RobotError Error1020(string edgeId)
|
||||
=> CreateError(1020, ErrorType.ORDER_ERROR, "Vui lòng kiểm tra lại trajectory", ErrorLevel.WARNING, $"Edge {edgeId} có trajectory không hợp lệ: cần ít nhất 2 controlPoints (điểm bắt đầu và kết thúc)");
|
||||
|
||||
public static RobotError Error2001()
|
||||
=> CreateError(2001, ErrorType.PERIPHERAL_ERROR, "", ErrorLevel.FATAL, "Có lỗi xảy ra trong quá trình đọc tín hiệu từ hệ thống ngoại vi(PLC)");
|
||||
public static RobotError Error2002()
|
||||
=> CreateError(2002, ErrorType.PERIPHERAL_ERROR, "", ErrorLevel.FATAL, "Có lỗi xảy ra trong quá trình gửi tín hiệu tới hệ thống ngoại vi(PLC)");
|
||||
public static RobotError Error2003()
|
||||
=> CreateError(2003, ErrorType.PERIPHERAL_ERROR, "", ErrorLevel.FATAL, "Mất kết nối với hệ thống ngoại vi(PLC)");
|
||||
|
||||
public static RobotError Error3001()
|
||||
=> CreateError(3001, ErrorType.LOCALIZATION_ERROR, "", ErrorLevel.WARNING, "Trạng thái định vị chưa sẵn sàng");
|
||||
}
|
||||
Reference in New Issue
Block a user