【C++三方库移植】移植BehaviorTree.CPP到OpenHarmony标准系统① 原创 精华

离北况归
发布于 2023-6-26 17:09
浏览
3收藏

目录

1. 为BehaviorTree.CPP编写BUILD.gn进行Rom集成

  • Rom集成笔者开发环境:
    • wsl2+ubuntu18.04
    • OpenHarmony 3.2 release 源码
    • 润和大禹200开发板

1.2 修改build/subsystem_config.json,新增子系统behaviortree定义

在源码/build/subsystem_config.json中增加子系统behaviortree

  "behaviortree": {
    "path": "third_party/behaviortree",
    "name": "behaviortree"
  }
  • 1.
  • 2.
  • 3.
  • 4.

1.3 修改vendor/hihope/rk3568/config.json文件将behaviortree添加至rk3568开发板

    {
      "subsystem": "behaviortree",
      "components": [
        {
          "component": "behaviortree",
          "features": []
        }
      ]
    }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

1.4 在OpenHarmony标准系统源码下third_party下放置BehaviorTree.CPP源码

1.5 third_party/behaviortree目录下添加bundle.json文件

  • 特别说明:ohos.build不再使用,OpenHarmony源码中全部使用bundle.json

  • bundle.json文件:

{
  "name": "@ohos/behaviortree",
  "description": "",
  "version": "",
  "license": "",
  "publishAs": "",
  "segment": {
      "destPath": "third_party/behaviortree"
  },
  "dirs": {},
  "scripts": {},
  "readmePath": {
  },
  "component": {
      "name": "behaviortree",
      "subsystem": "behaviortree",
      "syscap": [],
      "features": [],
      "adapted_system_type": [],
      "rom": "",
      "ram": "",
      "deps": {
          "components": [],
          "third_party": []
      },
      "build": {
          "sub_component": [
            "//third_party/behaviortree:lexy_file",
            "//third_party/behaviortree:bt_sample_nodes",
            "//third_party/behaviortree:behaviortree_cpp",
            "//third_party/behaviortree:dummy_nodes_dyn",
            "//third_party/behaviortree:crossdoor_nodes_dyn",
            "//third_party/behaviortree:movebase_node_dyn",
            "//third_party/behaviortree:t01_build_your_first_tree",
            "//third_party/behaviortree:t02_basic_ports",
            "//third_party/behaviortree:t03_generic_ports",
            "//third_party/behaviortree:t05_crossdoor",
            "//third_party/behaviortree:t04_reactive_sequence",
            "//third_party/behaviortree:t06_subtree_port_remapping",
            "//third_party/behaviortree:t07_load_multiple_xml",
            "//third_party/behaviortree:t08_additional_node_args",
            "//third_party/behaviortree:t09_scripting",
            "//third_party/behaviortree:t10_observer",
            "//third_party/behaviortree:t11_replace_rules",
            "//third_party/behaviortree:ex01_wrap_legacy",
            "//third_party/behaviortree:ex02_runtime_ports",
            "//third_party/behaviortree:ex03_ncurses_manual_selector",
            "//third_party/behaviortree:ex04_waypoints"
          ],
          "inner_kits": [],
          "test": []
      }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.

1.6 BehaviorTree.CPP编译gn化,在third_party/behaviortree下添加BUILD.gn脚本文件

  • third_party/behaviortree/BUILD.gn配置的模块有

    • so
      • libbehaviortree_cpp.z.so
      • libmovebase_node_dyn.z.so
      • libcrossdoor_nodes_dyn.z.so
      • libdummy_nodes_dyn.z.so
    • .a
      • liblexy_file.a
      • libbt_sample_nodes.a
    • 可执行文件
      • t01_build_your_first_tree
      • t02_basic_ports
      • t03_generic_ports
      • t04_reactive_sequence
      • t05_crossdoor
      • t06_subtree_port_remapping
      • t07_load_multiple_xml
      • t08_additional_node_args
      • t09_scripting
      • t10_observer
      • t11_replace_rules
      • ex01_wrap_legacy
      • ex02_runtime_ports
      • ex03_ncurses_manual_selector
      • ex04_waypoints
  • 模块之间的依赖关系

    • libbehaviortree_cpp.z.so依赖lexy_file.a
    • libcrossdoor_nodes_dyn.z.so依赖libbehaviortree_cpp.z.so
    • libmovebase_node_dyn.z.so依赖libbehaviortree_cpp.z.so
    • 所有的可执行文件都依赖libbt_sample_nodes.a和libbehaviortree_cpp.z.so
  • third_party/behaviortree/BUILD.gn文件如下:

import("//build/ohos.gni")  
##############################################################################

# 公共配置

config("public_config"){
    ldflags = [
       #"-lstdc++",
       #用-lc++替代-lstdc++
       "-lc++",
       "-Wl",
       "-lm",
       "-lc",
       "-lpthread",
    ]

}
##############################################################################

# liblexy_file.a

config("lexy_file_config"){
    #cflags_cc是用来存储专门针对 C++ 语言编译器的选项,只会被 C++ 编译器使用。
    cflags_cc = [
       "-O3",
       "-DNDEBUG",  
       "-Wpedantic", 
       "-pedantic-errors", 
       "-Werror", 
       "-Wall", 
       "-Wextra", 
       "-Wconversion", 
       "-Wsign-conversion", 
       "-Wno-parentheses", 
       "-Wno-unused-local-typedefs", 
       "-Wno-array-bounds", 
       "-Wno-maybe-uninitialized", 
       "-Wno-restrict", 
       "-std=gnu++20",
    ]
}

ohos_static_library("lexy_file") {
    output_name = "lexy_file" # 可选,模块输出名

    sources = [
         "//third_party/behaviortree/3rdparty/lexy/src/input/file.cpp",
    ]

    defines = [
    ]

    configs = [ 
         ":lexy_file_config", 
         ":public_config",
    ] 

    include_dirs = [
         "3rdparty/lexy/include",
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"
}

##############################################################################

# libbt_sample_nodes.a

config("bt_sample_nodes_config"){
    #cflags_cc是用来存储专门针对 C++ 语言编译器的选项,只会被 C++ 编译器使用。
     cflags_cc = [
        "-O3", 
        "-DNDEBUG",    
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除编译报错添加的
        "-fexceptions",
        "-frtti",
        "-Wno-unused-function",
     ]
}

ohos_static_library("bt_sample_nodes") {
    sources = [
        "sample_nodes/crossdoor_nodes.cpp",
        "sample_nodes/dummy_nodes.cpp",
        "sample_nodes/movebase_node.cpp",
    ]

    defines = [
    ]

    configs = [ 
         ":bt_sample_nodes_config", 
         ":public_config",
    ] 

    include_dirs = [
         "include",
         "sample_nodes"
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"
}

##############################################################################

# libbehaviortree_cpp.so

config("behaviortreecpp_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",  
        "-fPIC",    
        "-Wpedantic",  
        "-Wall",  
        "-Wextra",  
        "-std=gnu++20",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
    ]

    include_dirs = [
         ".",
         "include",
         "3rdparty",
         "3rdparty/lexy/include",
    ]

}

ohos_shared_library("behaviortree_cpp") {
    output_name = "behaviortree_cpp" # 可选,模块输出名

    sources = [
        "src/action_node.cpp",
        "src/basic_types.cpp",
        "src/behavior_tree.cpp",
        "src/blackboard.cpp",
        "src/bt_factory.cpp",
        "src/decorator_node.cpp",
        "src/condition_node.cpp",
        "src/control_node.cpp",
        "src/shared_library.cpp",
        "src/tree_node.cpp",
        "src/script_parser.cpp",
        "src/json_export.cpp",
        "src/xml_parsing.cpp",
        "src/actions/test_node.cpp",
        "src/decorators/inverter_node.cpp",
        "src/decorators/repeat_node.cpp",
        "src/decorators/retry_node.cpp",
        "src/decorators/subtree_node.cpp",
        "src/decorators/delay_node.cpp",
        "src/controls/if_then_else_node.cpp",
        "src/controls/fallback_node.cpp",
        "src/controls/parallel_node.cpp",
        "src/controls/reactive_sequence.cpp",
        "src/controls/reactive_fallback.cpp",
        "src/controls/sequence_node.cpp",
        "src/controls/sequence_star_node.cpp",
        "src/controls/switch_node.cpp",
        "src/controls/while_do_else_node.cpp",
        "src/loggers/bt_cout_logger.cpp",
        "src/loggers/bt_file_logger.cpp",
        "src/loggers/bt_minitrace_logger.cpp",
        "src/loggers/bt_observer.cpp",
        "3rdparty/tinyxml2/tinyxml2.cpp",
        "3rdparty/minitrace/minitrace.cpp",
        "src/shared_library_UNIX.cpp",
    ]

    defines = [
        "LEXY_HAS_UNICODE_DATABASE=1",
        "behaviortree_cpp_EXPORTS",
    ]

    configs = [ 
         ":behaviortreecpp_config", 
         ":public_config",
    ] 

    deps = [
         "//third_party/behaviortree:lexy_file",
    ]
    
    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# libdummy_nodes_dyn.so

config("dummy_nodes_dyn_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",  
        "-fPIC",    
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
    ]

    include_dirs = [
         "include",
         "sample_nodes"
    ]

}

ohos_shared_library("dummy_nodes_dyn") {
    
    output_name = "dummy_nodes_dyn" # 可选,模块输出名

    sources = [
        "sample_nodes/dummy_nodes.cpp",
    ]

    defines = [
        "BT_PLUGIN_EXPORT",
        "dummy_nodes_dyn_EXPORTS",
    ]

    configs = [ 
         ":dummy_nodes_dyn_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# libcrossdoor_nodes_dyn.so

config("crossdoor_nodes_dyn_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",  
        "-fPIC",    
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
    ]

    include_dirs = [
         "include",
         "sample_nodes"
    ]

}

ohos_shared_library("crossdoor_nodes_dyn") {
    
    output_name = "crossdoor_nodes_dyn" # 可选,模块输出名

    sources = [
        "sample_nodes/crossdoor_nodes.cpp",
    ]

    defines = [
        "BT_PLUGIN_EXPORT",
        "crossdoor_nodes_dyn_EXPORTS",
    ]

    configs = [ 
         ":crossdoor_nodes_dyn_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
    ]
    
    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# libmovebase_node_dyn.so

config("movebase_node_dyn_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",  
        "-fPIC",    
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
    ]

    include_dirs = [
         "include",
         "sample_nodes"
    ]

}

ohos_shared_library("movebase_node_dyn") {
    
    output_name = "movebase_node_dyn" # 可选,模块输出名

    sources = [
        "sample_nodes/movebase_node.cpp",
    ]

    defines = [
        "BT_PLUGIN_EXPORT",
        "movebase_node_dyn_EXPORTS",
    ]

    configs = [ 
         ":movebase_node_dyn_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t01_build_your_first_tree

config("executable_public_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",   
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
    ]

    include_dirs = [
         "include",
         "sample_nodes"
    ]

}

ohos_executable("t01_build_your_first_tree") {
    
    output_name = "t01_build_your_first_tree" # 可选,模块输出名

    sources = [
        "examples/t01_build_your_first_tree.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]
    
    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t02_basic_ports

ohos_executable("t02_basic_ports") {
    
    output_name = "t02_basic_ports" # 可选,模块输出名

    sources = [
        "examples/t02_basic_ports.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t03_generic_ports

ohos_executable("t03_generic_ports") {
    
    output_name = "t03_generic_ports" # 可选,模块输出名

    sources = [
        "examples/t03_generic_ports.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t04_reactive_sequence

ohos_executable("t04_reactive_sequence") {
    
    output_name = "t04_reactive_sequence" # 可选,模块输出名

    sources = [
        "examples/t04_reactive_sequence.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t05_crossdoor

ohos_executable("t05_crossdoor") {
    
    output_name = "t05_crossdoor" # 可选,模块输出名

    sources = [
        "examples/t05_crossdoor.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t06_subtree_port_remapping

ohos_executable("t06_subtree_port_remapping") {
    
    output_name = "t06_subtree_port_remapping" # 可选,模块输出名

    sources = [
        "examples/t06_subtree_port_remapping.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t07_load_multiple_xml

ohos_executable("t07_load_multiple_xml") {
    
    output_name = "t07_load_multiple_xml" # 可选,模块输出名

    sources = [
        "examples/t07_load_multiple_xml.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t08_additional_node_args

ohos_executable("t08_additional_node_args") {
    
    output_name = "t08_additional_node_args" # 可选,模块输出名

    sources = [
        "examples/t08_additional_node_args.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t09_scripting

ohos_executable("t09_scripting") {
    
    output_name = "t09_scripting" # 可选,模块输出名

    sources = [
        "examples/t09_scripting.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t10_observer

config("t10_observer_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",   
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
        "-Wno-unused-variable",
    ]

    include_dirs = [
         "include",
         "sample_nodes"
    ]

}

ohos_executable("t10_observer") {
    
    output_name = "t10_observer" # 可选,模块输出名

    sources = [
        "examples/t10_observer.cpp",
    ]

    configs = [ 
         ":t10_observer_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t11_replace_rules

ohos_executable("t11_replace_rules") {
    
    output_name = "t11_replace_rules" # 可选,模块输出名

    sources = [
        "examples/t11_replace_rules.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# ex01_wrap_legacy

ohos_executable("ex01_wrap_legacy") {
    
    output_name = "ex01_wrap_legacy" # 可选,模块输出名

    sources = [
        "examples/ex01_wrap_legacy.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# ex02_runtime_ports

ohos_executable("ex02_runtime_ports") {
    
    output_name = "ex02_runtime_ports" # 可选,模块输出名

    sources = [
        "examples/ex02_runtime_ports.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# ex03_ncurses_manual_selector

ohos_executable("ex03_ncurses_manual_selector") {
    
    output_name = "ex03_ncurses_manual_selector" # 可选,模块输出名

    sources = [
        "examples/ex03_ncurses_manual_selector.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# ex04_waypoints

ohos_executable("ex04_waypoints") {
    
    output_name = "ex04_waypoints" # 可选,模块输出名

    sources = [
        "examples/ex04_waypoints.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.
  • 209.
  • 210.
  • 211.
  • 212.
  • 213.
  • 214.
  • 215.
  • 216.
  • 217.
  • 218.
  • 219.
  • 220.
  • 221.
  • 222.
  • 223.
  • 224.
  • 225.
  • 226.
  • 227.
  • 228.
  • 229.
  • 230.
  • 231.
  • 232.
  • 233.
  • 234.
  • 235.
  • 236.
  • 237.
  • 238.
  • 239.
  • 240.
  • 241.
  • 242.
  • 243.
  • 244.
  • 245.
  • 246.
  • 247.
  • 248.
  • 249.
  • 250.
  • 251.
  • 252.
  • 253.
  • 254.
  • 255.
  • 256.
  • 257.
  • 258.
  • 259.
  • 260.
  • 261.
  • 262.
  • 263.
  • 264.
  • 265.
  • 266.
  • 267.
  • 268.
  • 269.
  • 270.
  • 271.
  • 272.
  • 273.
  • 274.
  • 275.
  • 276.
  • 277.
  • 278.
  • 279.
  • 280.
  • 281.
  • 282.
  • 283.
  • 284.
  • 285.
  • 286.
  • 287.
  • 288.
  • 289.
  • 290.
  • 291.
  • 292.
  • 293.
  • 294.
  • 295.
  • 296.
  • 297.
  • 298.
  • 299.
  • 300.
  • 301.
  • 302.
  • 303.
  • 304.
  • 305.
  • 306.
  • 307.
  • 308.
  • 309.
  • 310.
  • 311.
  • 312.
  • 313.
  • 314.
  • 315.
  • 316.
  • 317.
  • 318.
  • 319.
  • 320.
  • 321.
  • 322.
  • 323.
  • 324.
  • 325.
  • 326.
  • 327.
  • 328.
  • 329.
  • 330.
  • 331.
  • 332.
  • 333.
  • 334.
  • 335.
  • 336.
  • 337.
  • 338.
  • 339.
  • 340.
  • 341.
  • 342.
  • 343.
  • 344.
  • 345.
  • 346.
  • 347.
  • 348.
  • 349.
  • 350.
  • 351.
  • 352.
  • 353.
  • 354.
  • 355.
  • 356.
  • 357.
  • 358.
  • 359.
  • 360.
  • 361.
  • 362.
  • 363.
  • 364.
  • 365.
  • 366.
  • 367.
  • 368.
  • 369.
  • 370.
  • 371.
  • 372.
  • 373.
  • 374.
  • 375.
  • 376.
  • 377.
  • 378.
  • 379.
  • 380.
  • 381.
  • 382.
  • 383.
  • 384.
  • 385.
  • 386.
  • 387.
  • 388.
  • 389.
  • 390.
  • 391.
  • 392.
  • 393.
  • 394.
  • 395.
  • 396.
  • 397.
  • 398.
  • 399.
  • 400.
  • 401.
  • 402.
  • 403.
  • 404.
  • 405.
  • 406.
  • 407.
  • 408.
  • 409.
  • 410.
  • 411.
  • 412.
  • 413.
  • 414.
  • 415.
  • 416.
  • 417.
  • 418.
  • 419.
  • 420.
  • 421.
  • 422.
  • 423.
  • 424.
  • 425.
  • 426.
  • 427.
  • 428.
  • 429.
  • 430.
  • 431.
  • 432.
  • 433.
  • 434.
  • 435.
  • 436.
  • 437.
  • 438.
  • 439.
  • 440.
  • 441.
  • 442.
  • 443.
  • 444.
  • 445.
  • 446.
  • 447.
  • 448.
  • 449.
  • 450.
  • 451.
  • 452.
  • 453.
  • 454.
  • 455.
  • 456.
  • 457.
  • 458.
  • 459.
  • 460.
  • 461.
  • 462.
  • 463.
  • 464.
  • 465.
  • 466.
  • 467.
  • 468.
  • 469.
  • 470.
  • 471.
  • 472.
  • 473.
  • 474.
  • 475.
  • 476.
  • 477.
  • 478.
  • 479.
  • 480.
  • 481.
  • 482.
  • 483.
  • 484.
  • 485.
  • 486.
  • 487.
  • 488.
  • 489.
  • 490.
  • 491.
  • 492.
  • 493.
  • 494.
  • 495.
  • 496.
  • 497.
  • 498.
  • 499.
  • 500.
  • 501.
  • 502.
  • 503.
  • 504.
  • 505.
  • 506.
  • 507.
  • 508.
  • 509.
  • 510.
  • 511.
  • 512.
  • 513.
  • 514.
  • 515.
  • 516.
  • 517.
  • 518.
  • 519.
  • 520.
  • 521.
  • 522.
  • 523.
  • 524.
  • 525.
  • 526.
  • 527.
  • 528.
  • 529.
  • 530.
  • 531.
  • 532.
  • 533.
  • 534.
  • 535.
  • 536.
  • 537.
  • 538.
  • 539.
  • 540.
  • 541.
  • 542.
  • 543.
  • 544.
  • 545.
  • 546.
  • 547.
  • 548.
  • 549.
  • 550.
  • 551.
  • 552.
  • 553.
  • 554.
  • 555.
  • 556.
  • 557.
  • 558.
  • 559.
  • 560.
  • 561.
  • 562.
  • 563.
  • 564.
  • 565.
  • 566.
  • 567.
  • 568.
  • 569.
  • 570.
  • 571.
  • 572.
  • 573.
  • 574.
  • 575.
  • 576.
  • 577.
  • 578.
  • 579.
  • 580.
  • 581.
  • 582.
  • 583.
  • 584.
  • 585.
  • 586.
  • 587.
  • 588.
  • 589.
  • 590.
  • 591.
  • 592.
  • 593.
  • 594.
  • 595.
  • 596.
  • 597.
  • 598.
  • 599.
  • 600.
  • 601.
  • 602.
  • 603.
  • 604.
  • 605.
  • 606.
  • 607.
  • 608.
  • 609.
  • 610.
  • 611.
  • 612.
  • 613.
  • 614.
  • 615.
  • 616.
  • 617.
  • 618.
  • 619.
  • 620.
  • 621.
  • 622.
  • 623.
  • 624.
  • 625.
  • 626.
  • 627.
  • 628.
  • 629.
  • 630.
  • 631.
  • 632.
  • 633.
  • 634.
  • 635.
  • 636.
  • 637.
  • 638.
  • 639.
  • 640.
  • 641.
  • 642.
  • 643.
  • 644.
  • 645.
  • 646.
  • 647.
  • 648.
  • 649.
  • 650.
  • 651.
  • 652.
  • 653.
  • 654.
  • 655.
  • 656.
  • 657.
  • 658.
  • 659.
  • 660.
  • 661.
  • 662.
  • 663.
  • 664.
  • 665.
  • 666.
  • 667.
  • 668.
  • 669.
  • 670.
  • 671.
  • 672.
  • 673.
  • 674.
  • 675.
  • 676.
  • 677.
  • 678.
  • 679.
  • 680.
  • 681.
  • 682.
  • 683.
  • 684.
  • 685.
  • 686.
  • 687.
  • 688.
  • 689.
  • 690.
  • 691.
  • 692.
  • 693.
  • 694.
  • 695.
  • 696.
  • 697.
  • 698.
  • 699.
  • 700.
  • 701.
  • 702.
  • 703.
  • 704.
  • 705.
  • 706.
  • 707.
  • 708.
  • 709.
  • 710.
  • 711.
  • 712.
  • 713.
  • 714.
  • 715.
  • 716.
  • 717.
  • 718.
  • 719.
  • 720.
  • 721.
  • 722.
  • 723.
  • 724.
  • 725.
  • 726.
  • 727.
  • 728.
  • 729.
  • 730.
  • 731.
  • 732.
  • 733.
  • 734.
  • 735.
  • 736.
  • 737.
  • 738.
  • 739.
  • 740.
  • 741.
  • 742.
  • 743.
  • 744.
  • 745.
  • 746.
  • 747.
  • 748.
  • 749.
  • 750.
  • 751.
  • 752.
  • 753.
  • 754.
  • 755.
  • 756.
  • 757.
  • 758.
  • 759.
  • 760.
  • 761.
  • 762.
  • 763.
  • 764.
  • 765.
  • 766.
  • 767.
  • 768.
  • 769.
  • 770.
  • 771.
  • 772.
  • 773.
  • 774.
  • 775.
  • 776.
  • 777.
  • 778.
  • 779.
  • 780.
  • 781.
  • 782.
  • 783.
  • 784.
  • 785.
  • 786.
  • 787.
  • 788.
  • 789.
  • 790.
  • 791.
  • 792.
  • 793.
  • 794.
  • 795.
  • 796.
  • 797.
  • 798.
  • 799.
  • 800.
  • 801.
  • 802.
  • 803.
  • 804.
  • 805.
  • 806.
  • 807.
  • 808.
  • 809.
  • 810.
  • 811.
  • 812.
  • 813.
  • 814.
  • 815.
  • 816.
  • 817.
  • 818.
  • 819.
  • 820.
  • 821.
  • 822.
  • 823.
  • 824.
  • 825.
  • 826.
  • 827.
  • 828.
  • 829.
  • 830.
  • 831.
  • 832.
  • 833.
  • 834.
  • 835.
  • 836.
  • 837.
  • 838.
  • 839.
  • 840.
  • 841.
  • 842.
  • 843.
  • 844.
  • 845.
  • 846.
  • 847.
  • 848.
  • 849.
  • 850.
  • 851.
  • 852.
  • 853.
  • 854.
  • 855.
  • 856.
  • 857.
  • 858.
  • 859.
  • 860.
  • 861.
  • 862.
  • 863.
  • 864.
  • 865.
  • 866.
  • 867.
  • 868.
  • 869.
  • 870.
  • 871.
  • 872.
  • 873.
  • 874.
  • 875.
  • 876.
  • 877.
  • 878.
  • 879.
  • 880.
  • 881.
  • 882.
  • 883.
  • 884.
  • 885.
  • 886.
  • 887.
  • 888.
  • 889.
  • 890.
  • 891.
  • 892.
  • 893.
  • 894.
  • 895.
  • 896.
  • 897.
  • 898.
  • 899.
  • 900.
  • 901.
  • 902.
  • 903.
  • 904.
  • 905.
  • 906.
  • 907.
  • 908.
  • 909.
  • 910.
  • 911.
  • 912.
  • 913.
  • 914.
  • 915.
  • 916.
  • 917.
  • 918.
  • 919.
  • 920.
  • 921.
  • 922.
  • 923.
  • 924.
  • 925.
  • 926.
  • 927.
  • 928.
  • 929.
  • 930.
  • 931.
  • 932.
  • 933.
  • 934.
  • 935.
  • 936.
  • 937.
  • 938.
  • 939.
  • 940.
  • 941.
  • 942.
  • 943.
  • 944.
  • 945.
  • 946.
  • 947.
  • 948.
  • 949.
  • 950.
  • 951.
  • 952.
  • 953.
  • 954.
  • 955.
  • 956.
  • 957.
  • 958.
  • 959.
  • 960.
  • 961.
  • 962.
  • 963.
  • 964.
  • 965.
  • 966.
  • 967.
  • 968.
  • 969.
  • 970.
  • 971.
  • 972.
  • 973.
  • 974.
  • 975.
  • 976.
  • 977.
  • 978.
  • 979.
  • 980.
  • 981.
  • 982.
  • 983.
  • 984.
  • 985.

1.7 对源码进行增量编译,推送编译生成BehaviorTree.CPP的so以及可执行文件到开发板上,验证编译结果

1.7.1 对源码进行增量编译

  • 推荐使用如下命令对对源码进行增量编译,编译生成BehaviorTree.CPP的so以及可执行文件
./build.sh --product-name rk3568 --ccache --build-target=behaviortree --disable-post-build --disable-package-image --gn-args enable_notice_collection=false --gn-args load_test_config=false
  • 1.
  • 默认编译的是32位,添加–target-cpu arm64参数编译64位
--product-name rk3568 :表示编译的产品是rk3568 (润和大禹200)
--build-target=behaviortree :编译子系统behaviortree

以下这些都是加快编译速度的选项
--ccache --build-target=behaviortree --disable-post-build --disable-package-image --gn-args enable_notice_collection=false --gn-args load_test_config=false 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

1.7.2 推送编译生成BehaviorTree.CPP的so以及可执行文件到开发板上,验证编译结果

  • so和可执行文件在out\rk3568\behaviortree目录下
    【C++三方库移植】移植BehaviorTree.CPP到OpenHarmony标准系统①-鸿蒙开发者社区

  • liblexy_file.a、libbt_sample_nodes.a等静态库文件在out\rk3568\obj\third_party\behaviortree目录下
    【C++三方库移植】移植BehaviorTree.CPP到OpenHarmony标准系统①-鸿蒙开发者社区

  • 1、通过与ohos版本匹配的hdc_std工具,将编译生成的库以及测试用的可执行文件推送到开发板system/lib (lib64)

    • 推送到开发板system/lib (lib64),是因为运行需要链接该目录下的libc++.so
    • 注意,不再是用hdc_std,改成了hdc
hdc shell               
mount -o remount,rw /	    ## 重新加载系统为可读写
chmod 777 t02_basic_ports
./t02_basic_ports
  • 1.
  • 2.
  • 3.
  • 4.

【C++三方库移植】移植BehaviorTree.CPP到OpenHarmony标准系统①-鸿蒙开发者社区

1.8 对源码进行增量编译全量编译,烧录固件验证编译结果。

  • 如果有将编译生成BehaviorTree.CPP的so以及可执行文件打包到固件,随固件烧录到开发板的需求。推荐进行全量编译,执行 ./build.sh --product-name rk3568 --ccache ,然后编译烧录固件到开发板上即可。

  • 编译烧录好固件到开发板后,so文件会在开发板system/lib(64位系统的话在system/lib64),可执行文件会在system/bin

  • hdc shell进入开发板后,在任意目录层级下执行可执行文件都可以
    【C++三方库移植】移植BehaviorTree.CPP到OpenHarmony标准系统①-鸿蒙开发者社区

  • 将编译生成BehaviorTree.CPP的so以及可执行文件打包到固件,在上文third_party/behaviortree/BUILD.gn中已经添加相关代码

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2023-7-17 18:49:31修改
5
收藏 3
回复
举报
5
7
3
7条回复
按时间正序
/
按时间倒序
红叶亦知秋
红叶亦知秋

前排关注大佬项目!

1
回复
2023-6-26 17:33:43
唐佐林
唐佐林

不错,多了一个可用的组件!

建议后续考虑一下:

  • 怎么以接口方式提供到app应用层
  • 在app中是否还需要其它关于机器人的组件


2
回复
2023-6-26 18:54:15
离北况归
离北况归 回复了 唐佐林
不错,多了一个可用的组件!建议后续考虑一下:怎么以接口方式提供到app应用层在app中是否还需要其它关于机器人的组件

唐老师,后面继续通过napi框架导出接口到应用层。第二个问题没考虑过,网友之前有过移植这库的需求,我就移植了。

回复
2023-6-26 20:14:33
FlashinMiami
FlashinMiami

很详细的代码讲解

1
回复
2023-6-28 16:12:55
皮皮虾233
皮皮虾233

中间的代码读了好长时间,分享的很完整

1
回复
2023-6-29 11:27:45
只看看不说话
只看看不说话

见证大佬不断突破

1
回复
2023-6-29 18:35:00
喝一大口可乐
喝一大口可乐

我愿称作者为移植先锋

1
回复
2023-7-3 10:18:52


回复
    相关推荐
    这个用户很懒,还没有个人简介
    觉得TA不错?点个关注精彩不错过
    帖子
    视频
    声望
    粉丝
    最近发布
    社区精华内容