在学习赵虚左老师的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文件的转义要求,后面的参数需要用单引号括起来文章来源:https://www.toymoban.com/news/detail-621298.html
但为什么老师的没用也能正常运行呢?望大佬解答疑惑。文章来源地址https://www.toymoban.com/news/detail-621298.html
到了这里,关于launch文件加载urdf到rviz和gazebo中报错 Invalid <param> tag: Cannot load command parameter [robot_description]的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!