Skip to content

Tutorial 01 - unclear instructions #251

Closed
@samurairepo

Description

@samurairepo

Hello, I failed to reproduce the first tutorial, mainly because I think it is missing some steps, which might be obvious to more experienced developer.

Attempted tutorial:
https://www.behaviortree.dev/tutorial_01_first_tree/

Questions:
This class declaration, should be in "dummy_nodes.h" correct ?

// Example of custom SyncActionNode (synchronous action)
// without ports.
class ApproachObject : public BT::SyncActionNode
{
  public:
    ApproachObject(const std::string& name) :
        BT::SyncActionNode(name, {})
    {
    }

    // You must override the virtual function tick()
    BT::NodeStatus tick() override
    {
        std::cout << "ApproachObject: " << this->name() << std::endl;
        return BT::NodeStatus::SUCCESS;
    }
};

Main:
The header does not include all the classes that are in the next source code, but I understand it is my job to fill their declaration. I removed the undeclared ones instead.

#include "behaviortree_cpp_v3/bt_factory.h"

// file that contains the custom nodes definitions
#include "dummy_nodes.h"

int main()
{
    // We use the BehaviorTreeFactory to register our custom nodes
    BehaviorTreeFactory factory;

    // Note: the name used to register should be the same used in the XML.
    using namespace DummyNodes;

    // The recommended way to create a Node is through inheritance.
    factory.registerNodeType<ApproachObject>("ApproachObject");

    // TreeNodes are destroyed
    auto tree = factory.createTreeFromFile("./my_tree.xml");

    tree.tickRoot();

    return 0;
}
Please, notice that in the cpp file there is "using namespace DummyNodes;", but in the header from the same tutorial, there is no namespace DummyNodes. Should I add DummyNodes in the header

Now, from the Github page, I found this CMAKE file (it is not in the Tutorial 01).
What should be the correct CMAKE for this tutorial ?
How do I include XML file in CMAKE build ?

cmake_minimum_required(VERSION 3.5)

project(hello_BT)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(BehaviorTreeV3)

add_executable(${PROJECT_NAME} "hello_BT.cpp")
target_link_libraries(${PROJECT_NAME} BT::behaviortree_cpp_v3)

Lastly, I searched the Github folder with examples and another thing confuses me, which is, that the tutorial source codes are very different.
In Github main, for example, the tree is represented as string literal, but in the landing page, the tree is represented like extrernal XML file.
Also this line: "factory.registerFromPlugin("./libdummy_nodes_dyn.so");"
It is not in the landing page tutorial, but it is in github.. what is "libdummy_nodes_dyn.so" ? Where can I get this file ? What is its purpose ?

Please can you help me and future beginners. Please, can you provide sequential steps, with fully functional example ? I admit, it is probably due to my own lack of experience, but I am very lost, I have spent hours trying to make tutorial 01 work, with no success. Thank you, Tomas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions