From 177309c5c91f7661ff62a0f865940088f82850c5 Mon Sep 17 00:00:00 2001 From: backuppc Date: Mon, 27 Oct 2025 17:13:04 +0900 Subject: [PATCH] feat: Add comprehensive debug logging to path validation functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added detailed debug output to GetNextNodeByDirection() with: - Initial node information (positions, movement vectors) - All candidate nodes evaluation with step-by-step scoring - Score calculations: base score โ†’ motor direction โ†’ magnet direction - Final selection with best score - Added detailed debug output to ValidateDockingDirection() with: - Path validation stage information - Expected vs actual next node comparison - Movement vector analysis for mismatch debugging - Success/failure status for each path segment Debug output includes: - Node IDs, RFIDs, positions, and vectors - Normalized vectors and dot products - Score progression through each bonus/penalty application - Direction consistency analysis - Final scoring results with selection indicators This enables detailed tracing of path prediction and validation issues. ๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Utils/DirectionalHelper.cs | 39 ++++++++++++++++++- .../Utils/DockingValidator.cs | 33 +++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Cs_HMI/AGVLogic/AGVNavigationCore/Utils/DirectionalHelper.cs b/Cs_HMI/AGVLogic/AGVNavigationCore/Utils/DirectionalHelper.cs index c88967b..d8cf020 100644 --- a/Cs_HMI/AGVLogic/AGVNavigationCore/Utils/DirectionalHelper.cs +++ b/Cs_HMI/AGVLogic/AGVNavigationCore/Utils/DirectionalHelper.cs @@ -88,6 +88,19 @@ namespace AGVNavigationCore.Utils MapNode bestNode = null; float bestScore = float.MinValue; + System.Diagnostics.Debug.WriteLine( + $"\n[GetNextNodeByDirection] ========== ๋‹ค์Œ ๋…ธ๋“œ ์„ ํƒ ์‹œ์ž‘ =========="); + System.Diagnostics.Debug.WriteLine( + $" ํ˜„์žฌ๋…ธ๋“œ: {currentNode.NodeId}({currentNode.Position.X:F1}, {currentNode.Position.Y:F1})"); + System.Diagnostics.Debug.WriteLine( + $" ์ด์ „๋…ธ๋“œ: {prevNode.NodeId}({prevNode.Position.X:F1}, {prevNode.Position.Y:F1})"); + System.Diagnostics.Debug.WriteLine( + $" ์ด๋™๋ฒกํ„ฐ: ({movementVector.X:F2}, {movementVector.Y:F2}) โ†’ ์ •๊ทœํ™”: ({normalizedMovement.X:F3}, {normalizedMovement.Y:F3})"); + System.Diagnostics.Debug.WriteLine( + $" ํ˜„์žฌ๋ฐฉํ–ฅ: {direction}, ์ด์ „๋ฐฉํ–ฅ: {prevDirection}, ๋งˆ๊ทธ๋„ท๋ฐฉํ–ฅ: {magnetDirection}"); + System.Diagnostics.Debug.WriteLine( + $" ํ›„๋ณด๋…ธ๋“œ ๊ฐœ์ˆ˜: {candidateNodes.Count}"); + foreach (var candidate in candidateNodes) { var toNextVector = new PointF( @@ -113,7 +126,7 @@ namespace AGVNavigationCore.Utils (normalizedMovement.Y * normalizedToNext.Y); float score; - if (direction == AgvDirection.Forward) + if (direction == prevDirection) { // Forward: ์ง„ํ–‰ ๋ฐฉํ–ฅ๊ณผ ์œ ์‚ฌํ•œ ๋ฐฉํ–ฅ ์„ ํƒ (๋†’์€ ๋‚ด์  = ์ข‹์Œ) score = dotProduct; @@ -124,15 +137,30 @@ namespace AGVNavigationCore.Utils score = -dotProduct; } + System.Diagnostics.Debug.WriteLine( + $"\n [ํ›„๋ณด] {candidate.NodeId}({candidate.Position.X:F1}, {candidate.Position.Y:F1})"); + System.Diagnostics.Debug.WriteLine( + $" ๋ฒกํ„ฐ: ({toNextVector.X:F2}, {toNextVector.Y:F2}), ๊ธธ์ด: {toNextLength:F2}"); + System.Diagnostics.Debug.WriteLine( + $" ์ •๊ทœํ™”๋ฒกํ„ฐ: ({normalizedToNext.X:F3}, {normalizedToNext.Y:F3})"); + System.Diagnostics.Debug.WriteLine( + $" ๋‚ด์ (dotProduct): {dotProduct:F4}"); + System.Diagnostics.Debug.WriteLine( + $" ๊ธฐ๋ณธ์ ์ˆ˜ ({(direction == prevDirection ? "๋ฐฉํ–ฅ์œ ์ง€" : "๋ฐฉํ–ฅ๋ณ€๊ฒฝ")}): {score:F4}"); + // ์ด์ „ ๋ชจํ„ฐ ๋ฐฉํ–ฅ์ด ์ œ๊ณต๋œ ๊ฒฝ์šฐ: ๋ฐฉํ–ฅ ์ผ๊ด€์„ฑ ๋ณด๋„ˆ์Šค ์ถ”๊ฐ€ + var scoreBeforeMotor = score; score = ApplyMotorDirectionConsistencyBonus( score, direction, prevDirection, dotProduct ); + System.Diagnostics.Debug.WriteLine( + $" ๋ชจํ„ฐ๋ฐฉํ–ฅ ์ ์šฉ ํ›„: {scoreBeforeMotor:F4} โ†’ {score:F4}"); // ๋งˆ๊ทธ๋„ท ๋ฐฉํ–ฅ์„ ๊ณ ๋ คํ•œ ์ ์ˆ˜ ์กฐ์ • + var scoreBeforeMagnet = score; score = ApplyMagnetDirectionBonus( score, magnetDirection, @@ -141,14 +169,23 @@ namespace AGVNavigationCore.Utils currentNode, candidate ); + System.Diagnostics.Debug.WriteLine( + $" ๋งˆ๊ทธ๋„ท๋ฐฉํ–ฅ ์ ์šฉ ํ›„: {scoreBeforeMagnet:F4} โ†’ {score:F4}"); if (score > bestScore) { bestScore = score; bestNode = candidate; + System.Diagnostics.Debug.WriteLine( + $" โญ ํ˜„์žฌ ์ตœ๊ณ ์ ์ˆ˜ ์„ ํƒ๋จ!"); } } + System.Diagnostics.Debug.WriteLine( + $"\n ์ตœ์ข…์„ ํƒ: {bestNode?.NodeId ?? "null"} (์ ์ˆ˜: {bestScore:F4})"); + System.Diagnostics.Debug.WriteLine( + $"[GetNextNodeByDirection] ========== ๋‹ค์Œ ๋…ธ๋“œ ์„ ํƒ ์ข…๋ฃŒ ==========\n"); + return bestNode; } diff --git a/Cs_HMI/AGVLogic/AGVNavigationCore/Utils/DockingValidator.cs b/Cs_HMI/AGVLogic/AGVNavigationCore/Utils/DockingValidator.cs index cf954c0..e44e533 100644 --- a/Cs_HMI/AGVLogic/AGVNavigationCore/Utils/DockingValidator.cs +++ b/Cs_HMI/AGVLogic/AGVNavigationCore/Utils/DockingValidator.cs @@ -69,6 +69,17 @@ namespace AGVNavigationCore.Utils if (prevNode != null) { // DirectionalHelper๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์˜ˆ์ƒ๋˜๋Š” ๋‹ค์Œ ๋…ธ๋“œ ํ™•์ธ + System.Diagnostics.Debug.WriteLine( + $"\n[ValidateDockingDirection] ๊ฒฝ๋กœ ๊ฒ€์ฆ ๋‹จ๊ณ„ {i}:"); + System.Diagnostics.Debug.WriteLine( + $" ์ด์ „โ†’ํ˜„์žฌโ†’๋‹ค์Œ: {prevNode.NodeId}({prevNode.RfidId}) โ†’ {curNode.NodeId}({curNode.RfidId}) โ†’ {nextNode.NodeId}({nextNode.RfidId})"); + System.Diagnostics.Debug.WriteLine( + $" ํ˜„์žฌ ๋…ธ๋“œ ์œ„์น˜: ({curNode.Position.X:F1}, {curNode.Position.Y:F1})"); + System.Diagnostics.Debug.WriteLine( + $" ์ด์ „ ๋ชจํ„ฐ๋ฐฉํ–ฅ: {prevDir}, ํ˜„์žฌ ๋ชจํ„ฐ๋ฐฉํ–ฅ: {pathResult.DetailedPath[i].MotorDirection}"); + System.Diagnostics.Debug.WriteLine( + $" ๋งˆ๊ทธ๋„ท๋ฐฉํ–ฅ: {pathResult.DetailedPath[i].MagnetDirection}"); + var expectedNextNode = DirectionalHelper.GetNextNodeByDirection( curNode, prevNode, @@ -78,13 +89,28 @@ namespace AGVNavigationCore.Utils mapNodes ); + System.Diagnostics.Debug.WriteLine( + $" [์˜ˆ์ƒ] GetNextNodeByDirection ๊ฒฐ๊ณผ: {expectedNextNode?.NodeId ?? "null"}"); + System.Diagnostics.Debug.WriteLine( + $" [์‹ค์ œ] DetailedPath ๋‹ค์Œ ๋…ธ๋“œ: {nextNode.NodeId}"); + if (expectedNextNode != null && !expectedNextNode.NodeId.Equals(nextNode.NodeId)) { string error = $"[DockingValidator] โš ๏ธ ๊ฒฝ๋กœ ๋ฐฉํ–ฅ ๋ถˆ์ผ์น˜: " + $"ํ˜„์žฌ={curNode.RfidId}[{curNodeId}] ์ด์ „={prevNode.RfidId}[{(prevNode?.NodeId ?? string.Empty)}] " + $"์˜ˆ์ƒ๋‹ค์Œ={expectedNextNode.RfidId}[{expectedNextNode.NodeId}] ์‹ค์ œ๋‹ค์Œ={nextNode.RfidId}[{nextNodeId}]"; - System.Diagnostics.Debug.WriteLine($"[DockingValidator] โŒ ๋„ํ‚น ๊ฒ€์ฆ ์‹คํŒจ: {error}"); + System.Diagnostics.Debug.WriteLine( + $"[ValidateDockingDirection] โŒ ๊ฒฝ๋กœ ๋ฐฉํ–ฅ ๋ถˆ์ผ์น˜ ๊ฒ€์ถœ!"); + System.Diagnostics.Debug.WriteLine( + $" ์ด๋™ ๋ฒกํ„ฐ:"); + System.Diagnostics.Debug.WriteLine( + $" ์ด์ „โ†’ํ˜„์žฌ: ({(curNode.Position.X - prevNode.Position.X):F2}, {(curNode.Position.Y - prevNode.Position.Y):F2})"); + System.Diagnostics.Debug.WriteLine( + $" ํ˜„์žฌโ†’์˜ˆ์ƒ: ({(expectedNextNode.Position.X - curNode.Position.X):F2}, {(expectedNextNode.Position.Y - curNode.Position.Y):F2})"); + System.Diagnostics.Debug.WriteLine( + $" ํ˜„์žฌโ†’์‹ค์ œ: ({(nextNode.Position.X - curNode.Position.X):F2}, {(nextNode.Position.Y - curNode.Position.Y):F2})"); + System.Diagnostics.Debug.WriteLine($"[ValidateDockingDirection] ์—๋Ÿฌ๋ฉ”์‹œ์ง€: {error}"); return DockingValidationResult.CreateInvalid( LastNode.NodeId, LastNode.Type, @@ -94,6 +120,11 @@ namespace AGVNavigationCore.Utils } + else + { + System.Diagnostics.Debug.WriteLine( + $" โœ… ๊ฒฝ๋กœ ๋ฐฉํ–ฅ ์ผ์น˜!"); + } } } }