小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
在使用Gazebo接入ros2_control的时候出现parameter无法解析的错误
-
以下是根据小鱼的课程编辑的代码:
- fishbot.ros2_contro.xacro
<?xml version="1.0"?> <robot xmlns:xacro="http://www.ros.org/wiki/xacro"> <xacro:macro name="fishbot_ros2_control"> <!-- This '<ros2_control>' will be seen by '<gazebo>' --> <ros2_control name="FishBotGazeboSystem" type="system"> <hardware> <plugin>gazebo_ros2_control/GazeboSystem</plugin> </hardware> <joint name="left_wheel_joint"> <!-- 利用速度接口控制轮子输出的转速 --> <command_interface name="velocity"> <param name="min">-1</param> <param name="max">1</param> </command_interface> <!-- 利用速度接口控制轮子输出的力 --> <command_interface name="effort"> <param name="min">-0.1</param> <param name="max">0.1</param> </command_interface> <!-- position 表示轮子转了多少度 --> <!-- velocity 轮子转速 --> <!-- effort 轮子输出的力 --> <state_interface name="position" /> <state_interface name="velocity" /> <state_interface name="effort" /> </joint> <joint name="right_wheel_joint"> <command_interface name="velocity"> <param name="min">-1</param> <param name="max">1</param> </command_interface> <command_interface name="effort"> <param name="min">-0.1</param> <param name="max">0.1</param> </command_interface> <state_interface name="position" /> <state_interface name="velocity" /> <state_interface name="effort" /> </joint> </ros2_control> <gazebo> <plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control"> <parameters>$(find fishbot_description)/config/fishbot_ros2_controller.yaml</parameters> </plugin> </gazebo> </xacro:macro> </robot>
- fishbot_ros2_controller.yaml
controller_manager: ros__parameters: update_rate: 100 # Hz use_sim_time: true
- fishbot.urdf.xacro
<?xml version="1.0"?> <robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="fish_robot"> <!-- base --> <!-- 'find fishbot_description' is to find pkgs' share directory --> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/base.urdf.xacro"/> <!-- sensors --> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/imu.urdf.xacro"/> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/camera.urdf.xacro"/> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/sensor/laser.urdf.xacro"/> <!-- wheels --> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/actuator/wheel.urdf.xacro"/> <!-- casters --> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/actuator/caster.urdf.xacro"/> <!-- plugins --> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/plugins/gazebo_control_plugin.xacro"/> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/plugins/gazebo_sensor_plugin.xacro"/> <xacro:include filename="$(find fishbot_description)/urdf/fishbot/fishbot.ros2_control.xacro"/> <xacro:base_xacro length="0.12" radius='0.10'/> <xacro:imu_xacro xyz="0.0 0.0 0.02"/> <xacro:camera_xacro xyz="0.10 0.0 0.075"/> <xacro:laser_xacro xyz="0.0 0.0 0.10"/> <xacro:wheel_xacro wheel_name="left_wheel" xyz="0 0.10 -0.06"/> <xacro:wheel_xacro wheel_name="right_wheel" xyz="0 -0.10 -0.06"/> <!-- 0.076 = 0.06(half of base link's height) + 0.032(wheels' radius) - 0.016(caster's radius) --> <xacro:caster_xacro caster_name="back_caster" xyz="-0.08 0.0 -0.076"/> <xacro:caster_xacro caster_name="front_caster" xyz="0.08 0.0 -0.076"/> <!-- using plugins --> <!-- 因为使用两轮差速控制硬件和gazebo ros2 control相冲突 --> <!-- 所以在使用ros2 control的时候需要把两轮差速控制硬件的插件注释掉 --> <xacro:gazebo_sensor_plugin /> <xacro:fishbot_ros2_control /> </robot>
- gazebo_sim.launch.py
import launch import launch.launch_description_sources import launch_ros # find first_robot.urdf file's directory from ament_index_python.packages import get_package_share_directory import os from launch.substitutions import Command, LaunchConfiguration import launch_ros.parameter_descriptions def generate_launch_description(): # the code below return the fishbot_description path under the 'share' directory urdf_package_path = get_package_share_directory('fishbot_description') # obtain the xacro file's path default_xacro_path = os.path.join(urdf_package_path, 'urdf', 'fishbot/fishbot.urdf.xacro') # default gazebo file's path default_gazebo_world_path = os.path.join(urdf_package_path, 'world', 'custom_room.world') # declare a param for the xacro directory action_declare_arg_mode_path = launch.actions.DeclareLaunchArgument( name='model',default_value=str(default_xacro_path),description='file path of loaded model' ) substituted_command_result = Command(['xacro ', LaunchConfiguration('model')]) robot_description_value = launch_ros.parameter_descriptions.ParameterValue(substituted_command_result, value_type=str) action_robot_state_publisher = launch_ros.actions.Node( package='robot_state_publisher', executable='robot_state_publisher', parameters=[{'robot_description':robot_description_value}] # 这里的parameters参数是用来向节点传递配置参数的,来获取机器人的 URDF 文件内容 ) # launch gazebo action_launch_gazebo = launch.actions.IncludeLaunchDescription( launch.launch_description_sources.PythonLaunchDescriptionSource( [get_package_share_directory('gazebo_ros'),'/launch','/gazebo.launch.py'] ), launch_arguments=[('world',default_gazebo_world_path),('verbose','true')] ) action_spawn_entity = launch_ros.actions.Node( package='gazebo_ros', executable='spawn_entity.py', arguments=['-topic','/robot_description','-entity','fishbot'] ) return launch.LaunchDescription([ action_declare_arg_mode_path, action_robot_state_publisher, action_launch_gazebo, action_spawn_entity ])
build并source了之后,运行命令:ros2 launch fishbot_description gazebo_sim.launch.py出现如下错误信息:
[INFO] [launch]: All log files can be found below /home/rayray/.ros/log/2024-11-03-15-32-19-623161-ruirui-6405 [INFO] [launch]: Default logging verbosity is set to INFO [INFO] [robot_state_publisher-1]: process started with pid [6417] [INFO] [gzserver-2]: process started with pid [6419] [INFO] [gzclient-3]: process started with pid [6421] [INFO] [spawn_entity.py-4]: process started with pid [6423] [robot_state_publisher-1] [INFO] [1730619140.442733183] [robot_state_publisher]: got segment back_caster_link [robot_state_publisher-1] [INFO] [1730619140.442932242] [robot_state_publisher]: got segment base_footprint [robot_state_publisher-1] [INFO] [1730619140.442947571] [robot_state_publisher]: got segment base_link [robot_state_publisher-1] [INFO] [1730619140.442955913] [robot_state_publisher]: got segment camera_link [robot_state_publisher-1] [INFO] [1730619140.442963330] [robot_state_publisher]: got segment camera_optical_link [robot_state_publisher-1] [INFO] [1730619140.442970904] [robot_state_publisher]: got segment front_caster_link [robot_state_publisher-1] [INFO] [1730619140.443010637] [robot_state_publisher]: got segment imu_link [robot_state_publisher-1] [INFO] [1730619140.443018315] [robot_state_publisher]: got segment laser_cylinder_link [robot_state_publisher-1] [INFO] [1730619140.443025876] [robot_state_publisher]: got segment laser_link [robot_state_publisher-1] [INFO] [1730619140.443038634] [robot_state_publisher]: got segment left_wheel_link [robot_state_publisher-1] [INFO] [1730619140.443046157] [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] [spawn_entity.py-4] [INFO] [1730619140.932122723] [spawn_entity]: Spawn Entity started [spawn_entity.py-4] [INFO] [1730619140.932722353] [spawn_entity]: Loading entity published on topic /robot_description [spawn_entity.py-4] /opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/qos.py:307: UserWarning: DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL is deprecated. Use DurabilityPolicy.TRANSIENT_LOCAL instead. [spawn_entity.py-4] warnings.warn( [spawn_entity.py-4] [INFO] [1730619140.935257380] [spawn_entity]: Waiting for entity xml on /robot_description [spawn_entity.py-4] [INFO] [1730619140.947043458] [spawn_entity]: Waiting for service /spawn_entity, timeout = 30 [spawn_entity.py-4] [INFO] [1730619140.947584792] [spawn_entity]: Waiting for service /spawn_entity [spawn_entity.py-4] [INFO] [1730619141.703951446] [spawn_entity]: Calling service /spawn_entity [gzserver-2] [Msg] Waiting for master. [gzserver-2] [Msg] Connected to gazebo master @ http://127.0.0.1:11345 [gzserver-2] [Msg] Publicized address: 192.168.1.7 [gzserver-2] [Msg] Loading world file [/home/rayray/URDFLearning/URDFLearn_ws/install/fishbot_description/share/fishbot_description/world/custom_room.world] [gzserver-2] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call [gzclient-3] [gzclient-3] libcurl: (5) Unsupported proxy syntax in 'http://127.0.0.1 :7890/' [gzserver-2] [INFO] [1730619142.516533608] [depth_camera]: Publishing camera info to [/camera_sensor/camera_info] [gzserver-2] [INFO] [1730619142.517603375] [depth_camera]: Publishing depth camera info to [/camera_sensor/depth/camera_info] [gzserver-2] [INFO] [1730619142.518202683] [depth_camera]: Publishing pointcloud to [/camera_sensor/points] [spawn_entity.py-4] [INFO] [1730619142.670410667] [spawn_entity]: Spawn status: SpawnEntity: Successfully spawned entity [fishbot] [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.7 [gzclient-3] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call [gzserver-2] [INFO] [1730619142.792004313] [gazebo_ros2_control]: Loading gazebo_ros2_control plugin [gzserver-2] [INFO] [1730619142.798491513] [gazebo_ros2_control]: Starting gazebo_ros2_control plugin in namespace: / [gzserver-2] [INFO] [1730619142.798567602] [gazebo_ros2_control]: Starting gazebo_ros2_control plugin in ros 2 node: gazebo_ros2_control [gzserver-2] [INFO] [1730619142.809044792] [gazebo_ros2_control]: connected to service!! robot_state_publisher [gzserver-2] [INFO] [1730619142.812920852] [gazebo_ros2_control]: Received urdf from param server, parsing... [gzserver-2] [INFO] [1730619142.812998897] [gazebo_ros2_control]: Loading parameter files /home/rayray/URDFLearning/URDFLearn_ws/install/fishbot_description/share/fishbot_description/config/fishbot_ros2_controller.yaml [gzserver-2] [rcutils|error_handling.c:65] an error string (message, file name, or formatted message) will be truncated [gzserver-2] [ERROR] [1730619142.813820165] [gazebo_ros2_control]: parser error Couldn't parse parameter override rule: '--param robot_description:=<?xml version="1.0" ?> [gzserver-2] <!-- =================================================================================== --> [gzserver-2] <!-- | This document was autogenerated by xacro from /home/rayray/URDFLearning/URDFLearn_ws/install/fishbot_description/share/fishbot_description/urdf/fishbot/fishbot.urdf.xacro | --> [gzserver-2] <!-- | EDITING THIS FILE BY HAND IS NOT RECOMMENDED | --> [gzserver-2] <!-- =================================================================================== --> [gzserver-2] <robot name="fish_robot"> [gzserver-2] <link name="base_footprint"/> [gzserver-2] <link name="base_link"> [gzserver-2] <!-- Components' appearance --> [gzserver-2] <visual> [gzserver-2] <!-- Offset and rotation along it's own geometric center --> [gzserver-2] <ori, at ./src/rcl/arguments.c:343 [gzserver-2] [INFO] [spawn_entity.py-4]: process has finished cleanly [pid 6423] [gzclient-3] [Wrn] [Event.cc:61] Warning: Deleting a connection right after creation. Make sure to save the ConnectionPtr from a Connect call [INFO] [gzclient-3]: process has finished cleanly [pid 6421]
应该就是parser error Couldn't parse parameter override rule: '--param robot_description:=<?xml version="1.0" ?>这个错误一直解决不了,排除了很久的代码也没有找到问题,恳请各位大佬前辈帮帮忙,有前辈遇到过类似的问题吗
-
您遇到的问题是由于Gazebo尝试解析通过
--param
传递的机器人描述(URDF/XACRO)字符串时出错。这通常发生在Gazebo的ROS 2插件尝试从参数服务器获取URDF信息时,但获取到的格式不正确或解析方式有误。从错误信息来看,Gazebo尝试解析的URDF字符串被错误地直接放在了命令行参数中,而通常这应该是通过参数服务器正确加载的XML格式文件。这里的错误提示显示XML内容被直接作为字符串解析,导致解析失败。
解决步骤
-
确保URDF/XACRO文件正确加载:
- 确保
fishbot.urdf.xacro
文件正确无误,并且所有包含的文件路径都是正确的。 - 使用
xacro
命令行工具检查XACRO文件是否可以被正确解析:
确保输出是一个有效的URDF XML。xacro --inorder fishbot_description/urdf/fishbot/fishbot.urdf.xacro
- 确保
-
检查参数服务器上的
robot_description
:- 在运行Gazebo之前,确保
robot_description
参数已经被正确设置到参数服务器上。您可以通过ROS 2命令行工具查看:
这应该输出您的URDF XML内容。ros2 param get /robot_state_publisher robot_description
- 在运行Gazebo之前,确保
-
检查Gazebo的ROS 2插件配置:
- 在您的
fishbot.ros2_control.xacro
文件中,您配置了Gazebo的ROS 2控制插件来加载fishbot_ros2_controller.yaml
。确保这个YAML文件正确无误,并且路径正确。 - 确保Gazebo的ROS 2插件配置正确,并且它应该通过参数服务器获取
robot_description
,而不是直接从命令行参数获取。
- 在您的
-
修改启动文件:
- 您的
gazebo_sim.launch.py
文件看起来是正确设置了robot_description
参数。但是,确保在Gazebo尝试访问这个参数之前,robot_state_publisher
已经运行并发布了这个参数。 - 您可以尝试调整节点启动的顺序,确保
robot_state_publisher
在Gazebo之前完全启动并运行。
- 您的
-
调试和日志:
- 增加日志输出,特别是在设置
robot_description
参数和Gazebo尝试读取这个参数的地方。 - 检查Gazebo的日志文件,看是否有更详细的错误信息。
- 增加日志输出,特别是在设置
-
环境问题:
- 确保您的ROS 2和Gazebo环境配置正确,所有依赖都已正确安装。
通过上述步骤,您应该能够定位问题的根源,并找到解决方法。如果问题仍然存在,可能需要更详细地检查Gazebo的ROS 2插件的源代码,看看它是如何处理
robot_description
参数的。
以上为生成回答,仅供参考~
-
-
@yepraywong urdf格式错误吧,仔细检查
-
@小鱼 解决啦!把注释里的冒号全部删除就不报错了,应该是冒号影响了解析。
-
@小伊 运行ros2 param get /robot_state_publisher robot_description
提示Node not found -
@43996173 先运行节点
-
@yepraywong 注释里的冒号是指的哪里呢,我也遇到了相同的报错