6.2.2运行显示display_robot.launch.py报错[ERROR] [launch]: Caught exception in launch (see debug for traceback): 'ParameterValue' object has no attribute 'describe_sub_entities'
-
6.2.2运行显示display_robot.launch.py报错[ERROR] [launch]: Caught exception in launch (see debug for traceback): 'ParameterValue' object has no attribute 'describe_sub_entities'
debug log:
dw@dw:~/codes/chapt6/chapt6_ws/src/fishbot_description/launch$ ros2 launch fishbot_description display_robot.launch.py --debug
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.IncludeLaunchDescription'
[INFO] [launch]: All log files can be found below /home/dw/.ros/log/2025-05-06-11-43-05-130647-dw-11442
[INFO] [launch]: Default logging verbosity is set to DEBUG
[DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x7cd550b06560>'
[DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x7cd550b06560>' ✓ '<launch.event_handlers.on_include_launch_description.OnIncludeLaunchDescription object at 0x7cd550dcd6c0>'
[DEBUG] [launch]: An exception was raised in an async action/event
[DEBUG] [launch]: Traceback (most recent call last):
File "/opt/ros/humble/lib/python3.10/site-packages/launch/launch_service.py", line 336, in run_async
raise completed_tasks_exceptions[0]
File "/opt/ros/humble/lib/python3.10/site-packages/launch/launch_service.py", line 230, in _process_one_event
await self.__process_event(next_event)
File "/opt/ros/humble/lib/python3.10/site-packages/launch/launch_service.py", line 250, in __process_event
visit_all_entities_and_collect_futures(entity, self.__context))
File "/opt/ros/humble/lib/python3.10/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/humble/lib/python3.10/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/humble/lib/python3.10/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/humble/lib/python3.10/site-packages/launch/action.py", line 108, in visit
return self.execute(context)
File "/opt/ros/humble/lib/python3.10/site-packages/launch/actions/include_launch_description.py", line 164, in execute
launch_description.get_launch_arguments_with_include_launch_description_actions())
File "/opt/ros/humble/lib/python3.10/site-packages/launch/launch_description.py", line 161, in get_launch_arguments_with_include_launch_description_actions
process_entities(self.entities, _conditional_inclusion=conditional_inclusion)
File "/opt/ros/humble/lib/python3.10/site-packages/launch/launch_description.py", line 152, in process_entities
entity.describe_sub_entities(),
AttributeError: 'ParameterValue' object has no attribute 'describe_sub_entities'[ERROR] [launch]: Caught exception in launch (see debug for traceback): 'ParameterValue' object has no attribute 'describe_sub_entities'
[DEBUG] [launch.launch_context]: emitting event: 'launch.events.Shutdown'
[DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x7cd550dcd5a0>'
[DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x7cd550dcd5a0>' ✓ '<launch.event_handlers.on_shutdown.OnShutdown object at 0x7cd550b07a00>'从网上没搜到相关问题及解决方案,deepseek更改代码如下:
import launch
import launch_ros
from ament_index_python.packages import get_package_share_directory
import launch_ros.parameter_descriptionsdef generate_launch_description():
urdf_tutorial_path = get_package_share_directory('fishbot_description')
default_model_path = urdf_tutorial_path + '/urdf/first_robot.urdf'action_declare_arg_mode_path = launch.actions.DeclareLaunchArgument( name='model', default_value=default_model_path, # 不需要str()转换 description='URDF的绝对路径' ) robot_description = launch_ros.parameter_descriptions.ParameterValue( launch.substitutions.Command(['cat ', launch.substitutions.LaunchConfiguration('model')]), value_type=str ) robot_state_publisher_node = launch_ros.actions.Node( package='robot_state_publisher', executable='robot_state_publisher', parameters=[{'robot_description': robot_description}] ) joint_state_publisher_node = launch_ros.actions.Node( package='joint_state_publisher', executable='joint_state_publisher', name='joint_state_publisher' ) rviz_node = launch_ros.actions.Node( package='rviz2', executable='rviz2', name='rviz2' ) return launch.LaunchDescription([ action_declare_arg_mode_path, joint_state_publisher_node, robot_state_publisher_node, # 确保先启动robot_state_publisher rviz_node # 移除了robot_description的直接添加 ])
这段代码与书上的主要不同之处是把action_declare_arg_mode_path中default_value参数去掉str()