文章目錄
- 前言(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