Skip to content

GO2 + Humble + YOLOv8 in Real 简述:基于视频流的目标检测与视觉伺服控制系统,结合键盘遥控和YOLO目标识别,实现对 Unitree Go2 的自主与人工控制。

License

Notifications You must be signed in to change notification settings

Baituhao/Go2VisionCtrl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go2 Vision-Based Motion and Teleoperation Control System

GO2 + Humble + YOLOv8 in Real

简述:基于视频流的目标检测与视觉伺服控制系统,结合键盘遥控和YOLO目标识别,实现对 Unitree Go2 的自主与人工控制。

GO2 + Humble + YOLOv8 in Real

系统环境: Ubuntu 22.04.5 LTS

一、环境搭建

1. 安装ROS2 Humble

sudo apt update && sudo apt install locales -y
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
sudo apt install software-properties-common -y
sudo add-apt-repository universe
sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo tee /etc/apt/keyrings/ros.asc > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/ros.asc] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo "$UBUNTU_CODENAME") main" | \
sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt update
sudo apt upgrade -y
sudo apt install ros-humble-desktop -y
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc
ros2 run demo_nodes_cpp talker

注意: 你应该能看到 ROS 2 节点在发布消息(需要另一个终端运行 listener 来接收)。

2. Unitree_GO2 + ROS2 服务接口配置

参考宇树官方文档,直至连接测试完成。

文档链接:https://support.unitree.com/home/zh/developer/ROS2_service

3. Gst 安装(图传依赖)

wget https://launchpad.net/ubuntu/+archive/primary/+files/libgbm-dev_23.2.1-1ubuntu3.1~22.04.2_amd64.deb
wget https://mirrors.ocf.berkeley.edu/ubuntu/pool/main/libd/libdrm/libdrm-dev_2.4.113-2~ubuntu0.22.04.1_amd64.deb
sudo dpkg -i libdrm-dev_2.4.113-2~ubuntu0.22.04.1_amd64.deb
sudo dpkg -i libgbm-dev_23.2.1-1ubuntu3.1~22.04.2_amd64.deb
# 自动查找缺失的依赖并安装
sudo apt-get install -f
# Gst安装
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio

验证安装:

python3 -c "import cv2; print(cv2.__file__)"
python3 -c "import cv2; print(cv2.getBuildInformation())" | grep GStreamer

提示: 看到 GStreamer: YES,就大功告成!

4. 克隆仓库GO2VisionCtrl

sudo apt install git
cd ~
git clone https://github.com/Baituhao/Go2VisionCtrl

5. YOLOv8安装

sudo apt install python3-pip
pip3 install ultralytics
cd ~/Go2VisionCtrl
python3 -c "from ultralytics import YOLO; YOLO('yolov8n.pt')"

6. 编译运行

步骤1: 检查 go2_driver/params/params_driver.yaml 文件中网络接口 iface,修改为实际网口。

cd ~/Go2VisionCtrl
colcon build
cd ~/Go2VisionCtrl
ros2 launch go2_driver driver.launch.py

预期结果: 正常情况下可以看到rviz,rviz中GO2姿态和实机一致,有雷达显示。可以看到前置摄像头视频窗口,且窗口中会标出瓶子的检测框。

步骤2: 检查 rotate_detector.py 文件中网络接口 iface,修改为实际网口。

cd ~/Go2VisionCtrl
ros2 launch rotate_detector rotate_detector

提示: Go2会绕着瓶子旋转,速度参数可以在 src/base/go2_driver/params/params_driver.yaml 中设置。

二、包功能说明

driver.launch.py

文件路径: go2_driver/launch/driver.launch.py

功能简介:

该 ROS 2 启动文件统一集成并启动了 Unitree Go2 机器人系统的多个核心节点,主要包括:可视化、传感器处理、运动桥接、模型驱动与视觉检测等模块,便于快速部署和调试完整系统。

运行命令:

ros2 launch go2_driver driver.launch.py

预期结果: 正常情况下可以看到rviz,rviz中GO2姿态和实机一致,有雷达显示。可以看到前置摄像头视频窗口,且窗口中会标出瓶子的检测框。

rotate_detector

功能描述:

实现目标跟随控制逻辑 —— 若在图像中检测到瓶子目标,则控制GO2原地左右旋转,使目标居中。若未检测到,则GO2停止或主动搜索。

技术要点:

  • YOLOv8 模型检测目标位置;
  • 计算目标中心与图像中心偏移,根据偏移控制角速度;
  • 自动停止或旋转寻找目标;
  • 发布动作指令至 /api/sport/request

运行命令:

ros2 run rotate_detector rotate_detector

go2_teleop_ctrl_keyboard

功能描述:

实现基于键盘的遥控控制,支持基础移动(线速度/角速度控制)、多种运动模式(如打招呼、坐下等)、速度调整等。

技术要点:

  • 键盘读取采用 termios;
  • 使用 unitree_api/msg/Request 消息发布运动控制指令;
  • 控制命令包括移动(MOVE)、站立(BALANCESTAND)、姿态切换等;
  • 支持动态调节线速度与角速度参数。

用途: 手动控制GO2移动站立趴下进行测试或演示。

运行命令:

ros2 run go2_teleop_ctrl_keyboard go2_teleop_ctrl_keyboard

go2_front_video_viewer

功能描述:

仅用于视频图像显示,不进行目标检测或控制动作。用于前视相机的可视化验证和调试。

技术要点:

  • GStreamer 多播视频流接入;
  • 图像通过 OpenCV imshow() 实时显示;
  • 参数 show_camera_image 控制是否启用显示功能。

用途: 调试视频流连接、测试网络接口与画面质量。

运行命令:

ros2 run go2_front_video_viewer go2_front_video_viewer

front_detector

功能描述:

基于 YOLOv8 对前视相机中的图像进行实时目标检测(瓶子类目标),并使用 OpenCV 绘制检测结果。

技术要点:

  • 使用 Ultralytics YOLOv8 模型进行图像推理;
  • GStreamer 管道从 UDP 多播地址接收视频流;
  • 每帧绘制识别框与置信度,并支持通过 q 键退出节点。

用途: 适用于需实时检测瓶子(或其他指定类别)任务的场景,如目标定位、避障前感知等。已经集成到 driver.launch.py

运行命令:

ros2 run front_detector front_detector

retimestamp

功能描述:

对接收到的激光雷达点云数据 /utlidar/cloud 进行时间戳替换(使用当前 walltime),并发布到新话题 /cloud_retimestamp

技术要点:

  • 订阅 PointCloud2 消息;
  • 通过 get_clock().now().to_msg() 重新设置时间戳;
  • 保持消息结构不变,仅刷新时间。

用途: 解决仿真/回放过程中时间戳异常问题,提高同步精度。已经集成到 driver.launch.py

三、正在尝试的路线

【1】使用Claude MCP 多模态发布GO2 运动消息

# Clone this repository
git clone https://github.com/aaddrick/claude-desktop-debian.git
cd claude-desktop-debian

# Build the package (Defaults to .deb and cleans build files)
./build.sh

# Example: Build an AppImage and keep intermediate files
./build.sh --build appimage --clean no

# Example: Build a .deb (explicitly) and clean intermediate files (default)
./build.sh --build deb --clean yes

sudo dpkg -i ~/claude-desktop-debian/claude-desktop_0.12.28_amd64.deb

配置步骤:

  • 在 Cursor IDE 中设置MCP Tools,在 mcp.json 文件中设置:
{
  "mcpServers": {
      "unitree-go2-mcp-server": {
          "command": "uv",
          "args": [
            "--directory",
            "/home/nuc/unitree-go2-mcp-server",
            "run",
            "server.py"
          ]
      }
  }
}
  • 在Cursor IDE 中的大模型对话框中选择Agent,此时在项目文件夹下bash运行 uv run server.py,和Agent对话即可收到指令。

示例图片

【2】使用RealSenseD435i深度相机读取深度

安装步骤:

  • 安装 librealsense2_jammy_x86_debians_beta.zip
    • 下载链接:Intel® RealSense™ SDK 2.0 beta (v2.56.3)
    • 解压并安装所有 .deb

验证相机连接:

realsense-viewer

About

GO2 + Humble + YOLOv8 in Real 简述:基于视频流的目标检测与视觉伺服控制系统,结合键盘遥控和YOLO目标识别,实现对 Unitree Go2 的自主与人工控制。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published