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

    6.2.2使用launch组织文件节点,启动运行错误

    已定时 已固定 已锁定 已移动
    动手学ROS2
    launch文件启动报错 对象不可调用
    3
    10
    3.0k
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 4
      开心
      最后由 编辑

      出现问题:
      按display_robot.launch.py的代码清单录入,构建工作空间后运行错误,提示如下

      RROR] [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
      

      display_robot.launch.py代码清单如下:

      import launch
      import launch_ros
      from ament_index_python.packages import get_package_share_directory
      
      
      
      def generate_launch_description():
          urdf_tutorial_path = get_package_share_directory('fishbot_description')
          default_model_path = urdf_tutorial_path + '/urdf/first_robot.urdf'
          #print (str(default_model_path))
          action_declare_arg_mode_path = launch.actions.DeclareLaunchArgument(
              name='model', default_value=str(default_model_path),
              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_publish',
              executable='joint_state_publisher',
          )
          rviz_node = launch_ros.actions.Node(
              package='rviz2',
              executable='rviz2',
          )
          return launch.launch_description([
              action_declare_arg_mode_path,
              joint_state_publisher_node,
              robot_state_publisher_node,
              rviz_node
          ])
      

      cmakelists.txt代码清单如下:

      cmake_minimum_required(VERSION 3.8)
      project(fishbot_description)
      
      if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        add_compile_options(-Wall -Wextra -Wpedantic)
      endif()
      
      # find dependencies
      find_package(ament_cmake REQUIRED)
      # uncomment the following section in order to fill in
      # further dependencies manually.
      # find_package(<dependency> REQUIRED)
      
      if(BUILD_TESTING)
        find_package(ament_lint_auto REQUIRED)
        # the following line skips the linter which checks for copyrights
        # comment the line when a copyright and license is added to all source files
        set(ament_cmake_copyright_FOUND TRUE)
        # the following line skips cpplint (only works in a git repo)
        # comment the line when this package is in a git repo and when
        # a copyright and license is added to all source files
        set(ament_cmake_cpplint_FOUND TRUE)
        ament_lint_auto_find_test_dependencies()
      endif()
      
      
      install(DIRECTORY launch urdf 
      DESTINATION share/${PROJECT_NAME}
      )
      
      ament_package()
      
      4 小鱼小 2 条回复 最后回复 回复 引用 0
      • 4
        开心 @43996173
        最后由 编辑

        @43996173
        运行命令:

         ros2 launch fishbot_description display_robot.launch.py
        

        print的文件的目录

        /home/tingbo/chapt6/chapt6_ws/install/fishbot_description/share/fishbot_description/urdf/first_robot.urdf
        
        4 1 条回复 最后回复 回复 引用 0
        • 4
          开心 @43996173
          最后由 编辑

          @43996173
          运行后的完整日志:

          [INFO] [launch]: All log files can be found below /home/tingbo/.ros/log/2024-04-16-15-15-20-527656-DESKTOP-NHH5E05-22235
          [INFO] [launch]: Default logging verbosity is set to INFO
          [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
          
          小鱼小 1 条回复 最后回复 回复 引用 0
          • 小鱼小
            小鱼 技术大佬 @43996173
            最后由 编辑

            @43996173 这是一个语法错误。你可以运行

            ros2 launch fishbot_description display_robot.launch.py --debug
            

            查看详细的日志信息。

            新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

            4 1 条回复 最后回复 回复 引用 0
            • 4
              开心 @小鱼
              最后由 编辑

              @小鱼 在 6.2.2使用launch组织文件节点,启动运行错误 中说:

              ros2 launch fishbot_description display_robot.launch.py --debug
              运行此,还不行:

              tingbo@DESKTOP-NHH5E05:~/chapt6/chapt6_ws$ 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/tingbo/.ros/log/2024-04-16-20-04-15-269096-DESKTOP-NHH5E05-141776
              [INFO] [launch]: Default logging verbosity is set to DEBUG
              [DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x7f8a8a67d420>'
              [DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x7f8a8a67d420>' ✓ '<launch.event_handlers.on_include_launch_description.OnIncludeLaunchDescription object at 0x7f8a89a2ca00>'
              [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 "/home/tingbo/chapt6/chapt6_ws/install/fishbot_description/share/fishbot_description/launch/display_robot.launch.py", line 30, in generate_launch_description
                  return launch.launch_description([
              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
              
              小鱼小 1 条回复 最后回复 回复 引用 0
              • 小鱼小
                小鱼 技术大佬 @43996173
                最后由 编辑

                @43996173 试试这个:

                import launch
                import launch_ros
                from ament_index_python.packages import get_package_share_directory
                
                
                def generate_launch_description():
                    # 获取默认路径
                    urdf_tutorial_path = get_package_share_directory('fishbot_description')
                    default_model_path = urdf_tutorial_path + '/urdf/first_robot.urdf'
                    default_rviz_config_path = urdf_tutorial_path + '/config/rviz/display_model.rviz'
                    # 为 Launch 声明参数
                    action_declare_arg_mode_path = launch.actions.DeclareLaunchArgument(
                        name='model', default_value=str(default_model_path),
                        description='URDF 的绝对路径')
                    # 获取文件内容生成新的参数
                    robot_description = launch_ros.parameter_descriptions.ParameterValue(
                        launch.substitutions.Command(
                            ['xacro ', 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',
                    )
                    # RViz 节点
                    rviz_node = launch_ros.actions.Node(
                        package='rviz2',
                        executable='rviz2',
                        arguments=['-d', default_rviz_config_path]
                    )
                    return launch.LaunchDescription([
                        action_declare_arg_mode_path,
                        joint_state_publisher_node,
                        robot_state_publisher_node,
                        rviz_node
                    ])
                

                新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

                4 1 条回复 最后回复 回复 引用 0
                • 4
                  开心 @小鱼
                  最后由 编辑

                  @小鱼
                  还是不行:

                  tingbo@DESKTOP-NHH5E05:~/chapt6/chapt6_ws$ 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/tingbo/.ros/log/2024-04-16-20-38-13-594595-DESKTOP-NHH5E05-156593
                  [INFO] [launch]: Default logging verbosity is set to DEBUG
                  [DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x7fad2aec5420>'
                  [DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x7fad2aec5420>' ✓ '<launch.event_handlers.on_include_launch_description.OnIncludeLaunchDescription object at 0x7fad2a270a00>'
                  [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/ament_index_python/packages.py", line 58, in get_package_prefix
                      content, package_prefix = get_resource('packages', package_name)
                    File "/opt/ros/humble/lib/python3.10/site-packages/ament_index_python/resources.py", line 86, in get_resource
                      raise LookupError(
                  LookupError: Could not find the resource 'joint_state_publish' of type 'packages'
                  
                  During handling of the above exception, another exception occurred:
                  
                  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 45, in visit_all_entities_and_collect_futures
                      futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
                    [Previous line repeated 1 more time]
                    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_ros/actions/node.py", line 509, in execute
                      ret = super().execute(context)
                    File "/opt/ros/humble/lib/python3.10/site-packages/launch/actions/execute_local.py", line 619, in execute
                      self.prepare(context)
                    File "/opt/ros/humble/lib/python3.10/site-packages/launch/actions/execute_local.py", line 594, in prepare
                      self.__process_description.prepare(context, self)
                    File "/opt/ros/humble/lib/python3.10/site-packages/launch/descriptions/executable.py", line 175, in prepare
                      cmd = [perform_substitutions(context, x) for x in self.__cmd]
                    File "/opt/ros/humble/lib/python3.10/site-packages/launch/descriptions/executable.py", line 175, in <listcomp>
                      cmd = [perform_substitutions(context, x) for x in self.__cmd]
                    File "/opt/ros/humble/lib/python3.10/site-packages/launch/utilities/perform_substitutions_impl.py", line 26, in perform_substitutions
                      return ''.join([context.perform_substitution(sub) for sub in subs])
                    File "/opt/ros/humble/lib/python3.10/site-packages/launch/utilities/perform_substitutions_impl.py", line 26, in <listcomp>
                      return ''.join([context.perform_substitution(sub) for sub in subs])
                    File "/opt/ros/humble/lib/python3.10/site-packages/launch/launch_context.py", line 240, in perform_substitution
                      return substitution.perform(self)
                    File "/opt/ros/humble/lib/python3.10/site-packages/launch_ros/substitutions/executable_in_package.py", line 76, in perform
                      package_prefix = super().perform(context)
                    File "/opt/ros/humble/lib/python3.10/site-packages/launch_ros/substitutions/find_package.py", line 79, in perform
                      result = self.find(package)
                    File "/opt/ros/humble/lib/python3.10/site-packages/launch_ros/substitutions/find_package.py", line 96, in find
                      return get_package_prefix(package_name)
                    File "/opt/ros/humble/lib/python3.10/site-packages/ament_index_python/packages.py", line 60, in get_package_prefix
                      raise PackageNotFoundError(
                  ament_index_python.packages.PackageNotFoundError: "package 'joint_state_publish' not found, searching: ['/home/tingbo/chapt6/chapt6_ws/install/fishbot_description', '/opt/ros/humble']"
                  
                  [ERROR] [launch]: Caught exception in launch (see debug for traceback): "package 'joint_state_publish' not found, searching: ['/home/tingbo/chapt6/chapt6_ws/install/fishbot_description', '/opt/ros/humble']"
                  [DEBUG] [launch.launch_context]: emitting event: 'launch.events.Shutdown'
                  [DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x7fad2a270f70>'
                  [DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x7fad2a270f70>' ✓ '<launch.event_handlers.on_shutdown.OnShutdown object at 0x7fad2a272c50>'
                  
                  1 条回复 最后回复 回复 引用 0
                  • 小鱼小
                    小鱼 技术大佬 @43996173
                    最后由 编辑

                    @43996173 在 6.2.2使用launch组织文件节点,启动运行错误 中说:

                    package='joint_state_publish',

                    这里应该是 publisher

                    @43996173 在 6.2.2使用launch组织文件节点,启动运行错误 中说:

                    return launch.launch_description([

                    这里应该是 LaunchDescription

                    新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

                    4 2 2 条回复 最后回复 回复 引用 0
                    • 4
                      开心 @小鱼
                      最后由 编辑

                      @小鱼
                      好了,谢谢

                      1 条回复 最后回复 回复 引用 0
                      • 2
                        x @小鱼
                        最后由 编辑

                        @小鱼 /您好,我也遇到了同样的问题,我的launch文件是:
                        from launch import LaunchDescription
                        from launch.substitutions import EnvironmentVariable
                        import launch.actions
                        import launch_ros.actions

                        def generate_launch_description():
                        use_sim_time = launch.substitutions.LaunchConfiguration('use_sim_time', default='true')
                        return LaunchDescription([
                        launch_ros.actions.Node(
                        package='slam_gmapping', node_executable='slam_gmapping', output='screen', parameters=[{'use_sim_time':use_sim_time}]),
                        ])
                        请您帮我检查是否存在致命错误

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