Initial commit

This commit is contained in:
2026-07-03 16:37:12 +07:00
commit 63b8c1ea8b
1931 changed files with 640587 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
using RobotNet.VDA5050.Type;
using RobotNet10.RobotApp.Client.Pages;
using RobotNet10.RobotApp.Interfaces;
using RobotNet10.RobotApp.Modules;
namespace RobotNet10.RobotApp.Services.Robot.Actions;
[RobotAction(ActionType.DROP,
[ActionScope.INSTANT, ActionScope.NODE, ActionScope.EDGE],
[BlockingType.HARD],
"Hạ thấp pallet.",
"Robot đã hạ thấp pallet.")]
public class RobotDropAction(IServiceProvider ServiceProvider) : RobotAction(ServiceProvider)
{
private const int MAX_TIMEOUT = 60000;
private int CountTimeout = 0;
private ILoad? LoadManager;
private ILiftModule? LiftModule;
private IPlcController? PlcController;
private CancellationTokenSource CancellationToken = new();
protected override async Task StartAction()
{
try
{
LoadManager = ServiceProvider.GetRequiredService<ILoad>();
LiftModule = ServiceProvider.GetRequiredService<ILiftModule>();
PlcController = ServiceProvider.GetRequiredService<IPlcController>();
if (!LiftModule.IsReady)
{
SetStatus(ActionEvent.FAILED);
ResultDescription = "Lift module not ready";
return;
}
CancellationToken = new CancellationTokenSource();
PlcController.SetOperationState(OperationState.Lifting);
await LiftModule.LiftDownAsync(CancellationToken.Token);
CountTimeout = 0;
await base.StartAction();
}
catch (Exception ex)
{
SetStatus(ActionEvent.FAILED);
ResultDescription = $"Drop Failed: {ex.Message}";
}
}
protected override Task StopAction()
{
CancellationToken.Cancel();
return base.StopAction();
}
protected override Task CleanupAction()
{
CancellationToken.Dispose();
PlcController?.SetOperationState(OperationState.None);
return base.CleanupAction();
}
protected override async Task ExecuteAction()
{
if (LiftModule is null)
{
SetStatus(ActionEvent.FAILED);
ResultDescription = "Lift module not found";
}
else if (LiftModule.State == LiftModuleState.Error)
{
SetStatus(ActionEvent.FAILED);
ResultDescription = "Lift module error";
}
else if (LiftModule.Position == LiftPosition.Bottom)
{
LoadManager?.ClearLoad();
SetStatus(ActionEvent.FINISHED);
ResultDescription = string.IsNullOrEmpty(ActionAttribute.ResultDescription) ? "Robot has dropped the load." : ActionAttribute.ResultDescription;
}
else if (CountTimeout++ > MAX_TIMEOUT / ActionInterval)
{
CancellationToken.Cancel();
SetStatus(ActionEvent.FAILED);
ResultDescription = "Timeout action";
}
await base.ExecuteAction();
}
}