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

    求助6.42 Gazebo机器人模型加载不成功

    已定时 已固定 已锁定 已移动
    学习资源
    ros gazebo ros2 rviz2
    2
    4
    502
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 2
      261962418
      最后由 编辑

      import launch
      import launch_ros
      from ament_index_python.packages import get_package_share_directory
      import launch_ros.parameter_descriptions
      import os
      #from launch.substitutions import LaunchConfiguration, Command  # 修正导入
      
      def generate_launch_description():
          #获取功能包的share路径文件
          urdf_tutorial_path = get_package_share_directory('fishbot_description')
      
          default_xacro_path = os.path.join(urdf_tutorial_path, 'urdf/fishbot/fishbot.urdf.xacro')
          default_world_path = os.path.join(urdf_tutorial_path, 'world/custom_room.world')
          
          #获取launch参数
          action_declare_arg_model_path = launch.actions.DeclareLaunchArgument(
              name='model', default_value=str(default_xacro_path),
              description='URDF 绝对路径')
          #获取文件内容生成新的参数
          robot_description = launch_ros.parameter_descriptions.ParameterValue(
              launch.substitutions.Command(['xacro ', launch.substitutions.LaunchConfiguration('model')]),
              value_type=str)
          #机器人状态发布节点
          robot_state_publisher_node = launch_ros.actions.Node(
              package='robot_state_publisher',
              executable='robot_state_publisher',
              parameters=[{'robot_description': robot_description}]
          )
       #通过IncludeLaunchDescription 包含另一个launch文件
          gazebo_launch_path = os.path.join(get_package_share_directory('gazebo_ros'), 'launch', 'gazebo.launch.py')
          launch_gazebo = launch.actions.IncludeLaunchDescription(
              launch.launch_description_sources.PythonLaunchDescriptionSource(gazebo_launch_path), 
          #传递参数
              launch_arguments=[('world', default_world_path), ('verbose', 'true')]
          )
      
          #gazebo节点加载机器人模型
          spawn_entity = launch_ros.actions.Node(
              package='gazebo_ros',
              executable='spawn_entity.py',
              arguments=['-entity','fishbot',
                         '-topic','robot_description'])
         
      
          return launch.LaunchDescription([
              action_declare_arg_model_path,
              robot_state_publisher_node,
              launch_gazebo
          ])
      
      
      

      下文

      wan@wan-ThinkPad-X1-Yoga-3rd:~/chapt6/chapt6_ws$ ros2 launch fishbot_description gazebo_sim.launch.py
      [INFO] [launch]: All log files can be found below /home/wan/.ros/log/2025-01-11-14-07-04-583880-wan-ThinkPad-X1-Yoga-3rd-14586
      [INFO] [launch]: Default logging verbosity is set to INFO
      [INFO] [robot_state_publisher-1]: process started with pid [14600]
      [INFO] [gzserver-2]: process started with pid [14602]
      [INFO] [gzclient-3]: process started with pid [14604]
      [robot_state_publisher-1] [INFO] [1736575625.302549794] [robot_state_publisher]: got segment back_caster_link
      [robot_state_publisher-1] [INFO] [1736575625.302688095] [robot_state_publisher]: got segment base_footprint
      [robot_state_publisher-1] [INFO] [1736575625.302710647] [robot_state_publisher]: got segment base_link
      [robot_state_publisher-1] [INFO] [1736575625.302723829] [robot_state_publisher]: got segment camera_link
      [robot_state_publisher-1] [INFO] [1736575625.302735153] [robot_state_publisher]: got segment front_caster_link
      [robot_state_publisher-1] [INFO] [1736575625.302746297] [robot_state_publisher]: got segment imu_link
      [robot_state_publisher-1] [INFO] [1736575625.302759291] [robot_state_publisher]: got segment laser_cylinder_link
      [robot_state_publisher-1] [INFO] [1736575625.302770978] [robot_state_publisher]: got segment laser_link
      [robot_state_publisher-1] [INFO] [1736575625.302781974] [robot_state_publisher]: got segment left_wheel_link
      [robot_state_publisher-1] [INFO] [1736575625.302792327] [robot_state_publisher]: got segment right_wheel_link
      [gzclient-3] Gazebo multi-robot simulator, version 11.10.2
      [gzclient-3] Copyright (C) 2012 Open Source Robotics Foundation.
      [gzclient-3] Released under the Apache 2 License.
      [gzclient-3] http://gazebosim.org
      [gzclient-3] 
      [gzserver-2] Gazebo multi-robot simulator, version 11.10.2
      [gzserver-2] Copyright (C) 2012 Open Source Robotics Foundation.
      [gzserver-2] Released under the Apache 2 License.
      [gzserver-2] http://gazebosim.org
      [gzserver-2] 
      [gzclient-3] [Msg] Waiting for master.
      [gzclient-3] [Msg] Connected to gazebo master @ http://127.0.0.1:11345
      [gzclient-3] [Msg] Publicized address: 192.168.1.174
      [gzclient-3] [Wrn] [GuiIface.cc:120] Could not find the Qt platform plugin "wayland" in ""
      [gzclient-3] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call
      [gzclient-3] [Wrn] [Publisher.cc:135] Queue limit reached for topic /gazebo/default/user_camera/pose, deleting message. This warning is printed only once.
      
      

      截图 2025-01-11 14-17-39.png

      1 条回复 最后回复 回复 引用 0
      • 小伊小
        机器人小伊
        最后由 编辑

        从你提供的日志信息来看,Gazebo 成功启动并且 robot_state_publisher 节点也在运行,它成功地从 URDF 文件中解析了机器人模型的各个部分(如 base_link, left_wheel_link, right_wheel_link 等)。然而,日志中并没有显示有关机器人模型在 Gazebo 中成功加载的信息,也没有显示 spawn_entity 节点(用于在 Gazebo 中加载 URDF 模型)的启动信息。这通常意味着 spawn_entity 节点没有正确配置或没有执行。

        以下是几个可能的解决步骤和检查点:

        1. 确保 spawn_entity 节点被包含在 launch 文件中:
          你的当前 generate_launch_description 函数中并没有包含 spawn_entity 节点。你需要将其添加到返回的 LaunchDescription 列表中。例如:

          return launch.LaunchDescription([
              action_declare_arg_model_path,
              robot_state_publisher_node,
              launch_gazebo,
              spawn_entity  # 确保这一行被包含
          ])
          
        2. 检查 spawn_entity 的参数:
          你的 spawn_entity 节点使用了 -topic 参数为 robot_description,这通常不是正确的做法。spawn_entity 通常需要一个包含模型描述的文件(URDF/SDF)或者一个已经发布的参数(如通过 robot_state_publisher 发布的 robot_description),但需要通过 -urdf 或 -sdf 参数指定一个文件,或通过 -param 指定一个参数名(如果模型描述是通过 ROS 参数服务器发布的)。然而,由于 robot_state_publisher 已经发布了 robot_description,你可能需要使用 gazebo_ros 的 spawn_entity.py 的另一种用法,比如通过服务来加载模型。

          一个更常见的用法是通过服务来加载机器人,例如使用 ros2 service call /spawn_urdf gazebo_ros.srv.SpawnEntity '{"name": "fishbot", "model_xml": "", "robot_namespace": "", "initial_pose": {"position": {"x": 0, "y": 0, "z": 1}, "orientation": {"x": 0, "y": 0, "z": 0, "w": 1}}, "reference_frame": "world"}' 命令,其中 model_xml 可以是 XML 字符串(通常通过文件读取并转换为字符串)。但这种方式需要确保 Gazebo 环境中已经有一个服务 /spawn_urdf。

        3. 使用服务加载模型:
          如果上述方法不适用,你可以考虑在 Gazebo 启动后,通过命令行使用服务加载模型,或者修改你的 launch 文件以调用一个服务来加载模型。

        4. 检查 Gazebo 插件和依赖:
          确保所有必要的 Gazebo 插件和 ROS 2 桥接器都已正确安装和配置。

        5. 查看详细日志:
          增加 Gazebo 和 ROS 2 的日志详细级别,以获取更多关于为什么模型没有加载的信息。

        通过上述步骤,你应该能够诊断出问题所在,并成功在 Gazebo 中加载你的机器人模型。如果问题依旧存在,可能需要检查 URDF 文件是否有错误,或者 Gazebo 是否有特定的兼容性问题。


        以上为生成回答,仅供参考~

        我是小伊,已接入ChatGpt,所有回复,仅供参考~

        2 1 条回复 最后回复 回复 引用 0
        • 2
          261962418 @小伊
          最后由 编辑

          @小伊 ![替代文字](截图 2025-01-11 14-34-25.png 图片地址)

          1 条回复 最后回复 回复 引用 0
          • 小伊小
            机器人小伊
            最后由 编辑

            由于我无法直接显示图片,但我可以根据你提供的“图片地址”的占位符,给你一个使用Markdown语法在支持Markdown的环境中(如GitHub、一些博客平台等)插入图片的示例。假设你的图片地址是 "https://example.com/image.jpg",你可以这样写:

            ![替代文字](https://example.com/image.jpg)
            
            • 替代文字:这是图片的替代文本(alt text),用于在图片无法加载时显示,或者对于使用屏幕阅读器的用户来说,这段文字可以帮助他们理解图片的内容。
            • https://example.com/image.jpg:这是图片的实际网络地址(URL)。

            如果你是在一个不支持Markdown的环境(如纯文本编辑器或某些社交媒体平台),你可能需要直接粘贴图片的URL,或者按照该平台的要求上传图片。

            请注意,为了保护隐私和版权,上面的URL "https://example.com/image.jpg" 是一个示例,你应该使用你自己的图片的实际URL。


            以上为生成回答,仅供参考~

            我是小伊,已接入ChatGpt,所有回复,仅供参考~

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