-
Notifications
You must be signed in to change notification settings - Fork 46
Run-time factory #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run-time factory #21
Conversation
There was a problem hiding this 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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Condition?
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
src/behavior_tree.cpp
Outdated
|
||
namespace BT | ||
{ | ||
void RecursiveVisitor(const TreeNode* node, const std::function<void(const TreeNode*)> visitor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PascalCase?
src/behavior_tree.cpp
Outdated
} | ||
} | ||
|
||
void PrintTreeRecursively(const TreeNode* root_node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PascalCase?
e7d2e1a
to
3c6ab32
Compare
Hi, I realized that we may pass the ResetPolicy by Nodeparameter. This means that I have to consider the extra case of TreeNodes that have both constructors, with and without parameters. |
The unit test contains also the example with SubTree. |
What is DecoratorSubtree? |
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. 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 |
It was neither a BehaviorTree itself nor a MetaModel...
58f0599
to
1d5b179
Compare
Do you see the three pending questions above? |
The ones I see are about
|
What is the purpose of recursiveVisitor? |
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
}); |
great! thanks. Sorry for the delay in this. |
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 ;)
User must register actions into the class BehaviorTreeFactory as shown here and here.
After that, an instance of a node can be created using the method instantiateTreeNode.
The XML parser use the factory to create the entire Tree. Ignore the part related to BehaviorTreeMetaModel for the time being...
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.
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.