initial commit

This commit is contained in:
robotics_x1
2026-10-12 15:24:08 +07:00
commit 55228b3772
367 changed files with 162893 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
namespace Lab505.Shared;
public enum AsrsCoilAddress : ushort
{
// AUTO MODE
AUTO_MODE = 0x0BB6, // M950
// START System
START_SYSTEM = 0x0834, // M52
// MODE for picking up from conveyor to trays 3 and 4
MODE_PICK_FROM_CONVEYOR_3_4 = 0x08C8, // M200
// MODE for picking empty boxes from conveyor to trays 1 and 2
MODE_PICK_FROM_CONVEYOR_1_2 = 0x0ACB, // M715
// Return items to trays
RETURN_TRAY_X3 = 0x08CA, // M202
RETURN_TRAY_X3_SUCCESS = 0x08CF, // M207
RETURN_TRAY_X2 = 0x08DE, // M222
RETURN_TRAY_X2_SUCCESS = 0x08E3, // M227
RETURN_TRAY_X1 = 0x08F2, // M242
RETURN_TRAY_X1_SUCCESS = 0x08F7, // M247
// MODE for picking empty boxes from trays 1 and 2
MODE_PICK_EMPTY_BOX_1_2 = 0x092C, // M300
// MODE for picking up from trays 3 and 4 to conveyor
MODE_PICK_EMPTY_BOX_3_4 = 0x0ACA, // M714
// Pick empty boxes from trays
PICK_EMPTY_BOX_X3 = 0x092E, // M302
PICK_EMPTY_BOX_X3_SUCCESS = 0x0933, // M307
M314 = 0x093A, // M314
PICK_EMPTY_BOX_X2 = 0x0942, // M322
PICK_EMPTY_BOX_X2_SUCCESS = 0x08E3, // M227
PICK_EMPTY_BOX_X1 = 0x0956, // M342
PICK_EMPTY_BOX_X1_SUCCESS = 0x095B, // M347
FULL_TRAY_ALERT_13 = 0x093E, //M318
FULL_TRAY_ALERT_12 = 0x0952, //M338
FULL_TRAY_ALERT_11 = 0x0966, //M358
FULL_TRAY_ALERT_23 = 0x093F, //M319
FULL_TRAY_ALERT_22 = 0x0953, //M339
FULL_TRAY_ALERT_21 = 0x0967, //M359
FULL_TRAY_ALERT_33 = 0x08D0, // M208
FULL_TRAY_ALERT_32 = 0x08E4, // M228
FULL_TRAY_ALERT_31 = 0x08F8, // M248
FULL_TRAY_ALERT_43 = 0x08D1, // M209
FULL_TRAY_ALERT_42 = 0x08E5, // M229
FULL_TRAY_ALERT_41 = 0x08F9, // M249
// Reset full tray alerts
RESET_FULL_TRAY_ALERT = 0x08FB, // M251
// Cancel selection and clear tray
CANCEL_SELECTION = 0x0833, // M51
// Emergency Stop (Red Light)
EMERGENCY_STOP = 0x0990, // M400
// LIDAR (Front and Rear)
LIDAR_FRONT = 0x09B8, // M430
LIDAR_REAR = 0x09BB, // M443
// Safety Mode
SAFETY_MODE = 0x09C2, // M450
SYSTEM_HOMING = 0x0B20, // M451
SYSTEM_HOMING_SUCCESS = 0x0B2F // M815
}

View File

@@ -0,0 +1,19 @@
namespace Lab505.Shared;
/// <summary>
/// Full ASRS state pushed via SignalR.
/// Includes tray coils, safety mode, busy/locked status.
/// LockedOps contains the set of operation keys currently locked by the driver
/// (e.g. "X1_S34", "X2_S12" — one lock held during each ASRS operation).
/// </summary>
public record AsrsPushDto(
bool? X11, bool? X12, bool? X13,
bool? X21, bool? X22, bool? X23,
bool? X31, bool? X32, bool? X33,
bool? X41, bool? X42, bool? X43,
bool? SAFETY_MODE,
bool IsOffline,
bool IsBusy,
string[] LockedOps,
string? LastError // lỗi thực thi lệnh ASRS gần nhất (null = OK)
);

View File

@@ -0,0 +1,23 @@
namespace Lab505.Shared;
/// <summary>
/// Conveyor coil addresses
/// </summary>
public enum ConveyorCoilAddress : ushort
{
C1IMRin = 0x0864, //100
C1In = 0x0867, //103
C1Out = 0x0869, //105 2153
C1IMRout = 0x086C, //108
C1HasGoods = 0x088C,//140
C1NotGoods = 0x088D,//141
C1Ready = 0x08C6,//198
C2In = 0x086E, //110
C2Out = 0x0871, //113
C2HasGoods = 0x0891,//145
C2NotGoods = 0x0892,//146
C2Ready = 0x08C5,//197
}

View File

@@ -0,0 +1,21 @@
namespace Lab505.Shared;
/// <summary>
/// Full conveyor state pushed via SignalR.
/// Uses nullable bool: null = not yet read (offline), true/false = actual coil state.
/// </summary>
public record ConveyorPushDto(
bool? C1In,
bool? C1Out,
bool? C1IMRin,
bool? C1IMRout,
bool? C1HasGoods,
bool? C1NotGoods,
bool? C1Ready,
bool? C2In,
bool? C2Out,
bool? C2HasGoods,
bool? C2NotGoods,
bool? C2Ready,
string? WriteError // lỗi ghi coil gần nhất (null = OK)
);

View File

@@ -0,0 +1,32 @@
namespace Lab505.Shared;
/// <summary>
/// Shared constants for SignalR hubs — used by both server and WASM client.
/// </summary>
public static class HubContracts
{
// ── Hub routes ────────────────────────────────────────────────
public const string StateHubRoute = "/stateHub";
public const string ScriptHubRoute = "/scriptHub";
// ── StateHub: server → client push events ─────────────────────
public const string ImrStateEvent = "imr-state";
public const string AmrStateEvent = "amr-state";
public const string ConveyorStateEvent = "conveyor-state";
public const string AsrsStateEvent = "asrs-state";
public const string WorkflowStateEvent = "workflow-state";
public const string SystemStateEvent = "system-state";
// ── Notification: server → client (lệnh gửi / hoàn thành / lỗi) ──
public const string NotificationEvent = "notification";
// ── Lock state: server → client push events ───────────────────
public const string LockStateEvent = "lock-state";
// ── Mode change: server → specific user (T3 remote switch) ───
public const string ModeChangedEvent = "mode-changed";
// ── ScriptHub: server → client push events ────────────────────
public const string ScriptLogEvent = "scriptLog";
public const string SimPanelStateEvent = "sim-panel-state";
}

View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.3.9" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="5.3.0" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="10.0.6" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,10 @@
namespace Lab505.Shared;
public record LockStateDto(
LockHolderDto? Workflow,
IReadOnlyList<WaiterDto> WorkflowQueue,
Dictionary<string, LockHolderDto?> Groups,
Dictionary<string, IReadOnlyList<WaiterDto>> GroupQueues);
public record LockHolderDto(string UserId, string Name, long ExpiresMs, long RemainingMs);
public record WaiterDto(string UserId, string Name, bool IsPriority);

View File

@@ -0,0 +1,16 @@
namespace Lab505.Shared;
/// <summary>Một thông báo ngắn được push từ server xuống client qua SignalR.</summary>
/// <param name="Message">Nội dung thông báo gốc.</param>
/// <param name="Level">Mức độ: "info" | "success" | "error" | "warning".</param>
/// <param name="Toast">Cho phép hiện snackbar/toast.</param>
/// <param name="Source">Nguồn phát sinh: IMR, AMR, WF, ASRS, OPC...</param>
/// <param name="Command">Sự kiện/chủ đề chính để render cột command.</param>
/// <param name="Detail">Chi tiết bổ sung đi kèm command.</param>
public record NotificationDto(
string Message,
string Level = "info",
bool Toast = false,
string? Source = null,
string? Command = null,
string? Detail = null);

View File

@@ -0,0 +1,35 @@
namespace Lab505.Shared;
/// <summary>
/// Hằng số vị trí và tham số lùi robot — nguồn duy nhất cho toàn hệ thống.
/// Thay đổi ở đây tự động áp dụng vào SystemCondition, FlowService, drivers và simulation.
/// </summary>
public static class RobotPositions
{
// ── IMR docked positions ───────────────────────────────────────
public const double IMR_C1_X = -0.1, IMR_C1_Y = -5.2;
public const double IMR_ABB_X = 1.35, IMR_ABB_Y = -0.8;
// ── IMR undock parameters ──────────────────────────────────────
/// Khoảng lùi khỏi C1 (m) — gửi âm: UndockFromStation_IMR(-IMR_UNDOCK_C1, ...)
public const double IMR_UNDOCK_C1 = 2.2;
/// Khoảng lùi khỏi ABB (m)
public const double IMR_UNDOCK_ABB = 1.2;
/// Vận tốc lùi mặc định (m/s)
public const double IMR_UNDOCK_VEL = 0.2;
// ── AMR docked positions ───────────────────────────────────────
public const double AMR_CAP1_X = 6.0, AMR_CAP1_Y = 0.2;
public const double AMR_CAP2_X = -0.7, AMR_CAP2_Y = -3.19;
public const double AMR_HOME_X = 0.0, AMR_HOME_Y = 0.0;
// ── AMR undocked positions ─────────────────────────────────────
/// Vị trí AMR sau khi UndockFromStation khỏi Cap1 (NBR=true / ActionState=FINISHED).
/// Đọc X_Vda, Y_Vda tại thời điểm đó để lấy giá trị thực tế.
public const double AMR_UNDOCK_CAP1_X = 5.1, AMR_UNDOCK_CAP1_Y = 0.2; // TODO: đo thực tế
/// Vị trí AMR sau khi UndockFromStation khỏi Cap2.
public const double AMR_UNDOCK_CAP2_X = -0.71, AMR_UNDOCK_CAP2_Y = -2.19;
// ── Position matching tolerance ────────────────────────────────
public const double POS_TOL = 0.2;
}

View File

@@ -0,0 +1,27 @@
namespace Lab505.Shared;
/// <summary>
/// Robot state pushed via SignalR for both IMR and AMR.
/// DobotStatus_Opc / CodeDobotStatus_Opc are only meaningful for the IMR.
/// </summary>
public record RobotStateDto(
double X,
double Y,
bool IsOnline,
bool? NewBaseRequest,
List<string> Errors,
ActionStateDto[] Actions,
// IMR-only OPC fields (zero-value for AMR)
string DobotStatus_Opc,
uint CodeDobotStatus_Opc,
RobotErrorDto[] RawErrors
);
public record ActionStateDto(string ActionID, string? ActionStatus);
/// <summary>VDA 5050 error với đầy đủ ErrorType, ErrorLevel, ErrorDescription.</summary>
public record RobotErrorDto(
string? ErrorType,
string? ErrorLevel,
string? ErrorDescription
);

View File

@@ -0,0 +1,12 @@
namespace Lab505.Shared;
/// <summary>
/// Sim panel state snapshot pushed to a specific user's ScriptHub connection
/// so their panels reflect their isolated simulation state.
/// </summary>
public record SimPanelStateDto(
string ImrPosition,
string AmrPosition,
bool IsRunning,
ConveyorPushDto Conveyor
);

View File

@@ -0,0 +1,6 @@
namespace Lab505.Shared;
/// <summary>
/// System-level state pushed via SignalR (operation mode + connection status).
/// </summary>
public record SystemStateDto(bool IsSimulation, bool OpcUaConnected);

View File

@@ -0,0 +1,24 @@
namespace Lab505.Shared;
/// <summary>
/// Workflow state pushed via SignalR.
/// </summary>
public record WorkflowStateDto(
bool IsRunning,
string? LastError,
int CompletedCycles,
string ImrCmd, // "" = idle, "undocking" = undock in progress
string AmrCmd, // "" = idle, "undocking" = undock in progress
bool ImrBusy, // manual command đang chạy
string? ImrBusyLabel, // label lệnh đang chạy (nút nào bị khóa)
string? ImrNextLabel, // lệnh đang xếp hàng chờ (null = không có)
bool AmrBusy,
string? AmrBusyLabel, // label lệnh đang chạy AMR
string? AmrNextLabel,
string? ImrExecError, // lỗi thực thi lệnh thủ công IMR gần nhất
string? AmrExecError, // lỗi thực thi lệnh thủ công AMR gần nhất
bool DobotBusy,
string? DobotBusyLabel,
string? DobotNextLabel,
string? DobotExecError
);