Initial commit

This commit is contained in:
2026-07-03 16:31:37 +07:00
commit 899c7c637d
1939 changed files with 641750 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using RobotNet10.FleetManager.Script;
namespace RobotNet10.FleetManager.Services.Script;
public class ScriptLayoutManager : ILayoutManager
{
public Task<RobotNet.VDA5050.InstantAction.Action> GetAction(string layout, string version, string level, string name, string robotId)
{
throw new NotImplementedException();
}
public Task<INode> GetNode(string layout, string version, string level, string name)
{
throw new NotImplementedException();
}
public Task<IStation> GetStation(string layout, string version, string level, string name)
{
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,52 @@
using RobotNet10.FleetManager.Script;
using RobotNet10.FleetManager.Services.RobotController;
namespace RobotNet10.FleetManager.Services.Script;
public class ScriptRobot(string robotId, string robotName, Guid modelId, Guid? mapId, IRobotController robotController) : IRobot
{
public string RobotId { get; } = robotId;
public string Name { get; } = robotName;
public Guid ModelId { get; } = modelId;
public Guid? MapId { get; } = mapId;
public RobotState State => new( robotController.IsReady,
robotController.Data.State?.BatteryState.BatteryVoltage ?? 0,
robotController.Data.State?.Loads ?? [],
robotController.Data.State?.BatteryState.Charging ?? false,
robotController.Data.Visualization?.AgvPosition.X ?? 0,
robotController.Data.Visualization?.AgvPosition.Y ?? 0,
robotController.Data.Visualization?.AgvPosition.Theta ?? 0);
public Task AbortMovement()
{
throw new NotImplementedException();
}
public async Task<RobotResult> Execute(RobotNet.VDA5050.InstantAction.Action action, CancellationToken cancellationToken)
{
var result = await robotController.SendInstantActionAsync(action, cancellationToken);
return new(result.IsSuccess, result.Message);
}
public async Task<RobotResult> MoveToNode(string nodeName, CancellationToken cancellationToken)
{
var result = await robotController.MoveToNodeAsync(nodeName, null, cancellationToken);
return new(result.IsSuccess, result.Message);
}
public async Task<RobotResult> MoveToNode(string nodeName, double lastAngle, CancellationToken cancellationToken)
{
var result = await robotController.MoveToNodeAsync(nodeName, lastAngle, cancellationToken);
return new(result.IsSuccess, result.Message);
}
public async Task<RobotResult> MoveToStation(string stationName, StationAction action, CancellationToken cancellationToken)
{
var result = await robotController.MoveToStationAsync(stationName, action, cancellationToken);
return new(result.IsSuccess, result.Message);
}
}

View File

@@ -0,0 +1,53 @@
using RobotNet10.FleetManager.Script;
using RobotNet10.FleetManager.Services.RobotManager;
using RobotNet10.FleetManager.Services.TrafficControl;
using System.Linq.Expressions;
namespace RobotNet10.FleetManager.Services.Script;
public class ScriptRobotmanager(IRobotManagerService RobotManager, IServiceScopeFactory ScopeFactory, IOrderControlService OrderControlService) : IRobotManager
{
public async Task<IRobot?> GetRobotById(string robotId)
{
using var scope = ScopeFactory.CreateScope();
var _robotService = scope.ServiceProvider.GetRequiredService<IRobotService>();
var robotDb = await _robotService.GetByRobotIdAsync(robotId);
if (robotDb is null) return null;
var robotController = RobotManager.GetRobotController(robotId);
if (robotController is null) return null;
return new ScriptRobot(robotDb.RobotId, robotDb.Name, robotDb.ModelId, robotDb.MapId, robotController);
}
public Task<RobotOrderStatus> GetRobotOrderStatus(string robotId)
{
var orderStatus = OrderControlService.GetRobotOrderStatus(robotId);
return orderStatus switch
{
OrderStatus.IsError => Task.FromResult(RobotOrderStatus.IsError),
OrderStatus.IsCompleted => Task.FromResult(RobotOrderStatus.IsCompleted),
OrderStatus.IsProccessing => Task.FromResult(RobotOrderStatus.IsProccessing),
OrderStatus.IsCanceled => Task.FromResult(RobotOrderStatus.IsCanceled),
_ => Task.FromResult(RobotOrderStatus.Empty),
};
}
public Task<RobotState?> GetRobotState(string robotId)
{
var robotController = RobotManager.GetRobotController(robotId);
if (robotController is null || robotController.Data is null || robotController.Data.State is null || robotController.Data.Visualization is null) return Task.FromResult<RobotState?>(null);
return Task.FromResult<RobotState?>(new RobotState(robotController.IsReady,
robotController.Data.State.BatteryState.BatteryVoltage ?? 0,
robotController.Data.State.Loads,
robotController.Data.State.BatteryState.Charging,
robotController.Data.Visualization.AgvPosition.X,
robotController.Data.Visualization.AgvPosition.Y,
robotController.Data.Visualization.AgvPosition.Theta));
}
public async Task<IEnumerable<string>> SearchRobots(string layout, string version, string level, string model)
=> await RobotManager.GetAvailableRobots(layout, version, level, model, state => true);
public async Task<IEnumerable<string>> SearchRobots(string layout, string version, string level, string model, Expression<Func<RobotState, bool>> expr)
=> await RobotManager.GetAvailableRobots(layout, version, level, model, expr.Compile());
}