|
|
@@ -371,25 +371,35 @@ class MotionControlThread:
|
|
|
state.machine_y = new_y_abs
|
|
|
|
|
|
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."""
|
|
|
- logger.debug(f"Motion thread sending G-code: X{x} Y{y} at F{speed}")
|
|
|
+ """Synchronous version of send_grbl_coordinates for motion thread.
|
|
|
|
|
|
- # Track overall attempt time
|
|
|
- overall_start_time = time.time()
|
|
|
+ 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}"
|
|
|
|
|
|
while True:
|
|
|
+ # Check stop_requested at the start of each iteration
|
|
|
+ if state.stop_requested:
|
|
|
+ logger.debug("Motion thread: Stop requested, aborting command")
|
|
|
+ return False
|
|
|
+
|
|
|
try:
|
|
|
- gcode = f"$J=G91 G21 Y{y} F{speed}" if home else f"G1 G53 X{x} Y{y} F{speed}"
|
|
|
+ logger.debug(f"Motion thread sending G-code: {gcode}")
|
|
|
state.conn.send(gcode + "\n")
|
|
|
- logger.debug(f"Motion thread sent command: {gcode}")
|
|
|
|
|
|
- start_time = time.time()
|
|
|
+ # 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()
|
|
|
- logger.debug(f"Motion thread response: {response}")
|
|
|
- if response.lower() == "ok":
|
|
|
- logger.debug("Motion thread: Command execution confirmed.")
|
|
|
- return
|
|
|
+ if response:
|
|
|
+ logger.debug(f"Motion thread response: {response}")
|
|
|
+ if response.lower() == "ok":
|
|
|
+ logger.debug("Motion thread: Command execution confirmed.")
|
|
|
+ return True
|
|
|
|
|
|
except Exception as e:
|
|
|
error_str = str(e)
|
|
|
@@ -404,7 +414,8 @@ class MotionControlThread:
|
|
|
logger.info("Connection marked as disconnected due to device error")
|
|
|
return False
|
|
|
|
|
|
- logger.warning(f"Motion thread: No 'ok' received for X{x} Y{y}, speed {speed}. Retrying...")
|
|
|
+ # 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
|