webots和ros2笔记06-王者(turtlebot3)

本文通过turtlebot3示例详细介绍ROS2与Webots的深度整合过程,包括环境配置、常见错误排查及导航功能实现。

在学习完成05-新建:https://zhangrelay.blog.youkuaiyun.com/article/details/112756752之后,

继续将ROS2功能包和webots仿真利器深度融合,如何做呢?导航走一个?_?

?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_?

?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? 

稳不稳?六不六?

在最初以epuck为例,介绍了一些基本知识点,本节将以turtlebot3为主!

  • 从epuck到turtlebot3!

turtlebot系列是ROS最强的教学机器人。

那熟悉的感觉又回来啦!!!

注意事项,环境一定要正确配置,官网介绍非常详细,linux和windows通用,这里以windows演示为主。

如果配置不正确会出现如下报错!

第一种功能包不全!

请补齐确少功能包再次编译!

参考如下:

第二种节点不正常工作!

一定不能有ERROR!!!WARNING不用担心,但也要知道原因!

如果出错,topic不全,无法后续仿真!

如果,正确配置,一切正常启动如下:

这时候topic列表如下:

可以发现有/scan,/odom,/cmd_vel等SLAM和导航必备的主题哦!

两步:

  1.  ros2 launch webots_ros2_turtlebot robot_launch.py
  2.  set TURTLEBOT3_MODEL='burger' 
     ros2 launch turtlebot3_navigation2 navigation2.launch.py use_sim_time:=true map:=C:\ros_ws\webots2\src\webots_ros2\webots_ros2_turtlebot\resource\turtlebot3_burger_example_map.yaml 或者 ros2 launch turtlebot3_navigation2 navigation2.launch.py use_sim_time:=true map:=C:\ros_ws\webots2\install\webots_ros2_turtlebot\share\webots_ros2_turtlebot\resource\turtlebot3_burger_example_map.yaml 

开启导航前,请先定位机器人,一起正常如下:

这时候在仿真环境中的机器人如下:

来尝试一下导航吧???

如果ok?

细节后续讲解。

终端一:

终端二:

终端三:

这里比较重要的是launch和driver:

启动:

"""Launch Webots TurtleBot3 Burger driver."""

import os
from launch.substitutions import LaunchConfiguration
from launch.actions import DeclareLaunchArgument
from launch.substitutions.path_join_substitution import PathJoinSubstitution
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch import LaunchDescription
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    package_dir = get_package_share_directory('webots_ros2_turtlebot')
    world = LaunchConfiguration('world')

    webots = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(get_package_share_directory('webots_ros2_core'), 'launch', 'robot_launch.py')
        ),
        launch_arguments=[
            ('package', 'webots_ros2_turtlebot'),
            ('executable', 'turtlebot_driver'),
            ('world', PathJoinSubstitution([package_dir, 'worlds', world])),
        ]
    )

    return LaunchDescription([
        DeclareLaunchArgument(
            'world',
            default_value='turtlebot3_burger_example.wbt',
            description='Choose one of the world files from `/webots_ros2_turtlebot/world` directory'
        ),
        webots
    ])

驱动:

"""ROS2 TurtleBot3 Burger driver."""

import rclpy
from webots_ros2_core.webots_differential_drive_node import WebotsDifferentialDriveNode


class TurtlebotDriver(WebotsDifferentialDriveNode):
    def __init__(self, args):
        super().__init__(
            'turtlebot_driver',
            args,
            left_encoder='left wheel sensor',
            left_joint='left wheel motor',
            right_encoder='right wheel sensor',
            right_joint='right wheel motor',
            robot_base_frame='base_link',
            wheel_distance=0.160,
            wheel_radius=0.033
        )
        self.start_device_manager({
            'robot': {'publish_base_footprint': True},
            'LDS-01': {'topic_name': '/scan'},
            'accelerometer+gyro': {'frame_id': 'imu_link', 'topic_name': '/imu'}
        })


def main(args=None):
    rclpy.init(args=args)
    driver = TurtlebotDriver(args=args)
    rclpy.spin(driver)
    rclpy.shutdown()


if __name__ == '__main__':
    main()

比epuck-webotsros2驱动简洁一些。


 

Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting &#39;ros-noetic-turtlebot3-gazebo-dbgsym&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-fake-dbgsym&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-autorace-core&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-gazebo&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-example&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-fake&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-autorace-msgs&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-slam-dbgsym&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-autorace-driving&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-description&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-autorace-detect&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-bringup-dbgsym&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-msgs&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-bringup&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-navigation&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-simulations&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-slam&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-autorace-camera&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-autorace-2020&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Note, selecting &#39;ros-noetic-turtlebot3-teleop&#39; for glob &#39;ros-noetic-turtlebot3*&#39; Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: libboost-mpi-python-dev : Depends: libboost-mpi-python1.71-dev but it is not going to be installed libc6-dev : Breaks: libassimp-dev (<= 5.2.4~ds0-1) but 5.0.1~ds0-1build1 is to be installed Breaks: libfltk1.3-dev (<= 1.3.8-4+b1) but 1.3.4-10build1 is to be installed Breaks: libnetcdf-dev (<= 1:4.9.0-3) but 1:4.7.3-1 is to be installed libgrilo-0.3-0 : Breaks: grilo-plugins-0.3-base (< 0.3.16-1.1~) but 0.3.11-1ubuntu1 is to be installed ros-noetic-dynamic-reconfigure : Depends: ros-noetic-rosservice but it is not going to be installed ros-noetic-tf : Depends: ros-noetic-roswtf but it is not going to be installed ros-noetic-turtlebot3-autorace-camera : Depends: python-enum34 but it is not installable Depends: python3-opencv but it is not going to be installed Depends: ros-noetic-cv-bridge but it is not going to be installed ros-noetic-turtlebot3-autorace-core : Depends: python-enum34 but it is not installable ros-noetic-turtlebot3-autorace-detect : Depends: python-enum34 but it is not installable Depends: python3-opencv but it is not going to be installed Depends: ros-noetic-cv-bridge but it is not going to be installed ros-noetic-turtlebot3-autorace-driving : Depends: python-enum34 but it is not installable ros-noetic-turtlebot3-navigation : Depends: ros-noetic-amcl but it is not going to be installed Depends: ros-noetic-move-base but it is not going to be installed E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
05-27
### ROS Noetic 中 TurtleBot3 的依赖问题解决方案 在 ROS Noetic 下安装 `ros-noetic-turtlebot3` 及其相关依赖时,可能会遇到未满足的依赖项(unmet dependencies)。以下是针对这些特定依赖项的解决方法: #### 1. 更新系统包管理器索引 确保系统的软件源是最新的。运行以下命令来更新 APT 缓存并升级现有包: ```bash sudo apt update && sudo apt upgrade -y ``` #### 2. 安装缺失的依赖项 对于提到的具体依赖项,逐一分析如下: - **libboost-mpi-python-dev**: 这是一个 Boost 库的相关开发文件,用于支持 MPI Python 集成。可以通过以下命令安装[^1]: ```bash sudo apt install libboost-mpi-python-dev ``` - **libc6-dev**: C 标准库的开发者版本,通常已经预装于大多数 Linux 发行版中。如果缺少该组件,则可以执行以下操作[^2]: ```bash sudo apt install libc6-dev ``` - **libassimp-dev**: Open Asset Import Library (Assimp) 是一个开源的模型导入库。它提供了多种三维图形格式的支持。通过以下方式安装[^3]: ```bash sudo apt install libassimp-dev ``` - **grilo-plugins-0.3-base**: Grilo Plugins 提供多媒体内容检索功能的基础插件集合。此模块可能并非严格必要,但如果需要可尝试安装[^4]: ```bash sudo apt install grilo-plugins-0.3-base ``` - **python-enum34**: 此为 Python 枚举类型的兼容性扩展,在较新版本的 Python 中已内置枚举类。因此仅需确认当前环境是否仍需额外安装旧版支持工具[^5]: ```bash pip install enum34 --user ``` - **python3-opencv & ros-noetic-cv-bridge**: OpenCV 绑定以及 CV Bridge 转换工具链是计算机视觉应用的核心部分。分别采用标准仓库路径完成部署工作流程[^6][^7]: ```bash sudo apt install python3-opencv ros-noetic-cv-bridge ``` #### 3. 解决整体依赖冲突 当单独处理各单项失败后,考虑全局范围内的修复策略。利用 `apt-get` 或者更高级别的工具如 Synaptic Package Manager 来自动解析复杂关系网中的矛盾点。 例如强制重新计算最佳匹配方案的方法之一就是启用 `-f` 参数选项来进行自我修正模式下的重试过程[^8]: ```bash sudo apt-get -f install ``` 或者借助专门设计用来优化大型项目的辅助脚本程序——`rosdep` 工具来自动生成所需列表并向用户提供指导建议信息[^9]: ```bash sudo apt install python3-rosdep sudo rosdep init rosdep update cd ~/catkin_ws/ rosdep install --from-paths src --ignore-src -r -y ``` 以上步骤应当能够有效缓解乃至彻底消除因缺乏某些关键外部资源而导致的功能障碍现象。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangrelay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值