launch文件加载urdf到rviz和gazebo中报错 Invalid <param> tag: Cannot load command parameter [robot_description]

2023-05-16

        在学习赵虚左老师的ros入门教程urdf一章时,使用 launch文件加载urdf到rviz和gazebo中的时候(命令如下)

 roslaunch learning_gazebo demo2_car.launch 

意外出现报错:

RLException: Invalid <param> tag: Cannot load command parameter [robot_description]: command [['/opt/ros/noetic/lib/xacro/xacro', '/home/glc/simulation_ws/src/learning_gazebo/urdf/car_urdf.xacro']] returned with code [2]. 

Param xml is <param name="robot_description" command="$(find xacro)/xacro $(find learning_gazebo)/urdf/car_urdf.xacro"/>
The traceback for the exception was written to the log file

这是我的launch文件,与老师的除了几个名称其他一样

<launch>
    <!-- 在参数服务器中加载urdf -->
    <param name="robot_description" command="$(find xacro)/xacro $(find learning_gazebo)/urdf/car_urdf.xacro" />
    <!-- 启动gazebo 其已经有内置launch文件启动gazebo-->
    <include file="$(find gazebo_ros)/launch/empty_world.launch" />
    <!-- 在gazebo中添加机器人模型 -->
    <node pkg="gazebo_ros" type="spawn_model" name="spawn_model" args="-urdf -model car -param robot_description" />
</launch>

它一直提示标签无效,我以为是拼写错误,但仔细检查了一遍后没找到问题,去网上查找也没找到解决办法。直到我看了别人的博客中的代码,发现ta的command属性第二个参数用“ ‘’ ”引了起来,然后我也引了起来,发现成功了。

修改后的launch文件

<launch>
    <!-- 在参数服务器中加载urdf -->
    <param name="robot_description" command="$(find xacro)/xacro '$(find learning_gazebo)/urdf/car_urdf.xacro'" />
    <!-- 启动gazebo 其已经有内置launch文件启动gazebo-->
    <include file="$(find gazebo_ros)/launch/empty_world.launch" />
    <!-- 在gazebo中添加机器人模型 -->
    <node pkg="gazebo_ros" type="spawn_model" name="spawn_model" args="-urdf -model car -param robot_description" />
</launch>

查了官方文档:

command="$(find pkg-name)/exe '$(find pkg-name)/arg.txt'"(optional)

The output of the command will be read and stored as a string. It is strongly recommended that you use the package-relative $(find)/file.txt syntax to specify file arguments. You should also quote file arguments using single quotes due to XML escaping requirements.

大概是说由于xml文件的转义要求,后面的参数需要用单引号括起来

但为什么老师的没用也能正常运行呢?望大佬解答疑惑。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

launch文件加载urdf到rviz和gazebo中报错 Invalid <param> tag: Cannot load command parameter [robot_description] 的相关文章

随机推荐