当前位置: 首页 > news >正文

ros2-rviz2控制unity仿真的6关节机械臂,探索从仿真到实际应用的过程


文章目录

    • 前言(Introduction)
    • 搭建开发环境(Setup Development Environment)
    • 在window中安装Unity(Install Unity in window)
    • 创建Docker容器,并安装相关软件(Create Docker containers and install related software)
    • 运行测试(Run test)

前言(Introduction)

在这里插入图片描述

当机器人遇上游戏引擎:用Unity玩转机械臂仿真,妈妈再也不用担心我的Gazebo崩溃了!

想用Gazebo给机器人搞个仿真?恭喜你,即将开启“从入门到放弃”的经典副本——环境配置复杂得像解一道高数题,而构建复杂场景时,Gazebo可能会用“卡顿”和“崩溃”来考验你的耐心。尤其对新手来说,光是搞明白为什么模型突然飞天遁地,就足以让人怀疑人生。

但别慌!这里有个更快乐(且不会让你头秃)的方案——用Unity搭建仿真环境! 没错,就是那个做《原神》和《王者荣耀》的Unity!它不仅能让你像搭积木一样轻松构建场景,还能搞定Gazebo挠破头都难实现的复杂环境(比如让机械臂在火星捡土豆,或者在水下拧瓶盖)。

今天,我们就来点好玩的:用Unity仿真一个机械臂,再通过ROS2和RViz远程操控它! 从此,你可以在Unity里造个虚拟实验室,而ROS2负责当“传话小哥”,让现实和仿真无缝对接。

为什么选Unity?

  • 简单到流泪:拖拖拽拽就能建场景,不用再和URDF文件“打架”。

  • 画质狂魔:想要光影效果?想要真实物理?Unity表示:“就这?”

  • ROS2的好基友:通过ROS-TCP-Connector,Unity和ROS2秒变最佳拍档。

准备好让你的机械臂在Unity里跳个舞了吗?Let’s go!(Gazebo:明明是我先来的……)

When Robots Meet Game Engines: Simulating Robotic Arms with Unity—Because Gazebo Crashes Are So Last Season!

Trying to set up a robot simulation in Gazebo? Congratulations, you’re about to embark on the classic “From Beginner to Burnout” quest—where environment configuration feels like solving advanced calculus, and building complex scenes comes with Gazebo’s signature “lag-and-crash” combo. For beginners, just figuring out why your robot suddenly decided to phase through the floor or launch into orbit is enough to trigger an existential crisis.

But fear not! There’s a far more joyful (and less hair-pulling) alternative—building your simulation in Unity! Yep, the same Unity behind Genshin Impact and Honor of Kings. Not only does it let you assemble scenes like virtual LEGO, but it also handles complex environments that would make Gazebo sweat bullets (think robotic arms picking potatoes on Mars or unscrewing bottles underwater).

Today, we’re doing something fun: simulating a robotic arm in Unity and controlling it remotely via ROS2 and RViz! Now you can build a virtual lab in Unity while ROS2 acts as the middleman, seamlessly bridging simulation and reality.

Why Unity?

  • So easy it hurts—Drag, drop, and build scenes without wrestling with URDF files.

  • Graphics wizardry—Want realistic lighting and physics? Unity scoffs, “Is that all?”

  • ROS2’s best buddy—With ROS-TCP-Connector, Unity and ROS2 become the ultimate dynamic duo.

Ready to make your robotic arm dance in Unity? Let’s go! (Gazebo: “But… I was here first…”)

video:ros2-rviz2控制unity仿真的6关节机械臂,探索从仿真到实际应用的过程

code: https://github.com/laoxue888/DockerRos2UnityArm

参考:

  • docker-ros2-unity-tcp-endpoint
  • Robotics-Nav2-SLAM-Example
  • unity坐赛车游戏,简单三分钟了解一下
  • How to Setup Unity and ROS2 in less than 5 minutes!
  • ros2-for-unity
  • moveit2_yolobb_ws
  • Unity-Robotics-Hub

搭建开发环境(Setup Development Environment)

  • Unity:2022
  • Ubuntu:24.04
  • Ros2:jazzy

在window中安装Unity(Install Unity in window)

先安装Unityhuyb,然后再安装Unity

https://unity.cn/releases

创建Docker容器,并安装相关软件(Create Docker containers and install related software)

❇️创建Docker容器

docker run -it -p 6080:80 -p 10000:10000 -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=host.docker.internal:0.0 --gpus=all --name=Ros2UnityArm docker.1ms.run/ubuntu:24.04  /bin/bash

❇️安装相关软件

# 按照鱼香ros一键安装ros2
apt-get update
apt install wget -y
wget http://fishros.com/install -O fishros && bash fishros


# 安装远程显示服务程序
apt-get install x11-xserver-utils
apt install libxcb* -y
apt-get install x11-apps -y

# 安装moveit
apt install ros-${ROS_DISTRO}-moveit* -y

# 安装ros2的控制功能包
sudo apt install ros-${ROS_DISTRO}-controller-manager -y
sudo apt install ros-${ROS_DISTRO}-joint-trajectory-controller -y
sudo apt install ros-${ROS_DISTRO}-joint-state-broadcaster -y
sudo apt install ros-${ROS_DISTRO}-diff-drive-controller -y

# 安装其他功能包
# apt install ros-${ROS_DISTRO}-ros-gz -y
apt-get install ros-${ROS_DISTRO}-joint-state-publisher-gui -y
apt install ros-${ROS_DISTRO}-moveit-ros-planning-interface -y
# apt install ros-jazzy-gz-ros2-control 这个很重要 https://github.com/ros-controls/gz_ros2_control
apt install ros-${ROS_DISTRO}-gz-ros2-control -y

# 用于调试,可不安装
apt-get install gdb -y

运行测试(Run test)

source install/setup.bash
ros2 launch ros_tcp_endpoint endpoint.launch.py
source install/setup.bash
ros2 run unity_control_example follow_joint_trajectory_monitor
source install/setup.bash
ros2 launch niryo_one_moveit_config demo.launch.py

相关文章:

  • 论文精度:HeightFormer:基于Transformer的体素高度预测在路边3D目标检测中的应用
  • flutter 桌面应用之右键菜单
  • 【Cursor 】Cursor 安装与配置指南:从零开始的高效开发之旅
  • QT6 源(16):存储 QT 里元对象的类信息的类 QMetaClassInfo 的类,只有两个成员函数 name()、value(),比元对象属性简单多了
  • 数据驱动,数字能量分析API助力手机号数据解读
  • RAG Fusion技术详解与应用场景
  • 趣味编程之Spring的白学之路
  • 二、Android Studio环境安装
  • [React] 如何用 Zustand 构建一个响应式 Enum Store?附 RTKQ 实战与 TS 架构落地
  • 波束形成(BF)从算法仿真到工程源码实现-第七节-关于波束10个基本概念
  • Jenkins 发送钉钉消息
  • 前端jest(vitest)单元测试快速手上
  • Redis基础知识:
  • 解释:指数加权移动平均(EWMA)
  • C++ 编程指南36 - 使用Pimpl模式实现稳定的ABI接口
  • 链接世界:计算机网络的核心与前沿
  • 使用SSH解决在IDEA中Push出现403的问题
  • 基于电子等排体的3D分子生成模型 ShEPhERD - 评测
  • 从代码学习深度学习 - 多头注意力 PyTorch 版
  • 【2025软考高级架构师】——项目管理(3)
  • 1块钱解锁2万部微短剧还能日更,侵权盗版难题怎么破?
  • “上海-日喀则”援藏入境旅游包机在沪首航
  • 阳光保险拟设立私募证券投资基金,总规模200亿元
  • 大陆非遗项目打铁花、英歌舞将在台演出
  • 蒋圣龙突遭伤病出战世预赛存疑,国足生死战后防线严重减员
  • 国防部:菲方应停止一切侵权挑衅危险举动,否则只会自食苦果