1 #include <gtest/gtest.h> 3 #include "../sample_nodes/dummy_nodes.h" 7 TEST(SubTree, SiblingPorts_Issue_72)
11 <root main_tree_to_execute = "MainTree" > 13 <BehaviorTree ID="MainTree"> 15 <SetBlackboard value="hello" output_key="myParam" /> 16 <SubTree ID="mySubtree" param="myParam" /> 17 <SetBlackboard value="world" output_key="myParam" /> 18 <SubTree ID="mySubtree" param="myParam" /> 22 <BehaviorTree ID="mySubtree"> 23 <SaySomething message="{param}" /> 32 for (
auto& bb : tree.blackboard_stack)
35 std::cout <<
"-----" << std::endl;
41 ASSERT_EQ(tree.blackboard_stack.size(), 3);
53 auto msg = getInput<std::string>(
"in");
58 setOutput(
"out", msg.value());
64 return {BT::InputPort<std::string>(
"in"), BT::OutputPort<std::string>(
"out")};
68 TEST(SubTree, GoodRemapping)
72 <root main_tree_to_execute = "MainTree" > 74 <BehaviorTree ID="MainTree"> 76 <SetBlackboard value="hello" output_key="thoughts" /> 77 <SubTree ID="CopySubtree" in_arg="thoughts" out_arg="greetings"/> 78 <SaySomething message="{greetings}" /> 82 <BehaviorTree ID="CopySubtree"> 83 <CopyPorts in="{in_arg}" out="{out_arg}"/> 96 TEST(SubTree, BadRemapping)
102 static const char* xml_text_bad_in = R
"( 103 <root main_tree_to_execute = "MainTree" > 105 <BehaviorTree ID="MainTree"> 107 <SetBlackboard value="hello" output_key="thoughts" /> 108 <SubTree ID="CopySubtree" out_arg="greetings"/> 109 <SaySomething message="{greetings}" /> 113 <BehaviorTree ID="CopySubtree"> 114 <CopyPorts in="{in_arg}" out="{out_arg}"/> 119 EXPECT_ANY_THROW(tree_bad_in.tickRoot()); 121 static const char* xml_text_bad_out = R
"( 122 <root main_tree_to_execute = "MainTree" > 124 <BehaviorTree ID="MainTree"> 126 <SetBlackboard value="hello" output_key="thoughts" /> 127 <SubTree ID="CopySubtree" in_arg="thoughts"/> 128 <SaySomething message="{greetings}" /> 132 <BehaviorTree ID="CopySubtree"> 133 <CopyPorts in="{in_arg}" out="{out_arg}"/> 138 EXPECT_ANY_THROW(tree_bad_out.tickRoot()); 145 <root main_tree_to_execute = "MainTree" > 147 <BehaviorTree ID="MainTree"> 149 <SetBlackboard value="Auto remapped" output_key="param" /> 150 <SubTreePlus ID="mySubtree" __autoremap="1" /> 154 <BehaviorTree ID="mySubtree"> 155 <SaySomething message="{param}" /> 171 <root main_tree_to_execute = "MainTree" > 173 <BehaviorTree ID="MainTree"> 175 <SetBlackboard value="Hello World" output_key="myParam" /> 176 <SetBlackboard value="Auto remapped" output_key="param3" /> 177 <SubTreePlus ID="mySubtree" __autoremap="1" param1="{myParam}" param2="Straight Talking" /> 181 <BehaviorTree ID="mySubtree"> 183 <SaySomething message="{param1}" /> 184 <SaySomething message="{param2}" /> 185 <SaySomething message="{param3}" /> 202 <root main_tree_to_execute = "MainTree" > 204 <BehaviorTree ID="MainTree"> 206 <SetBlackboard value="Hello" output_key="param1" /> 207 <SetBlackboard value="World" output_key="param2" /> 208 <SubTree ID="mySubtree" __shared_blackboard="true"/> 212 <BehaviorTree ID="mySubtree"> 214 <SaySomething message="{param1}" /> 215 <SaySomething message="{param2}" /> 234 auto msg = getInput<std::string>(
"message");
247 return {BT::InputPort<std::string>(
"message")};
257 <root main_tree_to_execute = "MainTree" > 259 <BehaviorTree ID="MainTree"> 261 <SubTreePlus ID="mySubtree" __autoremap="1"/> 264 <BehaviorTree ID="mySubtree"> 265 <ReadInConstructor message="{message}" /> 283 <root main_tree_to_execute = "TestTree" > 284 <BehaviorTree ID="Subtree1"> 285 <Decorator ID="Repeat" num_cycles="{port_to_use}"> 286 <Action ID="AlwaysSuccess"/> 290 <BehaviorTree ID="Subtree2"> 291 <Action ID="SetBlackboard" output_key="test_port" value="{port_to_read}"/> 294 <BehaviorTree ID="TestTree"> 296 <Action ID="SetBlackboard" output_key="test_port" value="1"/> 297 <SubTree ID="Subtree1" port_to_use="test_port"/> 298 <SubTree ID="Subtree2" port_to_read="test_port"/> 318 std::cout <<
"CTOR:" << config.
blackboard->get<std::string>(
"ros_node") << std::endl;
323 std::cout <<
"tick:" << config().blackboard->get<std::string>(
"ros_node") << std::endl;
335 <root main_tree_to_execute="Tree1"> 337 <BehaviorTree ID="Tree1"> 339 <SetBlackboard output_key="the_message" value="hello world"/> 340 <SubTreePlus ID="Tree2" __autoremap="true"/> 341 <SaySomething message="{reply}" /> 345 <BehaviorTree ID="Tree2"> 346 <SubTreePlus ID="Tree3" __autoremap="true"/> 349 <BehaviorTree ID="Tree3"> 350 <SubTreePlus ID="Talker" __autoremap="true"/> 353 <BehaviorTree ID="Talker"> 355 <SaySomething message="{the_message}" /> 356 <SetBlackboard output_key="reply" value="done"/> 368 blackboard->set<std::string>(
"ros_node",
"nav2_shouldnt_do_this");
static Blackboard::Ptr create(Blackboard::Ptr parent={})
void registerNodeType(const std::string &ID)
CopyPorts(const std::string &name, const BT::NodeConfiguration &config)
static BT::PortsList providedPorts()
TEST(SubTree, SiblingPorts_Issue_72)
BT::NodeStatus tick() override
Method to be implemented by the user.
static BT::PortsList providedPorts()
static const char * xml_text
Blackboard::Ptr blackboard
static BT::PortsList providedPorts()
BT::NodeStatus tick() override
Method to be implemented by the user.
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
NodeStatus tickRoot()
tickRoot send the tick signal to the root node. It will propagate through the entire tree...
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
Struct used to store a tree. If this object goes out of scope, the tree is destroyed.
BT::NodeStatus tick() override
Method to be implemented by the user.
std::unordered_map< std::string, PortInfo > PortsList
NaughtyNav2Node(const std::string &name, const BT::NodeConfiguration &config)
ReadInConstructor(const std::string &name, const BT::NodeConfiguration &config)