This commit is contained in:
2025-12-14 22:56:04 +09:00
parent 3c8eae889c
commit a8cb952ea4
2 changed files with 27 additions and 28 deletions

View File

@@ -26,7 +26,6 @@ namespace AGVEmulator
// Map Control // Map Control
private UnifiedAGVCanvas _agvCanvas; private UnifiedAGVCanvas _agvCanvas;
private List<MapNode> _mapNodes;
private VirtualAGV _visualAgv; private VirtualAGV _visualAgv;
// Emulator State // Emulator State
@@ -385,14 +384,12 @@ namespace AGVEmulator
try try
{ {
var mapresult = MapLoader.LoadMapFromFile(mapPath); var mapresult = MapLoader.LoadMapFromFile(mapPath);
_mapNodes = mapresult.Nodes; _agvCanvas.SetMapLoadResult(mapresult);//.Nodes = _mapNodes;
_agvCanvas.Nodes = _mapNodes;
_agvCanvas.FitToNodes();
// Initialize Visual AGV // Initialize Visual AGV
if (_mapNodes.Count > 0) if (_agvCanvas.Nodes.Count > 0)
{ {
_visualAgv = new VirtualAGV("AGV01", _mapNodes[0].Position); _visualAgv = new VirtualAGV("AGV01", _agvCanvas.Nodes[0].Position);
_agvCanvas.AGVList = new List<IAGV> { _visualAgv }; _agvCanvas.AGVList = new List<IAGV> { _visualAgv };
} }
} }
@@ -405,16 +402,16 @@ namespace AGVEmulator
void UpdateVisualAgvPosition(string tag) void UpdateVisualAgvPosition(string tag)
{ {
if (_visualAgv == null || _mapNodes == null) return; if (_visualAgv == null || _agvCanvas.Nodes == null) return;
// Find node by tag // Find node by tag
// Assuming NodeId might be the tag or contain it // Assuming NodeId might be the tag or contain it
var node = _mapNodes.FirstOrDefault(n => n.NodeId == tag || n.NodeId.EndsWith(tag)); var node = _agvCanvas.Nodes.FirstOrDefault(n => n.Id == tag || n.Id.EndsWith(tag));
// If not found, try to parse tag as int and match // If not found, try to parse tag as int and match
if (node == null && int.TryParse(tag, out int tagNum)) if (node == null && int.TryParse(tag, out int tagNum))
{ {
node = _mapNodes.FirstOrDefault(n => n.NodeId == tagNum.ToString()); node = _agvCanvas.Nodes.FirstOrDefault(n => n.Id == tagNum.ToString());
} }
if (node != null) if (node != null)
@@ -575,7 +572,7 @@ private void UpdateVisualAGV()
private void UpdateEmulatorLogic() private void UpdateEmulatorLogic()
{ {
if (_visualAgv == null || _mapNodes == null) return; if (_visualAgv == null || _agvCanvas.Nodes == null) return;
// Initialize float position if needed // Initialize float position if needed
if (_currentPosF.IsEmpty) _currentPosF = _visualAgv.CurrentPosition; if (_currentPosF.IsEmpty) _currentPosF = _visualAgv.CurrentPosition;
@@ -614,18 +611,18 @@ private void UpdateVisualAGV()
_visualAgv.CurrentPosition = Point.Round(_currentPosF); _visualAgv.CurrentPosition = Point.Round(_currentPosF);
// Check for Nodes (RFID Trigger) // Check for Nodes (RFID Trigger)
foreach (var node in _mapNodes) foreach (var node in _agvCanvas.Nodes)
{ {
double dist = Math.Sqrt(Math.Pow(node.Position.X - _visualAgv.CurrentPosition.X, 2) + Math.Pow(node.Position.Y - _visualAgv.CurrentPosition.Y, 2)); double dist = Math.Sqrt(Math.Pow(node.Position.X - _visualAgv.CurrentPosition.X, 2) + Math.Pow(node.Position.Y - _visualAgv.CurrentPosition.Y, 2));
if (dist < 15) // Hit Node if (dist < 15) // Hit Node
{ {
// Send Tag // Send Tag
if (node.NodeId != numericUpDown1.Text) if (node.Id != numericUpDown1.Text)
{ {
if (int.TryParse(node.NodeId, out int tag)) if (int.TryParse(node.Id, out int tag))
{ {
AGV.SendTag(node.NodeId); AGV.SendTag(node.Id);
numericUpDown1.Text = node.NodeId; numericUpDown1.Text = node.Id;
// Snap to node // Snap to node
_currentPosF = node.Position; _currentPosF = node.Position;
@@ -665,14 +662,14 @@ private void UpdateVisualAGV()
while (_targetAngle < 0) _targetAngle += 360; while (_targetAngle < 0) _targetAngle += 360;
} }
private void _agvCanvas_NodeRightClicked(object sender, MapNode e) private void _agvCanvas_NodeRightClicked(object sender, NodeBase e)
{ {
if (e != null && _visualAgv != null) if (e != null && _visualAgv != null)
{ {
_visualAgv.CurrentPosition = e.Position; _visualAgv.CurrentPosition = e.Position;
_currentPosF = e.Position; _currentPosF = e.Position;
if (int.TryParse(e.NodeId, out int tag)) if (int.TryParse(e.Id, out int tag))
{ {
numericUpDown1.Text = tag.ToString(); numericUpDown1.Text = tag.ToString();
} }
@@ -796,6 +793,13 @@ private void UpdateVisualAGV()
private void toolStripButton3_Click(object sender, EventArgs e) private void toolStripButton3_Click(object sender, EventArgs e)
{ {
var file = @"C:\Data\Amkor\AGV4\route\NewMap.agvmap"; var file = @"C:\Data\Amkor\AGV4\route\NewMap.agvmap";
if(System.IO.File.Exists(file)==false)
{
var od = new OpenFileDialog();
od.Filter = "json|*.json";
if (od.ShowDialog() != DialogResult.OK) return;
file = od.FileName;
}
LoadMapFile(file); LoadMapFile(file);
} }
private string _currentMapFilePath; private string _currentMapFilePath;
@@ -809,13 +813,8 @@ private void UpdateVisualAGV()
{ {
Console.WriteLine($"Map File Load : {filePath}"); Console.WriteLine($"Map File Load : {filePath}");
_mapNodes = result.Nodes;
_currentMapFilePath = filePath;
// RFID 자동 할당 제거 - 에디터에서 설정한 값 그대로 사용
// 시뮬레이터 캔버스에 맵 설정 // 시뮬레이터 캔버스에 맵 설정
this._agvCanvas.Nodes = _mapNodes; this._agvCanvas.SetMapLoadResult(result);// = _mapNodes;
// 맵 설정 적용 (배경색, 그리드 표시) // 맵 설정 적용 (배경색, 그리드 표시)
if (result.Settings != null) if (result.Settings != null)
@@ -871,17 +870,17 @@ private void UpdateVisualAGV()
} }
} }
if (!string.IsNullOrEmpty(input) && _mapNodes != null && _visualAgv != null) if (!string.IsNullOrEmpty(input) && _agvCanvas.Nodes != null && _visualAgv != null)
{ {
var node = _mapNodes.FirstOrDefault(n => n.NodeId == input); var node = _agvCanvas.Nodes.FirstOrDefault(n => n.Id == input);
if (node != null) if (node != null)
{ {
_visualAgv.CurrentPosition = node.Position; _visualAgv.CurrentPosition = node.Position;
_currentPosF = node.Position; _currentPosF = node.Position;
numericUpDown1.Text = node.NodeId; numericUpDown1.Text = node.Id;
// Auto-orient: Prefer Right (0) or Up (270) // Auto-orient: Prefer Right (0) or Up (270)
var neighbors = _mapNodes.Where(n => n != node && var neighbors = _agvCanvas.Nodes.Where(n => n != node &&
Math.Sqrt(Math.Pow(n.Position.X - node.Position.X, 2) + Math.Pow(n.Position.Y - node.Position.Y, 2)) < 150) Math.Sqrt(Math.Pow(n.Position.X - node.Position.X, 2) + Math.Pow(n.Position.Y - node.Position.Y, 2)) < 150)
.ToList(); .ToList();

Submodule Cs_HMI/SubProject/EnigProtocol updated: 82bca1c90b...2a5bb77dab