| """Process-local wrist-camera retrofit for every 2/3/4-agent RoboFactory task. |
| |
| RoboFactory's YAML files declare world-fixed cameras, even when their uid says |
| ``head_camera_agent{i}``. This module leaves those files untouched and changes |
| only the live CameraConfig objects: local camera i is mounted on Panda i's |
| ``panda_hand`` link. Collection, training rollout, and evaluation must import |
| this same module so the observation distribution is identical end-to-end. |
| """ |
| from __future__ import annotations |
|
|
| import os |
| import numpy as np |
| import sapien |
|
|
|
|
| |
| |
| |
| |
| CAMERA_LINK_IN_HAND = sapien.Pose( |
| p=[0.0465, -0.0200, 0.0360], q=[0.0, 0.70710678, 0.0, 0.70710678] |
| ) |
| |
| LOCAL_POSE = CAMERA_LINK_IN_HAND |
| |
| |
| CAMERA_FOV = 1.5707963268 |
| |
| |
| |
| CAMERA_WIDTH = int(os.environ.get("ROBOFACTORY_WRIST_WIDTH", "320")) |
| CAMERA_HEIGHT = int(os.environ.get("ROBOFACTORY_WRIST_HEIGHT", "240")) |
| CAMERA_NEAR = 0.01 |
| CAMERA_FAR = 10.0 |
| |
| |
| |
| def _install(task_class, num_agents: int): |
| stock_property = task_class._default_sensor_configs |
|
|
| def wrist_sensor_configs(self): |
| |
| |
| configs = [config for config in stock_property.fget(self) |
| if config.uid != "head_camera_global"] |
| local = {f"head_camera_agent{index}": index for index in range(num_agents)} |
| for config in configs: |
| agent_index = local.get(config.uid) |
| if agent_index is None: |
| continue |
| hand = next( |
| link for link in self.agent.agents[agent_index].robot.links |
| if link.name == "panda_hand" |
| ) |
| config.mount = hand |
| config.pose = CAMERA_LINK_IN_HAND |
| |
| config.width = CAMERA_WIDTH |
| config.height = CAMERA_HEIGHT |
| config.fov = CAMERA_FOV |
| config.near = CAMERA_NEAR |
| config.far = CAMERA_FAR |
| return configs |
|
|
| task_class._default_sensor_configs = property(wrist_sensor_configs) |
|
|
|
|
| def install_all(): |
| """Install once per Python process; idempotent for normal script imports.""" |
| from robofactory.tasks.camera_alignment import CameraAlignmentEnv |
| from robofactory.tasks.lift_barrier import LiftBarrierEnv |
| from robofactory.tasks.pass_shoe import PassShoeEnv |
| from robofactory.tasks.place_food import PlaceFoodEnv |
| from robofactory.tasks.three_robots_stack_cube import ThreeRobotsStackCubeEnv |
| from robofactory.tasks.two_robots_stack_cube import TwoRobotsStackCubeEnv |
| from robofactory.tasks.long_pipeline_delivery import LongPipelineDeliveryEnv |
| from robofactory.tasks.take_photo import TakePhotoEnv |
|
|
| for task_class, count in ( |
| (LiftBarrierEnv, 2), |
| (PassShoeEnv, 2), |
| (PlaceFoodEnv, 2), |
| (TwoRobotsStackCubeEnv, 2), |
| (CameraAlignmentEnv, 3), |
| (ThreeRobotsStackCubeEnv, 3), |
| (LongPipelineDeliveryEnv, 4), |
| (TakePhotoEnv, 4), |
| ): |
| if not getattr(task_class, "_wrist_camera_patch_installed", False): |
| _install(task_class, count) |
| task_class._wrist_camera_patch_installed = True |
|
|
|
|
| install_all() |
|
|