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

举报
zhangrelay 发表于 2021/07/15 02:14:05 2021/07/15
【摘要】 在学习完成05-新建:https://zhangrelay.blog.csdn.net/article/details/112756752之后, 继续将ROS2功能包和webots仿真利器深度融合,如何做呢?导航走一个?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?_? ?...

在学习完成05-新建:https://zhangrelay.blog.csdn.net/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. 
        
    1. set TURTLEBOT3_MODEL='burger' 
    2. 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:

启动:


  
  1. """Launch Webots TurtleBot3 Burger driver."""
  2. import os
  3. from launch.substitutions import LaunchConfiguration
  4. from launch.actions import DeclareLaunchArgument
  5. from launch.substitutions.path_join_substitution import PathJoinSubstitution
  6. from launch.actions import IncludeLaunchDescription
  7. from launch.launch_description_sources import PythonLaunchDescriptionSource
  8. from launch import LaunchDescription
  9. from ament_index_python.packages import get_package_share_directory
  10. def generate_launch_description():
  11. package_dir = get_package_share_directory('webots_ros2_turtlebot')
  12. world = LaunchConfiguration('world')
  13. webots = IncludeLaunchDescription(
  14. PythonLaunchDescriptionSource(
  15. os.path.join(get_package_share_directory('webots_ros2_core'), 'launch', 'robot_launch.py')
  16. ),
  17. launch_arguments=[
  18. ('package', 'webots_ros2_turtlebot'),
  19. ('executable', 'turtlebot_driver'),
  20. ('world', PathJoinSubstitution([package_dir, 'worlds', world])),
  21. ]
  22. )
  23. return LaunchDescription([
  24. DeclareLaunchArgument(
  25. 'world',
  26. default_value='turtlebot3_burger_example.wbt',
  27. description='Choose one of the world files from `/webots_ros2_turtlebot/world` directory'
  28. ),
  29. webots
  30. ])

驱动:


  
  1. """ROS2 TurtleBot3 Burger driver."""
  2. import rclpy
  3. from webots_ros2_core.webots_differential_drive_node import WebotsDifferentialDriveNode
  4. class TurtlebotDriver(WebotsDifferentialDriveNode):
  5. def __init__(self, args):
  6. super().__init__(
  7. 'turtlebot_driver',
  8. args,
  9. left_encoder='left wheel sensor',
  10. left_joint='left wheel motor',
  11. right_encoder='right wheel sensor',
  12. right_joint='right wheel motor',
  13. robot_base_frame='base_link',
  14. wheel_distance=0.160,
  15. wheel_radius=0.033
  16. )
  17. self.start_device_manager({
  18. 'robot': {'publish_base_footprint': True},
  19. 'LDS-01': {'topic_name': '/scan'},
  20. 'accelerometer+gyro': {'frame_id': 'imu_link', 'topic_name': '/imu'}
  21. })
  22. def main(args=None):
  23. rclpy.init(args=args)
  24. driver = TurtlebotDriver(args=args)
  25. rclpy.spin(driver)
  26. rclpy.shutdown()
  27. if __name__ == '__main__':
  28. main()

比epuck-webotsros2驱动简洁一些。


 

文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。

原文链接:zhangrelay.blog.csdn.net/article/details/112772586

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。