文章目錄
- 前言
- 搭建開發環境
- 在window中安裝Unity
- 創建Docker容器,并安裝相關軟件
- 運行測試
- 改進
- 添加刪除節點前的函數調用
- 報錯
- ?框選節點的時候報錯
- ?如果無法控制機械臂,查看rviz2的終端,應該會有
- ?規劃路徑超出范圍
- 參考
前言
本項目介紹通過Unity3D仿真Panda機械臂,為研究機械臂的控制算法、控制效果和構建復雜仿真環境提供虛擬化平臺。
![]() | ![]() |
---|---|
2025-5-18 | 2025-6-2 |
要點:
PandaArmUnity3D
:Unity3D
項目ros2_docker_ws
:ros2
項目matlab
:包含了驗證機械臂位置正逆運動學的算法分析
video:
- 2025-6-2:YOLO機械臂丨使用unity搭建仿真環境,YOLO算法識別,Moveit2控制
- 2025-5-18: 機械臂位置正逆運動學原理與代碼
- 2025-4-13: ros2-rviz2控制unity仿真的6關節機械臂,探索從仿真到實際應用的過程
搭建開發環境
- Unity:2022
- Ubuntu:24.04
- Ros2:jazzy
在window中安裝Unity
先安裝Unityhuyb,然后再安裝Unity
https://unity.cn/releases
創建Docker容器,并安裝相關軟件
??創建Docker容器
docker run -it -p 6080:80 -p 10000:10000 -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=host.docker.internal:0.0 -e PULSE_SERVER=host.docker.internal --name=DockerUnityRos2Arm 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# 安裝遠程顯示服務程序
sudo apt-get install x11-xserver-utils
sudo apt install libxcb* -y
sudo apt-get install x11-apps -y# 安裝moveit
# 重新打開一個終端
sudo 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# 安裝運行`graph_executer_controller`相關的Python包
sudo apt update
sudo apt install python3-pip -y
sudo apt-get install portaudio19-dev -y
sudo apt install espeak -y# 安裝音頻
apt-get update && apt-get install -y alsa-utils pulseaudio
aplay -L # 列出音頻設備
# speaker-test -t wav # 測試播放# 使用清華源下載
cd src/graph_executer_controller/
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple --break-system-packages
pip install pyqtgraph ultralytics --break-system-packages# 調試工具
python3 -m pip install ipykernel -U --user --force-reinstall -i https://pypi.tuna.tsinghua.edu.cn/simple --break-system-packages# 配置Ubuntu支持中文
sudo apt-get install language-pack-zh-hans -y
apt install vim -yvim /etc/environment
# 添加內容
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh:en_US:en"vim /var/lib/locales/supported.d/local
# 添加內容
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
zh_CN.GBK GBK
zh_CN GB2312sudo locale-gen# 安裝中文字體
sudo apt-get install fonts-droid-fallback ttf-wqy-zenhei ttf-wqy-microhei fonts-arphic-ukai fonts-arphic-uming -y# 安裝支持playsound的庫
apt-get install libgstrtspserver-1.0-dev gstreamer1.0-rtsp -y
運行測試
??在windows上運行PulseAudio
服務
??啟動Unity
??編譯項目
colcon build
??啟動tcp,用于ros2與unity連接
source install/setup.bash
ros2 launch ros_tcp_endpoint endpoint.launch.py
??運行moveitpy_controller
# 打開新的終端
source install/setup.bash
ros2 launch control_server arm_control.launch.py
??運行graph_executer_controller
# 打開新的終端
source install/setup.bash
cd src/graph_executer_controller
python3 main.py
??運行panda_moveit_config
的demo.launch.py
# 打開新的終端
source install/setup.bash
ros2 launch panda_moveit_config demo.launch.py
啟動rviz2后,可以看到機械臂會有干涉,現手動調整到不干涉的位置,然后才使用moveitpy控制機械臂,否則無法控制機械臂。
改進
添加刪除節點前的函數調用
問題描述:由于nodegraphqt沒有刪除節點的操作,這里為其添加。
在/usr/local/lib/python3.12/dist-packages/NodeGraphQt/base/graph.py
的NodeGraph
類的delete_node(self, node, push_undo=True)
函數中添加以下內容:
if hasattr(node, '_del_node'):node._del_node()
報錯
?框選節點的時候報錯
File "/usr/local/lib/python3.12/dist-packages/NodeGraphQt/widgets/viewer.py", line 619, in mouseMoveEventself.scene().setSelectionArea(
TypeError: 'PySide6.QtWidgets.QGraphicsScene.setSelectionArea' called with wrong argument types:PySide6.QtWidgets.QGraphicsScene.setSelectionArea(QPainterPath, ItemSelectionMode)
Supported signatures:PySide6.QtWidgets.QGraphicsScene.setSelectionArea(path: PySide6.QtGui.QPainterPath, /, selectionOperation: PySide6.QtCore.Qt.ItemSelectionOperation = Instance(Qt.ReplaceSelection), mode: PySide6.QtCore.Qt.ItemSelectionMode = Instance(Qt.IntersectsItemShape), deviceTransform: PySide6.QtGui.QTransform = Default(QTransform))PySide6.QtWidgets.QGraphicsScene.setSelectionArea(path: PySide6.QtGui.QPainterPath, deviceTransform: PySide6.QtGui.QTransform, /)
Error calling Python override of QGraphicsView::mouseMoveEvent(): Traceback (most recent call last):File "/usr/local/lib/python3.12/dist-packages/NodeGraphQt/widgets/viewer.py", line 619, in mouseMoveEventself.scene().setSelectionArea(
TypeError: 'PySide6.QtWidgets.QGraphicsScene.setSelectionArea' called with wrong argument types:PySide6.QtWidgets.QGraphicsScene.setSelectionArea(QPainterPath, ItemSelectionMode)
Supported signatures:PySide6.QtWidgets.QGraphicsScene.setSelectionArea(path: PySide6.QtGui.QPainterPath, /, selectionOperation: PySide6.QtCore.Qt.ItemSelectionOperation = Instance(Qt.ReplaceSelection), mode: PySide6.QtCore.Qt.ItemSelectionMode = Instance(Qt.IntersectsItemShape), deviceTransform: PySide6.QtGui.QTransform = Default(QTransform))PySide6.QtWidgets.QGraphicsScene.setSelectionArea(path: PySide6.QtGui.QPainterPath, deviceTransform: PySide6.QtGui.QTransform, /)
??Pyside6和nodegraphqt版本不適配導致,更改viewer.py
以下位置即可:
# "/usr/local/lib/python3.12/dist-packages/NodeGraphQt/widgets/viewer.py"# self.scene().setSelectionArea(
# path, QtCore.Qt.IntersectsItemShape
# )
self.scene().setSelectionArea(path,selectionOperation=QtCore.Qt.ItemSelectionOperation.ReplaceSelection,mode=QtCore.Qt.ItemSelectionMode.IntersectsItemShape
)
?如果無法控制機械臂,查看rviz2的終端,應該會有
[move_group-3] [ERROR] [1748613208.480924749] [move_group.moveit.moveit.ros.check_start_state_bounds]: Joint 'panda_joint2' from the starting state is outside bounds by: [1.76294 ] should be in the range [-1.7628 ], [1.7628 ].
[move_group-3] [ERROR] [1748613208.480986559] [move_group]: PlanningRequestAdapter 'CheckStartStateBounds' failed, because 'Start state out of bounds.'. Aborting planning pipeline.
??:重新啟動rviz2即可
?規劃路徑超出范圍
[ERROR] [1742603349.012384448] [moveit_3836862178.moveit.ros.check_start_state_bounds]: Joint 'panda_finger_joint1' from the starting state is outside bounds by: [-6.61565e-14 ] should be in the range [0 ], [0.04 ].
[ERROR] [1742603349.012503158] [moveit_py]: PlanningRequestAdapter 'CheckStartStateBounds' failed, because 'Start state out of bounds.'. Aborting planning pipeline.
[ERROR] [1742603349.013678982] [moveit_py.pose_goal]: Planning failed
??修改joint_limits.yaml
,限制關節的最大最小位置
參考
- 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
- JSON Output
- DeepSeek提示庫
- Binary Installation on Ubuntu
- Docs / Gazebo Harmonic
- ros_gz branch jazzy
- Binary Installation on Ubuntu
- Docs / Gazebo Harmonic
- ros_gz branch jazzy
關注👇👇,發送:DockerRos2UnityArm,方便獲取仿真代碼。