Skip to content

Commit 7a3bde0

Browse files
committed
fix issue #696 (wrong autoremapping)
1 parent d7457d2 commit 7a3bde0

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

src/xml_parsing.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,10 @@ void BT::XMLParser::PImpl::recursivelyCreateSubtree(
870870
else
871871
{
872872
// constant string: just set that constant value into the BB
873+
// IMPORTANT: this must not be autoremapped!!!
874+
new_bb->enableAutoRemapping(false);
873875
new_bb->set(attr_name, static_cast<std::string>(attr_value));
876+
new_bb->enableAutoRemapping(do_autoremap);
874877
}
875878
}
876879

tests/gtest_subtree.cpp

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ TEST(SubTree, Issue653_SetBlackboard)
507507
tree.tickWhileRunning();
508508
}
509509

510-
511510
TEST(SubTree, SubtreeModels)
512511
{
513512
// clang-format off
@@ -548,3 +547,71 @@ TEST(SubTree, SubtreeModels)
548547
}
549548

550549

550+
551+
class PrintToConsole : public BT::SyncActionNode
552+
{
553+
public:
554+
PrintToConsole(const std::string& name, const BT::NodeConfiguration& config,
555+
std::vector<std::string>* console)
556+
: BT::SyncActionNode(name, config), console_(console) {}
557+
558+
static BT::PortsList providedPorts() {
559+
return {BT::InputPort<std::string>("message")};
560+
}
561+
562+
private:
563+
virtual BT::NodeStatus tick() override {
564+
if (auto res = getInput<std::string>("message"))
565+
{
566+
console_->push_back(res.value());
567+
return BT::NodeStatus::SUCCESS;
568+
}
569+
else
570+
return BT::NodeStatus::FAILURE;
571+
}
572+
std::vector<std::string>* console_;
573+
};
574+
575+
TEST(SubTree, RemappingIssue696)
576+
{
577+
// clang-format off
578+
579+
static const char* xml_text = R"(
580+
<root BTCPP_format="4">
581+
<BehaviorTree ID="Subtree1">\n"
582+
<Sequence>
583+
<PrintToConsole message="{msg1}"/>
584+
<PrintToConsole message="{msg2}"/>
585+
</Sequence>
586+
</BehaviorTree>
587+
588+
<BehaviorTree ID="Subtree2">
589+
<Sequence>
590+
<SubTree ID="Subtree1" msg1="foo1" _autoremap="true"/>
591+
<SubTree ID="Subtree1" msg1="foo2" _autoremap="true"/>
592+
</Sequence>
593+
</BehaviorTree>
594+
595+
<BehaviorTree ID="MainTree">
596+
<SubTree ID="Subtree2" msg2="bar"/>
597+
</BehaviorTree>
598+
</root>
599+
)";
600+
601+
// clang-format on
602+
603+
BehaviorTreeFactory factory;
604+
std::vector<std::string> console;
605+
factory.registerNodeType<PrintToConsole>("PrintToConsole", &console);
606+
607+
factory.registerBehaviorTreeFromText(xml_text);
608+
auto tree = factory.createTree("MainTree");
609+
tree.tickWhileRunning();
610+
611+
ASSERT_EQ(console.size(), 4);
612+
ASSERT_EQ(console[0], "foo1");
613+
ASSERT_EQ(console[1], "bar");
614+
ASSERT_EQ(console[2], "foo2");
615+
ASSERT_EQ(console[3], "bar");
616+
}
617+

0 commit comments

Comments
 (0)