Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb9f064

Browse files
committed
reverting to a better solution
1 parent c66fc23 commit eb9f064

File tree

4 files changed

+33
-44
lines changed

4 files changed

+33
-44
lines changed

include/behaviortree_cpp_v3/decorators/subtree_node.h

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,19 @@ class SubtreeNode : public DecoratorNode
2222
private:
2323
virtual BT::NodeStatus tick() override;
2424

25+
static PortsList providedPorts()
26+
{
27+
return { InputPort<bool>("__shared_blackboard", false,
28+
"If false (default) the subtree has its own blackboard and you"
29+
"need to do port remapping to connect it to the parent") };
30+
}
31+
2532
virtual NodeType type() const override final
2633
{
2734
return NodeType::SUBTREE;
2835
}
2936
};
3037

31-
/**
32-
* @brief Subtree that doesn't need any remapping.
33-
* Its blackboard is shared with the parent node
34-
*/
35-
class RemappedSubtreeNode : public DecoratorNode
36-
{
37-
public:
38-
RemappedSubtreeNode(const std::string& name);
39-
40-
virtual ~RemappedSubtreeNode() override = default;
41-
42-
private:
43-
virtual BT::NodeStatus tick() override;
44-
45-
virtual NodeType type() const override final
46-
{
47-
return NodeType::SUBTREE;
48-
}
49-
};
5038

5139

5240
/**
@@ -99,6 +87,12 @@ class SubtreePlusNode : public DecoratorNode
9987
private:
10088
virtual BT::NodeStatus tick() override;
10189

90+
static PortsList providedPorts()
91+
{
92+
return { InputPort<bool>("__autoremap", false,
93+
"If true, all the ports with the same name will be remapped") };
94+
}
95+
10296
virtual NodeType type() const override final
10397
{
10498
return NodeType::SUBTREE;

src/bt_factory.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ BehaviorTreeFactory::BehaviorTreeFactory()
4444

4545
registerNodeType<SubtreeNode>("SubTree");
4646
registerNodeType<SubtreePlusNode>("SubTreePlus");
47-
registerNodeType<RemappedSubtreeNode>("RemappedSubTree");
4847

4948
registerNodeType<BlackboardPreconditionNode<int>>("BlackboardCheckInt");
5049
registerNodeType<BlackboardPreconditionNode<double>>("BlackboardCheckDouble");

src/decorators/subtree_node.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ BT::NodeStatus BT::SubtreeNode::tick()
1717
return child_node_->executeTick();
1818
}
1919

20-
//--------------------------------
21-
BT::RemappedSubtreeNode::RemappedSubtreeNode(const std::string &name) :
22-
DecoratorNode(name, {} )
23-
{
24-
setRegistrationID("RemappedSubtree");
25-
}
26-
27-
BT::NodeStatus BT::RemappedSubtreeNode::tick()
28-
{
29-
NodeStatus prev_status = status();
30-
if (prev_status == NodeStatus::IDLE)
31-
{
32-
setStatus(NodeStatus::RUNNING);
33-
}
34-
return child_node_->executeTick();
35-
}
3620

3721
//--------------------------------
3822
BT::SubtreePlusNode::SubtreePlusNode(const std::string &name) :

src/xml_parsing.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,7 @@ TreeNode::Ptr XMLParser::Pimpl::createNodeFromXML(const XMLElement *element,
465465
PortsRemapping port_remap;
466466

467467
if (element_name == "SubTree" ||
468-
element_name == "SubTreePlus" ||
469-
element_name == "RemappedSubTree")
468+
element_name == "SubTreePlus" )
470469
{
471470
instance_name = element->Attribute("ID");
472471
}
@@ -611,13 +610,25 @@ void BT::XMLParser::Pimpl::recursivelyCreateTree(const std::string& tree_ID,
611610

612611
if( node->type() == NodeType::SUBTREE )
613612
{
614-
if( dynamic_cast<const RemappedSubtreeNode*>(node.get()) )
613+
if( dynamic_cast<const SubtreeNode*>(node.get()) )
615614
{
616-
recursivelyCreateTree( node->name(), output_tree, blackboard, node );
617-
}
618-
else if( dynamic_cast<const SubtreeNode*>(node.get()) )
619-
{
620-
// This is the former SubTree with manual remapping
615+
bool is_isolated = true;
616+
617+
for (const XMLAttribute* attr = element->FirstAttribute(); attr != nullptr; attr = attr->Next())
618+
{
619+
if( strcmp(attr->Name(), "__shared_blackboard") == 0 &&
620+
convertFromString<bool>(attr->Value()) == true )
621+
{
622+
is_isolated = false;
623+
}
624+
}
625+
626+
if( !is_isolated )
627+
{
628+
recursivelyCreateTree( node->name(), output_tree, blackboard, node );
629+
}
630+
else{
631+
// Creating an isolated
621632
auto new_bb = Blackboard::create(blackboard);
622633

623634
for (const XMLAttribute* attr = element->FirstAttribute(); attr != nullptr; attr = attr->Next())
@@ -630,6 +641,7 @@ void BT::XMLParser::Pimpl::recursivelyCreateTree(const std::string& tree_ID,
630641
}
631642
output_tree.blackboard_stack.emplace_back(new_bb);
632643
recursivelyCreateTree( node->name(), output_tree, new_bb, node );
644+
}
633645
}
634646
else if( dynamic_cast<const SubtreePlusNode*>(node.get()) )
635647
{

0 commit comments

Comments
 (0)