fix
This commit is contained in:
@@ -12,6 +12,10 @@ using Microsoft.Speech.Synthesis;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using AGVNavigationCore.Models;
|
||||
using AGVNavigationCore.Controls;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Project
|
||||
{
|
||||
@@ -22,7 +26,13 @@ namespace Project
|
||||
public static bool Automodeonreboot = false;
|
||||
public static bool AutRebootAlreay = false;
|
||||
public static bool DriveSpeed = false;
|
||||
public static AGVControl.MapControl mapctl;
|
||||
public static AGVNavigationCore.Controls.UnifiedAGVCanvas _mapCanvas;
|
||||
public static List<MapNode> _mapNodes;
|
||||
|
||||
/// <summary>
|
||||
/// 가상 AGV (시뮬레이션용)
|
||||
/// </summary>
|
||||
public static VirtualAGV _virtualAGV;
|
||||
|
||||
#region "Hardware"
|
||||
|
||||
@@ -570,5 +580,140 @@ namespace Project
|
||||
|
||||
}
|
||||
|
||||
#region VirtualAGV 실제 데이터 동기화
|
||||
|
||||
/// <summary>
|
||||
/// RFID 읽기 시 해당 노드 위치로 AGV 업데이트
|
||||
/// </summary>
|
||||
/// <param name="rfidId">읽은 RFID ID</param>
|
||||
/// <param name="motorDirection">모터 방향 (Forward/Backward)</param>
|
||||
/// <returns>업데이트 성공 여부</returns>
|
||||
public static bool UpdateAGVFromRFID(string rfidId, AgvDirection motorDirection = AgvDirection.Forward)
|
||||
{
|
||||
if (_virtualAGV == null || _mapNodes == null) return false;
|
||||
|
||||
// RFID에 해당하는 노드 찾기
|
||||
var node = _mapNodes.FirstOrDefault(n => n.RfidId == rfidId);
|
||||
if (node != null)
|
||||
{
|
||||
_virtualAGV.SetPosition(node, motorDirection);
|
||||
RefreshAGVCanvas();
|
||||
|
||||
log.Add($"[AGV] RFID {rfidId} 감지 → 노드 {node.NodeId} 위치 업데이트 (방향: {motorDirection})");
|
||||
return true;
|
||||
}
|
||||
|
||||
log.Add($"[AGV] RFID {rfidId}에 해당하는 노드를 찾을 수 없음");
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 노드ID로 AGV 위치 업데이트
|
||||
/// </summary>
|
||||
/// <param name="nodeId">노드 ID</param>
|
||||
/// <param name="motorDirection">모터 방향 (Forward/Backward)</param>
|
||||
/// <returns>업데이트 성공 여부</returns>
|
||||
public static bool UpdateAGVToNode(string nodeId, AgvDirection motorDirection = AgvDirection.Forward)
|
||||
{
|
||||
if (_virtualAGV == null || _mapNodes == null) return false;
|
||||
|
||||
var node = _mapNodes.FirstOrDefault(n => n.NodeId == nodeId);
|
||||
if (node != null)
|
||||
{
|
||||
_virtualAGV.SetPosition(node, motorDirection);
|
||||
RefreshAGVCanvas();
|
||||
|
||||
log.Add($"[AGV] 노드 {nodeId} 위치로 이동 (방향: {motorDirection})");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 방향 업데이트
|
||||
/// </summary>
|
||||
/// <param name="direction">새로운 방향</param>
|
||||
public static void UpdateAGVDirection(AgvDirection direction)
|
||||
{
|
||||
if (_virtualAGV == null) return;
|
||||
|
||||
_virtualAGV.CurrentDirection = direction;
|
||||
RefreshAGVCanvas();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 상태 업데이트
|
||||
/// </summary>
|
||||
/// <param name="state">새로운 상태</param>
|
||||
public static void UpdateAGVState(AGVState state)
|
||||
{
|
||||
if (_virtualAGV == null) return;
|
||||
|
||||
_virtualAGV.CurrentState = state;
|
||||
RefreshAGVCanvas();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AGV 배터리 레벨 업데이트
|
||||
/// </summary>
|
||||
/// <param name="batteryLevel">배터리 레벨 (0.0 ~ 100.0)</param>
|
||||
public static void UpdateAGVBattery(float batteryLevel)
|
||||
{
|
||||
if (_virtualAGV == null) return;
|
||||
|
||||
_virtualAGV.BatteryLevel = batteryLevel;
|
||||
RefreshAGVCanvas();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 맵 캔버스 강제 갱신 (AGV 위치 표시 업데이트)
|
||||
/// </summary>
|
||||
public static void RefreshAGVCanvas()
|
||||
{
|
||||
if (_mapCanvas != null && _mapCanvas.IsHandleCreated)
|
||||
{
|
||||
_mapCanvas.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 현재 AGV의 노드 ID 가져오기
|
||||
/// </summary>
|
||||
/// <returns>현재 노드 ID</returns>
|
||||
public static string GetCurrentAGVNodeId()
|
||||
{
|
||||
return _virtualAGV?.CurrentNodeId ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 현재 AGV 위치 가져오기
|
||||
/// </summary>
|
||||
/// <returns>현재 위치</returns>
|
||||
public static Point GetCurrentAGVPosition()
|
||||
{
|
||||
return _virtualAGV?.CurrentPosition ?? Point.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 현재 AGV 방향 가져오기
|
||||
/// </summary>
|
||||
/// <returns>현재 방향</returns>
|
||||
public static AgvDirection GetCurrentAGVDirection()
|
||||
{
|
||||
return _virtualAGV?.CurrentDirection ?? AgvDirection.Forward;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 현재 AGV 상태 가져오기
|
||||
/// </summary>
|
||||
/// <returns>현재 상태</returns>
|
||||
public static AGVState GetCurrentAGVState()
|
||||
{
|
||||
return _virtualAGV?.CurrentState ?? AGVState.Idle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user