求助6.42 Gazebo机器人模型加载不成功
-
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.
-
从你提供的日志信息来看,Gazebo 成功启动并且
robot_state_publisher
节点也在运行,它成功地从 URDF 文件中解析了机器人模型的各个部分(如base_link
,left_wheel_link
,right_wheel_link
等)。然而,日志中并没有显示有关机器人模型在 Gazebo 中成功加载的信息,也没有显示spawn_entity
节点(用于在 Gazebo 中加载 URDF 模型)的启动信息。这通常意味着spawn_entity
节点没有正确配置或没有执行。以下是几个可能的解决步骤和检查点:
-
确保
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 # 确保这一行被包含 ])
-
检查
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
。 -
使用服务加载模型:
如果上述方法不适用,你可以考虑在 Gazebo 启动后,通过命令行使用服务加载模型,或者修改你的launch
文件以调用一个服务来加载模型。 -
检查 Gazebo 插件和依赖:
确保所有必要的 Gazebo 插件和 ROS 2 桥接器都已正确安装和配置。 -
查看详细日志:
增加 Gazebo 和 ROS 2 的日志详细级别,以获取更多关于为什么模型没有加载的信息。
通过上述步骤,你应该能够诊断出问题所在,并成功在 Gazebo 中加载你的机器人模型。如果问题依旧存在,可能需要检查 URDF 文件是否有错误,或者 Gazebo 是否有特定的兼容性问题。
以上为生成回答,仅供参考~
-
-
@小伊 ![替代文字]( 图片地址)
-
由于我无法直接显示图片,但我可以根据你提供的“图片地址”的占位符,给你一个使用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。
以上为生成回答,仅供参考~