# data_collection_ws **Repository Path**: nics-robot/data_collection_ws ## Basic Information - **Project Name**: data_collection_ws - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-12 - **Last Updated**: 2026-06-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 数据采集管线 (Data Collection Pipeline) 面向机器人模仿学习的**头戴式多相机 + 双臂夹爪人工作业数据采集与处理管线**。 [English Version](README.md) ## 项目背景 本项目的目标是构建一套完整的**人类作业演示数据采集系统**,用于训练机器人模仿学习模型。操作员佩戴集成8台全局快门相机的头盔,手持双夹爪进行操作演示。系统同步录制头盔图像流和夹爪状态,并通过离线管线将原始数据转化为机器人可学习的格式。 ### 系统组成 | 组件 | 说明 | |------|------| | 头盔相机 | 8台全局快门RGB相机 (640×480@30fps),环绕头盔安装 | | 双夹爪 | 左右手各一,带6DoF位姿追踪 | | 双臂机器人 | GR3双臂机器人,用于验证动作可执行性 | | 计算平台 | Ubuntu 20.04 + ROS Noetic + NVIDIA GPU (CUDA 12.2) | ### 处理管线 ``` 录制 → 标定 → 预处理 → 立体校正 → 深度估计 → 夹爪分割 → 位姿估计 → 因子图优化 → 臂部定位 → LeRobot导出 ``` ### 核心特性 - **11个模块**覆盖从传感器标定到机器人学习数据集导出的全流程 - **多相机SfM**实现头盔里程计(M10),无需外部动捕系统 - **4对双目立体视觉**提供稠密深度(M5)和独立夹爪追踪(M7) - **因子图优化**(M8)融合头盔轨迹与夹爪位姿,输出世界坐标系下的平滑轨迹 - **Docker化部署**,一键构建和运行,支持离线构建 - **统一坐标树**(TF Tree),所有模块在同一坐标系下协作 ## 模块管线 ``` M1 kalibr → M2 record → M3 preprocessing → M4 rectify → M5 depth → M6 mask → M7 pose → M8 GTSAM → M9 arm_locator → M11 LeRobot ↕ ↕ M10 helmet odometry ──────┘ ``` ## 环境安装 已在 Ubuntu 20.04 + ROS Noetic + NVIDIA GPU (CUDA 12.2) 上测试通过。 M4-M11 使用 Python 3.11 (uv venv),M1-M3 使用系统 Python 3.8 (ROS 兼容)。 ### 1. 克隆仓库 ```bash git clone https://gitee.com/nics-robot/data_collection_ws.git cd data_collection_ws git submodule update --init --recursive ``` ### 2. 安装系统依赖 ```bash sudo apt-get update && sudo apt-get install -y \ cmake ninja-build libeigen3-dev libboost-all-dev \ python3-dev python3-pip python3-catkin-tools \ libopencv-dev libgoogle-glog-dev libgflags-dev \ sqlite3 libsqlite3-dev libcgal-dev libceres-dev \ libhdf5-dev libflann-dev libyaml-cpp-dev libzmq3-dev libmetis-dev ``` ### 3. 安装 CUDA 12.2 ```bash wget -qO- https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.1-1_all.deb | \ sudo tee /tmp/cuda-keyring.deb >/dev/null sudo dpkg -i /tmp/cuda-keyring.deb sudo apt-get update sudo apt-get install -y cuda-toolkit-12-2 ``` ### 4. 安装 ROS Noetic 参见 [ROS Noetic 安装指南](http://wiki.ros.org/noetic/Installation/Ubuntu) ### 5. 安装 uv 包管理器 ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` ### 6. 构建 kalibr (M1) ```bash cd modules/01_calibration/kalibr_workspace source /opt/ros/noetic/setup.bash catkin config --extend /opt/ros/noetic --cmake-args -DCMAKE_BUILD_TYPE=Release catkin build ``` ### 7. 构建 helmet-recorder (M2) ```bash cd modules/02_data_collection/catkin_ws source /opt/ros/noetic/setup.bash source ../../01_calibration/kalibr_workspace/devel/setup.bash catkin build ``` ### 8. 安装 Python 3.11 + M4-M11 共享虚拟环境 ```bash uv venv --python 3.11 .venv source .venv/bin/activate # 基础依赖 uv pip install numpy scipy matplotlib opencv-python pyyaml tqdm pillow imageio ninja # PyTorch (CUDA 12.1) uv pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121 # M6 依赖 uv pip install einops huggingface_hub yacs tifffile hydra-core \ supervision addict yapf pycocotools timm iopath 'transformers>=4.36,<5' # M7 依赖 uv pip install scikit-learn open3d pyrender PyOpenGL PyOpenGL_accelerate \ kornia omegaconf transformations h5py joblib ruamel.yaml \ trimesh pandas psutil warp-lang pybind11 # M9 依赖 uv pip install ikpy # FoundationPose 特有依赖 (需网络) uv pip install --no-build-isolation "git+https://github.com/NVlabs/nvdiffrast.git" uv pip install --no-build-isolation "git+https://github.com/facebookresearch/pytorch3d.git" # 编译 FoundationPose mycpp cd modules/07_pose_estimation/src/FoundationPose/mycpp rm -rf build && mkdir -p build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release \ -Dpybind11_DIR=$(python -c "import pybind11; print(pybind11.get_cmake_dir())") cmake --build . -j$(nproc) ``` ### 9. 构建 M10 依赖 (MGSfM + COLMAP 3.13.0) 详见 [M10 模块文档](modules/10_helmet_odometry/README.md) ## Docker 部署 ### 构建镜像 ```bash # 使用主机 VPN 代理加速下载 (端口 7897) docker build --network host -t dc-pipeline . # 不使用代理 docker build -t dc-pipeline . ``` ### 运行容器 ```bash bash run_container.sh ``` ## 快速开始 ### 完整管线 (单Episode) ```bash cd data_collection_ws source .venv/bin/activate BAG="data/raw_bags/test/155414.bag" OUT="data/output/ep_test" # M2 -> M3: 录制到预处理 python3 modules/03_preprocessing/scripts/preprocess_single.py \ --bag "$BAG" --output "$OUT" # M4: 立体校正 python modules/04_stereo_rectification/scripts/rectify_single.py \ --calib config --input "$OUT/images/head" --output "$OUT/rectified" # M5: 深度估计 python modules/05_depth_estimation/scripts/compute_depth_single.py \ --input "$OUT/rectified" --model modules/05_depth_estimation/weights/modelv2.pth \ --output "$OUT/depth" # M6: 夹爪遮罩 (4对双目分别生成) python modules/06_gripper_mask/scripts/generate_mask_single.py \ --image "$OUT/rectified/cam0_cam1/camL/000001.png" \ --prompt "robot gripper" --backend gdino_sam2 --output "$OUT/mask" # M7: 位姿估计 (需GPU) python modules/07_pose_estimation/scripts/estimate_pose_single.py \ --rgb "$OUT/rectified" --depth "$OUT/depth" \ --mask_dir "$OUT/mask" --calib "$OUT/rectified" \ --cam_pairs cam0_cam1 cam2_cam3 cam4_cam5 cam6_cam7 \ --output "$OUT/head_poses.json" # M7: 联合优化 python modules/07_pose_estimation/scripts/joint_optimization.py \ --head_poses "$OUT/head_poses.json" \ --extrinsics config \ --output "$OUT/head_poses_joint.json" # M10: 头盔里程计 python modules/10_helmet_odometry/scripts/estimate_helmet_pose_single.py \ --head_images "$OUT/images/head" --calib config \ --output "$OUT/helmet_trajectory.json" # M8: 世界帧优化 python modules/08_gtsam_optimization/scripts/chain_transforms.py \ --helmet_trajectory "$OUT/helmet_trajectory.json" \ --head_poses_joint "$OUT/head_poses_joint.json" \ --output "$OUT/gripper_world_initial.json" python modules/08_gtsam_optimization/scripts/optimize_single.py \ --head_poses "$OUT/head_poses_joint.json" \ --helmet_trajectory "$OUT/helmet_trajectory.json" \ --mode world --output "$OUT/optimized_world.json" ``` #### M9 → GR3 机器人回放 ```bash # Phase 1: RViz URDF 预览(安全,不需要真实机器人) source /opt/ros/noetic/setup.bash roscore & rosrun robot_state_publisher robot_state_publisher & python modules/09_arm_locator/scripts/send_to_gr3.py --mode rviz \ --result_dir data/output/ep_001/arm_result/ --fps 10 --loop # Phase 2: 干运行(验证关节限位) python modules/09_arm_locator/scripts/send_to_gr3.py --mode robot \ --result_dir data/output/ep_001/arm_result/ --dry_run # Phase 3: 真机回放(需在机器人NUC上安装 fourier-grx-client) python modules/09_arm_locator/scripts/send_to_gr3.py --mode robot \ --result_dir data/output/ep_001/arm_result/ \ --server_ip <机器人IP> --fps 5 --wait_ready --arm both ``` ## 模块详述 | 模块 | 功能 | 输入 | 输出 | |------|------|------|------| | M1 kalibr | 多相机/IMU联合标定 | 标定bag | camchain YAML | | M2 record | 8目+夹爪录制 | 传感器流 | ROS bag | | M3 preprocessing | bag解包+预处理 | ROS bag | PNG图像序列 | | M4 rectify | 双目立体校正 | kalibr参数 | 校正参数+映射 | | M5 depth | 深度估计 | 校正图像 | 16bit mm深度图 | | M6 mask | 夹爪检测分割 | RGB图像 | 二值mask | | M7 pose | 6DoF位姿估计 | RGB+深度+mask | 相机系夹爪位姿 | | M8 GTSAM | 因子图优化 | M7+M10位姿 | 世界系优化轨迹 | | M9 arm_locator | 臂部IK定位 → GR3回放 | 夹爪位姿 | 关节角度 → 机器人控制 | | M10 helmet | 头盔里程计 | 头盔图像 | 世界系头盔轨迹 | | M11 lerobot | 数据集导出 | 优化轨迹 | LeRobot格式 | ## TF 坐标树 ``` world (cam4 t=0, MGSfM原点) └── baselink (cam4 当前帧, M10输出) ├── cam0 ── cam0_optical ├── ... └── cam7 ── cam7_optical └── gripper_left / gripper_right (M7/M8输出) ``` ## 目录结构 ``` data_collection_ws/ ├── config/ # 标定+管线配置 ├── modules/ # 11个模块 │ ├── 01_calibration/ │ ├── 02_data_collection/ │ ├── 03_preprocessing/ │ ├── 04_stereo_rectification/ │ ├── 05_depth_estimation/ │ ├── 06_gripper_mask/ │ ├── 07_pose_estimation/ │ ├── 08_gtsam_optimization/ │ ├── 09_arm_locator/ │ ├── 10_helmet_odometry/ │ └── 11_lerobot_export/ ├── tools/ # 共享工具 ├── thirdparty/ # 预下载依赖 ├── Dockerfile ├── run_container.sh ├── entrypoint.sh ├── README.md # 英文文档 ├── README_zh.md # 本文档 └── 工作汇报.md # 项目进展汇报 ``` ## License 本项目用于学术研究目的。