diff --git a/AGENTS.md b/AGENTS.md index e201dee..f096b78 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,6 +14,10 @@ offline tests, installed-wheel tests and explicit user-operated real-machine trials. - Do not commit machine profiles, calibration, credentials, logs, models, SDK builds or caches. Configure device paths externally. Preserve third-party license notices. +- Sole calibration exception: the operator explicitly approved publishing the + sanitized, installation-specific head-camera baseline under `configs/cameras/`. + Keep its versions, hashes, frames and limitations; never include raw evidence, + personal paths/device topology, or auto-activate it on another installation. - Maintain one CLI, concise Viser interfaces, and public APIs documented in README. - Initial extraction keeps the legacy CAN lock directory to interoperate with the original bimanual_tactile installation; do not change one side independently. diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cee30e..e535234 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## 0.8.2 — 2026-11-10 + +- Publish the operator-approved, installation-specific Astra Pro RGB head-camera + baseline `20261110-v1`: native 1280×720 intrinsics/distortion, metric + `base_from_camera`, coordinate conventions, robot FK identity and provenance. + A SHA-256-pinned current selection prevents silent parameter replacement. +- Bind the same bytes to the existing Hugging Face OpenArm supplied-gripper model + in asset package `v0.3.1`. The immutable lock and camera scene entry reproduce + `head_calibrated` without modifying original meshes, task cameras or model/data + payloads. Retain physical-calibration limitations and the original raw evidence + externally; this is not independent absolute-accuracy certification. +- Add dependency-free configuration integrity tests and include the baseline and + asset lock in source distributions. No motor behavior, device selection, + live-service deployment or automatic hardware activation changes. +- Fix a read-only collection-preview freshness race by sampling wall time after + reading an atomic status snapshot. Preserve explicit-time checks and stale/future + rejection; add a deterministic concurrent-publication regression test. + ## 0.8.1 — 2026-11-01 - Add same-origin collection visualization at `/#collection`: fresh/stale diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9a29302..8358cd3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,6 +37,11 @@ including exception cleanup, rather than copying implementation details. Record actual hardware checks separately in [validation](docs/validation.md). Keep device configuration, calibration, logs and cached assets outside Git. +The explicit operator-approved exception is the sanitized, installation-specific +head-camera baseline in `configs/cameras/`. Keep it versioned and hash-bound; +raw calibration evidence and personal machine/device configuration stay external. +See `configs/cameras/README.md` for its scope and coordinate/validity contract. + ## API changes Keep examples and [the API guide](docs/api.md) aligned with public exports. diff --git a/MANIFEST.in b/MANIFEST.in index 7c5d875..f8db408 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,3 +3,4 @@ recursive-include docs *.md recursive-include tests *.py include LICENSE CHANGELOG.md CONTRIBUTING.md recursive-include examples *.py *.json +recursive-include configs/cameras *.json *.md diff --git a/README.md b/README.md index 55ed9fb..2279ed2 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,18 @@ the CLI for live inspection and user-operated control. Python 3.12 · MIT · Linux SocketCAN for followers · Independent community project +## 固定头部相机配置与仿真资产 + +**v0.8.2** includes the operator-selected Astra Pro RGB head-camera baseline +`20261110-v1`: [versioned parameters and usage](configs/cameras/README.md), +[SHA-256-pinned selection](configs/cameras/current-head.json), and the +[immutable Hugging Face asset lock](configs/cameras/huggingface-head.lock.json). +The bound MuJoCo scene renders `head_calibrated` using the same intrinsics and +camera-to-base transform. It reuses the existing robot model; historical task +cameras, policies and physical-control behavior are unchanged. This is specific +to the approved camera installation, not a universal Astra Pro default or an +automatic hardware activation. Raw calibration evidence remains external. + ## Policy execution and gravity compensation The platform also provides **数采可视化** at `/#collection`: recording state, @@ -55,10 +67,10 @@ python3.12 -m venv .venv source .venv/bin/activate # Core: state types, software mapping and control API; no GUI or hardware SDK. -pip install "openarm-runtime @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.1" +pip install "openarm-runtime @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.2" # Serial leader readout, with a browser-based virtual robot. -pip install "openarm-runtime[leader,viewer] @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.1" +pip install "openarm-runtime[leader,viewer] @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.2" ``` Extras compose freely: @@ -82,7 +94,7 @@ project's environment. With uv, declare and lock the dependency directly: ```sh # Run in your own Python 3.12 project. -uv add "openarm-runtime[leader,viewer] @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.1" +uv add "openarm-runtime[leader,viewer] @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.2" ``` **Modify the runtime while developing your application:** clone the source @@ -127,7 +139,7 @@ configure the machine once using [platform.example.json](platform.example.json), then launch: ```sh -python -m pip install "openarm-runtime[platform] @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.1" +python -m pip install "openarm-runtime[platform] @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.2" openarm-runtime platform --profile ~/.config/openarm-runtime/platform.json ``` @@ -282,7 +294,7 @@ ssh -N -L 8890:127.0.0.1:8890 -L 8891:127.0.0.1:8891 your-workstation Video is available starting with v0.3.0: ```sh -python -m pip install "openarm-runtime[video] @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.1" +python -m pip install "openarm-runtime[video] @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.2" # No cameras or vendor SDK required; clearly labelled SIMULATION. openarm-runtime video --simulate --port 5004 ``` @@ -400,7 +412,7 @@ examples in `examples/`. [Changelog](CHANGELOG.md) · [Provenance](ORIGIN.md) · Paxini IP-M2324-Core (68 points) with the single-channel USB serial converter: ```sh -pip install "openarm-runtime[tactile,viewer] @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.1" +pip install "openarm-runtime[tactile,viewer] @ git+https://github.com/Edge-Intelligence-Lab/openarm-runtime.git@v0.8.2" openarm-runtime tactile --device /dev/serial/by-id/YOUR_CONVERTER --device-id 2 --port 8891 ``` diff --git a/configs/cameras/README.md b/configs/cameras/README.md new file mode 100644 index 0000000..3583ba6 --- /dev/null +++ b/configs/cameras/README.md @@ -0,0 +1,85 @@ +# 头部相机基准配置 + +这是当前 OpenArm V2 安装上,经操作者确认的 **Astra Pro RGB 头部相机基准**。 +它包含实测内参、畸变、相机到机器人基座的外参,以及数据来源和适用条件。 +它不是所有 Astra Pro 的通用出厂参数,也不是程序启动时自动应用的全局默认值。 + +入口是 [`current-head.json`](current-head.json),其中的相对路径和 SHA-256 指向 +不可就地覆盖的版本文件 [`head-astra-pro/20261110-v1.json`](head-astra-pro/20261110-v1.json)。 +后续修订应增加版本文件、保留旧版,并在重新核对后更新入口及其哈希;不要只改矩阵。 + +## 怎么使用 + +- `camera.matrix` 是原生 **1280×720** 图像的 OpenCV 内参 K。 + `camera.distortion` 的顺序是 `[k1, k2, p1, p2, k3]`。 +- `extrinsics.base_from_camera` 将相机光学坐标转换到机器人 URDF 基座坐标: + `p_base = base_from_camera @ p_camera`,使用齐次列向量,平移单位为米。 + 相机轴是 **右、下、前**。不要直接把这个矩阵当作相机的 view matrix; + 基座点转到相机坐标时,应取它的逆。 +- 基座名 `world` 是已固定 URDF 的根坐标,不是测量过的房间/桌面世界坐标。 + 仿真场景若有自己的世界偏移,应另外组合该变换。 +- MuJoCo 相机轴是 **右、上、后**,因此旋转使用 + `R_base_mujoco = R_base_camera @ diag(1, -1, -1)`。 + 保留 K 中不相等的焦距和非居中的主点,不要只用一个近似视场角替代。 +- 仿真是理想针孔投影。与实拍对照时,使用同一个 K 和已保存的畸变参数去畸变; + 不做额外图像配准,也不手调相机以掩盖模型误差。 +- `robot.kinematics` 记录标定使用的 URDF 哈希、关节映射和工具坐标。 + 这些 locked 关节仅是当时 FK 的建模约定,不是当前右臂姿态。 + `calibration_fixture.tool_from_board` 仅描述当时的装板,不是永久 TCP。 + +使用前,调用者必须明确选用此安装实例并核对外部设备身份;不能仅因型号相同就套用。 +仓库不包含 USB 拓扑、设备端口、个人主机路径或认证信息。本次发布不修改实物运行配置, +不自动启用跟随、相机流或电机;也不依赖尚未发布的仿真重放实现。 +文件随 Git 和源码分发包保存,消费程序应显式选择配置路径,而非假设安装 wheel 会自动启用它。 + +## 这版已经检查了什么 + +- 原图、观测和机器人 FK 身份已核对,离线重算与保存结果一致。 +- **12 张拟合 + 4 张独立留出检查**;留出 RMS 为 **3.38 mm / 0.78°**。 + 这是同组一致性残差,不是独立测量的绝对定位精度。 +- 已按 16 个实测关节姿态复现仿真相机,并查看 4 个留出姿态的实拍/仿真对应关系; + 没有手调相机。渲染器的轴向、非居中主点和索引板纹理也已离线核对。 +- 内参边缘覆盖不足、静止时间区间不等于精确曝光同步等限制保留在版本文件中。 + +**相机移动、安装松动、对焦/镜头改变,或图像裁剪/缩放后,都要重新核对适用性。** +原始图像及连续关节反馈仍在外部证据存储,版本文件记录其原始文件与规范 JSON 的哈希, +两类哈希不可混用;精简后的本文件有自己的哈希,由 `current-head.json` 固定。 + +这是操作者明确要求发布的、去除个人环境信息的相机基准例外。 +其他机器配置、原始标定证据、日志和模型仍遵循仓库的外部存储规则,不应一起提交。 + +## 已绑定的 Hugging Face 仿真资产 + +[`huggingface-head.lock.json`](huggingface-head.lock.json) 固定私有模型仓库 +`tacpilot/tacpilot` 的完整提交和 `v0.3.1` 资产清单哈希;不要用不断变化的 `main` +代替锁中的 revision。仿真组件是 `head-camera`,其入口为 +`assets/simulation/cameras/head-astra-pro/20261110-v1/scene.xml`,相机名为 +**`head_calibrated`**。HF 内的 `calibration.json` 与这里的版本文件逐字节相同。 + +有 TacPilot 源码环境时,可复用其现有 SSH/LFS 资产下载器,只下载相机和模型依赖: + +```bash +python -m tacpilot.artifacts fetch \ + --lock /path/to/openarm-runtime/configs/cameras/huggingface-head.lock.json \ + --directory /path/to/new/external/assets --component head-camera +``` + +需要已有 HF SSH 授权和 Git LFS,不要求额外 API Token。不下载策略权重或示教数据。 +下载目录不能已存在,模型/场景保持原目录结构。 + +```python +import mujoco + +model = mujoco.MjModel.from_xml_path( + asset_root + '/assets/simulation/cameras/head-astra-pro/20261110-v1/scene.xml') +data = mujoco.MjData(model) +mujoco.mj_forward(model, data) +with mujoco.Renderer(model, height=720, width=1280) as renderer: + renderer.update_scene(data, camera='head_calibrated') + rgb = renderer.render() +``` + +这只加载并渲染仿真,不连接实物。入口引用原有机器人/夹爪场景,只增加固定相机和 +离屏分辨率;模型原始场景、历史训练/评测相机与模型权重不变。新工作明确选择这个 +相机入口;旧策略仍保留原有图像契约,不能因为标定已固定就宣称旧策略可直接换视角。 +场景的基座偏移另见绑定文件,不要将场景世界坐标误作物理桌面测量。 diff --git a/configs/cameras/current-head.json b/configs/cameras/current-head.json new file mode 100644 index 0000000..3546e3a --- /dev/null +++ b/configs/cameras/current-head.json @@ -0,0 +1,10 @@ +{ + "schema": "openarm.camera-baseline-selection.v1", + "installation_id": "openarm-v2-head-astra-pro", + "camera": "head", + "version": "20261110-v1", + "path": "head-astra-pro/20261110-v1.json", + "sha256": "2e33f3028e7e320f43b319b2ed0c7c60079ae8a4e1abab9e80b7732dfcfa9df4", + "automatic_device_selection": false, + "automatic_hardware_activation": false +} diff --git a/configs/cameras/head-astra-pro/20261110-v1.json b/configs/cameras/head-astra-pro/20261110-v1.json new file mode 100644 index 0000000..c1ce11f --- /dev/null +++ b/configs/cameras/head-astra-pro/20261110-v1.json @@ -0,0 +1,156 @@ +{ + "schema": "openarm.camera-baseline.v1", + "version": "20261110-v1", + "installation_id": "openarm-v2-head-astra-pro", + "scope": "this_installation_only_not_factory_calibration", + "selection": "operator_accepted_baseline_after_offline_simulation_visual_review", + "independently_physically_verified": false, + "automatically_activate_hardware": false, + "camera": { + "name": "head", + "model": "Astra Pro RGB", + "image_size": [1280, 720], + "image_geometry": "native_no_transform", + "camera_model": "pinhole", + "distortion_model": "opencv_5", + "pixel_coordinates": "x right, y down; native OpenCV image pixels", + "matrix": [ + [1007.3759323261551, 0.0, 648.5412534547582], + [0.0, 1005.894776547822, 383.16680235990856], + [0.0, 0.0, 1.0] + ], + "distortion": [ + 0.056219346631710014, + 0.38021308615459354, + -0.00025174339295446564, + -0.0006971512942885714, + -1.2772477652608862 + ], + "distortion_order": ["k1", "k2", "p1", "p2", "k3"], + "intrinsics_version": "20261110-v1" + }, + "extrinsics": { + "transform_name": "base_from_camera", + "base_frame": "world", + "base_frame_semantics": "root of the pinned robot URDF, not a surveyed room frame", + "camera_frame": "head_optical", + "camera_axes": {"x": "right", "y": "down", "z": "forward"}, + "units": "m", + "equation": "p_base = base_from_camera @ p_camera; homogeneous column vectors", + "base_from_camera": [ + [-0.0032977033174182158, -0.8940526827815002, 0.44794969088507086, 0.0567064761899711], + [-0.9995586812198728, 0.016171713676243114, 0.02491823578748592, 0.008392649899155363], + [-0.029522329698338623, -0.4476698293251111, -0.8937114500560048, 0.7890478461241447], + [0.0, 0.0, 0.0, 1.0] + ], + "mujoco_optical_rotation": [ + [1.0, 0.0, 0.0], + [0.0, -1.0, 0.0], + [0.0, 0.0, -1.0] + ], + "mujoco_rotation_equation": "R_base_mujoco_camera = R_base_opencv_camera @ mujoco_optical_rotation" + }, + "robot": { + "model": "OpenArm V2", + "calibration_arm": "left", + "tool_frame": "openarm_left_ee_base_link", + "kinematics_sha256": "79bd7cbe2ad98b46115f06f10c74934508eef7b93f86ffbd03a8ef5957c34af3", + "kinematics": { + "urdf_sha256": "56bd506b9686f5e472b143684dcd045c4e30783d27e1266f6f480a49f01b8bd8", + "joints": [ + "openarm_left_joint1", "openarm_left_joint2", "openarm_left_joint3", + "openarm_left_joint4", "openarm_left_joint5", "openarm_left_joint6", "openarm_left_joint7" + ], + "signs": [1, 1, 1, 1, 1, 1, 1], + "offsets": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + "locked": { + "openarm_left_finger_joint1": 0.0, + "openarm_left_finger_joint2": 0.0, + "openarm_right_joint1": 0.0, + "openarm_right_joint2": 0.0, + "openarm_right_joint3": 0.0, + "openarm_right_joint4": 0.0, + "openarm_right_joint5": 0.0, + "openarm_right_joint6": 0.0, + "openarm_right_joint7": 0.0, + "openarm_right_finger_joint1": 0.0, + "openarm_right_finger_joint2": 0.0 + }, + "frame": "openarm_left_ee_base_link", + "tcp": [ + [1.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 1.0, 0.0], + [0.0, 0.0, 0.0, 1.0] + ], + "encoder_limit_tolerance_rad": 0.008726646259971648 + } + }, + "calibration_fixture": { + "scope": "source_calibration_mount_only_not_a_permanent_robot_TCP", + "board_spec": { + "type": "charuco", + "squares_x": 6, + "squares_y": 4, + "square_size_m": 0.0225, + "marker_size_m": 0.0165, + "dictionary": "DICT_4X4_50" + }, + "tool_from_board": [ + [0.012978869663394066, -0.015578883162274959, -0.9997944025356797, 0.02576363703886798], + [-0.994733529809124, 0.10146488385157795, -0.014494206375876229, 0.0697281229014311], + [0.10166982647640022, 0.9947171335331477, -0.01417993793557265, -0.2155277765898749], + [0.0, 0.0, 0.0, 1.0] + ] + }, + "validation": { + "semantics": "within_session_consistency_not_absolute_accuracy_certification", + "fit": { + "samples": 12, + "rms_translation_m": 0.0026779717784152853, + "rms_rotation_rad": 0.01101961287392166, + "max_translation_m": 0.004164814363000099, + "max_rotation_rad": 0.018684684838539144 + }, + "validation": { + "samples": 4, + "rms_translation_m": 0.0033823555165824223, + "rms_rotation_rad": 0.013590291281268891, + "max_translation_m": 0.004937677744859555, + "max_rotation_rad": 0.019009805973595566 + }, + "rms_acceptance_limits": {"translation_m": 0.005, "rotation_rad": 0.03}, + "intrinsics_fit_rms_px": 0.25797656123975005, + "intrinsics_validation_rms_px": 0.23441138018504198, + "timing_contract": "stationary_bracket_not_exposure_synchronization", + "exposure_timestamp_known": false, + "simulation_review": "16 recorded joint poses replayed; 4 held-out real/rendered views visually reviewed without camera adjustment" + }, + "provenance": { + "group_id": "ef9692cd4c164350ac70b9c4b7de5466", + "intrinsics_session_id": "56db91e3fa30433d96a875a6852a5b7c", + "intrinsics_file_sha256": "378b052ca6a7c9032b1be8fafcad3fc971e21433e848b63a7f92742b007bb407", + "estimate_file_sha256": "d1198852e0c9d48867013f67c9dfdc9262119a03d56a700d9adc967fcee90d88", + "observations_file_sha256": "d543fc150c7d45c29023946105f6b49e6fcdfc97e8b5a33ec9c69c88a3f6e650", + "observations_canonical_json_sha256": "c24c91717829aaaab9019f933d40a7bb91e8a7fcb90683716acebd60fd3438ec", + "session_file_sha256": "173d79ed96f5d31c0da9f9fd2938453f2f8546994888b734cea57200a799e667", + "route_canonical_json_sha256": "ae8534b147cec562f0f685770d10a34096ec9c9a8196308b177966430919c62f", + "raw_evidence_storage": "external; original PNGs and feedback retained, not embedded in this repository" + }, + "validity_conditions": [ + "Use only this approved physical camera/lens and rigid mounting instance; model name alone is not a device identity check.", + "Keep focus and zoom unchanged. Refocusing or replacing the camera/lens requires intrinsics review.", + "Use native 1280x720 pixels. Cropping, resizing, rotation or binning requires an explicit corresponding intrinsic transform.", + "Moving the camera relative to the robot base invalidates these extrinsics.", + "Use the pinned robot coordinate frame, kinematic geometry and joint sign/offset conventions.", + "Raw images use the OpenCV distortion coefficients. Ideal simulation must be compared to images undistorted with the same K.", + "MuJoCo scene-world placement is not the robot base frame; apply the scene's declared base/world transform separately." + ], + "limitations": [ + "Intrinsics corner coverage near image edges, especially the bottom edge, was limited; edge distortion is less constrained.", + "This is an operator-accepted baseline, not independently surveyed physical metric accuracy.", + "Stationary acquisition intervals are qualified; exact exposure-time synchronization and moving-scene accuracy are not certified.", + "Right-arm current joint angles, table geometry, gripper transmission, lighting and background are not calibrated by this result.", + "The board transform applies only to its original rigid mount and must not be reused after re-clamping." + ] +} diff --git a/configs/cameras/huggingface-head.lock.json b/configs/cameras/huggingface-head.lock.json new file mode 100644 index 0000000..cdc8b31 --- /dev/null +++ b/configs/cameras/huggingface-head.lock.json @@ -0,0 +1,10 @@ +{ + "schema": "tacpilot.artifact-lock.v1", + "repo_id": "tacpilot/tacpilot", + "repo_type": "model", + "revision": "b712883b433a5d7005c38d2d99820dc70fedb3c8", + "manifest": { + "path": "releases/v0.3.1/manifest.json", + "sha256": "b066d7ec2e5f386ffabe4b139fd5d4360a3128e84fcd561df92c996853c9aa4b" + } +} diff --git a/pyproject.toml b/pyproject.toml index 86d81ef..00d7b23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "openarm-runtime" -version = "0.8.1" +version = "0.8.2" description = "Reusable OpenArm Classic CAN control, Feetech leader readout, tactile/video capture and optional Viser tools" readme = "README.md" license = "MIT" diff --git a/src/openarm_platform/collection.py b/src/openarm_platform/collection.py index 2589d76..f7dc780 100644 --- a/src/openarm_platform/collection.py +++ b/src/openarm_platform/collection.py @@ -48,7 +48,6 @@ def __init__(self, root): self.root = Path(root).expanduser().resolve() def live(self, now_ns=None): - now_ns = time.time_ns() if now_ns is None else now_ns directory = inside(self.root, self.root/'.runtime') result = [] for path in directory.glob('*.json') if directory.is_dir() else (): @@ -56,7 +55,10 @@ def live(self, now_ns=None): value = read_json(inside(directory, path)) if value.get('schema') != 'openarm.collection-status/1': continue - age = (now_ns-finite(value['updated_wall_time_ns'])) / 1e9 + # The publisher may atomically replace the file during I/O. + # Observe now after reading, not before the newer snapshot exists. + observed_ns = time.time_ns() if now_ns is None else now_ns + age = (observed_ns-finite(value['updated_wall_time_ns'])) / 1e9 value['fresh'] = 0 <= age <= 3 value['status_age_s'] = max(0, age) result.append(value) diff --git a/src/openarm_runtime/__init__.py b/src/openarm_runtime/__init__.py index 4000f45..9791b07 100644 --- a/src/openarm_runtime/__init__.py +++ b/src/openarm_runtime/__init__.py @@ -5,5 +5,5 @@ from .calibration import calibrate_arm from .telemetry import MotorRange, MotorState, ArmConnection -__version__ = "0.8.1" +__version__ = "0.8.2" __all__ = ["Profile", "hold_arm", "calibrate_arm", "MotorRange", "MotorState", "ArmConnection"] diff --git a/tests/test_camera_baseline_config.py b/tests/test_camera_baseline_config.py new file mode 100644 index 0000000..2e8b704 --- /dev/null +++ b/tests/test_camera_baseline_config.py @@ -0,0 +1,83 @@ +"""Published configuration integrity only; no device or scientific dependencies.""" +import hashlib +import json +import math +from pathlib import Path +import unittest + + +class HeadCameraBaselineTests(unittest.TestCase): + def setUp(self): + self.root=Path(__file__).resolve().parents[1]/'configs/cameras' + self.selection=json.loads((self.root/'current-head.json').read_text()) + self.path=(self.root/self.selection['path']).resolve() + self.data=json.loads(self.path.read_text()) + + def test_selected_version_is_immutable_and_installation_specific(self): + self.assertTrue(self.path.is_relative_to(self.root.resolve())) + self.assertEqual(self.selection['sha256'],hashlib.sha256(self.path.read_bytes()).hexdigest()) + self.assertEqual(self.data['version'],self.selection['version']) + self.assertEqual(self.data['installation_id'],self.selection['installation_id']) + self.assertEqual(self.data['scope'],'this_installation_only_not_factory_calibration') + self.assertFalse(self.selection['automatic_device_selection']) + self.assertFalse(self.selection['automatic_hardware_activation']) + self.assertFalse(self.data['automatically_activate_hardware']) + self.assertFalse(self.data['independently_physically_verified']) + + def test_intrinsics_and_transform_conventions_are_complete(self): + c=self.data['camera'];e=self.data['extrinsics'] + self.assertEqual(c['image_size'],[1280,720]) + self.assertEqual(c['distortion_order'],['k1','k2','p1','p2','k3']) + self.assertEqual(len(c['distortion']),5) + self.assertEqual(c['matrix'][2],[0,0,1]) + self.assertEqual(e['transform_name'],'base_from_camera') + self.assertEqual(e['units'],'m') + self.assertEqual(e['camera_axes'],dict(x='right',y='down',z='forward')) + for T in (e['base_from_camera'],self.data['calibration_fixture']['tool_from_board']): + self.assertEqual(T[3],[0,0,0,1]) + R=[row[:3] for row in T[:3]] + for i in range(3): + for j in range(3): + self.assertAlmostEqual(sum(R[k][i]*R[k][j] for k in range(3)),float(i==j),places=10) + det=sum(R[0][i]*(R[1][(i+1)%3]*R[2][(i+2)%3]-R[1][(i+2)%3]*R[2][(i+1)%3]) for i in range(3)) + self.assertAlmostEqual(det,1.,places=10) + self.assertEqual(e['mujoco_optical_rotation'],[[1,0,0],[0,-1,0],[0,0,-1]]) + + def test_source_kinematics_and_validation_roles_are_preserved(self): + robot=self.data['robot'] + raw=json.dumps(robot['kinematics'],sort_keys=True,separators=(',',':'),allow_nan=False).encode() + self.assertEqual(hashlib.sha256(raw).hexdigest(),robot['kinematics_sha256']) + v=self.data['validation'] + self.assertEqual(v['fit']['samples'],12) + self.assertEqual(v['validation']['samples'],4) + for role in ('fit','validation'): + self.assertLess(v[role]['rms_translation_m'],v['rms_acceptance_limits']['translation_m']) + self.assertLess(v[role]['rms_rotation_rad'],v['rms_acceptance_limits']['rotation_rad']) + self.assertEqual(self.data['provenance']['group_id'],'ef9692cd4c164350ac70b9c4b7de5466') + self.assertFalse(v['exposure_timestamp_known']) + self.assertGreater(len(self.data['limitations']),0) + + def test_published_data_has_no_machine_paths_network_addresses_or_nonfinite_values(self): + def check(value): + if isinstance(value,dict): + for v in value.values():check(v) + elif isinstance(value,list): + for v in value:check(v) + elif isinstance(value,str): + for forbidden in ('/home/','/Users/','yunzhen','bing-amd','/dev/','127.0.0.1','100.124.','192.168.','10.203.'): + self.assertNotIn(forbidden,value) + elif isinstance(value,(int,float)): + self.assertTrue(math.isfinite(value)) + check(self.data) + + def test_huggingface_lock_pins_an_immutable_model_asset_inventory(self): + lock=json.loads((self.root/'huggingface-head.lock.json').read_text()) + self.assertEqual(lock['schema'],'tacpilot.artifact-lock.v1') + self.assertEqual(lock['repo_type'],'model') + self.assertEqual(lock['repo_id'],'tacpilot/tacpilot') + self.assertRegex(lock['revision'],r'^[0-9a-f]{40}$') + self.assertRegex(lock['manifest']['sha256'],r'^[0-9a-f]{64}$') + self.assertEqual(lock['manifest']['path'],'releases/v0.3.1/manifest.json') + + +if __name__=='__main__':unittest.main() diff --git a/tests/test_collection_preview.py b/tests/test_collection_preview.py index 0b8f6f9..87dc40b 100644 --- a/tests/test_collection_preview.py +++ b/tests/test_collection_preview.py @@ -73,6 +73,21 @@ def test_stale_recording_status_is_not_reported_fresh(self): self.assertFalse(browser.live(now_ns=104_000_000_000)[0]['fresh']) self.assertFalse(browser.live(now_ns=99_000_000_000)[0]['fresh']) + def test_atomic_update_during_read_is_not_mistaken_for_future_status(self): + directory=self.root/'.runtime';directory.mkdir() + snapshot=dict(schema='openarm.collection-status/1',publisher='one', + updated_wall_time_ns=100_000_000_000,state='recording',streams={}) + atomic_json(directory/'one.json',snapshot) + clock=[99_000_000_000] + def read_after_publish(path): + clock[0]=100_000_000_000 + return dict(snapshot) + with patch('openarm_platform.collection.read_json',side_effect=read_after_publish), \ + patch('openarm_platform.collection.time.time_ns',side_effect=lambda:clock[0]): + browser=CollectionBrowser(self.root) + self.assertTrue(browser.live()[0]['fresh']) + self.assertFalse(browser.live(now_ns=99_000_000_000)[0]['fresh']) + def test_archive_is_read_only_and_preserves_target_feedback_distinction(self): path=fixture(self.root) before={p.name:hashlib.sha256(p.read_bytes()).hexdigest() for p in path.iterdir() if p.is_file()} diff --git a/tests/test_public_api.py b/tests/test_public_api.py index bdf24fd..0d9c2d9 100644 --- a/tests/test_public_api.py +++ b/tests/test_public_api.py @@ -35,7 +35,7 @@ def test_core_imports_are_passive_and_optional_dependencies_stay_unloaded(self): with tempfile.TemporaryDirectory() as root: result = subprocess.run([sys.executable, "-I", "-c", script], cwd=root, capture_output=True, text=True, check=True) - self.assertEqual(result.stdout.strip(), "0.8.1") + self.assertEqual(result.stdout.strip(), "0.8.2") def test_cli_works_outside_checkout(self): with tempfile.TemporaryDirectory() as root: @@ -63,7 +63,7 @@ def test_validation_uses_installed_wheel_not_checkout(self): self.assertIn("site-packages", Path(openarm_runtime.__file__).parts) self.assertIn("site-packages", Path(openarm_tactile.__file__).parts) self.assertIn("site-packages", Path(openarm_platform.__file__).parts) - self.assertEqual(version("openarm-runtime"), "0.8.1") + self.assertEqual(version("openarm-runtime"), "0.8.2") def test_video_resources_are_present_outside_source_tree(self): from importlib.resources import files diff --git a/uv.lock b/uv.lock index 963feee..e7c81cc 100644 --- a/uv.lock +++ b/uv.lock @@ -908,7 +908,7 @@ source = { git = "https://github.com/enactic/openarm_can.git?subdirectory=python [[package]] name = "openarm-runtime" -version = "0.8.1" +version = "0.8.2" source = { editable = "." } [package.optional-dependencies]