227 lines
8.8 KiB
Plaintext
227 lines
8.8 KiB
Plaintext
@using Lab505.Shared
|
|
@implements IAsyncDisposable
|
|
|
|
<MudPaper Elevation="0" Class="pa-3" Style="background:transparent;">
|
|
|
|
<MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center"
|
|
Style="cursor:pointer" @onclick="ToggleExpand">
|
|
<MudText Typo="Typo.subtitle1">IMR</MudText>
|
|
<MudIcon Icon="@(_expanded ? Icons.Material.Filled.ExpandMore : Icons.Material.Filled.ExpandLess)" Size="Size.Small" />
|
|
</MudStack>
|
|
|
|
<div class="status-row mt-2">
|
|
<MudIcon Icon="@Icons.Material.Filled.Circle" Size="Size.Small" Color="@StatusColor" />
|
|
<div>
|
|
<MudText Typo="Typo.caption">@StatusText.ToUpper()</MudText>
|
|
<MudText Typo="Typo.caption" Style="color:#9a9a9a;">
|
|
Errors: @(State.Imr.Errors is { Count: > 0 } errors ? string.Join(", ", errors) : "none")
|
|
</MudText>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-1 mb-1">
|
|
<MudButton FullWidth="true" Variant="Variant.Outlined" Color="Color.Error" Size="Size.Small" OnClick="Cancel" Disabled="@(!State.CanControl)">Cancel</MudButton>
|
|
</div>
|
|
|
|
@if (_expanded)
|
|
{
|
|
<MudText Typo="Typo.caption" Class="sec-title mt-2">Move</MudText>
|
|
<div class="op-grid-2">
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="MoveToC1" Disabled="@IsLocked("MoveTo Bt1")">C1</MudButton>
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="MoveToAbb" Disabled="@IsLocked("MoveTo Abb")">ABB</MudButton>
|
|
</div>
|
|
<MudText Typo="Typo.caption" Class="sec-title mt-2">Action</MudText>
|
|
<div class="op-grid-2">
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="Load" Disabled="@IsLocked("Load")">Load</MudButton>
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="Unload" Disabled="@IsLocked("Unload")">Unload</MudButton>
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="UndockFromC1" Disabled="@IsLocked("Undock")">MS@(RobotPositions.IMR_UNDOCK_C1)m</MudButton>
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="UndockFromAbb" Disabled="@IsLocked("Undock")">MS@(RobotPositions.IMR_UNDOCK_ABB)m</MudButton>
|
|
</div>
|
|
<MudText Typo="Typo.caption" Class="sec-title mt-2">NAV</MudText>
|
|
<div class="op-grid">
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="Resume">Resume</MudButton>
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="Pause">Pause</MudButton>
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="Reset">Reset</MudButton>
|
|
</div>
|
|
<div class="op-grid-4 mt-2">
|
|
<MudNumericField T="double?" @bind-Value="_poseX" Placeholder="X" Variant="Variant.Outlined"
|
|
Format="F3" Step="0.01" Culture="@System.Globalization.CultureInfo.InvariantCulture"
|
|
HideSpinButtons="true" Class="pnl-num" />
|
|
<MudNumericField T="double?" @bind-Value="_poseY" Placeholder="Y" Variant="Variant.Outlined"
|
|
Format="F3" Step="0.01" Culture="@System.Globalization.CultureInfo.InvariantCulture"
|
|
HideSpinButtons="true" Class="pnl-num" />
|
|
<MudNumericField T="double?" @bind-Value="_poseYaw" Placeholder="Yaw" Variant="Variant.Outlined"
|
|
Format="F3" Step="0.01" Culture="@System.Globalization.CultureInfo.InvariantCulture"
|
|
HideSpinButtons="true" Class="pnl-num" />
|
|
<MudButton Variant="Variant.Outlined" Size="Size.Small" Color="Color.Warning"
|
|
StartIcon="@(_settingPose ? Icons.Material.Filled.HourglassBottom : null)"
|
|
OnClick="RunInitPose" Disabled="@(_settingPose || !State.CanControl)">
|
|
@(_settingPose ? "..." : "InitPose")
|
|
</MudButton>
|
|
</div>
|
|
}
|
|
|
|
</MudPaper>
|
|
|
|
@code {
|
|
[Inject] StateService State { get; set; } = default!;
|
|
[Inject] CommandService Cmd { get; set; } = default!;
|
|
[Inject] ISnackbar Snackbar { get; set; } = default!;
|
|
[Inject] LangService Lang { get; set; } = default!;
|
|
|
|
private bool _expanded = true;
|
|
private double? _poseX;
|
|
private double? _poseY;
|
|
private double? _poseYaw;
|
|
private bool _settingPose;
|
|
private CancellationTokenSource? _initPoseCts;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await State.StartAsync();
|
|
State.ImrChanged += Refresh;
|
|
State.WorkflowChanged += Refresh;
|
|
Lang.LangChanged += Refresh;
|
|
}
|
|
|
|
public ValueTask DisposeAsync()
|
|
{
|
|
State.ImrChanged -= Refresh;
|
|
State.WorkflowChanged -= Refresh;
|
|
Lang.LangChanged -= Refresh;
|
|
CancelInitPose();
|
|
_initPoseCts?.Dispose();
|
|
_initPoseCts = null;
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
|
|
private void ToggleExpand() => _expanded = !_expanded;
|
|
|
|
private void Refresh() => InvokeAsync(StateHasChanged);
|
|
|
|
private string StatusText
|
|
{
|
|
get
|
|
{
|
|
var imr = State.Imr;
|
|
if (!imr.IsOnline) return "off";
|
|
if (imr.Errors.Count > 0) return "error";
|
|
if (imr.NewBaseRequest == false) return "moving";
|
|
return "ok";
|
|
}
|
|
}
|
|
|
|
private Color StatusColor => StatusText switch
|
|
{
|
|
"ok" => Color.Success,
|
|
"moving" => Color.Info,
|
|
"error" => Color.Error,
|
|
_ => Color.Default
|
|
};
|
|
|
|
private bool IsLocked(string label)
|
|
=> !State.CanControl || State.Workflow.ImrBusyLabel == label || State.Workflow.ImrNextLabel == label;
|
|
|
|
private static bool IsNear(double x, double y, double targetX, double targetY)
|
|
=> Math.Abs(x - targetX) < RobotPositions.POS_TOL && Math.Abs(y - targetY) < RobotPositions.POS_TOL;
|
|
|
|
private bool IsDocked()
|
|
{
|
|
var imr = State.Imr;
|
|
return IsNear(imr.X, imr.Y, RobotPositions.IMR_C1_X, RobotPositions.IMR_C1_Y)
|
|
|| IsNear(imr.X, imr.Y, RobotPositions.IMR_ABB_X, RobotPositions.IMR_ABB_Y);
|
|
}
|
|
|
|
private bool WarnIfDocked()
|
|
{
|
|
if (!IsDocked() || State.Workflow.ImrCmd == "undocking")
|
|
return false;
|
|
|
|
Snackbar.Add(
|
|
Lang.T("IMR đang docked — lùi trước khi di chuyển!", "IMR is docked — undock before moving!"),
|
|
Severity.Warning);
|
|
return true;
|
|
}
|
|
|
|
private Task MoveToC1() => WarnIfDocked() ? Task.CompletedTask : Cmd.ImrMoveToAsync("Bt1");
|
|
|
|
private Task MoveToAbb() => WarnIfDocked() ? Task.CompletedTask : Cmd.ImrMoveToAsync("Abb");
|
|
|
|
private Task UndockFromC1() => Cmd.ImrUndockAsync(-RobotPositions.IMR_UNDOCK_C1, RobotPositions.IMR_UNDOCK_VEL);
|
|
|
|
private Task UndockFromAbb() => Cmd.ImrUndockAsync(-RobotPositions.IMR_UNDOCK_ABB, RobotPositions.IMR_UNDOCK_VEL);
|
|
|
|
private Task Load() => Cmd.ImrLoadAsync();
|
|
|
|
private Task Unload() => Cmd.ImrUnloadAsync();
|
|
|
|
private Task Resume() => Cmd.ImrResumeAsync();
|
|
|
|
private Task Pause() => Cmd.ImrPauseAsync();
|
|
|
|
private Task Reset() => Cmd.ImrResetOpcAsync();
|
|
|
|
private Task Cancel()
|
|
{
|
|
CancelInitPose();
|
|
_settingPose = false;
|
|
StateHasChanged();
|
|
return Cmd.ImrCancelAsync();
|
|
}
|
|
|
|
private async Task RunInitPose()
|
|
{
|
|
_initPoseCts?.Dispose();
|
|
_initPoseCts = new CancellationTokenSource();
|
|
var ct = _initPoseCts.Token;
|
|
|
|
_settingPose = true;
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
try
|
|
{
|
|
var targetX = _poseX ?? 0;
|
|
var targetY = _poseY ?? 0;
|
|
var targetTheta = _poseYaw ?? 0;
|
|
|
|
// VDA initPosition instant action (thay cho OPC UA InitialPose)
|
|
await Cmd.ImrInitPositionAsync(targetX, targetY, targetTheta, ct);
|
|
Snackbar.Add(
|
|
Lang.T(
|
|
$"Đã gửi InitPosition ({targetX:F2}, {targetY:F2}, {targetTheta:F2})",
|
|
$"InitPosition sent ({targetX:F2}, {targetY:F2}, {targetTheta:F2})"),
|
|
Severity.Success);
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
Snackbar.Add(Lang.T("InitPosition đã huỷ", "InitPosition cancelled"), Severity.Info);
|
|
}
|
|
finally
|
|
{
|
|
_settingPose = false;
|
|
_initPoseCts?.Dispose();
|
|
_initPoseCts = null;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
private void CancelInitPose()
|
|
{
|
|
try
|
|
{
|
|
_initPoseCts?.Cancel();
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
<style>
|
|
.status-row { display:flex; align-items:center; gap:8px; margin-bottom:4px; }
|
|
.sec-title { display:block; color:#9CA3AF; margin-bottom:4px; }
|
|
.op-grid { display:grid; grid-template-columns:repeat(3, 1fr); gap:5px; }
|
|
.op-grid-2 { display:grid; grid-template-columns:1fr 1fr; gap:5px; }
|
|
.op-grid-4 { display:grid; grid-template-columns:repeat(4, 1fr); gap:5px; }
|
|
</style>
|