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

    4.2.1章节构建消息功能包错误string index out of range

    已定时 已固定 已锁定 已移动
    动手学ROS2
    facedetector 接口定义
    2
    4
    392
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 4
      开心
      最后由 小鱼 编辑

       sensor_msgs/Image image 
      ---
      int16 number          # 人脸个数
      float32 use_time      # 识别耗时
      int32[] top           # 人脸在图像中的位置
      int32[] right
      int32[] bottom
      int32[] left
      

      cmakelists.txt

      cmake_minimum_required(VERSION 3.8)
      project(chapt4_interfaces)
      
      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)
      find_package(rosidl_default_generators REQUIRED)
      find_package(sensor_msgs REQUIRED)
      
      rosidl_generate_interfaces(${PROJECT_NAME}
        "srv/FaceDetector.srv"
        DEPENDENCIES sensor_msgs
      )
      
      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()
      
      ament_package()
      

      构建错误

      CMake Error at /opt/ros/humble/share/rosidl_adapter/cmake/rosidl_adapt_interfaces.cmake:59 (message):
        execute_process(/usr/bin/python3 -m rosidl_adapter --package-name
        chapt4_interfaces --arguments-file
        /home/tingbo/chapt4/chapt4_ws/src/build/chapt4_interfaces/rosidl_adapter__arguments__chapt4_interfaces.json
        --output-dir
        /home/tingbo/chapt4/chapt4_ws/src/build/chapt4_interfaces/rosidl_adapter/chapt4_interfaces
        --output-file
        /home/tingbo/chapt4/chapt4_ws/src/build/chapt4_interfaces/rosidl_adapter/chapt4_interfaces.idls)
        returned error code 1:
      
        Error processing ' sensor_msgs/Image image' of
        'chapt4_interfaces/FaceDetector_Request': 'string index out of range'
      
        Traceback (most recent call last):
      
          File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
            return _run_code(code, main_globals, None,
          File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
            exec(code, run_globals)
          File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/__main__.py", line 19, in <module>
            sys.exit(main())
          File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/main.py", line 53, in main
            abs_idl_file = convert_to_idl(
          File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/__init__.py", line 24, in convert_to_idl
            return convert_srv_to_idl(
          File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/srv/__init__.py", line 28, in convert_srv_to_idl
            srv = parse_service_string(package_name, input_file.stem, content)
          File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/parser.py", line 859, in parse_service_string
            request_message = parse_message_string(
          File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/parser.py", line 520, in parse_message_string
            Type(type_string, context_package_name=pkg_name),
          File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_adapter/parser.py", line 241, in __init__
            self.is_array = type_string[-1] == ']'
      
        IndexError: string index out of range
      
      Call Stack (most recent call first):
        /opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:130 (rosidl_adapt_interfaces)
        CMakeLists.txt:13 (rosidl_generate_interfaces)
      
      小鱼小 2 条回复 最后回复 回复 引用 0
      • 小鱼小
        小鱼 技术大佬 @43996173
        最后由 小鱼 编辑

        @43996173 在 4.2.1章节构建消息功能包错误string index out of range 中说:

        se

        这个前面的空格是你复制问题,还是代码里就有

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

        1 条回复 最后回复 回复 引用 0
        • 小鱼小
          小鱼 技术大佬 @43996173
          最后由 编辑

          @43996173 在 4.2.1章节构建消息功能包错误string index out of range 中说:

          ' sensor_msgs/Image image'

          前面多了个空格,书籍是代码格式有部分出现缩进错误,我给你的不是终审稿子,还没修复

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

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

            @小鱼 好了谢谢

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