Skip to content

WantDog/camera_ros2_yolo_tool_learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

多种相机驱动、机械臂运动规划和YOLO目标检测

个人的学习记录和好用的工具🤖

ROS2 Humble Ubuntu 22.04 MoveIt2 License

集成多类型相机驱动、MoveIt2机械臂控制和YOLO目标检测

📁 项目结构

robot_toolkit/
├── D435i/                      # Intel D435i 独立录制工具
│   ├── camera.cpp              # 视频录制程序
│   └── CMakeLists.txt
│
├── ros2_camera_calibration/    # ROS2 相机驱动与标定
│   ├── d435_publisher/         # D435i ROS2驱动节点
│   ├── hk_cam_node/            # 海康威视相机节点
│   ├── usb_cam_publisher/      # USB相机节点
│   └── camera_driver/          # 海康SDK封装库
│
├── my_moveit/                  # MoveIt2 机械臂控制
│   ├── src/
│   │   ├── hello_moveit/       # 基础运动规划示例
│   │   └── mtc_tutorial/       # MTC抓取任务示例
│   └── urdf/                   # 机械臂URDF模型库
│       ├── arm_five/           # 五轴机械臂
│       ├── ur3/                # UR3机械臂
│       └── ur_description/     # UR系列完整模型
│
└── yolo_tool/                  # YOLO目标检测工具
    ├── 数据集处理/              # 数据集制作GUI工具
    ├── classify_dir.py         # 文件分类脚本
    └── split_dataset.py        # 数据集划分脚本

🚀 快速开始

环境要求

组件 版本 说明
Ubuntu 22.04 LTS 操作系统
ROS2 Humble Hawksbill 机器人中间件
OpenCV 4.7.0+ 计算机视觉库
MoveIt2 最新版 运动规划框架
RealSense SDK 2.0+ D435i驱动

安装依赖

# 安装ROS2 Humble (如未安装)
sudo apt update && sudo apt install -y curl gnupg lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt update
sudo apt install ros-humble-desktop

# 安装项目依赖
sudo apt install -y \
    ros-humble-moveit \
    ros-humble-camera-calibration \
    ros-humble-camera-info-manager \
    ros-humble-cv-bridge \
    ros-humble-image-transport \
    librealsense2-dev \
    librealsense2-utils \
    python3-pip \
    python3-opencv

# 安装Python依赖
pip3 install ultralytics torch torchvision

编译项目

# 创建工作空间
mkdir -p ~/robot_ws/src
cd ~/robot_ws/src

<<<<<<< HEAD
- [相机标定指南](ros2_camera_calibration/README.md)
- [MoveIt2开发经验](my_moveit/机械臂开发经验.md)  
- [YOLO工具使用](yolo_tool/数据集处理/README.md)
=======
# 克隆项目 (替换为实际仓库地址)
git clone <your-repo-url> .

# 编译
cd ~/robot_ws
source /opt/ros/humble/setup.bash
colcon build --symlink-install

# 设置环境
source install/setup.bash

📖 使用指南

1️⃣ 相机驱动

Intel D435i

# 启动D435i发布节点
ros2 launch d435_publisher d435_launch.py

# 查看图像
ros2 run rqt_image_view rqt_image_view /d435/color/image_raw

USB相机

# 启动USB相机 (默认/dev/video2)
ros2 launch usb_cam_publisher usb_cam_launch.py

# 或使用默认参数
ros2 run usb_cam_publisher usb_cam_publisher

海康威视相机

# 确保配置文件路径正确
camera_driver/camera_init/HIKcamera0.yaml

# 启动海康相机节点
ros2 run hk_cam_node hk_cam_node

2️⃣ 机械臂控制

显示机械臂模型

# 五轴机械臂
ros2 launch arm_five display.launch.py

# UR3机械臂
ros2 launch ur3 display.launch.py

运行运动规划示例

# 基础点规划示例
ros2 run hello_moveit hello_moveit_2

# MTC抓取任务示例
ros2 run mtc_tutorial mtc_node

3️⃣ 相机标定

# 安装标定工具
sudo apt install ros-humble-camera-calibration

# 启动相机并运行标定
ros2 launch d435_publisher d435_calibration_launch.py

# 运行标定程序 (8x6棋盘格,方格大小4cm)
ros2 run camera_calibration cameracalibrator \
    --size 8x6 \
    --square 0.04 \
    image:=/camera/image_raw \
    camera:=/camera

4️⃣ YOLO数据集工具

cd yolo_tool/数据集处理

# 安装依赖
pip install -r requirements.txt

# 启动GUI工具
python3 main.py

功能选项:

  1. Record Video - 录制训练视频 (按A开始,S停止)
  2. Extract Frames - 从视频提取帧
  3. Rename Frames - 批量重命名图像
  4. Delete Unpaired Labels - 清理无效标签
  5. Labeling - 使用YOLO模型自动标注

📚 详细文档

模块 文档 说明
相机标定 ros2_camera_calibration/README.md 三种相机的标定流程
机械臂开发 my_moveit/机械臂开发经验.md MoveIt2配置与开发经验
YOLO工具 yolo_tool/数据集处理/README.md 数据集制作完整指南

🔧 开发指南

编译单个包

# 只编译指定包
colcon build --packages-select d435_publisher

# 编译并允许警告
colcon build --packages-select hello_moveit --cmake-args -DCMAKE_CXX_FLAGS="-Wno-dev"

调试技巧

# 查看TF树
ros2 run tf2_tools view_frames

# 查看话题列表
ros2 topic list

# 查看节点图
ros2 run rqt_graph rqt_graph

# 检查相机内参
ros2 topic echo /camera/camera_info

🏗️ 系统架构

┌─────────────────────────────────────────────────────────────┐
│                    应用层 (Application)                      │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐  │
│  │  视觉检测    │  │  运动规划    │  │    相机标定         │  │
│  │  (YOLO)     │  │  (MoveIt2)  │  │  (camera_calibration)│ │
│  └──────┬──────┘  └──────┬──────┘  └──────────┬──────────┘  │
└─────────┼────────────────┼────────────────────┼─────────────┘
          │                │                    │
┌─────────▼────────────────▼────────────────────▼─────────────┐
│                    中间件 (ROS2 Humble)                      │
│         话题通信 / 服务调用 / Action / TF变换                 │
└─────────┬────────────────┬────────────────────┬─────────────┘
          │                │                    │
┌─────────▼────────────────▼────────────────────▼─────────────┐
│                    硬件接口层 (Hardware)                      │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐  │
│  │  D435i相机   │  │  海康相机    │  │    USB相机          │  │
│  │  (RealSense)│  │  (GigE/USB3)│  │    (V4L2)           │  │
│  └─────────────┘  └─────────────┘  └─────────────────────┘  │
│  ┌─────────────────────────────────────────────────────────┐│
│  │              机械臂控制器 (ROS2 Control)                 ││
│  │         arm_controller / gripper_controller             ││
│  └─────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────┘

🐛 常见问题

Q: D435i无法识别

# 检查USB连接
lsusb | grep Intel

# 检查权限
sudo usermod -a -G dialout $USER
# 重新登录后生效

Q: MoveIt规划失败

  • 检查目标点是否在机械臂可达范围内
  • 增加规划时间和尝试次数
  • 检查是否有碰撞物体干扰

Q: 海康相机启动失败

  • 确认配置文件路径正确
  • 检查相机IP地址和网线连接
  • 确认海康SDK库文件存在

📄 许可证

本项目采用 MIT License 开源许可证。

🙏 致谢


Made with ❤️ for robotics enthusiasts

About

多种相机驱动(Intel D435i深度相机、海康威视工业相机、USB相机)的ROS2节点,支持相机标定与图像发布。包含MoveIt运动规划框架的机械臂控制实现(学习),以及YOLO目标检测的数据集处理工具。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors