Initial commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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<ActionParameter> ActionParameters = new List<ActionParameter>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user