Behavior Tree using Python Codelet

I tried to create behavior tree example using selector. But I am getting error
PANIC engine/alice/backend/modules.cpp@280: Could not load component 'isaac::behavior_tree::MemorySelectorBehavior’”

Can somebody please help me with that. I have attached image of python file and json file

Also would like to request NVIDIA team to upload complete example of behavior tree not only json file

Hi @nasrin.saiyed,

When using components from different modules in your app, the modules must be 1) added as a dependency in the BUILD file, and 2) loaded into the application. For your case, make sure you have behavior_tree under modules in the bazel rule for the app. To load the module after defining the application, use app.load_module('behavior_tree') in main().

The cart delivery application serves as a working example for the behavior tree components. See the docs here.

Thank you for using Isaac!

A working example of the MemorySelectorBehavior inspired from the above question.

BUILD File

load("//bzl:py.bzl", "isaac_py_app")

isaac_py_app(
    name = "selector_example",
    srcs = [
        "__init__.py",
        "selector_example.py",
    ],

    data = [
        "selector_example.app.json",
        "//apps:py_init",
    ],

    modules = [
        "behavior_tree",
    ],

    deps = [
        "//packages/pyalice",
    ],
)

filegroup(
    name = "py_init",
    data = ["__init__.py"],
    visibility = ["//visibility:public"],
)

JSON File

{
    "name" : "selector_example",
    "modules" : [
        "behavior_tree"
    ],
    "graph" : {
        "nodes" : [
            {
                "name" : "selector_node",
                "components" : [
                    {
                        "name" : "NodeGroup",
                        "type" : "isaac::behavior_tree::NodeGroup"
                    },
                    {
                        "name" : "MemorySelectorBehavior",
                        "type" : "isaac::behavior_tree::MemorySelectorBehavior"
                    }
                ]
            },
            {
                "name" : "child_node_1",
                "components" : [
                    {
                        "name" : "node_1",
                        "type" : "isaac::alice::PyCodelet"
                    }
                ],
                "disable_automatic_start" : true
            },
            {
                "name" : "child_node_2",
                "components" : [
                    {
                        "name" : "node_2",
                        "type" : "isaac::alice::PyCodelet"
                    }
                ],
                "disable_automatic_start" : true
            }
        ]
    },
    "config" : {
        "selector_node" : {
            "NodeGroup" : {
                "node_names" : [
                    "child_node_1",
                    "child_node_2"
                ]
            }
        }
    }
}

PyCodelets

from isaac import Application, Codelet

class node_1(Codelet):
    def start(self):
        self.count = 0
        self.tick_periodically(1.0)

    def tick(self):
        self.count += 1
        if self.count > 3:
            print("Failure? count from Codelet: child_node_1: ", self.count)
            self.report_failure('Status set to Failure to trigger the child_node_2')
        else:
            print("Success! count from Codelet: child_node_1: ", self.count)

class node_2(Codelet):
    def start(self):
        # pass
        self.count = 0
        self.tick_periodically(1.0)

    def tick(self):
        self.count += 1
        print("Success! Codelet: child_node_2 count: ", self.count)

        if self.count > 2:
            self.report_failure('Status set to Failure to stop execution of child_node_2')

def main():
    app = Application(app_filename = "apps/selector_example.app.json")
    app.nodes["child_node_1"].add(node_1, "node_1")
    app.nodes["child_node_2"].add(node_2, "node_2")
    app.run()

if __name__ == "__main__":
    main()