Skip to content

Commit

Permalink
fix issue BehaviorTree#702 : output ports require {}
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide authored and Gaël Écorchard committed Dec 5, 2023
1 parent f7ec907 commit ab66356
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 3 additions & 1 deletion include/behaviortree_cpp/actions/set_blackboard_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class SetBlackboard : public SyncActionNode
{
throw RuntimeError("missing port [value]");
}
setOutput("output_key", value);

config().blackboard->set(static_cast<std::string>(key), value);

return NodeStatus::SUCCESS;
}
};
Expand Down
10 changes: 7 additions & 3 deletions include/behaviortree_cpp/tree_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,16 @@ inline Result TreeNode::setOutput(const std::string& key, const T& value)
StringView remapped_key = remap_it->second;
if (remapped_key == "=")
{
remapped_key = key;
config().blackboard->set(static_cast<std::string>(key), value);
return {};
}
if (isBlackboardPointer(remapped_key))

if (!isBlackboardPointer(remapped_key))
{
remapped_key = stripBlackboardPointer(remapped_key);
return nonstd::make_unexpected("setOutput requires a blackboard pointer. Use {}");
}

remapped_key = stripBlackboardPointer(remapped_key);
config().blackboard->set(static_cast<std::string>(remapped_key), value);

return {};
Expand Down
2 changes: 1 addition & 1 deletion src/blackboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AnyPtrLocked Blackboard::getAnyLocked(const std::string &key) const
{
if(auto entry = getEntry(key))
{
return AnyPtrLocked(&entry->value, const_cast<std::mutex*>(&entry->entry_mutex));
return AnyPtrLocked(&entry->value, const_cast<std::mutex*>(&entry->entry_mutex));
}
return {};
}
Expand Down
17 changes: 17 additions & 0 deletions tests/gtest_blackboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,5 +459,22 @@ TEST(BlackboardTest, IssueSetBlackboard)
ASSERT_EQ(42, tree.rootBlackboard()->get<int>("value"));
}

TEST(BlackboardTest, NullOutputRemapping)
{
auto bb = Blackboard::create();

NodeConfig config;

config.blackboard = bb;
config.input_ports["in_port"] = "{my_input_port}";
config.output_ports["out_port"] = "";
bb->set("my_input_port", 11);

BB_TestNode node("good_one", config);

// This will throw because setOutput should fail in BB_TestNode::tick()
ASSERT_ANY_THROW(node.executeTick());
}



0 comments on commit ab66356

Please sign in to comment.