鱼香ROS社区
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组
    • 注册
    • 登录
    紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
    提问前必看的发帖注意事项: 社区问答规则(小鱼个人)更新 | 高质量帖子发布指南

    ros2 gazebo多机器人仿真问题

    已定时 已固定 已锁定 已移动 未解决
    综合问题
    ros2 gazebo 多机器人
    2
    6
    508
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 11321092421
      YoungRicky
      最后由 编辑

      请问ros2 gazebo仿真多机器人时该怎么进行设置?我启动rivz2后查看坐标系只有一个机器人的坐标系 而且odom坐标系在不停的跳动

      11321092421 1 条回复 最后回复 回复 引用 0
      • 11321092421
        YoungRicky @1132109242
        最后由 编辑

        @1132109242 版本为humble

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

          @1132109242 上下文?

          新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

          1 条回复 最后回复 回复 引用 0
          • 11321092421
            YoungRicky
            最后由 编辑

            这是我的launch文件,使用的urdf模型是轻松学ros2gazebo教程的fish_robot.urdf

            from launch import LaunchDescription
            from launch_ros.actions import Node
            #terminator command class
            from launch.actions import ExecuteProcess
            from launch.substitutions import FindExecutable
            
            #parameters' declare and obtain in a node
            from launch.actions import DeclareLaunchArgument
            from launch.substitutions import LaunchConfiguration
            
            #file, use launch to launch muitiple launch files
            from launch.actions import IncludeLaunchDescription
            from launch.launch_description_sources import PythonLaunchDescriptionSource
            
            #group
            from launch_ros.actions import PushRosNamespace
            from launch.actions import GroupAction
            
            #event
            from launch.event_handlers import OnProcessStart, OnProcessExit
            from launch.actions import ExecuteProcess, RegisterEventHandler,LogInfo
            
            #obtain the "share" path of the package
            from ament_index_python.packages import get_package_share_directory
            from launch_ros.substitutions import FindPackageShare
            import os
            
            #parameters load
            from launch_ros.parameter_descriptions import ParameterValue
            from launch.substitutions import Command
            
            def generate_launch_description():
               t1 = Node(package="",executable="",name="")
               return LaunchDescription([])
            
            def generate_launch_description():
            
               robot_name_in_model1 = 'robot1'
               robot_name_in_model2 = 'robot2'
               robot_name_in_model3 = 'robot3'
               package_name = 'gazebo_formation'
               urdf_name = 'fishbot_gazebo.urdf.xacro'
               world_name = 'demo.world'
               
               pkg_share = get_package_share_directory(package_name=package_name)
               urdf_model_path = os.path.join(pkg_share, f'urdf/{urdf_name}')
               icar_urdf_model_path = os.path.join(pkg_share, f'urdf/icar_description/{urdf_name}')
               gazebo_world_path = os.path.join(pkg_share,f'world/{world_name}')
            
               robot_description = ParameterValue(Command(["xacro" + " ",urdf_model_path]),value_type=str)
            
               robot_state_pub = Node(package="robot_state_publisher",
                                      executable="robot_state_publisher", 
                                      parameters=[{"robot_description":robot_description}])
              
               joint_state_pub = Node(package="joint_state_publisher",executable="joint_state_publisher")
            
               start_gazebo_cmd = ExecuteProcess(
                  cmd=['gazebo','--verbose','-s','libgazebo_ros_init.so', '-s', 'libgazebo_ros_factory.so',gazebo_world_path],
                  output = 'screen'
               )
               
               L = DeclareLaunchArgument(name="L",default_value="0.2")
               gui_service = Node(package="formation_qt_ros2",executable="gui_server")
            
               robot2_front =Node(package="tf2_ros",executable="static_transform_publisher",name="robot2_front",arguments=["--frame-id","robot2","--child-frame-id","robot2_front_frame","--x",LaunchConfiguration("L")])
               robot3_front =Node(package="tf2_ros",executable="static_transform_publisher",name="robot3_front",arguments=["--frame-id","robot3","--child-frame-id","robot3_front_frame","--x",LaunchConfiguration("L")])
            
               robot_spawn_1 = Node(package="gazebo_ros",executable="spawn_entity.py",arguments=['-entity', robot_name_in_model1,'-topic', 'robot_description','-robot_namespace','robot1'],output = 'screen')
               robot_spawn_2 = Node(package="gazebo_ros",executable="spawn_entity.py",arguments=['-entity', robot_name_in_model2,'-topic', 'robot_description','-robot_namespace','robot2','-x','1.0'],output = 'screen')
               robot_spawn_3 = Node(package="gazebo_ros",executable="spawn_entity.py",arguments=['-entity', robot_name_in_model3,'-topic', 'robot_description','-robot_namespace','robot3','-x','-1.0'],output = 'screen')
            
               g1 = GroupAction(actions=[PushRosNamespace('robot1'),robot_spawn_1])
               g2 = GroupAction(actions=[PushRosNamespace('robot2'),robot_spawn_2])
               g3 = GroupAction(actions=[PushRosNamespace('robot3'),robot_spawn_3])
            
               crossing_robot2_goal =Node(package="tf2_ros",executable="static_transform_publisher",name="crossing_robot2_goal",arguments=["--frame-id","robot1","--child-frame-id","crossing_robot2_goal_frame","--y","-1.2","--x","0.0"])
               crossing_robot3_goal =Node(package="tf2_ros",executable="static_transform_publisher",name="crossing_robot3_goal",arguments=["--frame-id","robot1","--child-frame-id","crossing_robot3_goal_frame","--y","1.2","--x","0.0"])
               crossing_robot2_goal_front =Node(package="tf2_ros",executable="static_transform_publisher",name="straight_robot2_goal_front",arguments=["--frame-id","crossing_robot2_goal_frame","--child-frame-id","crossing_robot2_goal_front_frame","--x",LaunchConfiguration("L")])
               crossing_robot3_goal_front =Node(package="tf2_ros",executable="static_transform_publisher",name="straight_robot3_goal_front",arguments=["--frame-id","crossing_robot3_goal_frame","--child-frame-id","crossing_robot3_goal_front_frame","--x",LaunchConfiguration("L")])
            
               straight_robot2_goal =Node(package="tf2_ros",executable="static_transform_publisher",name="straight_robot2_goal",arguments=["--frame-id","robot1","--child-frame-id","straight_robot2_goal_frame","--x","-1.2","--y","0.0"])
               straight_robot3_goal =Node(package="tf2_ros",executable="static_transform_publisher",name="straight_robot3_goal",arguments=["--frame-id","robot1","--child-frame-id","straight_robot3_goal_frame","--x","-2.4","--y","0.0"])
               straight_robot2_goal_front =Node(package="tf2_ros",executable="static_transform_publisher",name="straight_robot2_goal_front",arguments=["--frame-id","straight_robot2_goal_frame","--child-frame-id","straight_robot2_goal_front_frame","--x",LaunchConfiguration("L")])
               straight_robot3_goal_front =Node(package="tf2_ros",executable="static_transform_publisher",name="straight_robot3_goal_front",arguments=["--frame-id","straight_robot3_goal_frame","--child-frame-id","straight_robot3_goal_front_frame","--x",LaunchConfiguration("L")])
            
               tri_robot2_goal =Node(package="tf2_ros",executable="static_transform_publisher",name="tri_robot2_goal",arguments=["--frame-id","robot1","--child-frame-id","tri_robot2_goal_frame","--x","-1.0","--y","-1.0"])
               tri_robot3_goal =Node(package="tf2_ros",executable="static_transform_publisher",name="tri_robot3_goal",arguments=["--frame-id","robot1","--child-frame-id","tri_robot3_goal_frame","--x","-1.0","--y","1.0"])
               tri_robot2_goal_front =Node(package="tf2_ros",executable="static_transform_publisher",name="tri_robot2_goal_front",arguments=["--frame-id","tri_robot2_goal_frame","--child-frame-id","tri_robot2_goal_front_frame","--x",LaunchConfiguration("L")])
               tri_robot3_goal_front =Node(package="tf2_ros",executable="static_transform_publisher",name="tri_robot3_goal_front",arguments=["--frame-id","tri_robot3_goal_frame","--child-frame-id","tri_robot3_goal_front_frame","--x",LaunchConfiguration("L")])
            
               tf_broadcaster = Node(package="formation_qt_ros2",executable="tf_broadcaster")
               tf_listener = Node(package="formation_qt_ros2",executable="tf_listener")
               
               return LaunchDescription([L,gui_service,robot_state_pub,joint_state_pub,start_gazebo_cmd,
                                        g1,g2,g3,robot2_front,robot3_front,
                                        crossing_robot2_goal,crossing_robot3_goal,crossing_robot2_goal_front,crossing_robot3_goal_front,
                                        straight_robot2_goal,straight_robot3_goal,straight_robot2_goal_front,straight_robot3_goal_front,
                                        tri_robot2_goal,tri_robot3_goal,tri_robot2_goal_front,tri_robot3_goal_front,
                                        tf_broadcaster,tf_listener])
            

            这是我使用的启动命令
            ros2 launch gazebo_formation gazebo_formation_gui.launch.py \ use_sim_time:=true
            36906369-8702-4c55-851d-93535847f211-截图 2023-04-18 17-51-00.png

            在rviz里查看时只有一个机器人的坐标系,并且没有命名空间的前缀,并且在运行时还会报这样的错误

            [tf_listener-23] [ERROR] [1681811595.820197319] [TFListener_node_cpp]: error:"world" passed to lookupTransform argument target_frame does not exist.
            
            11321092421 1 条回复 最后回复 回复 引用 0
            • 11321092421
              YoungRicky @1132109242
              最后由 编辑

              @1132109242 tf错误解决了现在主要是多机器人的坐标系重名的问题未解决了,设置了命名空间不起作用

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

                @1132109242 应该就是namespace为生效造成的

                新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

                1 条回复 最后回复 回复 引用 0
                • 第一个帖子
                  最后一个帖子
                皖ICP备16016415号-7
                Powered by NodeBB | 鱼香ROS