Kaynağa Gözat

Add NaN/Infinity validation before sending GRBL coordinates

GRBL error:2 ("Numeric value format is not valid") can be caused by
NaN or Infinity values in coordinates. This can happen if:
- y_steps_per_mm = 0 (division by zero in offset calculation)
- gear_ratio = 0 (division by zero in offset calculation)

Now validates coordinates before sending and logs detailed diagnostic
info if invalid values are detected, helping identify the root cause.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
tuanchris 1 hafta önce
ebeveyn
işleme
064762f0c1
1 değiştirilmiş dosya ile 9 ekleme ve 1 silme
  1. 9 1
      modules/core/pattern_manager.py

+ 9 - 1
modules/core/pattern_manager.py

@@ -8,7 +8,7 @@ from datetime import datetime, time as datetime_time
 from tqdm import tqdm
 from modules.connection import connection_manager
 from modules.core.state import state
-from math import pi
+from math import pi, isnan, isinf
 import asyncio
 import json
 # Import for legacy support, but we'll use LED interface through state
@@ -506,6 +506,14 @@ class MotionControlThread:
         # Use provided speed or fall back to state.speed
         actual_speed = speed if speed is not None else state.speed
 
+        # Validate coordinates before sending to prevent GRBL error:2
+        if isnan(new_x_abs) or isnan(new_y_abs) or isinf(new_x_abs) or isinf(new_y_abs):
+            logger.error(f"Motion thread: Invalid coordinates detected - X:{new_x_abs}, Y:{new_y_abs}")
+            logger.error(f"  theta:{theta}, rho:{rho}, current_theta:{state.current_theta}, current_rho:{state.current_rho}")
+            logger.error(f"  x_steps_per_mm:{state.x_steps_per_mm}, y_steps_per_mm:{state.y_steps_per_mm}, gear_ratio:{state.gear_ratio}")
+            state.stop_requested = True
+            return
+
         # Call sync version of send_grbl_coordinates in this thread
         self._send_grbl_coordinates_sync(round(new_x_abs, 3), round(new_y_abs, 3), actual_speed)