Преглед изворни кода

Revert retry timeout - wait indefinitely for GRBL 'ok'

GRBL only sends 'ok' after a move completes, which can take many
seconds at slow speeds. The 1-second timeout was causing premature
resends and duplicate commands.

Reverted to original behavior: wait indefinitely for 'ok' response.
Added stop_requested checks so patterns can still be cancelled.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
tuanchris пре 1 недеља
родитељ
комит
ef8787a6c1
1 измењених фајлова са 16 додато и 20 уклоњено
  1. 16 20
      modules/core/pattern_manager.py

+ 16 - 20
modules/core/pattern_manager.py

@@ -373,25 +373,27 @@ class MotionControlThread:
     def _send_grbl_coordinates_sync(self, x: float, y: float, speed: int = 600, timeout: int = 2, home: bool = False):
         """Synchronous version of send_grbl_coordinates for motion thread.
 
-        Sends coordinate and waits for 'ok'. If no 'ok' received within 1 second,
-        resends the command. Retries forever until 'ok' is received.
+        Waits indefinitely for 'ok' because GRBL only responds after the move completes,
+        which can take many seconds at slow speeds.
         """
         gcode = f"$J=G91 G21 Y{y} F{speed}" if home else f"G1 G53 X{x} Y{y} F{speed}"
-        retry_count = 0
 
         while True:
-            try:
-                # Check if stop was requested
-                if state.stop_requested:
-                    logger.debug("Motion thread: Stop requested, aborting send")
-                    return False
+            # Check stop_requested at the start of each iteration
+            if state.stop_requested:
+                logger.debug("Motion thread: Stop requested, aborting command")
+                return False
 
+            try:
                 logger.debug(f"Motion thread sending G-code: {gcode}")
                 state.conn.send(gcode + "\n")
 
-                # Wait for 'ok' response with 1 second timeout
-                start_time = time.time()
-                while time.time() - start_time < 1.0:
+                # Wait indefinitely for 'ok' - GRBL sends it after move completes
+                while True:
+                    # Check stop_requested while waiting
+                    if state.stop_requested:
+                        logger.debug("Motion thread: Stop requested while waiting for response")
+                        return False
                     response = state.conn.readline()
                     if response:
                         logger.debug(f"Motion thread response: {response}")
@@ -399,10 +401,6 @@ class MotionControlThread:
                             logger.debug("Motion thread: Command execution confirmed.")
                             return True
 
-                # No 'ok' received within timeout, will retry
-                retry_count += 1
-                logger.warning(f"Motion thread: No 'ok' received for {gcode}, resending... (attempt {retry_count})")
-
             except Exception as e:
                 error_str = str(e)
                 logger.warning(f"Motion thread error sending command: {error_str}")
@@ -416,11 +414,9 @@ class MotionControlThread:
                     logger.info("Connection marked as disconnected due to device error")
                     return False
 
-                retry_count += 1
-                logger.warning(f"Motion thread: Exception occurred, retrying... (attempt {retry_count})")
-
-            # Wait 1 second before resending
-            time.sleep(1.0)
+            # Only retry on exception (not on timeout)
+            logger.warning(f"Motion thread: Error sending {gcode}, retrying...")
+            time.sleep(0.1)
 
 # Global motion control thread instance
 motion_controller = MotionControlThread()