Initial commit

This commit is contained in:
2026-07-13 09:25:40 +07:00
parent c08ff54676
commit bccfb156d7
1938 changed files with 641646 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
namespace RobotNet10.RobotApp.Services.Robot;
/// <summary>
/// Modbus coil addresses aligned with PLC mapping document.
/// Input (read): 2848-2879 (M800-M821 sensors, M825-M831 speed SLS).
/// Output (write): 2948-2977 (M900-M909 state, M915-M917 operation, M920-M929 actions).
/// </summary>
public partial class RobotPlcController
{
// === Input coils: ReadOnlyStartAddress 2848 (0x0b20), offsets vs 2848 ===
public static readonly ushort ReadOnlyStartAddress = 0x0b20; // 2848, M800
public static readonly ushort EmergencyOffsetAddress = 0; // M800 EMC
public static readonly ushort BumperOffsetAddress = 1; // M801 Bumper
public static readonly ushort LidarFrontProtectFieldOffsetAddress = 2; // M802 Lidar NS3-FR
public static readonly ushort LidarBackProtectFieldOffsetAddress = 3; // M803 Lidar NS3-RR
public static readonly ushort LidarFrontTimProtectFieldOffsetAddress = 4; // M804 Lidar TIM718S-FR
public static readonly ushort LiftedUpOffsetAddress = 5; // M805 Lift up limit
public static readonly ushort LiftedDownOffsetAddress = 6; // M806 Lift down limit
public static readonly ushort LiftHomeOffsetAddress = 7; // M807 Rotate homing
public static readonly ushort LeftMotorReadyOffsetAddress = 8; // M808
public static readonly ushort RightMotorReadyOffsetAddress = 9; // M809
public static readonly ushort LiftMotorReadyOffsetAddress = 10; // M810
public static readonly ushort SwitchLockOffsetAddress = 11; // M811 Lock
public static readonly ushort SwitchAutoOffsetAddress = 12; // M812 Auto
public static readonly ushort SwitchManualOffsetAddress = 13; // M813 Manual
public static readonly ushort StartButtonOffsetAddress = 14; // M814 Start
public static readonly ushort ResetButtonOffsetAddress = 15; // M815 Reset
public static readonly ushort StopButtonOffsetAddress = 16; // M816 Stop
public static readonly ushort HasLoadOffsetAddress = 17; // M817 Báo có tải
public static readonly ushort EnabledChargerOffsetAddress = 18; // M818 PLC charging contact
public static readonly ushort ResponseChargingOffsetAddress = 19; // M819 Response Charging
public static readonly ushort MutedBaseOffsetAddress = 20; // M820 Response Muted Base
public static readonly ushort MutedLoadOffsetAddress = 21; // M821 Response Muted Load
// Speed SLS: 2873-2879 (M825-M831)
public static readonly ushort SpeedLimitReadAddress = 0x0b39; // 2873, M825
public static readonly ushort SpeedRange = 7;
public static readonly ushort SpeedVerySlowOffetAddress = 0; // M825 0.15
public static readonly ushort SpeedSlowOffetAddress = 1; // M826 0.25
public static readonly ushort SpeedNormalOffetAddress = 2; // M827 0.55
public static readonly ushort SpeedMediumOffetAddress = 3; // M828 0.9
public static readonly ushort SpeedOptimalOffetAddress = 4; // M829 1.28
public static readonly ushort SpeedFastOffetAddress = 5; // M830 1.6
public static readonly ushort SpeedVeryFastOffetAddress = 6; // M831 1.9 Overspeed
// Robot state: 2948-2957 (M900-M909 INIT, PAUSE, IDLE, PROCESSING, DOCKING, MAINTENANCE, MANUAL, OVERRIDE, CHARGING, Error)
public static readonly ushort RobotStateWriteAddress = 0x0b84; // 2948, M900
public static readonly bool[] RobotInitState = [true, false, false, false, false, false, false, false, false, false];
public static readonly bool[] RobotPauseState = [false, true, false, false, false, false, false, false, false, false];
public static readonly bool[] RobotIdleState = [false, false, true, false, false, false, false, false, false, false];
public static readonly bool[] RobotProccessingState = [false, false, false, true, false, false, false, false, false, false];
public static readonly bool[] RobotDockingState = [false, false, false, false, true, false, false, false, false, false];
public static readonly bool[] RobotMaintenanceState = [false, false, false, false, false, true, false, false, false, false];
public static readonly bool[] RobotManualState = [false, false, false, false, false, false, true, false, false, false];
public static readonly bool[] RobotOverrideState = [false, false, false, false, false, false, false, true, false, false];
public static readonly bool[] RobotCharingState = [false, false, false, false, false, false, false, false, true, false];
public static readonly bool[] RobotErrorState = [false, false, false, false, false, false, false, false, false, true];
// Movement/lift: 2963-2965 (M915 Moving, M916 Lifting, M917 Rotating)
public static readonly ushort RobotOperationWriteAddress = 0x0b93; // 2963, M915
public static readonly bool[] RobotExecuteClearState = [false, false, false];
public static readonly bool[] RobotExecuteMoveState = [true, false, false];
public static readonly bool[] RobotExecuteLiftingState = [false, true, false];
public static readonly bool[] RobotExecuteLiftRotatingState = [false, false, true];
// M918 Bật đèn — coil 2966 (TCP address)
public static readonly ushort SetLightOnAddress = 0x0b96; // 2966, M918 Bật đèn
// Actions: 2968-2977 (M920-M929)
public static readonly ushort EnableChargerAddress = 0x0b98; // 2968 M920 Bắt tiếp điểm
public static readonly ushort SetHorizontalLoadAddress = 0x0b99; // 2969 M921 Báo tải nằm ngang
public static readonly ushort SetMutedBaseAddress = 0x0b9a; // 2970 M922 Set Muted Base
public static readonly ushort SetMutedLoadAddress = 0x0b9b; // 2971 M923 Muted Load
public static readonly ushort SetRFModeAddress = 0x0b9c; // 2972 M924-M926 RF Default/Maintenance/Override
public static readonly bool[] RFModeNone = [false, false, false];
public static readonly bool[] RFModeDefault = [true, false, false];
public static readonly bool[] RFModeMaintenance = [false, true, false];
public static readonly bool[] RFModeOverride = [false, false, true];
public static readonly ushort SetHasLoadAddress = 0x0b9f; // 2975 M927 Báo có tải
public static readonly ushort SetRFEStopAddress = 0x0ba0; // 2976 M928 EMC RF Remote
public static readonly ushort SetBatteryLowAddress = 0x0ba1; // 2977 M929 Pin yếu
/// <summary>Ghi M815 Alarm Reset xuống PLC — cùng coil với nút M815 (2848+15=2863), pulse ON rồi OFF để PLC alarm reset.</summary>
public static readonly ushort AlarmResetM815WriteAddress = (ushort)(ReadOnlyStartAddress + ResetButtonOffsetAddress); // 2863 M815
// Hướng di chuyển: truyền xuống PLC — tiến M931, lùi M932, không đi thì cả 2 off
public static readonly ushort DirectionForwardAddress = 0x0ba3; // 2979 M931 Tiến
public static readonly ushort DirectionBackwardAddress = 0x0ba4; // 2980 M932 Lùi
// Lift module: Homing (pulse), Velocity (up/down coils), Position (holding register 32-bit)
public static readonly ushort LiftHomingAddress = 0x0ba5; // M933 Lift homing (pulse)
public static readonly ushort LiftVelocityUpAddress = 0x0ba6; // M934 Lift lên (velocity)
public static readonly ushort LiftVelocityDownAddress = 0x0ba7; // M935 Lift xuống (velocity)
public static readonly ushort LiftTargetPositionRegister = 0x0bc0; // D register: target position (32-bit = 2 registers). 10000 = 0.01m
public static readonly ushort LiftGoToPositionAddress = 0x0ba8; // M936 Trigger di chuyển đến vị trí (pulse)
}