Gazebo 仿真环境搭建指南(Ubuntu 22.04)
这里以 Ubuntu 22.04 和 ROS 2 Humble Hawksbill 为例。注意,Ubuntu 22.04 通常推荐使用 ROS 2 Humble。
完整 ROS 2 Humble 安装流程
# 1. 确保系统最新
sudo apt update && sudo apt upgrade -y
# 2. 安装基础依赖
sudo apt install software-properties-common curl gnupg lsb-release
# 3. 添加 Ubuntu Universe 仓库(如果未启用)
sudo add-apt-repository universe
# 4. 添加 ROS 源(使用现代方法)
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key | sudo tee /usr/share/keyrings/ros-archive-keyring.gpg > /dev/null
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list
# 5. 更新并安装 ROS
sudo apt update
sudo apt install ros-humble-desktop -y
# 6. 安装构建工具
sudo apt install python3-colcon-common-extensions python3-rosdep -y
sudo rosdep init
rosdep update
# 7. 配置环境
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc
安装 Gazebo Fortress(ROS Humble 推荐版本)
# 1. 确保系统已更新
sudo apt update
sudo apt upgrade -y
# 2. 安装与 ROS Humble 兼容的 Gazebo
sudo apt install -y \
gazebo \
libgazebo-dev \
gazebo-plugin-base \
gazebo-common \
ros-humble-gazebo-ros-pkgs
# 3. 验证安装的 Gazebo 版本
gazebo --version
安装 TurtleBot3 完整依赖
# 安装所有必要的 TurtleBot3 依赖
sudo apt install -y \
ros-humble-turtlebot3 \
ros-humble-turtlebot3-msgs \
ros-humble-turtlebot3-description \
ros-humble-turtlebot3-simulations \
ros-humble-turtlebot3-gazebo \
ros-humble-gazebo-ros-pkgs
在官方预定义世界启动 TurtleBot3 Waffle Pi
# 将 waffle_pi 设为默认机器人型号
echo "export TURTLEBOT3_MODEL=waffle_pi" >> ~/.bashrc
source ~/.bashrc
# 启动空世界
ros2 launch turtlebot3_gazebo turtlebot3_empty_world.launch.py
# 启动带房子的世界
ros2 launch turtlebot3_gazebo turtlebot3_house.launch.py
# 启动带迷宫的挑战世界
ros2 launch turtlebot3_gazebo turtlebot3_world_maze.launch.py
可能出现的问题
启动后黑屏
# 软件渲染模式
export LIBGL_ALWAYS_SOFTWARE=1
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
模型加载缓慢
# 提前下载所有模型
mkdir -p ~/.gazebo/models
wget https://github.com/osrf/gazebo_models/archive/refs/heads/master.zip
unzip master.zip -d ~/.gazebo/models
rm master.zip
摄像头不显示图像
# 安装必要的编解码器
sudo apt install -y gstreamer1.0-plugins-bad gstreamer1.0-plugins-base
