MOSS: a small, mostly 3D-printed litter-picking rover. Cleaner streets, one maker at a time.
Python
wrist camera: any UVC camera that is not the RealSense is the wrist camera
metrox0b256a8a9d42
diff --git a/benches/bench_moss_blueprints_cold.py b/benches/bench_moss_blueprints_cold.pyindex 97623ee..44d475a 100644--- a/benches/bench_moss_blueprints_cold.py+++ b/benches/bench_moss_blueprints_cold.py@@ -308,6 +308,14 @@ check("KD-USB by-id video-index0 -> /dev/video6 -> 6 (index1 ignored)", mb.wristcheck("MOSS_WRIST_DEV=3 -> 3", mb.wrist_camera_index({"MOSS_WRIST_DEV": "3"}, v4l) == 3)check("MOSS_WRIST_DEV=/dev/video9 -> 9", mb.wrist_camera_index({"MOSS_WRIST_DEV": "/dev/video9"}, v4l) == 9)check("MOSS_WRIST_DEV=/dev/ttyUSB0 (not a video device) -> None", mb.wrist_camera_index({"MOSS_WRIST_DEV": "/dev/ttyUSB0"}, v4l) is None)+v4l2 = tempfile.mkdtemp(prefix="v4l_other_")+os.symlink("/dev/video2", os.path.join(v4l2, "usb-Intel_R_RealSense_TM_Depth_Camera_455f_Intel_R_RealSense_TM_Depth_Camera_455f_000000000000-video-index0"))+check("only the RealSense under by-id -> None (the nose camera is never the wrist)", mb.wrist_camera_index({}, v4l2) is None)+os.symlink("/dev/video8", os.path.join(v4l2, "usb-Generic_Vendor_USB_Camera_XYZ-video-index0"))+os.symlink("/dev/video9", os.path.join(v4l2, "usb-Generic_Vendor_USB_Camera_XYZ-video-index1"))+check("an unknown UVC camera next to the RealSense -> it is the wrist (/dev/video8), index1 ignored", mb.wrist_camera_index({}, v4l2) == 8)+os.symlink("/dev/video6", os.path.join(v4l2, "usb-Sonix_Technology_Co.__Ltd._KD-USB_Cameras_KD-USB_Cameras-video-index0"))+check("a known name wins over the unknown one", mb.wrist_camera_index({}, v4l2) == 6)mb.V4L_BY_ID = v4l # F and G build the blueprints against this fake by-idprint()diff --git a/benches/bench_moss_preflight_cold.py b/benches/bench_moss_preflight_cold.pyindex 811f14f..934b253 100644--- a/benches/bench_moss_preflight_cold.py+++ b/benches/bench_moss_preflight_cold.py@@ -454,6 +454,14 @@ check("MOSS_CAMERA unset, no pyrealsense2 -> KO RealSense with the install / MOSf"rc {rc} {last_line(out)}")rc, out, res, w = run(realsense_exc=NO_RS, env={"MOSS_CAMERA": "1"})check("MOSS_CAMERA=1 -> the same KO", rc == 1 and line_of(out, "RealSense").startswith("KO"))+RS_V4L = "/dev/v4l/by-id/usb-Intel_R_RealSense_TM_Depth_Camera_455f_000000000000-video-index0"+OTHER_CAM = "/dev/v4l/by-id/usb-Generic_Vendor_USB_Camera_XYZ-video-index0"+rc, out, res, w = run(files={QTPY, C1, "/dev/input/js0", RS_V4L, OTHER_CAM})+check("an unknown UVC camera next to the RealSense is reported as the wrist camera",+ any(r["label"] == "wrist camera" and r["ok"] and OTHER_CAM in r["detail"] for r in res), str([r for r in res if r["label"] == "wrist camera"]))+rc, out, res, w = run(files={QTPY, C1, "/dev/input/js0", RS_V4L})+check("only the RealSense under by-id -> wrist camera WARN (never the nose camera)",+ any(r["label"] == "wrist camera" and r["ok"] and "WARN" in r["detail"] for r in res), str([r for r in res if r["label"] == "wrist camera"]))rc, out, res, w = run(files={QTPY, C1, "/dev/input/js0"}, env={"MOSS_WRIST": "false"})wr = find(res, "wrist camera")check("MOSS_WRIST=false -> wrist camera skipped (the stack builds none)",diff --git a/moss_dimos/blueprints.py b/moss_dimos/blueprints.pyindex 97191cf..50ca1b6 100644--- a/moss_dimos/blueprints.py+++ b/moss_dimos/blueprints.py@@ -265,16 +265,19 @@ def moss_ports(env: dict | None = None) -> dict:WRIST_WIDTH, WRIST_HEIGHT, WRIST_FPS = 640, 480, 5-WRIST_BY_ID_GLOBS = ("*KD-USB*-video-index0", "*Sonix*-video-index0") # the arm's UVC camera, as moss_preflight+WRIST_BY_ID_GLOBS = ("*KD-USB*-video-index0", "*Sonix*-video-index0") # known arm cameras, tried first (as moss_preflight)+WRIST_ANY_GLOB = "*-video-index0" # then any other UVC camera on the robot...+WRIST_NOT = ("realsense",) # ...except the nose camera (lower-cased by-id name)V4L_BY_ID = "/dev/v4l/by-id"def wrist_camera_index(env: dict | None = None, by_id_dir: str | None = None) -> int | None:"""/dev/videoN index of the wrist camera, or None when it is not there.MOSS_WRIST_DEV wins (an index or a /dev/videoN path); otherwise the first- by-id match of the known names. The kernel numbers video devices in plug- order, so the by-id name is the stable handle and the index is resolved- when the blueprint is built."""+ by-id match of the known names; otherwise the first other UVC camera under+ by-id that is not the RealSense (MOSS carries two cameras: the nose and the+ arm). The kernel numbers video devices in plug order, so the by-id name is+ the stable handle and the index is resolved when the blueprint is built."""import globimport reenv = os.environ if env is None else env@@ -291,6 +294,11 @@ def wrist_camera_index(env: dict | None = None, by_id_dir: str | None = None) ->if hits:target = os.path.realpath(hits[0])break+ if target is None:+ others = [h for h in sorted(glob.glob(os.path.join(by_id_dir, WRIST_ANY_GLOB)))+ if not any(x in os.path.basename(h).lower() for x in WRIST_NOT)]+ if others:+ target = os.path.realpath(others[0])if target is None:return Nonem = re.fullmatch(r"/dev/video(\d+)", target)@@ -400,7 +408,7 @@ def _common_parts(ports: dict, profile: RobotProfile) -> list:idx = wrist_camera_index()if idx is None:_logger.warning("MOSS blueprint: no wrist camera (%s under %s, or MOSS_WRIST_DEV): "- "wrist_image will not be published", " / ".join(WRIST_BY_ID_GLOBS), V4L_BY_ID)+ "wrist_image will not be published", " / ".join(WRIST_BY_ID_GLOBS + (WRIST_ANY_GLOB,)), V4L_BY_ID)else:_logger.info(f"MOSS blueprint: wrist camera /dev/video{idx}, {WRIST_WIDTH}x{WRIST_HEIGHT} @ {WRIST_FPS} fps")parts.append(_wrist_part(idx))diff --git a/tools/moss_preflight.py b/tools/moss_preflight.pyindex ba87dab..5376efc 100755--- a/tools/moss_preflight.py+++ b/tools/moss_preflight.py@@ -64,7 +64,9 @@ V4L_DIR = "/dev/v4l/by-id"JS_PATH = "/dev/input/js0"QTPY_GLOB = "*QT_Py*"C1_GLOB = "*CP2102N*"-WRIST_GLOBS = ("*KD-USB*-video-index0", "*Sonix*-video-index0")+WRIST_GLOBS = ("*KD-USB*-video-index0", "*Sonix*-video-index0") # known arm cameras first+WRIST_ANY_GLOB = "*-video-index0" # then any other UVC camera...+WRIST_NOT = ("realsense",) # ...except the nose cameraFIRMWARE_BAUD = 115200LISTEN_S = 1.5 # five telemetry lines at the firmware's 200 ms periodLIDAR_TURNS = 3@@ -612,10 +614,14 @@ def check_wrist(ctx: dict) -> None:skipped("wrist camera", f"MOSS_WRIST={_raw('MOSS_WRIST')}: this flight builds no wrist camera")returnpath = _first(os.path.join(V4L_DIR, g) for g in WRIST_GLOBS)+ if path is None:+ others = [h for h in _ls(os.path.join(V4L_DIR, WRIST_ANY_GLOB))+ if not any(x in os.path.basename(h).lower() for x in WRIST_NOT)]+ path = others[0] if others else None# The stack skips a missing wrist camera with a warning (no wrist_image):# its absence is a warning here too, not a refusal.- verdict(True, "wrist camera", path or f"WARN not seen (no {' or '.join(WRIST_GLOBS)} under {V4L_DIR}); "- "the stack runs without wrist_image")+ verdict(True, "wrist camera", path or f"WARN not seen (no {' or '.join(WRIST_GLOBS)} and no other "+ f"{WRIST_ANY_GLOB} besides the RealSense under {V4L_DIR}); the stack runs without wrist_image")def check_gamepad(ctx: dict) -> None: