Skip to content

Commit 65e8cfb

Browse files
committed
retry camera resolve
1 parent 6026c3b commit 65e8cfb

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎robot_orchestrator/boot/fsm.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ async def run(self) -> BootResult:
100100
await self._maybe_scan_qr(facts)
101101

102102
self.progress.step = "probing_hardware"
103-
camera_device = resolve_camera_device(self.settings.hardware.camera, self.hal.camera_probe)
103+
camera_device = await asyncio.to_thread(
104+
resolve_camera_device, self.settings.hardware.camera, self.hal.camera_probe
105+
)
104106
await asyncio.to_thread(self._probe_hardware, facts, camera_device)
105107

106108
self.progress.step = "updating_repos"

‎robot_orchestrator/boot/hardware.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import shutil
22
import subprocess
3+
import time
34
from pathlib import Path
45
from typing import Callable
56

67
from robot_orchestrator.config import CameraConfig, McuConfig
78
from robot_orchestrator.hal.base import CameraProbe, UsbInventory
89

910
UdevQueryT = Callable[[Path, str], "str | None"]
11+
CAMERA_RESOLVE_RETRY_ATTEMPTS = 5
12+
CAMERA_RESOLVE_RETRY_DELAY_S = 1.5
1013

1114

1215
def resolve_chromium_bin(which: Callable[[str], "str | None"] = shutil.which) -> str:
@@ -23,6 +26,16 @@ def resolve_camera_device(
2326
) -> str | None:
2427
if config.device != "auto":
2528
return config.device
29+
for attempt in range(CAMERA_RESOLVE_RETRY_ATTEMPTS):
30+
if attempt > 0:
31+
time.sleep(CAMERA_RESOLVE_RETRY_DELAY_S)
32+
device = _resolve_camera_device_once(config, probe, by_id_dir)
33+
if device is not None:
34+
return device
35+
return None
36+
37+
38+
def _resolve_camera_device_once(config: CameraConfig, probe: CameraProbe, by_id_dir: Path) -> str | None:
2639
if not by_id_dir.exists():
2740
return None
2841
for candidate in sorted(by_id_dir.glob("*")):

0 commit comments

Comments
 (0)