Skip to content

Commit ccefa65

Browse files
dsobekshaur-k
authored andcommitted
Fix subtree ports
1 parent 5e1a0db commit ccefa65

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/xml_parsing.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
639639
const auto element_name = element->Name();
640640
const auto element_ID = element->Attribute("ID");
641641

642+
// TODO: Pull out this node type logic
642643
auto node_type = convertFromString<NodeType>(element_name);
643644
// name used by the factory
644645
std::string type_ID;
@@ -683,6 +684,8 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
683684

684685
PortsRemapping port_remap;
685686
NonPortAttributes other_attributes;
687+
// Only relevant for subtrees
688+
bool do_autoremap = false;
686689

687690
// Parse ports and validate them where we can.
688691
for(const XMLAttribute* att = element->FirstAttribute(); att; att = att->Next())
@@ -730,6 +733,10 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
730733

731734
port_remap[port_name] = port_value;
732735
}
736+
else if(node_type == NodeType::SUBTREE && port_name == "_autoremap")
737+
{
738+
do_autoremap = convertFromString<bool>(port_value);
739+
}
733740
else if(!IsReservedAttribute(port_name))
734741
{
735742
other_attributes[port_name] = port_value;
@@ -781,6 +788,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
781788
//---------------------------------------------
782789
TreeNode::Ptr new_node;
783790

791+
// TODO: in order to set the config at this point, we need the subtree model, which is parsed after this function call in recursivelyCreateSubtree
784792
if(node_type == NodeType::SUBTREE)
785793
{
786794
// check if this subtree has a model. If it does,
@@ -814,7 +822,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
814822
// populate the node config
815823
for(const auto& [port_name, port_value] : port_remap)
816824
{
817-
auto direction = PortDirection::INPUT;
825+
PortDirection direction = PortDirection::INPUT;
818826
if(subtree_model_it != subtree_models.end())
819827
{
820828
const PortsList& subtree_model_ports = subtree_model_it->second.ports;
@@ -1015,7 +1023,7 @@ void BT::XMLParser::PImpl::recursivelyCreateSubtree(const std::string& tree_ID,
10151023

10161024
// Populate the subtree's blackboard with it's port values.
10171025
PortsRemapping subtree_remapping = const_node->config().input_ports;
1018-
const PortsRemapping& output_ports = const_node->config().output_ports;
1026+
const PortsRemapping output_ports = const_node->config().output_ports;
10191027
subtree_remapping.insert(output_ports.begin(), output_ports.end());
10201028
for(const auto& [port_name, port_value] : subtree_remapping)
10211029
{

tests/gtest_subtree.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <gtest/gtest.h>
2+
#include <gmock/gmock-matchers.h>
23
#include "behaviortree_cpp/bt_factory.h"
34
#include "../sample_nodes/dummy_nodes.h"
45
#include "../sample_nodes/movebase_node.h"
@@ -7,6 +8,8 @@
78
#include "test_helper.hpp"
89

910
using namespace BT;
11+
using ::testing::Contains;
12+
using ::testing::Pair;
1013

1114
TEST(SubTree, SiblingPorts_Issue_72)
1215
{
@@ -602,21 +605,10 @@ TEST(SubTree, SubtreeModels)
602605
}
603606
});
604607

605-
// Make sure ports are correct in the node config
606608
ASSERT_NE(subtreeNode, nullptr);
607-
const PortsRemapping& input_ports = subtreeNode->config().input_ports;
608-
EXPECT_EQ(input_ports.size(), 2);
609-
ASSERT_TRUE(input_ports.contains("in_name"));
610-
EXPECT_EQ(input_ports.at("in_name"), "{my_name}");
611-
ASSERT_TRUE(input_ports.contains("in_value"));
612-
EXPECT_EQ(input_ports.at("in_value"), "42");
613-
const PortsRemapping& output_ports = subtreeNode->config().output_ports;
614-
EXPECT_EQ(output_ports.size(), 2);
615-
ASSERT_TRUE(output_ports.contains("out_result"));
616-
EXPECT_EQ(output_ports.at("out_result"), "{output}");
617-
ASSERT_TRUE(output_ports.contains("out_state"));
618-
EXPECT_EQ(output_ports.at("out_state"), "{my_state}");
619-
609+
EXPECT_THAT(subtreeNode->config().input_ports, Contains(Pair("in_name", "{my_name}")));
610+
EXPECT_THAT(subtreeNode->config().output_ports, Contains(Pair("out_state", "{my_"
611+
"state}")));
620612
tree.tickWhileRunning();
621613
}
622614

0 commit comments

Comments
 (0)