using RobotNet.VDA5050.Factsheet; using RobotNet.VDA5050.Type; using RobotNet10.RobotApp.Services.Exceptions; using System.Collections.ObjectModel; namespace RobotNet10.RobotApp.Services.Robot.Actions; [RobotAction(ActionType.ROTATE_KEEP_LIFT, [ActionScope.INSTANT, ActionScope.NODE, ActionScope.EDGE], [BlockingType.HARD], "Xoay robot tại chỗ giữ nguyên trạng thái bàn nâng.", "Robot đã xoay tại chỗ giữ nguyên trạng thái bàn nâng.")] public class RobotRotateKeepLift(IServiceProvider ServiceProvider) : RobotAction(ServiceProvider) { private static readonly ReadOnlyCollection ActionParameters = new List { new() { Key = "angle", Description = "Góc xoay của robot. (rad)", ValueDataType = ValueDataType.FLOAT, IsOptional = false, } }.AsReadOnly(); double Angle = 0; protected override Task StartAction() { SetStatus(ActionEvent.FINISHED); ResultDescription = string.IsNullOrEmpty(ActionAttribute.ResultDescription) ? ResultDescription : ActionAttribute.ResultDescription; return base.StartAction(); } protected override Task ExecuteAction() { return base.ExecuteAction(); } protected override void Initialize() { base.Initialize(); if (ActionParameters.Count > 0) { foreach (var parameterStore in ActionParameters) { if (!parameterStore.IsOptional) { if (Action is null || Action.ActionParameters is null || !Action.ActionParameters.Any(a => a.Key == parameterStore.Key)) throw new ActionException($"Thiếu tham số bắt buộc '{parameterStore.Key}' cho action {Type}."); } } Parameters = Action is null || Action.ActionParameters is null ? [] : Action.ActionParameters; } var anglePara = Parameters.FirstOrDefault(p => p.Key == "angle") ?? throw new ActionException($"Action {Type} không tìm thấy parameter key 'angle'"); var angleParse = double.TryParse(anglePara.Value, out double angleData); if (!angleParse) throw new ActionException($"Action {Type} có parameter 'angle' không đúng kiểu dữ liệu"); Angle = angleData; } }