ROS2 launch文件解析错误:AttributeError: Attribute 'exec' not found
在运行ROS2 launch文件 '/home/ubuntu/lslidar_ws/install/pe_ars408_ros/share/pe_ars408_ros/launch/continental_ars408_socket_can.launch.xml' 时,遇到了错误:'InvalidLaunchFileError'。错误信息如下:
[INFO] [launch]: All log files can be found below /home/ubuntu/.ros/log/2023-04-14-09-07-34-866162-THNCHL-1-3513
[INFO] [launch]: Default logging verbosity is set to INFO
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<LaunchService._process_one_event() done, defined at /opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py:226> exception=InvalidLaunchFileError('xml')>
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py", line 53, in get_launch_description_from_any_launch_file
return loader(launch_file_path)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/frontend_launch_file_utilities.py", line 35, in get_launch_description_from_frontend_launch_file
return parser.parse_description(root_entity)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/frontend/parser.py", line 106, in parse_description
actions = [self.parse_action(child) for child in entity.children]
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/frontend/parser.py", line 106, in <listcomp>
actions = [self.parse_action(child) for child in entity.children]
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/frontend/parser.py", line 83, in parse_action
return instantiate_action(entity, self)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/frontend/expose.py", line 39, in instantiate_action
action_type, kwargs = action_parse_methods[entity.type_name](entity, parser)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/frontend/expose.py", line 105, in wrapper
ret = found_parse_method(entity, parser)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch_ros/actions/node.py", line 303, in parse
kwargs['executable'] = parser.parse_substitution(entity.get_attr('exec'))
File "/opt/ros/foxy/lib/python3.8/site-packages/launch_xml/entity.py", line 119, in get_attr
raise attr_error
AttributeError: Attribute exec of type <class 'str'> not found in Entity node
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 228, in _process_one_event
await self.__process_event(next_event)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 248, in __process_event
visit_all_entities_and_collect_futures(entity, self.__context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futures
sub_entities = entity.visit(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/action.py", line 108, in visit
return self.execute(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/include_launch_description.py", line 130, in execute
launch_description = self.__launch_description_source.get_launch_description(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_source.py", line 84, in get_launch_description
self._get_launch_description(self.__expanded_location)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_description_source.py", line 53, in _get_launch_description
return get_launch_description_from_any_launch_file(location)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py", line 56, in get_launch_description_from_any_launch_file
raise InvalidLaunchFileError(extension, likely_errors=exceptions)
launch.invalid_launch_file_error.InvalidLaunchFileError: Caught exception when trying to load file of format [xml]: Attribute exec of type <class 'str'> not found in Entity node
该错误表明在解析launch文件时,无法找到名为'exec'的属性。这个错误可能是由于以下原因导致的:
- 文件格式错误: launch文件可能存在语法错误,导致解析失败。
- 文件路径错误: launch文件路径可能错误,导致无法找到文件。
- 节点定义错误: launch文件中定义的节点缺少'exec'属性,导致解析失败。
为了解决这个问题,您可以尝试以下步骤:
- 检查launch文件语法: 确保launch文件语法正确,可以使用ROS提供的launch文件验证工具进行验证。
- 检查文件路径: 确认launch文件路径正确,并确保文件存在。
- 检查节点定义: 确认launch文件中定义的节点包含'exec'属性,并确保属性值正确。
如果以上步骤都无法解决问题,建议您参考ROS官方文档或社区论坛寻求帮助。
以下是一个示例的launch文件代码:
<launch>
<arg name="output/objects" default="objects" />
<arg name="interface" default="can0" />
<arg name="receiver_interval_sec" default="0.01" />
<arg name="launch_driver" default="true" />
<include file="$(find-pkg-share ros2_socketcan)/launch/socket_can_receiver.launch.py" if="$(var launch_driver)">
<arg name="interface" value="$(var interface)" />
<arg name="interval_sec" value="$(var receiver_interval_sec)" />
</include>
<include file="$(find-pkg-share pe_ars408_ros)/launch/continental_ars408.launch.xml">
<arg name="input/frame" value="from_can_bus" />
<arg name="output/objects" value="$(var output/objects)" />
</include>
<node name="rviz2" pkg="rviz2" type="rviz2" args="-d /lslidar_ws/install/pe_ars408.rviz" />
</launch>
该launch文件定义了一些参数,然后包含了两个其他launch文件,分别是ros2_socketcan和pe_ars408_ros包中的文件。最后,它启动了一个名为rviz2的节点,用于可视化数据。
需要注意的是,launch文件中的每个节点都需要定义'exec'属性,该属性指定了节点的执行文件路径。如果launch文件中缺少'exec'属性,就会导致解析错误。
建议您仔细检查launch文件,并确保每个节点都定义了'exec'属性。如果仍然无法解决问题,请尝试参考ROS官方文档或社区论坛寻求帮助。
原文地址: https://www.cveoy.top/t/topic/jDyQ 著作权归作者所有。请勿转载和采集!