鱼香ROS社区
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组
    • 注册
    • 登录
    紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
    提问前必看的发帖注意事项: 社区问答规则(小鱼个人)更新 | 高质量帖子发布指南

    6.2.2章节的launch文件我还是报错运行不了,附上我的代码看着和源代码一样

    已定时 已固定 已锁定 已移动
    ROS2机器人开发:从入门到实践
    launch文件启动报错 ros2 linux
    1
    2
    191
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 1
      1419965014
      最后由 编辑

      import launch
      import launch_ros
      from ament_index_python.packages import get_package_share_directory
      import os

      def generate_launch_description():
      # 获取默认的urdf文件路径
      urdf_package_path = get_package_share_directory('fishbot_description')
      default_urdf_path = os.path.join(urdf_package_path, 'urdf', 'first_robot.urdf')
      # 声明一个URDF目录的参数,方便修改
      action_declare_arg_mode_path = launch.actions.DeclareLaunchArgument(
      name = 'model',default_value=str(default_urdf_path),description='加载的模型文件路径'

      )
      # 通过文件路径,获取内容,并转换成参数值对象,以供robot_state_publisher节点使用
      substitutions_command_result = launch.substitutions.command(['cat ',launch.substitutions.LaunchConfiguration('model')])
      robot_description_value = launch_ros.parameter_descriptions.ParameterValue(substitutions_command_result,value_type=str)
      
      action_robot_state_publisher = launch_ros.actions.Node(
          package='robot_state_publisher',
          executable='robot_state_publisher',
          parameters=[{'robot_description': robot_description_value}]
      
      )
      action_joint_state_publisher = launch_ros.actions.Node(
          package='joint_state_publisher',
          executable='joint_state_publisher',
          
      )
      action_rviz_node = launch_ros.actions.Node(
          package='rviz2',
          executable='rviz2',
      
      )
      
      return launch.LaunchDescription([
          action_declare_arg_mode_path,
          action_robot_state_publisher,
          action_joint_state_publisher,
          action_rviz_node,
      
      ])
      

      以下是报错:[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.IncludeLaunchDescription'
      [INFO] [launch]: All log files can be found below /home/jin/.ros/log/2025-04-22-16-49-27-291232-jin-Virtual-Machine-11473
      [INFO] [launch]: Default logging verbosity is set to DEBUG
      [DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x74ce4db9f730>'
      [DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x74ce4db9f730>' ✓ '<launch.event_handlers.on_include_launch_description.OnIncludeLaunchDescription object at 0x74ce4c64fd60>'
      [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_description_sources/any_launch_file_utilities.py", line 54, in get_launch_description_from_any_launch_file
      return loader(launch_file_path)
      File "/opt/ros/humble/lib/python3.10/site-packages/launch/launch_description_sources/python_launch_file_utilities.py", line 68, in get_launch_description_from_python_launch_file
      return getattr(launch_file_module, 'generate_launch_description')()
      File "display_robot.launch.py", line 16, in generate_launch_description
      substitutions_command_result = launch.substitutions.command(['cat ',launch.substitutions.LaunchConfiguration('model')])
      TypeError: 'module' object is not callable

      The above exception was the direct cause of the following exception:

      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 148, in execute
      launch_description = self.__launch_description_source.get_launch_description(context)
      File "/opt/ros/humble/lib/python3.10/site-packages/launch/launch_description_source.py", line 84, in get_launch_description
      self._get_launch_description(self.__expanded_location)
      File "/opt/ros/humble/lib/python3.10/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/humble/lib/python3.10/site-packages/launch/launch_description_sources/any_launch_file_utilities.py", line 57, in get_launch_description_from_any_launch_file
      raise InvalidLaunchFileError(extension, likely_errors=exceptions)
      launch.invalid_launch_file_error.InvalidLaunchFileError: Caught multiple exceptions when trying to load file of format [py]:

      • TypeError: 'module' object is not callable
      • InvalidFrontendLaunchFileError: The launch file may have a syntax error, or its format is unknown

      [ERROR] [launch]: Caught exception in launch (see debug for traceback): Caught multiple exceptions when trying to load file of format [py]:

      • TypeError: 'module' object is not callable
      • InvalidFrontendLaunchFileError: The launch file may have a syntax error, or its format is unknown
        [DEBUG] [launch.launch_context]: emitting event: 'launch.events.Shutdown'
        [DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x74ce4db9c340>'
        [DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x74ce4db9c340>' ✓ '<launch.event_handlers.on_shutdown.OnShutdown object at 0x74ce4db94b50>'
      1 条回复 最后回复 回复 引用 0
      • 1
        1419965014
        最后由 编辑

        找到问题了,原来代码中的方法没有大写,错误的代码是这一行:substitutions_command_result = launch.substitutions.command(['cat ',launch.substitutions.LaunchConfiguration('model')])
        正确的需要将command大写首字母同时注意cat后面需要有一个空格: substitutions_command_result = launch.substitutions.Command(['cat ',launch.substitutions.LaunchConfiguration('model')])

        1 条回复 最后回复 回复 引用 0
        • 第一个帖子
          最后一个帖子
        皖ICP备16016415号-7
        Powered by NodeBB | 鱼香ROS