Ver código fonte

Fix move to center/perimeter timing out in touch app

The backend's move_to_center and move_to_perimeter endpoints call
reset_theta() (up to 30s idle check) then check_idle_async(timeout=60),
but the touch app used the generic _api_call with a 10s timeout. Replace
with a dedicated _move_to method using a 95s timeout to cover the
worst-case scenario.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
tuanchris 5 meses atrás
pai
commit
ab659cac5c
1 arquivos alterados com 33 adições e 3 exclusões
  1. 33 3
      dune-weaver-touch/backend.py

+ 33 - 3
dune-weaver-touch/backend.py

@@ -719,12 +719,42 @@ class Backend(QObject):
     @Slot()
     def moveToCenter(self):
         logger.info("Moving to center...")
-        asyncio.create_task(self._api_call("/move_to_center"))
-    
+        asyncio.create_task(self._move_to("/move_to_center"))
+
     @Slot()
     def moveToPerimeter(self):
         logger.info("Moving to perimeter...")
-        asyncio.create_task(self._api_call("/move_to_perimeter"))
+        asyncio.create_task(self._move_to("/move_to_perimeter"))
+
+    async def _move_to(self, endpoint):
+        """Move to center/perimeter with extended timeout.
+
+        Backend calls reset_theta() (up to 30s idle check if hard_reset_theta
+        enabled) then move_polar() + check_idle_async(timeout=60). Use 95s
+        timeout to accommodate the worst-case scenario.
+        """
+        if not self.session:
+            self.errorOccurred.emit("Backend not ready")
+            return
+
+        try:
+            logger.debug(f"Calling {endpoint} (95s timeout for idle checks)...")
+            timeout = aiohttp.ClientTimeout(total=95)
+            async with self.session.post(f"{self.base_url}{endpoint}", timeout=timeout) as resp:
+                logger.debug(f"Move response status for {endpoint}: {resp.status}")
+                if resp.status == 200:
+                    response_data = await resp.json()
+                    logger.info(f"Move command {endpoint} successful: {response_data}")
+                else:
+                    logger.error(f"Move command {endpoint} failed with status: {resp.status}")
+                    response_text = await resp.text()
+                    self.errorOccurred.emit(f"Move failed: {endpoint} - {resp.status} - {response_text}")
+        except asyncio.TimeoutError:
+            logger.warning(f"Move command {endpoint} timed out after 95s")
+            self.errorOccurred.emit(f"Move command {endpoint} timed out")
+        except Exception as e:
+            logger.error(f"Exception in move command {endpoint}: {e}")
+            self.errorOccurred.emit(str(e))
     
     # Speed Control
     @Slot(int)