鱼香社区

    • 登录
    • 搜索
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组

    重要提示

    鱼香小铺正式开业,最低499可入手一台能建图会导航的移动机器人,淘宝搜店:鱼香ROS 或点击链接查看。
    提问前必看的发帖注意事项—— 提问的智慧
    社区使用指南—如何添加标签修改密码

    未解决 在rviz2中显示多个机器人

    综合问题
    ros2 多机器人
    3
    4
    42
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 1654939697
      1654939697 最后由 编辑

      平台:Ubuntu22.04,ros2:humble
      问题:在学习完小鱼的“动手学ros2”建模仿真篇后,我学会了如何运用launch将单个机器人添加Gazebo中和利用rqt添加多个机器人到gazebo。
      现在我想利用一个launch将多个机器人模型展示在gazebo中,并且在rviz2中显示多个机器人。目前,在gazebo中可以显示多个机器人,但是rviz2中,只能显示一个机器人模型,且模型来回跳动,如图:
      15e34ea1-d62a-42b4-88eb-1a9e5e1aab8f-fe7f53048045685e97000b38f9f03f1.png
      fa2c85af-236c-4cf8-9345-28de1cbe443d-35c61805ca141e1f60d2e1f6a415c1d.png
      launch文件如下:
      import os
      from launch import LaunchDescription
      from launch.actions import ExecuteProcess
      from launch_ros.actions import Node
      from launch_ros.substitutions import FindPackageShare

      def generate_launch_description():
      name1 = 'fishbot1'
      name2 = 'fishbot2'
      package_name = 'fishbot_description'
      urdf_name = "fishbot_gazebo.urdf"

      ld = LaunchDescription()
      pkg_share = FindPackageShare(package=package_name).find(package_name) 
      urdf_model_path = os.path.join(pkg_share, f'urdf/{urdf_name}')
      gazebo_world_path = os.path.join(pkg_share, 'world/fishbot.world')
      
      # Start Gazebo server
      start_gazebo_cmd =  ExecuteProcess(
          cmd=['gazebo', '--verbose','-s', 'libgazebo_ros_init.so', '-s', 'libgazebo_ros_factory.so',gazebo_world_path],
          output='screen')
      
      # Launch the robot1
      spawn_entity_cmd1 = Node(
          package='gazebo_ros', 
          executable='spawn_entity.py',
          # namespace='robot1',
          arguments=[
              '-entity', name1,  
              '-file', urdf_model_path,
              '-robot_namespace', name1,
              ], 
          output='screen'
      )
      
      # Start Robot1 State publisher
      start_robot_state_publisher_cmd1 = Node(
          package='robot_state_publisher',
          executable='robot_state_publisher',
          namespace=name1,
          arguments=[urdf_model_path]
      )
      
      # Launch the robot2
      spawn_entity_cmd2 = Node(
          package='gazebo_ros', 
          executable='spawn_entity.py',
          # namespace='robot2',
          arguments=[
              '-entity', name2,  
              '-file', urdf_model_path,
              '-robot_namespace', name2,
              '-x', '0.5' 
              ], 
          output='screen'
      )
      
      # Start Robot2 State publisher
      start_robot_state_publisher_cmd2 = Node(
          package='robot_state_publisher',
          executable='robot_state_publisher',
          namespace=name2,
          arguments=[urdf_model_path]
      )
      
      # Launch RViz
      start_rviz_cmd = Node(
          package='rviz2',
          executable='rviz2',
          name='rviz2',
          output='screen',
          # arguments=['-d', default_rviz_config_path]
          
          )
      
      
      ld.add_action(start_gazebo_cmd)
      ld.add_action(spawn_entity_cmd1)
      ld.add_action(spawn_entity_cmd2)
      ld.add_action(start_robot_state_publisher_cmd1)
      ld.add_action(start_robot_state_publisher_cmd2)
      ld.add_action(start_rviz_cmd)
      
      return ld
      
      小鱼 1 条回复 最后回复 回复 引用 0
      • 小鱼
        小鱼 技术大佬 @1654939697 最后由 编辑

        @1654939697 两个机器人没有使用明明空间可能

        2918095496 1 条回复 最后回复 回复 引用 0
        • 2918095496
          天问 @小鱼 最后由 编辑

          @小鱼 怎么样去添加命名空间,我看他这个好像有用啊,是不是用的不对。

          小鱼 1 条回复 最后回复 回复 引用 0
          • 小鱼
            小鱼 技术大佬 @2918095496 最后由 编辑

            @2918095496 ros2 topic list 看一下 和 TF 也看一下

            1 条回复 最后回复 回复 引用 0
            • First post
              Last post
            皖ICP备16016415号-7
            Powered by NodeBB | 鱼香ROS