gazebo仿真中遇到的坑

1.urdf中的关节无法加载到gazebo

[error]:This robot has a joint named “joint_1” which is not in the gazebo model.

原因:urdf的link标签下的惯性设置问题

已解决,参考:https://answers.ros.org/question/238899/this-robot-has-a-joint-named-joint_1-which-is-not-in-the-gazebo-model/


2.urdf的标签缺少hardware_interface/

[ WARN] [1592977254.131172803, 0.157000000]: Deprecated syntax, please prepend ‘hardware_interface/’ to ‘PositionJointInterface’ within the tag in joint ‘shoulder_pan_joint’.

已解决。
提示已经很明显了,把下面的标签

<hardwareInterface>PositionJointInterface</hardwareInterface>

换成这个:

<hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>

3.没有指定pid

No p gain specified for pid

已解决,参考:
1.https://answers.ros.org/question/293830/what-is-the-fix-for-no-p-gain-specified-for-pid-namespace-gazebo_ros_controlpid_gainsback_right_wheel_joint-ros-melodic/

2.http://www.dtmao.cc/news_show_494301.shtml

3.https://www.pianshen.com/article/44461332312/

虽然3个都差不多但还是建议都打开看看


4.urdf文件和python编码冲突导致无法加载参数服务器

UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-1: ordinal not in range

在这里插入图片描述urdf采用UTF-8的编码方式,而python默认采用ascll码

已解决

参考(一个是原因,一个是解决办法):
https://www.cnblogs.com/excellentlhw/p/10916953.html
https://blog.csdn.net/weixin_39221360/article/details/79525341
解决方法有三种:


                
<think>我们正在安装ROS2(Humble版本,并配置Gazebo11。根据引用,Ubuntu22.04对应ROS2Humble版本,而Gazebo11是ROS2Humble推荐搭配的版本(尽管Gazebo11通常与ROS1搭配,但ROS2Humble也可以使用它,但注意官方推荐的是GazeboFortress,但考虑到用户要求Gazebo11,我们按照用户要求进行)。 步骤: 1. 准备工作:换源(确保下载速度快) 2. 设置语言环境(确保无语言问题) 3. 添加ROS2仓库和密钥 4. 安装ROS2 Humble 5. 安装Gazebo11 6. 配置环境变量 7. 测试安装 注意:由于Gazebo11并不是ROS2Humble的官方默认仿真器(官方默认是GazeboFortress),所以安装Gazebo11可能需要额外的步骤,并且可能遇到兼容性问题。但用户要求Gazebo11,我们将尝试安装。 具体步骤: 1. 换国内源(如阿里源)以加速下载(非常重要,避免下载失败): ```bash sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.aliyun.com@g" /etc/apt/sources.list sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.aliyun.com@g" /etc/apt/sources.list sudo apt update ``` 2. 设置语言环境(确保是UTF-8): ```bash sudo apt update && sudo apt install locales 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 ``` 3. 添加ROS2仓库: ```bash sudo apt install software-properties-common sudo add-apt-repository universe sudo apt update && sudo apt install curl -y sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] 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 ``` 4. 安装ROS2 Humble桌面版(包含ROS、RViz、示例等): ```bash sudo apt update sudo apt install ros-humble-desktop ``` 5. 安装colcon构建工具(用于构建ROS2工作空间): ```bash sudo apt install python3-colcon-common-extensions ``` 6. 安装Gazebo11: Gazebo11在Ubuntu22.04的官方仓库中可能没有,因为Ubuntu22.04默认的Gazebo版本是Fortress。但我们可以尝试从旧版本的Ubuntu仓库中安装,但这样可能存在兼容性问题。或者,我们可以使用osrf的仓库来安装Gazebo11。 方法:添加osrf的仓库并安装Gazebo11 ```bash sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add - sudo apt update sudo apt install gazebo11 libgazebo11-dev ``` 注意:如果上述方法失败,可以尝试直接安装Ubuntu提供的gazebo包(但Ubuntu22.04默认只有gazebo-fortress,所以我们需要指定版本): ```bash sudo apt install gazebo11 # 如果直接可用 ``` 如果不可用,可能需要下载源码编译,但这样比较复杂,我们尽量使用二进制安装。 7. 安装ROS2与Gazebo的桥接包(ros_gz): 由于ROS2 Humble官方支持的是Gazebo Fortress,所以对于Gazebo11,我们需要安装兼容的桥接包。但是,请注意,ros_gz_bridge包可能对Gazebo11的支持有限。 我们可以尝试安装ros-humble-ros-gz包(这个包是用于与Gazebo交互的,但可能只支持Fortress)。不过,我们可以尝试安装旧版本的桥接包(如果有的话)。但官方可能没有提供针对Gazebo11的桥接包。因此,这里我们安装通用的桥接包,并希望它能工作。 安装: ```bash sudo apt install ros-humble-ros-gz ``` 如果上述包不存在,可以尝试从源码编译ros_gz_bridge,但需要指定分支(例如,使用Gazebo11的分支)。这比较复杂,我们暂时先使用二进制安装。 8. 配置环境变量: 将ROS2的环境变量添加到bashrc中: ```bash echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc source ~/.bashrc ``` 9. 测试: - 测试ROS2:打开一个终端,运行: ```bash ros2 run demo_nodes_cpp talker ``` 在另一个终端运行: ```bash ros2 run demo_nodes_py listener ``` 如果能看到消息传递,则ROS2安装成功。 - 测试Gazebo:运行: ```bash gazebo ``` 应该能启动Gazebo11。 - 测试ROS2与Gazebo的桥接:可以尝试运行一个示例,例如: ```bash ros2 launch ros_gz_sim gz_sim.launch.py gz_args:="-v 4 empty.sdf" ``` 但注意,这个命令可能需要安装ros-gz-sim包(我们之前安装的是ros-humble-ros-gz,它可能包含了这个包)。如果出现错误,可能需要进一步调整。 注意事项: - 安装Gazebo11可能会遇到依赖问题,因为Ubuntu22.04默认的库版本较高,而Gazebo11需要一些较旧的库。如果出现依赖问题,可以尝试使用`aptitude`来安装,它会提供解决方案,但可能会需要降级一些包。 - 如果Gazebo11无法安装,可以考虑使用Gazebo Fortress(官方推荐),但用户要求是Gazebo11,所以这里按照用户要求。 引用[3]中提到,学姐通过QQ邮箱传文件包,然后删除build文件夹再colcon build成功。这提示我们在构建工作空间时,如果遇到问题,可以尝试删除build文件夹重新构建。 如果遇到问题,请参考引用中的避指南和常见问题急救包。 相关问题: 1. 如何验证ROS2和Gazebo11是否安装成功? 2. 安装Gazebo11时遇到依赖问题怎么办? 3. ROS2 Humble与Gazebo11的桥接包如何安装和使用?</think>### Ubuntu 22.04 安装 ROS2 Humble 并配置 Gazebo 11 指南 #### 1. 🛠️ 准备工作 ```bash # 1.1 更换国内源(加速下载) sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.aliyun.com@g" /etc/apt/sources.list sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.aliyun.com@g" /etc/apt/sources.list sudo apt update # 1.2 安装基础依赖 sudo apt install -y curl software-properties-common lsb-release gnupg ``` #### 2. 📦 安装 ROS2 Humble ```bash # 2.1 添加ROS2仓库 sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg 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 > /dev/null # 2.2 安装ROS2桌面版 sudo apt update sudo apt install -y ros-humble-desktop # 2.3 配置环境变量 echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc source ~/.bashrc ``` #### 3. 🔧 安装 Gazebo 11 ```bash # 3.1 添加Gazebo官方源 sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" > /etc/apt/sources.list.d/gazebo-stable.list' curl -sSL https://packages.osrfoundation.org/gazebo.key | sudo apt-key add - # 3.2 安装Gazebo11 sudo apt update sudo apt install -y gazebo11 libgazebo11-dev # 3.3 验证安装 gazebo --version # 应输出: gazebo11 ``` #### 4. 🔗 配置 ROS2-Gazebo 桥接 ```bash # 4.1 安装桥接包 sudo apt install -y ros-humble-ros-gz # 4.2 测试桥接功能 # 终端1: 启动Gazebo gz sim -v4 empty.sdf # 终端2: 查看ROS2话题 source /opt/ros/humble/setup.bash ros2 topic list # 应显示Gazebo话题 ``` #### 5. 🧪 验证完整安装 ```bash # 创建测试工作空间 mkdir -p ~/ros2_ws/src && cd ~/ros2_ws ros2 pkg create --build-type ament_cmake test_gz # 编译工作空间 colcon build # 启动示例(需新终端) source ~/ros2_ws/install/setup.bash ros2 launch ros_gz_sim gz_sim.launch.py gz_args:="-v 4 empty.sdf" ``` #### 💡 避指南 1. **依赖冲突问题** 若出现`libignition`冲突,执行: ```bash sudo apt --fix-broken install sudo apt install ros-humble-ros-gz --reinstall ``` 2. **Gazebo黑屏问题** 编辑配置文件: ```bash echo "export SVGA_VGPU10=0" >> ~/.bashrc source ~/.bashrc ``` 3. **工作空间编译失败** 参考引用[3]经验: > "删除build文件夹,在ros_ws下重新执行`colcon build`"[^3] #### 验证成功标志 - ROS2节点通信:`ros2 run demo_nodes_cpp talker` 和 `ros2 run demo_nodes_py listener` - Gazebo可视化:`gz sim` 正常启动3D界面 - 桥接功能:`ros2 topic list` 显示`/world/default/*`话题 > 提示:完整安装约需5GB磁盘空间,安装时间取决于网络速度(约20-60分钟) --- ###
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值