You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ROS2 Humble教程运行报错:无法导入launch.substitutions的FileContent

问题原因

报错核心是FileContent类在ROS2 Humble的launch.substitutions模块中不存在——该类是ROS2 Iron及后续版本才引入的新特性,你使用的Humble版本不支持,直接照搬高版本教程代码会触发兼容性错误。

解决方法

修改你的launch.py文件,将FileContent替换为Humble兼容的实现逻辑:

  1. 定位原教程中的问题代码片段:
from launch.substitutions import FileContent
...
robot_description = ParameterValue(
    FileContent(Command(['xacro ', get_package_share_path('urdf_tutorial_cpp'), '/description/robot.urdf.xacro'])),
    value_type=str
)
  1. 替换为Humble支持的代码:
from launch.substitutions import Command
...
robot_description = ParameterValue(
    Command(['xacro ', str(get_package_share_path('urdf_tutorial_cpp')), '/description/robot.urdf.xacro']),
    value_type=str
)
  1. 重新编译并生效:
colcon build --packages-select urdf_tutorial_cpp
source install/setup.bash
  1. 再次执行launch命令:
ros2 launch urdf_tutorial_cpp launch.py
额外提示

ROS2不同版本的launch API存在差异,Humble作为长期支持版本,部分新特性并未包含。后续跟随教程时,务必确认教程对应的ROS2版本与你使用的版本一致,避免类似兼容性问题。

内容的提问来源于stack exchange,提问作者Searcher

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 08:12:06