Skip to content

Conversation

facontidavide
Copy link

@facontidavide facontidavide commented May 4, 2018

Hi,

this pretty large PR introduce the ability (optional) to create a Tree at run-time loading it from an XML.

For simplicity, I included in the 3rdparty directory a popular library to parse XMLs.

You can see an example of XML here.

Hopefully the code in the unit test is self explaining ;)

  1. User must register actions into the class BehaviorTreeFactory as shown here and here.

  2. After that, an instance of a node can be created using the method instantiateTreeNode.

  3. The XML parser use the factory to create the entire Tree. Ignore the part related to BehaviorTreeMetaModel for the time being...

  4. As discussed, Actions and Decorators can have parameters. Since this parameters for the time being are read from XML, they are a pair of [attribute/value], both strings. We call them NodeParameters.

  5. Since the core library can not know all the possible ways in which a parameter can be parsed, it just assumes that it is up to the user's code to parse the string. You can see an example in DecoratorRetryNode.

.... I just realized I didn't included in the unit test how to use these NodeParameters, whooops....

If you have any suggestion, doubt, request, let me know.

Copy link
Owner

@miccol miccol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I want to try the runtime subtree stuff

case NodeType::SUBTREE_NODE:
return "SubTree";
default:
return "Undefined";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

switch (type)
{
case NodeType::ACTION_NODE:
return "Action";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For actions and condition I would suggest to print the name instead

Copy link
Author

@facontidavide facontidavide May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look carefully. This print NodeType, not TreeNode.

NodeType is an enum.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK


namespace BT
{
void RecursiveVisitor(const TreeNode* node, const std::function<void(const TreeNode*)> visitor)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PascalCase?

}
}

void PrintTreeRecursively(const TreeNode* root_node)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PascalCase?

@facontidavide
Copy link
Author

Hi,

I realized that we may pass the ResetPolicy by Nodeparameter.

3fc7998

This means that I have to consider the extra case of TreeNodes that have both constructors, with and without parameters.

@facontidavide
Copy link
Author

Looks good. I want to try the runtime subtree stuff

The unit test contains also the example with SubTree.
From my point of view, there is still a lot of work that needs to be done to make SubTree really useful. This is only a first step, I guess we need more experience with it to understand the typical use cases and pitfalls.

@miccol
Copy link
Owner

miccol commented May 8, 2018

What is DecoratorSubtree?

@facontidavide
Copy link
Author

facontidavide commented May 8, 2018

Based on the fact that the difference between a ControlNode and the DecoratorNode differs only in the number of children (only one for the latter), the concept of SubTree is conceptually a Decorator (one child).

This node is purely a dummy, as you can see in the implementation.
It's only function, for the time being, is to be used as as element that the GUI will use to collapse/expand the subtree.

In the future, it may also implement the concept of scoped blackboard i.e. a blackboard that can be seen only by the subtree, but not the parent tree.

EDIT: if you prefer, it can be renamed simply SubTreeNode

@miccol
Copy link
Owner

miccol commented May 14, 2018

Do you see the three pending questions above?

@facontidavide
Copy link
Author

The ones I see are about

  • "PascalCase": corrected
  • "What is a DecoratorSubTree": answered
  • The one about the funtion printing NodeType as string: answered.

@miccol
Copy link
Owner

miccol commented May 14, 2018

What is the purpose of recursiveVisitor?

@facontidavide
Copy link
Author

facontidavide commented May 14, 2018

recursiveVisitor is just an utility to do a ordered for-loop on a node and all its children.

A "visitor" is just a user-defined function (or lambda) that does something on a node. For example, imagine that you want to make a snapshot of the state of a the nodes of a tree.

std::map<const TreeNode*, NodeStatus> status_by_node;
recursiveVisitor( root_node, [&status_by_node](const TreeNode* node)
{
    status_by_node[node] = node->status();
});

Or, once the blackboard functionality is added (future PR):

// For the time being, consider this pseudo-code
Blackboard blackboard;
recursiveVisitor( root_node, [&status_by_node](const TreeNode* node)
{
    node->setBlackboard( &blackboard ); // this method will exist in the future
});

@miccol
Copy link
Owner

miccol commented May 14, 2018

great! thanks. Sorry for the delay in this.

@miccol miccol merged commit 45b0c16 into miccol:devel May 14, 2018
@facontidavide
Copy link
Author

giphy

@facontidavide facontidavide deleted the devel_factory branch May 14, 2018 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants