initial commit
This commit is contained in:
50
Lab505.Script/Sim/SimImr.cs
Normal file
50
Lab505.Script/Sim/SimImr.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Lab505.Script.Facades;
|
||||
|
||||
namespace Lab505.Script.Sim;
|
||||
|
||||
/// <summary>Per-user in-memory IMR simulation. All operations complete after a fixed delay.</summary>
|
||||
public sealed class SimImr : IImrFacade
|
||||
{
|
||||
private const int MoveDelayMs = 1500;
|
||||
private const int ActionDelayMs = 800;
|
||||
|
||||
private string _position = "C1";
|
||||
|
||||
public string Position => _position;
|
||||
public event Action<string>? OnMoved;
|
||||
|
||||
public bool IsAt(string position, double tol = 0.2) =>
|
||||
string.Equals(_position, position, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public async Task GoTo(string position, CancellationToken ct = default)
|
||||
{
|
||||
await Task.Delay(MoveDelayMs, ct);
|
||||
_position = position;
|
||||
OnMoved?.Invoke(_position);
|
||||
}
|
||||
|
||||
public async Task Undock(string fromPosition, CancellationToken ct = default) =>
|
||||
await Task.Delay(ActionDelayMs, ct);
|
||||
|
||||
public async Task Load(CancellationToken ct = default) =>
|
||||
await Task.Delay(ActionDelayMs, ct);
|
||||
|
||||
public async Task Unload(CancellationToken ct = default) =>
|
||||
await Task.Delay(ActionDelayMs, ct);
|
||||
|
||||
public async Task PickUp(int ok, int ng = 0, CancellationToken ct = default) =>
|
||||
await Task.Delay(ActionDelayMs, ct);
|
||||
|
||||
public async Task Pause(CancellationToken ct = default) =>
|
||||
await Task.Delay(ActionDelayMs, ct);
|
||||
|
||||
public async Task Resume(CancellationToken ct = default) =>
|
||||
await Task.Delay(ActionDelayMs, ct);
|
||||
|
||||
public async Task InitPosition(double x, double y, double theta, CancellationToken ct = default) =>
|
||||
await Task.Delay(ActionDelayMs, ct);
|
||||
|
||||
public async Task Cancel(CancellationToken ct = default) =>
|
||||
await Task.Delay(200, ct);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user