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

        在学习赵虚左老师的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文件的转义要求,后面的参数需要用单引号括起来

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

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值